dmsynth: Remove DECLSPEC_HIDDEN usage.
[wine.git] / dlls / winex11.drv / window.c
blob974bd376fe62357a004ef8904a036a72bd60e032
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( data->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 ret = data->client_window = XCreateWindow( gdi_display,
1587 data->whole_window ? data->whole_window : dummy_parent,
1588 x, y, cx, cy, 0, default_visual.depth, InputOutput,
1589 visual->visual, CWBitGravity | CWWinGravity |
1590 CWBackingStore | CWColormap | CWBorderPixel, &attr );
1591 if (data->client_window)
1593 XSaveContext( data->display, data->client_window, winContext, (char *)data->hwnd );
1594 XMapWindow( gdi_display, data->client_window );
1595 XSync( gdi_display, False );
1596 if (data->whole_window) XSelectInput( data->display, data->client_window, ExposureMask );
1597 TRACE( "%p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1599 release_win_data( data );
1600 return ret;
1604 /**********************************************************************
1605 * create_whole_window
1607 * Create the whole X window for a given window
1609 static void create_whole_window( struct x11drv_win_data *data )
1611 int cx, cy, mask;
1612 XSetWindowAttributes attr;
1613 WCHAR text[1024];
1614 COLORREF key;
1615 BYTE alpha;
1616 DWORD layered_flags;
1617 HRGN win_rgn;
1618 POINT pos;
1620 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1622 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1623 data->managed = TRUE;
1626 if ((win_rgn = NtGdiCreateRectRgn( 0, 0, 0, 0 )) &&
1627 NtUserGetWindowRgnEx( data->hwnd, win_rgn, 0 ) == ERROR)
1629 NtGdiDeleteObjectApp( win_rgn );
1630 win_rgn = 0;
1632 data->shaped = (win_rgn != 0);
1634 if (data->vis.visualid != default_visual.visualid)
1635 data->whole_colormap = XCreateColormap( data->display, root_window, data->vis.visual, AllocNone );
1637 mask = get_window_attributes( data, &attr );
1639 if (!(cx = data->whole_rect.right - data->whole_rect.left)) cx = 1;
1640 else if (cx > 65535) cx = 65535;
1641 if (!(cy = data->whole_rect.bottom - data->whole_rect.top)) cy = 1;
1642 else if (cy > 65535) cy = 65535;
1644 pos = virtual_screen_to_root( data->whole_rect.left, data->whole_rect.top );
1645 data->whole_window = XCreateWindow( data->display, root_window, pos.x, pos.y,
1646 cx, cy, 0, data->vis.depth, InputOutput,
1647 data->vis.visual, mask, &attr );
1648 if (!data->whole_window) goto done;
1650 set_initial_wm_hints( data->display, data->whole_window );
1651 set_wm_hints( data );
1653 XSaveContext( data->display, data->whole_window, winContext, (char *)data->hwnd );
1654 NtUserSetProp( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
1656 /* set the window text */
1657 if (!NtUserInternalGetWindowText( data->hwnd, text, ARRAY_SIZE( text ))) text[0] = 0;
1658 sync_window_text( data->display, data->whole_window, text );
1660 /* set the window region */
1661 if (win_rgn || IsRectEmpty( &data->window_rect )) sync_window_region( data, win_rgn );
1663 /* set the window opacity */
1664 if (!NtUserGetLayeredWindowAttributes( data->hwnd, &key, &alpha, &layered_flags )) layered_flags = 0;
1665 sync_window_opacity( data->display, data->whole_window, key, alpha, layered_flags );
1667 XFlush( data->display ); /* make sure the window exists before we start painting to it */
1669 done:
1670 if (win_rgn) NtGdiDeleteObjectApp( win_rgn );
1674 /**********************************************************************
1675 * destroy_whole_window
1677 * Destroy the whole X window for a given window.
1679 static void destroy_whole_window( struct x11drv_win_data *data, BOOL already_destroyed )
1681 TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1683 if (data->client_window) XDeleteContext( data->display, data->client_window, winContext );
1685 if (!data->whole_window)
1687 if (data->embedded)
1689 Window xwin = (Window)NtUserGetProp( data->hwnd, foreign_window_prop );
1690 if (xwin)
1692 if (!already_destroyed) XSelectInput( data->display, xwin, 0 );
1693 XDeleteContext( data->display, xwin, winContext );
1694 NtUserRemoveProp( data->hwnd, foreign_window_prop );
1696 return;
1699 else
1701 if (data->client_window && !already_destroyed)
1703 XSelectInput( data->display, data->client_window, 0 );
1704 XReparentWindow( data->display, data->client_window, get_dummy_parent(), 0, 0 );
1705 XSync( data->display, False );
1707 XDeleteContext( data->display, data->whole_window, winContext );
1708 if (!already_destroyed) XDestroyWindow( data->display, data->whole_window );
1710 if (data->whole_colormap) XFreeColormap( data->display, data->whole_colormap );
1711 data->whole_window = data->client_window = 0;
1712 data->whole_colormap = 0;
1713 data->wm_state = WithdrawnState;
1714 data->net_wm_state = 0;
1715 data->mapped = FALSE;
1716 if (data->xic)
1718 XUnsetICFocus( data->xic );
1719 XDestroyIC( data->xic );
1720 data->xic = 0;
1722 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1723 XFlush( data->display );
1724 if (data->surface) window_surface_release( data->surface );
1725 data->surface = NULL;
1726 NtUserRemoveProp( data->hwnd, whole_window_prop );
1730 /**********************************************************************
1731 * set_window_visual
1733 * Change the visual by destroying and recreating the X window if needed.
1735 void set_window_visual( struct x11drv_win_data *data, const XVisualInfo *vis, BOOL use_alpha )
1737 Window client_window = data->client_window;
1738 Window whole_window = data->whole_window;
1740 if (!data->use_alpha == !use_alpha) return;
1741 if (data->surface) window_surface_release( data->surface );
1742 data->surface = NULL;
1743 data->use_alpha = use_alpha;
1745 if (data->vis.visualid == vis->visualid) return;
1746 data->client_window = 0;
1747 destroy_whole_window( data, client_window != 0 /* don't destroy whole_window until reparented */ );
1748 data->vis = *vis;
1749 create_whole_window( data );
1750 if (!client_window) return;
1751 /* move the client to the new parent */
1752 XReparentWindow( data->display, client_window, data->whole_window,
1753 data->client_rect.left - data->whole_rect.left,
1754 data->client_rect.top - data->whole_rect.top );
1755 data->client_window = client_window;
1756 XDestroyWindow( data->display, whole_window );
1760 /*****************************************************************
1761 * SetWindowText (X11DRV.@)
1763 void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
1765 Window win;
1767 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(gdi_display))
1769 Display *display = thread_init_display();
1770 sync_window_text( display, win, text );
1775 /***********************************************************************
1776 * SetWindowStyle (X11DRV.@)
1778 * Update the X state of a window to reflect a style change
1780 void X11DRV_SetWindowStyle( HWND hwnd, INT offset, STYLESTRUCT *style )
1782 struct x11drv_win_data *data;
1783 DWORD changed = style->styleNew ^ style->styleOld;
1785 if (hwnd == NtUserGetDesktopWindow()) return;
1786 if (!(data = get_win_data( hwnd ))) return;
1787 if (!data->whole_window) goto done;
1789 if (offset == GWL_STYLE && (changed & WS_DISABLED)) set_wm_hints( data );
1791 if (offset == GWL_EXSTYLE && (changed & WS_EX_LAYERED)) /* changing WS_EX_LAYERED resets attributes */
1793 data->layered = FALSE;
1794 set_window_visual( data, &default_visual, FALSE );
1795 sync_window_opacity( data->display, data->whole_window, 0, 0, 0 );
1796 if (data->surface) set_surface_color_key( data->surface, CLR_INVALID );
1798 done:
1799 release_win_data( data );
1803 /***********************************************************************
1804 * DestroyWindow (X11DRV.@)
1806 void X11DRV_DestroyWindow( HWND hwnd )
1808 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1809 struct x11drv_win_data *data;
1811 if (!(data = get_win_data( hwnd ))) return;
1813 destroy_whole_window( data, FALSE );
1814 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
1815 if (thread_data->last_xic_hwnd == hwnd) thread_data->last_xic_hwnd = 0;
1816 if (data->icon_pixmap) XFreePixmap( gdi_display, data->icon_pixmap );
1817 if (data->icon_mask) XFreePixmap( gdi_display, data->icon_mask );
1818 if (data->client_colormap) XFreeColormap( data->display, data->client_colormap );
1819 free( data->icon_bits );
1820 XDeleteContext( gdi_display, (XID)hwnd, win_data_context );
1821 release_win_data( data );
1822 free( data );
1823 destroy_gl_drawable( hwnd );
1824 wine_vk_surface_destroy( hwnd );
1828 /***********************************************************************
1829 * X11DRV_DestroyNotify
1831 BOOL X11DRV_DestroyNotify( HWND hwnd, XEvent *event )
1833 struct x11drv_win_data *data;
1834 BOOL embedded;
1836 if (!(data = get_win_data( hwnd ))) return FALSE;
1837 embedded = data->embedded;
1838 if (!embedded) FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window );
1840 destroy_whole_window( data, TRUE );
1841 release_win_data( data );
1842 if (embedded) send_message( hwnd, WM_CLOSE, 0, 0 );
1843 return TRUE;
1847 /* initialize the desktop window id in the desktop manager process */
1848 static BOOL create_desktop_win_data( Window win, HWND hwnd )
1850 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1851 Display *display = thread_data->display;
1852 struct x11drv_win_data *data;
1854 if (!(data = alloc_win_data( display, hwnd ))) return FALSE;
1855 data->whole_window = win;
1856 data->managed = TRUE;
1857 NtUserSetProp( data->hwnd, whole_window_prop, (HANDLE)win );
1858 set_initial_wm_hints( display, win );
1859 release_win_data( data );
1860 if (thread_data->clip_window) XReparentWindow( display, thread_data->clip_window, win, 0, 0 );
1861 return TRUE;
1864 /**********************************************************************
1865 * SetDesktopWindow (X11DRV.@)
1867 void X11DRV_SetDesktopWindow( HWND hwnd )
1869 unsigned int width, height;
1871 /* retrieve the real size of the desktop */
1872 SERVER_START_REQ( get_window_rectangles )
1874 req->handle = wine_server_user_handle( hwnd );
1875 req->relative = COORDS_CLIENT;
1876 wine_server_call( req );
1877 width = reply->window.right;
1878 height = reply->window.bottom;
1880 SERVER_END_REQ;
1882 if (!width && !height) /* not initialized yet */
1884 RECT rect;
1886 X11DRV_DisplayDevices_Init( TRUE );
1887 rect = NtUserGetVirtualScreenRect();
1889 SERVER_START_REQ( set_window_pos )
1891 req->handle = wine_server_user_handle( hwnd );
1892 req->previous = 0;
1893 req->swp_flags = SWP_NOZORDER;
1894 req->window.left = rect.left;
1895 req->window.top = rect.top;
1896 req->window.right = rect.right;
1897 req->window.bottom = rect.bottom;
1898 req->client = req->window;
1899 wine_server_call( req );
1901 SERVER_END_REQ;
1903 if (!is_virtual_desktop()) return;
1904 if (!create_desktop_win_data( root_window, hwnd ))
1906 ERR( "Failed to create virtual desktop window data\n" );
1907 root_window = DefaultRootWindow( gdi_display );
1909 else if (is_desktop_fullscreen())
1911 Display *display = x11drv_thread_data()->display;
1912 TRACE("setting desktop to fullscreen\n");
1913 XChangeProperty( display, root_window, x11drv_atom(_NET_WM_STATE), XA_ATOM, 32, PropModeReplace,
1914 (unsigned char*)&x11drv_atom(_NET_WM_STATE_FULLSCREEN), 1 );
1917 else
1919 Window win = (Window)NtUserGetProp( hwnd, whole_window_prop );
1920 if (win && win != root_window)
1922 X11DRV_init_desktop( win, width, height );
1923 X11DRV_DisplayDevices_Init( TRUE );
1929 #define WM_WINE_NOTIFY_ACTIVITY WM_USER
1930 #define WM_WINE_DELETE_TAB (WM_USER + 1)
1931 #define WM_WINE_ADD_TAB (WM_USER + 2)
1933 /**********************************************************************
1934 * DesktopWindowProc (X11DRV.@)
1936 LRESULT X11DRV_DesktopWindowProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
1938 switch (msg)
1940 case WM_WINE_NOTIFY_ACTIVITY:
1942 static ULONG last = 0;
1943 ULONG now = NtGetTickCount();
1944 /* calling XResetScreenSaver too often can cause performance
1945 * problems, so throttle it */
1946 if (now > last + 5000)
1948 XResetScreenSaver( gdi_display );
1949 XFlush( gdi_display );
1950 last = now;
1952 break;
1954 case WM_WINE_DELETE_TAB:
1955 send_notify_message( (HWND)wp, WM_X11DRV_DELETE_TAB, 0, 0 );
1956 break;
1957 case WM_WINE_ADD_TAB:
1958 send_notify_message( (HWND)wp, WM_X11DRV_ADD_TAB, 0, 0 );
1959 break;
1960 case WM_DISPLAYCHANGE:
1961 X11DRV_resize_desktop();
1962 break;
1964 return NtUserMessageCall( hwnd, msg, wp, lp, 0, NtUserDefWindowProc, FALSE );
1967 /**********************************************************************
1968 * CreateWindow (X11DRV.@)
1970 BOOL X11DRV_CreateWindow( HWND hwnd )
1972 if (hwnd == NtUserGetDesktopWindow())
1974 struct x11drv_thread_data *data = x11drv_init_thread_data();
1975 XSetWindowAttributes attr;
1977 /* create the cursor clipping window */
1978 attr.override_redirect = TRUE;
1979 attr.event_mask = StructureNotifyMask | FocusChangeMask;
1980 data->clip_window = XCreateWindow( data->display, root_window, 0, 0, 1, 1, 0, 0,
1981 InputOnly, default_visual.visual,
1982 CWOverrideRedirect | CWEventMask, &attr );
1983 XFlush( data->display );
1984 NtUserSetProp( hwnd, clip_window_prop, (HANDLE)data->clip_window );
1985 X11DRV_DisplayDevices_RegisterEventHandlers();
1987 return TRUE;
1991 /***********************************************************************
1992 * get_win_data
1994 * Lock and return the X11 data structure associated with a window.
1996 struct x11drv_win_data *get_win_data( HWND hwnd )
1998 char *data;
2000 if (!hwnd) return NULL;
2001 pthread_mutex_lock( &win_data_mutex );
2002 if (!XFindContext( gdi_display, (XID)hwnd, win_data_context, &data ))
2003 return (struct x11drv_win_data *)data;
2004 pthread_mutex_unlock( &win_data_mutex );
2005 return NULL;
2009 /***********************************************************************
2010 * release_win_data
2012 * Release the data returned by get_win_data.
2014 void release_win_data( struct x11drv_win_data *data )
2016 if (data) pthread_mutex_unlock( &win_data_mutex );
2020 /***********************************************************************
2021 * X11DRV_create_win_data
2023 * Create an X11 data window structure for an existing window.
2025 static struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd, const RECT *window_rect,
2026 const RECT *client_rect )
2028 Display *display;
2029 struct x11drv_win_data *data;
2030 HWND parent;
2032 if (!(parent = NtUserGetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
2034 /* don't create win data for HWND_MESSAGE windows */
2035 if (parent != NtUserGetDesktopWindow() && !NtUserGetAncestor( parent, GA_PARENT )) return NULL;
2037 if (NtUserGetWindowThread( hwnd, NULL ) != GetCurrentThreadId()) return NULL;
2039 /* Recreate the parent gl_drawable now that we know there are child windows
2040 * that will need clipping support.
2042 sync_gl_drawable( parent, TRUE );
2044 display = thread_init_display();
2045 init_clip_window(); /* make sure the clip window is initialized in this thread */
2047 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
2049 data->whole_rect = data->window_rect = *window_rect;
2050 data->client_rect = *client_rect;
2051 if (parent == NtUserGetDesktopWindow())
2053 create_whole_window( data );
2054 TRACE( "win %p/%lx window %s whole %s client %s\n",
2055 hwnd, data->whole_window, wine_dbgstr_rect( &data->window_rect ),
2056 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
2058 return data;
2062 /***********************************************************************
2063 * create_foreign_window
2065 * Create a foreign window for the specified X window and its ancestors
2067 HWND create_foreign_window( Display *display, Window xwin )
2069 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};
2070 static BOOL class_registered;
2071 struct x11drv_win_data *data;
2072 HWND hwnd, parent;
2073 POINT pos;
2074 Window xparent, xroot;
2075 Window *xchildren;
2076 unsigned int nchildren;
2077 XWindowAttributes attr;
2078 UINT style = WS_CLIPCHILDREN;
2079 UNICODE_STRING class_name = RTL_CONSTANT_STRING( classW );
2081 if (!class_registered)
2083 UNICODE_STRING version = { 0 };
2084 WNDCLASSEXW class;
2086 memset( &class, 0, sizeof(class) );
2087 class.cbSize = sizeof(class);
2088 class.lpfnWndProc = client_foreign_window_proc;
2089 class.lpszClassName = classW;
2090 if (!NtUserRegisterClassExWOW( &class, &class_name, &version, NULL, 0, 0, NULL ) &&
2091 RtlGetLastWin32Error() != ERROR_CLASS_ALREADY_EXISTS)
2093 ERR( "Could not register foreign window class\n" );
2094 return FALSE;
2096 class_registered = TRUE;
2099 if (XFindContext( display, xwin, winContext, (char **)&hwnd )) hwnd = 0;
2100 if (hwnd) return hwnd; /* already created */
2102 XSelectInput( display, xwin, StructureNotifyMask );
2103 if (!XGetWindowAttributes( display, xwin, &attr ) ||
2104 !XQueryTree( display, xwin, &xroot, &xparent, &xchildren, &nchildren ))
2106 XSelectInput( display, xwin, 0 );
2107 return 0;
2109 XFree( xchildren );
2111 if (xparent == xroot)
2113 parent = NtUserGetDesktopWindow();
2114 style |= WS_POPUP;
2115 pos = root_to_virtual_screen( attr.x, attr.y );
2117 else
2119 parent = create_foreign_window( display, xparent );
2120 style |= WS_CHILD;
2121 pos.x = attr.x;
2122 pos.y = attr.y;
2125 RtlInitUnicodeString( &class_name, classW );
2126 hwnd = NtUserCreateWindowEx( 0, &class_name, &class_name, NULL, style, pos.x, pos.y,
2127 attr.width, attr.height, parent, 0, NULL, NULL, 0, NULL,
2128 0, FALSE );
2130 if (!(data = alloc_win_data( display, hwnd )))
2132 NtUserDestroyWindow( hwnd );
2133 return 0;
2135 SetRect( &data->window_rect, pos.x, pos.y, pos.x + attr.width, pos.y + attr.height );
2136 data->whole_rect = data->client_rect = data->window_rect;
2137 data->whole_window = data->client_window = 0;
2138 data->embedded = TRUE;
2139 data->mapped = TRUE;
2141 NtUserSetProp( hwnd, foreign_window_prop, (HANDLE)xwin );
2142 XSaveContext( display, xwin, winContext, (char *)data->hwnd );
2144 TRACE( "win %lx parent %p style %08x %s -> hwnd %p\n",
2145 xwin, parent, style, wine_dbgstr_rect(&data->window_rect), hwnd );
2147 release_win_data( data );
2149 NtUserShowWindow( hwnd, SW_SHOW );
2150 return hwnd;
2154 NTSTATUS x11drv_systray_init( void *arg )
2156 Display *display;
2158 if (is_virtual_desktop()) return FALSE;
2160 display = thread_init_display();
2161 if (DefaultScreen( display ) == 0)
2162 systray_atom = x11drv_atom(_NET_SYSTEM_TRAY_S0);
2163 else
2165 char systray_buffer[29]; /* strlen(_NET_SYSTEM_TRAY_S4294967295)+1 */
2166 sprintf( systray_buffer, "_NET_SYSTEM_TRAY_S%u", DefaultScreen( display ) );
2167 systray_atom = XInternAtom( display, systray_buffer, False );
2169 XSelectInput( display, root_window, StructureNotifyMask );
2171 return TRUE;
2175 NTSTATUS x11drv_systray_clear( void *arg )
2177 HWND hwnd = *(HWND*)arg;
2178 Window win = X11DRV_get_whole_window( hwnd );
2179 if (win) XClearArea( gdi_display, win, 0, 0, 0, 0, True );
2180 return 0;
2184 NTSTATUS x11drv_systray_hide( void *arg )
2186 HWND hwnd = *(HWND*)arg;
2187 struct x11drv_win_data *data;
2189 /* make sure we don't try to unmap it, it confuses some systray docks */
2190 if ((data = get_win_data( hwnd )))
2192 if (data->embedded) data->mapped = FALSE;
2193 release_win_data( data );
2196 return 0;
2200 /* find the X11 window owner the system tray selection */
2201 static Window get_systray_selection_owner( Display *display )
2203 return XGetSelectionOwner( display, systray_atom );
2207 static void get_systray_visual_info( Display *display, Window systray_window, XVisualInfo *info )
2209 XVisualInfo *list, template;
2210 VisualID *visual_id;
2211 Atom type;
2212 int format, num;
2213 unsigned long count, remaining;
2215 *info = default_visual;
2216 if (XGetWindowProperty( display, systray_window, x11drv_atom(_NET_SYSTEM_TRAY_VISUAL), 0,
2217 65536/sizeof(CARD32), False, XA_VISUALID, &type, &format, &count,
2218 &remaining, (unsigned char **)&visual_id ))
2219 return;
2221 if (type == XA_VISUALID && format == 32)
2223 template.visualid = visual_id[0];
2224 if ((list = XGetVisualInfo( display, VisualIDMask, &template, &num )))
2226 *info = list[0];
2227 TRACE_(systray)( "systray window %lx got visual %lx\n", systray_window, info->visualid );
2228 XFree( list );
2231 XFree( visual_id );
2235 NTSTATUS x11drv_systray_dock( void *arg )
2237 struct systray_dock_params *params = arg;
2238 Window systray_window, window;
2239 Display *display;
2240 XEvent ev;
2241 XSetWindowAttributes attr;
2242 XVisualInfo visual;
2243 struct x11drv_win_data *data;
2244 UNICODE_STRING class_name;
2245 BOOL layered;
2246 HWND hwnd;
2248 static const WCHAR icon_classname[] =
2249 {'_','_','w','i','n','e','x','1','1','_','t','r','a','y','_','i','c','o','n',0};
2251 if (params->event_handle)
2253 XClientMessageEvent *event = (XClientMessageEvent *)(UINT_PTR)params->event_handle;
2254 display = event->display;
2255 systray_window = event->data.l[2];
2257 else
2259 display = thread_init_display();
2260 if (!(systray_window = get_systray_selection_owner( display ))) return STATUS_UNSUCCESSFUL;
2263 get_systray_visual_info( display, systray_window, &visual );
2265 *params->layered = layered = (visual.depth == 32);
2267 RtlInitUnicodeString( &class_name, icon_classname );
2268 hwnd = NtUserCreateWindowEx( layered ? WS_EX_LAYERED : 0, &class_name, &class_name, NULL,
2269 WS_CLIPSIBLINGS | WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
2270 params->cx, params->cy, NULL, 0, NULL, params->icon, 0,
2271 NULL, 0, FALSE );
2273 if (!(data = get_win_data( hwnd ))) return STATUS_UNSUCCESSFUL;
2274 if (layered) set_window_visual( data, &visual, TRUE );
2275 make_window_embedded( data );
2276 window = data->whole_window;
2277 release_win_data( data );
2279 NtUserShowWindow( hwnd, SW_SHOWNA );
2281 TRACE_(systray)( "icon window %p/%lx\n", hwnd, window );
2283 /* send the docking request message */
2284 ev.xclient.type = ClientMessage;
2285 ev.xclient.window = systray_window;
2286 ev.xclient.message_type = x11drv_atom( _NET_SYSTEM_TRAY_OPCODE );
2287 ev.xclient.format = 32;
2288 ev.xclient.data.l[0] = CurrentTime;
2289 ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
2290 ev.xclient.data.l[2] = window;
2291 ev.xclient.data.l[3] = 0;
2292 ev.xclient.data.l[4] = 0;
2293 XSendEvent( display, systray_window, False, NoEventMask, &ev );
2295 if (!layered)
2297 attr.background_pixmap = ParentRelative;
2298 attr.bit_gravity = ForgetGravity;
2299 XChangeWindowAttributes( display, window, CWBackPixmap | CWBitGravity, &attr );
2301 else
2303 /* force repainig */
2304 send_message( hwnd, WM_SIZE, SIZE_RESTORED, MAKELONG( params->cx, params->cy ));
2307 return STATUS_SUCCESS;
2311 /***********************************************************************
2312 * X11DRV_get_whole_window
2314 * Return the X window associated with the full area of a window
2316 Window X11DRV_get_whole_window( HWND hwnd )
2318 struct x11drv_win_data *data = get_win_data( hwnd );
2319 Window ret;
2321 if (!data)
2323 if (hwnd == NtUserGetDesktopWindow()) return root_window;
2324 return (Window)NtUserGetProp( hwnd, whole_window_prop );
2326 ret = data->whole_window;
2327 release_win_data( data );
2328 return ret;
2332 /***********************************************************************
2333 * X11DRV_GetDC (X11DRV.@)
2335 void X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect,
2336 const RECT *top_rect, DWORD flags )
2338 struct x11drv_escape_set_drawable escape;
2339 HWND parent;
2341 escape.code = X11DRV_SET_DRAWABLE;
2342 escape.mode = IncludeInferiors;
2343 escape.drawable = 0;
2345 escape.dc_rect.left = win_rect->left - top_rect->left;
2346 escape.dc_rect.top = win_rect->top - top_rect->top;
2347 escape.dc_rect.right = win_rect->right - top_rect->left;
2348 escape.dc_rect.bottom = win_rect->bottom - top_rect->top;
2350 if (top == hwnd)
2352 struct x11drv_win_data *data = get_win_data( hwnd );
2354 escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd );
2356 /* special case: when repainting the root window, clip out top-level windows */
2357 if (data && data->whole_window == root_window) escape.mode = ClipByChildren;
2358 release_win_data( data );
2360 else
2362 /* find the first ancestor that has a drawable */
2363 for (parent = hwnd; parent && parent != top; parent = NtUserGetAncestor( parent, GA_PARENT ))
2364 if ((escape.drawable = X11DRV_get_whole_window( parent ))) break;
2366 if (escape.drawable)
2368 POINT pt = { 0, 0 };
2369 NtUserMapWindowPoints( 0, parent, &pt, 1 );
2370 escape.dc_rect = *win_rect;
2371 OffsetRect( &escape.dc_rect, pt.x, pt.y );
2372 if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren;
2374 else escape.drawable = X11DRV_get_whole_window( top );
2377 NtGdiExtEscape( hdc, NULL, 0, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2381 /***********************************************************************
2382 * X11DRV_ReleaseDC (X11DRV.@)
2384 void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
2386 struct x11drv_escape_set_drawable escape;
2388 escape.code = X11DRV_SET_DRAWABLE;
2389 escape.drawable = root_window;
2390 escape.mode = IncludeInferiors;
2391 escape.dc_rect = NtUserGetVirtualScreenRect();
2392 OffsetRect( &escape.dc_rect, -2 * escape.dc_rect.left, -2 * escape.dc_rect.top );
2393 NtGdiExtEscape( hdc, NULL, 0, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2397 /*************************************************************************
2398 * ScrollDC (X11DRV.@)
2400 BOOL X11DRV_ScrollDC( HDC hdc, INT dx, INT dy, HRGN update )
2402 RECT rect;
2403 BOOL ret;
2404 HRGN expose_rgn = 0;
2406 NtGdiGetAppClipBox( hdc, &rect );
2408 if (update)
2410 INT code = X11DRV_START_EXPOSURES;
2411 NtGdiExtEscape( hdc, NULL, 0, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2413 ret = NtGdiBitBlt( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
2414 hdc, rect.left - dx, rect.top - dy, SRCCOPY, 0, 0 );
2416 code = X11DRV_END_EXPOSURES;
2417 NtGdiExtEscape( hdc, NULL, 0, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code,
2418 sizeof(expose_rgn), (LPSTR)&expose_rgn );
2419 if (expose_rgn)
2421 NtGdiCombineRgn( update, update, expose_rgn, RGN_OR );
2422 NtGdiDeleteObjectApp( expose_rgn );
2425 else ret = NtGdiBitBlt( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
2426 hdc, rect.left - dx, rect.top - dy, SRCCOPY, 0, 0 );
2428 return ret;
2432 /***********************************************************************
2433 * SetCapture (X11DRV.@)
2435 void X11DRV_SetCapture( HWND hwnd, UINT flags )
2437 struct x11drv_thread_data *thread_data = x11drv_thread_data();
2438 struct x11drv_win_data *data;
2440 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
2442 if (hwnd)
2444 if (!(data = get_win_data( NtUserGetAncestor( hwnd, GA_ROOT )))) return;
2445 if (data->whole_window)
2447 XFlush( gdi_display );
2448 XGrabPointer( data->display, data->whole_window, False,
2449 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
2450 GrabModeAsync, GrabModeAsync, None, None, CurrentTime );
2451 thread_data->grab_hwnd = data->hwnd;
2453 release_win_data( data );
2455 else /* release capture */
2457 if (!(data = get_win_data( thread_data->grab_hwnd ))) return;
2458 XFlush( gdi_display );
2459 XUngrabPointer( data->display, CurrentTime );
2460 XFlush( data->display );
2461 thread_data->grab_hwnd = NULL;
2462 release_win_data( data );
2467 /*****************************************************************
2468 * SetParent (X11DRV.@)
2470 void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
2472 struct x11drv_win_data *data;
2474 if (parent == old_parent) return;
2475 if (!(data = get_win_data( hwnd ))) return;
2476 if (data->embedded) goto done;
2478 if (parent != NtUserGetDesktopWindow()) /* a child window */
2480 if (old_parent == NtUserGetDesktopWindow())
2482 /* destroy the old X windows */
2483 destroy_whole_window( data, FALSE );
2484 data->managed = FALSE;
2487 else /* new top level window */
2489 create_whole_window( data );
2491 done:
2492 release_win_data( data );
2493 set_gl_drawable_parent( hwnd, parent );
2495 /* Recreate the parent gl_drawable now that we know there are child windows
2496 * that will need clipping support.
2498 sync_gl_drawable( parent, TRUE );
2500 fetch_icon_data( hwnd, 0, 0 );
2504 static inline BOOL get_surface_rect( const RECT *visible_rect, RECT *surface_rect )
2506 *surface_rect = NtUserGetVirtualScreenRect();
2508 if (!intersect_rect( surface_rect, surface_rect, visible_rect )) return FALSE;
2509 OffsetRect( surface_rect, -visible_rect->left, -visible_rect->top );
2510 surface_rect->left &= ~31;
2511 surface_rect->top &= ~31;
2512 surface_rect->right = max( surface_rect->left + 32, (surface_rect->right + 31) & ~31 );
2513 surface_rect->bottom = max( surface_rect->top + 32, (surface_rect->bottom + 31) & ~31 );
2514 return TRUE;
2518 /***********************************************************************
2519 * WindowPosChanging (X11DRV.@)
2521 BOOL X11DRV_WindowPosChanging( HWND hwnd, HWND insert_after, UINT swp_flags,
2522 const RECT *window_rect, const RECT *client_rect, RECT *visible_rect,
2523 struct window_surface **surface )
2525 struct x11drv_win_data *data = get_win_data( hwnd );
2526 RECT surface_rect;
2527 DWORD flags;
2528 COLORREF key;
2529 BOOL layered = NtUserGetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYERED;
2531 if (!data && !(data = X11DRV_create_win_data( hwnd, window_rect, client_rect ))) return TRUE;
2533 /* check if we need to switch the window to managed */
2534 if (!data->managed && data->whole_window && is_window_managed( hwnd, swp_flags, window_rect ))
2536 TRACE( "making win %p/%lx managed\n", hwnd, data->whole_window );
2537 release_win_data( data );
2538 unmap_window( hwnd );
2539 if (!(data = get_win_data( hwnd ))) return TRUE;
2540 data->managed = TRUE;
2543 *visible_rect = *window_rect;
2544 X11DRV_window_to_X_rect( data, visible_rect, window_rect, client_rect );
2546 /* create the window surface if necessary */
2548 if (!data->whole_window && !data->embedded) goto done;
2549 if (swp_flags & SWP_HIDEWINDOW) goto done;
2550 if (data->use_alpha) goto done;
2551 if (!get_surface_rect( visible_rect, &surface_rect )) goto done;
2553 if (*surface) window_surface_release( *surface );
2554 *surface = NULL; /* indicate that we want to draw directly to the window */
2556 if (data->embedded) goto done;
2557 if (data->whole_window == root_window) goto done;
2558 if (data->client_window) goto done;
2559 if (!client_side_graphics && !layered) goto done;
2561 if (data->surface)
2563 if (EqualRect( &data->surface->rect, &surface_rect ))
2565 /* existing surface is good enough */
2566 window_surface_add_ref( data->surface );
2567 *surface = data->surface;
2568 goto done;
2571 else if (!(swp_flags & SWP_SHOWWINDOW) && !(NtUserGetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)) goto done;
2573 if (!layered || !NtUserGetLayeredWindowAttributes( hwnd, &key, NULL, &flags ) || !(flags & LWA_COLORKEY))
2574 key = CLR_INVALID;
2576 *surface = create_surface( data->whole_window, &data->vis, &surface_rect, key, FALSE );
2578 done:
2579 release_win_data( data );
2580 return TRUE;
2584 /***********************************************************************
2585 * WindowPosChanged (X11DRV.@)
2587 void X11DRV_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_flags,
2588 const RECT *rectWindow, const RECT *rectClient,
2589 const RECT *visible_rect, const RECT *valid_rects,
2590 struct window_surface *surface )
2592 struct x11drv_thread_data *thread_data;
2593 struct x11drv_win_data *data;
2594 UINT new_style = NtUserGetWindowLongW( hwnd, GWL_STYLE );
2595 RECT old_window_rect, old_whole_rect, old_client_rect;
2596 int event_type;
2598 if (!(data = get_win_data( hwnd ))) return;
2600 thread_data = x11drv_thread_data();
2602 old_window_rect = data->window_rect;
2603 old_whole_rect = data->whole_rect;
2604 old_client_rect = data->client_rect;
2605 data->window_rect = *rectWindow;
2606 data->whole_rect = *visible_rect;
2607 data->client_rect = *rectClient;
2608 if (data->vis.visualid == default_visual.visualid)
2610 if (surface) window_surface_add_ref( surface );
2611 if (data->surface) window_surface_release( data->surface );
2612 data->surface = surface;
2615 TRACE( "win %p window %s client %s style %08x flags %08x\n",
2616 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style, swp_flags );
2618 if (!IsRectEmpty( &valid_rects[0] ))
2620 Window window = data->whole_window;
2621 int x_offset = old_whole_rect.left - data->whole_rect.left;
2622 int y_offset = old_whole_rect.top - data->whole_rect.top;
2624 /* if all that happened is that the whole window moved, copy everything */
2625 if (!(swp_flags & SWP_FRAMECHANGED) &&
2626 old_whole_rect.right - data->whole_rect.right == x_offset &&
2627 old_whole_rect.bottom - data->whole_rect.bottom == y_offset &&
2628 old_client_rect.left - data->client_rect.left == x_offset &&
2629 old_client_rect.right - data->client_rect.right == x_offset &&
2630 old_client_rect.top - data->client_rect.top == y_offset &&
2631 old_client_rect.bottom - data->client_rect.bottom == y_offset &&
2632 EqualRect( &valid_rects[0], &data->client_rect ))
2634 /* if we have an X window the bits will be moved by the X server */
2635 if (!window && (x_offset != 0 || y_offset != 0))
2637 release_win_data( data );
2638 move_window_bits( hwnd, window, &old_whole_rect, visible_rect,
2639 &old_client_rect, rectClient, rectWindow );
2640 if (!(data = get_win_data( hwnd ))) return;
2643 else
2645 release_win_data( data );
2646 move_window_bits( hwnd, window, &valid_rects[1], &valid_rects[0],
2647 &old_client_rect, rectClient, rectWindow );
2648 if (!(data = get_win_data( hwnd ))) return;
2652 XFlush( gdi_display ); /* make sure painting is done before we move the window */
2654 sync_client_position( data, &old_client_rect, &old_whole_rect );
2656 if (!data->whole_window)
2658 BOOL needs_resize = (!data->client_window &&
2659 (data->client_rect.right - data->client_rect.left !=
2660 old_client_rect.right - old_client_rect.left ||
2661 data->client_rect.bottom - data->client_rect.top !=
2662 old_client_rect.bottom - old_client_rect.top));
2663 release_win_data( data );
2664 if (needs_resize) sync_gl_drawable( hwnd, FALSE );
2665 return;
2668 /* check if we are currently processing an event relevant to this window */
2669 event_type = 0;
2670 if (thread_data &&
2671 thread_data->current_event &&
2672 thread_data->current_event->xany.window == data->whole_window)
2674 event_type = thread_data->current_event->type;
2675 if (event_type != ConfigureNotify && event_type != PropertyNotify &&
2676 event_type != GravityNotify && event_type != ReparentNotify)
2677 event_type = 0; /* ignore other events */
2680 if (data->mapped && event_type != ReparentNotify)
2682 if (((swp_flags & SWP_HIDEWINDOW) && !(new_style & WS_VISIBLE)) ||
2683 (!event_type && !(new_style & WS_MINIMIZE) &&
2684 !is_window_rect_mapped( rectWindow ) && is_window_rect_mapped( &old_window_rect )))
2686 release_win_data( data );
2687 unmap_window( hwnd );
2688 if (NtUserIsWindowRectFullScreen( &old_window_rect )) NtUserClipCursor( NULL );
2689 if (!(data = get_win_data( hwnd ))) return;
2693 /* don't change position if we are about to minimize or maximize a managed window */
2694 if (!event_type &&
2695 !(data->managed && (swp_flags & SWP_STATECHANGED) && (new_style & (WS_MINIMIZE|WS_MAXIMIZE))))
2696 sync_window_position( data, swp_flags, &old_window_rect, &old_whole_rect, &old_client_rect );
2698 if ((new_style & WS_VISIBLE) &&
2699 ((new_style & WS_MINIMIZE) || is_window_rect_mapped( rectWindow )))
2701 if (!data->mapped)
2703 BOOL needs_icon = !data->icon_pixmap;
2704 BOOL needs_map = TRUE;
2706 /* layered windows are mapped only once their attributes are set */
2707 if (NtUserGetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYERED)
2708 needs_map = data->layered || IsRectEmpty( rectWindow );
2709 release_win_data( data );
2710 if (needs_icon) fetch_icon_data( hwnd, 0, 0 );
2711 if (needs_map) map_window( hwnd, new_style );
2712 return;
2714 else if ((swp_flags & SWP_STATECHANGED) && (!data->iconic != !(new_style & WS_MINIMIZE)))
2716 set_wm_hints( data );
2717 data->iconic = (new_style & WS_MINIMIZE) != 0;
2718 TRACE( "changing win %p iconic state to %u\n", data->hwnd, data->iconic );
2719 if (data->iconic)
2720 XIconifyWindow( data->display, data->whole_window, data->vis.screen );
2721 else if (is_window_rect_mapped( rectWindow ))
2722 XMapWindow( data->display, data->whole_window );
2723 update_net_wm_states( data );
2725 else
2727 if (swp_flags & (SWP_FRAMECHANGED|SWP_STATECHANGED)) set_wm_hints( data );
2728 if (!event_type) update_net_wm_states( data );
2732 XFlush( data->display ); /* make sure changes are done before we start painting again */
2733 if (data->surface && data->vis.visualid != default_visual.visualid)
2734 data->surface->funcs->flush( data->surface );
2736 release_win_data( data );
2739 /* check if the window icon should be hidden (i.e. moved off-screen) */
2740 static BOOL hide_icon( struct x11drv_win_data *data )
2742 static const WCHAR trayW[] = {'S','h','e','l','l','_','T','r','a','y','W','n','d',0};
2743 UNICODE_STRING str = RTL_CONSTANT_STRING( trayW );
2745 if (data->managed) return TRUE;
2746 /* hide icons in desktop mode when the taskbar is active */
2747 if (!is_virtual_desktop()) return FALSE;
2748 return NtUserIsWindowVisible( NtUserFindWindowEx( 0, 0, &str, NULL, 0 ));
2751 /***********************************************************************
2752 * ShowWindow (X11DRV.@)
2754 UINT X11DRV_ShowWindow( HWND hwnd, INT cmd, RECT *rect, UINT swp )
2756 int x, y;
2757 unsigned int width, height, border, depth;
2758 Window root, top;
2759 POINT pos;
2760 DWORD style = NtUserGetWindowLongW( hwnd, GWL_STYLE );
2761 struct x11drv_thread_data *thread_data = x11drv_thread_data();
2762 struct x11drv_win_data *data = get_win_data( hwnd );
2764 if (!data || !data->whole_window) goto done;
2765 if (style & WS_MINIMIZE)
2767 if (((rect->left != -32000 || rect->top != -32000)) && hide_icon( data ))
2769 OffsetRect( rect, -32000 - rect->left, -32000 - rect->top );
2770 swp &= ~(SWP_NOMOVE | SWP_NOCLIENTMOVE);
2772 goto done;
2774 if (!data->managed || !data->mapped || data->iconic) goto done;
2776 /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */
2778 if (!thread_data->current_event || thread_data->current_event->xany.window != data->whole_window)
2779 goto done;
2781 if (thread_data->current_event->type != ConfigureNotify &&
2782 thread_data->current_event->type != PropertyNotify)
2783 goto done;
2785 TRACE( "win %p/%lx cmd %d at %s flags %08x\n",
2786 hwnd, data->whole_window, cmd, wine_dbgstr_rect(rect), swp );
2788 XGetGeometry( thread_data->display, data->whole_window,
2789 &root, &x, &y, &width, &height, &border, &depth );
2790 XTranslateCoordinates( thread_data->display, data->whole_window, root, 0, 0, &x, &y, &top );
2791 pos = root_to_virtual_screen( x, y );
2792 X11DRV_X_to_window_rect( data, rect, pos.x, pos.y, width, height );
2793 swp &= ~(SWP_NOMOVE | SWP_NOCLIENTMOVE | SWP_NOSIZE | SWP_NOCLIENTSIZE);
2795 done:
2796 release_win_data( data );
2797 return swp;
2801 /**********************************************************************
2802 * SetWindowIcon (X11DRV.@)
2804 * hIcon or hIconSm has changed (or is being initialised for the
2805 * first time). Complete the X11 driver-specific initialisation
2806 * and set the window hints.
2808 void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
2810 struct x11drv_win_data *data;
2812 if (!(data = get_win_data( hwnd ))) return;
2813 if (!data->whole_window) goto done;
2814 release_win_data( data ); /* release the lock, fetching the icon requires sending messages */
2816 if (type == ICON_BIG) fetch_icon_data( hwnd, icon, 0 );
2817 else fetch_icon_data( hwnd, 0, icon );
2819 if (!(data = get_win_data( hwnd ))) return;
2820 set_wm_hints( data );
2821 done:
2822 release_win_data( data );
2826 /***********************************************************************
2827 * SetWindowRgn (X11DRV.@)
2829 * Assign specified region to window (for non-rectangular windows)
2831 void X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
2833 struct x11drv_win_data *data;
2835 if ((data = get_win_data( hwnd )))
2837 sync_window_region( data, hrgn );
2838 release_win_data( data );
2840 else if (X11DRV_get_whole_window( hwnd ))
2842 send_message( hwnd, WM_X11DRV_SET_WIN_REGION, 0, 0 );
2847 /***********************************************************************
2848 * SetLayeredWindowAttributes (X11DRV.@)
2850 * Set transparency attributes for a layered window.
2852 void X11DRV_SetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags )
2854 struct x11drv_win_data *data = get_win_data( hwnd );
2856 if (data)
2858 set_window_visual( data, &default_visual, FALSE );
2860 if (data->whole_window)
2861 sync_window_opacity( data->display, data->whole_window, key, alpha, flags );
2862 if (data->surface)
2863 set_surface_color_key( data->surface, (flags & LWA_COLORKEY) ? key : CLR_INVALID );
2865 data->layered = TRUE;
2866 if (!data->mapped) /* mapping is delayed until attributes are set */
2868 DWORD style = NtUserGetWindowLongW( data->hwnd, GWL_STYLE );
2870 if ((style & WS_VISIBLE) &&
2871 ((style & WS_MINIMIZE) || is_window_rect_mapped( &data->window_rect )))
2873 release_win_data( data );
2874 map_window( hwnd, style );
2875 return;
2878 release_win_data( data );
2880 else
2882 Window win = X11DRV_get_whole_window( hwnd );
2883 if (win)
2885 sync_window_opacity( gdi_display, win, key, alpha, flags );
2886 if (flags & LWA_COLORKEY)
2887 FIXME( "LWA_COLORKEY not supported on foreign process window %p\n", hwnd );
2893 /*****************************************************************************
2894 * UpdateLayeredWindow (X11DRV.@)
2896 BOOL X11DRV_UpdateLayeredWindow( HWND hwnd, const UPDATELAYEREDWINDOWINFO *info,
2897 const RECT *window_rect )
2899 struct window_surface *surface;
2900 struct x11drv_win_data *data;
2901 BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255, 0 };
2902 COLORREF color_key = (info->dwFlags & ULW_COLORKEY) ? info->crKey : CLR_INVALID;
2903 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
2904 BITMAPINFO *bmi = (BITMAPINFO *)buffer;
2905 void *src_bits, *dst_bits;
2906 RECT rect, src_rect;
2907 HDC hdc = 0;
2908 HBITMAP dib;
2909 BOOL mapped, ret = FALSE;
2911 if (!(data = get_win_data( hwnd ))) return FALSE;
2913 data->layered = TRUE;
2914 if (!data->embedded && argb_visual.visualid) set_window_visual( data, &argb_visual, TRUE );
2916 rect = *window_rect;
2917 OffsetRect( &rect, -window_rect->left, -window_rect->top );
2919 surface = data->surface;
2920 if (!surface || !EqualRect( &surface->rect, &rect ))
2922 data->surface = create_surface( data->whole_window, &data->vis, &rect,
2923 color_key, data->use_alpha );
2924 if (surface) window_surface_release( surface );
2925 surface = data->surface;
2927 else set_surface_color_key( surface, color_key );
2929 if (surface) window_surface_add_ref( surface );
2930 mapped = data->mapped;
2931 release_win_data( data );
2933 /* layered windows are mapped only once their attributes are set */
2934 if (!mapped)
2936 DWORD style = NtUserGetWindowLongW( hwnd, GWL_STYLE );
2938 if ((style & WS_VISIBLE) && ((style & WS_MINIMIZE) || is_window_rect_mapped( window_rect )))
2939 map_window( hwnd, style );
2942 if (!surface) return FALSE;
2943 if (!info->hdcSrc)
2945 window_surface_release( surface );
2946 return TRUE;
2949 dst_bits = surface->funcs->get_info( surface, bmi );
2951 if (!(dib = NtGdiCreateDIBSection( info->hdcDst, NULL, 0, bmi, DIB_RGB_COLORS, 0, 0, 0, &src_bits )))
2952 goto done;
2953 if (!(hdc = NtGdiCreateCompatibleDC( 0 ))) goto done;
2955 NtGdiSelectBitmap( hdc, dib );
2957 surface->funcs->lock( surface );
2959 if (info->prcDirty)
2961 intersect_rect( &rect, &rect, info->prcDirty );
2962 memcpy( src_bits, dst_bits, bmi->bmiHeader.biSizeImage );
2963 NtGdiPatBlt( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, BLACKNESS );
2965 src_rect = rect;
2966 if (info->pptSrc) OffsetRect( &src_rect, info->pptSrc->x, info->pptSrc->y );
2967 NtGdiTransformPoints( info->hdcSrc, (POINT *)&src_rect, (POINT *)&src_rect, 2, NtGdiDPtoLP );
2969 if (info->dwFlags & ULW_ALPHA) blend = *info->pblend;
2970 ret = NtGdiAlphaBlend( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
2971 info->hdcSrc, src_rect.left, src_rect.top,
2972 src_rect.right - src_rect.left, src_rect.bottom - src_rect.top,
2973 *(DWORD *)&blend, 0 );
2974 if (ret)
2976 memcpy( dst_bits, src_bits, bmi->bmiHeader.biSizeImage );
2977 add_bounds_rect( surface->funcs->get_bounds( surface ), &rect );
2980 surface->funcs->unlock( surface );
2981 surface->funcs->flush( surface );
2983 done:
2984 window_surface_release( surface );
2985 if (hdc) NtGdiDeleteObjectApp( hdc );
2986 if (dib) NtGdiDeleteObjectApp( dib );
2987 return ret;
2990 /* Add a window to taskbar */
2991 static void taskbar_add_tab( HWND hwnd )
2993 struct x11drv_win_data *data;
2995 TRACE("hwnd %p\n", hwnd);
2997 data = get_win_data( hwnd );
2998 if (!data)
2999 return;
3001 data->add_taskbar = TRUE;
3002 data->skip_taskbar = FALSE;
3003 update_net_wm_states( data );
3004 release_win_data( data );
3007 /* Delete a window from taskbar */
3008 static void taskbar_delete_tab( HWND hwnd )
3010 struct x11drv_win_data *data;
3012 TRACE("hwnd %p\n", hwnd);
3014 data = get_win_data( hwnd );
3015 if (!data)
3016 return;
3018 data->skip_taskbar = TRUE;
3019 data->add_taskbar = FALSE;
3020 update_net_wm_states( data );
3021 release_win_data( data );
3024 /**********************************************************************
3025 * X11DRV_WindowMessage (X11DRV.@)
3027 LRESULT X11DRV_WindowMessage( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
3029 struct x11drv_win_data *data;
3031 switch(msg)
3033 case WM_X11DRV_UPDATE_CLIPBOARD:
3034 return update_clipboard( hwnd );
3035 case WM_X11DRV_SET_WIN_REGION:
3036 if ((data = get_win_data( hwnd )))
3038 sync_window_region( data, (HRGN)1 );
3039 release_win_data( data );
3041 return 0;
3042 case WM_X11DRV_DESKTOP_RESIZED:
3043 if ((data = get_win_data( hwnd )))
3045 /* update the full screen state */
3046 update_net_wm_states( data );
3048 if (data->whole_window)
3050 /* sync window position with the new virtual screen rect */
3051 POINT old_pos = {.x = data->whole_rect.left - wp, .y = data->whole_rect.top - lp};
3052 POINT pos = virtual_screen_to_root( data->whole_rect.left, data->whole_rect.top );
3053 XWindowChanges changes = {.x = pos.x, .y = pos.y};
3054 UINT mask = 0;
3056 if (old_pos.x != pos.x) mask |= CWX;
3057 if (old_pos.y != pos.y) mask |= CWY;
3059 if (mask) XReconfigureWMWindow( data->display, data->whole_window, data->vis.screen, mask, &changes );
3062 release_win_data( data );
3064 return 0;
3065 case WM_X11DRV_DELETE_TAB:
3066 taskbar_delete_tab( hwnd );
3067 return 0;
3068 case WM_X11DRV_ADD_TAB:
3069 taskbar_add_tab( hwnd );
3070 return 0;
3071 default:
3072 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg, hwnd, (long)wp, lp );
3073 return 0;
3078 /***********************************************************************
3079 * is_netwm_supported
3081 static BOOL is_netwm_supported( Display *display, Atom atom )
3083 static Atom *net_supported;
3084 static int net_supported_count = -1;
3085 int i;
3087 if (net_supported_count == -1)
3089 Atom type;
3090 int format;
3091 unsigned long count, remaining;
3093 if (!XGetWindowProperty( display, DefaultRootWindow(display), x11drv_atom(_NET_SUPPORTED), 0,
3094 ~0UL, False, XA_ATOM, &type, &format, &count,
3095 &remaining, (unsigned char **)&net_supported ))
3096 net_supported_count = get_property_size( format, count ) / sizeof(Atom);
3097 else
3098 net_supported_count = 0;
3101 for (i = 0; i < net_supported_count; i++)
3102 if (net_supported[i] == atom) return TRUE;
3103 return FALSE;
3107 /***********************************************************************
3108 * start_screensaver
3110 static LRESULT start_screensaver(void)
3112 if (!is_virtual_desktop())
3114 const char *argv[3] = { "xdg-screensaver", "activate", NULL };
3115 int pid = __wine_unix_spawnvp( (char **)argv, FALSE );
3116 if (pid > 0)
3118 TRACE( "started process %d\n", pid );
3119 return 0;
3122 return -1;
3126 /***********************************************************************
3127 * SysCommand (X11DRV.@)
3129 * Perform WM_SYSCOMMAND handling.
3131 LRESULT X11DRV_SysCommand( HWND hwnd, WPARAM wparam, LPARAM lparam )
3133 WPARAM hittest = wparam & 0x0f;
3134 int dir;
3135 struct x11drv_win_data *data;
3137 if (!(data = get_win_data( hwnd )))
3139 if (wparam == SC_SCREENSAVE && hwnd == NtUserGetDesktopWindow()) return start_screensaver();
3140 return -1;
3142 if (!data->whole_window || !data->managed || !data->mapped) goto failed;
3144 switch (wparam & 0xfff0)
3146 case SC_MOVE:
3147 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
3148 else dir = _NET_WM_MOVERESIZE_MOVE;
3149 break;
3150 case SC_SIZE:
3151 /* windows without WS_THICKFRAME are not resizable through the window manager */
3152 if (!(NtUserGetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) goto failed;
3154 switch (hittest)
3156 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
3157 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
3158 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
3159 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
3160 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
3161 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
3162 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
3163 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
3164 case 9: dir = _NET_WM_MOVERESIZE_MOVE; break;
3165 default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break;
3167 break;
3169 case SC_KEYMENU:
3170 /* prevent a simple ALT press+release from activating the system menu,
3171 * as that can get confusing on managed windows */
3172 if ((WCHAR)lparam) goto failed; /* got an explicit char */
3173 if (NtUserGetWindowLongPtrW( hwnd, GWLP_ID )) goto failed; /* window has a real menu */
3174 if (!(NtUserGetWindowLongW( hwnd, GWL_STYLE ) & WS_SYSMENU)) goto failed; /* no system menu */
3175 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", (long)wparam, lparam );
3176 release_win_data( data );
3177 return 0;
3179 default:
3180 goto failed;
3183 if (NtUserGetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE) goto failed;
3185 if (!is_netwm_supported( data->display, x11drv_atom(_NET_WM_MOVERESIZE) ))
3187 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
3188 goto failed;
3191 release_win_data( data );
3192 move_resize_window( hwnd, dir );
3193 return 0;
3195 failed:
3196 release_win_data( data );
3197 return -1;
3200 void X11DRV_FlashWindowEx( FLASHWINFO *pfinfo )
3202 struct x11drv_win_data *data = get_win_data( pfinfo->hwnd );
3203 XEvent xev;
3205 if (!data)
3206 return;
3208 if (data->mapped)
3210 xev.type = ClientMessage;
3211 xev.xclient.window = data->whole_window;
3212 xev.xclient.message_type = x11drv_atom( _NET_WM_STATE );
3213 xev.xclient.serial = 0;
3214 xev.xclient.display = data->display;
3215 xev.xclient.send_event = True;
3216 xev.xclient.format = 32;
3217 xev.xclient.data.l[0] = pfinfo->dwFlags ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
3218 xev.xclient.data.l[1] = x11drv_atom( _NET_WM_STATE_DEMANDS_ATTENTION );
3219 xev.xclient.data.l[2] = 0;
3220 xev.xclient.data.l[3] = 1;
3221 xev.xclient.data.l[4] = 0;
3223 XSendEvent( data->display, DefaultRootWindow( data->display ), False,
3224 SubstructureNotifyMask, &xev );
3226 release_win_data( data );
3229 void init_win_context(void)
3231 init_recursive_mutex( &win_data_mutex );
3233 winContext = XUniqueContext();
3234 win_data_context = XUniqueContext();
3235 cursor_context = XUniqueContext();