2 * Window related functions
4 * Copyright 1993, 1994, 1995, 1996, 2001 Alexandre Julliard
5 * Copyright 1993 David Metcalfe
6 * Copyright 1995, 1996 Alex Korobka
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
34 #include <X11/Xresource.h>
35 #include <X11/Xutil.h>
37 #include <X11/extensions/shape.h>
38 #endif /* HAVE_LIBXSHAPE */
44 #include "wine/unicode.h"
47 #include "wine/debug.h"
48 #include "wine/server.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
53 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
54 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
55 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
56 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
57 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
58 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
59 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
60 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
61 #define _NET_WM_MOVERESIZE_MOVE 8
62 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9
63 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10
65 #define _NET_WM_STATE_REMOVE 0
66 #define _NET_WM_STATE_ADD 1
67 #define _NET_WM_STATE_TOGGLE 2
69 static const unsigned int net_wm_state_atoms
[NB_NET_WM_STATES
] =
71 XATOM__NET_WM_STATE_FULLSCREEN
,
72 XATOM__NET_WM_STATE_ABOVE
,
73 XATOM__NET_WM_STATE_MAXIMIZED_VERT
,
74 XATOM__NET_WM_STATE_SKIP_PAGER
,
75 XATOM__NET_WM_STATE_SKIP_TASKBAR
78 #define SWP_AGG_NOPOSCHANGE (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
80 /* is cursor clipping active? */
81 BOOL clipping_cursor
= FALSE
;
83 /* X context to associate a hwnd to an X window */
84 XContext winContext
= 0;
86 /* X context to associate a struct x11drv_win_data to an hwnd */
87 XContext win_data_context
= 0;
89 /* time of last user event and window where it's stored */
90 static Time last_user_time
;
91 static Window user_time_window
;
93 static const char foreign_window_prop
[] = "__wine_x11_foreign_window";
94 static const char whole_window_prop
[] = "__wine_x11_whole_window";
95 static const char clip_window_prop
[] = "__wine_x11_clip_window";
97 static CRITICAL_SECTION win_data_section
;
98 static CRITICAL_SECTION_DEBUG critsect_debug
=
100 0, 0, &win_data_section
,
101 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
102 0, 0, { (DWORD_PTR
)(__FILE__
": win_data_section") }
104 static CRITICAL_SECTION win_data_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
107 /***********************************************************************
108 * http://standards.freedesktop.org/startup-notification-spec
110 static void remove_startup_notification(Display
*display
, Window window
)
112 static LONG startup_notification_removed
= 0;
121 if (InterlockedCompareExchange(&startup_notification_removed
, 1, 0) != 0)
124 if (GetEnvironmentVariableA("DESKTOP_STARTUP_ID", id
, sizeof(id
)) == 0)
126 SetEnvironmentVariableA("DESKTOP_STARTUP_ID", NULL
);
128 if ((src
= strstr( id
, "_TIME" ))) update_user_time( atol( src
+ 5 ));
130 pos
= snprintf(message
, sizeof(message
), "remove: ID=");
131 message
[pos
++] = '"';
132 for (i
= 0; id
[i
] && pos
< sizeof(message
) - 3; i
++)
134 if (id
[i
] == '"' || id
[i
] == '\\')
135 message
[pos
++] = '\\';
136 message
[pos
++] = id
[i
];
138 message
[pos
++] = '"';
139 message
[pos
++] = '\0';
141 xevent
.xclient
.type
= ClientMessage
;
142 xevent
.xclient
.message_type
= x11drv_atom(_NET_STARTUP_INFO_BEGIN
);
143 xevent
.xclient
.display
= display
;
144 xevent
.xclient
.window
= window
;
145 xevent
.xclient
.format
= 8;
148 srclen
= strlen(src
) + 1;
155 memset(&xevent
.xclient
.data
.b
[0], 0, 20);
156 memcpy(&xevent
.xclient
.data
.b
[0], src
, msglen
);
160 XSendEvent( display
, DefaultRootWindow( display
), False
, PropertyChangeMask
, &xevent
);
161 xevent
.xclient
.message_type
= x11drv_atom(_NET_STARTUP_INFO
);
166 struct has_popup_result
172 static BOOL
is_managed( HWND hwnd
)
174 struct x11drv_win_data
*data
= get_win_data( hwnd
);
175 BOOL ret
= data
&& data
->managed
;
176 release_win_data( data
);
180 static BOOL CALLBACK
has_managed_popup( HWND hwnd
, LPARAM lparam
)
182 struct has_popup_result
*result
= (struct has_popup_result
*)lparam
;
184 if (hwnd
== result
->hwnd
) return FALSE
; /* popups are always above owner */
185 if (GetWindow( hwnd
, GW_OWNER
) != result
->hwnd
) return TRUE
;
186 result
->found
= is_managed( hwnd
);
187 return !result
->found
;
190 static BOOL
has_owned_popups( HWND hwnd
)
192 struct has_popup_result result
;
195 result
.found
= FALSE
;
196 EnumWindows( has_managed_popup
, (LPARAM
)&result
);
201 /***********************************************************************
204 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
206 struct x11drv_win_data
*data
;
208 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
210 data
->display
= display
;
211 data
->vis
= default_visual
;
213 EnterCriticalSection( &win_data_section
);
214 XSaveContext( gdi_display
, (XID
)hwnd
, win_data_context
, (char *)data
);
220 /***********************************************************************
223 * Check if a given window should be managed
225 static BOOL
is_window_managed( HWND hwnd
, UINT swp_flags
, const RECT
*window_rect
)
227 DWORD style
, ex_style
;
229 if (!managed_mode
) return FALSE
;
231 /* child windows are not managed */
232 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
233 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) return FALSE
;
234 /* activated windows are managed */
235 if (!(swp_flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
))) return TRUE
;
236 if (hwnd
== GetActiveWindow()) return TRUE
;
237 /* windows with caption are managed */
238 if ((style
& WS_CAPTION
) == WS_CAPTION
) return TRUE
;
239 /* windows with thick frame are managed */
240 if (style
& WS_THICKFRAME
) return TRUE
;
241 if (style
& WS_POPUP
)
246 /* popup with sysmenu == caption are managed */
247 if (style
& WS_SYSMENU
) return TRUE
;
248 /* full-screen popup windows are managed */
249 hmon
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
);
250 mi
.cbSize
= sizeof( mi
);
251 GetMonitorInfoW( hmon
, &mi
);
252 if (window_rect
->left
<= mi
.rcWork
.left
&& window_rect
->right
>= mi
.rcWork
.right
&&
253 window_rect
->top
<= mi
.rcWork
.top
&& window_rect
->bottom
>= mi
.rcWork
.bottom
)
256 /* application windows are managed */
257 ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
258 if (ex_style
& WS_EX_APPWINDOW
) return TRUE
;
259 /* windows that own popups are managed */
260 if (has_owned_popups( hwnd
)) return TRUE
;
261 /* default: not managed */
266 /***********************************************************************
267 * is_window_resizable
269 * Check if window should be made resizable by the window manager
271 static inline BOOL
is_window_resizable( struct x11drv_win_data
*data
, DWORD style
)
273 if (style
& WS_THICKFRAME
) return TRUE
;
274 /* Metacity needs the window to be resizable to make it fullscreen */
275 return is_window_rect_fullscreen( &data
->whole_rect
);
279 /***********************************************************************
280 * get_mwm_decorations
282 static unsigned long get_mwm_decorations( struct x11drv_win_data
*data
,
283 DWORD style
, DWORD ex_style
,
284 const RECT
*window_rect
,
285 const RECT
*client_rect
)
287 unsigned long ret
= 0;
289 if (!decorated_mode
) return 0;
291 if (EqualRect( window_rect
, client_rect
)) return 0;
292 if (IsRectEmpty( window_rect
)) return 0;
293 if (data
->shaped
) return 0;
295 if (ex_style
& WS_EX_TOOLWINDOW
) return 0;
296 if (ex_style
& WS_EX_LAYERED
) return 0;
298 if ((style
& WS_CAPTION
) == WS_CAPTION
)
300 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
301 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
302 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
303 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
305 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
306 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
307 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
312 /***********************************************************************
313 * get_window_attributes
315 * Fill the window attributes structure for an X window.
317 static int get_window_attributes( struct x11drv_win_data
*data
, XSetWindowAttributes
*attr
)
319 attr
->override_redirect
= !data
->managed
;
320 attr
->colormap
= data
->whole_colormap
? data
->whole_colormap
: default_colormap
;
321 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
322 attr
->bit_gravity
= NorthWestGravity
;
323 attr
->backing_store
= NotUseful
;
324 attr
->border_pixel
= 0;
325 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
326 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
327 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
|
328 KeymapStateMask
| StructureNotifyMask
);
329 if (data
->managed
) attr
->event_mask
|= PropertyChangeMask
;
331 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
| CWBorderPixel
|
332 CWEventMask
| CWBitGravity
| CWBackingStore
);
336 /***********************************************************************
339 * Change the X window attributes when the window style has changed.
341 static void sync_window_style( struct x11drv_win_data
*data
)
343 if (data
->whole_window
!= root_window
)
345 XSetWindowAttributes attr
;
346 int mask
= get_window_attributes( data
, &attr
);
348 XChangeWindowAttributes( data
->display
, data
->whole_window
, mask
, &attr
);
353 /***********************************************************************
356 * Update the X11 window region.
358 static void sync_window_region( struct x11drv_win_data
*data
, HRGN win_region
)
360 #ifdef HAVE_LIBXSHAPE
361 HRGN hrgn
= win_region
;
363 if (!data
->whole_window
) return;
364 data
->shaped
= FALSE
;
366 if (IsRectEmpty( &data
->window_rect
)) /* set an empty shape */
368 static XRectangle empty_rect
;
369 XShapeCombineRectangles( data
->display
, data
->whole_window
, ShapeBounding
, 0, 0,
370 &empty_rect
, 1, ShapeSet
, YXBanded
);
374 if (hrgn
== (HRGN
)1) /* hack: win_region == 1 means retrieve region from server */
376 if (!(hrgn
= CreateRectRgn( 0, 0, 0, 0 ))) return;
377 if (GetWindowRgn( data
->hwnd
, hrgn
) == ERROR
)
379 DeleteObject( hrgn
);
386 XShapeCombineMask( data
->display
, data
->whole_window
, ShapeBounding
, 0, 0, None
, ShapeSet
);
390 RGNDATA
*pRegionData
;
392 if (GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) MirrorRgn( data
->hwnd
, hrgn
);
393 if ((pRegionData
= X11DRV_GetRegionData( hrgn
, 0 )))
395 XShapeCombineRectangles( data
->display
, data
->whole_window
, ShapeBounding
,
396 data
->window_rect
.left
- data
->whole_rect
.left
,
397 data
->window_rect
.top
- data
->whole_rect
.top
,
398 (XRectangle
*)pRegionData
->Buffer
,
399 pRegionData
->rdh
.nCount
, ShapeSet
, YXBanded
);
400 HeapFree(GetProcessHeap(), 0, pRegionData
);
404 if (hrgn
&& hrgn
!= win_region
) DeleteObject( hrgn
);
405 #endif /* HAVE_LIBXSHAPE */
409 /***********************************************************************
410 * sync_window_opacity
412 static void sync_window_opacity( Display
*display
, Window win
,
413 COLORREF key
, BYTE alpha
, DWORD flags
)
415 unsigned long opacity
= 0xffffffff;
417 if (flags
& LWA_ALPHA
) opacity
= (0xffffffff / 0xff) * alpha
;
419 if (opacity
== 0xffffffff)
420 XDeleteProperty( display
, win
, x11drv_atom(_NET_WM_WINDOW_OPACITY
) );
422 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_WINDOW_OPACITY
),
423 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&opacity
, 1 );
427 /***********************************************************************
430 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
433 char *buffer
, *utf8_buffer
;
436 /* allocate new buffer for window text */
437 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
438 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
439 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
441 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
442 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
444 HeapFree( GetProcessHeap(), 0, buffer
);
447 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
449 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
451 XSetWMName( display
, win
, &prop
);
452 XSetWMIconName( display
, win
, &prop
);
456 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
457 according to the standard
458 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
460 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
461 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
463 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
464 HeapFree( GetProcessHeap(), 0, buffer
);
468 /***********************************************************************
471 * Return the bitmap bits in ARGB format. Helper for setting icon hints.
473 static unsigned long *get_bitmap_argb( HDC hdc
, HBITMAP color
, HBITMAP mask
, unsigned int *size
)
475 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
476 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
478 unsigned int *ptr
, *bits
= NULL
;
479 unsigned char *mask_bits
= NULL
;
481 BOOL has_alpha
= FALSE
;
483 if (!GetObjectW( color
, sizeof(bm
), &bm
)) return NULL
;
484 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
485 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
486 info
->bmiHeader
.biHeight
= -bm
.bmHeight
;
487 info
->bmiHeader
.biPlanes
= 1;
488 info
->bmiHeader
.biBitCount
= 32;
489 info
->bmiHeader
.biCompression
= BI_RGB
;
490 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* bm
.bmHeight
* 4;
491 info
->bmiHeader
.biXPelsPerMeter
= 0;
492 info
->bmiHeader
.biYPelsPerMeter
= 0;
493 info
->bmiHeader
.biClrUsed
= 0;
494 info
->bmiHeader
.biClrImportant
= 0;
495 *size
= bm
.bmWidth
* bm
.bmHeight
+ 2;
496 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, *size
* sizeof(long) ))) goto failed
;
497 if (!GetDIBits( hdc
, color
, 0, bm
.bmHeight
, bits
+ 2, info
, DIB_RGB_COLORS
)) goto failed
;
499 bits
[0] = bm
.bmWidth
;
500 bits
[1] = bm
.bmHeight
;
502 for (i
= 0; i
< bm
.bmWidth
* bm
.bmHeight
; i
++)
503 if ((has_alpha
= (bits
[i
+ 2] & 0xff000000) != 0)) break;
507 unsigned int width_bytes
= (bm
.bmWidth
+ 31) / 32 * 4;
508 /* generate alpha channel from the mask */
509 info
->bmiHeader
.biBitCount
= 1;
510 info
->bmiHeader
.biSizeImage
= width_bytes
* bm
.bmHeight
;
511 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto failed
;
512 if (!GetDIBits( hdc
, mask
, 0, bm
.bmHeight
, mask_bits
, info
, DIB_RGB_COLORS
)) goto failed
;
514 for (i
= 0; i
< bm
.bmHeight
; i
++)
515 for (j
= 0; j
< bm
.bmWidth
; j
++, ptr
++)
516 if (!((mask_bits
[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80)) *ptr
|= 0xff000000;
517 HeapFree( GetProcessHeap(), 0, mask_bits
);
520 /* convert to array of longs */
521 if (bits
&& sizeof(long) > sizeof(int))
522 for (i
= *size
- 1; i
>= 0; i
--) ((unsigned long *)bits
)[i
] = bits
[i
];
524 return (unsigned long *)bits
;
527 HeapFree( GetProcessHeap(), 0, bits
);
528 HeapFree( GetProcessHeap(), 0, mask_bits
);
533 /***********************************************************************
534 * create_icon_pixmaps
536 static BOOL
create_icon_pixmaps( HDC hdc
, const ICONINFO
*icon
, Pixmap
*icon_ret
, Pixmap
*mask_ret
)
538 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
539 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
540 XVisualInfo vis
= default_visual
;
541 struct gdi_image_bits bits
;
542 Pixmap color_pixmap
= 0, mask_pixmap
= 0;
550 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
551 info
->bmiHeader
.biBitCount
= 0;
552 if (!(lines
= GetDIBits( hdc
, icon
->hbmColor
, 0, 0, NULL
, info
, DIB_RGB_COLORS
))) goto failed
;
553 if (!(bits
.ptr
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto failed
;
554 if (!GetDIBits( hdc
, icon
->hbmColor
, 0, lines
, bits
.ptr
, info
, DIB_RGB_COLORS
)) goto failed
;
556 color_pixmap
= create_pixmap_from_image( hdc
, &vis
, info
, &bits
, DIB_RGB_COLORS
);
557 HeapFree( GetProcessHeap(), 0, bits
.ptr
);
559 if (!color_pixmap
) goto failed
;
561 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
562 info
->bmiHeader
.biBitCount
= 0;
563 if (!(lines
= GetDIBits( hdc
, icon
->hbmMask
, 0, 0, NULL
, info
, DIB_RGB_COLORS
))) goto failed
;
564 if (!(bits
.ptr
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto failed
;
565 if (!GetDIBits( hdc
, icon
->hbmMask
, 0, lines
, bits
.ptr
, info
, DIB_RGB_COLORS
)) goto failed
;
567 /* invert the mask */
568 for (i
= 0; i
< info
->bmiHeader
.biSizeImage
/ sizeof(DWORD
); i
++) ((DWORD
*)bits
.ptr
)[i
] ^= ~0u;
571 mask_pixmap
= create_pixmap_from_image( hdc
, &vis
, info
, &bits
, DIB_RGB_COLORS
);
572 HeapFree( GetProcessHeap(), 0, bits
.ptr
);
574 if (!mask_pixmap
) goto failed
;
576 *icon_ret
= color_pixmap
;
577 *mask_ret
= mask_pixmap
;
581 if (color_pixmap
) XFreePixmap( gdi_display
, color_pixmap
);
582 HeapFree( GetProcessHeap(), 0, bits
.ptr
);
587 /***********************************************************************
590 static void fetch_icon_data( HWND hwnd
, HICON icon_big
, HICON icon_small
)
592 struct x11drv_win_data
*data
;
593 ICONINFO ii
, ii_small
;
597 Pixmap icon_pixmap
, mask_pixmap
;
601 icon_big
= (HICON
)SendMessageW( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
602 if (!icon_big
) icon_big
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
603 if (!icon_big
) icon_big
= LoadIconW( 0, (LPWSTR
)IDI_WINLOGO
);
607 icon_small
= (HICON
)SendMessageW( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
608 if (!icon_small
) icon_small
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICONSM
);
611 if (!GetIconInfo(icon_big
, &ii
)) return;
613 hDC
= CreateCompatibleDC(0);
614 bits
= get_bitmap_argb( hDC
, ii
.hbmColor
, ii
.hbmMask
, &size
);
615 if (bits
&& GetIconInfo( icon_small
, &ii_small
))
617 unsigned int size_small
;
618 unsigned long *bits_small
, *new;
620 if ((bits_small
= get_bitmap_argb( hDC
, ii_small
.hbmColor
, ii_small
.hbmMask
, &size_small
)) &&
621 (bits_small
[0] != bits
[0] || bits_small
[1] != bits
[1])) /* size must be different */
623 if ((new = HeapReAlloc( GetProcessHeap(), 0, bits
,
624 (size
+ size_small
) * sizeof(unsigned long) )))
627 memcpy( bits
+ size
, bits_small
, size_small
* sizeof(unsigned long) );
631 HeapFree( GetProcessHeap(), 0, bits_small
);
632 DeleteObject( ii_small
.hbmColor
);
633 DeleteObject( ii_small
.hbmMask
);
636 if (!create_icon_pixmaps( hDC
, &ii
, &icon_pixmap
, &mask_pixmap
)) icon_pixmap
= mask_pixmap
= 0;
638 DeleteObject( ii
.hbmColor
);
639 DeleteObject( ii
.hbmMask
);
642 if ((data
= get_win_data( hwnd
)))
644 if (data
->icon_pixmap
) XFreePixmap( gdi_display
, data
->icon_pixmap
);
645 if (data
->icon_mask
) XFreePixmap( gdi_display
, data
->icon_mask
);
646 HeapFree( GetProcessHeap(), 0, data
->icon_bits
);
647 data
->icon_pixmap
= icon_pixmap
;
648 data
->icon_mask
= mask_pixmap
;
649 data
->icon_bits
= bits
;
650 data
->icon_size
= size
;
651 release_win_data( data
);
655 if (icon_pixmap
) XFreePixmap( gdi_display
, icon_pixmap
);
656 if (mask_pixmap
) XFreePixmap( gdi_display
, mask_pixmap
);
657 HeapFree( GetProcessHeap(), 0, bits
);
662 /***********************************************************************
665 * set the window size hints
667 static void set_size_hints( struct x11drv_win_data
*data
, DWORD style
)
669 XSizeHints
* size_hints
;
671 if (!(size_hints
= XAllocSizeHints())) return;
673 size_hints
->win_gravity
= StaticGravity
;
674 size_hints
->flags
|= PWinGravity
;
676 /* don't update size hints if window is not in normal state */
677 if (!(style
& (WS_MINIMIZE
| WS_MAXIMIZE
)))
679 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
681 size_hints
->x
= data
->whole_rect
.left
;
682 size_hints
->y
= data
->whole_rect
.top
;
683 size_hints
->flags
|= PPosition
;
685 else size_hints
->win_gravity
= NorthWestGravity
;
687 if (!is_window_resizable( data
, style
))
689 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
690 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
691 if (size_hints
->max_width
<= 0 ||size_hints
->max_height
<= 0)
692 size_hints
->max_width
= size_hints
->max_height
= 1;
693 size_hints
->min_width
= size_hints
->max_width
;
694 size_hints
->min_height
= size_hints
->max_height
;
695 size_hints
->flags
|= PMinSize
| PMaxSize
;
698 XSetWMNormalHints( data
->display
, data
->whole_window
, size_hints
);
703 /***********************************************************************
706 static void set_mwm_hints( struct x11drv_win_data
*data
, DWORD style
, DWORD ex_style
)
710 if (data
->hwnd
== GetDesktopWindow())
712 if (is_desktop_fullscreen()) mwm_hints
.decorations
= 0;
713 else mwm_hints
.decorations
= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
| MWM_DECOR_MENU
| MWM_DECOR_MINIMIZE
;
714 mwm_hints
.functions
= MWM_FUNC_MOVE
| MWM_FUNC_MINIMIZE
| MWM_FUNC_CLOSE
;
718 mwm_hints
.decorations
= get_mwm_decorations( data
, style
, ex_style
, &data
->window_rect
, &data
->client_rect
);
719 mwm_hints
.functions
= MWM_FUNC_MOVE
;
720 if (is_window_resizable( data
, style
)) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
721 if (!(style
& WS_DISABLED
))
723 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
724 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
725 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
729 TRACE( "%p setting mwm hints to %lx,%lx (style %x exstyle %x)\n",
730 data
->hwnd
, mwm_hints
.decorations
, mwm_hints
.functions
, style
, ex_style
);
732 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
733 mwm_hints
.input_mode
= 0;
734 mwm_hints
.status
= 0;
735 XChangeProperty( data
->display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
736 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
737 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
741 /***********************************************************************
744 static void set_style_hints( struct x11drv_win_data
*data
, DWORD style
, DWORD ex_style
)
746 Window group_leader
= data
->whole_window
;
747 HWND owner
= GetWindow( data
->hwnd
, GW_OWNER
);
748 Window owner_win
= 0;
754 owner
= GetAncestor( owner
, GA_ROOT
);
755 owner_win
= X11DRV_get_whole_window( owner
);
760 XSetTransientForHint( data
->display
, data
->whole_window
, owner_win
);
761 group_leader
= owner_win
;
764 /* Only use dialog type for owned popups. Metacity allows making fullscreen
765 * only normal windows, and doesn't handle correctly TRANSIENT_FOR hint for
766 * dialogs owned by fullscreen windows.
768 if (((style
& WS_POPUP
) || (ex_style
& WS_EX_DLGMODALFRAME
)) && owner
)
769 window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
771 window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
773 XChangeProperty(data
->display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
774 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
776 if ((wm_hints
= XAllocWMHints()))
778 wm_hints
->flags
= InputHint
| StateHint
| WindowGroupHint
;
779 wm_hints
->input
= !use_take_focus
&& !(style
& WS_DISABLED
);
780 wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
781 wm_hints
->window_group
= group_leader
;
782 if (data
->icon_pixmap
)
784 wm_hints
->icon_pixmap
= data
->icon_pixmap
;
785 wm_hints
->icon_mask
= data
->icon_mask
;
786 wm_hints
->flags
|= IconPixmapHint
| IconMaskHint
;
788 XSetWMHints( data
->display
, data
->whole_window
, wm_hints
);
793 XChangeProperty( data
->display
, data
->whole_window
, x11drv_atom(_NET_WM_ICON
),
794 XA_CARDINAL
, 32, PropModeReplace
,
795 (unsigned char *)data
->icon_bits
, data
->icon_size
);
797 XDeleteProperty( data
->display
, data
->whole_window
, x11drv_atom(_NET_WM_ICON
) );
802 /***********************************************************************
803 * set_initial_wm_hints
805 * Set the window manager hints that don't change over the lifetime of a window.
807 static void set_initial_wm_hints( Display
*display
, Window window
)
811 Atom dndVersion
= WINE_XDND_VERSION
;
812 XClassHint
*class_hints
;
816 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
817 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
818 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
819 XChangeProperty( display
, window
, x11drv_atom(WM_PROTOCOLS
),
820 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
823 if ((class_hints
= XAllocClassHint()))
825 class_hints
->res_name
= process_name
;
826 class_hints
->res_class
= process_name
;
827 XSetClassHint( display
, window
, class_hints
);
828 XFree( class_hints
);
831 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
832 XSetWMProperties(display
, window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
833 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
835 XChangeProperty(display
, window
, x11drv_atom(_NET_WM_PID
),
836 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
838 XChangeProperty( display
, window
, x11drv_atom(XdndAware
),
839 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
841 update_user_time( 0 ); /* make sure that the user time window exists */
842 if (user_time_window
)
843 XChangeProperty( display
, window
, x11drv_atom(_NET_WM_USER_TIME_WINDOW
),
844 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&user_time_window
, 1 );
848 /***********************************************************************
851 * If the window is managed, make sure its owner window is too.
853 static void make_owner_managed( HWND hwnd
)
857 if (!(owner
= GetWindow( hwnd
, GW_OWNER
))) return;
858 if (is_managed( owner
)) return;
859 if (!is_managed( hwnd
)) return;
861 SetWindowPos( owner
, 0, 0, 0, 0, 0,
862 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOMOVE
|
863 SWP_NOREDRAW
| SWP_DEFERERASE
| SWP_NOSENDCHANGING
| SWP_STATECHANGED
);
867 /***********************************************************************
870 * Set all the window manager hints for a window.
872 static void set_wm_hints( struct x11drv_win_data
*data
)
874 DWORD style
, ex_style
;
876 if (data
->hwnd
== GetDesktopWindow())
878 /* force some styles for the desktop to get the correct decorations */
879 style
= WS_POPUP
| WS_VISIBLE
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
880 ex_style
= WS_EX_APPWINDOW
;
884 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
885 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
888 set_size_hints( data
, style
);
889 set_mwm_hints( data
, style
, ex_style
);
890 set_style_hints( data
, style
, ex_style
);
894 /***********************************************************************
897 Window
init_clip_window(void)
899 struct x11drv_thread_data
*data
= x11drv_init_thread_data();
901 if (!data
->clip_window
&&
902 (data
->clip_window
= (Window
)GetPropA( GetDesktopWindow(), clip_window_prop
)))
904 XSelectInput( data
->display
, data
->clip_window
, StructureNotifyMask
);
906 return data
->clip_window
;
910 /***********************************************************************
913 void update_user_time( Time time
)
915 if (!user_time_window
)
917 Window win
= XCreateWindow( gdi_display
, root_window
, -1, -1, 1, 1, 0, CopyFromParent
,
918 InputOnly
, CopyFromParent
, 0, NULL
);
919 if (InterlockedCompareExchangePointer( (void **)&user_time_window
, (void *)win
, 0 ))
920 XDestroyWindow( gdi_display
, win
);
921 TRACE( "user time window %lx\n", user_time_window
);
925 XLockDisplay( gdi_display
);
926 if (!last_user_time
|| (long)(time
- last_user_time
) > 0)
928 last_user_time
= time
;
929 XChangeProperty( gdi_display
, user_time_window
, x11drv_atom(_NET_WM_USER_TIME
),
930 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&time
, 1 );
932 XUnlockDisplay( gdi_display
);
935 /***********************************************************************
936 * update_net_wm_states
938 void update_net_wm_states( struct x11drv_win_data
*data
)
940 DWORD i
, style
, ex_style
, new_state
= 0;
942 if (!data
->managed
) return;
943 if (data
->whole_window
== root_window
) return;
945 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
946 if (style
& WS_MINIMIZE
)
947 new_state
|= data
->net_wm_state
& ((1 << NET_WM_STATE_FULLSCREEN
)|(1 << NET_WM_STATE_MAXIMIZED
));
948 if (is_window_rect_fullscreen( &data
->whole_rect
))
950 if ((style
& WS_MAXIMIZE
) && (style
& WS_CAPTION
) == WS_CAPTION
)
951 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
952 else if (!(style
& WS_MINIMIZE
))
953 new_state
|= (1 << NET_WM_STATE_FULLSCREEN
);
955 else if (style
& WS_MAXIMIZE
)
956 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
958 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
959 if (ex_style
& WS_EX_TOPMOST
)
960 new_state
|= (1 << NET_WM_STATE_ABOVE
);
961 if (ex_style
& (WS_EX_TOOLWINDOW
| WS_EX_NOACTIVATE
))
962 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
) | (1 << NET_WM_STATE_SKIP_PAGER
);
963 if (!(ex_style
& WS_EX_APPWINDOW
) && GetWindow( data
->hwnd
, GW_OWNER
))
964 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
);
966 if (!data
->mapped
) /* set the _NET_WM_STATE atom directly */
968 Atom atoms
[NB_NET_WM_STATES
+1];
971 for (i
= count
= 0; i
< NB_NET_WM_STATES
; i
++)
973 if (!(new_state
& (1 << i
))) continue;
974 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
975 i
, data
->hwnd
, data
->whole_window
);
976 atoms
[count
++] = X11DRV_Atoms
[net_wm_state_atoms
[i
] - FIRST_XATOM
];
977 if (net_wm_state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
)
978 atoms
[count
++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
);
980 XChangeProperty( data
->display
, data
->whole_window
, x11drv_atom(_NET_WM_STATE
), XA_ATOM
,
981 32, PropModeReplace
, (unsigned char *)atoms
, count
);
983 else /* ask the window manager to do it for us */
987 xev
.xclient
.type
= ClientMessage
;
988 xev
.xclient
.window
= data
->whole_window
;
989 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
990 xev
.xclient
.serial
= 0;
991 xev
.xclient
.display
= data
->display
;
992 xev
.xclient
.send_event
= True
;
993 xev
.xclient
.format
= 32;
994 xev
.xclient
.data
.l
[3] = 1;
995 xev
.xclient
.data
.l
[4] = 0;
997 for (i
= 0; i
< NB_NET_WM_STATES
; i
++)
999 if (!((data
->net_wm_state
^ new_state
) & (1 << i
))) continue; /* unchanged */
1001 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1002 i
, data
->hwnd
, data
->whole_window
,
1003 (new_state
& (1 << i
)) != 0, (data
->net_wm_state
& (1 << i
)) != 0 );
1005 xev
.xclient
.data
.l
[0] = (new_state
& (1 << i
)) ? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
1006 xev
.xclient
.data
.l
[1] = X11DRV_Atoms
[net_wm_state_atoms
[i
] - FIRST_XATOM
];
1007 xev
.xclient
.data
.l
[2] = ((net_wm_state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
) ?
1008 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
) : 0);
1009 XSendEvent( data
->display
, root_window
, False
,
1010 SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
1013 data
->net_wm_state
= new_state
;
1016 /***********************************************************************
1017 * read_net_wm_states
1019 void read_net_wm_states( Display
* display
, struct x11drv_win_data
*data
)
1023 unsigned long i
, j
, count
, remaining
;
1024 DWORD new_state
= 0;
1025 BOOL maximized_horz
= FALSE
;
1027 if (!data
->whole_window
) return;
1029 if (!XGetWindowProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_STATE
), 0,
1030 65536/sizeof(CARD32
), False
, XA_ATOM
, &type
, &format
, &count
,
1031 &remaining
, (unsigned char **)&state
))
1033 if (type
== XA_ATOM
&& format
== 32)
1035 for (i
= 0; i
< count
; i
++)
1037 if (state
[i
] == x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
))
1038 maximized_horz
= TRUE
;
1039 for (j
=0; j
< NB_NET_WM_STATES
; j
++)
1041 if (state
[i
] == X11DRV_Atoms
[net_wm_state_atoms
[j
] - FIRST_XATOM
])
1043 new_state
|= 1 << j
;
1051 if (!maximized_horz
)
1052 new_state
&= ~(1 << NET_WM_STATE_MAXIMIZED
);
1054 data
->net_wm_state
= new_state
;
1058 /***********************************************************************
1061 static void set_xembed_flags( struct x11drv_win_data
*data
, unsigned long flags
)
1063 unsigned long info
[2];
1065 if (!data
->whole_window
) return;
1067 info
[0] = 0; /* protocol version */
1069 XChangeProperty( data
->display
, data
->whole_window
, x11drv_atom(_XEMBED_INFO
),
1070 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
, (unsigned char*)info
, 2 );
1074 /***********************************************************************
1077 static void map_window( HWND hwnd
, DWORD new_style
)
1079 struct x11drv_win_data
*data
;
1081 make_owner_managed( hwnd
);
1082 wait_for_withdrawn_state( hwnd
, TRUE
);
1084 if (!(data
= get_win_data( hwnd
))) return;
1086 if (data
->whole_window
&& !data
->mapped
)
1088 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1090 remove_startup_notification( data
->display
, data
->whole_window
);
1091 set_wm_hints( data
);
1093 if (!data
->embedded
)
1095 update_net_wm_states( data
);
1096 sync_window_style( data
);
1097 XMapWindow( data
->display
, data
->whole_window
);
1098 XFlush( data
->display
);
1099 if (data
->surface
&& data
->vis
.visualid
!= default_visual
.visualid
)
1100 data
->surface
->funcs
->flush( data
->surface
);
1102 else set_xembed_flags( data
, XEMBED_MAPPED
);
1104 data
->mapped
= TRUE
;
1105 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
1107 release_win_data( data
);
1111 /***********************************************************************
1114 static void unmap_window( HWND hwnd
)
1116 struct x11drv_win_data
*data
;
1118 wait_for_withdrawn_state( hwnd
, FALSE
);
1120 if (!(data
= get_win_data( hwnd
))) return;
1124 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1126 if (data
->embedded
) set_xembed_flags( data
, 0 );
1127 else if (!data
->managed
) XUnmapWindow( data
->display
, data
->whole_window
);
1128 else XWithdrawWindow( data
->display
, data
->whole_window
, data
->vis
.screen
);
1130 data
->mapped
= FALSE
;
1131 data
->net_wm_state
= 0;
1133 release_win_data( data
);
1137 /***********************************************************************
1138 * make_window_embedded
1140 void make_window_embedded( struct x11drv_win_data
*data
)
1142 /* the window cannot be mapped before being embedded */
1145 if (!data
->managed
) XUnmapWindow( data
->display
, data
->whole_window
);
1146 else XWithdrawWindow( data
->display
, data
->whole_window
, data
->vis
.screen
);
1147 data
->net_wm_state
= 0;
1149 data
->embedded
= TRUE
;
1150 data
->managed
= TRUE
;
1151 sync_window_style( data
);
1152 set_xembed_flags( data
, (data
->mapped
|| data
->embedder
) ? XEMBED_MAPPED
: 0 );
1156 /***********************************************************************
1157 * X11DRV_window_to_X_rect
1159 * Convert a rect from client to X window coordinates
1161 static void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
,
1162 const RECT
*window_rect
, const RECT
*client_rect
)
1164 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
1165 unsigned long decor
;
1168 if (!data
->managed
) return;
1169 if (IsRectEmpty( rect
)) return;
1171 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1172 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
1173 decor
= get_mwm_decorations( data
, style
, ex_style
, window_rect
, client_rect
);
1175 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
1176 if (decor
& MWM_DECOR_BORDER
)
1178 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
1179 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
1182 SetRectEmpty( &rc
);
1183 AdjustWindowRectEx( &rc
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
1185 rect
->left
-= rc
.left
;
1186 rect
->right
-= rc
.right
;
1187 rect
->top
-= rc
.top
;
1188 rect
->bottom
-= rc
.bottom
;
1189 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1190 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1194 /***********************************************************************
1195 * X11DRV_X_to_window_rect
1197 * Opposite of X11DRV_window_to_X_rect
1199 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
, int x
, int y
, int cx
, int cy
)
1201 x
+= data
->window_rect
.left
- data
->whole_rect
.left
;
1202 y
+= data
->window_rect
.top
- data
->whole_rect
.top
;
1203 cx
+= (data
->window_rect
.right
- data
->window_rect
.left
) -
1204 (data
->whole_rect
.right
- data
->whole_rect
.left
);
1205 cy
+= (data
->window_rect
.bottom
- data
->window_rect
.top
) -
1206 (data
->whole_rect
.bottom
- data
->whole_rect
.top
);
1207 SetRect( rect
, x
, y
, x
+ cx
, y
+ cy
);
1211 /***********************************************************************
1212 * sync_window_position
1214 * Synchronize the X window position with the Windows one
1216 static void sync_window_position( struct x11drv_win_data
*data
,
1217 UINT swp_flags
, const RECT
*old_window_rect
,
1218 const RECT
*old_whole_rect
, const RECT
*old_client_rect
)
1220 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1221 DWORD ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
1222 XWindowChanges changes
;
1223 unsigned int mask
= 0;
1225 if (data
->managed
&& data
->iconic
) return;
1227 /* resizing a managed maximized window is not allowed */
1228 if (!(style
& WS_MAXIMIZE
) || !data
->managed
)
1230 changes
.width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
1231 changes
.height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
1232 /* if window rect is empty force size to 1x1 */
1233 if (changes
.width
<= 0 || changes
.height
<= 0) changes
.width
= changes
.height
= 1;
1234 if (changes
.width
> 65535) changes
.width
= 65535;
1235 if (changes
.height
> 65535) changes
.height
= 65535;
1236 mask
|= CWWidth
| CWHeight
;
1239 /* only the size is allowed to change for the desktop window */
1240 if (data
->whole_window
!= root_window
)
1242 POINT pt
= virtual_screen_to_root( data
->whole_rect
.left
, data
->whole_rect
.top
);
1248 if (!(swp_flags
& SWP_NOZORDER
) || (swp_flags
& SWP_SHOWWINDOW
))
1250 /* find window that this one must be after */
1251 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
1252 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
1253 prev
= GetWindow( prev
, GW_HWNDPREV
);
1254 if (!prev
) /* top child */
1256 changes
.stack_mode
= Above
;
1257 mask
|= CWStackMode
;
1259 /* should use stack_mode Below but most window managers don't get it right */
1260 /* and Above with a sibling doesn't work so well either, so we ignore it */
1263 set_size_hints( data
, style
);
1264 set_mwm_hints( data
, style
, ex_style
);
1265 update_net_wm_states( data
);
1266 data
->configure_serial
= NextRequest( data
->display
);
1267 XReconfigureWMWindow( data
->display
, data
->whole_window
, data
->vis
.screen
, mask
, &changes
);
1268 #ifdef HAVE_LIBXSHAPE
1269 if (IsRectEmpty( old_window_rect
) != IsRectEmpty( &data
->window_rect
))
1270 sync_window_region( data
, (HRGN
)1 );
1273 int old_x_offset
= old_window_rect
->left
- old_whole_rect
->left
;
1274 int old_y_offset
= old_window_rect
->top
- old_whole_rect
->top
;
1275 int new_x_offset
= data
->window_rect
.left
- data
->whole_rect
.left
;
1276 int new_y_offset
= data
->window_rect
.top
- data
->whole_rect
.top
;
1277 if (old_x_offset
!= new_x_offset
|| old_y_offset
!= new_y_offset
)
1278 XShapeOffsetShape( data
->display
, data
->whole_window
, ShapeBounding
,
1279 new_x_offset
- old_x_offset
, new_y_offset
- old_y_offset
);
1283 TRACE( "win %p/%lx pos %d,%d,%dx%d after %lx changes=%x serial=%lu\n",
1284 data
->hwnd
, data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1285 data
->whole_rect
.right
- data
->whole_rect
.left
,
1286 data
->whole_rect
.bottom
- data
->whole_rect
.top
,
1287 changes
.sibling
, mask
, data
->configure_serial
);
1291 /***********************************************************************
1292 * sync_client_position
1294 * Synchronize the X client window position with the Windows one
1296 static void sync_client_position( struct x11drv_win_data
*data
,
1297 const RECT
*old_client_rect
, const RECT
*old_whole_rect
)
1300 XWindowChanges changes
;
1302 if (!data
->client_window
) return;
1304 changes
.x
= data
->client_rect
.left
- data
->whole_rect
.left
;
1305 changes
.y
= data
->client_rect
.top
- data
->whole_rect
.top
;
1306 changes
.width
= min( max( 1, data
->client_rect
.right
- data
->client_rect
.left
), 65535 );
1307 changes
.height
= min( max( 1, data
->client_rect
.bottom
- data
->client_rect
.top
), 65535 );
1309 if (changes
.x
!= old_client_rect
->left
- old_whole_rect
->left
) mask
|= CWX
;
1310 if (changes
.y
!= old_client_rect
->top
- old_whole_rect
->top
) mask
|= CWY
;
1311 if (changes
.width
!= old_client_rect
->right
- old_client_rect
->left
) mask
|= CWWidth
;
1312 if (changes
.height
!= old_client_rect
->bottom
- old_client_rect
->top
) mask
|= CWHeight
;
1316 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1317 data
->client_window
, changes
.x
, changes
.y
, changes
.width
, changes
.height
, mask
);
1318 XConfigureWindow( data
->display
, data
->client_window
, mask
, &changes
);
1323 /***********************************************************************
1326 * Move the window bits when a window is moved.
1328 static void move_window_bits( HWND hwnd
, Window window
, const RECT
*old_rect
, const RECT
*new_rect
,
1329 const RECT
*old_client_rect
, const RECT
*new_client_rect
,
1330 const RECT
*new_window_rect
)
1332 RECT src_rect
= *old_rect
;
1333 RECT dst_rect
= *new_rect
;
1334 HDC hdc_src
, hdc_dst
;
1341 OffsetRect( &dst_rect
, -new_window_rect
->left
, -new_window_rect
->top
);
1342 parent
= GetAncestor( hwnd
, GA_PARENT
);
1343 hdc_src
= GetDCEx( parent
, 0, DCX_CACHE
);
1344 hdc_dst
= GetDCEx( hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
1348 OffsetRect( &dst_rect
, -new_client_rect
->left
, -new_client_rect
->top
);
1349 /* make src rect relative to the old position of the window */
1350 OffsetRect( &src_rect
, -old_client_rect
->left
, -old_client_rect
->top
);
1351 if (dst_rect
.left
== src_rect
.left
&& dst_rect
.top
== src_rect
.top
) return;
1352 hdc_src
= hdc_dst
= GetDCEx( hwnd
, 0, DCX_CACHE
);
1355 rgn
= CreateRectRgnIndirect( &dst_rect
);
1356 SelectClipRgn( hdc_dst
, rgn
);
1357 DeleteObject( rgn
);
1358 /* WS_CLIPCHILDREN doesn't exclude children from the window update
1359 * region, and ExcludeUpdateRgn call may inappropriately clip valid
1360 * child window contents from the copied parent window bits, but we
1361 * still want to avoid copying invalid window bits when possible.
1363 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CLIPCHILDREN
))
1364 ExcludeUpdateRgn( hdc_dst
, hwnd
);
1366 code
= X11DRV_START_EXPOSURES
;
1367 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
1369 TRACE( "copying bits for win %p/%lx %s -> %s\n",
1370 hwnd
, window
, wine_dbgstr_rect(&src_rect
), wine_dbgstr_rect(&dst_rect
) );
1371 BitBlt( hdc_dst
, dst_rect
.left
, dst_rect
.top
,
1372 dst_rect
.right
- dst_rect
.left
, dst_rect
.bottom
- dst_rect
.top
,
1373 hdc_src
, src_rect
.left
, src_rect
.top
, SRCCOPY
);
1376 code
= X11DRV_END_EXPOSURES
;
1377 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, sizeof(rgn
), (LPSTR
)&rgn
);
1379 ReleaseDC( hwnd
, hdc_dst
);
1380 if (hdc_src
!= hdc_dst
) ReleaseDC( parent
, hdc_src
);
1386 /* map region to client rect since we are using DCX_WINDOW */
1387 OffsetRgn( rgn
, new_window_rect
->left
- new_client_rect
->left
,
1388 new_window_rect
->top
- new_client_rect
->top
);
1389 RedrawWindow( hwnd
, NULL
, rgn
,
1390 RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
1392 else RedrawWindow( hwnd
, NULL
, rgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1393 DeleteObject( rgn
);
1398 /***********************************************************************
1401 * Create a dummy parent window for child windows that don't have a true X11 parent.
1403 static Window
get_dummy_parent(void)
1405 static Window dummy_parent
;
1409 XSetWindowAttributes attrib
;
1411 attrib
.override_redirect
= True
;
1412 attrib
.border_pixel
= 0;
1413 attrib
.colormap
= default_colormap
;
1414 dummy_parent
= XCreateWindow( gdi_display
, root_window
, -1, -1, 1, 1, 0, default_visual
.depth
,
1415 InputOutput
, default_visual
.visual
,
1416 CWColormap
| CWBorderPixel
| CWOverrideRedirect
, &attrib
);
1417 XMapWindow( gdi_display
, dummy_parent
);
1419 return dummy_parent
;
1423 /**********************************************************************
1424 * create_client_window
1426 Window
create_client_window( HWND hwnd
, const XVisualInfo
*visual
)
1428 Window dummy_parent
= get_dummy_parent();
1429 struct x11drv_win_data
*data
= get_win_data( hwnd
);
1430 XSetWindowAttributes attr
;
1436 /* explicitly create data for HWND_MESSAGE windows since they can be used for OpenGL */
1437 HWND parent
= GetAncestor( hwnd
, GA_PARENT
);
1438 if (parent
== GetDesktopWindow() || GetAncestor( parent
, GA_PARENT
)) return 0;
1439 if (!(data
= alloc_win_data( thread_init_display(), hwnd
))) return 0;
1440 GetClientRect( hwnd
, &data
->client_rect
);
1441 data
->window_rect
= data
->whole_rect
= data
->client_rect
;
1444 if (data
->client_window
)
1446 XDeleteContext( data
->display
, data
->client_window
, winContext
);
1447 XReparentWindow( gdi_display
, data
->client_window
, dummy_parent
, 0, 0 );
1448 TRACE( "%p reparent xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1451 if (data
->client_colormap
) XFreeColormap( gdi_display
, data
->client_colormap
);
1452 data
->client_colormap
= XCreateColormap( gdi_display
, dummy_parent
, visual
->visual
,
1453 (visual
->class == PseudoColor
||
1454 visual
->class == GrayScale
||
1455 visual
->class == DirectColor
) ? AllocAll
: AllocNone
);
1456 attr
.colormap
= data
->client_colormap
;
1457 attr
.bit_gravity
= NorthWestGravity
;
1458 attr
.win_gravity
= NorthWestGravity
;
1459 attr
.backing_store
= NotUseful
;
1460 attr
.border_pixel
= 0;
1462 x
= data
->client_rect
.left
- data
->whole_rect
.left
;
1463 y
= data
->client_rect
.top
- data
->whole_rect
.top
;
1464 cx
= min( max( 1, data
->client_rect
.right
- data
->client_rect
.left
), 65535 );
1465 cy
= min( max( 1, data
->client_rect
.bottom
- data
->client_rect
.top
), 65535 );
1467 ret
= data
->client_window
= XCreateWindow( gdi_display
,
1468 data
->whole_window
? data
->whole_window
: dummy_parent
,
1469 x
, y
, cx
, cy
, 0, default_visual
.depth
, InputOutput
,
1470 visual
->visual
, CWBitGravity
| CWWinGravity
|
1471 CWBackingStore
| CWColormap
| CWBorderPixel
, &attr
);
1472 if (data
->client_window
)
1474 XSaveContext( data
->display
, data
->client_window
, winContext
, (char *)data
->hwnd
);
1475 XMapWindow( gdi_display
, data
->client_window
);
1476 XSync( gdi_display
, False
);
1477 if (data
->whole_window
) XSelectInput( data
->display
, data
->client_window
, ExposureMask
);
1478 TRACE( "%p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1480 release_win_data( data
);
1485 /**********************************************************************
1486 * create_whole_window
1488 * Create the whole X window for a given window
1490 static void create_whole_window( struct x11drv_win_data
*data
)
1493 XSetWindowAttributes attr
;
1497 DWORD layered_flags
;
1501 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1503 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1504 data
->managed
= TRUE
;
1507 if ((win_rgn
= CreateRectRgn( 0, 0, 0, 0 )) && GetWindowRgn( data
->hwnd
, win_rgn
) == ERROR
)
1509 DeleteObject( win_rgn
);
1512 data
->shaped
= (win_rgn
!= 0);
1514 if (data
->vis
.visualid
!= default_visual
.visualid
)
1515 data
->whole_colormap
= XCreateColormap( data
->display
, root_window
, data
->vis
.visual
, AllocNone
);
1517 mask
= get_window_attributes( data
, &attr
);
1519 if (!(cx
= data
->whole_rect
.right
- data
->whole_rect
.left
)) cx
= 1;
1520 else if (cx
> 65535) cx
= 65535;
1521 if (!(cy
= data
->whole_rect
.bottom
- data
->whole_rect
.top
)) cy
= 1;
1522 else if (cy
> 65535) cy
= 65535;
1524 pos
= virtual_screen_to_root( data
->whole_rect
.left
, data
->whole_rect
.top
);
1525 data
->whole_window
= XCreateWindow( data
->display
, root_window
, pos
.x
, pos
.y
,
1526 cx
, cy
, 0, data
->vis
.depth
, InputOutput
,
1527 data
->vis
.visual
, mask
, &attr
);
1528 if (!data
->whole_window
) goto done
;
1530 set_initial_wm_hints( data
->display
, data
->whole_window
);
1531 set_wm_hints( data
);
1533 XSaveContext( data
->display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1534 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1536 /* set the window text */
1537 if (!InternalGetWindowText( data
->hwnd
, text
, ARRAY_SIZE( text
))) text
[0] = 0;
1538 sync_window_text( data
->display
, data
->whole_window
, text
);
1540 /* set the window region */
1541 if (win_rgn
|| IsRectEmpty( &data
->window_rect
)) sync_window_region( data
, win_rgn
);
1543 /* set the window opacity */
1544 if (!GetLayeredWindowAttributes( data
->hwnd
, &key
, &alpha
, &layered_flags
)) layered_flags
= 0;
1545 sync_window_opacity( data
->display
, data
->whole_window
, key
, alpha
, layered_flags
);
1547 XFlush( data
->display
); /* make sure the window exists before we start painting to it */
1549 sync_window_cursor( data
->whole_window
);
1552 if (win_rgn
) DeleteObject( win_rgn
);
1556 /**********************************************************************
1557 * destroy_whole_window
1559 * Destroy the whole X window for a given window.
1561 static void destroy_whole_window( struct x11drv_win_data
*data
, BOOL already_destroyed
)
1563 TRACE( "win %p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1565 if (data
->client_window
) XDeleteContext( data
->display
, data
->client_window
, winContext
);
1567 if (!data
->whole_window
)
1571 Window xwin
= (Window
)GetPropA( data
->hwnd
, foreign_window_prop
);
1574 if (!already_destroyed
) XSelectInput( data
->display
, xwin
, 0 );
1575 XDeleteContext( data
->display
, xwin
, winContext
);
1576 RemovePropA( data
->hwnd
, foreign_window_prop
);
1583 if (data
->client_window
&& !already_destroyed
)
1585 XSelectInput( data
->display
, data
->client_window
, 0 );
1586 XReparentWindow( data
->display
, data
->client_window
, get_dummy_parent(), 0, 0 );
1587 XSync( data
->display
, False
);
1589 XDeleteContext( data
->display
, data
->whole_window
, winContext
);
1590 if (!already_destroyed
) XDestroyWindow( data
->display
, data
->whole_window
);
1592 if (data
->whole_colormap
) XFreeColormap( data
->display
, data
->whole_colormap
);
1593 data
->whole_window
= data
->client_window
= 0;
1594 data
->whole_colormap
= 0;
1595 data
->wm_state
= WithdrawnState
;
1596 data
->net_wm_state
= 0;
1597 data
->mapped
= FALSE
;
1600 XUnsetICFocus( data
->xic
);
1601 XDestroyIC( data
->xic
);
1604 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1605 XFlush( data
->display
);
1606 if (data
->surface
) window_surface_release( data
->surface
);
1607 data
->surface
= NULL
;
1608 RemovePropA( data
->hwnd
, whole_window_prop
);
1612 /**********************************************************************
1615 * Change the visual by destroying and recreating the X window if needed.
1617 void set_window_visual( struct x11drv_win_data
*data
, const XVisualInfo
*vis
, BOOL use_alpha
)
1619 Window client_window
= data
->client_window
;
1620 Window whole_window
= data
->whole_window
;
1622 if (!data
->use_alpha
== !use_alpha
) return;
1623 if (data
->surface
) window_surface_release( data
->surface
);
1624 data
->surface
= NULL
;
1625 data
->use_alpha
= use_alpha
;
1627 if (data
->vis
.visualid
== vis
->visualid
) return;
1628 data
->client_window
= 0;
1629 destroy_whole_window( data
, client_window
!= 0 /* don't destroy whole_window until reparented */ );
1631 create_whole_window( data
);
1632 if (!client_window
) return;
1633 /* move the client to the new parent */
1634 XReparentWindow( data
->display
, client_window
, data
->whole_window
,
1635 data
->client_rect
.left
- data
->whole_rect
.left
,
1636 data
->client_rect
.top
- data
->whole_rect
.top
);
1637 data
->client_window
= client_window
;
1638 XDestroyWindow( data
->display
, whole_window
);
1642 /*****************************************************************
1643 * SetWindowText (X11DRV.@)
1645 void CDECL
X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1649 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(gdi_display
))
1651 Display
*display
= thread_init_display();
1652 sync_window_text( display
, win
, text
);
1657 /***********************************************************************
1658 * SetWindowStyle (X11DRV.@)
1660 * Update the X state of a window to reflect a style change
1662 void CDECL
X11DRV_SetWindowStyle( HWND hwnd
, INT offset
, STYLESTRUCT
*style
)
1664 struct x11drv_win_data
*data
;
1665 DWORD changed
= style
->styleNew
^ style
->styleOld
;
1667 if (hwnd
== GetDesktopWindow()) return;
1668 if (!(data
= get_win_data( hwnd
))) return;
1669 if (!data
->whole_window
) goto done
;
1671 if (offset
== GWL_STYLE
&& (changed
& WS_DISABLED
)) set_wm_hints( data
);
1673 if (offset
== GWL_EXSTYLE
&& (changed
& WS_EX_LAYERED
)) /* changing WS_EX_LAYERED resets attributes */
1675 data
->layered
= FALSE
;
1676 set_window_visual( data
, &default_visual
, FALSE
);
1677 sync_window_opacity( data
->display
, data
->whole_window
, 0, 0, 0 );
1678 if (data
->surface
) set_surface_color_key( data
->surface
, CLR_INVALID
);
1681 release_win_data( data
);
1685 /***********************************************************************
1686 * DestroyWindow (X11DRV.@)
1688 void CDECL
X11DRV_DestroyWindow( HWND hwnd
)
1690 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1691 struct x11drv_win_data
*data
;
1693 if (!(data
= get_win_data( hwnd
))) return;
1695 destroy_whole_window( data
, FALSE
);
1696 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1697 if (thread_data
->last_xic_hwnd
== hwnd
) thread_data
->last_xic_hwnd
= 0;
1698 if (data
->icon_pixmap
) XFreePixmap( gdi_display
, data
->icon_pixmap
);
1699 if (data
->icon_mask
) XFreePixmap( gdi_display
, data
->icon_mask
);
1700 if (data
->client_colormap
) XFreeColormap( data
->display
, data
->client_colormap
);
1701 HeapFree( GetProcessHeap(), 0, data
->icon_bits
);
1702 XDeleteContext( gdi_display
, (XID
)hwnd
, win_data_context
);
1703 release_win_data( data
);
1704 HeapFree( GetProcessHeap(), 0, data
);
1705 destroy_gl_drawable( hwnd
);
1706 wine_vk_surface_destroy( hwnd
);
1710 /***********************************************************************
1711 * X11DRV_DestroyNotify
1713 BOOL
X11DRV_DestroyNotify( HWND hwnd
, XEvent
*event
)
1715 struct x11drv_win_data
*data
;
1718 if (!(data
= get_win_data( hwnd
))) return FALSE
;
1719 embedded
= data
->embedded
;
1720 if (!embedded
) FIXME( "window %p/%lx destroyed from the outside\n", hwnd
, data
->whole_window
);
1722 destroy_whole_window( data
, TRUE
);
1723 release_win_data( data
);
1724 if (embedded
) SendMessageW( hwnd
, WM_CLOSE
, 0, 0 );
1729 /* initialize the desktop window id in the desktop manager process */
1730 BOOL
create_desktop_win_data( Window win
)
1732 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1733 Display
*display
= thread_data
->display
;
1734 struct x11drv_win_data
*data
;
1736 if (!(data
= alloc_win_data( display
, GetDesktopWindow() ))) return FALSE
;
1737 data
->whole_window
= win
;
1738 data
->managed
= TRUE
;
1739 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)win
);
1740 set_initial_wm_hints( display
, win
);
1741 release_win_data( data
);
1742 if (thread_data
->clip_window
) XReparentWindow( display
, thread_data
->clip_window
, win
, 0, 0 );
1746 /**********************************************************************
1747 * CreateDesktopWindow (X11DRV.@)
1749 BOOL CDECL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1751 unsigned int width
, height
;
1753 /* retrieve the real size of the desktop */
1754 SERVER_START_REQ( get_window_rectangles
)
1756 req
->handle
= wine_server_user_handle( hwnd
);
1757 req
->relative
= COORDS_CLIENT
;
1758 wine_server_call( req
);
1759 width
= reply
->window
.right
;
1760 height
= reply
->window
.bottom
;
1764 if (!width
&& !height
) /* not initialized yet */
1766 RECT rect
= get_virtual_screen_rect();
1768 SERVER_START_REQ( set_window_pos
)
1770 req
->handle
= wine_server_user_handle( hwnd
);
1772 req
->swp_flags
= SWP_NOZORDER
;
1773 req
->window
.left
= rect
.left
;
1774 req
->window
.top
= rect
.top
;
1775 req
->window
.right
= rect
.right
;
1776 req
->window
.bottom
= rect
.bottom
;
1777 req
->client
= req
->window
;
1778 wine_server_call( req
);
1784 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1785 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1791 static WNDPROC desktop_orig_wndproc
;
1793 #define WM_WINE_NOTIFY_ACTIVITY WM_USER
1795 static LRESULT CALLBACK
desktop_wndproc_wrapper( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1799 case WM_WINE_NOTIFY_ACTIVITY
:
1801 static ULONGLONG last
= 0;
1802 ULONGLONG now
= GetTickCount64();
1803 /* calling XResetScreenSaver too often can cause performance
1804 * problems, so throttle it */
1805 if (now
> last
+ 5000)
1807 XResetScreenSaver( gdi_display
);
1808 XFlush( gdi_display
);
1814 return desktop_orig_wndproc( hwnd
, msg
, wp
, lp
);
1817 /**********************************************************************
1818 * CreateWindow (X11DRV.@)
1820 BOOL CDECL
X11DRV_CreateWindow( HWND hwnd
)
1822 if (hwnd
== GetDesktopWindow())
1824 struct x11drv_thread_data
*data
= x11drv_init_thread_data();
1825 XSetWindowAttributes attr
;
1827 desktop_orig_wndproc
= (WNDPROC
)SetWindowLongPtrW( hwnd
, GWLP_WNDPROC
,
1828 (LONG_PTR
)desktop_wndproc_wrapper
);
1830 /* create the cursor clipping window */
1831 attr
.override_redirect
= TRUE
;
1832 attr
.event_mask
= StructureNotifyMask
| FocusChangeMask
;
1833 data
->clip_window
= XCreateWindow( data
->display
, root_window
, 0, 0, 1, 1, 0, 0,
1834 InputOnly
, default_visual
.visual
,
1835 CWOverrideRedirect
| CWEventMask
, &attr
);
1836 XFlush( data
->display
);
1837 SetPropA( hwnd
, clip_window_prop
, (HANDLE
)data
->clip_window
);
1838 X11DRV_InitClipboard();
1839 X11DRV_DisplayDevices_RegisterEventHandlers();
1845 /***********************************************************************
1848 * Lock and return the X11 data structure associated with a window.
1850 struct x11drv_win_data
*get_win_data( HWND hwnd
)
1854 if (!hwnd
) return NULL
;
1855 EnterCriticalSection( &win_data_section
);
1856 if (!XFindContext( gdi_display
, (XID
)hwnd
, win_data_context
, &data
))
1857 return (struct x11drv_win_data
*)data
;
1858 LeaveCriticalSection( &win_data_section
);
1863 /***********************************************************************
1866 * Release the data returned by get_win_data.
1868 void release_win_data( struct x11drv_win_data
*data
)
1870 if (data
) LeaveCriticalSection( &win_data_section
);
1874 /***********************************************************************
1875 * X11DRV_create_win_data
1877 * Create an X11 data window structure for an existing window.
1879 static struct x11drv_win_data
*X11DRV_create_win_data( HWND hwnd
, const RECT
*window_rect
,
1880 const RECT
*client_rect
)
1883 struct x11drv_win_data
*data
;
1886 if (!(parent
= GetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop */
1888 /* don't create win data for HWND_MESSAGE windows */
1889 if (parent
!= GetDesktopWindow() && !GetAncestor( parent
, GA_PARENT
)) return NULL
;
1891 if (GetWindowThreadProcessId( hwnd
, NULL
) != GetCurrentThreadId()) return NULL
;
1893 /* Recreate the parent gl_drawable now that we know there are child windows
1894 * that will need clipping support.
1896 sync_gl_drawable( parent
, TRUE
);
1898 display
= thread_init_display();
1899 init_clip_window(); /* make sure the clip window is initialized in this thread */
1901 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1903 data
->whole_rect
= data
->window_rect
= *window_rect
;
1904 data
->client_rect
= *client_rect
;
1905 if (parent
== GetDesktopWindow())
1907 create_whole_window( data
);
1908 TRACE( "win %p/%lx window %s whole %s client %s\n",
1909 hwnd
, data
->whole_window
, wine_dbgstr_rect( &data
->window_rect
),
1910 wine_dbgstr_rect( &data
->whole_rect
), wine_dbgstr_rect( &data
->client_rect
));
1916 /* window procedure for foreign windows */
1917 static LRESULT WINAPI
foreign_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1921 case WM_WINDOWPOSCHANGED
:
1922 update_systray_balloon_position();
1924 case WM_PARENTNOTIFY
:
1925 if (LOWORD(wparam
) == WM_DESTROY
)
1927 TRACE( "%p: got parent notify destroy for win %lx\n", hwnd
, lparam
);
1928 PostMessageW( hwnd
, WM_CLOSE
, 0, 0 ); /* so that we come back here once the child is gone */
1932 if (GetWindow( hwnd
, GW_CHILD
)) return 0; /* refuse to die if we still have children */
1935 return DefWindowProcW( hwnd
, msg
, wparam
, lparam
);
1939 /***********************************************************************
1940 * create_foreign_window
1942 * Create a foreign window for the specified X window and its ancestors
1944 HWND
create_foreign_window( Display
*display
, Window xwin
)
1946 static const WCHAR classW
[] = {'_','_','w','i','n','e','_','x','1','1','_','f','o','r','e','i','g','n','_','w','i','n','d','o','w',0};
1947 static BOOL class_registered
;
1948 struct x11drv_win_data
*data
;
1951 Window xparent
, xroot
;
1953 unsigned int nchildren
;
1954 XWindowAttributes attr
;
1955 DWORD style
= WS_CLIPCHILDREN
;
1957 if (!class_registered
)
1961 memset( &class, 0, sizeof(class) );
1962 class.cbSize
= sizeof(class);
1963 class.lpfnWndProc
= foreign_window_proc
;
1964 class.lpszClassName
= classW
;
1965 if (!RegisterClassExW( &class ) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS
)
1967 ERR( "Could not register foreign window class\n" );
1970 class_registered
= TRUE
;
1973 if (XFindContext( display
, xwin
, winContext
, (char **)&hwnd
)) hwnd
= 0;
1974 if (hwnd
) return hwnd
; /* already created */
1976 XSelectInput( display
, xwin
, StructureNotifyMask
);
1977 if (!XGetWindowAttributes( display
, xwin
, &attr
) ||
1978 !XQueryTree( display
, xwin
, &xroot
, &xparent
, &xchildren
, &nchildren
))
1980 XSelectInput( display
, xwin
, 0 );
1985 if (xparent
== xroot
)
1987 parent
= GetDesktopWindow();
1989 pos
= root_to_virtual_screen( attr
.x
, attr
.y
);
1993 parent
= create_foreign_window( display
, xparent
);
1999 hwnd
= CreateWindowW( classW
, NULL
, style
, pos
.x
, pos
.y
, attr
.width
, attr
.height
,
2000 parent
, 0, 0, NULL
);
2002 if (!(data
= alloc_win_data( display
, hwnd
)))
2004 DestroyWindow( hwnd
);
2007 SetRect( &data
->window_rect
, pos
.x
, pos
.y
, pos
.x
+ attr
.width
, pos
.y
+ attr
.height
);
2008 data
->whole_rect
= data
->client_rect
= data
->window_rect
;
2009 data
->whole_window
= data
->client_window
= 0;
2010 data
->embedded
= TRUE
;
2011 data
->mapped
= TRUE
;
2013 SetPropA( hwnd
, foreign_window_prop
, (HANDLE
)xwin
);
2014 XSaveContext( display
, xwin
, winContext
, (char *)data
->hwnd
);
2016 TRACE( "win %lx parent %p style %08x %s -> hwnd %p\n",
2017 xwin
, parent
, style
, wine_dbgstr_rect(&data
->window_rect
), hwnd
);
2019 release_win_data( data
);
2021 ShowWindow( hwnd
, SW_SHOW
);
2026 /***********************************************************************
2027 * X11DRV_get_whole_window
2029 * Return the X window associated with the full area of a window
2031 Window
X11DRV_get_whole_window( HWND hwnd
)
2033 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2038 if (hwnd
== GetDesktopWindow()) return root_window
;
2039 return (Window
)GetPropA( hwnd
, whole_window_prop
);
2041 ret
= data
->whole_window
;
2042 release_win_data( data
);
2047 /***********************************************************************
2050 * Return the X input context associated with a window
2052 XIC
X11DRV_get_ic( HWND hwnd
)
2054 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2060 x11drv_thread_data()->last_xic_hwnd
= hwnd
;
2062 if (!ret
&& (xim
= x11drv_thread_data()->xim
)) ret
= X11DRV_CreateIC( xim
, data
);
2063 release_win_data( data
);
2069 /***********************************************************************
2070 * X11DRV_GetDC (X11DRV.@)
2072 void CDECL
X11DRV_GetDC( HDC hdc
, HWND hwnd
, HWND top
, const RECT
*win_rect
,
2073 const RECT
*top_rect
, DWORD flags
)
2075 struct x11drv_escape_set_drawable escape
;
2078 escape
.code
= X11DRV_SET_DRAWABLE
;
2079 escape
.mode
= IncludeInferiors
;
2081 escape
.dc_rect
.left
= win_rect
->left
- top_rect
->left
;
2082 escape
.dc_rect
.top
= win_rect
->top
- top_rect
->top
;
2083 escape
.dc_rect
.right
= win_rect
->right
- top_rect
->left
;
2084 escape
.dc_rect
.bottom
= win_rect
->bottom
- top_rect
->top
;
2088 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2090 escape
.drawable
= data
? data
->whole_window
: X11DRV_get_whole_window( hwnd
);
2092 /* special case: when repainting the root window, clip out top-level windows */
2093 if (data
&& data
->whole_window
== root_window
) escape
.mode
= ClipByChildren
;
2094 release_win_data( data
);
2098 /* find the first ancestor that has a drawable */
2099 for (parent
= hwnd
; parent
&& parent
!= top
; parent
= GetAncestor( parent
, GA_PARENT
))
2100 if ((escape
.drawable
= X11DRV_get_whole_window( parent
))) break;
2102 if (escape
.drawable
)
2104 POINT pt
= { 0, 0 };
2105 MapWindowPoints( 0, parent
, &pt
, 1 );
2106 escape
.dc_rect
= *win_rect
;
2107 OffsetRect( &escape
.dc_rect
, pt
.x
, pt
.y
);
2108 if (flags
& DCX_CLIPCHILDREN
) escape
.mode
= ClipByChildren
;
2110 else escape
.drawable
= X11DRV_get_whole_window( top
);
2113 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2117 /***********************************************************************
2118 * X11DRV_ReleaseDC (X11DRV.@)
2120 void CDECL
X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
2122 struct x11drv_escape_set_drawable escape
;
2124 escape
.code
= X11DRV_SET_DRAWABLE
;
2125 escape
.drawable
= root_window
;
2126 escape
.mode
= IncludeInferiors
;
2127 escape
.dc_rect
= get_virtual_screen_rect();
2128 OffsetRect( &escape
.dc_rect
, -2 * escape
.dc_rect
.left
, -2 * escape
.dc_rect
.top
);
2129 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2133 /*************************************************************************
2134 * ScrollDC (X11DRV.@)
2136 BOOL CDECL
X11DRV_ScrollDC( HDC hdc
, INT dx
, INT dy
, HRGN update
)
2140 HRGN expose_rgn
= 0;
2142 GetClipBox( hdc
, &rect
);
2146 INT code
= X11DRV_START_EXPOSURES
;
2147 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2149 ret
= BitBlt( hdc
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2150 hdc
, rect
.left
- dx
, rect
.top
- dy
, SRCCOPY
);
2152 code
= X11DRV_END_EXPOSURES
;
2153 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
,
2154 sizeof(expose_rgn
), (LPSTR
)&expose_rgn
);
2157 CombineRgn( update
, update
, expose_rgn
, RGN_OR
);
2158 DeleteObject( expose_rgn
);
2161 else ret
= BitBlt( hdc
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2162 hdc
, rect
.left
- dx
, rect
.top
- dy
, SRCCOPY
);
2168 /***********************************************************************
2169 * SetCapture (X11DRV.@)
2171 void CDECL
X11DRV_SetCapture( HWND hwnd
, UINT flags
)
2173 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2174 struct x11drv_win_data
*data
;
2176 if (!(flags
& (GUI_INMOVESIZE
| GUI_INMENUMODE
))) return;
2180 if (!(data
= get_win_data( GetAncestor( hwnd
, GA_ROOT
)))) return;
2181 if (data
->whole_window
)
2183 XFlush( gdi_display
);
2184 XGrabPointer( data
->display
, data
->whole_window
, False
,
2185 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
2186 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
);
2187 thread_data
->grab_hwnd
= data
->hwnd
;
2189 release_win_data( data
);
2191 else /* release capture */
2193 if (!(data
= get_win_data( thread_data
->grab_hwnd
))) return;
2194 XFlush( gdi_display
);
2195 XUngrabPointer( data
->display
, CurrentTime
);
2196 XFlush( data
->display
);
2197 thread_data
->grab_hwnd
= NULL
;
2198 release_win_data( data
);
2203 /*****************************************************************
2204 * SetParent (X11DRV.@)
2206 void CDECL
X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
2208 struct x11drv_win_data
*data
;
2210 if (parent
== old_parent
) return;
2211 if (!(data
= get_win_data( hwnd
))) return;
2212 if (data
->embedded
) goto done
;
2214 if (parent
!= GetDesktopWindow()) /* a child window */
2216 if (old_parent
== GetDesktopWindow())
2218 /* destroy the old X windows */
2219 destroy_whole_window( data
, FALSE
);
2220 data
->managed
= FALSE
;
2223 else /* new top level window */
2225 create_whole_window( data
);
2228 release_win_data( data
);
2229 set_gl_drawable_parent( hwnd
, parent
);
2231 /* Recreate the parent gl_drawable now that we know there are child windows
2232 * that will need clipping support.
2234 sync_gl_drawable( parent
, TRUE
);
2236 fetch_icon_data( hwnd
, 0, 0 );
2240 static inline BOOL
get_surface_rect( const RECT
*visible_rect
, RECT
*surface_rect
)
2242 *surface_rect
= get_virtual_screen_rect();
2244 if (!IntersectRect( surface_rect
, surface_rect
, visible_rect
)) return FALSE
;
2245 OffsetRect( surface_rect
, -visible_rect
->left
, -visible_rect
->top
);
2246 surface_rect
->left
&= ~31;
2247 surface_rect
->top
&= ~31;
2248 surface_rect
->right
= max( surface_rect
->left
+ 32, (surface_rect
->right
+ 31) & ~31 );
2249 surface_rect
->bottom
= max( surface_rect
->top
+ 32, (surface_rect
->bottom
+ 31) & ~31 );
2254 /***********************************************************************
2255 * WindowPosChanging (X11DRV.@)
2257 void CDECL
X11DRV_WindowPosChanging( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
2258 const RECT
*window_rect
, const RECT
*client_rect
, RECT
*visible_rect
,
2259 struct window_surface
**surface
)
2261 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2265 BOOL layered
= GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYERED
;
2267 if (!data
&& !(data
= X11DRV_create_win_data( hwnd
, window_rect
, client_rect
))) return;
2269 /* check if we need to switch the window to managed */
2270 if (!data
->managed
&& data
->whole_window
&& is_window_managed( hwnd
, swp_flags
, window_rect
))
2272 TRACE( "making win %p/%lx managed\n", hwnd
, data
->whole_window
);
2273 release_win_data( data
);
2274 unmap_window( hwnd
);
2275 if (!(data
= get_win_data( hwnd
))) return;
2276 data
->managed
= TRUE
;
2279 *visible_rect
= *window_rect
;
2280 X11DRV_window_to_X_rect( data
, visible_rect
, window_rect
, client_rect
);
2282 /* create the window surface if necessary */
2284 if (!data
->whole_window
&& !data
->embedded
) goto done
;
2285 if (swp_flags
& SWP_HIDEWINDOW
) goto done
;
2286 if (data
->use_alpha
) goto done
;
2287 if (!get_surface_rect( visible_rect
, &surface_rect
)) goto done
;
2289 if (*surface
) window_surface_release( *surface
);
2290 *surface
= NULL
; /* indicate that we want to draw directly to the window */
2292 if (data
->embedded
) goto done
;
2293 if (data
->whole_window
== root_window
) goto done
;
2294 if (data
->client_window
) goto done
;
2295 if (!client_side_graphics
&& !layered
) goto done
;
2299 if (EqualRect( &data
->surface
->rect
, &surface_rect
))
2301 /* existing surface is good enough */
2302 window_surface_add_ref( data
->surface
);
2303 *surface
= data
->surface
;
2307 else if (!(swp_flags
& SWP_SHOWWINDOW
) && !(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)) goto done
;
2309 if (!layered
|| !GetLayeredWindowAttributes( hwnd
, &key
, NULL
, &flags
) || !(flags
& LWA_COLORKEY
))
2312 *surface
= create_surface( data
->whole_window
, &data
->vis
, &surface_rect
, key
, FALSE
);
2315 release_win_data( data
);
2319 /***********************************************************************
2320 * WindowPosChanged (X11DRV.@)
2322 void CDECL
X11DRV_WindowPosChanged( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
2323 const RECT
*rectWindow
, const RECT
*rectClient
,
2324 const RECT
*visible_rect
, const RECT
*valid_rects
,
2325 struct window_surface
*surface
)
2327 struct x11drv_thread_data
*thread_data
;
2328 struct x11drv_win_data
*data
;
2329 DWORD new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2330 RECT old_window_rect
, old_whole_rect
, old_client_rect
;
2333 if (!(data
= get_win_data( hwnd
))) return;
2335 thread_data
= x11drv_thread_data();
2337 old_window_rect
= data
->window_rect
;
2338 old_whole_rect
= data
->whole_rect
;
2339 old_client_rect
= data
->client_rect
;
2340 data
->window_rect
= *rectWindow
;
2341 data
->whole_rect
= *visible_rect
;
2342 data
->client_rect
= *rectClient
;
2343 if (data
->vis
.visualid
== default_visual
.visualid
)
2345 if (surface
) window_surface_add_ref( surface
);
2346 if (data
->surface
) window_surface_release( data
->surface
);
2347 data
->surface
= surface
;
2350 TRACE( "win %p window %s client %s style %08x flags %08x\n",
2351 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
, swp_flags
);
2353 if (!IsRectEmpty( &valid_rects
[0] ))
2355 Window window
= data
->whole_window
;
2356 int x_offset
= old_whole_rect
.left
- data
->whole_rect
.left
;
2357 int y_offset
= old_whole_rect
.top
- data
->whole_rect
.top
;
2359 /* if all that happened is that the whole window moved, copy everything */
2360 if (!(swp_flags
& SWP_FRAMECHANGED
) &&
2361 old_whole_rect
.right
- data
->whole_rect
.right
== x_offset
&&
2362 old_whole_rect
.bottom
- data
->whole_rect
.bottom
== y_offset
&&
2363 old_client_rect
.left
- data
->client_rect
.left
== x_offset
&&
2364 old_client_rect
.right
- data
->client_rect
.right
== x_offset
&&
2365 old_client_rect
.top
- data
->client_rect
.top
== y_offset
&&
2366 old_client_rect
.bottom
- data
->client_rect
.bottom
== y_offset
&&
2367 EqualRect( &valid_rects
[0], &data
->client_rect
))
2369 /* if we have an X window the bits will be moved by the X server */
2370 if (!window
&& (x_offset
!= 0 || y_offset
!= 0))
2372 release_win_data( data
);
2373 move_window_bits( hwnd
, window
, &old_whole_rect
, visible_rect
,
2374 &old_client_rect
, rectClient
, rectWindow
);
2375 if (!(data
= get_win_data( hwnd
))) return;
2380 release_win_data( data
);
2381 move_window_bits( hwnd
, window
, &valid_rects
[1], &valid_rects
[0],
2382 &old_client_rect
, rectClient
, rectWindow
);
2383 if (!(data
= get_win_data( hwnd
))) return;
2387 XFlush( gdi_display
); /* make sure painting is done before we move the window */
2389 sync_client_position( data
, &old_client_rect
, &old_whole_rect
);
2391 if (!data
->whole_window
)
2393 BOOL needs_resize
= (!data
->client_window
&&
2394 (data
->client_rect
.right
- data
->client_rect
.left
!=
2395 old_client_rect
.right
- old_client_rect
.left
||
2396 data
->client_rect
.bottom
- data
->client_rect
.top
!=
2397 old_client_rect
.bottom
- old_client_rect
.top
));
2398 release_win_data( data
);
2399 if (needs_resize
) sync_gl_drawable( hwnd
, FALSE
);
2403 /* check if we are currently processing an event relevant to this window */
2406 thread_data
->current_event
&&
2407 thread_data
->current_event
->xany
.window
== data
->whole_window
)
2409 event_type
= thread_data
->current_event
->type
;
2410 if (event_type
!= ConfigureNotify
&& event_type
!= PropertyNotify
&&
2411 event_type
!= GravityNotify
&& event_type
!= ReparentNotify
)
2412 event_type
= 0; /* ignore other events */
2415 if (data
->mapped
&& event_type
!= ReparentNotify
)
2417 if (((swp_flags
& SWP_HIDEWINDOW
) && !(new_style
& WS_VISIBLE
)) ||
2418 (!event_type
&& !(new_style
& WS_MINIMIZE
) &&
2419 !is_window_rect_mapped( rectWindow
) && is_window_rect_mapped( &old_window_rect
)))
2421 release_win_data( data
);
2422 unmap_window( hwnd
);
2423 if (is_window_rect_fullscreen( &old_window_rect
)) reset_clipping_window();
2424 if (!(data
= get_win_data( hwnd
))) return;
2428 /* don't change position if we are about to minimize or maximize a managed window */
2430 !(data
->managed
&& (swp_flags
& SWP_STATECHANGED
) && (new_style
& (WS_MINIMIZE
|WS_MAXIMIZE
))))
2431 sync_window_position( data
, swp_flags
, &old_window_rect
, &old_whole_rect
, &old_client_rect
);
2433 if ((new_style
& WS_VISIBLE
) &&
2434 ((new_style
& WS_MINIMIZE
) || is_window_rect_mapped( rectWindow
)))
2438 BOOL needs_icon
= !data
->icon_pixmap
;
2439 BOOL needs_map
= TRUE
;
2441 /* layered windows are mapped only once their attributes are set */
2442 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYERED
) needs_map
= data
->layered
;
2443 release_win_data( data
);
2444 if (needs_icon
) fetch_icon_data( hwnd
, 0, 0 );
2445 if (needs_map
) map_window( hwnd
, new_style
);
2448 else if ((swp_flags
& SWP_STATECHANGED
) && (!data
->iconic
!= !(new_style
& WS_MINIMIZE
)))
2450 set_wm_hints( data
);
2451 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
2452 TRACE( "changing win %p iconic state to %u\n", data
->hwnd
, data
->iconic
);
2454 XIconifyWindow( data
->display
, data
->whole_window
, data
->vis
.screen
);
2455 else if (is_window_rect_mapped( rectWindow
))
2456 XMapWindow( data
->display
, data
->whole_window
);
2457 update_net_wm_states( data
);
2461 if (swp_flags
& (SWP_FRAMECHANGED
|SWP_STATECHANGED
)) set_wm_hints( data
);
2462 if (!event_type
) update_net_wm_states( data
);
2466 XFlush( data
->display
); /* make sure changes are done before we start painting again */
2467 if (data
->surface
&& data
->vis
.visualid
!= default_visual
.visualid
)
2468 data
->surface
->funcs
->flush( data
->surface
);
2470 release_win_data( data
);
2473 /* check if the window icon should be hidden (i.e. moved off-screen) */
2474 static BOOL
hide_icon( struct x11drv_win_data
*data
)
2476 static const WCHAR trayW
[] = {'S','h','e','l','l','_','T','r','a','y','W','n','d',0};
2478 if (data
->managed
) return TRUE
;
2479 /* hide icons in desktop mode when the taskbar is active */
2480 if (!is_virtual_desktop()) return FALSE
;
2481 return IsWindowVisible( FindWindowW( trayW
, NULL
));
2484 /***********************************************************************
2485 * ShowWindow (X11DRV.@)
2487 UINT CDECL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
, RECT
*rect
, UINT swp
)
2490 unsigned int width
, height
, border
, depth
;
2493 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2494 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2495 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2497 if (!data
|| !data
->whole_window
) goto done
;
2498 if (IsRectEmpty( rect
)) goto done
;
2499 if (style
& WS_MINIMIZE
)
2501 if (((rect
->left
!= -32000 || rect
->top
!= -32000)) && hide_icon( data
))
2503 OffsetRect( rect
, -32000 - rect
->left
, -32000 - rect
->top
);
2504 swp
&= ~(SWP_NOMOVE
| SWP_NOCLIENTMOVE
);
2508 if (!data
->managed
|| !data
->mapped
|| data
->iconic
) goto done
;
2510 /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */
2512 if (!thread_data
->current_event
|| thread_data
->current_event
->xany
.window
!= data
->whole_window
)
2515 if (thread_data
->current_event
->type
!= ConfigureNotify
&&
2516 thread_data
->current_event
->type
!= PropertyNotify
)
2519 TRACE( "win %p/%lx cmd %d at %s flags %08x\n",
2520 hwnd
, data
->whole_window
, cmd
, wine_dbgstr_rect(rect
), swp
);
2522 XGetGeometry( thread_data
->display
, data
->whole_window
,
2523 &root
, &x
, &y
, &width
, &height
, &border
, &depth
);
2524 XTranslateCoordinates( thread_data
->display
, data
->whole_window
, root
, 0, 0, &x
, &y
, &top
);
2525 pos
= root_to_virtual_screen( x
, y
);
2526 X11DRV_X_to_window_rect( data
, rect
, pos
.x
, pos
.y
, width
, height
);
2527 swp
&= ~(SWP_NOMOVE
| SWP_NOCLIENTMOVE
| SWP_NOSIZE
| SWP_NOCLIENTSIZE
);
2530 release_win_data( data
);
2535 /**********************************************************************
2536 * SetWindowIcon (X11DRV.@)
2538 * hIcon or hIconSm has changed (or is being initialised for the
2539 * first time). Complete the X11 driver-specific initialisation
2540 * and set the window hints.
2542 void CDECL
X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
2544 struct x11drv_win_data
*data
;
2546 if (!(data
= get_win_data( hwnd
))) return;
2547 if (!data
->whole_window
) goto done
;
2548 release_win_data( data
); /* release the lock, fetching the icon requires sending messages */
2550 if (type
== ICON_BIG
) fetch_icon_data( hwnd
, icon
, 0 );
2551 else fetch_icon_data( hwnd
, 0, icon
);
2553 if (!(data
= get_win_data( hwnd
))) return;
2554 set_wm_hints( data
);
2556 release_win_data( data
);
2560 /***********************************************************************
2561 * SetWindowRgn (X11DRV.@)
2563 * Assign specified region to window (for non-rectangular windows)
2565 void CDECL
X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
2567 struct x11drv_win_data
*data
;
2569 if ((data
= get_win_data( hwnd
)))
2571 sync_window_region( data
, hrgn
);
2572 release_win_data( data
);
2574 else if (X11DRV_get_whole_window( hwnd
))
2576 SendMessageW( hwnd
, WM_X11DRV_SET_WIN_REGION
, 0, 0 );
2581 /***********************************************************************
2582 * SetLayeredWindowAttributes (X11DRV.@)
2584 * Set transparency attributes for a layered window.
2586 void CDECL
X11DRV_SetLayeredWindowAttributes( HWND hwnd
, COLORREF key
, BYTE alpha
, DWORD flags
)
2588 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2592 set_window_visual( data
, &default_visual
, FALSE
);
2594 if (data
->whole_window
)
2595 sync_window_opacity( data
->display
, data
->whole_window
, key
, alpha
, flags
);
2597 set_surface_color_key( data
->surface
, (flags
& LWA_COLORKEY
) ? key
: CLR_INVALID
);
2599 data
->layered
= TRUE
;
2600 if (!data
->mapped
) /* mapping is delayed until attributes are set */
2602 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
2604 if ((style
& WS_VISIBLE
) &&
2605 ((style
& WS_MINIMIZE
) || is_window_rect_mapped( &data
->window_rect
)))
2607 release_win_data( data
);
2608 map_window( hwnd
, style
);
2612 release_win_data( data
);
2616 Window win
= X11DRV_get_whole_window( hwnd
);
2619 sync_window_opacity( gdi_display
, win
, key
, alpha
, flags
);
2620 if (flags
& LWA_COLORKEY
)
2621 FIXME( "LWA_COLORKEY not supported on foreign process window %p\n", hwnd
);
2627 /*****************************************************************************
2628 * UpdateLayeredWindow (X11DRV.@)
2630 BOOL CDECL
X11DRV_UpdateLayeredWindow( HWND hwnd
, const UPDATELAYEREDWINDOWINFO
*info
,
2631 const RECT
*window_rect
)
2633 struct window_surface
*surface
;
2634 struct x11drv_win_data
*data
;
2635 BLENDFUNCTION blend
= { AC_SRC_OVER
, 0, 255, 0 };
2636 COLORREF color_key
= (info
->dwFlags
& ULW_COLORKEY
) ? info
->crKey
: CLR_INVALID
;
2637 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
2638 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
2639 void *src_bits
, *dst_bits
;
2640 RECT rect
, src_rect
;
2645 if (!(data
= get_win_data( hwnd
))) return FALSE
;
2647 data
->layered
= TRUE
;
2648 if (!data
->embedded
&& argb_visual
.visualid
) set_window_visual( data
, &argb_visual
, TRUE
);
2650 rect
= *window_rect
;
2651 OffsetRect( &rect
, -window_rect
->left
, -window_rect
->top
);
2653 surface
= data
->surface
;
2654 if (!surface
|| !EqualRect( &surface
->rect
, &rect
))
2656 data
->surface
= create_surface( data
->whole_window
, &data
->vis
, &rect
,
2657 color_key
, data
->use_alpha
);
2658 if (surface
) window_surface_release( surface
);
2659 surface
= data
->surface
;
2661 else set_surface_color_key( surface
, color_key
);
2663 if (surface
) window_surface_add_ref( surface
);
2664 release_win_data( data
);
2666 if (!surface
) return FALSE
;
2669 window_surface_release( surface
);
2673 dst_bits
= surface
->funcs
->get_info( surface
, bmi
);
2675 if (!(dib
= CreateDIBSection( info
->hdcDst
, bmi
, DIB_RGB_COLORS
, &src_bits
, NULL
, 0 ))) goto done
;
2676 if (!(hdc
= CreateCompatibleDC( 0 ))) goto done
;
2678 SelectObject( hdc
, dib
);
2680 surface
->funcs
->lock( surface
);
2684 IntersectRect( &rect
, &rect
, info
->prcDirty
);
2685 memcpy( src_bits
, dst_bits
, bmi
->bmiHeader
.biSizeImage
);
2686 PatBlt( hdc
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, BLACKNESS
);
2689 if (info
->pptSrc
) OffsetRect( &src_rect
, info
->pptSrc
->x
, info
->pptSrc
->y
);
2690 DPtoLP( info
->hdcSrc
, (POINT
*)&src_rect
, 2 );
2692 ret
= GdiAlphaBlend( hdc
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2693 info
->hdcSrc
, src_rect
.left
, src_rect
.top
,
2694 src_rect
.right
- src_rect
.left
, src_rect
.bottom
- src_rect
.top
,
2695 (info
->dwFlags
& ULW_ALPHA
) ? *info
->pblend
: blend
);
2698 memcpy( dst_bits
, src_bits
, bmi
->bmiHeader
.biSizeImage
);
2699 add_bounds_rect( surface
->funcs
->get_bounds( surface
), &rect
);
2702 surface
->funcs
->unlock( surface
);
2703 surface
->funcs
->flush( surface
);
2706 window_surface_release( surface
);
2707 if (hdc
) DeleteDC( hdc
);
2708 if (dib
) DeleteObject( dib
);
2713 /**********************************************************************
2714 * X11DRV_WindowMessage (X11DRV.@)
2716 LRESULT CDECL
X11DRV_WindowMessage( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2718 struct x11drv_win_data
*data
;
2722 case WM_X11DRV_UPDATE_CLIPBOARD
:
2723 return update_clipboard( hwnd
);
2724 case WM_X11DRV_SET_WIN_REGION
:
2725 if ((data
= get_win_data( hwnd
)))
2727 sync_window_region( data
, (HRGN
)1 );
2728 release_win_data( data
);
2731 case WM_X11DRV_RESIZE_DESKTOP
:
2732 X11DRV_resize_desktop( (BOOL
)lp
);
2734 case WM_X11DRV_SET_CURSOR
:
2735 if ((data
= get_win_data( hwnd
)))
2737 Window win
= data
->whole_window
;
2738 release_win_data( data
);
2739 if (win
) set_window_cursor( win
, (HCURSOR
)lp
);
2741 else if (hwnd
== x11drv_thread_data()->clip_hwnd
)
2742 set_window_cursor( x11drv_thread_data()->clip_window
, (HCURSOR
)lp
);
2744 case WM_X11DRV_CLIP_CURSOR
:
2745 return clip_cursor_notify( hwnd
, (HWND
)wp
, (HWND
)lp
);
2747 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg
, hwnd
, wp
, lp
);
2753 /***********************************************************************
2754 * is_netwm_supported
2756 static BOOL
is_netwm_supported( Display
*display
, Atom atom
)
2758 static Atom
*net_supported
;
2759 static int net_supported_count
= -1;
2762 if (net_supported_count
== -1)
2766 unsigned long count
, remaining
;
2768 if (!XGetWindowProperty( display
, DefaultRootWindow(display
), x11drv_atom(_NET_SUPPORTED
), 0,
2769 ~0UL, False
, XA_ATOM
, &type
, &format
, &count
,
2770 &remaining
, (unsigned char **)&net_supported
))
2771 net_supported_count
= get_property_size( format
, count
) / sizeof(Atom
);
2773 net_supported_count
= 0;
2776 for (i
= 0; i
< net_supported_count
; i
++)
2777 if (net_supported
[i
] == atom
) return TRUE
;
2782 /***********************************************************************
2785 static LRESULT
start_screensaver(void)
2787 if (!is_virtual_desktop())
2789 const char *argv
[3] = { "xdg-screensaver", "activate", NULL
};
2790 int pid
= _spawnvp( _P_DETACH
, argv
[0], argv
);
2793 TRACE( "started process %d\n", pid
);
2801 /***********************************************************************
2802 * SysCommand (X11DRV.@)
2804 * Perform WM_SYSCOMMAND handling.
2806 LRESULT CDECL
X11DRV_SysCommand( HWND hwnd
, WPARAM wparam
, LPARAM lparam
)
2808 WPARAM hittest
= wparam
& 0x0f;
2810 struct x11drv_win_data
*data
;
2812 if (!(data
= get_win_data( hwnd
)))
2814 if (wparam
== SC_SCREENSAVE
&& hwnd
== GetDesktopWindow()) return start_screensaver();
2817 if (!data
->whole_window
|| !data
->managed
|| !data
->mapped
) goto failed
;
2819 switch (wparam
& 0xfff0)
2822 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
2823 else dir
= _NET_WM_MOVERESIZE_MOVE
;
2826 /* windows without WS_THICKFRAME are not resizable through the window manager */
2827 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_THICKFRAME
)) goto failed
;
2831 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
2832 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
2833 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
2834 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
2835 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
2836 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
2837 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
2838 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
2839 default: dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
; break;
2844 /* prevent a simple ALT press+release from activating the system menu,
2845 * as that can get confusing on managed windows */
2846 if ((WCHAR
)lparam
) goto failed
; /* got an explicit char */
2847 if (GetMenu( hwnd
)) goto failed
; /* window has a real menu */
2848 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_SYSMENU
)) goto failed
; /* no system menu */
2849 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam
, lparam
);
2850 release_win_data( data
);
2857 if (IsZoomed(hwnd
)) goto failed
;
2859 if (!is_netwm_supported( data
->display
, x11drv_atom(_NET_WM_MOVERESIZE
) ))
2861 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
2865 release_win_data( data
);
2866 move_resize_window( hwnd
, dir
);
2870 release_win_data( data
);
2874 void CDECL
X11DRV_FlashWindowEx( PFLASHWINFO pfinfo
)
2876 struct x11drv_win_data
*data
= get_win_data( pfinfo
->hwnd
);
2884 xev
.type
= ClientMessage
;
2885 xev
.xclient
.window
= data
->whole_window
;
2886 xev
.xclient
.message_type
= x11drv_atom( _NET_WM_STATE
);
2887 xev
.xclient
.serial
= 0;
2888 xev
.xclient
.display
= data
->display
;
2889 xev
.xclient
.send_event
= True
;
2890 xev
.xclient
.format
= 32;
2891 xev
.xclient
.data
.l
[0] = pfinfo
->dwFlags
? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
2892 xev
.xclient
.data
.l
[1] = x11drv_atom( _NET_WM_STATE_DEMANDS_ATTENTION
);
2893 xev
.xclient
.data
.l
[2] = 0;
2894 xev
.xclient
.data
.l
[3] = 1;
2895 xev
.xclient
.data
.l
[4] = 0;
2897 XSendEvent( data
->display
, DefaultRootWindow( data
->display
), False
,
2898 SubstructureNotifyMask
, &xev
);
2900 release_win_data( data
);