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
)
285 unsigned long ret
= 0;
287 if (!decorated_mode
) return 0;
289 if (IsRectEmpty( &data
->window_rect
)) return 0;
290 if (data
->shaped
) return 0;
292 if (ex_style
& WS_EX_TOOLWINDOW
) return 0;
293 if (ex_style
& WS_EX_LAYERED
) return 0;
295 if ((style
& WS_CAPTION
) == WS_CAPTION
)
297 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
298 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
299 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
300 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
302 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
303 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
304 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
309 /***********************************************************************
310 * get_window_attributes
312 * Fill the window attributes structure for an X window.
314 static int get_window_attributes( struct x11drv_win_data
*data
, XSetWindowAttributes
*attr
)
316 attr
->override_redirect
= !data
->managed
;
317 attr
->colormap
= data
->colormap
? data
->colormap
: default_colormap
;
318 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
319 attr
->bit_gravity
= NorthWestGravity
;
320 attr
->backing_store
= NotUseful
;
321 attr
->border_pixel
= 0;
322 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
323 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
324 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
|
325 KeymapStateMask
| StructureNotifyMask
);
326 if (data
->managed
) attr
->event_mask
|= PropertyChangeMask
;
328 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
| CWBorderPixel
|
329 CWEventMask
| CWBitGravity
| CWBackingStore
);
333 /***********************************************************************
336 * Change the X window attributes when the window style has changed.
338 static void sync_window_style( struct x11drv_win_data
*data
)
340 if (data
->whole_window
!= root_window
)
342 XSetWindowAttributes attr
;
343 int mask
= get_window_attributes( data
, &attr
);
345 XChangeWindowAttributes( data
->display
, data
->whole_window
, mask
, &attr
);
350 /***********************************************************************
353 * Update the X11 window region.
355 static void sync_window_region( struct x11drv_win_data
*data
, HRGN win_region
)
357 #ifdef HAVE_LIBXSHAPE
358 HRGN hrgn
= win_region
;
360 if (!data
->whole_window
) return;
361 data
->shaped
= FALSE
;
363 if (IsRectEmpty( &data
->window_rect
)) /* set an empty shape */
365 static XRectangle empty_rect
;
366 XShapeCombineRectangles( data
->display
, data
->whole_window
, ShapeBounding
, 0, 0,
367 &empty_rect
, 1, ShapeSet
, YXBanded
);
371 if (hrgn
== (HRGN
)1) /* hack: win_region == 1 means retrieve region from server */
373 if (!(hrgn
= CreateRectRgn( 0, 0, 0, 0 ))) return;
374 if (GetWindowRgn( data
->hwnd
, hrgn
) == ERROR
)
376 DeleteObject( hrgn
);
383 XShapeCombineMask( data
->display
, data
->whole_window
, ShapeBounding
, 0, 0, None
, ShapeSet
);
387 RGNDATA
*pRegionData
;
389 if (GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) MirrorRgn( data
->hwnd
, hrgn
);
390 if ((pRegionData
= X11DRV_GetRegionData( hrgn
, 0 )))
392 XShapeCombineRectangles( data
->display
, data
->whole_window
, ShapeBounding
,
393 data
->window_rect
.left
- data
->whole_rect
.left
,
394 data
->window_rect
.top
- data
->whole_rect
.top
,
395 (XRectangle
*)pRegionData
->Buffer
,
396 pRegionData
->rdh
.nCount
, ShapeSet
, YXBanded
);
397 HeapFree(GetProcessHeap(), 0, pRegionData
);
401 if (hrgn
&& hrgn
!= win_region
) DeleteObject( hrgn
);
402 #endif /* HAVE_LIBXSHAPE */
406 /***********************************************************************
407 * sync_window_opacity
409 static void sync_window_opacity( Display
*display
, Window win
,
410 COLORREF key
, BYTE alpha
, DWORD flags
)
412 unsigned long opacity
= 0xffffffff;
414 if (flags
& LWA_ALPHA
) opacity
= (0xffffffff / 0xff) * alpha
;
416 if (opacity
== 0xffffffff)
417 XDeleteProperty( display
, win
, x11drv_atom(_NET_WM_WINDOW_OPACITY
) );
419 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_WINDOW_OPACITY
),
420 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&opacity
, 1 );
424 /***********************************************************************
427 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
430 char *buffer
, *utf8_buffer
;
433 /* allocate new buffer for window text */
434 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
435 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
436 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
438 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
439 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
441 HeapFree( GetProcessHeap(), 0, buffer
);
444 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
446 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
448 XSetWMName( display
, win
, &prop
);
449 XSetWMIconName( display
, win
, &prop
);
453 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
454 according to the standard
455 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
457 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
458 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
460 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
461 HeapFree( GetProcessHeap(), 0, buffer
);
465 /***********************************************************************
468 * Return the bitmap bits in ARGB format. Helper for setting icon hints.
470 static unsigned long *get_bitmap_argb( HDC hdc
, HBITMAP color
, HBITMAP mask
, unsigned int *size
)
472 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
473 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
475 unsigned int *ptr
, *bits
= NULL
;
476 unsigned char *mask_bits
= NULL
;
478 BOOL has_alpha
= FALSE
;
480 if (!GetObjectW( color
, sizeof(bm
), &bm
)) return NULL
;
481 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
482 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
483 info
->bmiHeader
.biHeight
= -bm
.bmHeight
;
484 info
->bmiHeader
.biPlanes
= 1;
485 info
->bmiHeader
.biBitCount
= 32;
486 info
->bmiHeader
.biCompression
= BI_RGB
;
487 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* bm
.bmHeight
* 4;
488 info
->bmiHeader
.biXPelsPerMeter
= 0;
489 info
->bmiHeader
.biYPelsPerMeter
= 0;
490 info
->bmiHeader
.biClrUsed
= 0;
491 info
->bmiHeader
.biClrImportant
= 0;
492 *size
= bm
.bmWidth
* bm
.bmHeight
+ 2;
493 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, *size
* sizeof(long) ))) goto failed
;
494 if (!GetDIBits( hdc
, color
, 0, bm
.bmHeight
, bits
+ 2, info
, DIB_RGB_COLORS
)) goto failed
;
496 bits
[0] = bm
.bmWidth
;
497 bits
[1] = bm
.bmHeight
;
499 for (i
= 0; i
< bm
.bmWidth
* bm
.bmHeight
; i
++)
500 if ((has_alpha
= (bits
[i
+ 2] & 0xff000000) != 0)) break;
504 unsigned int width_bytes
= (bm
.bmWidth
+ 31) / 32 * 4;
505 /* generate alpha channel from the mask */
506 info
->bmiHeader
.biBitCount
= 1;
507 info
->bmiHeader
.biSizeImage
= width_bytes
* bm
.bmHeight
;
508 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto failed
;
509 if (!GetDIBits( hdc
, mask
, 0, bm
.bmHeight
, mask_bits
, info
, DIB_RGB_COLORS
)) goto failed
;
511 for (i
= 0; i
< bm
.bmHeight
; i
++)
512 for (j
= 0; j
< bm
.bmWidth
; j
++, ptr
++)
513 if (!((mask_bits
[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80)) *ptr
|= 0xff000000;
514 HeapFree( GetProcessHeap(), 0, mask_bits
);
517 /* convert to array of longs */
518 if (bits
&& sizeof(long) > sizeof(int))
519 for (i
= *size
- 1; i
>= 0; i
--) ((unsigned long *)bits
)[i
] = bits
[i
];
521 return (unsigned long *)bits
;
524 HeapFree( GetProcessHeap(), 0, bits
);
525 HeapFree( GetProcessHeap(), 0, mask_bits
);
530 /***********************************************************************
531 * create_icon_pixmaps
533 static BOOL
create_icon_pixmaps( HDC hdc
, const ICONINFO
*icon
, Pixmap
*icon_ret
, Pixmap
*mask_ret
)
535 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
536 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
537 XVisualInfo vis
= default_visual
;
538 struct gdi_image_bits bits
;
539 Pixmap color_pixmap
= 0, mask_pixmap
= 0;
547 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
548 info
->bmiHeader
.biBitCount
= 0;
549 if (!(lines
= GetDIBits( hdc
, icon
->hbmColor
, 0, 0, NULL
, info
, DIB_RGB_COLORS
))) goto failed
;
550 if (!(bits
.ptr
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto failed
;
551 if (!GetDIBits( hdc
, icon
->hbmColor
, 0, lines
, bits
.ptr
, info
, DIB_RGB_COLORS
)) goto failed
;
553 color_pixmap
= create_pixmap_from_image( hdc
, &vis
, info
, &bits
, DIB_RGB_COLORS
);
554 HeapFree( GetProcessHeap(), 0, bits
.ptr
);
556 if (!color_pixmap
) goto failed
;
558 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
559 info
->bmiHeader
.biBitCount
= 0;
560 if (!(lines
= GetDIBits( hdc
, icon
->hbmMask
, 0, 0, NULL
, info
, DIB_RGB_COLORS
))) goto failed
;
561 if (!(bits
.ptr
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto failed
;
562 if (!GetDIBits( hdc
, icon
->hbmMask
, 0, lines
, bits
.ptr
, info
, DIB_RGB_COLORS
)) goto failed
;
564 /* invert the mask */
565 for (i
= 0; i
< info
->bmiHeader
.biSizeImage
/ sizeof(DWORD
); i
++) ((DWORD
*)bits
.ptr
)[i
] ^= ~0u;
568 mask_pixmap
= create_pixmap_from_image( hdc
, &vis
, info
, &bits
, DIB_RGB_COLORS
);
569 HeapFree( GetProcessHeap(), 0, bits
.ptr
);
571 if (!mask_pixmap
) goto failed
;
573 *icon_ret
= color_pixmap
;
574 *mask_ret
= mask_pixmap
;
578 if (color_pixmap
) XFreePixmap( gdi_display
, color_pixmap
);
579 HeapFree( GetProcessHeap(), 0, bits
.ptr
);
584 /***********************************************************************
587 static void fetch_icon_data( HWND hwnd
, HICON icon_big
, HICON icon_small
)
589 struct x11drv_win_data
*data
;
590 ICONINFO ii
, ii_small
;
594 Pixmap icon_pixmap
, mask_pixmap
;
598 icon_big
= (HICON
)SendMessageW( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
599 if (!icon_big
) icon_big
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
600 if (!icon_big
) icon_big
= LoadIconW( 0, (LPWSTR
)IDI_WINLOGO
);
604 icon_small
= (HICON
)SendMessageW( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
605 if (!icon_small
) icon_small
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICONSM
);
608 if (!GetIconInfo(icon_big
, &ii
)) return;
610 hDC
= CreateCompatibleDC(0);
611 bits
= get_bitmap_argb( hDC
, ii
.hbmColor
, ii
.hbmMask
, &size
);
612 if (bits
&& GetIconInfo( icon_small
, &ii_small
))
614 unsigned int size_small
;
615 unsigned long *bits_small
, *new;
617 if ((bits_small
= get_bitmap_argb( hDC
, ii_small
.hbmColor
, ii_small
.hbmMask
, &size_small
)) &&
618 (bits_small
[0] != bits
[0] || bits_small
[1] != bits
[1])) /* size must be different */
620 if ((new = HeapReAlloc( GetProcessHeap(), 0, bits
,
621 (size
+ size_small
) * sizeof(unsigned long) )))
624 memcpy( bits
+ size
, bits_small
, size_small
* sizeof(unsigned long) );
628 HeapFree( GetProcessHeap(), 0, bits_small
);
629 DeleteObject( ii_small
.hbmColor
);
630 DeleteObject( ii_small
.hbmMask
);
633 if (!create_icon_pixmaps( hDC
, &ii
, &icon_pixmap
, &mask_pixmap
)) icon_pixmap
= mask_pixmap
= 0;
635 DeleteObject( ii
.hbmColor
);
636 DeleteObject( ii
.hbmMask
);
639 if ((data
= get_win_data( hwnd
)))
641 if (data
->icon_pixmap
) XFreePixmap( gdi_display
, data
->icon_pixmap
);
642 if (data
->icon_mask
) XFreePixmap( gdi_display
, data
->icon_mask
);
643 HeapFree( GetProcessHeap(), 0, data
->icon_bits
);
644 data
->icon_pixmap
= icon_pixmap
;
645 data
->icon_mask
= mask_pixmap
;
646 data
->icon_bits
= bits
;
647 data
->icon_size
= size
;
648 release_win_data( data
);
652 if (icon_pixmap
) XFreePixmap( gdi_display
, icon_pixmap
);
653 if (mask_pixmap
) XFreePixmap( gdi_display
, mask_pixmap
);
654 HeapFree( GetProcessHeap(), 0, bits
);
659 /***********************************************************************
662 * set the window size hints
664 static void set_size_hints( struct x11drv_win_data
*data
, DWORD style
)
666 XSizeHints
* size_hints
;
668 if (!(size_hints
= XAllocSizeHints())) return;
670 size_hints
->win_gravity
= StaticGravity
;
671 size_hints
->flags
|= PWinGravity
;
673 /* don't update size hints if window is not in normal state */
674 if (!(style
& (WS_MINIMIZE
| WS_MAXIMIZE
)))
676 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
678 size_hints
->x
= data
->whole_rect
.left
;
679 size_hints
->y
= data
->whole_rect
.top
;
680 size_hints
->flags
|= PPosition
;
682 else size_hints
->win_gravity
= NorthWestGravity
;
684 if (!is_window_resizable( data
, style
))
686 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
687 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
688 if (size_hints
->max_width
<= 0 ||size_hints
->max_height
<= 0)
689 size_hints
->max_width
= size_hints
->max_height
= 1;
690 size_hints
->min_width
= size_hints
->max_width
;
691 size_hints
->min_height
= size_hints
->max_height
;
692 size_hints
->flags
|= PMinSize
| PMaxSize
;
695 XSetWMNormalHints( data
->display
, data
->whole_window
, size_hints
);
700 /***********************************************************************
703 static void set_mwm_hints( struct x11drv_win_data
*data
, DWORD style
, DWORD ex_style
)
707 if (data
->hwnd
== GetDesktopWindow())
709 if (is_desktop_fullscreen()) mwm_hints
.decorations
= 0;
710 else mwm_hints
.decorations
= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
| MWM_DECOR_MENU
| MWM_DECOR_MINIMIZE
;
711 mwm_hints
.functions
= MWM_FUNC_MOVE
| MWM_FUNC_MINIMIZE
| MWM_FUNC_CLOSE
;
715 mwm_hints
.decorations
= get_mwm_decorations( data
, style
, ex_style
);
716 mwm_hints
.functions
= MWM_FUNC_MOVE
;
717 if (is_window_resizable( data
, style
)) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
718 if (!(style
& WS_DISABLED
))
720 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
721 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
722 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
726 TRACE( "%p setting mwm hints to %lx,%lx (style %x exstyle %x)\n",
727 data
->hwnd
, mwm_hints
.decorations
, mwm_hints
.functions
, style
, ex_style
);
729 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
730 mwm_hints
.input_mode
= 0;
731 mwm_hints
.status
= 0;
732 XChangeProperty( data
->display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
733 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
734 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
738 /***********************************************************************
741 static void set_style_hints( struct x11drv_win_data
*data
, DWORD style
, DWORD ex_style
)
743 Window group_leader
= data
->whole_window
;
744 HWND owner
= GetWindow( data
->hwnd
, GW_OWNER
);
745 Window owner_win
= 0;
751 owner
= GetAncestor( owner
, GA_ROOT
);
752 owner_win
= X11DRV_get_whole_window( owner
);
757 XSetTransientForHint( data
->display
, data
->whole_window
, owner_win
);
758 group_leader
= owner_win
;
761 /* Only use dialog type for owned popups. Metacity allows making fullscreen
762 * only normal windows, and doesn't handle correctly TRANSIENT_FOR hint for
763 * dialogs owned by fullscreen windows.
765 if (((style
& WS_POPUP
) || (ex_style
& WS_EX_DLGMODALFRAME
)) && owner
)
766 window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
768 window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
770 XChangeProperty(data
->display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
771 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
773 if ((wm_hints
= XAllocWMHints()))
775 wm_hints
->flags
= InputHint
| StateHint
| WindowGroupHint
;
776 wm_hints
->input
= !use_take_focus
&& !(style
& WS_DISABLED
);
777 wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
778 wm_hints
->window_group
= group_leader
;
779 if (data
->icon_pixmap
)
781 wm_hints
->icon_pixmap
= data
->icon_pixmap
;
782 wm_hints
->icon_mask
= data
->icon_mask
;
783 wm_hints
->flags
|= IconPixmapHint
| IconMaskHint
;
785 XSetWMHints( data
->display
, data
->whole_window
, wm_hints
);
790 XChangeProperty( data
->display
, data
->whole_window
, x11drv_atom(_NET_WM_ICON
),
791 XA_CARDINAL
, 32, PropModeReplace
,
792 (unsigned char *)data
->icon_bits
, data
->icon_size
);
794 XDeleteProperty( data
->display
, data
->whole_window
, x11drv_atom(_NET_WM_ICON
) );
799 /***********************************************************************
800 * set_initial_wm_hints
802 * Set the window manager hints that don't change over the lifetime of a window.
804 static void set_initial_wm_hints( Display
*display
, Window window
)
808 Atom dndVersion
= WINE_XDND_VERSION
;
809 XClassHint
*class_hints
;
813 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
814 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
815 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
816 XChangeProperty( display
, window
, x11drv_atom(WM_PROTOCOLS
),
817 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
820 if ((class_hints
= XAllocClassHint()))
822 static char wine
[] = "Wine";
824 class_hints
->res_name
= process_name
;
825 class_hints
->res_class
= wine
;
826 XSetClassHint( display
, window
, class_hints
);
827 XFree( class_hints
);
830 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
831 XSetWMProperties(display
, window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
832 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
834 XChangeProperty(display
, window
, x11drv_atom(_NET_WM_PID
),
835 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
837 XChangeProperty( display
, window
, x11drv_atom(XdndAware
),
838 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
840 update_user_time( 0 ); /* make sure that the user time window exists */
841 if (user_time_window
)
842 XChangeProperty( display
, window
, x11drv_atom(_NET_WM_USER_TIME_WINDOW
),
843 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&user_time_window
, 1 );
847 /***********************************************************************
850 * If the window is managed, make sure its owner window is too.
852 static void make_owner_managed( HWND hwnd
)
856 if (!(owner
= GetWindow( hwnd
, GW_OWNER
))) return;
857 if (is_managed( owner
)) return;
858 if (!is_managed( hwnd
)) return;
860 SetWindowPos( owner
, 0, 0, 0, 0, 0,
861 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOMOVE
|
862 SWP_NOREDRAW
| SWP_DEFERERASE
| SWP_NOSENDCHANGING
| SWP_STATECHANGED
);
866 /***********************************************************************
869 * Set all the window manager hints for a window.
871 static void set_wm_hints( struct x11drv_win_data
*data
)
873 DWORD style
, ex_style
;
875 if (data
->hwnd
== GetDesktopWindow())
877 /* force some styles for the desktop to get the correct decorations */
878 style
= WS_POPUP
| WS_VISIBLE
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
879 ex_style
= WS_EX_APPWINDOW
;
883 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
884 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
887 set_size_hints( data
, style
);
888 set_mwm_hints( data
, style
, ex_style
);
889 set_style_hints( data
, style
, ex_style
);
893 /***********************************************************************
896 Window
init_clip_window(void)
898 struct x11drv_thread_data
*data
= x11drv_init_thread_data();
900 if (!data
->clip_window
&&
901 (data
->clip_window
= (Window
)GetPropA( GetDesktopWindow(), clip_window_prop
)))
903 XSelectInput( data
->display
, data
->clip_window
, StructureNotifyMask
);
905 return data
->clip_window
;
909 /***********************************************************************
912 void update_user_time( Time time
)
914 if (!user_time_window
)
916 Window win
= XCreateWindow( gdi_display
, root_window
, -1, -1, 1, 1, 0, CopyFromParent
,
917 InputOnly
, CopyFromParent
, 0, NULL
);
918 if (InterlockedCompareExchangePointer( (void **)&user_time_window
, (void *)win
, 0 ))
919 XDestroyWindow( gdi_display
, win
);
920 TRACE( "user time window %lx\n", user_time_window
);
924 XLockDisplay( gdi_display
);
925 if (!last_user_time
|| (long)(time
- last_user_time
) > 0)
927 last_user_time
= time
;
928 XChangeProperty( gdi_display
, user_time_window
, x11drv_atom(_NET_WM_USER_TIME
),
929 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&time
, 1 );
931 XUnlockDisplay( gdi_display
);
934 /***********************************************************************
935 * update_net_wm_states
937 void update_net_wm_states( struct x11drv_win_data
*data
)
939 DWORD i
, style
, ex_style
, new_state
= 0;
941 if (!data
->managed
) return;
942 if (data
->whole_window
== root_window
) return;
944 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
945 if (style
& WS_MINIMIZE
)
946 new_state
|= data
->net_wm_state
& ((1 << NET_WM_STATE_FULLSCREEN
)|(1 << NET_WM_STATE_MAXIMIZED
));
947 if (is_window_rect_fullscreen( &data
->whole_rect
))
949 if ((style
& WS_MAXIMIZE
) && (style
& WS_CAPTION
) == WS_CAPTION
)
950 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
951 else if (!(style
& WS_MINIMIZE
))
952 new_state
|= (1 << NET_WM_STATE_FULLSCREEN
);
954 else if (style
& WS_MAXIMIZE
)
955 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
957 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
958 if (ex_style
& WS_EX_TOPMOST
)
959 new_state
|= (1 << NET_WM_STATE_ABOVE
);
960 if (ex_style
& (WS_EX_TOOLWINDOW
| WS_EX_NOACTIVATE
))
961 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
) | (1 << NET_WM_STATE_SKIP_PAGER
);
962 if (!(ex_style
& WS_EX_APPWINDOW
) && GetWindow( data
->hwnd
, GW_OWNER
))
963 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
);
965 if (!data
->mapped
) /* set the _NET_WM_STATE atom directly */
967 Atom atoms
[NB_NET_WM_STATES
+1];
970 for (i
= count
= 0; i
< NB_NET_WM_STATES
; i
++)
972 if (!(new_state
& (1 << i
))) continue;
973 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
974 i
, data
->hwnd
, data
->whole_window
);
975 atoms
[count
++] = X11DRV_Atoms
[net_wm_state_atoms
[i
] - FIRST_XATOM
];
976 if (net_wm_state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
)
977 atoms
[count
++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
);
979 XChangeProperty( data
->display
, data
->whole_window
, x11drv_atom(_NET_WM_STATE
), XA_ATOM
,
980 32, PropModeReplace
, (unsigned char *)atoms
, count
);
982 else /* ask the window manager to do it for us */
986 xev
.xclient
.type
= ClientMessage
;
987 xev
.xclient
.window
= data
->whole_window
;
988 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
989 xev
.xclient
.serial
= 0;
990 xev
.xclient
.display
= data
->display
;
991 xev
.xclient
.send_event
= True
;
992 xev
.xclient
.format
= 32;
993 xev
.xclient
.data
.l
[3] = 1;
994 xev
.xclient
.data
.l
[4] = 0;
996 for (i
= 0; i
< NB_NET_WM_STATES
; i
++)
998 if (!((data
->net_wm_state
^ new_state
) & (1 << i
))) continue; /* unchanged */
1000 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1001 i
, data
->hwnd
, data
->whole_window
,
1002 (new_state
& (1 << i
)) != 0, (data
->net_wm_state
& (1 << i
)) != 0 );
1004 xev
.xclient
.data
.l
[0] = (new_state
& (1 << i
)) ? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
1005 xev
.xclient
.data
.l
[1] = X11DRV_Atoms
[net_wm_state_atoms
[i
] - FIRST_XATOM
];
1006 xev
.xclient
.data
.l
[2] = ((net_wm_state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
) ?
1007 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
) : 0);
1008 XSendEvent( data
->display
, root_window
, False
,
1009 SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
1012 data
->net_wm_state
= new_state
;
1015 /***********************************************************************
1016 * read_net_wm_states
1018 void read_net_wm_states( Display
* display
, struct x11drv_win_data
*data
)
1022 unsigned long i
, j
, count
, remaining
;
1023 DWORD new_state
= 0;
1024 BOOL maximized_horz
= FALSE
;
1026 if (!data
->whole_window
) return;
1028 if (!XGetWindowProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_STATE
), 0,
1029 65536/sizeof(CARD32
), False
, XA_ATOM
, &type
, &format
, &count
,
1030 &remaining
, (unsigned char **)&state
))
1032 if (type
== XA_ATOM
&& format
== 32)
1034 for (i
= 0; i
< count
; i
++)
1036 if (state
[i
] == x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
))
1037 maximized_horz
= TRUE
;
1038 for (j
=0; j
< NB_NET_WM_STATES
; j
++)
1040 if (state
[i
] == X11DRV_Atoms
[net_wm_state_atoms
[j
] - FIRST_XATOM
])
1042 new_state
|= 1 << j
;
1050 if (!maximized_horz
)
1051 new_state
&= ~(1 << NET_WM_STATE_MAXIMIZED
);
1053 data
->net_wm_state
= new_state
;
1057 /***********************************************************************
1060 static void set_xembed_flags( struct x11drv_win_data
*data
, unsigned long flags
)
1062 unsigned long info
[2];
1064 if (!data
->whole_window
) return;
1066 info
[0] = 0; /* protocol version */
1068 XChangeProperty( data
->display
, data
->whole_window
, x11drv_atom(_XEMBED_INFO
),
1069 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
, (unsigned char*)info
, 2 );
1073 /***********************************************************************
1076 static void map_window( HWND hwnd
, DWORD new_style
)
1078 struct x11drv_win_data
*data
;
1080 make_owner_managed( hwnd
);
1081 wait_for_withdrawn_state( hwnd
, TRUE
);
1083 if (!(data
= get_win_data( hwnd
))) return;
1085 if (data
->whole_window
&& !data
->mapped
)
1087 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1089 remove_startup_notification( data
->display
, data
->whole_window
);
1090 set_wm_hints( data
);
1092 if (!data
->embedded
)
1094 update_net_wm_states( data
);
1095 sync_window_style( data
);
1096 XMapWindow( data
->display
, data
->whole_window
);
1097 XFlush( data
->display
);
1098 if (data
->surface
&& data
->vis
.visualid
!= default_visual
.visualid
)
1099 data
->surface
->funcs
->flush( data
->surface
);
1101 else set_xembed_flags( data
, XEMBED_MAPPED
);
1103 data
->mapped
= TRUE
;
1104 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
1106 release_win_data( data
);
1110 /***********************************************************************
1113 static void unmap_window( HWND hwnd
)
1115 struct x11drv_win_data
*data
;
1117 wait_for_withdrawn_state( hwnd
, FALSE
);
1119 if (!(data
= get_win_data( hwnd
))) return;
1123 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1125 if (data
->embedded
) set_xembed_flags( data
, 0 );
1126 else if (!data
->managed
) XUnmapWindow( data
->display
, data
->whole_window
);
1127 else XWithdrawWindow( data
->display
, data
->whole_window
, data
->vis
.screen
);
1129 data
->mapped
= FALSE
;
1130 data
->net_wm_state
= 0;
1132 release_win_data( data
);
1136 /***********************************************************************
1137 * make_window_embedded
1139 void make_window_embedded( struct x11drv_win_data
*data
)
1141 /* the window cannot be mapped before being embedded */
1144 if (!data
->managed
) XUnmapWindow( data
->display
, data
->whole_window
);
1145 else XWithdrawWindow( data
->display
, data
->whole_window
, data
->vis
.screen
);
1146 data
->net_wm_state
= 0;
1148 data
->embedded
= TRUE
;
1149 data
->managed
= TRUE
;
1150 sync_window_style( data
);
1151 set_xembed_flags( data
, (data
->mapped
|| data
->embedder
) ? XEMBED_MAPPED
: 0 );
1155 /***********************************************************************
1156 * X11DRV_window_to_X_rect
1158 * Convert a rect from client to X window coordinates
1160 static void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1162 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
1163 unsigned long decor
;
1166 if (!data
->managed
) return;
1167 if (IsRectEmpty( rect
)) return;
1169 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1170 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
1171 decor
= get_mwm_decorations( data
, style
, ex_style
);
1173 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
1174 if (decor
& MWM_DECOR_BORDER
)
1176 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
1177 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
1180 SetRectEmpty( &rc
);
1181 AdjustWindowRectEx( &rc
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
1183 rect
->left
-= rc
.left
;
1184 rect
->right
-= rc
.right
;
1185 rect
->top
-= rc
.top
;
1186 rect
->bottom
-= rc
.bottom
;
1187 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1188 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1192 /***********************************************************************
1193 * X11DRV_X_to_window_rect
1195 * Opposite of X11DRV_window_to_X_rect
1197 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
, int x
, int y
, int cx
, int cy
)
1199 x
+= data
->window_rect
.left
- data
->whole_rect
.left
;
1200 y
+= data
->window_rect
.top
- data
->whole_rect
.top
;
1201 cx
+= (data
->window_rect
.right
- data
->window_rect
.left
) -
1202 (data
->whole_rect
.right
- data
->whole_rect
.left
);
1203 cy
+= (data
->window_rect
.bottom
- data
->window_rect
.top
) -
1204 (data
->whole_rect
.bottom
- data
->whole_rect
.top
);
1205 SetRect( rect
, x
, y
, x
+ cx
, y
+ cy
);
1209 /***********************************************************************
1210 * sync_window_position
1212 * Synchronize the X window position with the Windows one
1214 static void sync_window_position( struct x11drv_win_data
*data
,
1215 UINT swp_flags
, const RECT
*old_window_rect
,
1216 const RECT
*old_whole_rect
, const RECT
*old_client_rect
)
1218 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1219 DWORD ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
1220 XWindowChanges changes
;
1221 unsigned int mask
= 0;
1223 if (data
->managed
&& data
->iconic
) return;
1225 /* resizing a managed maximized window is not allowed */
1226 if (!(style
& WS_MAXIMIZE
) || !data
->managed
)
1228 changes
.width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
1229 changes
.height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
1230 /* if window rect is empty force size to 1x1 */
1231 if (changes
.width
<= 0 || changes
.height
<= 0) changes
.width
= changes
.height
= 1;
1232 if (changes
.width
> 65535) changes
.width
= 65535;
1233 if (changes
.height
> 65535) changes
.height
= 65535;
1234 mask
|= CWWidth
| CWHeight
;
1237 /* only the size is allowed to change for the desktop window */
1238 if (data
->whole_window
!= root_window
)
1240 POINT pt
= virtual_screen_to_root( data
->whole_rect
.left
, data
->whole_rect
.top
);
1246 if (!(swp_flags
& SWP_NOZORDER
) || (swp_flags
& SWP_SHOWWINDOW
))
1248 /* find window that this one must be after */
1249 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
1250 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
1251 prev
= GetWindow( prev
, GW_HWNDPREV
);
1252 if (!prev
) /* top child */
1254 changes
.stack_mode
= Above
;
1255 mask
|= CWStackMode
;
1257 /* should use stack_mode Below but most window managers don't get it right */
1258 /* and Above with a sibling doesn't work so well either, so we ignore it */
1261 set_size_hints( data
, style
);
1262 set_mwm_hints( data
, style
, ex_style
);
1263 data
->configure_serial
= NextRequest( data
->display
);
1264 XReconfigureWMWindow( data
->display
, data
->whole_window
, data
->vis
.screen
, mask
, &changes
);
1265 #ifdef HAVE_LIBXSHAPE
1266 if (IsRectEmpty( old_window_rect
) != IsRectEmpty( &data
->window_rect
))
1267 sync_window_region( data
, (HRGN
)1 );
1270 int old_x_offset
= old_window_rect
->left
- old_whole_rect
->left
;
1271 int old_y_offset
= old_window_rect
->top
- old_whole_rect
->top
;
1272 int new_x_offset
= data
->window_rect
.left
- data
->whole_rect
.left
;
1273 int new_y_offset
= data
->window_rect
.top
- data
->whole_rect
.top
;
1274 if (old_x_offset
!= new_x_offset
|| old_y_offset
!= new_y_offset
)
1275 XShapeOffsetShape( data
->display
, data
->whole_window
, ShapeBounding
,
1276 new_x_offset
- old_x_offset
, new_y_offset
- old_y_offset
);
1280 TRACE( "win %p/%lx pos %d,%d,%dx%d after %lx changes=%x serial=%lu\n",
1281 data
->hwnd
, data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1282 data
->whole_rect
.right
- data
->whole_rect
.left
,
1283 data
->whole_rect
.bottom
- data
->whole_rect
.top
,
1284 changes
.sibling
, mask
, data
->configure_serial
);
1288 /***********************************************************************
1289 * sync_client_position
1291 * Synchronize the X client window position with the Windows one
1293 static void sync_client_position( struct x11drv_win_data
*data
,
1294 const RECT
*old_client_rect
, const RECT
*old_whole_rect
)
1297 XWindowChanges changes
;
1299 if (!data
->client_window
) return;
1301 changes
.x
= data
->client_rect
.left
- data
->whole_rect
.left
;
1302 changes
.y
= data
->client_rect
.top
- data
->whole_rect
.top
;
1303 changes
.width
= min( max( 1, data
->client_rect
.right
- data
->client_rect
.left
), 65535 );
1304 changes
.height
= min( max( 1, data
->client_rect
.bottom
- data
->client_rect
.top
), 65535 );
1306 if (changes
.x
!= old_client_rect
->left
- old_whole_rect
->left
) mask
|= CWX
;
1307 if (changes
.y
!= old_client_rect
->top
- old_whole_rect
->top
) mask
|= CWY
;
1308 if (changes
.width
!= old_client_rect
->right
- old_client_rect
->left
) mask
|= CWWidth
;
1309 if (changes
.height
!= old_client_rect
->bottom
- old_client_rect
->top
) mask
|= CWHeight
;
1313 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1314 data
->client_window
, changes
.x
, changes
.y
, changes
.width
, changes
.height
, mask
);
1315 XConfigureWindow( data
->display
, data
->client_window
, mask
, &changes
);
1320 /***********************************************************************
1323 * Move the window bits when a window is moved.
1325 static void move_window_bits( HWND hwnd
, Window window
, const RECT
*old_rect
, const RECT
*new_rect
,
1326 const RECT
*old_client_rect
, const RECT
*new_client_rect
,
1327 const RECT
*new_window_rect
)
1329 RECT src_rect
= *old_rect
;
1330 RECT dst_rect
= *new_rect
;
1331 HDC hdc_src
, hdc_dst
;
1338 OffsetRect( &dst_rect
, -new_window_rect
->left
, -new_window_rect
->top
);
1339 parent
= GetAncestor( hwnd
, GA_PARENT
);
1340 hdc_src
= GetDCEx( parent
, 0, DCX_CACHE
);
1341 hdc_dst
= GetDCEx( hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
1345 OffsetRect( &dst_rect
, -new_client_rect
->left
, -new_client_rect
->top
);
1346 /* make src rect relative to the old position of the window */
1347 OffsetRect( &src_rect
, -old_client_rect
->left
, -old_client_rect
->top
);
1348 if (dst_rect
.left
== src_rect
.left
&& dst_rect
.top
== src_rect
.top
) return;
1349 hdc_src
= hdc_dst
= GetDCEx( hwnd
, 0, DCX_CACHE
);
1352 rgn
= CreateRectRgnIndirect( &dst_rect
);
1353 SelectClipRgn( hdc_dst
, rgn
);
1354 DeleteObject( rgn
);
1355 /* WS_CLIPCHILDREN doesn't exclude children from the window update
1356 * region, and ExcludeUpdateRgn call may inappropriately clip valid
1357 * child window contents from the copied parent window bits, but we
1358 * still want to avoid copying invalid window bits when possible.
1360 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CLIPCHILDREN
))
1361 ExcludeUpdateRgn( hdc_dst
, hwnd
);
1363 code
= X11DRV_START_EXPOSURES
;
1364 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
1366 TRACE( "copying bits for win %p/%lx %s -> %s\n",
1367 hwnd
, window
, wine_dbgstr_rect(&src_rect
), wine_dbgstr_rect(&dst_rect
) );
1368 BitBlt( hdc_dst
, dst_rect
.left
, dst_rect
.top
,
1369 dst_rect
.right
- dst_rect
.left
, dst_rect
.bottom
- dst_rect
.top
,
1370 hdc_src
, src_rect
.left
, src_rect
.top
, SRCCOPY
);
1373 code
= X11DRV_END_EXPOSURES
;
1374 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, sizeof(rgn
), (LPSTR
)&rgn
);
1376 ReleaseDC( hwnd
, hdc_dst
);
1377 if (hdc_src
!= hdc_dst
) ReleaseDC( parent
, hdc_src
);
1383 /* map region to client rect since we are using DCX_WINDOW */
1384 OffsetRgn( rgn
, new_window_rect
->left
- new_client_rect
->left
,
1385 new_window_rect
->top
- new_client_rect
->top
);
1386 RedrawWindow( hwnd
, NULL
, rgn
,
1387 RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
1389 else RedrawWindow( hwnd
, NULL
, rgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1390 DeleteObject( rgn
);
1395 /***********************************************************************
1398 * Create a dummy parent window for child windows that don't have a true X11 parent.
1400 static Window
get_dummy_parent(void)
1402 static Window dummy_parent
;
1406 XSetWindowAttributes attrib
;
1408 attrib
.override_redirect
= True
;
1409 attrib
.border_pixel
= 0;
1410 attrib
.colormap
= default_colormap
;
1411 dummy_parent
= XCreateWindow( gdi_display
, root_window
, -1, -1, 1, 1, 0, default_visual
.depth
,
1412 InputOutput
, default_visual
.visual
,
1413 CWColormap
| CWBorderPixel
| CWOverrideRedirect
, &attrib
);
1414 XMapWindow( gdi_display
, dummy_parent
);
1416 return dummy_parent
;
1420 /**********************************************************************
1421 * create_client_window
1423 Window
create_client_window( HWND hwnd
, const XVisualInfo
*visual
)
1425 Window dummy_parent
= get_dummy_parent();
1426 struct x11drv_win_data
*data
= get_win_data( hwnd
);
1427 XSetWindowAttributes attr
;
1433 /* explicitly create data for HWND_MESSAGE windows since they can be used for OpenGL */
1434 HWND parent
= GetAncestor( hwnd
, GA_PARENT
);
1435 if (parent
== GetDesktopWindow() || GetAncestor( parent
, GA_PARENT
)) return 0;
1436 if (!(data
= alloc_win_data( thread_init_display(), hwnd
))) return 0;
1437 GetClientRect( hwnd
, &data
->client_rect
);
1438 data
->window_rect
= data
->whole_rect
= data
->client_rect
;
1441 if (data
->client_window
)
1443 XDeleteContext( data
->display
, data
->client_window
, winContext
);
1444 XReparentWindow( gdi_display
, data
->client_window
, dummy_parent
, 0, 0 );
1445 TRACE( "%p reparent xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1448 if (data
->colormap
) XFreeColormap( gdi_display
, data
->colormap
);
1449 data
->colormap
= XCreateColormap( gdi_display
, dummy_parent
, visual
->visual
,
1450 (visual
->class == PseudoColor
||
1451 visual
->class == GrayScale
||
1452 visual
->class == DirectColor
) ? AllocAll
: AllocNone
);
1453 attr
.colormap
= data
->colormap
;
1454 attr
.bit_gravity
= NorthWestGravity
;
1455 attr
.win_gravity
= NorthWestGravity
;
1456 attr
.backing_store
= NotUseful
;
1457 attr
.border_pixel
= 0;
1459 x
= data
->client_rect
.left
- data
->whole_rect
.left
;
1460 y
= data
->client_rect
.top
- data
->whole_rect
.top
;
1461 cx
= min( max( 1, data
->client_rect
.right
- data
->client_rect
.left
), 65535 );
1462 cy
= min( max( 1, data
->client_rect
.bottom
- data
->client_rect
.top
), 65535 );
1464 ret
= data
->client_window
= XCreateWindow( gdi_display
,
1465 data
->whole_window
? data
->whole_window
: dummy_parent
,
1466 x
, y
, cx
, cy
, 0, default_visual
.depth
, InputOutput
,
1467 visual
->visual
, CWBitGravity
| CWWinGravity
|
1468 CWBackingStore
| CWColormap
| CWBorderPixel
, &attr
);
1469 if (data
->client_window
)
1471 XSaveContext( data
->display
, data
->client_window
, winContext
, (char *)data
->hwnd
);
1472 XMapWindow( gdi_display
, data
->client_window
);
1473 XSync( gdi_display
, False
);
1474 if (data
->whole_window
) XSelectInput( data
->display
, data
->client_window
, ExposureMask
);
1475 TRACE( "%p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1477 release_win_data( data
);
1482 /**********************************************************************
1483 * create_whole_window
1485 * Create the whole X window for a given window
1487 static void create_whole_window( struct x11drv_win_data
*data
)
1490 XSetWindowAttributes attr
;
1494 DWORD layered_flags
;
1498 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1500 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1501 data
->managed
= TRUE
;
1504 if ((win_rgn
= CreateRectRgn( 0, 0, 0, 0 )) && GetWindowRgn( data
->hwnd
, win_rgn
) == ERROR
)
1506 DeleteObject( win_rgn
);
1509 data
->shaped
= (win_rgn
!= 0);
1511 if (data
->vis
.visualid
!= default_visual
.visualid
)
1512 data
->colormap
= XCreateColormap( data
->display
, root_window
, data
->vis
.visual
, AllocNone
);
1514 mask
= get_window_attributes( data
, &attr
);
1516 if (!(cx
= data
->whole_rect
.right
- data
->whole_rect
.left
)) cx
= 1;
1517 else if (cx
> 65535) cx
= 65535;
1518 if (!(cy
= data
->whole_rect
.bottom
- data
->whole_rect
.top
)) cy
= 1;
1519 else if (cy
> 65535) cy
= 65535;
1521 pos
= virtual_screen_to_root( data
->whole_rect
.left
, data
->whole_rect
.top
);
1522 data
->whole_window
= XCreateWindow( data
->display
, root_window
, pos
.x
, pos
.y
,
1523 cx
, cy
, 0, data
->vis
.depth
, InputOutput
,
1524 data
->vis
.visual
, mask
, &attr
);
1525 if (!data
->whole_window
) goto done
;
1527 set_initial_wm_hints( data
->display
, data
->whole_window
);
1528 set_wm_hints( data
);
1530 XSaveContext( data
->display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1531 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1533 /* set the window text */
1534 if (!InternalGetWindowText( data
->hwnd
, text
, ARRAY_SIZE( text
))) text
[0] = 0;
1535 sync_window_text( data
->display
, data
->whole_window
, text
);
1537 /* set the window region */
1538 if (win_rgn
|| IsRectEmpty( &data
->window_rect
)) sync_window_region( data
, win_rgn
);
1540 /* set the window opacity */
1541 if (!GetLayeredWindowAttributes( data
->hwnd
, &key
, &alpha
, &layered_flags
)) layered_flags
= 0;
1542 sync_window_opacity( data
->display
, data
->whole_window
, key
, alpha
, layered_flags
);
1544 XFlush( data
->display
); /* make sure the window exists before we start painting to it */
1546 sync_window_cursor( data
->whole_window
);
1549 if (win_rgn
) DeleteObject( win_rgn
);
1553 /**********************************************************************
1554 * destroy_whole_window
1556 * Destroy the whole X window for a given window.
1558 static void destroy_whole_window( struct x11drv_win_data
*data
, BOOL already_destroyed
)
1560 TRACE( "win %p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1562 if (data
->client_window
) XDeleteContext( data
->display
, data
->client_window
, winContext
);
1564 if (!data
->whole_window
)
1568 Window xwin
= (Window
)GetPropA( data
->hwnd
, foreign_window_prop
);
1571 if (!already_destroyed
) XSelectInput( data
->display
, xwin
, 0 );
1572 XDeleteContext( data
->display
, xwin
, winContext
);
1573 RemovePropA( data
->hwnd
, foreign_window_prop
);
1580 if (data
->client_window
&& !already_destroyed
)
1582 XSelectInput( data
->display
, data
->client_window
, 0 );
1583 XReparentWindow( data
->display
, data
->client_window
, get_dummy_parent(), 0, 0 );
1584 XSync( data
->display
, False
);
1586 XDeleteContext( data
->display
, data
->whole_window
, winContext
);
1587 if (!already_destroyed
) XDestroyWindow( data
->display
, data
->whole_window
);
1589 if (data
->colormap
) XFreeColormap( data
->display
, data
->colormap
);
1590 data
->whole_window
= data
->client_window
= 0;
1592 data
->wm_state
= WithdrawnState
;
1593 data
->net_wm_state
= 0;
1594 data
->mapped
= FALSE
;
1597 XUnsetICFocus( data
->xic
);
1598 XDestroyIC( data
->xic
);
1601 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1602 XFlush( data
->display
);
1603 if (data
->surface
) window_surface_release( data
->surface
);
1604 data
->surface
= NULL
;
1605 RemovePropA( data
->hwnd
, whole_window_prop
);
1609 /**********************************************************************
1612 * Change the visual by destroying and recreating the X window if needed.
1614 void set_window_visual( struct x11drv_win_data
*data
, const XVisualInfo
*vis
, BOOL use_alpha
)
1616 Window client_window
= data
->client_window
;
1617 Window whole_window
= data
->whole_window
;
1619 if (!data
->use_alpha
== !use_alpha
) return;
1620 if (data
->surface
) window_surface_release( data
->surface
);
1621 data
->surface
= NULL
;
1622 data
->use_alpha
= use_alpha
;
1624 if (data
->vis
.visualid
== vis
->visualid
) return;
1625 data
->client_window
= 0;
1626 destroy_whole_window( data
, client_window
!= 0 /* don't destroy whole_window until reparented */ );
1628 create_whole_window( data
);
1629 if (!client_window
) return;
1630 /* move the client to the new parent */
1631 XReparentWindow( data
->display
, client_window
, data
->whole_window
,
1632 data
->client_rect
.left
- data
->whole_rect
.left
,
1633 data
->client_rect
.top
- data
->whole_rect
.top
);
1634 data
->client_window
= client_window
;
1635 XDestroyWindow( data
->display
, whole_window
);
1639 /*****************************************************************
1640 * SetWindowText (X11DRV.@)
1642 void CDECL
X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1646 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(gdi_display
))
1648 Display
*display
= thread_init_display();
1649 sync_window_text( display
, win
, text
);
1654 /***********************************************************************
1655 * SetWindowStyle (X11DRV.@)
1657 * Update the X state of a window to reflect a style change
1659 void CDECL
X11DRV_SetWindowStyle( HWND hwnd
, INT offset
, STYLESTRUCT
*style
)
1661 struct x11drv_win_data
*data
;
1662 DWORD changed
= style
->styleNew
^ style
->styleOld
;
1664 if (hwnd
== GetDesktopWindow()) return;
1665 if (!(data
= get_win_data( hwnd
))) return;
1666 if (!data
->whole_window
) goto done
;
1668 if (offset
== GWL_STYLE
&& (changed
& WS_DISABLED
)) set_wm_hints( data
);
1670 if (offset
== GWL_EXSTYLE
&& (changed
& WS_EX_LAYERED
)) /* changing WS_EX_LAYERED resets attributes */
1672 data
->layered
= FALSE
;
1673 set_window_visual( data
, &default_visual
, FALSE
);
1674 sync_window_opacity( data
->display
, data
->whole_window
, 0, 0, 0 );
1675 if (data
->surface
) set_surface_color_key( data
->surface
, CLR_INVALID
);
1678 release_win_data( data
);
1682 /***********************************************************************
1683 * DestroyWindow (X11DRV.@)
1685 void CDECL
X11DRV_DestroyWindow( HWND hwnd
)
1687 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1688 struct x11drv_win_data
*data
;
1690 if (!(data
= get_win_data( hwnd
))) return;
1692 destroy_whole_window( data
, FALSE
);
1693 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1694 if (thread_data
->last_xic_hwnd
== hwnd
) thread_data
->last_xic_hwnd
= 0;
1695 if (data
->icon_pixmap
) XFreePixmap( gdi_display
, data
->icon_pixmap
);
1696 if (data
->icon_mask
) XFreePixmap( gdi_display
, data
->icon_mask
);
1697 HeapFree( GetProcessHeap(), 0, data
->icon_bits
);
1698 XDeleteContext( gdi_display
, (XID
)hwnd
, win_data_context
);
1699 release_win_data( data
);
1700 HeapFree( GetProcessHeap(), 0, data
);
1701 destroy_gl_drawable( hwnd
);
1702 wine_vk_surface_destroy( hwnd
);
1706 /***********************************************************************
1707 * X11DRV_DestroyNotify
1709 BOOL
X11DRV_DestroyNotify( HWND hwnd
, XEvent
*event
)
1711 struct x11drv_win_data
*data
;
1714 if (!(data
= get_win_data( hwnd
))) return FALSE
;
1715 embedded
= data
->embedded
;
1716 if (!embedded
) FIXME( "window %p/%lx destroyed from the outside\n", hwnd
, data
->whole_window
);
1718 destroy_whole_window( data
, TRUE
);
1719 release_win_data( data
);
1720 if (embedded
) SendMessageW( hwnd
, WM_CLOSE
, 0, 0 );
1725 /* initialize the desktop window id in the desktop manager process */
1726 BOOL
create_desktop_win_data( Window win
)
1728 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1729 Display
*display
= thread_data
->display
;
1730 struct x11drv_win_data
*data
;
1732 if (!(data
= alloc_win_data( display
, GetDesktopWindow() ))) return FALSE
;
1733 data
->whole_window
= win
;
1734 data
->managed
= TRUE
;
1735 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)win
);
1736 set_initial_wm_hints( display
, win
);
1737 release_win_data( data
);
1738 if (thread_data
->clip_window
) XReparentWindow( display
, thread_data
->clip_window
, win
, 0, 0 );
1742 /**********************************************************************
1743 * CreateDesktopWindow (X11DRV.@)
1745 BOOL CDECL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1747 unsigned int width
, height
;
1749 /* retrieve the real size of the desktop */
1750 SERVER_START_REQ( get_window_rectangles
)
1752 req
->handle
= wine_server_user_handle( hwnd
);
1753 req
->relative
= COORDS_CLIENT
;
1754 wine_server_call( req
);
1755 width
= reply
->window
.right
;
1756 height
= reply
->window
.bottom
;
1760 if (!width
&& !height
) /* not initialized yet */
1762 RECT rect
= get_virtual_screen_rect();
1764 SERVER_START_REQ( set_window_pos
)
1766 req
->handle
= wine_server_user_handle( hwnd
);
1768 req
->swp_flags
= SWP_NOZORDER
;
1769 req
->window
.left
= rect
.left
;
1770 req
->window
.top
= rect
.top
;
1771 req
->window
.right
= rect
.right
;
1772 req
->window
.bottom
= rect
.bottom
;
1773 req
->client
= req
->window
;
1774 wine_server_call( req
);
1780 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1781 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1787 static WNDPROC desktop_orig_wndproc
;
1789 #define WM_WINE_NOTIFY_ACTIVITY WM_USER
1791 static LRESULT CALLBACK
desktop_wndproc_wrapper( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1795 case WM_WINE_NOTIFY_ACTIVITY
:
1796 XResetScreenSaver( gdi_display
);
1797 XFlush( gdi_display
);
1800 return desktop_orig_wndproc( hwnd
, msg
, wp
, lp
);
1803 /**********************************************************************
1804 * CreateWindow (X11DRV.@)
1806 BOOL CDECL
X11DRV_CreateWindow( HWND hwnd
)
1808 if (hwnd
== GetDesktopWindow())
1810 struct x11drv_thread_data
*data
= x11drv_init_thread_data();
1811 XSetWindowAttributes attr
;
1813 desktop_orig_wndproc
= (WNDPROC
)SetWindowLongPtrW( hwnd
, GWLP_WNDPROC
,
1814 (LONG_PTR
)desktop_wndproc_wrapper
);
1816 /* create the cursor clipping window */
1817 attr
.override_redirect
= TRUE
;
1818 attr
.event_mask
= StructureNotifyMask
| FocusChangeMask
;
1819 data
->clip_window
= XCreateWindow( data
->display
, root_window
, 0, 0, 1, 1, 0, 0,
1820 InputOnly
, default_visual
.visual
,
1821 CWOverrideRedirect
| CWEventMask
, &attr
);
1822 XFlush( data
->display
);
1823 SetPropA( hwnd
, clip_window_prop
, (HANDLE
)data
->clip_window
);
1824 X11DRV_InitClipboard();
1830 /***********************************************************************
1833 * Lock and return the X11 data structure associated with a window.
1835 struct x11drv_win_data
*get_win_data( HWND hwnd
)
1839 if (!hwnd
) return NULL
;
1840 EnterCriticalSection( &win_data_section
);
1841 if (!XFindContext( gdi_display
, (XID
)hwnd
, win_data_context
, &data
))
1842 return (struct x11drv_win_data
*)data
;
1843 LeaveCriticalSection( &win_data_section
);
1848 /***********************************************************************
1851 * Release the data returned by get_win_data.
1853 void release_win_data( struct x11drv_win_data
*data
)
1855 if (data
) LeaveCriticalSection( &win_data_section
);
1859 /***********************************************************************
1860 * X11DRV_create_win_data
1862 * Create an X11 data window structure for an existing window.
1864 static struct x11drv_win_data
*X11DRV_create_win_data( HWND hwnd
, const RECT
*window_rect
,
1865 const RECT
*client_rect
)
1868 struct x11drv_win_data
*data
;
1871 if (!(parent
= GetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop */
1873 /* don't create win data for HWND_MESSAGE windows */
1874 if (parent
!= GetDesktopWindow() && !GetAncestor( parent
, GA_PARENT
)) return NULL
;
1876 if (GetWindowThreadProcessId( hwnd
, NULL
) != GetCurrentThreadId()) return NULL
;
1878 /* Recreate the parent gl_drawable now that we know there are child windows
1879 * that will need clipping support.
1881 sync_gl_drawable( parent
, TRUE
);
1883 display
= thread_init_display();
1884 init_clip_window(); /* make sure the clip window is initialized in this thread */
1886 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1888 data
->whole_rect
= data
->window_rect
= *window_rect
;
1889 data
->client_rect
= *client_rect
;
1890 if (parent
== GetDesktopWindow())
1892 create_whole_window( data
);
1893 TRACE( "win %p/%lx window %s whole %s client %s\n",
1894 hwnd
, data
->whole_window
, wine_dbgstr_rect( &data
->window_rect
),
1895 wine_dbgstr_rect( &data
->whole_rect
), wine_dbgstr_rect( &data
->client_rect
));
1901 /* window procedure for foreign windows */
1902 static LRESULT WINAPI
foreign_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1906 case WM_WINDOWPOSCHANGED
:
1907 update_systray_balloon_position();
1909 case WM_PARENTNOTIFY
:
1910 if (LOWORD(wparam
) == WM_DESTROY
)
1912 TRACE( "%p: got parent notify destroy for win %lx\n", hwnd
, lparam
);
1913 PostMessageW( hwnd
, WM_CLOSE
, 0, 0 ); /* so that we come back here once the child is gone */
1917 if (GetWindow( hwnd
, GW_CHILD
)) return 0; /* refuse to die if we still have children */
1920 return DefWindowProcW( hwnd
, msg
, wparam
, lparam
);
1924 /***********************************************************************
1925 * create_foreign_window
1927 * Create a foreign window for the specified X window and its ancestors
1929 HWND
create_foreign_window( Display
*display
, Window xwin
)
1931 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};
1932 static BOOL class_registered
;
1933 struct x11drv_win_data
*data
;
1936 Window xparent
, xroot
;
1938 unsigned int nchildren
;
1939 XWindowAttributes attr
;
1940 DWORD style
= WS_CLIPCHILDREN
;
1942 if (!class_registered
)
1946 memset( &class, 0, sizeof(class) );
1947 class.cbSize
= sizeof(class);
1948 class.lpfnWndProc
= foreign_window_proc
;
1949 class.lpszClassName
= classW
;
1950 if (!RegisterClassExW( &class ) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS
)
1952 ERR( "Could not register foreign window class\n" );
1955 class_registered
= TRUE
;
1958 if (XFindContext( display
, xwin
, winContext
, (char **)&hwnd
)) hwnd
= 0;
1959 if (hwnd
) return hwnd
; /* already created */
1961 XSelectInput( display
, xwin
, StructureNotifyMask
);
1962 if (!XGetWindowAttributes( display
, xwin
, &attr
) ||
1963 !XQueryTree( display
, xwin
, &xroot
, &xparent
, &xchildren
, &nchildren
))
1965 XSelectInput( display
, xwin
, 0 );
1970 if (xparent
== xroot
)
1972 parent
= GetDesktopWindow();
1974 pos
= root_to_virtual_screen( attr
.x
, attr
.y
);
1978 parent
= create_foreign_window( display
, xparent
);
1984 hwnd
= CreateWindowW( classW
, NULL
, style
, pos
.x
, pos
.y
, attr
.width
, attr
.height
,
1985 parent
, 0, 0, NULL
);
1987 if (!(data
= alloc_win_data( display
, hwnd
)))
1989 DestroyWindow( hwnd
);
1992 SetRect( &data
->window_rect
, pos
.x
, pos
.y
, pos
.x
+ attr
.width
, pos
.y
+ attr
.height
);
1993 data
->whole_rect
= data
->client_rect
= data
->window_rect
;
1994 data
->whole_window
= data
->client_window
= 0;
1995 data
->embedded
= TRUE
;
1996 data
->mapped
= TRUE
;
1998 SetPropA( hwnd
, foreign_window_prop
, (HANDLE
)xwin
);
1999 XSaveContext( display
, xwin
, winContext
, (char *)data
->hwnd
);
2001 TRACE( "win %lx parent %p style %08x %s -> hwnd %p\n",
2002 xwin
, parent
, style
, wine_dbgstr_rect(&data
->window_rect
), hwnd
);
2004 release_win_data( data
);
2006 ShowWindow( hwnd
, SW_SHOW
);
2011 /***********************************************************************
2012 * X11DRV_get_whole_window
2014 * Return the X window associated with the full area of a window
2016 Window
X11DRV_get_whole_window( HWND hwnd
)
2018 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2023 if (hwnd
== GetDesktopWindow()) return root_window
;
2024 return (Window
)GetPropA( hwnd
, whole_window_prop
);
2026 ret
= data
->whole_window
;
2027 release_win_data( data
);
2032 /***********************************************************************
2035 * Return the X input context associated with a window
2037 XIC
X11DRV_get_ic( HWND hwnd
)
2039 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2045 x11drv_thread_data()->last_xic_hwnd
= hwnd
;
2047 if (!ret
&& (xim
= x11drv_thread_data()->xim
)) ret
= X11DRV_CreateIC( xim
, data
);
2048 release_win_data( data
);
2054 /***********************************************************************
2055 * X11DRV_GetDC (X11DRV.@)
2057 void CDECL
X11DRV_GetDC( HDC hdc
, HWND hwnd
, HWND top
, const RECT
*win_rect
,
2058 const RECT
*top_rect
, DWORD flags
)
2060 struct x11drv_escape_set_drawable escape
;
2063 escape
.code
= X11DRV_SET_DRAWABLE
;
2064 escape
.mode
= IncludeInferiors
;
2066 escape
.dc_rect
.left
= win_rect
->left
- top_rect
->left
;
2067 escape
.dc_rect
.top
= win_rect
->top
- top_rect
->top
;
2068 escape
.dc_rect
.right
= win_rect
->right
- top_rect
->left
;
2069 escape
.dc_rect
.bottom
= win_rect
->bottom
- top_rect
->top
;
2073 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2075 escape
.drawable
= data
? data
->whole_window
: X11DRV_get_whole_window( hwnd
);
2077 /* special case: when repainting the root window, clip out top-level windows */
2078 if (data
&& data
->whole_window
== root_window
) escape
.mode
= ClipByChildren
;
2079 release_win_data( data
);
2083 /* find the first ancestor that has a drawable */
2084 for (parent
= hwnd
; parent
&& parent
!= top
; parent
= GetAncestor( parent
, GA_PARENT
))
2085 if ((escape
.drawable
= X11DRV_get_whole_window( parent
))) break;
2087 if (escape
.drawable
)
2089 POINT pt
= { 0, 0 };
2090 MapWindowPoints( 0, parent
, &pt
, 1 );
2091 escape
.dc_rect
= *win_rect
;
2092 OffsetRect( &escape
.dc_rect
, pt
.x
, pt
.y
);
2093 if (flags
& DCX_CLIPCHILDREN
) escape
.mode
= ClipByChildren
;
2095 else escape
.drawable
= X11DRV_get_whole_window( top
);
2098 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2102 /***********************************************************************
2103 * X11DRV_ReleaseDC (X11DRV.@)
2105 void CDECL
X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
2107 struct x11drv_escape_set_drawable escape
;
2109 escape
.code
= X11DRV_SET_DRAWABLE
;
2110 escape
.drawable
= root_window
;
2111 escape
.mode
= IncludeInferiors
;
2112 escape
.dc_rect
= get_virtual_screen_rect();
2113 OffsetRect( &escape
.dc_rect
, -2 * escape
.dc_rect
.left
, -2 * escape
.dc_rect
.top
);
2114 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2118 /*************************************************************************
2119 * ScrollDC (X11DRV.@)
2121 BOOL CDECL
X11DRV_ScrollDC( HDC hdc
, INT dx
, INT dy
, HRGN update
)
2125 HRGN expose_rgn
= 0;
2127 GetClipBox( hdc
, &rect
);
2131 INT code
= X11DRV_START_EXPOSURES
;
2132 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
2134 ret
= BitBlt( hdc
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2135 hdc
, rect
.left
- dx
, rect
.top
- dy
, SRCCOPY
);
2137 code
= X11DRV_END_EXPOSURES
;
2138 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
,
2139 sizeof(expose_rgn
), (LPSTR
)&expose_rgn
);
2142 CombineRgn( update
, update
, expose_rgn
, RGN_OR
);
2143 DeleteObject( expose_rgn
);
2146 else ret
= BitBlt( hdc
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2147 hdc
, rect
.left
- dx
, rect
.top
- dy
, SRCCOPY
);
2153 /***********************************************************************
2154 * SetCapture (X11DRV.@)
2156 void CDECL
X11DRV_SetCapture( HWND hwnd
, UINT flags
)
2158 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2159 struct x11drv_win_data
*data
;
2161 if (!(flags
& (GUI_INMOVESIZE
| GUI_INMENUMODE
))) return;
2165 if (!(data
= get_win_data( GetAncestor( hwnd
, GA_ROOT
)))) return;
2166 if (data
->whole_window
)
2168 XFlush( gdi_display
);
2169 XGrabPointer( data
->display
, data
->whole_window
, False
,
2170 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
2171 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
);
2172 thread_data
->grab_hwnd
= data
->hwnd
;
2174 release_win_data( data
);
2176 else /* release capture */
2178 if (!(data
= get_win_data( thread_data
->grab_hwnd
))) return;
2179 XFlush( gdi_display
);
2180 XUngrabPointer( data
->display
, CurrentTime
);
2181 XFlush( data
->display
);
2182 thread_data
->grab_hwnd
= NULL
;
2183 release_win_data( data
);
2188 /*****************************************************************
2189 * SetParent (X11DRV.@)
2191 void CDECL
X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
2193 struct x11drv_win_data
*data
;
2195 if (parent
== old_parent
) return;
2196 if (!(data
= get_win_data( hwnd
))) return;
2197 if (data
->embedded
) goto done
;
2199 if (parent
!= GetDesktopWindow()) /* a child window */
2201 if (old_parent
== GetDesktopWindow())
2203 /* destroy the old X windows */
2204 destroy_whole_window( data
, FALSE
);
2205 data
->managed
= FALSE
;
2208 else /* new top level window */
2210 create_whole_window( data
);
2213 release_win_data( data
);
2214 set_gl_drawable_parent( hwnd
, parent
);
2216 /* Recreate the parent gl_drawable now that we know there are child windows
2217 * that will need clipping support.
2219 sync_gl_drawable( parent
, TRUE
);
2221 fetch_icon_data( hwnd
, 0, 0 );
2225 static inline BOOL
get_surface_rect( const RECT
*visible_rect
, RECT
*surface_rect
)
2227 *surface_rect
= get_virtual_screen_rect();
2229 if (!IntersectRect( surface_rect
, surface_rect
, visible_rect
)) return FALSE
;
2230 OffsetRect( surface_rect
, -visible_rect
->left
, -visible_rect
->top
);
2231 surface_rect
->left
&= ~31;
2232 surface_rect
->top
&= ~31;
2233 surface_rect
->right
= max( surface_rect
->left
+ 32, (surface_rect
->right
+ 31) & ~31 );
2234 surface_rect
->bottom
= max( surface_rect
->top
+ 32, (surface_rect
->bottom
+ 31) & ~31 );
2239 /***********************************************************************
2240 * WindowPosChanging (X11DRV.@)
2242 void CDECL
X11DRV_WindowPosChanging( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
2243 const RECT
*window_rect
, const RECT
*client_rect
, RECT
*visible_rect
,
2244 struct window_surface
**surface
)
2246 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2250 BOOL layered
= GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYERED
;
2252 if (!data
&& !(data
= X11DRV_create_win_data( hwnd
, window_rect
, client_rect
))) return;
2254 /* check if we need to switch the window to managed */
2255 if (!data
->managed
&& data
->whole_window
&& is_window_managed( hwnd
, swp_flags
, window_rect
))
2257 TRACE( "making win %p/%lx managed\n", hwnd
, data
->whole_window
);
2258 release_win_data( data
);
2259 unmap_window( hwnd
);
2260 if (!(data
= get_win_data( hwnd
))) return;
2261 data
->managed
= TRUE
;
2264 *visible_rect
= *window_rect
;
2265 X11DRV_window_to_X_rect( data
, visible_rect
);
2267 /* create the window surface if necessary */
2269 if (!data
->whole_window
&& !data
->embedded
) goto done
;
2270 if (swp_flags
& SWP_HIDEWINDOW
) goto done
;
2271 if (data
->use_alpha
) goto done
;
2272 if (!get_surface_rect( visible_rect
, &surface_rect
)) goto done
;
2274 if (*surface
) window_surface_release( *surface
);
2275 *surface
= NULL
; /* indicate that we want to draw directly to the window */
2277 if (data
->embedded
) goto done
;
2278 if (data
->whole_window
== root_window
) goto done
;
2279 if (data
->client_window
) goto done
;
2280 if (!client_side_graphics
&& !layered
) goto done
;
2284 if (EqualRect( &data
->surface
->rect
, &surface_rect
))
2286 /* existing surface is good enough */
2287 window_surface_add_ref( data
->surface
);
2288 *surface
= data
->surface
;
2292 else if (!(swp_flags
& SWP_SHOWWINDOW
) && !(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)) goto done
;
2294 if (!layered
|| !GetLayeredWindowAttributes( hwnd
, &key
, NULL
, &flags
) || !(flags
& LWA_COLORKEY
))
2297 *surface
= create_surface( data
->whole_window
, &data
->vis
, &surface_rect
, key
, FALSE
);
2300 release_win_data( data
);
2304 /***********************************************************************
2305 * WindowPosChanged (X11DRV.@)
2307 void CDECL
X11DRV_WindowPosChanged( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
2308 const RECT
*rectWindow
, const RECT
*rectClient
,
2309 const RECT
*visible_rect
, const RECT
*valid_rects
,
2310 struct window_surface
*surface
)
2312 struct x11drv_thread_data
*thread_data
;
2313 struct x11drv_win_data
*data
;
2314 DWORD new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2315 RECT old_window_rect
, old_whole_rect
, old_client_rect
;
2318 if (!(data
= get_win_data( hwnd
))) return;
2320 thread_data
= x11drv_thread_data();
2322 old_window_rect
= data
->window_rect
;
2323 old_whole_rect
= data
->whole_rect
;
2324 old_client_rect
= data
->client_rect
;
2325 data
->window_rect
= *rectWindow
;
2326 data
->whole_rect
= *visible_rect
;
2327 data
->client_rect
= *rectClient
;
2328 if (data
->vis
.visualid
== default_visual
.visualid
)
2330 if (surface
) window_surface_add_ref( surface
);
2331 if (data
->surface
) window_surface_release( data
->surface
);
2332 data
->surface
= surface
;
2335 TRACE( "win %p window %s client %s style %08x flags %08x\n",
2336 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
, swp_flags
);
2338 if (!IsRectEmpty( &valid_rects
[0] ))
2340 Window window
= data
->whole_window
;
2341 int x_offset
= old_whole_rect
.left
- data
->whole_rect
.left
;
2342 int y_offset
= old_whole_rect
.top
- data
->whole_rect
.top
;
2344 /* if all that happened is that the whole window moved, copy everything */
2345 if (!(swp_flags
& SWP_FRAMECHANGED
) &&
2346 old_whole_rect
.right
- data
->whole_rect
.right
== x_offset
&&
2347 old_whole_rect
.bottom
- data
->whole_rect
.bottom
== y_offset
&&
2348 old_client_rect
.left
- data
->client_rect
.left
== x_offset
&&
2349 old_client_rect
.right
- data
->client_rect
.right
== x_offset
&&
2350 old_client_rect
.top
- data
->client_rect
.top
== y_offset
&&
2351 old_client_rect
.bottom
- data
->client_rect
.bottom
== y_offset
&&
2352 EqualRect( &valid_rects
[0], &data
->client_rect
))
2354 /* if we have an X window the bits will be moved by the X server */
2355 if (!window
&& (x_offset
!= 0 || y_offset
!= 0))
2357 release_win_data( data
);
2358 move_window_bits( hwnd
, window
, &old_whole_rect
, visible_rect
,
2359 &old_client_rect
, rectClient
, rectWindow
);
2360 if (!(data
= get_win_data( hwnd
))) return;
2365 release_win_data( data
);
2366 move_window_bits( hwnd
, window
, &valid_rects
[1], &valid_rects
[0],
2367 &old_client_rect
, rectClient
, rectWindow
);
2368 if (!(data
= get_win_data( hwnd
))) return;
2372 XFlush( gdi_display
); /* make sure painting is done before we move the window */
2374 sync_client_position( data
, &old_client_rect
, &old_whole_rect
);
2376 if (!data
->whole_window
)
2378 BOOL needs_resize
= (!data
->client_window
&&
2379 (data
->client_rect
.right
- data
->client_rect
.left
!=
2380 old_client_rect
.right
- old_client_rect
.left
||
2381 data
->client_rect
.bottom
- data
->client_rect
.top
!=
2382 old_client_rect
.bottom
- old_client_rect
.top
));
2383 release_win_data( data
);
2384 if (needs_resize
) sync_gl_drawable( hwnd
, FALSE
);
2388 /* check if we are currently processing an event relevant to this window */
2391 thread_data
->current_event
&&
2392 thread_data
->current_event
->xany
.window
== data
->whole_window
)
2394 event_type
= thread_data
->current_event
->type
;
2395 if (event_type
!= ConfigureNotify
&& event_type
!= PropertyNotify
&&
2396 event_type
!= GravityNotify
&& event_type
!= ReparentNotify
)
2397 event_type
= 0; /* ignore other events */
2400 if (data
->mapped
&& event_type
!= ReparentNotify
)
2402 if (((swp_flags
& SWP_HIDEWINDOW
) && !(new_style
& WS_VISIBLE
)) ||
2403 (!event_type
&& !(new_style
& WS_MINIMIZE
) &&
2404 !is_window_rect_mapped( rectWindow
) && is_window_rect_mapped( &old_window_rect
)))
2406 release_win_data( data
);
2407 unmap_window( hwnd
);
2408 if (is_window_rect_fullscreen( &old_window_rect
)) reset_clipping_window();
2409 if (!(data
= get_win_data( hwnd
))) return;
2413 /* don't change position if we are about to minimize or maximize a managed window */
2415 !(data
->managed
&& (swp_flags
& SWP_STATECHANGED
) && (new_style
& (WS_MINIMIZE
|WS_MAXIMIZE
))))
2416 sync_window_position( data
, swp_flags
, &old_window_rect
, &old_whole_rect
, &old_client_rect
);
2418 if ((new_style
& WS_VISIBLE
) &&
2419 ((new_style
& WS_MINIMIZE
) || is_window_rect_mapped( rectWindow
)))
2423 BOOL needs_icon
= !data
->icon_pixmap
;
2424 BOOL needs_map
= TRUE
;
2426 /* layered windows are mapped only once their attributes are set */
2427 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYERED
) needs_map
= data
->layered
;
2428 release_win_data( data
);
2429 if (needs_icon
) fetch_icon_data( hwnd
, 0, 0 );
2430 if (needs_map
) map_window( hwnd
, new_style
);
2433 else if ((swp_flags
& SWP_STATECHANGED
) && (!data
->iconic
!= !(new_style
& WS_MINIMIZE
)))
2435 set_wm_hints( data
);
2436 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
2437 TRACE( "changing win %p iconic state to %u\n", data
->hwnd
, data
->iconic
);
2439 XIconifyWindow( data
->display
, data
->whole_window
, data
->vis
.screen
);
2440 else if (is_window_rect_mapped( rectWindow
))
2441 XMapWindow( data
->display
, data
->whole_window
);
2442 update_net_wm_states( data
);
2446 if (swp_flags
& (SWP_FRAMECHANGED
|SWP_STATECHANGED
)) set_wm_hints( data
);
2447 if (!event_type
) update_net_wm_states( data
);
2451 XFlush( data
->display
); /* make sure changes are done before we start painting again */
2452 if (data
->surface
&& data
->vis
.visualid
!= default_visual
.visualid
)
2453 data
->surface
->funcs
->flush( data
->surface
);
2455 release_win_data( data
);
2458 /* check if the window icon should be hidden (i.e. moved off-screen) */
2459 static BOOL
hide_icon( struct x11drv_win_data
*data
)
2461 static const WCHAR trayW
[] = {'S','h','e','l','l','_','T','r','a','y','W','n','d',0};
2463 if (data
->managed
) return TRUE
;
2464 /* hide icons in desktop mode when the taskbar is active */
2465 if (root_window
== DefaultRootWindow( gdi_display
)) return FALSE
;
2466 return IsWindowVisible( FindWindowW( trayW
, NULL
));
2469 /***********************************************************************
2470 * ShowWindow (X11DRV.@)
2472 UINT CDECL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
, RECT
*rect
, UINT swp
)
2475 unsigned int width
, height
, border
, depth
;
2478 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2479 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2480 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2482 if (!data
|| !data
->whole_window
) goto done
;
2483 if (IsRectEmpty( rect
)) goto done
;
2484 if (style
& WS_MINIMIZE
)
2486 if (((rect
->left
!= -32000 || rect
->top
!= -32000)) && hide_icon( data
))
2488 OffsetRect( rect
, -32000 - rect
->left
, -32000 - rect
->top
);
2489 swp
&= ~(SWP_NOMOVE
| SWP_NOCLIENTMOVE
);
2493 if (!data
->managed
|| !data
->mapped
|| data
->iconic
) goto done
;
2495 /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */
2497 if (!thread_data
->current_event
|| thread_data
->current_event
->xany
.window
!= data
->whole_window
)
2500 if (thread_data
->current_event
->type
!= ConfigureNotify
&&
2501 thread_data
->current_event
->type
!= PropertyNotify
)
2504 TRACE( "win %p/%lx cmd %d at %s flags %08x\n",
2505 hwnd
, data
->whole_window
, cmd
, wine_dbgstr_rect(rect
), swp
);
2507 XGetGeometry( thread_data
->display
, data
->whole_window
,
2508 &root
, &x
, &y
, &width
, &height
, &border
, &depth
);
2509 XTranslateCoordinates( thread_data
->display
, data
->whole_window
, root
, 0, 0, &x
, &y
, &top
);
2510 pos
= root_to_virtual_screen( x
, y
);
2511 X11DRV_X_to_window_rect( data
, rect
, pos
.x
, pos
.y
, width
, height
);
2512 swp
&= ~(SWP_NOMOVE
| SWP_NOCLIENTMOVE
| SWP_NOSIZE
| SWP_NOCLIENTSIZE
);
2515 release_win_data( data
);
2520 /**********************************************************************
2521 * SetWindowIcon (X11DRV.@)
2523 * hIcon or hIconSm has changed (or is being initialised for the
2524 * first time). Complete the X11 driver-specific initialisation
2525 * and set the window hints.
2527 void CDECL
X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
2529 struct x11drv_win_data
*data
;
2531 if (!(data
= get_win_data( hwnd
))) return;
2532 if (!data
->whole_window
) goto done
;
2533 release_win_data( data
); /* release the lock, fetching the icon requires sending messages */
2535 if (type
== ICON_BIG
) fetch_icon_data( hwnd
, icon
, 0 );
2536 else fetch_icon_data( hwnd
, 0, icon
);
2538 if (!(data
= get_win_data( hwnd
))) return;
2539 set_wm_hints( data
);
2541 release_win_data( data
);
2545 /***********************************************************************
2546 * SetWindowRgn (X11DRV.@)
2548 * Assign specified region to window (for non-rectangular windows)
2550 void CDECL
X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
2552 struct x11drv_win_data
*data
;
2554 if ((data
= get_win_data( hwnd
)))
2556 sync_window_region( data
, hrgn
);
2557 release_win_data( data
);
2559 else if (X11DRV_get_whole_window( hwnd
))
2561 SendMessageW( hwnd
, WM_X11DRV_SET_WIN_REGION
, 0, 0 );
2566 /***********************************************************************
2567 * SetLayeredWindowAttributes (X11DRV.@)
2569 * Set transparency attributes for a layered window.
2571 void CDECL
X11DRV_SetLayeredWindowAttributes( HWND hwnd
, COLORREF key
, BYTE alpha
, DWORD flags
)
2573 struct x11drv_win_data
*data
= get_win_data( hwnd
);
2577 set_window_visual( data
, &default_visual
, FALSE
);
2579 if (data
->whole_window
)
2580 sync_window_opacity( data
->display
, data
->whole_window
, key
, alpha
, flags
);
2582 set_surface_color_key( data
->surface
, (flags
& LWA_COLORKEY
) ? key
: CLR_INVALID
);
2584 data
->layered
= TRUE
;
2585 if (!data
->mapped
) /* mapping is delayed until attributes are set */
2587 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
2589 if ((style
& WS_VISIBLE
) &&
2590 ((style
& WS_MINIMIZE
) || is_window_rect_mapped( &data
->window_rect
)))
2592 release_win_data( data
);
2593 map_window( hwnd
, style
);
2597 release_win_data( data
);
2601 Window win
= X11DRV_get_whole_window( hwnd
);
2604 sync_window_opacity( gdi_display
, win
, key
, alpha
, flags
);
2605 if (flags
& LWA_COLORKEY
)
2606 FIXME( "LWA_COLORKEY not supported on foreign process window %p\n", hwnd
);
2612 /*****************************************************************************
2613 * UpdateLayeredWindow (X11DRV.@)
2615 BOOL CDECL
X11DRV_UpdateLayeredWindow( HWND hwnd
, const UPDATELAYEREDWINDOWINFO
*info
,
2616 const RECT
*window_rect
)
2618 struct window_surface
*surface
;
2619 struct x11drv_win_data
*data
;
2620 BLENDFUNCTION blend
= { AC_SRC_OVER
, 0, 255, 0 };
2621 COLORREF color_key
= (info
->dwFlags
& ULW_COLORKEY
) ? info
->crKey
: CLR_INVALID
;
2622 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
2623 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
2624 void *src_bits
, *dst_bits
;
2625 RECT rect
, src_rect
;
2630 if (!(data
= get_win_data( hwnd
))) return FALSE
;
2632 data
->layered
= TRUE
;
2633 if (!data
->embedded
&& argb_visual
.visualid
) set_window_visual( data
, &argb_visual
, TRUE
);
2635 rect
= *window_rect
;
2636 OffsetRect( &rect
, -window_rect
->left
, -window_rect
->top
);
2638 surface
= data
->surface
;
2639 if (!surface
|| !EqualRect( &surface
->rect
, &rect
))
2641 data
->surface
= create_surface( data
->whole_window
, &data
->vis
, &rect
,
2642 color_key
, data
->use_alpha
);
2643 if (surface
) window_surface_release( surface
);
2644 surface
= data
->surface
;
2646 else set_surface_color_key( surface
, color_key
);
2648 if (surface
) window_surface_add_ref( surface
);
2649 release_win_data( data
);
2651 if (!surface
) return FALSE
;
2654 window_surface_release( surface
);
2658 dst_bits
= surface
->funcs
->get_info( surface
, bmi
);
2660 if (!(dib
= CreateDIBSection( info
->hdcDst
, bmi
, DIB_RGB_COLORS
, &src_bits
, NULL
, 0 ))) goto done
;
2661 if (!(hdc
= CreateCompatibleDC( 0 ))) goto done
;
2663 SelectObject( hdc
, dib
);
2665 surface
->funcs
->lock( surface
);
2669 IntersectRect( &rect
, &rect
, info
->prcDirty
);
2670 memcpy( src_bits
, dst_bits
, bmi
->bmiHeader
.biSizeImage
);
2671 PatBlt( hdc
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, BLACKNESS
);
2674 if (info
->pptSrc
) OffsetRect( &src_rect
, info
->pptSrc
->x
, info
->pptSrc
->y
);
2675 DPtoLP( info
->hdcSrc
, (POINT
*)&src_rect
, 2 );
2677 ret
= GdiAlphaBlend( hdc
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2678 info
->hdcSrc
, src_rect
.left
, src_rect
.top
,
2679 src_rect
.right
- src_rect
.left
, src_rect
.bottom
- src_rect
.top
,
2680 (info
->dwFlags
& ULW_ALPHA
) ? *info
->pblend
: blend
);
2683 memcpy( dst_bits
, src_bits
, bmi
->bmiHeader
.biSizeImage
);
2684 add_bounds_rect( surface
->funcs
->get_bounds( surface
), &rect
);
2687 surface
->funcs
->unlock( surface
);
2688 surface
->funcs
->flush( surface
);
2691 window_surface_release( surface
);
2692 if (hdc
) DeleteDC( hdc
);
2693 if (dib
) DeleteObject( dib
);
2698 /**********************************************************************
2699 * X11DRV_WindowMessage (X11DRV.@)
2701 LRESULT CDECL
X11DRV_WindowMessage( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2703 struct x11drv_win_data
*data
;
2707 case WM_X11DRV_UPDATE_CLIPBOARD
:
2708 return update_clipboard( hwnd
);
2709 case WM_X11DRV_SET_WIN_REGION
:
2710 if ((data
= get_win_data( hwnd
)))
2712 sync_window_region( data
, (HRGN
)1 );
2713 release_win_data( data
);
2716 case WM_X11DRV_RESIZE_DESKTOP
:
2717 X11DRV_resize_desktop( LOWORD(lp
), HIWORD(lp
) );
2719 case WM_X11DRV_SET_CURSOR
:
2720 if ((data
= get_win_data( hwnd
)))
2722 Window win
= data
->whole_window
;
2723 release_win_data( data
);
2724 if (win
) set_window_cursor( win
, (HCURSOR
)lp
);
2726 else if (hwnd
== x11drv_thread_data()->clip_hwnd
)
2727 set_window_cursor( x11drv_thread_data()->clip_window
, (HCURSOR
)lp
);
2729 case WM_X11DRV_CLIP_CURSOR
:
2730 return clip_cursor_notify( hwnd
, (HWND
)lp
);
2732 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg
, hwnd
, wp
, lp
);
2738 /***********************************************************************
2739 * is_netwm_supported
2741 static BOOL
is_netwm_supported( Display
*display
, Atom atom
)
2743 static Atom
*net_supported
;
2744 static int net_supported_count
= -1;
2747 if (net_supported_count
== -1)
2751 unsigned long count
, remaining
;
2753 if (!XGetWindowProperty( display
, DefaultRootWindow(display
), x11drv_atom(_NET_SUPPORTED
), 0,
2754 ~0UL, False
, XA_ATOM
, &type
, &format
, &count
,
2755 &remaining
, (unsigned char **)&net_supported
))
2756 net_supported_count
= get_property_size( format
, count
) / sizeof(Atom
);
2758 net_supported_count
= 0;
2761 for (i
= 0; i
< net_supported_count
; i
++)
2762 if (net_supported
[i
] == atom
) return TRUE
;
2767 /***********************************************************************
2770 static LRESULT
start_screensaver(void)
2772 if (root_window
== DefaultRootWindow(gdi_display
))
2774 const char *argv
[3] = { "xdg-screensaver", "activate", NULL
};
2775 int pid
= _spawnvp( _P_DETACH
, argv
[0], argv
);
2778 TRACE( "started process %d\n", pid
);
2786 /***********************************************************************
2787 * SysCommand (X11DRV.@)
2789 * Perform WM_SYSCOMMAND handling.
2791 LRESULT CDECL
X11DRV_SysCommand( HWND hwnd
, WPARAM wparam
, LPARAM lparam
)
2793 WPARAM hittest
= wparam
& 0x0f;
2795 struct x11drv_win_data
*data
;
2797 if (!(data
= get_win_data( hwnd
)))
2799 if (wparam
== SC_SCREENSAVE
&& hwnd
== GetDesktopWindow()) return start_screensaver();
2802 if (!data
->whole_window
|| !data
->managed
|| !data
->mapped
) goto failed
;
2804 switch (wparam
& 0xfff0)
2807 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
2808 else dir
= _NET_WM_MOVERESIZE_MOVE
;
2811 /* windows without WS_THICKFRAME are not resizable through the window manager */
2812 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_THICKFRAME
)) goto failed
;
2816 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
2817 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
2818 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
2819 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
2820 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
2821 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
2822 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
2823 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
2824 default: dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
; break;
2829 /* prevent a simple ALT press+release from activating the system menu,
2830 * as that can get confusing on managed windows */
2831 if ((WCHAR
)lparam
) goto failed
; /* got an explicit char */
2832 if (GetMenu( hwnd
)) goto failed
; /* window has a real menu */
2833 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_SYSMENU
)) goto failed
; /* no system menu */
2834 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam
, lparam
);
2835 release_win_data( data
);
2842 if (IsZoomed(hwnd
)) goto failed
;
2844 if (!is_netwm_supported( data
->display
, x11drv_atom(_NET_WM_MOVERESIZE
) ))
2846 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
2850 release_win_data( data
);
2851 move_resize_window( hwnd
, dir
);
2855 release_win_data( data
);
2859 void CDECL
X11DRV_FlashWindowEx( PFLASHWINFO pfinfo
)
2861 struct x11drv_win_data
*data
= get_win_data( pfinfo
->hwnd
);
2869 xev
.type
= ClientMessage
;
2870 xev
.xclient
.window
= data
->whole_window
;
2871 xev
.xclient
.message_type
= x11drv_atom( _NET_WM_STATE
);
2872 xev
.xclient
.serial
= 0;
2873 xev
.xclient
.display
= data
->display
;
2874 xev
.xclient
.send_event
= True
;
2875 xev
.xclient
.format
= 32;
2876 xev
.xclient
.data
.l
[0] = pfinfo
->dwFlags
? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
2877 xev
.xclient
.data
.l
[1] = x11drv_atom( _NET_WM_STATE_DEMANDS_ATTENTION
);
2878 xev
.xclient
.data
.l
[2] = 0;
2879 xev
.xclient
.data
.l
[3] = 1;
2880 xev
.xclient
.data
.l
[4] = 0;
2882 XSendEvent( data
->display
, DefaultRootWindow( data
->display
), False
,
2883 SubstructureNotifyMask
, &xev
);
2885 release_win_data( data
);