opengl32: Correctly interpret glMapBuffer() access in wow64 mapping.
[wine.git] / dlls / winex11.drv / window.c
blob14490ecd028d5c8b303f89a8f362e0f7d9b55076
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;
1515 dummy_parent = XCreateWindow( gdi_display, root_window, -1, -1, 1, 1, 0, default_visual.depth,
1516 InputOutput, default_visual.visual,
1517 CWColormap | CWBorderPixel | CWOverrideRedirect, &attrib );
1518 XMapWindow( gdi_display, dummy_parent );
1520 return dummy_parent;
1524 /**********************************************************************
1525 * create_dummy_client_window
1527 Window create_dummy_client_window(void)
1529 XSetWindowAttributes attr;
1531 attr.colormap = default_colormap;
1532 attr.bit_gravity = NorthWestGravity;
1533 attr.win_gravity = NorthWestGravity;
1534 attr.backing_store = NotUseful;
1535 attr.border_pixel = 0;
1537 return XCreateWindow( gdi_display, get_dummy_parent(), 0, 0, 1, 1, 0,
1538 default_visual.depth, InputOutput, default_visual.visual,
1539 CWBitGravity | CWWinGravity | CWBackingStore | CWColormap | CWBorderPixel, &attr );
1542 /**********************************************************************
1543 * create_client_window
1545 Window create_client_window( HWND hwnd, const XVisualInfo *visual )
1547 Window dummy_parent = get_dummy_parent();
1548 struct x11drv_win_data *data = get_win_data( hwnd );
1549 XSetWindowAttributes attr;
1550 Window ret;
1551 int x, y, cx, cy;
1553 if (!data)
1555 /* explicitly create data for HWND_MESSAGE windows since they can be used for OpenGL */
1556 HWND parent = NtUserGetAncestor( hwnd, GA_PARENT );
1557 if (parent == NtUserGetDesktopWindow() || NtUserGetAncestor( parent, GA_PARENT )) return 0;
1558 if (!(data = alloc_win_data( thread_init_display(), hwnd ))) return 0;
1559 NtUserGetClientRect( hwnd, &data->client_rect );
1560 data->window_rect = data->whole_rect = data->client_rect;
1563 if (data->client_window)
1565 XDeleteContext( data->display, data->client_window, winContext );
1566 XReparentWindow( gdi_display, data->client_window, dummy_parent, 0, 0 );
1567 TRACE( "%p reparent xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1570 if (data->client_colormap) XFreeColormap( gdi_display, data->client_colormap );
1571 data->client_colormap = XCreateColormap( gdi_display, dummy_parent, visual->visual,
1572 (visual->class == PseudoColor ||
1573 visual->class == GrayScale ||
1574 visual->class == DirectColor) ? AllocAll : AllocNone );
1575 attr.colormap = data->client_colormap;
1576 attr.bit_gravity = NorthWestGravity;
1577 attr.win_gravity = NorthWestGravity;
1578 attr.backing_store = NotUseful;
1579 attr.border_pixel = 0;
1581 x = data->client_rect.left - data->whole_rect.left;
1582 y = data->client_rect.top - data->whole_rect.top;
1583 cx = min( max( 1, data->client_rect.right - data->client_rect.left ), 65535 );
1584 cy = min( max( 1, data->client_rect.bottom - data->client_rect.top ), 65535 );
1586 XSync( gdi_display, False ); /* make sure whole_window is known from gdi_display */
1587 ret = data->client_window = XCreateWindow( gdi_display,
1588 data->whole_window ? data->whole_window : dummy_parent,
1589 x, y, cx, cy, 0, default_visual.depth, InputOutput,
1590 visual->visual, CWBitGravity | CWWinGravity |
1591 CWBackingStore | CWColormap | CWBorderPixel, &attr );
1592 if (data->client_window)
1594 XSaveContext( data->display, data->client_window, winContext, (char *)data->hwnd );
1595 XMapWindow( gdi_display, data->client_window );
1596 if (data->whole_window)
1598 XFlush( gdi_display ); /* make sure client_window is created for XSelectInput */
1599 XSync( data->display, False ); /* make sure client_window is known from data->display */
1600 XSelectInput( data->display, data->client_window, ExposureMask );
1602 TRACE( "%p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1604 release_win_data( data );
1605 return ret;
1609 /**********************************************************************
1610 * create_whole_window
1612 * Create the whole X window for a given window
1614 static void create_whole_window( struct x11drv_win_data *data )
1616 int cx, cy, mask;
1617 XSetWindowAttributes attr;
1618 WCHAR text[1024];
1619 COLORREF key;
1620 BYTE alpha;
1621 DWORD layered_flags;
1622 HRGN win_rgn;
1623 POINT pos;
1625 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1627 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1628 data->managed = TRUE;
1631 if ((win_rgn = NtGdiCreateRectRgn( 0, 0, 0, 0 )) &&
1632 NtUserGetWindowRgnEx( data->hwnd, win_rgn, 0 ) == ERROR)
1634 NtGdiDeleteObjectApp( win_rgn );
1635 win_rgn = 0;
1637 data->shaped = (win_rgn != 0);
1639 if (data->vis.visualid != default_visual.visualid)
1640 data->whole_colormap = XCreateColormap( data->display, root_window, data->vis.visual, AllocNone );
1642 mask = get_window_attributes( data, &attr );
1644 if (!(cx = data->whole_rect.right - data->whole_rect.left)) cx = 1;
1645 else if (cx > 65535) cx = 65535;
1646 if (!(cy = data->whole_rect.bottom - data->whole_rect.top)) cy = 1;
1647 else if (cy > 65535) cy = 65535;
1649 pos = virtual_screen_to_root( data->whole_rect.left, data->whole_rect.top );
1650 data->whole_window = XCreateWindow( data->display, root_window, pos.x, pos.y,
1651 cx, cy, 0, data->vis.depth, InputOutput,
1652 data->vis.visual, mask, &attr );
1653 if (!data->whole_window) goto done;
1655 set_initial_wm_hints( data->display, data->whole_window );
1656 set_wm_hints( data );
1658 XSaveContext( data->display, data->whole_window, winContext, (char *)data->hwnd );
1659 NtUserSetProp( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
1661 /* set the window text */
1662 if (!NtUserInternalGetWindowText( data->hwnd, text, ARRAY_SIZE( text ))) text[0] = 0;
1663 sync_window_text( data->display, data->whole_window, text );
1665 /* set the window region */
1666 if (win_rgn || IsRectEmpty( &data->window_rect )) sync_window_region( data, win_rgn );
1668 /* set the window opacity */
1669 if (!NtUserGetLayeredWindowAttributes( data->hwnd, &key, &alpha, &layered_flags )) layered_flags = 0;
1670 sync_window_opacity( data->display, data->whole_window, key, alpha, layered_flags );
1672 XFlush( data->display ); /* make sure the window exists before we start painting to it */
1674 done:
1675 if (win_rgn) NtGdiDeleteObjectApp( win_rgn );
1679 /**********************************************************************
1680 * destroy_whole_window
1682 * Destroy the whole X window for a given window.
1684 static void destroy_whole_window( struct x11drv_win_data *data, BOOL already_destroyed )
1686 TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1688 if (data->client_window) XDeleteContext( data->display, data->client_window, winContext );
1690 if (!data->whole_window)
1692 if (data->embedded)
1694 Window xwin = (Window)NtUserGetProp( data->hwnd, foreign_window_prop );
1695 if (xwin)
1697 if (!already_destroyed) XSelectInput( data->display, xwin, 0 );
1698 XDeleteContext( data->display, xwin, winContext );
1699 NtUserRemoveProp( data->hwnd, foreign_window_prop );
1701 return;
1704 else
1706 if (data->client_window && !already_destroyed)
1708 XSelectInput( data->display, data->client_window, 0 );
1709 XFlush( data->display ); /* make sure XSelectInput doesn't use client_window after this point */
1710 XReparentWindow( gdi_display, data->client_window, get_dummy_parent(), 0, 0 );
1712 XDeleteContext( data->display, data->whole_window, winContext );
1713 if (!already_destroyed)
1715 XSync( gdi_display, False ); /* make sure XReparentWindow requests have completed before destroying whole_window */
1716 XDestroyWindow( data->display, data->whole_window );
1719 if (data->whole_colormap) XFreeColormap( data->display, data->whole_colormap );
1720 data->whole_window = data->client_window = 0;
1721 data->whole_colormap = 0;
1722 data->wm_state = WithdrawnState;
1723 data->net_wm_state = 0;
1724 data->mapped = FALSE;
1725 if (data->xic)
1727 XUnsetICFocus( data->xic );
1728 XDestroyIC( data->xic );
1729 data->xic = 0;
1731 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1732 XFlush( data->display );
1733 if (data->surface) window_surface_release( data->surface );
1734 data->surface = NULL;
1735 NtUserRemoveProp( data->hwnd, whole_window_prop );
1739 /**********************************************************************
1740 * set_window_visual
1742 * Change the visual by destroying and recreating the X window if needed.
1744 void set_window_visual( struct x11drv_win_data *data, const XVisualInfo *vis, BOOL use_alpha )
1746 Window client_window = data->client_window;
1747 Window whole_window = data->whole_window;
1749 if (!data->use_alpha == !use_alpha) return;
1750 if (data->surface) window_surface_release( data->surface );
1751 data->surface = NULL;
1752 data->use_alpha = use_alpha;
1754 if (data->vis.visualid == vis->visualid) return;
1755 data->client_window = 0;
1756 destroy_whole_window( data, client_window != 0 /* don't destroy whole_window until reparented */ );
1757 data->vis = *vis;
1758 create_whole_window( data );
1759 if (!client_window) return;
1760 /* move the client to the new parent */
1761 XReparentWindow( gdi_display, client_window, data->whole_window,
1762 data->client_rect.left - data->whole_rect.left,
1763 data->client_rect.top - data->whole_rect.top );
1764 data->client_window = client_window;
1765 XSync( gdi_display, False ); /* make sure XReparentWindow requests have completed before destroying whole_window */
1766 XDestroyWindow( data->display, whole_window );
1770 /*****************************************************************
1771 * SetWindowText (X11DRV.@)
1773 void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
1775 Window win;
1777 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(gdi_display))
1779 Display *display = thread_init_display();
1780 sync_window_text( display, win, text );
1785 /***********************************************************************
1786 * SetWindowStyle (X11DRV.@)
1788 * Update the X state of a window to reflect a style change
1790 void X11DRV_SetWindowStyle( HWND hwnd, INT offset, STYLESTRUCT *style )
1792 struct x11drv_win_data *data;
1793 DWORD changed = style->styleNew ^ style->styleOld;
1795 if (hwnd == NtUserGetDesktopWindow()) return;
1796 if (!(data = get_win_data( hwnd ))) return;
1797 if (!data->whole_window) goto done;
1799 if (offset == GWL_STYLE && (changed & WS_DISABLED)) set_wm_hints( data );
1801 if (offset == GWL_EXSTYLE && (changed & WS_EX_LAYERED)) /* changing WS_EX_LAYERED resets attributes */
1803 data->layered = FALSE;
1804 set_window_visual( data, &default_visual, FALSE );
1805 sync_window_opacity( data->display, data->whole_window, 0, 0, 0 );
1806 if (data->surface) set_surface_color_key( data->surface, CLR_INVALID );
1808 done:
1809 release_win_data( data );
1813 /***********************************************************************
1814 * DestroyWindow (X11DRV.@)
1816 void X11DRV_DestroyWindow( HWND hwnd )
1818 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1819 struct x11drv_win_data *data;
1821 if (!(data = get_win_data( hwnd ))) return;
1823 destroy_whole_window( data, FALSE );
1824 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
1825 if (thread_data->last_xic_hwnd == hwnd) thread_data->last_xic_hwnd = 0;
1826 if (data->icon_pixmap) XFreePixmap( gdi_display, data->icon_pixmap );
1827 if (data->icon_mask) XFreePixmap( gdi_display, data->icon_mask );
1828 if (data->client_colormap) XFreeColormap( data->display, data->client_colormap );
1829 free( data->icon_bits );
1830 XDeleteContext( gdi_display, (XID)hwnd, win_data_context );
1831 release_win_data( data );
1832 free( data );
1833 destroy_gl_drawable( hwnd );
1834 wine_vk_surface_destroy( hwnd );
1838 /***********************************************************************
1839 * X11DRV_DestroyNotify
1841 BOOL X11DRV_DestroyNotify( HWND hwnd, XEvent *event )
1843 struct x11drv_win_data *data;
1844 BOOL embedded;
1846 if (!(data = get_win_data( hwnd ))) return FALSE;
1847 embedded = data->embedded;
1848 if (!embedded) FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window );
1850 destroy_whole_window( data, TRUE );
1851 release_win_data( data );
1852 if (embedded) send_message( hwnd, WM_CLOSE, 0, 0 );
1853 return TRUE;
1857 /* initialize the desktop window id in the desktop manager process */
1858 static BOOL create_desktop_win_data( Window win, HWND hwnd )
1860 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1861 Display *display = thread_data->display;
1862 struct x11drv_win_data *data;
1864 if (!(data = alloc_win_data( display, hwnd ))) return FALSE;
1865 data->whole_window = win;
1866 data->managed = TRUE;
1867 NtUserSetProp( data->hwnd, whole_window_prop, (HANDLE)win );
1868 set_initial_wm_hints( display, win );
1869 release_win_data( data );
1870 if (thread_data->clip_window) XReparentWindow( display, thread_data->clip_window, win, 0, 0 );
1871 return TRUE;
1874 /**********************************************************************
1875 * SetDesktopWindow (X11DRV.@)
1877 void X11DRV_SetDesktopWindow( HWND hwnd )
1879 unsigned int width, height;
1881 /* retrieve the real size of the desktop */
1882 SERVER_START_REQ( get_window_rectangles )
1884 req->handle = wine_server_user_handle( hwnd );
1885 req->relative = COORDS_CLIENT;
1886 wine_server_call( req );
1887 width = reply->window.right;
1888 height = reply->window.bottom;
1890 SERVER_END_REQ;
1892 if (!width && !height) /* not initialized yet */
1894 RECT rect;
1896 X11DRV_DisplayDevices_Init( TRUE );
1897 rect = NtUserGetVirtualScreenRect();
1899 SERVER_START_REQ( set_window_pos )
1901 req->handle = wine_server_user_handle( hwnd );
1902 req->previous = 0;
1903 req->swp_flags = SWP_NOZORDER;
1904 req->window.left = rect.left;
1905 req->window.top = rect.top;
1906 req->window.right = rect.right;
1907 req->window.bottom = rect.bottom;
1908 req->client = req->window;
1909 wine_server_call( req );
1911 SERVER_END_REQ;
1913 if (!is_virtual_desktop()) return;
1914 if (!create_desktop_win_data( root_window, hwnd ))
1916 ERR( "Failed to create virtual desktop window data\n" );
1917 root_window = DefaultRootWindow( gdi_display );
1919 else if (is_desktop_fullscreen())
1921 Display *display = x11drv_thread_data()->display;
1922 TRACE("setting desktop to fullscreen\n");
1923 XChangeProperty( display, root_window, x11drv_atom(_NET_WM_STATE), XA_ATOM, 32, PropModeReplace,
1924 (unsigned char*)&x11drv_atom(_NET_WM_STATE_FULLSCREEN), 1 );
1927 else
1929 Window win = (Window)NtUserGetProp( hwnd, whole_window_prop );
1930 if (win && win != root_window)
1932 X11DRV_init_desktop( win, width, height );
1933 X11DRV_DisplayDevices_Init( TRUE );
1939 #define WM_WINE_NOTIFY_ACTIVITY WM_USER
1940 #define WM_WINE_DELETE_TAB (WM_USER + 1)
1941 #define WM_WINE_ADD_TAB (WM_USER + 2)
1943 /**********************************************************************
1944 * DesktopWindowProc (X11DRV.@)
1946 LRESULT X11DRV_DesktopWindowProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
1948 switch (msg)
1950 case WM_WINE_NOTIFY_ACTIVITY:
1952 static ULONG last = 0;
1953 ULONG now = NtGetTickCount();
1954 /* calling XResetScreenSaver too often can cause performance
1955 * problems, so throttle it */
1956 if (now > last + 5000)
1958 XResetScreenSaver( gdi_display );
1959 XFlush( gdi_display );
1960 last = now;
1962 break;
1964 case WM_WINE_DELETE_TAB:
1965 send_notify_message( (HWND)wp, WM_X11DRV_DELETE_TAB, 0, 0 );
1966 break;
1967 case WM_WINE_ADD_TAB:
1968 send_notify_message( (HWND)wp, WM_X11DRV_ADD_TAB, 0, 0 );
1969 break;
1970 case WM_DISPLAYCHANGE:
1971 X11DRV_resize_desktop();
1972 break;
1974 return NtUserMessageCall( hwnd, msg, wp, lp, 0, NtUserDefWindowProc, FALSE );
1977 /**********************************************************************
1978 * CreateWindow (X11DRV.@)
1980 BOOL X11DRV_CreateWindow( HWND hwnd )
1982 if (hwnd == NtUserGetDesktopWindow())
1984 struct x11drv_thread_data *data = x11drv_init_thread_data();
1985 XSetWindowAttributes attr;
1987 /* create the cursor clipping window */
1988 attr.override_redirect = TRUE;
1989 attr.event_mask = StructureNotifyMask | FocusChangeMask;
1990 data->clip_window = XCreateWindow( data->display, root_window, 0, 0, 1, 1, 0, 0,
1991 InputOnly, default_visual.visual,
1992 CWOverrideRedirect | CWEventMask, &attr );
1993 XFlush( data->display );
1994 NtUserSetProp( hwnd, clip_window_prop, (HANDLE)data->clip_window );
1995 X11DRV_DisplayDevices_RegisterEventHandlers();
1997 return TRUE;
2001 /***********************************************************************
2002 * get_win_data
2004 * Lock and return the X11 data structure associated with a window.
2006 struct x11drv_win_data *get_win_data( HWND hwnd )
2008 char *data;
2010 if (!hwnd) return NULL;
2011 pthread_mutex_lock( &win_data_mutex );
2012 if (!XFindContext( gdi_display, (XID)hwnd, win_data_context, &data ))
2013 return (struct x11drv_win_data *)data;
2014 pthread_mutex_unlock( &win_data_mutex );
2015 return NULL;
2019 /***********************************************************************
2020 * release_win_data
2022 * Release the data returned by get_win_data.
2024 void release_win_data( struct x11drv_win_data *data )
2026 if (data) pthread_mutex_unlock( &win_data_mutex );
2030 /***********************************************************************
2031 * X11DRV_create_win_data
2033 * Create an X11 data window structure for an existing window.
2035 static struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd, const RECT *window_rect,
2036 const RECT *client_rect )
2038 Display *display;
2039 struct x11drv_win_data *data;
2040 HWND parent;
2042 if (!(parent = NtUserGetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
2044 /* don't create win data for HWND_MESSAGE windows */
2045 if (parent != NtUserGetDesktopWindow() && !NtUserGetAncestor( parent, GA_PARENT )) return NULL;
2047 if (NtUserGetWindowThread( hwnd, NULL ) != GetCurrentThreadId()) return NULL;
2049 /* Recreate the parent gl_drawable now that we know there are child windows
2050 * that will need clipping support.
2052 sync_gl_drawable( parent, TRUE );
2054 display = thread_init_display();
2055 init_clip_window(); /* make sure the clip window is initialized in this thread */
2057 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
2059 data->whole_rect = data->window_rect = *window_rect;
2060 data->client_rect = *client_rect;
2061 if (parent == NtUserGetDesktopWindow())
2063 create_whole_window( data );
2064 TRACE( "win %p/%lx window %s whole %s client %s\n",
2065 hwnd, data->whole_window, wine_dbgstr_rect( &data->window_rect ),
2066 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
2068 return data;
2072 /***********************************************************************
2073 * create_foreign_window
2075 * Create a foreign window for the specified X window and its ancestors
2077 HWND create_foreign_window( Display *display, Window xwin )
2079 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};
2080 static BOOL class_registered;
2081 struct x11drv_win_data *data;
2082 HWND hwnd, parent;
2083 POINT pos;
2084 Window xparent, xroot;
2085 Window *xchildren;
2086 unsigned int nchildren;
2087 XWindowAttributes attr;
2088 UINT style = WS_CLIPCHILDREN;
2089 UNICODE_STRING class_name = RTL_CONSTANT_STRING( classW );
2091 if (!class_registered)
2093 UNICODE_STRING version = { 0 };
2094 WNDCLASSEXW class;
2096 memset( &class, 0, sizeof(class) );
2097 class.cbSize = sizeof(class);
2098 class.lpfnWndProc = client_foreign_window_proc;
2099 class.lpszClassName = classW;
2100 if (!NtUserRegisterClassExWOW( &class, &class_name, &version, NULL, 0, 0, NULL ) &&
2101 RtlGetLastWin32Error() != ERROR_CLASS_ALREADY_EXISTS)
2103 ERR( "Could not register foreign window class\n" );
2104 return FALSE;
2106 class_registered = TRUE;
2109 if (XFindContext( display, xwin, winContext, (char **)&hwnd )) hwnd = 0;
2110 if (hwnd) return hwnd; /* already created */
2112 XSelectInput( display, xwin, StructureNotifyMask );
2113 if (!XGetWindowAttributes( display, xwin, &attr ) ||
2114 !XQueryTree( display, xwin, &xroot, &xparent, &xchildren, &nchildren ))
2116 XSelectInput( display, xwin, 0 );
2117 return 0;
2119 XFree( xchildren );
2121 if (xparent == xroot)
2123 parent = NtUserGetDesktopWindow();
2124 style |= WS_POPUP;
2125 pos = root_to_virtual_screen( attr.x, attr.y );
2127 else
2129 parent = create_foreign_window( display, xparent );
2130 style |= WS_CHILD;
2131 pos.x = attr.x;
2132 pos.y = attr.y;
2135 RtlInitUnicodeString( &class_name, classW );
2136 hwnd = NtUserCreateWindowEx( 0, &class_name, &class_name, NULL, style, pos.x, pos.y,
2137 attr.width, attr.height, parent, 0, NULL, NULL, 0, NULL,
2138 0, FALSE );
2140 if (!(data = alloc_win_data( display, hwnd )))
2142 NtUserDestroyWindow( hwnd );
2143 return 0;
2145 SetRect( &data->window_rect, pos.x, pos.y, pos.x + attr.width, pos.y + attr.height );
2146 data->whole_rect = data->client_rect = data->window_rect;
2147 data->whole_window = data->client_window = 0;
2148 data->embedded = TRUE;
2149 data->mapped = TRUE;
2151 NtUserSetProp( hwnd, foreign_window_prop, (HANDLE)xwin );
2152 XSaveContext( display, xwin, winContext, (char *)data->hwnd );
2154 TRACE( "win %lx parent %p style %08x %s -> hwnd %p\n",
2155 xwin, parent, style, wine_dbgstr_rect(&data->window_rect), hwnd );
2157 release_win_data( data );
2159 NtUserShowWindow( hwnd, SW_SHOW );
2160 return hwnd;
2164 NTSTATUS x11drv_systray_init( void *arg )
2166 Display *display;
2168 if (is_virtual_desktop()) return FALSE;
2170 display = thread_init_display();
2171 if (DefaultScreen( display ) == 0)
2172 systray_atom = x11drv_atom(_NET_SYSTEM_TRAY_S0);
2173 else
2175 char systray_buffer[29]; /* strlen(_NET_SYSTEM_TRAY_S4294967295)+1 */
2176 sprintf( systray_buffer, "_NET_SYSTEM_TRAY_S%u", DefaultScreen( display ) );
2177 systray_atom = XInternAtom( display, systray_buffer, False );
2179 XSelectInput( display, root_window, StructureNotifyMask );
2181 return TRUE;
2185 NTSTATUS x11drv_systray_clear( void *arg )
2187 HWND hwnd = *(HWND*)arg;
2188 Window win = X11DRV_get_whole_window( hwnd );
2189 if (win) XClearArea( gdi_display, win, 0, 0, 0, 0, True );
2190 return 0;
2194 NTSTATUS x11drv_systray_hide( void *arg )
2196 HWND hwnd = *(HWND*)arg;
2197 struct x11drv_win_data *data;
2199 /* make sure we don't try to unmap it, it confuses some systray docks */
2200 if ((data = get_win_data( hwnd )))
2202 if (data->embedded) data->mapped = FALSE;
2203 release_win_data( data );
2206 return 0;
2210 /* find the X11 window owner the system tray selection */
2211 static Window get_systray_selection_owner( Display *display )
2213 return XGetSelectionOwner( display, systray_atom );
2217 static void get_systray_visual_info( Display *display, Window systray_window, XVisualInfo *info )
2219 XVisualInfo *list, template;
2220 VisualID *visual_id;
2221 Atom type;
2222 int format, num;
2223 unsigned long count, remaining;
2225 *info = default_visual;
2226 if (XGetWindowProperty( display, systray_window, x11drv_atom(_NET_SYSTEM_TRAY_VISUAL), 0,
2227 65536/sizeof(CARD32), False, XA_VISUALID, &type, &format, &count,
2228 &remaining, (unsigned char **)&visual_id ))
2229 return;
2231 if (type == XA_VISUALID && format == 32)
2233 template.visualid = visual_id[0];
2234 if ((list = XGetVisualInfo( display, VisualIDMask, &template, &num )))
2236 *info = list[0];
2237 TRACE_(systray)( "systray window %lx got visual %lx\n", systray_window, info->visualid );
2238 XFree( list );
2241 XFree( visual_id );
2245 NTSTATUS x11drv_systray_dock( void *arg )
2247 struct systray_dock_params *params = arg;
2248 Window systray_window, window;
2249 Display *display;
2250 XEvent ev;
2251 XSetWindowAttributes attr;
2252 XVisualInfo visual;
2253 struct x11drv_win_data *data;
2254 UNICODE_STRING class_name;
2255 BOOL layered;
2256 HWND hwnd;
2258 static const WCHAR icon_classname[] =
2259 {'_','_','w','i','n','e','x','1','1','_','t','r','a','y','_','i','c','o','n',0};
2261 if (params->event_handle)
2263 XClientMessageEvent *event = (XClientMessageEvent *)(UINT_PTR)params->event_handle;
2264 display = event->display;
2265 systray_window = event->data.l[2];
2267 else
2269 display = thread_init_display();
2270 if (!(systray_window = get_systray_selection_owner( display ))) return STATUS_UNSUCCESSFUL;
2273 get_systray_visual_info( display, systray_window, &visual );
2275 *params->layered = layered = (visual.depth == 32);
2277 RtlInitUnicodeString( &class_name, icon_classname );
2278 hwnd = NtUserCreateWindowEx( layered ? WS_EX_LAYERED : 0, &class_name, &class_name, NULL,
2279 WS_CLIPSIBLINGS | WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
2280 params->cx, params->cy, NULL, 0, NULL, params->icon, 0,
2281 NULL, 0, FALSE );
2283 if (!(data = get_win_data( hwnd ))) return STATUS_UNSUCCESSFUL;
2284 if (layered) set_window_visual( data, &visual, TRUE );
2285 make_window_embedded( data );
2286 window = data->whole_window;
2287 release_win_data( data );
2289 NtUserShowWindow( hwnd, SW_SHOWNA );
2291 TRACE_(systray)( "icon window %p/%lx\n", hwnd, window );
2293 /* send the docking request message */
2294 ev.xclient.type = ClientMessage;
2295 ev.xclient.window = systray_window;
2296 ev.xclient.message_type = x11drv_atom( _NET_SYSTEM_TRAY_OPCODE );
2297 ev.xclient.format = 32;
2298 ev.xclient.data.l[0] = CurrentTime;
2299 ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
2300 ev.xclient.data.l[2] = window;
2301 ev.xclient.data.l[3] = 0;
2302 ev.xclient.data.l[4] = 0;
2303 XSendEvent( display, systray_window, False, NoEventMask, &ev );
2305 if (!layered)
2307 attr.background_pixmap = ParentRelative;
2308 attr.bit_gravity = ForgetGravity;
2309 XChangeWindowAttributes( display, window, CWBackPixmap | CWBitGravity, &attr );
2311 else
2313 /* force repainig */
2314 send_message( hwnd, WM_SIZE, SIZE_RESTORED, MAKELONG( params->cx, params->cy ));
2317 return STATUS_SUCCESS;
2321 /***********************************************************************
2322 * X11DRV_get_whole_window
2324 * Return the X window associated with the full area of a window
2326 Window X11DRV_get_whole_window( HWND hwnd )
2328 struct x11drv_win_data *data = get_win_data( hwnd );
2329 Window ret;
2331 if (!data)
2333 if (hwnd == NtUserGetDesktopWindow()) return root_window;
2334 return (Window)NtUserGetProp( hwnd, whole_window_prop );
2336 ret = data->whole_window;
2337 release_win_data( data );
2338 return ret;
2342 /***********************************************************************
2343 * X11DRV_GetDC (X11DRV.@)
2345 void X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect,
2346 const RECT *top_rect, DWORD flags )
2348 struct x11drv_escape_set_drawable escape;
2349 HWND parent;
2351 escape.code = X11DRV_SET_DRAWABLE;
2352 escape.mode = IncludeInferiors;
2353 escape.drawable = 0;
2355 escape.dc_rect.left = win_rect->left - top_rect->left;
2356 escape.dc_rect.top = win_rect->top - top_rect->top;
2357 escape.dc_rect.right = win_rect->right - top_rect->left;
2358 escape.dc_rect.bottom = win_rect->bottom - top_rect->top;
2360 if (top == hwnd)
2362 struct x11drv_win_data *data = get_win_data( hwnd );
2364 escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd );
2366 /* special case: when repainting the root window, clip out top-level windows */
2367 if (data && data->whole_window == root_window) escape.mode = ClipByChildren;
2368 release_win_data( data );
2370 else
2372 /* find the first ancestor that has a drawable */
2373 for (parent = hwnd; parent && parent != top; parent = NtUserGetAncestor( parent, GA_PARENT ))
2374 if ((escape.drawable = X11DRV_get_whole_window( parent ))) break;
2376 if (escape.drawable)
2378 POINT pt = { 0, 0 };
2379 NtUserMapWindowPoints( 0, parent, &pt, 1 );
2380 escape.dc_rect = *win_rect;
2381 OffsetRect( &escape.dc_rect, pt.x, pt.y );
2382 if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren;
2384 else escape.drawable = X11DRV_get_whole_window( top );
2387 NtGdiExtEscape( hdc, NULL, 0, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2391 /***********************************************************************
2392 * X11DRV_ReleaseDC (X11DRV.@)
2394 void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
2396 struct x11drv_escape_set_drawable escape;
2398 escape.code = X11DRV_SET_DRAWABLE;
2399 escape.drawable = root_window;
2400 escape.mode = IncludeInferiors;
2401 escape.dc_rect = NtUserGetVirtualScreenRect();
2402 OffsetRect( &escape.dc_rect, -2 * escape.dc_rect.left, -2 * escape.dc_rect.top );
2403 NtGdiExtEscape( hdc, NULL, 0, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2407 /*************************************************************************
2408 * ScrollDC (X11DRV.@)
2410 BOOL X11DRV_ScrollDC( HDC hdc, INT dx, INT dy, HRGN update )
2412 RECT rect;
2413 BOOL ret;
2414 HRGN expose_rgn = 0;
2416 NtGdiGetAppClipBox( hdc, &rect );
2418 if (update)
2420 INT code = X11DRV_START_EXPOSURES;
2421 NtGdiExtEscape( hdc, NULL, 0, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2423 ret = NtGdiBitBlt( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
2424 hdc, rect.left - dx, rect.top - dy, SRCCOPY, 0, 0 );
2426 code = X11DRV_END_EXPOSURES;
2427 NtGdiExtEscape( hdc, NULL, 0, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code,
2428 sizeof(expose_rgn), (LPSTR)&expose_rgn );
2429 if (expose_rgn)
2431 NtGdiCombineRgn( update, update, expose_rgn, RGN_OR );
2432 NtGdiDeleteObjectApp( expose_rgn );
2435 else ret = NtGdiBitBlt( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
2436 hdc, rect.left - dx, rect.top - dy, SRCCOPY, 0, 0 );
2438 return ret;
2442 /***********************************************************************
2443 * SetCapture (X11DRV.@)
2445 void X11DRV_SetCapture( HWND hwnd, UINT flags )
2447 struct x11drv_thread_data *thread_data = x11drv_thread_data();
2448 struct x11drv_win_data *data;
2450 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
2452 if (hwnd)
2454 if (!(data = get_win_data( NtUserGetAncestor( hwnd, GA_ROOT )))) return;
2455 if (data->whole_window)
2457 XFlush( gdi_display );
2458 XGrabPointer( data->display, data->whole_window, False,
2459 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
2460 GrabModeAsync, GrabModeAsync, None, None, CurrentTime );
2461 thread_data->grab_hwnd = data->hwnd;
2463 release_win_data( data );
2465 else /* release capture */
2467 if (!(data = get_win_data( thread_data->grab_hwnd ))) return;
2468 XFlush( gdi_display );
2469 XUngrabPointer( data->display, CurrentTime );
2470 XFlush( data->display );
2471 thread_data->grab_hwnd = NULL;
2472 release_win_data( data );
2477 /*****************************************************************
2478 * SetParent (X11DRV.@)
2480 void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
2482 struct x11drv_win_data *data;
2484 if (parent == old_parent) return;
2485 if (!(data = get_win_data( hwnd ))) return;
2486 if (data->embedded) goto done;
2488 if (parent != NtUserGetDesktopWindow()) /* a child window */
2490 if (old_parent == NtUserGetDesktopWindow())
2492 /* destroy the old X windows */
2493 destroy_whole_window( data, FALSE );
2494 data->managed = FALSE;
2497 else /* new top level window */
2499 create_whole_window( data );
2501 done:
2502 release_win_data( data );
2503 set_gl_drawable_parent( hwnd, parent );
2505 /* Recreate the parent gl_drawable now that we know there are child windows
2506 * that will need clipping support.
2508 sync_gl_drawable( parent, TRUE );
2510 fetch_icon_data( hwnd, 0, 0 );
2514 static inline BOOL get_surface_rect( const RECT *visible_rect, RECT *surface_rect )
2516 *surface_rect = NtUserGetVirtualScreenRect();
2518 if (!intersect_rect( surface_rect, surface_rect, visible_rect )) return FALSE;
2519 OffsetRect( surface_rect, -visible_rect->left, -visible_rect->top );
2520 surface_rect->left &= ~31;
2521 surface_rect->top &= ~31;
2522 surface_rect->right = max( surface_rect->left + 32, (surface_rect->right + 31) & ~31 );
2523 surface_rect->bottom = max( surface_rect->top + 32, (surface_rect->bottom + 31) & ~31 );
2524 return TRUE;
2528 /***********************************************************************
2529 * WindowPosChanging (X11DRV.@)
2531 BOOL X11DRV_WindowPosChanging( HWND hwnd, HWND insert_after, UINT swp_flags,
2532 const RECT *window_rect, const RECT *client_rect, RECT *visible_rect,
2533 struct window_surface **surface )
2535 struct x11drv_win_data *data = get_win_data( hwnd );
2536 RECT surface_rect;
2537 DWORD flags;
2538 COLORREF key;
2539 BOOL layered = NtUserGetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYERED;
2541 if (!data && !(data = X11DRV_create_win_data( hwnd, window_rect, client_rect ))) return TRUE;
2543 /* check if we need to switch the window to managed */
2544 if (!data->managed && data->whole_window && is_window_managed( hwnd, swp_flags, window_rect ))
2546 TRACE( "making win %p/%lx managed\n", hwnd, data->whole_window );
2547 release_win_data( data );
2548 unmap_window( hwnd );
2549 if (!(data = get_win_data( hwnd ))) return TRUE;
2550 data->managed = TRUE;
2553 *visible_rect = *window_rect;
2554 X11DRV_window_to_X_rect( data, visible_rect, window_rect, client_rect );
2556 /* create the window surface if necessary */
2558 if (!data->whole_window && !data->embedded) goto done;
2559 if (swp_flags & SWP_HIDEWINDOW) goto done;
2560 if (data->use_alpha) goto done;
2561 if (!get_surface_rect( visible_rect, &surface_rect )) goto done;
2563 if (*surface) window_surface_release( *surface );
2564 *surface = NULL; /* indicate that we want to draw directly to the window */
2566 if (data->embedded) goto done;
2567 if (data->whole_window == root_window) goto done;
2568 if (data->client_window) goto done;
2569 if (!client_side_graphics && !layered) goto done;
2571 if (data->surface)
2573 if (EqualRect( &data->surface->rect, &surface_rect ))
2575 /* existing surface is good enough */
2576 window_surface_add_ref( data->surface );
2577 *surface = data->surface;
2578 goto done;
2581 else if (!(swp_flags & SWP_SHOWWINDOW) && !(NtUserGetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)) goto done;
2583 if (!layered || !NtUserGetLayeredWindowAttributes( hwnd, &key, NULL, &flags ) || !(flags & LWA_COLORKEY))
2584 key = CLR_INVALID;
2586 *surface = create_surface( data->whole_window, &data->vis, &surface_rect, key, FALSE );
2588 done:
2589 release_win_data( data );
2590 return TRUE;
2594 /***********************************************************************
2595 * WindowPosChanged (X11DRV.@)
2597 void X11DRV_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_flags,
2598 const RECT *rectWindow, const RECT *rectClient,
2599 const RECT *visible_rect, const RECT *valid_rects,
2600 struct window_surface *surface )
2602 struct x11drv_thread_data *thread_data;
2603 struct x11drv_win_data *data;
2604 UINT new_style = NtUserGetWindowLongW( hwnd, GWL_STYLE );
2605 RECT old_window_rect, old_whole_rect, old_client_rect;
2606 int event_type;
2608 if (!(data = get_win_data( hwnd ))) return;
2610 thread_data = x11drv_thread_data();
2612 old_window_rect = data->window_rect;
2613 old_whole_rect = data->whole_rect;
2614 old_client_rect = data->client_rect;
2615 data->window_rect = *rectWindow;
2616 data->whole_rect = *visible_rect;
2617 data->client_rect = *rectClient;
2618 if (data->vis.visualid == default_visual.visualid)
2620 if (surface) window_surface_add_ref( surface );
2621 if (data->surface) window_surface_release( data->surface );
2622 data->surface = surface;
2625 TRACE( "win %p window %s client %s style %08x flags %08x\n",
2626 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style, swp_flags );
2628 if (!IsRectEmpty( &valid_rects[0] ))
2630 Window window = data->whole_window;
2631 int x_offset = old_whole_rect.left - data->whole_rect.left;
2632 int y_offset = old_whole_rect.top - data->whole_rect.top;
2634 /* if all that happened is that the whole window moved, copy everything */
2635 if (!(swp_flags & SWP_FRAMECHANGED) &&
2636 old_whole_rect.right - data->whole_rect.right == x_offset &&
2637 old_whole_rect.bottom - data->whole_rect.bottom == y_offset &&
2638 old_client_rect.left - data->client_rect.left == x_offset &&
2639 old_client_rect.right - data->client_rect.right == x_offset &&
2640 old_client_rect.top - data->client_rect.top == y_offset &&
2641 old_client_rect.bottom - data->client_rect.bottom == y_offset &&
2642 EqualRect( &valid_rects[0], &data->client_rect ))
2644 /* if we have an X window the bits will be moved by the X server */
2645 if (!window && (x_offset != 0 || y_offset != 0))
2647 release_win_data( data );
2648 move_window_bits( hwnd, window, &old_whole_rect, visible_rect,
2649 &old_client_rect, rectClient, rectWindow );
2650 if (!(data = get_win_data( hwnd ))) return;
2653 else
2655 release_win_data( data );
2656 move_window_bits( hwnd, window, &valid_rects[1], &valid_rects[0],
2657 &old_client_rect, rectClient, rectWindow );
2658 if (!(data = get_win_data( hwnd ))) return;
2662 XFlush( gdi_display ); /* make sure painting is done before we move the window */
2664 sync_client_position( data, &old_client_rect, &old_whole_rect );
2666 if (!data->whole_window)
2668 BOOL needs_resize = (!data->client_window &&
2669 (data->client_rect.right - data->client_rect.left !=
2670 old_client_rect.right - old_client_rect.left ||
2671 data->client_rect.bottom - data->client_rect.top !=
2672 old_client_rect.bottom - old_client_rect.top));
2673 release_win_data( data );
2674 if (needs_resize) sync_gl_drawable( hwnd, FALSE );
2675 return;
2678 /* check if we are currently processing an event relevant to this window */
2679 event_type = 0;
2680 if (thread_data &&
2681 thread_data->current_event &&
2682 thread_data->current_event->xany.window == data->whole_window)
2684 event_type = thread_data->current_event->type;
2685 if (event_type != ConfigureNotify && event_type != PropertyNotify &&
2686 event_type != GravityNotify && event_type != ReparentNotify)
2687 event_type = 0; /* ignore other events */
2690 if (data->mapped && event_type != ReparentNotify)
2692 if (((swp_flags & SWP_HIDEWINDOW) && !(new_style & WS_VISIBLE)) ||
2693 (!event_type && !(new_style & WS_MINIMIZE) &&
2694 !is_window_rect_mapped( rectWindow ) && is_window_rect_mapped( &old_window_rect )))
2696 release_win_data( data );
2697 unmap_window( hwnd );
2698 if (NtUserIsWindowRectFullScreen( &old_window_rect )) NtUserClipCursor( NULL );
2699 if (!(data = get_win_data( hwnd ))) return;
2703 /* don't change position if we are about to minimize or maximize a managed window */
2704 if (!event_type &&
2705 !(data->managed && (swp_flags & SWP_STATECHANGED) && (new_style & (WS_MINIMIZE|WS_MAXIMIZE))))
2706 sync_window_position( data, swp_flags, &old_window_rect, &old_whole_rect, &old_client_rect );
2708 if ((new_style & WS_VISIBLE) &&
2709 ((new_style & WS_MINIMIZE) || is_window_rect_mapped( rectWindow )))
2711 if (!data->mapped)
2713 BOOL needs_icon = !data->icon_pixmap;
2714 BOOL needs_map = TRUE;
2716 /* layered windows are mapped only once their attributes are set */
2717 if (NtUserGetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYERED)
2718 needs_map = data->layered || IsRectEmpty( rectWindow );
2719 release_win_data( data );
2720 if (needs_icon) fetch_icon_data( hwnd, 0, 0 );
2721 if (needs_map) map_window( hwnd, new_style );
2722 return;
2724 else if ((swp_flags & SWP_STATECHANGED) && (!data->iconic != !(new_style & WS_MINIMIZE)))
2726 set_wm_hints( data );
2727 data->iconic = (new_style & WS_MINIMIZE) != 0;
2728 TRACE( "changing win %p iconic state to %u\n", data->hwnd, data->iconic );
2729 if (data->iconic)
2730 XIconifyWindow( data->display, data->whole_window, data->vis.screen );
2731 else if (is_window_rect_mapped( rectWindow ))
2732 XMapWindow( data->display, data->whole_window );
2733 update_net_wm_states( data );
2735 else
2737 if (swp_flags & (SWP_FRAMECHANGED|SWP_STATECHANGED)) set_wm_hints( data );
2738 if (!event_type) update_net_wm_states( data );
2742 XFlush( data->display ); /* make sure changes are done before we start painting again */
2743 if (data->surface && data->vis.visualid != default_visual.visualid)
2744 data->surface->funcs->flush( data->surface );
2746 release_win_data( data );
2749 /* check if the window icon should be hidden (i.e. moved off-screen) */
2750 static BOOL hide_icon( struct x11drv_win_data *data )
2752 static const WCHAR trayW[] = {'S','h','e','l','l','_','T','r','a','y','W','n','d',0};
2753 UNICODE_STRING str = RTL_CONSTANT_STRING( trayW );
2755 if (data->managed) return TRUE;
2756 /* hide icons in desktop mode when the taskbar is active */
2757 if (!is_virtual_desktop()) return FALSE;
2758 return NtUserIsWindowVisible( NtUserFindWindowEx( 0, 0, &str, NULL, 0 ));
2761 /***********************************************************************
2762 * ShowWindow (X11DRV.@)
2764 UINT X11DRV_ShowWindow( HWND hwnd, INT cmd, RECT *rect, UINT swp )
2766 int x, y;
2767 unsigned int width, height, border, depth;
2768 Window root, top;
2769 POINT pos;
2770 DWORD style = NtUserGetWindowLongW( hwnd, GWL_STYLE );
2771 struct x11drv_thread_data *thread_data = x11drv_thread_data();
2772 struct x11drv_win_data *data = get_win_data( hwnd );
2774 if (!data || !data->whole_window) goto done;
2775 if (style & WS_MINIMIZE)
2777 if (((rect->left != -32000 || rect->top != -32000)) && hide_icon( data ))
2779 OffsetRect( rect, -32000 - rect->left, -32000 - rect->top );
2780 swp &= ~(SWP_NOMOVE | SWP_NOCLIENTMOVE);
2782 goto done;
2784 if (!data->managed || !data->mapped || data->iconic) goto done;
2786 /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */
2788 if (!thread_data->current_event || thread_data->current_event->xany.window != data->whole_window)
2789 goto done;
2791 if (thread_data->current_event->type != ConfigureNotify &&
2792 thread_data->current_event->type != PropertyNotify)
2793 goto done;
2795 TRACE( "win %p/%lx cmd %d at %s flags %08x\n",
2796 hwnd, data->whole_window, cmd, wine_dbgstr_rect(rect), swp );
2798 XGetGeometry( thread_data->display, data->whole_window,
2799 &root, &x, &y, &width, &height, &border, &depth );
2800 XTranslateCoordinates( thread_data->display, data->whole_window, root, 0, 0, &x, &y, &top );
2801 pos = root_to_virtual_screen( x, y );
2802 X11DRV_X_to_window_rect( data, rect, pos.x, pos.y, width, height );
2803 swp &= ~(SWP_NOMOVE | SWP_NOCLIENTMOVE | SWP_NOSIZE | SWP_NOCLIENTSIZE);
2805 done:
2806 release_win_data( data );
2807 return swp;
2811 /**********************************************************************
2812 * SetWindowIcon (X11DRV.@)
2814 * hIcon or hIconSm has changed (or is being initialised for the
2815 * first time). Complete the X11 driver-specific initialisation
2816 * and set the window hints.
2818 void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
2820 struct x11drv_win_data *data;
2822 if (!(data = get_win_data( hwnd ))) return;
2823 if (!data->whole_window) goto done;
2824 release_win_data( data ); /* release the lock, fetching the icon requires sending messages */
2826 if (type == ICON_BIG) fetch_icon_data( hwnd, icon, 0 );
2827 else fetch_icon_data( hwnd, 0, icon );
2829 if (!(data = get_win_data( hwnd ))) return;
2830 set_wm_hints( data );
2831 done:
2832 release_win_data( data );
2836 /***********************************************************************
2837 * SetWindowRgn (X11DRV.@)
2839 * Assign specified region to window (for non-rectangular windows)
2841 void X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
2843 struct x11drv_win_data *data;
2845 if ((data = get_win_data( hwnd )))
2847 sync_window_region( data, hrgn );
2848 release_win_data( data );
2850 else if (X11DRV_get_whole_window( hwnd ))
2852 send_message( hwnd, WM_X11DRV_SET_WIN_REGION, 0, 0 );
2857 /***********************************************************************
2858 * SetLayeredWindowAttributes (X11DRV.@)
2860 * Set transparency attributes for a layered window.
2862 void X11DRV_SetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags )
2864 struct x11drv_win_data *data = get_win_data( hwnd );
2866 if (data)
2868 set_window_visual( data, &default_visual, FALSE );
2870 if (data->whole_window)
2871 sync_window_opacity( data->display, data->whole_window, key, alpha, flags );
2872 if (data->surface)
2873 set_surface_color_key( data->surface, (flags & LWA_COLORKEY) ? key : CLR_INVALID );
2875 data->layered = TRUE;
2876 if (!data->mapped) /* mapping is delayed until attributes are set */
2878 DWORD style = NtUserGetWindowLongW( data->hwnd, GWL_STYLE );
2880 if ((style & WS_VISIBLE) &&
2881 ((style & WS_MINIMIZE) || is_window_rect_mapped( &data->window_rect )))
2883 release_win_data( data );
2884 map_window( hwnd, style );
2885 return;
2888 release_win_data( data );
2890 else
2892 Window win = X11DRV_get_whole_window( hwnd );
2893 if (win)
2895 sync_window_opacity( gdi_display, win, key, alpha, flags );
2896 if (flags & LWA_COLORKEY)
2897 FIXME( "LWA_COLORKEY not supported on foreign process window %p\n", hwnd );
2903 /*****************************************************************************
2904 * UpdateLayeredWindow (X11DRV.@)
2906 BOOL X11DRV_UpdateLayeredWindow( HWND hwnd, const UPDATELAYEREDWINDOWINFO *info,
2907 const RECT *window_rect )
2909 struct window_surface *surface;
2910 struct x11drv_win_data *data;
2911 BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255, 0 };
2912 COLORREF color_key = (info->dwFlags & ULW_COLORKEY) ? info->crKey : CLR_INVALID;
2913 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
2914 BITMAPINFO *bmi = (BITMAPINFO *)buffer;
2915 void *src_bits, *dst_bits;
2916 RECT rect, src_rect;
2917 HDC hdc = 0;
2918 HBITMAP dib;
2919 BOOL mapped, ret = FALSE;
2921 if (!(data = get_win_data( hwnd ))) return FALSE;
2923 data->layered = TRUE;
2924 if (!data->embedded && argb_visual.visualid) set_window_visual( data, &argb_visual, TRUE );
2926 rect = *window_rect;
2927 OffsetRect( &rect, -window_rect->left, -window_rect->top );
2929 surface = data->surface;
2930 if (!surface || !EqualRect( &surface->rect, &rect ))
2932 data->surface = create_surface( data->whole_window, &data->vis, &rect,
2933 color_key, data->use_alpha );
2934 if (surface) window_surface_release( surface );
2935 surface = data->surface;
2937 else set_surface_color_key( surface, color_key );
2939 if (surface) window_surface_add_ref( surface );
2940 mapped = data->mapped;
2941 release_win_data( data );
2943 /* layered windows are mapped only once their attributes are set */
2944 if (!mapped)
2946 DWORD style = NtUserGetWindowLongW( hwnd, GWL_STYLE );
2948 if ((style & WS_VISIBLE) && ((style & WS_MINIMIZE) || is_window_rect_mapped( window_rect )))
2949 map_window( hwnd, style );
2952 if (!surface) return FALSE;
2953 if (!info->hdcSrc)
2955 window_surface_release( surface );
2956 return TRUE;
2959 dst_bits = surface->funcs->get_info( surface, bmi );
2961 if (!(dib = NtGdiCreateDIBSection( info->hdcDst, NULL, 0, bmi, DIB_RGB_COLORS, 0, 0, 0, &src_bits )))
2962 goto done;
2963 if (!(hdc = NtGdiCreateCompatibleDC( 0 ))) goto done;
2965 NtGdiSelectBitmap( hdc, dib );
2967 surface->funcs->lock( surface );
2969 if (info->prcDirty)
2971 intersect_rect( &rect, &rect, info->prcDirty );
2972 memcpy( src_bits, dst_bits, bmi->bmiHeader.biSizeImage );
2973 NtGdiPatBlt( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, BLACKNESS );
2975 src_rect = rect;
2976 if (info->pptSrc) OffsetRect( &src_rect, info->pptSrc->x, info->pptSrc->y );
2977 NtGdiTransformPoints( info->hdcSrc, (POINT *)&src_rect, (POINT *)&src_rect, 2, NtGdiDPtoLP );
2979 if (info->dwFlags & ULW_ALPHA) blend = *info->pblend;
2980 ret = NtGdiAlphaBlend( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
2981 info->hdcSrc, src_rect.left, src_rect.top,
2982 src_rect.right - src_rect.left, src_rect.bottom - src_rect.top,
2983 *(DWORD *)&blend, 0 );
2984 if (ret)
2986 memcpy( dst_bits, src_bits, bmi->bmiHeader.biSizeImage );
2987 add_bounds_rect( surface->funcs->get_bounds( surface ), &rect );
2990 surface->funcs->unlock( surface );
2991 surface->funcs->flush( surface );
2993 done:
2994 window_surface_release( surface );
2995 if (hdc) NtGdiDeleteObjectApp( hdc );
2996 if (dib) NtGdiDeleteObjectApp( dib );
2997 return ret;
3000 /* Add a window to taskbar */
3001 static void taskbar_add_tab( HWND hwnd )
3003 struct x11drv_win_data *data;
3005 TRACE("hwnd %p\n", hwnd);
3007 data = get_win_data( hwnd );
3008 if (!data)
3009 return;
3011 data->add_taskbar = TRUE;
3012 data->skip_taskbar = FALSE;
3013 update_net_wm_states( data );
3014 release_win_data( data );
3017 /* Delete a window from taskbar */
3018 static void taskbar_delete_tab( HWND hwnd )
3020 struct x11drv_win_data *data;
3022 TRACE("hwnd %p\n", hwnd);
3024 data = get_win_data( hwnd );
3025 if (!data)
3026 return;
3028 data->skip_taskbar = TRUE;
3029 data->add_taskbar = FALSE;
3030 update_net_wm_states( data );
3031 release_win_data( data );
3034 /**********************************************************************
3035 * X11DRV_WindowMessage (X11DRV.@)
3037 LRESULT X11DRV_WindowMessage( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
3039 struct x11drv_win_data *data;
3041 switch(msg)
3043 case WM_X11DRV_UPDATE_CLIPBOARD:
3044 return update_clipboard( hwnd );
3045 case WM_X11DRV_SET_WIN_REGION:
3046 if ((data = get_win_data( hwnd )))
3048 sync_window_region( data, (HRGN)1 );
3049 release_win_data( data );
3051 return 0;
3052 case WM_X11DRV_DESKTOP_RESIZED:
3053 if ((data = get_win_data( hwnd )))
3055 /* update the full screen state */
3056 update_net_wm_states( data );
3058 if (data->whole_window)
3060 /* sync window position with the new virtual screen rect */
3061 POINT old_pos = {.x = data->whole_rect.left - wp, .y = data->whole_rect.top - lp};
3062 POINT pos = virtual_screen_to_root( data->whole_rect.left, data->whole_rect.top );
3063 XWindowChanges changes = {.x = pos.x, .y = pos.y};
3064 UINT mask = 0;
3066 if (old_pos.x != pos.x) mask |= CWX;
3067 if (old_pos.y != pos.y) mask |= CWY;
3069 if (mask) XReconfigureWMWindow( data->display, data->whole_window, data->vis.screen, mask, &changes );
3072 release_win_data( data );
3074 return 0;
3075 case WM_X11DRV_DELETE_TAB:
3076 taskbar_delete_tab( hwnd );
3077 return 0;
3078 case WM_X11DRV_ADD_TAB:
3079 taskbar_add_tab( hwnd );
3080 return 0;
3081 default:
3082 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg, hwnd, (long)wp, lp );
3083 return 0;
3088 /***********************************************************************
3089 * is_netwm_supported
3091 static BOOL is_netwm_supported( Display *display, Atom atom )
3093 static Atom *net_supported;
3094 static int net_supported_count = -1;
3095 int i;
3097 if (net_supported_count == -1)
3099 Atom type;
3100 int format;
3101 unsigned long count, remaining;
3103 if (!XGetWindowProperty( display, DefaultRootWindow(display), x11drv_atom(_NET_SUPPORTED), 0,
3104 ~0UL, False, XA_ATOM, &type, &format, &count,
3105 &remaining, (unsigned char **)&net_supported ))
3106 net_supported_count = get_property_size( format, count ) / sizeof(Atom);
3107 else
3108 net_supported_count = 0;
3111 for (i = 0; i < net_supported_count; i++)
3112 if (net_supported[i] == atom) return TRUE;
3113 return FALSE;
3117 /***********************************************************************
3118 * start_screensaver
3120 static LRESULT start_screensaver(void)
3122 if (!is_virtual_desktop())
3124 const char *argv[3] = { "xdg-screensaver", "activate", NULL };
3125 int pid = __wine_unix_spawnvp( (char **)argv, FALSE );
3126 if (pid > 0)
3128 TRACE( "started process %d\n", pid );
3129 return 0;
3132 return -1;
3136 /***********************************************************************
3137 * SysCommand (X11DRV.@)
3139 * Perform WM_SYSCOMMAND handling.
3141 LRESULT X11DRV_SysCommand( HWND hwnd, WPARAM wparam, LPARAM lparam )
3143 WPARAM hittest = wparam & 0x0f;
3144 int dir;
3145 struct x11drv_win_data *data;
3147 if (!(data = get_win_data( hwnd )))
3149 if (wparam == SC_SCREENSAVE && hwnd == NtUserGetDesktopWindow()) return start_screensaver();
3150 return -1;
3152 if (!data->whole_window || !data->managed || !data->mapped) goto failed;
3154 switch (wparam & 0xfff0)
3156 case SC_MOVE:
3157 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
3158 else dir = _NET_WM_MOVERESIZE_MOVE;
3159 break;
3160 case SC_SIZE:
3161 /* windows without WS_THICKFRAME are not resizable through the window manager */
3162 if (!(NtUserGetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) goto failed;
3164 switch (hittest)
3166 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
3167 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
3168 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
3169 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
3170 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
3171 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
3172 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
3173 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
3174 case 9: dir = _NET_WM_MOVERESIZE_MOVE; break;
3175 default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break;
3177 break;
3179 case SC_KEYMENU:
3180 /* prevent a simple ALT press+release from activating the system menu,
3181 * as that can get confusing on managed windows */
3182 if ((WCHAR)lparam) goto failed; /* got an explicit char */
3183 if (NtUserGetWindowLongPtrW( hwnd, GWLP_ID )) goto failed; /* window has a real menu */
3184 if (!(NtUserGetWindowLongW( hwnd, GWL_STYLE ) & WS_SYSMENU)) goto failed; /* no system menu */
3185 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", (long)wparam, lparam );
3186 release_win_data( data );
3187 return 0;
3189 default:
3190 goto failed;
3193 if (NtUserGetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE) goto failed;
3195 if (!is_netwm_supported( data->display, x11drv_atom(_NET_WM_MOVERESIZE) ))
3197 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
3198 goto failed;
3201 release_win_data( data );
3202 move_resize_window( hwnd, dir );
3203 return 0;
3205 failed:
3206 release_win_data( data );
3207 return -1;
3210 void X11DRV_FlashWindowEx( FLASHWINFO *pfinfo )
3212 struct x11drv_win_data *data = get_win_data( pfinfo->hwnd );
3213 XEvent xev;
3215 if (!data)
3216 return;
3218 if (data->mapped)
3220 xev.type = ClientMessage;
3221 xev.xclient.window = data->whole_window;
3222 xev.xclient.message_type = x11drv_atom( _NET_WM_STATE );
3223 xev.xclient.serial = 0;
3224 xev.xclient.display = data->display;
3225 xev.xclient.send_event = True;
3226 xev.xclient.format = 32;
3227 xev.xclient.data.l[0] = pfinfo->dwFlags ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
3228 xev.xclient.data.l[1] = x11drv_atom( _NET_WM_STATE_DEMANDS_ATTENTION );
3229 xev.xclient.data.l[2] = 0;
3230 xev.xclient.data.l[3] = 1;
3231 xev.xclient.data.l[4] = 0;
3233 XSendEvent( data->display, DefaultRootWindow( data->display ), False,
3234 SubstructureNotifyMask, &xev );
3236 release_win_data( data );
3239 void init_win_context(void)
3241 init_recursive_mutex( &win_data_mutex );
3243 winContext = XUniqueContext();
3244 win_data_context = XUniqueContext();
3245 cursor_context = XUniqueContext();