windows.networking.hostname/tests: Check if passed HSTRING is duplicated.
[wine.git] / dlls / winex11.drv / window.c
blob9ada6a63d596fa9d380ead5d10d545e9c9c52990
1 /*
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
23 #if 0
24 #pragma makedep unix
25 #endif
27 #include "config.h"
29 #include <stdarg.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <unistd.h>
34 #include <X11/Xlib.h>
35 #include <X11/Xresource.h>
36 #include <X11/Xutil.h>
37 #ifdef HAVE_LIBXSHAPE
38 #include <X11/extensions/shape.h>
39 #endif /* HAVE_LIBXSHAPE */
40 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
41 #include <X11/extensions/XInput2.h>
42 #endif
44 /* avoid conflict with field names in included win32 headers */
45 #undef Status
47 #include "ntstatus.h"
48 #define WIN32_NO_STATUS
50 #include "x11drv.h"
51 #include "wingdi.h"
52 #include "winuser.h"
54 #include "wine/debug.h"
55 #include "wine/server.h"
56 #include "mwm.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
59 WINE_DECLARE_DEBUG_CHANNEL(systray);
61 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
62 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
63 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
64 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
65 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
66 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
67 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
68 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
69 #define _NET_WM_MOVERESIZE_MOVE 8
70 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9
71 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10
73 #define _NET_WM_STATE_REMOVE 0
74 #define _NET_WM_STATE_ADD 1
75 #define _NET_WM_STATE_TOGGLE 2
77 #define SYSTEM_TRAY_REQUEST_DOCK 0
78 #define SYSTEM_TRAY_BEGIN_MESSAGE 1
79 #define SYSTEM_TRAY_CANCEL_MESSAGE 2
81 static const unsigned int net_wm_state_atoms[NB_NET_WM_STATES] =
83 XATOM__KDE_NET_WM_STATE_SKIP_SWITCHER,
84 XATOM__NET_WM_STATE_FULLSCREEN,
85 XATOM__NET_WM_STATE_ABOVE,
86 XATOM__NET_WM_STATE_MAXIMIZED_VERT,
87 XATOM__NET_WM_STATE_SKIP_PAGER,
88 XATOM__NET_WM_STATE_SKIP_TASKBAR
91 #define SWP_AGG_NOPOSCHANGE (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
93 /* is cursor clipping active? */
94 BOOL clipping_cursor = FALSE;
96 /* X context to associate a hwnd to an X window */
97 XContext winContext = 0;
99 /* X context to associate a struct x11drv_win_data to an hwnd */
100 static XContext win_data_context = 0;
102 /* time of last user event and window where it's stored */
103 static Time last_user_time;
104 static Window user_time_window;
106 static const WCHAR foreign_window_prop[] =
107 {'_','_','w','i','n','e','_','x','1','1','_','f','o','r','e','i','g','n','_','w','i','n','d','o','w',0};
108 static const WCHAR whole_window_prop[] =
109 {'_','_','w','i','n','e','_','x','1','1','_','w','h','o','l','e','_','w','i','n','d','o','w',0};
110 static const WCHAR clip_window_prop[] =
111 {'_','_','w','i','n','e','_','x','1','1','_','c','l','i','p','_','w','i','n','d','o','w',0};
113 static pthread_mutex_t win_data_mutex = PTHREAD_MUTEX_INITIALIZER;
116 /***********************************************************************
117 * http://standards.freedesktop.org/startup-notification-spec
119 static void remove_startup_notification(Display *display, Window window)
121 static LONG startup_notification_removed = 0;
122 char message[1024];
123 const char *id;
124 int i;
125 int pos;
126 XEvent xevent;
127 const char *src;
128 int srclen;
130 if (InterlockedCompareExchange(&startup_notification_removed, 1, 0) != 0)
131 return;
133 if (!(id = getenv( "DESKTOP_STARTUP_ID" )) || !id[0]) return;
135 if ((src = strstr( id, "_TIME" ))) update_user_time( atol( src + 5 ));
137 pos = snprintf(message, sizeof(message), "remove: ID=");
138 message[pos++] = '"';
139 for (i = 0; id[i] && pos < sizeof(message) - 3; i++)
141 if (id[i] == '"' || id[i] == '\\')
142 message[pos++] = '\\';
143 message[pos++] = id[i];
145 message[pos++] = '"';
146 message[pos++] = '\0';
147 unsetenv( "DESKTOP_STARTUP_ID" );
149 xevent.xclient.type = ClientMessage;
150 xevent.xclient.message_type = x11drv_atom(_NET_STARTUP_INFO_BEGIN);
151 xevent.xclient.display = display;
152 xevent.xclient.window = window;
153 xevent.xclient.format = 8;
155 src = message;
156 srclen = strlen(src) + 1;
158 while (srclen > 0)
160 int msglen = srclen;
161 if (msglen > 20)
162 msglen = 20;
163 memset(&xevent.xclient.data.b[0], 0, 20);
164 memcpy(&xevent.xclient.data.b[0], src, msglen);
165 src += msglen;
166 srclen -= msglen;
168 XSendEvent( display, DefaultRootWindow( display ), False, PropertyChangeMask, &xevent );
169 xevent.xclient.message_type = x11drv_atom(_NET_STARTUP_INFO);
174 static BOOL is_managed( HWND hwnd )
176 struct x11drv_win_data *data = get_win_data( hwnd );
177 BOOL ret = data && data->managed;
178 release_win_data( data );
179 return ret;
182 HWND *build_hwnd_list(void)
184 NTSTATUS status;
185 HWND *list;
186 ULONG count = 128;
188 for (;;)
190 if (!(list = malloc( count * sizeof(*list) ))) return NULL;
191 status = NtUserBuildHwndList( 0, 0, 0, 0, 0, count, list, &count );
192 if (!status) return list;
193 free( list );
194 if (status != STATUS_BUFFER_TOO_SMALL) return NULL;
198 static BOOL has_owned_popups( HWND hwnd )
200 HWND *list;
201 UINT i;
202 BOOL ret = FALSE;
204 if (!(list = build_hwnd_list())) return FALSE;
206 for (i = 0; list[i] != HWND_BOTTOM; i++)
208 if (list[i] == hwnd) break; /* popups are always above owner */
209 if (NtUserGetWindowRelative( list[i], GW_OWNER ) != hwnd) continue;
210 if ((ret = is_managed( list[i] ))) break;
213 free( list );
214 return ret;
218 /***********************************************************************
219 * alloc_win_data
221 static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
223 struct x11drv_win_data *data;
225 if ((data = calloc( 1, sizeof(*data) )))
227 data->display = display;
228 data->vis = default_visual;
229 data->hwnd = hwnd;
230 pthread_mutex_lock( &win_data_mutex );
231 XSaveContext( gdi_display, (XID)hwnd, win_data_context, (char *)data );
233 return data;
237 /***********************************************************************
238 * is_window_managed
240 * Check if a given window should be managed
242 static BOOL is_window_managed( HWND hwnd, UINT swp_flags, const RECT *window_rect )
244 DWORD style, ex_style;
246 if (!managed_mode) return FALSE;
248 /* child windows are not managed */
249 style = NtUserGetWindowLongW( hwnd, GWL_STYLE );
250 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD) return FALSE;
251 /* activated windows are managed */
252 if (!(swp_flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) return TRUE;
253 if (hwnd == get_active_window()) return TRUE;
254 /* windows with caption are managed */
255 if ((style & WS_CAPTION) == WS_CAPTION) return TRUE;
256 /* windows with thick frame are managed */
257 if (style & WS_THICKFRAME) return TRUE;
258 if (style & WS_POPUP)
260 HMONITOR hmon;
261 MONITORINFO mi;
263 /* popup with sysmenu == caption are managed */
264 if (style & WS_SYSMENU) return TRUE;
265 /* full-screen popup windows are managed */
266 hmon = NtUserMonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY );
267 mi.cbSize = sizeof( mi );
268 NtUserGetMonitorInfo( hmon, &mi );
269 if (window_rect->left <= mi.rcWork.left && window_rect->right >= mi.rcWork.right &&
270 window_rect->top <= mi.rcWork.top && window_rect->bottom >= mi.rcWork.bottom)
271 return TRUE;
273 /* application windows are managed */
274 ex_style = NtUserGetWindowLongW( hwnd, GWL_EXSTYLE );
275 if (ex_style & WS_EX_APPWINDOW) return TRUE;
276 /* windows that own popups are managed */
277 if (has_owned_popups( hwnd )) return TRUE;
278 /* default: not managed */
279 return FALSE;
283 /***********************************************************************
284 * is_window_resizable
286 * Check if window should be made resizable by the window manager
288 static inline BOOL is_window_resizable( struct x11drv_win_data *data, DWORD style )
290 if (style & WS_THICKFRAME) return TRUE;
291 /* Metacity needs the window to be resizable to make it fullscreen */
292 return NtUserIsWindowRectFullScreen( &data->whole_rect );
295 /***********************************************************************
296 * get_mwm_decorations
298 static unsigned long get_mwm_decorations( struct x11drv_win_data *data,
299 DWORD style, DWORD ex_style,
300 const RECT *window_rect,
301 const RECT *client_rect )
303 unsigned long ret = 0;
305 if (!decorated_mode) return 0;
307 if (EqualRect( window_rect, client_rect )) return 0;
308 if (IsRectEmpty( window_rect )) return 0;
309 if (data->shaped) return 0;
311 if (ex_style & WS_EX_TOOLWINDOW) return 0;
312 if (ex_style & WS_EX_LAYERED) return 0;
314 if ((style & WS_CAPTION) == WS_CAPTION)
316 ret |= MWM_DECOR_TITLE | MWM_DECOR_BORDER;
317 if (style & WS_SYSMENU) ret |= MWM_DECOR_MENU;
318 if (style & WS_MINIMIZEBOX) ret |= MWM_DECOR_MINIMIZE;
319 if (style & WS_MAXIMIZEBOX) ret |= MWM_DECOR_MAXIMIZE;
321 if (ex_style & WS_EX_DLGMODALFRAME) ret |= MWM_DECOR_BORDER;
322 else if (style & WS_THICKFRAME) ret |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
323 else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) ret |= MWM_DECOR_BORDER;
324 return ret;
328 /***********************************************************************
329 * get_window_attributes
331 * Fill the window attributes structure for an X window.
333 static int get_window_attributes( struct x11drv_win_data *data, XSetWindowAttributes *attr )
335 attr->override_redirect = !data->managed;
336 attr->colormap = data->whole_colormap ? data->whole_colormap : default_colormap;
337 attr->save_under = ((NtUserGetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0);
338 attr->bit_gravity = NorthWestGravity;
339 attr->backing_store = NotUseful;
340 attr->border_pixel = 0;
341 attr->event_mask = (ExposureMask | PointerMotionMask |
342 ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
343 KeyPressMask | KeyReleaseMask | FocusChangeMask |
344 KeymapStateMask | StructureNotifyMask);
345 if (data->managed) attr->event_mask |= PropertyChangeMask;
347 return (CWOverrideRedirect | CWSaveUnder | CWColormap | CWBorderPixel |
348 CWEventMask | CWBitGravity | CWBackingStore);
352 /***********************************************************************
353 * sync_window_style
355 * Change the X window attributes when the window style has changed.
357 static void sync_window_style( struct x11drv_win_data *data )
359 if (data->whole_window != root_window)
361 XSetWindowAttributes attr;
362 int mask = get_window_attributes( data, &attr );
364 XChangeWindowAttributes( data->display, data->whole_window, mask, &attr );
369 /***********************************************************************
370 * sync_window_region
372 * Update the X11 window region.
374 static void sync_window_region( struct x11drv_win_data *data, HRGN win_region )
376 #ifdef HAVE_LIBXSHAPE
377 HRGN hrgn = win_region;
379 if (!data->whole_window) return;
380 data->shaped = FALSE;
382 if (IsRectEmpty( &data->window_rect )) /* set an empty shape */
384 static XRectangle empty_rect;
385 XShapeCombineRectangles( data->display, data->whole_window, ShapeBounding, 0, 0,
386 &empty_rect, 1, ShapeSet, YXBanded );
387 return;
390 if (hrgn == (HRGN)1) /* hack: win_region == 1 means retrieve region from server */
392 if (!(hrgn = NtGdiCreateRectRgn( 0, 0, 0, 0 ))) return;
393 if (NtUserGetWindowRgnEx( data->hwnd, hrgn, 0 ) == ERROR)
395 NtGdiDeleteObjectApp( hrgn );
396 hrgn = 0;
400 if (!hrgn)
402 XShapeCombineMask( data->display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet );
404 else
406 RGNDATA *pRegionData;
408 if (NtUserGetWindowLongW( data->hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL)
409 NtUserMirrorRgn( data->hwnd, hrgn );
410 if ((pRegionData = X11DRV_GetRegionData( hrgn, 0 )))
412 XShapeCombineRectangles( data->display, data->whole_window, ShapeBounding,
413 data->window_rect.left - data->whole_rect.left,
414 data->window_rect.top - data->whole_rect.top,
415 (XRectangle *)pRegionData->Buffer,
416 pRegionData->rdh.nCount, ShapeSet, YXBanded );
417 free( pRegionData );
418 data->shaped = TRUE;
421 if (hrgn && hrgn != win_region) NtGdiDeleteObjectApp( hrgn );
422 #endif /* HAVE_LIBXSHAPE */
426 /***********************************************************************
427 * sync_window_opacity
429 static void sync_window_opacity( Display *display, Window win,
430 COLORREF key, BYTE alpha, DWORD flags )
432 unsigned long opacity = 0xffffffff;
434 if (flags & LWA_ALPHA) opacity = (0xffffffff / 0xff) * alpha;
436 if (opacity == 0xffffffff)
437 XDeleteProperty( display, win, x11drv_atom(_NET_WM_WINDOW_OPACITY) );
438 else
439 XChangeProperty( display, win, x11drv_atom(_NET_WM_WINDOW_OPACITY),
440 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&opacity, 1 );
444 /***********************************************************************
445 * sync_window_text
447 static void sync_window_text( Display *display, Window win, const WCHAR *text )
449 DWORD count, len;
450 char *buffer, *utf8_buffer;
451 XTextProperty prop;
453 /* allocate new buffer for window text */
454 len = lstrlenW( text );
455 count = len * 3 + 1;
456 if (!(buffer = malloc( count ))) return;
457 ntdll_wcstoumbs( text, len + 1, buffer, count, FALSE );
459 RtlUnicodeToUTF8N( NULL, 0, &count, text, len * sizeof(WCHAR) );
460 if (!(utf8_buffer = malloc( count )))
462 free( buffer );
463 return;
465 RtlUnicodeToUTF8N( utf8_buffer, count, &count, text, len * sizeof(WCHAR) );
467 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
469 XSetWMName( display, win, &prop );
470 XSetWMIconName( display, win, &prop );
471 XFree( prop.value );
474 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
475 according to the standard
476 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
478 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
479 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
481 free( utf8_buffer );
482 free( buffer );
486 /***********************************************************************
487 * get_bitmap_argb
489 * Return the bitmap bits in ARGB format. Helper for setting icon hints.
491 static unsigned long *get_bitmap_argb( HDC hdc, HBITMAP color, HBITMAP mask, unsigned int *size )
493 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
494 BITMAPINFO *info = (BITMAPINFO *)buffer;
495 BITMAP bm;
496 unsigned int *ptr, *bits = NULL;
497 unsigned char *mask_bits = NULL;
498 int i, j;
499 BOOL has_alpha = FALSE;
501 if (!NtGdiExtGetObjectW( color, sizeof(bm), &bm )) return NULL;
502 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
503 info->bmiHeader.biWidth = bm.bmWidth;
504 info->bmiHeader.biHeight = -bm.bmHeight;
505 info->bmiHeader.biPlanes = 1;
506 info->bmiHeader.biBitCount = 32;
507 info->bmiHeader.biCompression = BI_RGB;
508 info->bmiHeader.biSizeImage = bm.bmWidth * bm.bmHeight * 4;
509 info->bmiHeader.biXPelsPerMeter = 0;
510 info->bmiHeader.biYPelsPerMeter = 0;
511 info->bmiHeader.biClrUsed = 0;
512 info->bmiHeader.biClrImportant = 0;
513 *size = bm.bmWidth * bm.bmHeight + 2;
514 if (!(bits = malloc( *size * sizeof(long) ))) goto failed;
515 if (!NtGdiGetDIBitsInternal( hdc, color, 0, bm.bmHeight, bits + 2, info, DIB_RGB_COLORS, 0, 0 ))
516 goto failed;
518 bits[0] = bm.bmWidth;
519 bits[1] = bm.bmHeight;
521 for (i = 0; i < bm.bmWidth * bm.bmHeight; i++)
522 if ((has_alpha = (bits[i + 2] & 0xff000000) != 0)) break;
524 if (!has_alpha)
526 unsigned int width_bytes = (bm.bmWidth + 31) / 32 * 4;
527 /* generate alpha channel from the mask */
528 info->bmiHeader.biBitCount = 1;
529 info->bmiHeader.biSizeImage = width_bytes * bm.bmHeight;
530 if (!(mask_bits = malloc( info->bmiHeader.biSizeImage ))) goto failed;
531 if (!NtGdiGetDIBitsInternal( hdc, mask, 0, bm.bmHeight, mask_bits, info, DIB_RGB_COLORS, 0, 0 ))
532 goto failed;
533 ptr = bits + 2;
534 for (i = 0; i < bm.bmHeight; i++)
535 for (j = 0; j < bm.bmWidth; j++, ptr++)
536 if (!((mask_bits[i * width_bytes + j / 8] << (j % 8)) & 0x80)) *ptr |= 0xff000000;
537 free( mask_bits );
540 /* convert to array of longs */
541 if (bits && sizeof(long) > sizeof(int))
542 for (i = *size - 1; i >= 0; i--) ((unsigned long *)bits)[i] = bits[i];
544 return (unsigned long *)bits;
546 failed:
547 free( bits );
548 free( mask_bits );
549 return NULL;
553 /***********************************************************************
554 * create_icon_pixmaps
556 static BOOL create_icon_pixmaps( HDC hdc, const ICONINFO *icon, Pixmap *icon_ret, Pixmap *mask_ret )
558 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
559 BITMAPINFO *info = (BITMAPINFO *)buffer;
560 XVisualInfo vis = default_visual;
561 struct gdi_image_bits bits;
562 Pixmap color_pixmap = 0, mask_pixmap = 0;
563 int lines;
564 unsigned int i;
566 bits.ptr = NULL;
567 bits.free = NULL;
568 bits.is_copy = TRUE;
570 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
571 info->bmiHeader.biBitCount = 0;
572 if (!(lines = NtGdiGetDIBitsInternal( hdc, icon->hbmColor, 0, 0, NULL, info, DIB_RGB_COLORS, 0, 0 )))
573 goto failed;
574 if (!(bits.ptr = malloc( info->bmiHeader.biSizeImage ))) goto failed;
575 if (!NtGdiGetDIBitsInternal( hdc, icon->hbmColor, 0, lines, bits.ptr, info, DIB_RGB_COLORS, 0, 0 ))
576 goto failed;
578 color_pixmap = create_pixmap_from_image( hdc, &vis, info, &bits, DIB_RGB_COLORS );
579 free( bits.ptr );
580 bits.ptr = NULL;
581 if (!color_pixmap) goto failed;
583 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
584 info->bmiHeader.biBitCount = 0;
585 if (!(lines = NtGdiGetDIBitsInternal( hdc, icon->hbmMask, 0, 0, NULL, info, DIB_RGB_COLORS, 0, 0 )))
586 goto failed;
587 if (!(bits.ptr = malloc( info->bmiHeader.biSizeImage ))) goto failed;
588 if (!NtGdiGetDIBitsInternal( hdc, icon->hbmMask, 0, lines, bits.ptr, info, DIB_RGB_COLORS, 0, 0 ))
589 goto failed;
591 /* invert the mask */
592 for (i = 0; i < info->bmiHeader.biSizeImage / sizeof(DWORD); i++) ((DWORD *)bits.ptr)[i] ^= ~0u;
594 vis.depth = 1;
595 mask_pixmap = create_pixmap_from_image( hdc, &vis, info, &bits, DIB_RGB_COLORS );
596 free( bits.ptr );
597 bits.ptr = NULL;
598 if (!mask_pixmap) goto failed;
600 *icon_ret = color_pixmap;
601 *mask_ret = mask_pixmap;
602 return TRUE;
604 failed:
605 if (color_pixmap) XFreePixmap( gdi_display, color_pixmap );
606 free( bits.ptr );
607 return FALSE;
611 static HICON get_icon_info( HICON icon, ICONINFO *ii )
613 return icon && NtUserGetIconInfo( icon, ii, NULL, NULL, NULL, 0 ) ? icon : NULL;
616 /***********************************************************************
617 * fetch_icon_data
619 static void fetch_icon_data( HWND hwnd, HICON icon_big, HICON icon_small )
621 struct x11drv_win_data *data;
622 ICONINFO ii, ii_small;
623 HDC hDC;
624 unsigned int size;
625 unsigned long *bits;
626 Pixmap icon_pixmap, mask_pixmap;
628 icon_big = get_icon_info( icon_big, &ii );
629 if (!icon_big)
631 icon_big = get_icon_info( (HICON)send_message( hwnd, WM_GETICON, ICON_BIG, 0 ), &ii );
632 if (!icon_big)
633 icon_big = get_icon_info( (HICON)NtUserGetClassLongPtrW( hwnd, GCLP_HICON ), &ii );
634 if (!icon_big)
636 icon_big = LoadImageW( 0, (const WCHAR *)IDI_WINLOGO, IMAGE_ICON, 0, 0,
637 LR_SHARED | LR_DEFAULTSIZE );
638 icon_big = get_icon_info( icon_big, &ii );
642 icon_small = get_icon_info( icon_small, &ii_small );
643 if (!icon_small)
645 icon_small = get_icon_info( (HICON)send_message( hwnd, WM_GETICON, ICON_SMALL, 0 ), &ii_small );
646 if (!icon_small)
647 icon_small = get_icon_info( (HICON)NtUserGetClassLongPtrW( hwnd, GCLP_HICONSM ), &ii_small );
650 if (!icon_big) return;
652 hDC = NtGdiCreateCompatibleDC(0);
653 bits = get_bitmap_argb( hDC, ii.hbmColor, ii.hbmMask, &size );
654 if (bits && icon_small)
656 unsigned int size_small;
657 unsigned long *bits_small, *new;
659 if ((bits_small = get_bitmap_argb( hDC, ii_small.hbmColor, ii_small.hbmMask, &size_small )) &&
660 (bits_small[0] != bits[0] || bits_small[1] != bits[1])) /* size must be different */
662 if ((new = realloc( bits, (size + size_small) * sizeof(unsigned long) )))
664 bits = new;
665 memcpy( bits + size, bits_small, size_small * sizeof(unsigned long) );
666 size += size_small;
669 free( bits_small );
670 NtGdiDeleteObjectApp( ii_small.hbmColor );
671 NtGdiDeleteObjectApp( ii_small.hbmMask );
674 if (!create_icon_pixmaps( hDC, &ii, &icon_pixmap, &mask_pixmap )) icon_pixmap = mask_pixmap = 0;
676 NtGdiDeleteObjectApp( ii.hbmColor );
677 NtGdiDeleteObjectApp( ii.hbmMask );
678 NtGdiDeleteObjectApp( hDC );
680 if ((data = get_win_data( hwnd )))
682 if (data->icon_pixmap) XFreePixmap( gdi_display, data->icon_pixmap );
683 if (data->icon_mask) XFreePixmap( gdi_display, data->icon_mask );
684 free( data->icon_bits );
685 data->icon_pixmap = icon_pixmap;
686 data->icon_mask = mask_pixmap;
687 data->icon_bits = bits;
688 data->icon_size = size;
689 release_win_data( data );
691 else
693 if (icon_pixmap) XFreePixmap( gdi_display, icon_pixmap );
694 if (mask_pixmap) XFreePixmap( gdi_display, mask_pixmap );
695 free( bits );
700 /***********************************************************************
701 * set_size_hints
703 * set the window size hints
705 static void set_size_hints( struct x11drv_win_data *data, DWORD style )
707 XSizeHints* size_hints;
709 if (!(size_hints = XAllocSizeHints())) return;
711 size_hints->win_gravity = StaticGravity;
712 size_hints->flags |= PWinGravity;
714 /* don't update size hints if window is not in normal state */
715 if (!(style & (WS_MINIMIZE | WS_MAXIMIZE)))
717 if (data->hwnd != NtUserGetDesktopWindow()) /* don't force position of desktop */
719 size_hints->x = data->whole_rect.left;
720 size_hints->y = data->whole_rect.top;
721 size_hints->flags |= PPosition;
723 else size_hints->win_gravity = NorthWestGravity;
725 if (!is_window_resizable( data, style ))
727 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
728 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
729 if (size_hints->max_width <= 0 ||size_hints->max_height <= 0)
730 size_hints->max_width = size_hints->max_height = 1;
731 size_hints->min_width = size_hints->max_width;
732 size_hints->min_height = size_hints->max_height;
733 size_hints->flags |= PMinSize | PMaxSize;
736 XSetWMNormalHints( data->display, data->whole_window, size_hints );
737 XFree( size_hints );
741 /***********************************************************************
742 * set_mwm_hints
744 static void set_mwm_hints( struct x11drv_win_data *data, UINT style, UINT ex_style )
746 MwmHints mwm_hints;
748 if (data->hwnd == NtUserGetDesktopWindow())
750 if (is_desktop_fullscreen()) mwm_hints.decorations = 0;
751 else mwm_hints.decorations = MWM_DECOR_TITLE | MWM_DECOR_BORDER | MWM_DECOR_MENU | MWM_DECOR_MINIMIZE;
752 mwm_hints.functions = MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE | MWM_FUNC_CLOSE;
754 else
756 mwm_hints.decorations = get_mwm_decorations( data, style, ex_style, &data->window_rect, &data->client_rect );
757 mwm_hints.functions = MWM_FUNC_MOVE;
758 if (is_window_resizable( data, style )) mwm_hints.functions |= MWM_FUNC_RESIZE;
759 if (!(style & WS_DISABLED))
761 mwm_hints.functions |= MWM_FUNC_CLOSE;
762 if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
763 if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
765 /* The window can be programmatically minimized even without
766 a minimize box button. Allow the WM to restore it. */
767 if (style & WS_MINIMIZE) mwm_hints.functions |= MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE;
771 TRACE( "%p setting mwm hints to %lx,%lx (style %x exstyle %x)\n",
772 data->hwnd, mwm_hints.decorations, mwm_hints.functions, style, ex_style );
774 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
775 mwm_hints.input_mode = 0;
776 mwm_hints.status = 0;
777 XChangeProperty( data->display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
778 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
779 (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
783 /***********************************************************************
784 * set_style_hints
786 static void set_style_hints( struct x11drv_win_data *data, DWORD style, DWORD ex_style )
788 Window group_leader = data->whole_window;
789 HWND owner = NtUserGetWindowRelative( data->hwnd, GW_OWNER );
790 Window owner_win = 0;
791 XWMHints *wm_hints;
792 Atom window_type;
794 if (owner)
796 owner = NtUserGetAncestor( owner, GA_ROOT );
797 owner_win = X11DRV_get_whole_window( owner );
800 if (owner_win)
802 XSetTransientForHint( data->display, data->whole_window, owner_win );
803 group_leader = owner_win;
806 /* Only use dialog type for owned popups. Metacity allows making fullscreen
807 * only normal windows, and doesn't handle correctly TRANSIENT_FOR hint for
808 * dialogs owned by fullscreen windows.
810 if (((style & WS_POPUP) || (ex_style & WS_EX_DLGMODALFRAME)) && owner)
811 window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
812 else
813 window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
815 XChangeProperty(data->display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
816 XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1);
818 if ((wm_hints = XAllocWMHints()))
820 wm_hints->flags = InputHint | StateHint | WindowGroupHint;
821 wm_hints->input = !use_take_focus && !(style & WS_DISABLED);
822 wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
823 wm_hints->window_group = group_leader;
824 if (data->icon_pixmap)
826 wm_hints->icon_pixmap = data->icon_pixmap;
827 wm_hints->icon_mask = data->icon_mask;
828 wm_hints->flags |= IconPixmapHint | IconMaskHint;
830 XSetWMHints( data->display, data->whole_window, wm_hints );
831 XFree( wm_hints );
834 if (data->icon_bits)
835 XChangeProperty( data->display, data->whole_window, x11drv_atom(_NET_WM_ICON),
836 XA_CARDINAL, 32, PropModeReplace,
837 (unsigned char *)data->icon_bits, data->icon_size );
838 else
839 XDeleteProperty( data->display, data->whole_window, x11drv_atom(_NET_WM_ICON) );
844 /***********************************************************************
845 * set_initial_wm_hints
847 * Set the window manager hints that don't change over the lifetime of a window.
849 static void set_initial_wm_hints( Display *display, Window window )
851 long i;
852 Atom protocols[3];
853 Atom dndVersion = WINE_XDND_VERSION;
854 XClassHint *class_hints;
856 /* wm protocols */
857 i = 0;
858 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
859 protocols[i++] = x11drv_atom(_NET_WM_PING);
860 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
861 XChangeProperty( display, window, x11drv_atom(WM_PROTOCOLS),
862 XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
864 /* class hints */
865 if ((class_hints = XAllocClassHint()))
867 class_hints->res_name = process_name;
868 class_hints->res_class = process_name;
869 XSetClassHint( display, window, class_hints );
870 XFree( class_hints );
873 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
874 XSetWMProperties(display, window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
875 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
876 i = getpid();
877 XChangeProperty(display, window, x11drv_atom(_NET_WM_PID),
878 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
880 XChangeProperty( display, window, x11drv_atom(XdndAware),
881 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
883 update_user_time( 0 ); /* make sure that the user time window exists */
884 if (user_time_window)
885 XChangeProperty( display, window, x11drv_atom(_NET_WM_USER_TIME_WINDOW),
886 XA_WINDOW, 32, PropModeReplace, (unsigned char *)&user_time_window, 1 );
890 /***********************************************************************
891 * make_owner_managed
893 * If the window is managed, make sure its owner window is too.
895 static void make_owner_managed( HWND hwnd )
897 HWND owner;
899 if (!(owner = NtUserGetWindowRelative( hwnd, GW_OWNER ))) return;
900 if (is_managed( owner )) return;
901 if (!is_managed( hwnd )) return;
903 NtUserSetWindowPos( owner, 0, 0, 0, 0, 0,
904 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE |
905 SWP_NOREDRAW | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_STATECHANGED );
909 /***********************************************************************
910 * set_wm_hints
912 * Set all the window manager hints for a window.
914 static void set_wm_hints( struct x11drv_win_data *data )
916 DWORD style, ex_style;
918 if (data->hwnd == NtUserGetDesktopWindow())
920 /* force some styles for the desktop to get the correct decorations */
921 style = WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
922 ex_style = WS_EX_APPWINDOW;
924 else
926 style = NtUserGetWindowLongW( data->hwnd, GWL_STYLE );
927 ex_style = NtUserGetWindowLongW( data->hwnd, GWL_EXSTYLE );
930 set_size_hints( data, style );
931 set_mwm_hints( data, style, ex_style );
932 set_style_hints( data, style, ex_style );
936 /***********************************************************************
937 * init_clip_window
939 Window init_clip_window(void)
941 struct x11drv_thread_data *data = x11drv_init_thread_data();
943 if (!data->clip_window &&
944 (data->clip_window = (Window)NtUserGetProp( NtUserGetDesktopWindow(), clip_window_prop )))
946 XSelectInput( data->display, data->clip_window, StructureNotifyMask );
948 return data->clip_window;
952 /***********************************************************************
953 * update_user_time
955 void update_user_time( Time time )
957 if (!user_time_window)
959 Window win = XCreateWindow( gdi_display, root_window, -1, -1, 1, 1, 0, CopyFromParent,
960 InputOnly, CopyFromParent, 0, NULL );
961 if (InterlockedCompareExchangePointer( (void **)&user_time_window, (void *)win, 0 ))
962 XDestroyWindow( gdi_display, win );
963 TRACE( "user time window %lx\n", user_time_window );
966 if (!time) return;
967 XLockDisplay( gdi_display );
968 if (!last_user_time || (long)(time - last_user_time) > 0)
970 last_user_time = time;
971 XChangeProperty( gdi_display, user_time_window, x11drv_atom(_NET_WM_USER_TIME),
972 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&time, 1 );
974 XUnlockDisplay( gdi_display );
977 /* Update _NET_WM_FULLSCREEN_MONITORS when _NET_WM_STATE_FULLSCREEN is set to support fullscreen
978 * windows spanning multiple monitors */
979 static void update_net_wm_fullscreen_monitors( struct x11drv_win_data *data )
981 long monitors[4];
982 XEvent xev;
984 if (!(data->net_wm_state & (1 << NET_WM_STATE_FULLSCREEN)) || is_virtual_desktop())
985 return;
987 /* If the current display device handler cannot detect dynamic device changes, do not use
988 * _NET_WM_FULLSCREEN_MONITORS because xinerama_get_fullscreen_monitors() may report wrong
989 * indices because of stale xinerama monitor information */
990 if (!X11DRV_DisplayDevices_SupportEventHandlers())
991 return;
993 if (!xinerama_get_fullscreen_monitors( &data->whole_rect, monitors ))
994 return;
996 if (!data->mapped)
998 XChangeProperty( data->display, data->whole_window, x11drv_atom(_NET_WM_FULLSCREEN_MONITORS),
999 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)monitors, 4 );
1001 else
1003 xev.xclient.type = ClientMessage;
1004 xev.xclient.window = data->whole_window;
1005 xev.xclient.message_type = x11drv_atom(_NET_WM_FULLSCREEN_MONITORS);
1006 xev.xclient.serial = 0;
1007 xev.xclient.display = data->display;
1008 xev.xclient.send_event = True;
1009 xev.xclient.format = 32;
1010 xev.xclient.data.l[4] = 1;
1011 memcpy( xev.xclient.data.l, monitors, sizeof(monitors) );
1012 XSendEvent( data->display, root_window, False,
1013 SubstructureRedirectMask | SubstructureNotifyMask, &xev );
1017 /***********************************************************************
1018 * update_net_wm_states
1020 void update_net_wm_states( struct x11drv_win_data *data )
1022 UINT i, style, ex_style, new_state = 0;
1024 if (!data->managed) return;
1025 if (data->whole_window == root_window) return;
1027 style = NtUserGetWindowLongW( data->hwnd, GWL_STYLE );
1028 if (style & WS_MINIMIZE)
1029 new_state |= data->net_wm_state & ((1 << NET_WM_STATE_FULLSCREEN)|(1 << NET_WM_STATE_MAXIMIZED));
1030 if (NtUserIsWindowRectFullScreen( &data->whole_rect ))
1032 if ((style & WS_MAXIMIZE) && (style & WS_CAPTION) == WS_CAPTION)
1033 new_state |= (1 << NET_WM_STATE_MAXIMIZED);
1034 else if (!(style & WS_MINIMIZE))
1035 new_state |= (1 << NET_WM_STATE_FULLSCREEN);
1037 else if (style & WS_MAXIMIZE)
1038 new_state |= (1 << NET_WM_STATE_MAXIMIZED);
1040 ex_style = NtUserGetWindowLongW( data->hwnd, GWL_EXSTYLE );
1041 if (ex_style & WS_EX_TOPMOST)
1042 new_state |= (1 << NET_WM_STATE_ABOVE);
1043 if (!data->add_taskbar)
1045 if (data->skip_taskbar || (ex_style & WS_EX_NOACTIVATE)
1046 || (ex_style & WS_EX_TOOLWINDOW && !(ex_style & WS_EX_APPWINDOW)))
1047 new_state |= (1 << NET_WM_STATE_SKIP_TASKBAR) | (1 << NET_WM_STATE_SKIP_PAGER) | (1 << KDE_NET_WM_STATE_SKIP_SWITCHER);
1048 else if (!(ex_style & WS_EX_APPWINDOW) && NtUserGetWindowRelative( data->hwnd, GW_OWNER ))
1049 new_state |= (1 << NET_WM_STATE_SKIP_TASKBAR);
1052 if (!data->mapped) /* set the _NET_WM_STATE atom directly */
1054 Atom atoms[NB_NET_WM_STATES+1];
1055 DWORD count;
1057 for (i = count = 0; i < NB_NET_WM_STATES; i++)
1059 if (!(new_state & (1 << i))) continue;
1060 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
1061 i, data->hwnd, data->whole_window );
1062 atoms[count++] = X11DRV_Atoms[net_wm_state_atoms[i] - FIRST_XATOM];
1063 if (net_wm_state_atoms[i] == XATOM__NET_WM_STATE_MAXIMIZED_VERT)
1064 atoms[count++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ);
1066 XChangeProperty( data->display, data->whole_window, x11drv_atom(_NET_WM_STATE), XA_ATOM,
1067 32, PropModeReplace, (unsigned char *)atoms, count );
1069 else /* ask the window manager to do it for us */
1071 XEvent xev;
1073 xev.xclient.type = ClientMessage;
1074 xev.xclient.window = data->whole_window;
1075 xev.xclient.message_type = x11drv_atom(_NET_WM_STATE);
1076 xev.xclient.serial = 0;
1077 xev.xclient.display = data->display;
1078 xev.xclient.send_event = True;
1079 xev.xclient.format = 32;
1080 xev.xclient.data.l[3] = 1;
1081 xev.xclient.data.l[4] = 0;
1083 for (i = 0; i < NB_NET_WM_STATES; i++)
1085 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1086 i, data->hwnd, data->whole_window,
1087 (new_state & (1 << i)) != 0, (data->net_wm_state & (1 << i)) != 0 );
1089 xev.xclient.data.l[0] = (new_state & (1 << i)) ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1090 xev.xclient.data.l[1] = X11DRV_Atoms[net_wm_state_atoms[i] - FIRST_XATOM];
1091 xev.xclient.data.l[2] = ((net_wm_state_atoms[i] == XATOM__NET_WM_STATE_MAXIMIZED_VERT) ?
1092 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ) : 0);
1093 XSendEvent( data->display, root_window, False,
1094 SubstructureRedirectMask | SubstructureNotifyMask, &xev );
1097 data->net_wm_state = new_state;
1098 update_net_wm_fullscreen_monitors( data );
1101 /***********************************************************************
1102 * read_net_wm_states
1104 void read_net_wm_states( Display* display, struct x11drv_win_data *data )
1106 Atom type, *state;
1107 int format;
1108 unsigned long i, j, count, remaining;
1109 DWORD new_state = 0;
1110 BOOL maximized_horz = FALSE;
1112 if (!data->whole_window) return;
1114 if (!XGetWindowProperty( display, data->whole_window, x11drv_atom(_NET_WM_STATE), 0,
1115 65536/sizeof(CARD32), False, XA_ATOM, &type, &format, &count,
1116 &remaining, (unsigned char **)&state ))
1118 if (type == XA_ATOM && format == 32)
1120 for (i = 0; i < count; i++)
1122 if (state[i] == x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ))
1123 maximized_horz = TRUE;
1124 for (j=0; j < NB_NET_WM_STATES; j++)
1126 if (state[i] == X11DRV_Atoms[net_wm_state_atoms[j] - FIRST_XATOM])
1128 new_state |= 1 << j;
1133 XFree( state );
1136 if (!maximized_horz)
1137 new_state &= ~(1 << NET_WM_STATE_MAXIMIZED);
1139 data->net_wm_state = new_state;
1143 /***********************************************************************
1144 * set_xembed_flags
1146 static void set_xembed_flags( struct x11drv_win_data *data, unsigned long flags )
1148 unsigned long info[2];
1150 if (!data->whole_window) return;
1152 info[0] = 0; /* protocol version */
1153 info[1] = flags;
1154 XChangeProperty( data->display, data->whole_window, x11drv_atom(_XEMBED_INFO),
1155 x11drv_atom(_XEMBED_INFO), 32, PropModeReplace, (unsigned char*)info, 2 );
1159 /***********************************************************************
1160 * map_window
1162 static void map_window( HWND hwnd, DWORD new_style )
1164 struct x11drv_win_data *data;
1166 make_owner_managed( hwnd );
1167 wait_for_withdrawn_state( hwnd, TRUE );
1169 if (!(data = get_win_data( hwnd ))) return;
1171 if (data->whole_window && !data->mapped)
1173 TRACE( "win %p/%lx\n", data->hwnd, data->whole_window );
1175 remove_startup_notification( data->display, data->whole_window );
1176 set_wm_hints( data );
1178 if (!data->embedded)
1180 update_net_wm_states( data );
1181 sync_window_style( data );
1182 XMapWindow( data->display, data->whole_window );
1183 XFlush( data->display );
1184 if (data->surface && data->vis.visualid != default_visual.visualid)
1185 data->surface->funcs->flush( data->surface );
1187 else set_xembed_flags( data, XEMBED_MAPPED );
1189 data->mapped = TRUE;
1190 data->iconic = (new_style & WS_MINIMIZE) != 0;
1191 update_net_wm_fullscreen_monitors( data );
1193 release_win_data( data );
1197 /***********************************************************************
1198 * unmap_window
1200 static void unmap_window( HWND hwnd )
1202 struct x11drv_win_data *data;
1204 wait_for_withdrawn_state( hwnd, FALSE );
1206 if (!(data = get_win_data( hwnd ))) return;
1208 if (data->mapped)
1210 TRACE( "win %p/%lx\n", data->hwnd, data->whole_window );
1212 if (data->embedded) set_xembed_flags( data, 0 );
1213 else if (!data->managed) XUnmapWindow( data->display, data->whole_window );
1214 else XWithdrawWindow( data->display, data->whole_window, data->vis.screen );
1216 data->mapped = FALSE;
1217 data->net_wm_state = 0;
1219 release_win_data( data );
1223 /***********************************************************************
1224 * make_window_embedded
1226 void make_window_embedded( struct x11drv_win_data *data )
1228 /* the window cannot be mapped before being embedded */
1229 if (data->mapped)
1231 if (!data->managed) XUnmapWindow( data->display, data->whole_window );
1232 else XWithdrawWindow( data->display, data->whole_window, data->vis.screen );
1233 data->net_wm_state = 0;
1235 data->embedded = TRUE;
1236 data->managed = TRUE;
1237 sync_window_style( data );
1238 set_xembed_flags( data, (data->mapped || data->embedder) ? XEMBED_MAPPED : 0 );
1242 /***********************************************************************
1243 * get_decoration_rect
1245 static void get_decoration_rect( struct x11drv_win_data *data, RECT *rect,
1246 const RECT *window_rect, const RECT *client_rect )
1248 DWORD style, ex_style, style_mask = 0, ex_style_mask = 0;
1249 unsigned long decor;
1251 SetRectEmpty( rect );
1252 if (!data->managed) return;
1254 style = NtUserGetWindowLongW( data->hwnd, GWL_STYLE );
1255 ex_style = NtUserGetWindowLongW( data->hwnd, GWL_EXSTYLE );
1256 decor = get_mwm_decorations( data, style, ex_style, window_rect, client_rect );
1258 if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION;
1259 if (decor & MWM_DECOR_BORDER)
1261 style_mask |= WS_DLGFRAME | WS_THICKFRAME;
1262 ex_style_mask |= WS_EX_DLGMODALFRAME;
1265 AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask );
1269 /***********************************************************************
1270 * X11DRV_window_to_X_rect
1272 * Convert a rect from client to X window coordinates
1274 static void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect,
1275 const RECT *window_rect, const RECT *client_rect )
1277 RECT rc;
1279 if (IsRectEmpty( rect )) return;
1281 get_decoration_rect( data, &rc, window_rect, client_rect );
1282 rect->left -= rc.left;
1283 rect->right -= rc.right;
1284 rect->top -= rc.top;
1285 rect->bottom -= rc.bottom;
1286 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1287 if (rect->left >= rect->right) rect->right = rect->left + 1;
1291 /***********************************************************************
1292 * X11DRV_X_to_window_rect
1294 * Opposite of X11DRV_window_to_X_rect
1296 void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect, int x, int y, int cx, int cy )
1298 RECT rc;
1300 get_decoration_rect( data, &rc, &data->window_rect, &data->client_rect );
1302 x += min( data->window_rect.left - data->whole_rect.left, rc.left );
1303 y += min( data->window_rect.top - data->whole_rect.top, rc.top );
1304 cx += max( (data->window_rect.right - data->window_rect.left) -
1305 (data->whole_rect.right - data->whole_rect.left), rc.right - rc.left );
1306 cy += max( (data->window_rect.bottom - data->window_rect.top) -
1307 (data->whole_rect.bottom - data->whole_rect.top), rc.bottom - rc.top );
1308 SetRect( rect, x, y, x + cx, y + cy );
1312 /***********************************************************************
1313 * sync_window_position
1315 * Synchronize the X window position with the Windows one
1317 static void sync_window_position( struct x11drv_win_data *data,
1318 UINT swp_flags, const RECT *old_window_rect,
1319 const RECT *old_whole_rect, const RECT *old_client_rect )
1321 DWORD style = NtUserGetWindowLongW( data->hwnd, GWL_STYLE );
1322 DWORD ex_style = NtUserGetWindowLongW( data->hwnd, GWL_EXSTYLE );
1323 XWindowChanges changes;
1324 unsigned int mask = 0;
1326 if (data->managed && data->iconic) return;
1328 /* resizing a managed maximized window is not allowed */
1329 if (!(style & WS_MAXIMIZE) || !data->managed)
1331 changes.width = data->whole_rect.right - data->whole_rect.left;
1332 changes.height = data->whole_rect.bottom - data->whole_rect.top;
1333 /* if window rect is empty force size to 1x1 */
1334 if (changes.width <= 0 || changes.height <= 0) changes.width = changes.height = 1;
1335 if (changes.width > 65535) changes.width = 65535;
1336 if (changes.height > 65535) changes.height = 65535;
1337 mask |= CWWidth | CWHeight;
1340 /* only the size is allowed to change for the desktop window */
1341 if (data->whole_window != root_window)
1343 POINT pt = virtual_screen_to_root( data->whole_rect.left, data->whole_rect.top );
1344 changes.x = pt.x;
1345 changes.y = pt.y;
1346 mask |= CWX | CWY;
1349 if (!(swp_flags & SWP_NOZORDER) || (swp_flags & SWP_SHOWWINDOW))
1351 /* find window that this one must be after */
1352 HWND prev = NtUserGetWindowRelative( data->hwnd, GW_HWNDPREV );
1353 while (prev && !(NtUserGetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
1354 prev = NtUserGetWindowRelative( prev, GW_HWNDPREV );
1355 if (!prev) /* top child */
1357 changes.stack_mode = Above;
1358 mask |= CWStackMode;
1360 /* should use stack_mode Below but most window managers don't get it right */
1361 /* and Above with a sibling doesn't work so well either, so we ignore it */
1364 set_size_hints( data, style );
1365 set_mwm_hints( data, style, ex_style );
1366 update_net_wm_states( data );
1367 data->configure_serial = NextRequest( data->display );
1368 XReconfigureWMWindow( data->display, data->whole_window, data->vis.screen, mask, &changes );
1369 #ifdef HAVE_LIBXSHAPE
1370 if (IsRectEmpty( old_window_rect ) != IsRectEmpty( &data->window_rect ))
1371 sync_window_region( data, (HRGN)1 );
1372 if (data->shaped)
1374 int old_x_offset = old_window_rect->left - old_whole_rect->left;
1375 int old_y_offset = old_window_rect->top - old_whole_rect->top;
1376 int new_x_offset = data->window_rect.left - data->whole_rect.left;
1377 int new_y_offset = data->window_rect.top - data->whole_rect.top;
1378 if (old_x_offset != new_x_offset || old_y_offset != new_y_offset)
1379 XShapeOffsetShape( data->display, data->whole_window, ShapeBounding,
1380 new_x_offset - old_x_offset, new_y_offset - old_y_offset );
1382 #endif
1384 TRACE( "win %p/%lx pos %d,%d,%dx%d after %lx changes=%x serial=%lu\n",
1385 data->hwnd, data->whole_window, (int)data->whole_rect.left, (int)data->whole_rect.top,
1386 (int)(data->whole_rect.right - data->whole_rect.left),
1387 (int)(data->whole_rect.bottom - data->whole_rect.top),
1388 changes.sibling, mask, data->configure_serial );
1392 /***********************************************************************
1393 * sync_client_position
1395 * Synchronize the X client window position with the Windows one
1397 static void sync_client_position( struct x11drv_win_data *data,
1398 const RECT *old_client_rect, const RECT *old_whole_rect )
1400 int mask = 0;
1401 XWindowChanges changes;
1403 if (!data->client_window) return;
1405 changes.x = data->client_rect.left - data->whole_rect.left;
1406 changes.y = data->client_rect.top - data->whole_rect.top;
1407 changes.width = min( max( 1, data->client_rect.right - data->client_rect.left ), 65535 );
1408 changes.height = min( max( 1, data->client_rect.bottom - data->client_rect.top ), 65535 );
1410 if (changes.x != old_client_rect->left - old_whole_rect->left) mask |= CWX;
1411 if (changes.y != old_client_rect->top - old_whole_rect->top) mask |= CWY;
1412 if (changes.width != old_client_rect->right - old_client_rect->left) mask |= CWWidth;
1413 if (changes.height != old_client_rect->bottom - old_client_rect->top) mask |= CWHeight;
1415 if (mask)
1417 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1418 data->client_window, changes.x, changes.y, changes.width, changes.height, mask );
1419 XConfigureWindow( gdi_display, data->client_window, mask, &changes );
1424 /***********************************************************************
1425 * move_window_bits
1427 * Move the window bits when a window is moved.
1429 static void move_window_bits( HWND hwnd, Window window, const RECT *old_rect, const RECT *new_rect,
1430 const RECT *old_client_rect, const RECT *new_client_rect,
1431 const RECT *new_window_rect )
1433 RECT src_rect = *old_rect;
1434 RECT dst_rect = *new_rect;
1435 HDC hdc_src, hdc_dst;
1436 INT code;
1437 HRGN rgn;
1438 HWND parent = 0;
1440 if (!window)
1442 OffsetRect( &dst_rect, -new_window_rect->left, -new_window_rect->top );
1443 parent = NtUserGetAncestor( hwnd, GA_PARENT );
1444 hdc_src = NtUserGetDCEx( parent, 0, DCX_CACHE );
1445 hdc_dst = NtUserGetDCEx( hwnd, 0, DCX_CACHE | DCX_WINDOW );
1447 else
1449 OffsetRect( &dst_rect, -new_client_rect->left, -new_client_rect->top );
1450 /* make src rect relative to the old position of the window */
1451 OffsetRect( &src_rect, -old_client_rect->left, -old_client_rect->top );
1452 if (dst_rect.left == src_rect.left && dst_rect.top == src_rect.top) return;
1453 hdc_src = hdc_dst = NtUserGetDCEx( hwnd, 0, DCX_CACHE );
1456 rgn = NtGdiCreateRectRgn( dst_rect.left, dst_rect.top, dst_rect.right, dst_rect.bottom );
1457 NtGdiExtSelectClipRgn( hdc_dst, rgn, RGN_COPY );
1458 NtGdiDeleteObjectApp( rgn );
1459 /* WS_CLIPCHILDREN doesn't exclude children from the window update
1460 * region, and ExcludeUpdateRgn call may inappropriately clip valid
1461 * child window contents from the copied parent window bits, but we
1462 * still want to avoid copying invalid window bits when possible.
1464 if (!(NtUserGetWindowLongW( hwnd, GWL_STYLE ) & WS_CLIPCHILDREN ))
1465 NtUserExcludeUpdateRgn( hdc_dst, hwnd );
1467 code = X11DRV_START_EXPOSURES;
1468 NtGdiExtEscape( hdc_dst, NULL, 0, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1470 TRACE( "copying bits for win %p/%lx %s -> %s\n",
1471 hwnd, window, wine_dbgstr_rect(&src_rect), wine_dbgstr_rect(&dst_rect) );
1472 NtGdiBitBlt( hdc_dst, dst_rect.left, dst_rect.top,
1473 dst_rect.right - dst_rect.left, dst_rect.bottom - dst_rect.top,
1474 hdc_src, src_rect.left, src_rect.top, SRCCOPY, 0, 0 );
1476 rgn = 0;
1477 code = X11DRV_END_EXPOSURES;
1478 NtGdiExtEscape( hdc_dst, NULL, 0, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, sizeof(rgn), (LPSTR)&rgn );
1480 NtUserReleaseDC( hwnd, hdc_dst );
1481 if (hdc_src != hdc_dst) NtUserReleaseDC( parent, hdc_src );
1483 if (rgn)
1485 if (!window)
1487 /* map region to client rect since we are using DCX_WINDOW */
1488 NtGdiOffsetRgn( rgn, new_window_rect->left - new_client_rect->left,
1489 new_window_rect->top - new_client_rect->top );
1490 NtUserRedrawWindow( hwnd, NULL, rgn,
1491 RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ALLCHILDREN );
1493 else NtUserRedrawWindow( hwnd, NULL, rgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
1494 NtGdiDeleteObjectApp( rgn );
1499 /***********************************************************************
1500 * get_dummy_parent
1502 * Create a dummy parent window for child windows that don't have a true X11 parent.
1504 Window get_dummy_parent(void)
1506 static Window dummy_parent;
1508 if (!dummy_parent)
1510 XSetWindowAttributes attrib;
1512 attrib.override_redirect = True;
1513 attrib.border_pixel = 0;
1514 attrib.colormap = default_colormap;
1516 #ifdef HAVE_LIBXSHAPE
1518 static XRectangle empty_rect;
1519 dummy_parent = XCreateWindow( gdi_display, root_window, 0, 0, 1, 1, 0,
1520 default_visual.depth, InputOutput, default_visual.visual,
1521 CWColormap | CWBorderPixel | CWOverrideRedirect, &attrib );
1522 XShapeCombineRectangles( gdi_display, dummy_parent, ShapeBounding, 0, 0, &empty_rect, 1,
1523 ShapeSet, YXBanded );
1525 #else
1526 dummy_parent = XCreateWindow( gdi_display, root_window, -1, -1, 1, 1, 0, default_visual.depth,
1527 InputOutput, default_visual.visual,
1528 CWColormap | CWBorderPixel | CWOverrideRedirect, &attrib );
1529 WARN("Xshape support is not compiled in. Applications under XWayland may have poor performance.");
1530 #endif
1531 XMapWindow( gdi_display, dummy_parent );
1533 return dummy_parent;
1537 /**********************************************************************
1538 * create_dummy_client_window
1540 Window create_dummy_client_window(void)
1542 XSetWindowAttributes attr;
1544 attr.colormap = default_colormap;
1545 attr.bit_gravity = NorthWestGravity;
1546 attr.win_gravity = NorthWestGravity;
1547 attr.backing_store = NotUseful;
1548 attr.border_pixel = 0;
1550 return XCreateWindow( gdi_display, get_dummy_parent(), 0, 0, 1, 1, 0,
1551 default_visual.depth, InputOutput, default_visual.visual,
1552 CWBitGravity | CWWinGravity | CWBackingStore | CWColormap | CWBorderPixel, &attr );
1555 /**********************************************************************
1556 * create_client_window
1558 Window create_client_window( HWND hwnd, const XVisualInfo *visual )
1560 Window dummy_parent = get_dummy_parent();
1561 struct x11drv_win_data *data = get_win_data( hwnd );
1562 XSetWindowAttributes attr;
1563 Window ret;
1564 int x, y, cx, cy;
1566 if (!data)
1568 /* explicitly create data for HWND_MESSAGE windows since they can be used for OpenGL */
1569 HWND parent = NtUserGetAncestor( hwnd, GA_PARENT );
1570 if (parent == NtUserGetDesktopWindow() || NtUserGetAncestor( parent, GA_PARENT )) return 0;
1571 if (!(data = alloc_win_data( thread_init_display(), hwnd ))) return 0;
1572 NtUserGetClientRect( hwnd, &data->client_rect );
1573 data->window_rect = data->whole_rect = data->client_rect;
1576 if (data->client_window)
1578 XDeleteContext( data->display, data->client_window, winContext );
1579 XReparentWindow( gdi_display, data->client_window, dummy_parent, 0, 0 );
1580 TRACE( "%p reparent xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1583 if (data->client_colormap) XFreeColormap( gdi_display, data->client_colormap );
1584 data->client_colormap = XCreateColormap( gdi_display, dummy_parent, visual->visual,
1585 (visual->class == PseudoColor ||
1586 visual->class == GrayScale ||
1587 visual->class == DirectColor) ? AllocAll : AllocNone );
1588 attr.colormap = data->client_colormap;
1589 attr.bit_gravity = NorthWestGravity;
1590 attr.win_gravity = NorthWestGravity;
1591 attr.backing_store = NotUseful;
1592 attr.border_pixel = 0;
1594 x = data->client_rect.left - data->whole_rect.left;
1595 y = data->client_rect.top - data->whole_rect.top;
1596 cx = min( max( 1, data->client_rect.right - data->client_rect.left ), 65535 );
1597 cy = min( max( 1, data->client_rect.bottom - data->client_rect.top ), 65535 );
1599 XSync( gdi_display, False ); /* make sure whole_window is known from gdi_display */
1600 ret = data->client_window = XCreateWindow( gdi_display,
1601 data->whole_window ? data->whole_window : dummy_parent,
1602 x, y, cx, cy, 0, default_visual.depth, InputOutput,
1603 visual->visual, CWBitGravity | CWWinGravity |
1604 CWBackingStore | CWColormap | CWBorderPixel, &attr );
1605 if (data->client_window)
1607 XSaveContext( data->display, data->client_window, winContext, (char *)data->hwnd );
1608 XMapWindow( gdi_display, data->client_window );
1609 if (data->whole_window)
1611 XFlush( gdi_display ); /* make sure client_window is created for XSelectInput */
1612 XSync( data->display, False ); /* make sure client_window is known from data->display */
1613 XSelectInput( data->display, data->client_window, ExposureMask );
1615 TRACE( "%p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1617 release_win_data( data );
1618 return ret;
1622 /**********************************************************************
1623 * create_whole_window
1625 * Create the whole X window for a given window
1627 static void create_whole_window( struct x11drv_win_data *data )
1629 int cx, cy, mask;
1630 XSetWindowAttributes attr;
1631 WCHAR text[1024];
1632 COLORREF key;
1633 BYTE alpha;
1634 DWORD layered_flags;
1635 HRGN win_rgn;
1636 POINT pos;
1638 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1640 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1641 data->managed = TRUE;
1644 if ((win_rgn = NtGdiCreateRectRgn( 0, 0, 0, 0 )) &&
1645 NtUserGetWindowRgnEx( data->hwnd, win_rgn, 0 ) == ERROR)
1647 NtGdiDeleteObjectApp( win_rgn );
1648 win_rgn = 0;
1650 data->shaped = (win_rgn != 0);
1652 if (data->vis.visualid != default_visual.visualid)
1653 data->whole_colormap = XCreateColormap( data->display, root_window, data->vis.visual, AllocNone );
1655 mask = get_window_attributes( data, &attr );
1657 if (!(cx = data->whole_rect.right - data->whole_rect.left)) cx = 1;
1658 else if (cx > 65535) cx = 65535;
1659 if (!(cy = data->whole_rect.bottom - data->whole_rect.top)) cy = 1;
1660 else if (cy > 65535) cy = 65535;
1662 pos = virtual_screen_to_root( data->whole_rect.left, data->whole_rect.top );
1663 data->whole_window = XCreateWindow( data->display, root_window, pos.x, pos.y,
1664 cx, cy, 0, data->vis.depth, InputOutput,
1665 data->vis.visual, mask, &attr );
1666 if (!data->whole_window) goto done;
1668 set_initial_wm_hints( data->display, data->whole_window );
1669 set_wm_hints( data );
1671 XSaveContext( data->display, data->whole_window, winContext, (char *)data->hwnd );
1672 NtUserSetProp( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
1674 /* set the window text */
1675 if (!NtUserInternalGetWindowText( data->hwnd, text, ARRAY_SIZE( text ))) text[0] = 0;
1676 sync_window_text( data->display, data->whole_window, text );
1678 /* set the window region */
1679 if (win_rgn || IsRectEmpty( &data->window_rect )) sync_window_region( data, win_rgn );
1681 /* set the window opacity */
1682 if (!NtUserGetLayeredWindowAttributes( data->hwnd, &key, &alpha, &layered_flags )) layered_flags = 0;
1683 sync_window_opacity( data->display, data->whole_window, key, alpha, layered_flags );
1685 XFlush( data->display ); /* make sure the window exists before we start painting to it */
1687 done:
1688 if (win_rgn) NtGdiDeleteObjectApp( win_rgn );
1692 /**********************************************************************
1693 * destroy_whole_window
1695 * Destroy the whole X window for a given window.
1697 static void destroy_whole_window( struct x11drv_win_data *data, BOOL already_destroyed )
1699 TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1701 if (data->client_window) XDeleteContext( data->display, data->client_window, winContext );
1703 if (!data->whole_window)
1705 if (data->embedded)
1707 Window xwin = (Window)NtUserGetProp( data->hwnd, foreign_window_prop );
1708 if (xwin)
1710 if (!already_destroyed) XSelectInput( data->display, xwin, 0 );
1711 XDeleteContext( data->display, xwin, winContext );
1712 NtUserRemoveProp( data->hwnd, foreign_window_prop );
1714 return;
1717 else
1719 if (data->client_window && !already_destroyed)
1721 XSelectInput( data->display, data->client_window, 0 );
1722 XFlush( data->display ); /* make sure XSelectInput doesn't use client_window after this point */
1723 XReparentWindow( gdi_display, data->client_window, get_dummy_parent(), 0, 0 );
1725 XDeleteContext( data->display, data->whole_window, winContext );
1726 if (!already_destroyed)
1728 XSync( gdi_display, False ); /* make sure XReparentWindow requests have completed before destroying whole_window */
1729 XDestroyWindow( data->display, data->whole_window );
1732 if (data->whole_colormap) XFreeColormap( data->display, data->whole_colormap );
1733 data->whole_window = data->client_window = 0;
1734 data->whole_colormap = 0;
1735 data->wm_state = WithdrawnState;
1736 data->net_wm_state = 0;
1737 data->mapped = FALSE;
1738 if (data->xic)
1740 XUnsetICFocus( data->xic );
1741 XDestroyIC( data->xic );
1742 data->xic = 0;
1744 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1745 XFlush( data->display );
1746 if (data->surface) window_surface_release( data->surface );
1747 data->surface = NULL;
1748 NtUserRemoveProp( data->hwnd, whole_window_prop );
1752 /**********************************************************************
1753 * set_window_visual
1755 * Change the visual by destroying and recreating the X window if needed.
1757 void set_window_visual( struct x11drv_win_data *data, const XVisualInfo *vis, BOOL use_alpha )
1759 Window client_window = data->client_window;
1760 Window whole_window = data->whole_window;
1762 if (!data->use_alpha == !use_alpha) return;
1763 if (data->surface) window_surface_release( data->surface );
1764 data->surface = NULL;
1765 data->use_alpha = use_alpha;
1767 if (data->vis.visualid == vis->visualid) return;
1768 data->client_window = 0;
1769 destroy_whole_window( data, client_window != 0 /* don't destroy whole_window until reparented */ );
1770 data->vis = *vis;
1771 create_whole_window( data );
1772 if (!client_window) return;
1773 /* move the client to the new parent */
1774 XReparentWindow( gdi_display, client_window, data->whole_window,
1775 data->client_rect.left - data->whole_rect.left,
1776 data->client_rect.top - data->whole_rect.top );
1777 data->client_window = client_window;
1778 XSync( gdi_display, False ); /* make sure XReparentWindow requests have completed before destroying whole_window */
1779 XDestroyWindow( data->display, whole_window );
1783 /*****************************************************************
1784 * SetWindowText (X11DRV.@)
1786 void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
1788 Window win;
1790 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(gdi_display))
1792 Display *display = thread_init_display();
1793 sync_window_text( display, win, text );
1798 /***********************************************************************
1799 * SetWindowStyle (X11DRV.@)
1801 * Update the X state of a window to reflect a style change
1803 void X11DRV_SetWindowStyle( HWND hwnd, INT offset, STYLESTRUCT *style )
1805 struct x11drv_win_data *data;
1806 DWORD changed = style->styleNew ^ style->styleOld;
1808 if (hwnd == NtUserGetDesktopWindow()) return;
1809 if (!(data = get_win_data( hwnd ))) return;
1810 if (!data->whole_window) goto done;
1812 if (offset == GWL_STYLE && (changed & WS_DISABLED)) set_wm_hints( data );
1814 if (offset == GWL_EXSTYLE && (changed & WS_EX_LAYERED)) /* changing WS_EX_LAYERED resets attributes */
1816 data->layered = FALSE;
1817 set_window_visual( data, &default_visual, FALSE );
1818 sync_window_opacity( data->display, data->whole_window, 0, 0, 0 );
1819 if (data->surface) set_surface_color_key( data->surface, CLR_INVALID );
1821 done:
1822 release_win_data( data );
1826 /***********************************************************************
1827 * DestroyWindow (X11DRV.@)
1829 void X11DRV_DestroyWindow( HWND hwnd )
1831 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1832 struct x11drv_win_data *data;
1834 if (!(data = get_win_data( hwnd ))) return;
1836 destroy_whole_window( data, FALSE );
1837 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
1838 if (thread_data->last_xic_hwnd == hwnd) thread_data->last_xic_hwnd = 0;
1839 if (data->icon_pixmap) XFreePixmap( gdi_display, data->icon_pixmap );
1840 if (data->icon_mask) XFreePixmap( gdi_display, data->icon_mask );
1841 if (data->client_colormap) XFreeColormap( data->display, data->client_colormap );
1842 free( data->icon_bits );
1843 XDeleteContext( gdi_display, (XID)hwnd, win_data_context );
1844 release_win_data( data );
1845 free( data );
1846 destroy_gl_drawable( hwnd );
1847 wine_vk_surface_destroy( hwnd );
1851 /***********************************************************************
1852 * X11DRV_DestroyNotify
1854 BOOL X11DRV_DestroyNotify( HWND hwnd, XEvent *event )
1856 struct x11drv_win_data *data;
1857 BOOL embedded;
1859 if (!(data = get_win_data( hwnd ))) return FALSE;
1860 embedded = data->embedded;
1861 if (!embedded) FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window );
1863 destroy_whole_window( data, TRUE );
1864 release_win_data( data );
1865 if (embedded) send_message( hwnd, WM_CLOSE, 0, 0 );
1866 return TRUE;
1870 /* initialize the desktop window id in the desktop manager process */
1871 static BOOL create_desktop_win_data( Window win, HWND hwnd )
1873 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1874 Display *display = thread_data->display;
1875 struct x11drv_win_data *data;
1877 if (!(data = alloc_win_data( display, hwnd ))) return FALSE;
1878 data->whole_window = win;
1879 data->managed = TRUE;
1880 NtUserSetProp( data->hwnd, whole_window_prop, (HANDLE)win );
1881 set_initial_wm_hints( display, win );
1882 release_win_data( data );
1883 if (thread_data->clip_window) XReparentWindow( display, thread_data->clip_window, win, 0, 0 );
1884 return TRUE;
1887 /**********************************************************************
1888 * SetDesktopWindow (X11DRV.@)
1890 void X11DRV_SetDesktopWindow( HWND hwnd )
1892 unsigned int width, height;
1894 /* retrieve the real size of the desktop */
1895 SERVER_START_REQ( get_window_rectangles )
1897 req->handle = wine_server_user_handle( hwnd );
1898 req->relative = COORDS_CLIENT;
1899 wine_server_call( req );
1900 width = reply->window.right;
1901 height = reply->window.bottom;
1903 SERVER_END_REQ;
1905 if (!width && !height) /* not initialized yet */
1907 RECT rect;
1909 X11DRV_DisplayDevices_Init( TRUE );
1910 rect = NtUserGetVirtualScreenRect();
1912 SERVER_START_REQ( set_window_pos )
1914 req->handle = wine_server_user_handle( hwnd );
1915 req->previous = 0;
1916 req->swp_flags = SWP_NOZORDER;
1917 req->window.left = rect.left;
1918 req->window.top = rect.top;
1919 req->window.right = rect.right;
1920 req->window.bottom = rect.bottom;
1921 req->client = req->window;
1922 wine_server_call( req );
1924 SERVER_END_REQ;
1926 if (!is_virtual_desktop()) return;
1927 if (!create_desktop_win_data( root_window, hwnd ))
1929 ERR( "Failed to create virtual desktop window data\n" );
1930 root_window = DefaultRootWindow( gdi_display );
1932 else if (is_desktop_fullscreen())
1934 Display *display = x11drv_thread_data()->display;
1935 TRACE("setting desktop to fullscreen\n");
1936 XChangeProperty( display, root_window, x11drv_atom(_NET_WM_STATE), XA_ATOM, 32, PropModeReplace,
1937 (unsigned char*)&x11drv_atom(_NET_WM_STATE_FULLSCREEN), 1 );
1940 else
1942 Window win = (Window)NtUserGetProp( hwnd, whole_window_prop );
1943 if (win && win != root_window)
1945 X11DRV_init_desktop( win, width, height );
1946 X11DRV_DisplayDevices_Init( TRUE );
1952 #define WM_WINE_NOTIFY_ACTIVITY WM_USER
1953 #define WM_WINE_DELETE_TAB (WM_USER + 1)
1954 #define WM_WINE_ADD_TAB (WM_USER + 2)
1956 /**********************************************************************
1957 * DesktopWindowProc (X11DRV.@)
1959 LRESULT X11DRV_DesktopWindowProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
1961 switch (msg)
1963 case WM_WINE_NOTIFY_ACTIVITY:
1965 static ULONG last = 0;
1966 ULONG now = NtGetTickCount();
1967 /* calling XResetScreenSaver too often can cause performance
1968 * problems, so throttle it */
1969 if (now > last + 5000)
1971 XResetScreenSaver( gdi_display );
1972 XFlush( gdi_display );
1973 last = now;
1975 break;
1977 case WM_WINE_DELETE_TAB:
1978 send_notify_message( (HWND)wp, WM_X11DRV_DELETE_TAB, 0, 0 );
1979 break;
1980 case WM_WINE_ADD_TAB:
1981 send_notify_message( (HWND)wp, WM_X11DRV_ADD_TAB, 0, 0 );
1982 break;
1983 case WM_DISPLAYCHANGE:
1984 X11DRV_resize_desktop();
1985 break;
1987 return NtUserMessageCall( hwnd, msg, wp, lp, 0, NtUserDefWindowProc, FALSE );
1990 /**********************************************************************
1991 * CreateWindow (X11DRV.@)
1993 BOOL X11DRV_CreateWindow( HWND hwnd )
1995 if (hwnd == NtUserGetDesktopWindow())
1997 struct x11drv_thread_data *data = x11drv_init_thread_data();
1998 XSetWindowAttributes attr;
2000 /* create the cursor clipping window */
2001 attr.override_redirect = TRUE;
2002 attr.event_mask = StructureNotifyMask | FocusChangeMask;
2003 data->clip_window = XCreateWindow( data->display, root_window, 0, 0, 1, 1, 0, 0,
2004 InputOnly, default_visual.visual,
2005 CWOverrideRedirect | CWEventMask, &attr );
2006 XFlush( data->display );
2007 NtUserSetProp( hwnd, clip_window_prop, (HANDLE)data->clip_window );
2008 X11DRV_DisplayDevices_RegisterEventHandlers();
2010 return TRUE;
2014 /***********************************************************************
2015 * get_win_data
2017 * Lock and return the X11 data structure associated with a window.
2019 struct x11drv_win_data *get_win_data( HWND hwnd )
2021 char *data;
2023 if (!hwnd) return NULL;
2024 pthread_mutex_lock( &win_data_mutex );
2025 if (!XFindContext( gdi_display, (XID)hwnd, win_data_context, &data ))
2026 return (struct x11drv_win_data *)data;
2027 pthread_mutex_unlock( &win_data_mutex );
2028 return NULL;
2032 /***********************************************************************
2033 * release_win_data
2035 * Release the data returned by get_win_data.
2037 void release_win_data( struct x11drv_win_data *data )
2039 if (data) pthread_mutex_unlock( &win_data_mutex );
2043 /***********************************************************************
2044 * X11DRV_create_win_data
2046 * Create an X11 data window structure for an existing window.
2048 static struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd, const RECT *window_rect,
2049 const RECT *client_rect )
2051 Display *display;
2052 struct x11drv_win_data *data;
2053 HWND parent;
2055 if (!(parent = NtUserGetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
2057 /* don't create win data for HWND_MESSAGE windows */
2058 if (parent != NtUserGetDesktopWindow() && !NtUserGetAncestor( parent, GA_PARENT )) return NULL;
2060 if (NtUserGetWindowThread( hwnd, NULL ) != GetCurrentThreadId()) return NULL;
2062 /* Recreate the parent gl_drawable now that we know there are child windows
2063 * that will need clipping support.
2065 sync_gl_drawable( parent, TRUE );
2067 display = thread_init_display();
2068 init_clip_window(); /* make sure the clip window is initialized in this thread */
2070 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
2072 data->whole_rect = data->window_rect = *window_rect;
2073 data->client_rect = *client_rect;
2074 if (parent == NtUserGetDesktopWindow())
2076 create_whole_window( data );
2077 TRACE( "win %p/%lx window %s whole %s client %s\n",
2078 hwnd, data->whole_window, wine_dbgstr_rect( &data->window_rect ),
2079 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
2081 return data;
2085 /***********************************************************************
2086 * create_foreign_window
2088 * Create a foreign window for the specified X window and its ancestors
2090 HWND create_foreign_window( Display *display, Window xwin )
2092 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};
2093 static BOOL class_registered;
2094 struct x11drv_win_data *data;
2095 HWND hwnd, parent;
2096 POINT pos;
2097 Window xparent, xroot;
2098 Window *xchildren;
2099 unsigned int nchildren;
2100 XWindowAttributes attr;
2101 UINT style = WS_CLIPCHILDREN;
2102 UNICODE_STRING class_name = RTL_CONSTANT_STRING( classW );
2104 if (!class_registered)
2106 UNICODE_STRING version = { 0 };
2107 WNDCLASSEXW class;
2109 memset( &class, 0, sizeof(class) );
2110 class.cbSize = sizeof(class);
2111 class.lpfnWndProc = client_foreign_window_proc;
2112 class.lpszClassName = classW;
2113 if (!NtUserRegisterClassExWOW( &class, &class_name, &version, NULL, 0, 0, NULL ) &&
2114 RtlGetLastWin32Error() != ERROR_CLASS_ALREADY_EXISTS)
2116 ERR( "Could not register foreign window class\n" );
2117 return FALSE;
2119 class_registered = TRUE;
2122 if (XFindContext( display, xwin, winContext, (char **)&hwnd )) hwnd = 0;
2123 if (hwnd) return hwnd; /* already created */
2125 XSelectInput( display, xwin, StructureNotifyMask );
2126 if (!XGetWindowAttributes( display, xwin, &attr ) ||
2127 !XQueryTree( display, xwin, &xroot, &xparent, &xchildren, &nchildren ))
2129 XSelectInput( display, xwin, 0 );
2130 return 0;
2132 XFree( xchildren );
2134 if (xparent == xroot)
2136 parent = NtUserGetDesktopWindow();
2137 style |= WS_POPUP;
2138 pos = root_to_virtual_screen( attr.x, attr.y );
2140 else
2142 parent = create_foreign_window( display, xparent );
2143 style |= WS_CHILD;
2144 pos.x = attr.x;
2145 pos.y = attr.y;
2148 RtlInitUnicodeString( &class_name, classW );
2149 hwnd = NtUserCreateWindowEx( 0, &class_name, &class_name, NULL, style, pos.x, pos.y,
2150 attr.width, attr.height, parent, 0, NULL, NULL, 0, NULL,
2151 0, FALSE );
2153 if (!(data = alloc_win_data( display, hwnd )))
2155 NtUserDestroyWindow( hwnd );
2156 return 0;
2158 SetRect( &data->window_rect, pos.x, pos.y, pos.x + attr.width, pos.y + attr.height );
2159 data->whole_rect = data->client_rect = data->window_rect;
2160 data->whole_window = data->client_window = 0;
2161 data->embedded = TRUE;
2162 data->mapped = TRUE;
2164 NtUserSetProp( hwnd, foreign_window_prop, (HANDLE)xwin );
2165 XSaveContext( display, xwin, winContext, (char *)data->hwnd );
2167 TRACE( "win %lx parent %p style %08x %s -> hwnd %p\n",
2168 xwin, parent, style, wine_dbgstr_rect(&data->window_rect), hwnd );
2170 release_win_data( data );
2172 NtUserShowWindow( hwnd, SW_SHOW );
2173 return hwnd;
2177 NTSTATUS x11drv_systray_init( void *arg )
2179 Display *display;
2181 if (is_virtual_desktop()) return FALSE;
2183 display = thread_init_display();
2184 if (DefaultScreen( display ) == 0)
2185 systray_atom = x11drv_atom(_NET_SYSTEM_TRAY_S0);
2186 else
2188 char systray_buffer[29]; /* strlen(_NET_SYSTEM_TRAY_S4294967295)+1 */
2189 sprintf( systray_buffer, "_NET_SYSTEM_TRAY_S%u", DefaultScreen( display ) );
2190 systray_atom = XInternAtom( display, systray_buffer, False );
2192 XSelectInput( display, root_window, StructureNotifyMask );
2194 return TRUE;
2198 NTSTATUS x11drv_systray_clear( void *arg )
2200 HWND hwnd = *(HWND*)arg;
2201 Window win = X11DRV_get_whole_window( hwnd );
2202 if (win) XClearArea( gdi_display, win, 0, 0, 0, 0, True );
2203 return 0;
2207 NTSTATUS x11drv_systray_hide( void *arg )
2209 HWND hwnd = *(HWND*)arg;
2210 struct x11drv_win_data *data;
2212 /* make sure we don't try to unmap it, it confuses some systray docks */
2213 if ((data = get_win_data( hwnd )))
2215 if (data->embedded) data->mapped = FALSE;
2216 release_win_data( data );
2219 return 0;
2223 /* find the X11 window owner the system tray selection */
2224 static Window get_systray_selection_owner( Display *display )
2226 return XGetSelectionOwner( display, systray_atom );
2230 static void get_systray_visual_info( Display *display, Window systray_window, XVisualInfo *info )
2232 XVisualInfo *list, template;
2233 VisualID *visual_id;
2234 Atom type;
2235 int format, num;
2236 unsigned long count, remaining;
2238 *info = default_visual;
2239 if (XGetWindowProperty( display, systray_window, x11drv_atom(_NET_SYSTEM_TRAY_VISUAL), 0,
2240 65536/sizeof(CARD32), False, XA_VISUALID, &type, &format, &count,
2241 &remaining, (unsigned char **)&visual_id ))
2242 return;
2244 if (type == XA_VISUALID && format == 32)
2246 template.visualid = visual_id[0];
2247 if ((list = XGetVisualInfo( display, VisualIDMask, &template, &num )))
2249 *info = list[0];
2250 TRACE_(systray)( "systray window %lx got visual %lx\n", systray_window, info->visualid );
2251 XFree( list );
2254 XFree( visual_id );
2258 NTSTATUS x11drv_systray_dock( void *arg )
2260 struct systray_dock_params *params = arg;
2261 Window systray_window, window;
2262 Display *display;
2263 XEvent ev;
2264 XSetWindowAttributes attr;
2265 XVisualInfo visual;
2266 struct x11drv_win_data *data;
2267 UNICODE_STRING class_name;
2268 BOOL layered;
2269 HWND hwnd;
2271 static const WCHAR icon_classname[] =
2272 {'_','_','w','i','n','e','x','1','1','_','t','r','a','y','_','i','c','o','n',0};
2274 if (params->event_handle)
2276 XClientMessageEvent *event = (XClientMessageEvent *)(UINT_PTR)params->event_handle;
2277 display = event->display;
2278 systray_window = event->data.l[2];
2280 else
2282 display = thread_init_display();
2283 if (!(systray_window = get_systray_selection_owner( display ))) return STATUS_UNSUCCESSFUL;
2286 get_systray_visual_info( display, systray_window, &visual );
2288 *params->layered = layered = (visual.depth == 32);
2290 RtlInitUnicodeString( &class_name, icon_classname );
2291 hwnd = NtUserCreateWindowEx( layered ? WS_EX_LAYERED : 0, &class_name, &class_name, NULL,
2292 WS_CLIPSIBLINGS | WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
2293 params->cx, params->cy, NULL, 0, NULL, params->icon, 0,
2294 NULL, 0, FALSE );
2296 if (!(data = get_win_data( hwnd ))) return STATUS_UNSUCCESSFUL;
2297 if (layered) set_window_visual( data, &visual, TRUE );
2298 make_window_embedded( data );
2299 window = data->whole_window;
2300 release_win_data( data );
2302 NtUserShowWindow( hwnd, SW_SHOWNA );
2304 TRACE_(systray)( "icon window %p/%lx\n", hwnd, window );
2306 /* send the docking request message */
2307 ev.xclient.type = ClientMessage;
2308 ev.xclient.window = systray_window;
2309 ev.xclient.message_type = x11drv_atom( _NET_SYSTEM_TRAY_OPCODE );
2310 ev.xclient.format = 32;
2311 ev.xclient.data.l[0] = CurrentTime;
2312 ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
2313 ev.xclient.data.l[2] = window;
2314 ev.xclient.data.l[3] = 0;
2315 ev.xclient.data.l[4] = 0;
2316 XSendEvent( display, systray_window, False, NoEventMask, &ev );
2318 if (!layered)
2320 attr.background_pixmap = ParentRelative;
2321 attr.bit_gravity = ForgetGravity;
2322 XChangeWindowAttributes( display, window, CWBackPixmap | CWBitGravity, &attr );
2324 else
2326 /* force repainig */
2327 send_message( hwnd, WM_SIZE, SIZE_RESTORED, MAKELONG( params->cx, params->cy ));
2330 return STATUS_SUCCESS;
2334 /***********************************************************************
2335 * X11DRV_get_whole_window
2337 * Return the X window associated with the full area of a window
2339 Window X11DRV_get_whole_window( HWND hwnd )
2341 struct x11drv_win_data *data = get_win_data( hwnd );
2342 Window ret;
2344 if (!data)
2346 if (hwnd == NtUserGetDesktopWindow()) return root_window;
2347 return (Window)NtUserGetProp( hwnd, whole_window_prop );
2349 ret = data->whole_window;
2350 release_win_data( data );
2351 return ret;
2355 /***********************************************************************
2356 * X11DRV_GetDC (X11DRV.@)
2358 void X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect,
2359 const RECT *top_rect, DWORD flags )
2361 struct x11drv_escape_set_drawable escape;
2362 HWND parent;
2364 escape.code = X11DRV_SET_DRAWABLE;
2365 escape.mode = IncludeInferiors;
2366 escape.drawable = 0;
2368 escape.dc_rect.left = win_rect->left - top_rect->left;
2369 escape.dc_rect.top = win_rect->top - top_rect->top;
2370 escape.dc_rect.right = win_rect->right - top_rect->left;
2371 escape.dc_rect.bottom = win_rect->bottom - top_rect->top;
2373 if (top == hwnd)
2375 struct x11drv_win_data *data = get_win_data( hwnd );
2377 escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd );
2379 /* special case: when repainting the root window, clip out top-level windows */
2380 if (data && data->whole_window == root_window) escape.mode = ClipByChildren;
2381 release_win_data( data );
2383 else
2385 /* find the first ancestor that has a drawable */
2386 for (parent = hwnd; parent && parent != top; parent = NtUserGetAncestor( parent, GA_PARENT ))
2387 if ((escape.drawable = X11DRV_get_whole_window( parent ))) break;
2389 if (escape.drawable)
2391 POINT pt = { 0, 0 };
2392 NtUserMapWindowPoints( 0, parent, &pt, 1 );
2393 escape.dc_rect = *win_rect;
2394 OffsetRect( &escape.dc_rect, pt.x, pt.y );
2395 if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren;
2397 else escape.drawable = X11DRV_get_whole_window( top );
2400 NtGdiExtEscape( hdc, NULL, 0, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2404 /***********************************************************************
2405 * X11DRV_ReleaseDC (X11DRV.@)
2407 void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
2409 struct x11drv_escape_set_drawable escape;
2411 escape.code = X11DRV_SET_DRAWABLE;
2412 escape.drawable = root_window;
2413 escape.mode = IncludeInferiors;
2414 escape.dc_rect = NtUserGetVirtualScreenRect();
2415 OffsetRect( &escape.dc_rect, -2 * escape.dc_rect.left, -2 * escape.dc_rect.top );
2416 NtGdiExtEscape( hdc, NULL, 0, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2420 /*************************************************************************
2421 * ScrollDC (X11DRV.@)
2423 BOOL X11DRV_ScrollDC( HDC hdc, INT dx, INT dy, HRGN update )
2425 RECT rect;
2426 BOOL ret;
2427 HRGN expose_rgn = 0;
2429 NtGdiGetAppClipBox( hdc, &rect );
2431 if (update)
2433 INT code = X11DRV_START_EXPOSURES;
2434 NtGdiExtEscape( hdc, NULL, 0, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2436 ret = NtGdiBitBlt( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
2437 hdc, rect.left - dx, rect.top - dy, SRCCOPY, 0, 0 );
2439 code = X11DRV_END_EXPOSURES;
2440 NtGdiExtEscape( hdc, NULL, 0, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code,
2441 sizeof(expose_rgn), (LPSTR)&expose_rgn );
2442 if (expose_rgn)
2444 NtGdiCombineRgn( update, update, expose_rgn, RGN_OR );
2445 NtGdiDeleteObjectApp( expose_rgn );
2448 else ret = NtGdiBitBlt( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
2449 hdc, rect.left - dx, rect.top - dy, SRCCOPY, 0, 0 );
2451 return ret;
2455 /***********************************************************************
2456 * SetCapture (X11DRV.@)
2458 void X11DRV_SetCapture( HWND hwnd, UINT flags )
2460 struct x11drv_thread_data *thread_data = x11drv_thread_data();
2461 struct x11drv_win_data *data;
2463 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
2465 if (hwnd)
2467 if (!(data = get_win_data( NtUserGetAncestor( hwnd, GA_ROOT )))) return;
2468 if (data->whole_window)
2470 XFlush( gdi_display );
2471 XGrabPointer( data->display, data->whole_window, False,
2472 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
2473 GrabModeAsync, GrabModeAsync, None, None, CurrentTime );
2474 thread_data->grab_hwnd = data->hwnd;
2476 release_win_data( data );
2478 else /* release capture */
2480 if (!(data = get_win_data( thread_data->grab_hwnd ))) return;
2481 XFlush( gdi_display );
2482 XUngrabPointer( data->display, CurrentTime );
2483 XFlush( data->display );
2484 thread_data->grab_hwnd = NULL;
2485 release_win_data( data );
2490 /*****************************************************************
2491 * SetParent (X11DRV.@)
2493 void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
2495 struct x11drv_win_data *data;
2497 if (parent == old_parent) return;
2498 if (!(data = get_win_data( hwnd ))) return;
2499 if (data->embedded) goto done;
2501 if (parent != NtUserGetDesktopWindow()) /* a child window */
2503 if (old_parent == NtUserGetDesktopWindow())
2505 /* destroy the old X windows */
2506 destroy_whole_window( data, FALSE );
2507 data->managed = FALSE;
2510 else /* new top level window */
2512 create_whole_window( data );
2514 done:
2515 release_win_data( data );
2516 set_gl_drawable_parent( hwnd, parent );
2518 /* Recreate the parent gl_drawable now that we know there are child windows
2519 * that will need clipping support.
2521 sync_gl_drawable( parent, TRUE );
2523 fetch_icon_data( hwnd, 0, 0 );
2527 static inline BOOL get_surface_rect( const RECT *visible_rect, RECT *surface_rect )
2529 *surface_rect = NtUserGetVirtualScreenRect();
2531 if (!intersect_rect( surface_rect, surface_rect, visible_rect )) return FALSE;
2532 OffsetRect( surface_rect, -visible_rect->left, -visible_rect->top );
2533 surface_rect->left &= ~31;
2534 surface_rect->top &= ~31;
2535 surface_rect->right = max( surface_rect->left + 32, (surface_rect->right + 31) & ~31 );
2536 surface_rect->bottom = max( surface_rect->top + 32, (surface_rect->bottom + 31) & ~31 );
2537 return TRUE;
2541 /***********************************************************************
2542 * WindowPosChanging (X11DRV.@)
2544 BOOL X11DRV_WindowPosChanging( HWND hwnd, HWND insert_after, UINT swp_flags,
2545 const RECT *window_rect, const RECT *client_rect, RECT *visible_rect,
2546 struct window_surface **surface )
2548 struct x11drv_win_data *data = get_win_data( hwnd );
2549 RECT surface_rect;
2550 DWORD flags;
2551 COLORREF key;
2552 BOOL layered = NtUserGetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYERED;
2554 if (!data && !(data = X11DRV_create_win_data( hwnd, window_rect, client_rect ))) return TRUE;
2556 /* check if we need to switch the window to managed */
2557 if (!data->managed && data->whole_window && is_window_managed( hwnd, swp_flags, window_rect ))
2559 TRACE( "making win %p/%lx managed\n", hwnd, data->whole_window );
2560 release_win_data( data );
2561 unmap_window( hwnd );
2562 if (!(data = get_win_data( hwnd ))) return TRUE;
2563 data->managed = TRUE;
2566 *visible_rect = *window_rect;
2567 X11DRV_window_to_X_rect( data, visible_rect, window_rect, client_rect );
2569 /* create the window surface if necessary */
2571 if (!data->whole_window && !data->embedded) goto done;
2572 if (swp_flags & SWP_HIDEWINDOW) goto done;
2573 if (data->use_alpha) goto done;
2574 if (!get_surface_rect( visible_rect, &surface_rect )) goto done;
2576 if (*surface) window_surface_release( *surface );
2577 *surface = NULL; /* indicate that we want to draw directly to the window */
2579 if (data->embedded) goto done;
2580 if (data->whole_window == root_window) goto done;
2581 if (data->client_window) goto done;
2582 if (!client_side_graphics && !layered) goto done;
2584 if (data->surface)
2586 if (EqualRect( &data->surface->rect, &surface_rect ))
2588 /* existing surface is good enough */
2589 window_surface_add_ref( data->surface );
2590 *surface = data->surface;
2591 goto done;
2594 else if (!(swp_flags & SWP_SHOWWINDOW) && !(NtUserGetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)) goto done;
2596 if (!layered || !NtUserGetLayeredWindowAttributes( hwnd, &key, NULL, &flags ) || !(flags & LWA_COLORKEY))
2597 key = CLR_INVALID;
2599 *surface = create_surface( data->whole_window, &data->vis, &surface_rect, key, FALSE );
2601 done:
2602 release_win_data( data );
2603 return TRUE;
2607 /***********************************************************************
2608 * WindowPosChanged (X11DRV.@)
2610 void X11DRV_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_flags,
2611 const RECT *rectWindow, const RECT *rectClient,
2612 const RECT *visible_rect, const RECT *valid_rects,
2613 struct window_surface *surface )
2615 struct x11drv_thread_data *thread_data;
2616 struct x11drv_win_data *data;
2617 UINT new_style = NtUserGetWindowLongW( hwnd, GWL_STYLE );
2618 RECT old_window_rect, old_whole_rect, old_client_rect;
2619 int event_type;
2621 if (!(data = get_win_data( hwnd ))) return;
2623 thread_data = x11drv_thread_data();
2625 old_window_rect = data->window_rect;
2626 old_whole_rect = data->whole_rect;
2627 old_client_rect = data->client_rect;
2628 data->window_rect = *rectWindow;
2629 data->whole_rect = *visible_rect;
2630 data->client_rect = *rectClient;
2631 if (data->vis.visualid == default_visual.visualid)
2633 if (surface) window_surface_add_ref( surface );
2634 if (data->surface) window_surface_release( data->surface );
2635 data->surface = surface;
2638 TRACE( "win %p window %s client %s style %08x flags %08x\n",
2639 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style, swp_flags );
2641 if (!IsRectEmpty( &valid_rects[0] ))
2643 Window window = data->whole_window;
2644 int x_offset = old_whole_rect.left - data->whole_rect.left;
2645 int y_offset = old_whole_rect.top - data->whole_rect.top;
2647 /* if all that happened is that the whole window moved, copy everything */
2648 if (!(swp_flags & SWP_FRAMECHANGED) &&
2649 old_whole_rect.right - data->whole_rect.right == x_offset &&
2650 old_whole_rect.bottom - data->whole_rect.bottom == y_offset &&
2651 old_client_rect.left - data->client_rect.left == x_offset &&
2652 old_client_rect.right - data->client_rect.right == x_offset &&
2653 old_client_rect.top - data->client_rect.top == y_offset &&
2654 old_client_rect.bottom - data->client_rect.bottom == y_offset &&
2655 EqualRect( &valid_rects[0], &data->client_rect ))
2657 /* if we have an X window the bits will be moved by the X server */
2658 if (!window && (x_offset != 0 || y_offset != 0))
2660 release_win_data( data );
2661 move_window_bits( hwnd, window, &old_whole_rect, visible_rect,
2662 &old_client_rect, rectClient, rectWindow );
2663 if (!(data = get_win_data( hwnd ))) return;
2666 else
2668 release_win_data( data );
2669 move_window_bits( hwnd, window, &valid_rects[1], &valid_rects[0],
2670 &old_client_rect, rectClient, rectWindow );
2671 if (!(data = get_win_data( hwnd ))) return;
2675 XFlush( gdi_display ); /* make sure painting is done before we move the window */
2677 sync_client_position( data, &old_client_rect, &old_whole_rect );
2679 if (!data->whole_window)
2681 BOOL needs_resize = (!data->client_window &&
2682 (data->client_rect.right - data->client_rect.left !=
2683 old_client_rect.right - old_client_rect.left ||
2684 data->client_rect.bottom - data->client_rect.top !=
2685 old_client_rect.bottom - old_client_rect.top));
2686 release_win_data( data );
2687 if (needs_resize) sync_gl_drawable( hwnd, FALSE );
2688 return;
2691 /* check if we are currently processing an event relevant to this window */
2692 event_type = 0;
2693 if (thread_data &&
2694 thread_data->current_event &&
2695 thread_data->current_event->xany.window == data->whole_window)
2697 event_type = thread_data->current_event->type;
2698 if (event_type != ConfigureNotify && event_type != PropertyNotify &&
2699 event_type != GravityNotify && event_type != ReparentNotify)
2700 event_type = 0; /* ignore other events */
2703 if (data->mapped && event_type != ReparentNotify)
2705 if (((swp_flags & SWP_HIDEWINDOW) && !(new_style & WS_VISIBLE)) ||
2706 (!event_type && !(new_style & WS_MINIMIZE) &&
2707 !is_window_rect_mapped( rectWindow ) && is_window_rect_mapped( &old_window_rect )))
2709 release_win_data( data );
2710 unmap_window( hwnd );
2711 if (NtUserIsWindowRectFullScreen( &old_window_rect )) NtUserClipCursor( NULL );
2712 if (!(data = get_win_data( hwnd ))) return;
2716 /* don't change position if we are about to minimize or maximize a managed window */
2717 if (!event_type &&
2718 !(data->managed && (swp_flags & SWP_STATECHANGED) && (new_style & (WS_MINIMIZE|WS_MAXIMIZE))))
2719 sync_window_position( data, swp_flags, &old_window_rect, &old_whole_rect, &old_client_rect );
2721 if ((new_style & WS_VISIBLE) &&
2722 ((new_style & WS_MINIMIZE) || is_window_rect_mapped( rectWindow )))
2724 if (!data->mapped)
2726 BOOL needs_icon = !data->icon_pixmap;
2727 BOOL needs_map = TRUE;
2729 /* layered windows are mapped only once their attributes are set */
2730 if (NtUserGetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYERED)
2731 needs_map = data->layered || IsRectEmpty( rectWindow );
2732 release_win_data( data );
2733 if (needs_icon) fetch_icon_data( hwnd, 0, 0 );
2734 if (needs_map) map_window( hwnd, new_style );
2735 return;
2737 else if ((swp_flags & SWP_STATECHANGED) && (!data->iconic != !(new_style & WS_MINIMIZE)))
2739 set_wm_hints( data );
2740 data->iconic = (new_style & WS_MINIMIZE) != 0;
2741 TRACE( "changing win %p iconic state to %u\n", data->hwnd, data->iconic );
2742 if (data->iconic)
2743 XIconifyWindow( data->display, data->whole_window, data->vis.screen );
2744 else if (is_window_rect_mapped( rectWindow ))
2745 XMapWindow( data->display, data->whole_window );
2746 update_net_wm_states( data );
2748 else
2750 if (swp_flags & (SWP_FRAMECHANGED|SWP_STATECHANGED)) set_wm_hints( data );
2751 if (!event_type) update_net_wm_states( data );
2755 XFlush( data->display ); /* make sure changes are done before we start painting again */
2756 if (data->surface && data->vis.visualid != default_visual.visualid)
2757 data->surface->funcs->flush( data->surface );
2759 release_win_data( data );
2762 /* check if the window icon should be hidden (i.e. moved off-screen) */
2763 static BOOL hide_icon( struct x11drv_win_data *data )
2765 static const WCHAR trayW[] = {'S','h','e','l','l','_','T','r','a','y','W','n','d',0};
2766 UNICODE_STRING str = RTL_CONSTANT_STRING( trayW );
2768 if (data->managed) return TRUE;
2769 /* hide icons in desktop mode when the taskbar is active */
2770 if (!is_virtual_desktop()) return FALSE;
2771 return NtUserIsWindowVisible( NtUserFindWindowEx( 0, 0, &str, NULL, 0 ));
2774 /***********************************************************************
2775 * ShowWindow (X11DRV.@)
2777 UINT X11DRV_ShowWindow( HWND hwnd, INT cmd, RECT *rect, UINT swp )
2779 int x, y;
2780 unsigned int width, height, border, depth;
2781 Window root, top;
2782 POINT pos;
2783 DWORD style = NtUserGetWindowLongW( hwnd, GWL_STYLE );
2784 struct x11drv_thread_data *thread_data = x11drv_thread_data();
2785 struct x11drv_win_data *data = get_win_data( hwnd );
2787 if (!data || !data->whole_window) goto done;
2788 if (style & WS_MINIMIZE)
2790 if (((rect->left != -32000 || rect->top != -32000)) && hide_icon( data ))
2792 OffsetRect( rect, -32000 - rect->left, -32000 - rect->top );
2793 swp &= ~(SWP_NOMOVE | SWP_NOCLIENTMOVE);
2795 goto done;
2797 if (!data->managed || !data->mapped || data->iconic) goto done;
2799 /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */
2801 if (!thread_data->current_event || thread_data->current_event->xany.window != data->whole_window)
2802 goto done;
2804 if (thread_data->current_event->type != ConfigureNotify &&
2805 thread_data->current_event->type != PropertyNotify)
2806 goto done;
2808 TRACE( "win %p/%lx cmd %d at %s flags %08x\n",
2809 hwnd, data->whole_window, cmd, wine_dbgstr_rect(rect), swp );
2811 XGetGeometry( thread_data->display, data->whole_window,
2812 &root, &x, &y, &width, &height, &border, &depth );
2813 XTranslateCoordinates( thread_data->display, data->whole_window, root, 0, 0, &x, &y, &top );
2814 pos = root_to_virtual_screen( x, y );
2815 X11DRV_X_to_window_rect( data, rect, pos.x, pos.y, width, height );
2816 swp &= ~(SWP_NOMOVE | SWP_NOCLIENTMOVE | SWP_NOSIZE | SWP_NOCLIENTSIZE);
2818 done:
2819 release_win_data( data );
2820 return swp;
2824 /**********************************************************************
2825 * SetWindowIcon (X11DRV.@)
2827 * hIcon or hIconSm has changed (or is being initialised for the
2828 * first time). Complete the X11 driver-specific initialisation
2829 * and set the window hints.
2831 void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
2833 struct x11drv_win_data *data;
2835 if (!(data = get_win_data( hwnd ))) return;
2836 if (!data->whole_window) goto done;
2837 release_win_data( data ); /* release the lock, fetching the icon requires sending messages */
2839 if (type == ICON_BIG) fetch_icon_data( hwnd, icon, 0 );
2840 else fetch_icon_data( hwnd, 0, icon );
2842 if (!(data = get_win_data( hwnd ))) return;
2843 set_wm_hints( data );
2844 done:
2845 release_win_data( data );
2849 /***********************************************************************
2850 * SetWindowRgn (X11DRV.@)
2852 * Assign specified region to window (for non-rectangular windows)
2854 void X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
2856 struct x11drv_win_data *data;
2858 if ((data = get_win_data( hwnd )))
2860 sync_window_region( data, hrgn );
2861 release_win_data( data );
2863 else if (X11DRV_get_whole_window( hwnd ))
2865 send_message( hwnd, WM_X11DRV_SET_WIN_REGION, 0, 0 );
2870 /***********************************************************************
2871 * SetLayeredWindowAttributes (X11DRV.@)
2873 * Set transparency attributes for a layered window.
2875 void X11DRV_SetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags )
2877 struct x11drv_win_data *data = get_win_data( hwnd );
2879 if (data)
2881 set_window_visual( data, &default_visual, FALSE );
2883 if (data->whole_window)
2884 sync_window_opacity( data->display, data->whole_window, key, alpha, flags );
2885 if (data->surface)
2886 set_surface_color_key( data->surface, (flags & LWA_COLORKEY) ? key : CLR_INVALID );
2888 data->layered = TRUE;
2889 if (!data->mapped) /* mapping is delayed until attributes are set */
2891 DWORD style = NtUserGetWindowLongW( data->hwnd, GWL_STYLE );
2893 if ((style & WS_VISIBLE) &&
2894 ((style & WS_MINIMIZE) || is_window_rect_mapped( &data->window_rect )))
2896 release_win_data( data );
2897 map_window( hwnd, style );
2898 return;
2901 release_win_data( data );
2903 else
2905 Window win = X11DRV_get_whole_window( hwnd );
2906 if (win)
2908 sync_window_opacity( gdi_display, win, key, alpha, flags );
2909 if (flags & LWA_COLORKEY)
2910 FIXME( "LWA_COLORKEY not supported on foreign process window %p\n", hwnd );
2916 /*****************************************************************************
2917 * UpdateLayeredWindow (X11DRV.@)
2919 BOOL X11DRV_UpdateLayeredWindow( HWND hwnd, const UPDATELAYEREDWINDOWINFO *info,
2920 const RECT *window_rect )
2922 struct window_surface *surface;
2923 struct x11drv_win_data *data;
2924 BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255, 0 };
2925 COLORREF color_key = (info->dwFlags & ULW_COLORKEY) ? info->crKey : CLR_INVALID;
2926 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
2927 BITMAPINFO *bmi = (BITMAPINFO *)buffer;
2928 void *src_bits, *dst_bits;
2929 RECT rect, src_rect;
2930 HDC hdc = 0;
2931 HBITMAP dib;
2932 BOOL mapped, ret = FALSE;
2934 if (!(data = get_win_data( hwnd ))) return FALSE;
2936 data->layered = TRUE;
2937 if (!data->embedded && argb_visual.visualid) set_window_visual( data, &argb_visual, TRUE );
2939 rect = *window_rect;
2940 OffsetRect( &rect, -window_rect->left, -window_rect->top );
2942 surface = data->surface;
2943 if (!surface || !EqualRect( &surface->rect, &rect ))
2945 data->surface = create_surface( data->whole_window, &data->vis, &rect,
2946 color_key, data->use_alpha );
2947 if (surface) window_surface_release( surface );
2948 surface = data->surface;
2950 else set_surface_color_key( surface, color_key );
2952 if (surface) window_surface_add_ref( surface );
2953 mapped = data->mapped;
2954 release_win_data( data );
2956 /* layered windows are mapped only once their attributes are set */
2957 if (!mapped)
2959 DWORD style = NtUserGetWindowLongW( hwnd, GWL_STYLE );
2961 if ((style & WS_VISIBLE) && ((style & WS_MINIMIZE) || is_window_rect_mapped( window_rect )))
2962 map_window( hwnd, style );
2965 if (!surface) return FALSE;
2966 if (!info->hdcSrc)
2968 window_surface_release( surface );
2969 return TRUE;
2972 dst_bits = surface->funcs->get_info( surface, bmi );
2974 if (!(dib = NtGdiCreateDIBSection( info->hdcDst, NULL, 0, bmi, DIB_RGB_COLORS, 0, 0, 0, &src_bits )))
2975 goto done;
2976 if (!(hdc = NtGdiCreateCompatibleDC( 0 ))) goto done;
2978 NtGdiSelectBitmap( hdc, dib );
2980 surface->funcs->lock( surface );
2982 if (info->prcDirty)
2984 intersect_rect( &rect, &rect, info->prcDirty );
2985 memcpy( src_bits, dst_bits, bmi->bmiHeader.biSizeImage );
2986 NtGdiPatBlt( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, BLACKNESS );
2988 src_rect = rect;
2989 if (info->pptSrc) OffsetRect( &src_rect, info->pptSrc->x, info->pptSrc->y );
2990 NtGdiTransformPoints( info->hdcSrc, (POINT *)&src_rect, (POINT *)&src_rect, 2, NtGdiDPtoLP );
2992 if (info->dwFlags & ULW_ALPHA) blend = *info->pblend;
2993 ret = NtGdiAlphaBlend( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
2994 info->hdcSrc, src_rect.left, src_rect.top,
2995 src_rect.right - src_rect.left, src_rect.bottom - src_rect.top,
2996 *(DWORD *)&blend, 0 );
2997 if (ret)
2999 memcpy( dst_bits, src_bits, bmi->bmiHeader.biSizeImage );
3000 add_bounds_rect( surface->funcs->get_bounds( surface ), &rect );
3003 surface->funcs->unlock( surface );
3004 surface->funcs->flush( surface );
3006 done:
3007 window_surface_release( surface );
3008 if (hdc) NtGdiDeleteObjectApp( hdc );
3009 if (dib) NtGdiDeleteObjectApp( dib );
3010 return ret;
3013 /* Add a window to taskbar */
3014 static void taskbar_add_tab( HWND hwnd )
3016 struct x11drv_win_data *data;
3018 TRACE("hwnd %p\n", hwnd);
3020 data = get_win_data( hwnd );
3021 if (!data)
3022 return;
3024 data->add_taskbar = TRUE;
3025 data->skip_taskbar = FALSE;
3026 update_net_wm_states( data );
3027 release_win_data( data );
3030 /* Delete a window from taskbar */
3031 static void taskbar_delete_tab( HWND hwnd )
3033 struct x11drv_win_data *data;
3035 TRACE("hwnd %p\n", hwnd);
3037 data = get_win_data( hwnd );
3038 if (!data)
3039 return;
3041 data->skip_taskbar = TRUE;
3042 data->add_taskbar = FALSE;
3043 update_net_wm_states( data );
3044 release_win_data( data );
3047 /**********************************************************************
3048 * X11DRV_WindowMessage (X11DRV.@)
3050 LRESULT X11DRV_WindowMessage( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
3052 struct x11drv_win_data *data;
3054 switch(msg)
3056 case WM_X11DRV_UPDATE_CLIPBOARD:
3057 return update_clipboard( hwnd );
3058 case WM_X11DRV_SET_WIN_REGION:
3059 if ((data = get_win_data( hwnd )))
3061 sync_window_region( data, (HRGN)1 );
3062 release_win_data( data );
3064 return 0;
3065 case WM_X11DRV_DESKTOP_RESIZED:
3066 if ((data = get_win_data( hwnd )))
3068 /* update the full screen state */
3069 update_net_wm_states( data );
3071 if (data->whole_window)
3073 /* sync window position with the new virtual screen rect */
3074 POINT old_pos = {.x = data->whole_rect.left - wp, .y = data->whole_rect.top - lp};
3075 POINT pos = virtual_screen_to_root( data->whole_rect.left, data->whole_rect.top );
3076 XWindowChanges changes = {.x = pos.x, .y = pos.y};
3077 UINT mask = 0;
3079 if (old_pos.x != pos.x) mask |= CWX;
3080 if (old_pos.y != pos.y) mask |= CWY;
3082 if (mask) XReconfigureWMWindow( data->display, data->whole_window, data->vis.screen, mask, &changes );
3085 release_win_data( data );
3087 return 0;
3088 case WM_X11DRV_DELETE_TAB:
3089 taskbar_delete_tab( hwnd );
3090 return 0;
3091 case WM_X11DRV_ADD_TAB:
3092 taskbar_add_tab( hwnd );
3093 return 0;
3094 default:
3095 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg, hwnd, (long)wp, lp );
3096 return 0;
3101 /***********************************************************************
3102 * is_netwm_supported
3104 static BOOL is_netwm_supported( Display *display, Atom atom )
3106 static Atom *net_supported;
3107 static int net_supported_count = -1;
3108 int i;
3110 if (net_supported_count == -1)
3112 Atom type;
3113 int format;
3114 unsigned long count, remaining;
3116 if (!XGetWindowProperty( display, DefaultRootWindow(display), x11drv_atom(_NET_SUPPORTED), 0,
3117 ~0UL, False, XA_ATOM, &type, &format, &count,
3118 &remaining, (unsigned char **)&net_supported ))
3119 net_supported_count = get_property_size( format, count ) / sizeof(Atom);
3120 else
3121 net_supported_count = 0;
3124 for (i = 0; i < net_supported_count; i++)
3125 if (net_supported[i] == atom) return TRUE;
3126 return FALSE;
3130 /***********************************************************************
3131 * start_screensaver
3133 static LRESULT start_screensaver(void)
3135 if (!is_virtual_desktop())
3137 const char *argv[3] = { "xdg-screensaver", "activate", NULL };
3138 int pid = __wine_unix_spawnvp( (char **)argv, FALSE );
3139 if (pid > 0)
3141 TRACE( "started process %d\n", pid );
3142 return 0;
3145 return -1;
3149 /***********************************************************************
3150 * SysCommand (X11DRV.@)
3152 * Perform WM_SYSCOMMAND handling.
3154 LRESULT X11DRV_SysCommand( HWND hwnd, WPARAM wparam, LPARAM lparam )
3156 WPARAM hittest = wparam & 0x0f;
3157 int dir;
3158 struct x11drv_win_data *data;
3160 if (!(data = get_win_data( hwnd )))
3162 if (wparam == SC_SCREENSAVE && hwnd == NtUserGetDesktopWindow()) return start_screensaver();
3163 return -1;
3165 if (!data->whole_window || !data->managed || !data->mapped) goto failed;
3167 switch (wparam & 0xfff0)
3169 case SC_MOVE:
3170 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
3171 else dir = _NET_WM_MOVERESIZE_MOVE;
3172 break;
3173 case SC_SIZE:
3174 /* windows without WS_THICKFRAME are not resizable through the window manager */
3175 if (!(NtUserGetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) goto failed;
3177 switch (hittest)
3179 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
3180 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
3181 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
3182 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
3183 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
3184 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
3185 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
3186 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
3187 case 9: dir = _NET_WM_MOVERESIZE_MOVE; break;
3188 default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break;
3190 break;
3192 case SC_KEYMENU:
3193 /* prevent a simple ALT press+release from activating the system menu,
3194 * as that can get confusing on managed windows */
3195 if ((WCHAR)lparam) goto failed; /* got an explicit char */
3196 if (NtUserGetWindowLongPtrW( hwnd, GWLP_ID )) goto failed; /* window has a real menu */
3197 if (!(NtUserGetWindowLongW( hwnd, GWL_STYLE ) & WS_SYSMENU)) goto failed; /* no system menu */
3198 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", (long)wparam, lparam );
3199 release_win_data( data );
3200 return 0;
3202 default:
3203 goto failed;
3206 if (NtUserGetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE) goto failed;
3208 if (!is_netwm_supported( data->display, x11drv_atom(_NET_WM_MOVERESIZE) ))
3210 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
3211 goto failed;
3214 release_win_data( data );
3215 move_resize_window( hwnd, dir );
3216 return 0;
3218 failed:
3219 release_win_data( data );
3220 return -1;
3223 void X11DRV_FlashWindowEx( FLASHWINFO *pfinfo )
3225 struct x11drv_win_data *data = get_win_data( pfinfo->hwnd );
3226 XEvent xev;
3228 if (!data)
3229 return;
3231 if (data->mapped)
3233 xev.type = ClientMessage;
3234 xev.xclient.window = data->whole_window;
3235 xev.xclient.message_type = x11drv_atom( _NET_WM_STATE );
3236 xev.xclient.serial = 0;
3237 xev.xclient.display = data->display;
3238 xev.xclient.send_event = True;
3239 xev.xclient.format = 32;
3240 xev.xclient.data.l[0] = pfinfo->dwFlags ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
3241 xev.xclient.data.l[1] = x11drv_atom( _NET_WM_STATE_DEMANDS_ATTENTION );
3242 xev.xclient.data.l[2] = 0;
3243 xev.xclient.data.l[3] = 1;
3244 xev.xclient.data.l[4] = 0;
3246 XSendEvent( data->display, DefaultRootWindow( data->display ), False,
3247 SubstructureNotifyMask, &xev );
3249 release_win_data( data );
3252 void init_win_context(void)
3254 init_recursive_mutex( &win_data_mutex );
3256 winContext = XUniqueContext();
3257 win_data_context = XUniqueContext();
3258 cursor_context = XUniqueContext();