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
33 #include <X11/Xresource.h>
34 #include <X11/Xutil.h>
36 #include <X11/extensions/shape.h>
37 #endif /* HAVE_LIBXSHAPE */
43 #include "wine/unicode.h"
46 #include "xcomposite.h"
47 #include "wine/debug.h"
48 #include "wine/server.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
53 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
54 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
55 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
56 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
57 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
58 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
59 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
60 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
61 #define _NET_WM_MOVERESIZE_MOVE 8
62 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9
63 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10
65 #define _NET_WM_STATE_REMOVE 0
66 #define _NET_WM_STATE_ADD 1
67 #define _NET_WM_STATE_TOGGLE 2
69 #define SWP_AGG_NOPOSCHANGE (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
71 /* is cursor clipping active? */
72 int clipping_cursor = 0;
74 /* X context to associate a hwnd to an X window */
75 XContext winContext = 0;
77 /* X context to associate a struct x11drv_win_data to an hwnd */
78 XContext win_data_context = 0;
80 /* time of last user event and window where it's stored */
81 static Time last_user_time;
82 static Window user_time_window;
84 static const char foreign_window_prop[] = "__wine_x11_foreign_window";
85 static const char whole_window_prop[] = "__wine_x11_whole_window";
86 static const char client_window_prop[]= "__wine_x11_client_window";
87 static const char icon_window_prop[] = "__wine_x11_icon_window";
88 static const char clip_window_prop[] = "__wine_x11_clip_window";
89 static const char fbconfig_id_prop[] = "__wine_x11_fbconfig_id";
90 static const char gl_drawable_prop[] = "__wine_x11_gl_drawable";
91 static const char pixmap_prop[] = "__wine_x11_pixmap";
92 static const char managed_prop[] = "__wine_x11_managed";
95 /***********************************************************************
96 * http://standards.freedesktop.org/startup-notification-spec
98 static void remove_startup_notification(Display *display, Window window)
100 static LONG startup_notification_removed = 0;
109 if (InterlockedCompareExchange(&startup_notification_removed, 1, 0) != 0)
112 if (GetEnvironmentVariableA("DESKTOP_STARTUP_ID", id, sizeof(id)) == 0)
114 SetEnvironmentVariableA("DESKTOP_STARTUP_ID", NULL);
116 if ((src = strstr( id, "_TIME" ))) update_user_time( atol( src + 5 ));
118 pos = snprintf(message, sizeof(message), "remove: ID=");
119 message[pos++] = '"';
120 for (i = 0; id[i] && pos < sizeof(message) - 2; i++)
122 if (id[i] == '"' || id[i] == '\\')
123 message[pos++] = '\\';
124 message[pos++] = id[i];
126 message[pos++] = '"';
127 message[pos++] = '\0';
129 xevent.xclient.type = ClientMessage;
130 xevent.xclient.message_type = x11drv_atom(_NET_STARTUP_INFO_BEGIN);
131 xevent.xclient.display = display;
132 xevent.xclient.window = window;
133 xevent.xclient.format = 8;
136 srclen = strlen(src) + 1;
143 memset(&xevent.xclient.data.b[0], 0, 20);
144 memcpy(&xevent.xclient.data.b[0], src, msglen);
148 XSendEvent( display, DefaultRootWindow( display ), False, PropertyChangeMask, &xevent );
149 xevent.xclient.message_type = x11drv_atom(_NET_STARTUP_INFO);
154 struct has_popup_result
160 static BOOL CALLBACK has_managed_popup( HWND hwnd, LPARAM lparam )
162 struct has_popup_result *result = (struct has_popup_result *)lparam;
163 struct x11drv_win_data *data;
165 if (hwnd == result->hwnd) return FALSE; /* popups are always above owner */
166 if (!(data = X11DRV_get_win_data( hwnd ))) return TRUE;
167 if (GetWindow( hwnd, GW_OWNER ) != result->hwnd) return TRUE;
168 result->found = data->managed;
169 return !result->found;
172 static BOOL has_owned_popups( HWND hwnd )
174 struct has_popup_result result;
177 result.found = FALSE;
178 EnumWindows( has_managed_popup, (LPARAM)&result );
182 /***********************************************************************
185 * Check if a given window should be managed
187 static BOOL is_window_managed( HWND hwnd, UINT swp_flags, const RECT *window_rect )
189 DWORD style, ex_style;
191 if (!managed_mode) return FALSE;
193 /* child windows are not managed */
194 style = GetWindowLongW( hwnd, GWL_STYLE );
195 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD) return FALSE;
196 /* activated windows are managed */
197 if (!(swp_flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) return TRUE;
198 if (hwnd == GetActiveWindow()) return TRUE;
199 /* windows with caption are managed */
200 if ((style & WS_CAPTION) == WS_CAPTION) return TRUE;
201 /* windows with thick frame are managed */
202 if (style & WS_THICKFRAME) return TRUE;
203 if (style & WS_POPUP)
208 /* popup with sysmenu == caption are managed */
209 if (style & WS_SYSMENU) return TRUE;
210 /* full-screen popup windows are managed */
211 hmon = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY );
212 mi.cbSize = sizeof( mi );
213 GetMonitorInfoW( hmon, &mi );
214 if (window_rect->left <= mi.rcWork.left && window_rect->right >= mi.rcWork.right &&
215 window_rect->top <= mi.rcWork.top && window_rect->bottom >= mi.rcWork.bottom)
218 /* application windows are managed */
219 ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE );
220 if (ex_style & WS_EX_APPWINDOW) return TRUE;
221 /* windows that own popups are managed */
222 if (has_owned_popups( hwnd )) return TRUE;
223 /* default: not managed */
228 /***********************************************************************
229 * is_window_resizable
231 * Check if window should be made resizable by the window manager
233 static inline BOOL is_window_resizable( struct x11drv_win_data *data, DWORD style )
235 if (style & WS_THICKFRAME) return TRUE;
236 /* Metacity needs the window to be resizable to make it fullscreen */
237 return is_window_rect_fullscreen( &data->whole_rect );
241 /***********************************************************************
242 * get_mwm_decorations
244 static unsigned long get_mwm_decorations( struct x11drv_win_data *data,
245 DWORD style, DWORD ex_style )
247 unsigned long ret = 0;
249 if (!decorated_mode) return 0;
251 if (IsRectEmpty( &data->window_rect )) return 0;
252 if (data->shaped) return 0;
254 if (ex_style & WS_EX_TOOLWINDOW) return 0;
256 if ((style & WS_CAPTION) == WS_CAPTION)
258 ret |= MWM_DECOR_TITLE | MWM_DECOR_BORDER;
259 if (style & WS_SYSMENU) ret |= MWM_DECOR_MENU;
260 if (style & WS_MINIMIZEBOX) ret |= MWM_DECOR_MINIMIZE;
261 if (style & WS_MAXIMIZEBOX) ret |= MWM_DECOR_MAXIMIZE;
263 if (ex_style & WS_EX_DLGMODALFRAME) ret |= MWM_DECOR_BORDER;
264 else if (style & WS_THICKFRAME) ret |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
265 else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) ret |= MWM_DECOR_BORDER;
270 /***********************************************************************
271 * get_x11_rect_offset
273 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
275 static void get_x11_rect_offset( struct x11drv_win_data *data, RECT *rect )
277 DWORD style, ex_style, style_mask = 0, ex_style_mask = 0;
280 rect->top = rect->bottom = rect->left = rect->right = 0;
282 style = GetWindowLongW( data->hwnd, GWL_STYLE );
283 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
284 decor = get_mwm_decorations( data, style, ex_style );
286 if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION;
287 if (decor & MWM_DECOR_BORDER)
289 style_mask |= WS_DLGFRAME | WS_THICKFRAME;
290 ex_style_mask |= WS_EX_DLGMODALFRAME;
293 AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask );
297 /***********************************************************************
298 * get_window_attributes
300 * Fill the window attributes structure for an X window.
302 static int get_window_attributes( Display *display, struct x11drv_win_data *data,
303 XSetWindowAttributes *attr )
305 attr->override_redirect = !data->managed;
306 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
307 attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0);
308 attr->bit_gravity = NorthWestGravity;
309 attr->win_gravity = StaticGravity;
310 attr->backing_store = NotUseful;
311 attr->event_mask = (ExposureMask | PointerMotionMask |
312 ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
313 KeyPressMask | KeyReleaseMask | FocusChangeMask |
314 KeymapStateMask | StructureNotifyMask);
315 if (data->managed) attr->event_mask |= PropertyChangeMask;
317 return (CWOverrideRedirect | CWSaveUnder | CWColormap |
318 CWEventMask | CWBitGravity | CWBackingStore);
322 /***********************************************************************
323 * create_client_window
325 static Window create_client_window( Display *display, struct x11drv_win_data *data, XVisualInfo *vis )
328 XSetWindowAttributes attr;
330 Visual *client_visual = vis ? vis->visual : visual;
332 attr.bit_gravity = NorthWestGravity;
333 attr.win_gravity = NorthWestGravity;
334 attr.backing_store = NotUseful;
335 attr.event_mask = (ExposureMask | PointerMotionMask |
336 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
337 mask = CWEventMask | CWBitGravity | CWWinGravity | CWBackingStore;
339 if ((cx = data->client_rect.right - data->client_rect.left) <= 0) cx = 1;
340 else if (cx > 65535) cx = 65535;
341 if ((cy = data->client_rect.bottom - data->client_rect.top) <= 0) cy = 1;
342 else if (cy > 65535) cy = 65535;
346 attr.colormap = XCreateColormap( display, root_window, vis->visual,
347 (vis->class == PseudoColor || vis->class == GrayScale ||
348 vis->class == DirectColor) ? AllocAll : AllocNone );
352 client = XCreateWindow( display, data->whole_window,
353 data->client_rect.left - data->whole_rect.left,
354 data->client_rect.top - data->whole_rect.top,
355 cx, cy, 0, screen_depth, InputOutput,
356 client_visual, mask, &attr );
359 if (vis) XFreeColormap( display, attr.colormap );
363 if (data->client_window)
365 XDeleteContext( display, data->client_window, winContext );
366 XDestroyWindow( display, data->client_window );
368 data->client_window = client;
369 data->visualid = XVisualIDFromVisual( client_visual );
371 if (data->colormap) XFreeColormap( display, data->colormap );
372 data->colormap = vis ? attr.colormap : 0;
374 XMapWindow( display, data->client_window );
375 XSaveContext( display, data->client_window, winContext, (char *)data->hwnd );
376 SetPropA( data->hwnd, client_window_prop, (HANDLE)data->client_window );
377 return data->client_window;
381 /***********************************************************************
384 * Change the X window attributes when the window style has changed.
386 static void sync_window_style( Display *display, struct x11drv_win_data *data )
388 if (data->whole_window != root_window)
390 XSetWindowAttributes attr;
391 int mask = get_window_attributes( display, data, &attr );
393 XChangeWindowAttributes( display, data->whole_window, mask, &attr );
398 /***********************************************************************
401 * Update the X11 window region.
403 static void sync_window_region( Display *display, struct x11drv_win_data *data, HRGN win_region )
405 #ifdef HAVE_LIBXSHAPE
406 HRGN hrgn = win_region;
408 if (!data->whole_window) return;
409 data->shaped = FALSE;
411 if (IsRectEmpty( &data->window_rect )) /* set an empty shape */
413 static XRectangle empty_rect;
414 XShapeCombineRectangles( display, data->whole_window, ShapeBounding, 0, 0,
415 &empty_rect, 1, ShapeSet, YXBanded );
419 if (hrgn == (HRGN)1) /* hack: win_region == 1 means retrieve region from server */
421 if (!(hrgn = CreateRectRgn( 0, 0, 0, 0 ))) return;
422 if (GetWindowRgn( data->hwnd, hrgn ) == ERROR)
424 DeleteObject( hrgn );
431 XShapeCombineMask( display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet );
435 RGNDATA *pRegionData;
437 if (GetWindowLongW( data->hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) MirrorRgn( data->hwnd, hrgn );
438 if ((pRegionData = X11DRV_GetRegionData( hrgn, 0 )))
440 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
441 data->window_rect.left - data->whole_rect.left,
442 data->window_rect.top - data->whole_rect.top,
443 (XRectangle *)pRegionData->Buffer,
444 pRegionData->rdh.nCount, ShapeSet, YXBanded );
445 HeapFree(GetProcessHeap(), 0, pRegionData);
449 if (hrgn && hrgn != win_region) DeleteObject( hrgn );
450 #endif /* HAVE_LIBXSHAPE */
454 /***********************************************************************
455 * sync_window_opacity
457 static void sync_window_opacity( Display *display, Window win,
458 COLORREF key, BYTE alpha, DWORD flags )
460 unsigned long opacity = 0xffffffff;
462 if (flags & LWA_ALPHA) opacity = (0xffffffff / 0xff) * alpha;
464 if (flags & LWA_COLORKEY) FIXME("LWA_COLORKEY not supported\n");
466 if (opacity == 0xffffffff)
467 XDeleteProperty( display, win, x11drv_atom(_NET_WM_WINDOW_OPACITY) );
469 XChangeProperty( display, win, x11drv_atom(_NET_WM_WINDOW_OPACITY),
470 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&opacity, 1 );
474 /***********************************************************************
477 static void sync_window_text( Display *display, Window win, const WCHAR *text )
480 char *buffer, *utf8_buffer;
483 /* allocate new buffer for window text */
484 count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
485 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) return;
486 WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
488 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
489 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
491 HeapFree( GetProcessHeap(), 0, buffer );
494 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
496 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
498 XSetWMName( display, win, &prop );
499 XSetWMIconName( display, win, &prop );
503 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
504 according to the standard
505 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
507 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
508 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
510 HeapFree( GetProcessHeap(), 0, utf8_buffer );
511 HeapFree( GetProcessHeap(), 0, buffer );
515 /***********************************************************************
518 static BOOL set_win_format( HWND hwnd, XID fbconfig_id )
520 struct x11drv_win_data *data;
524 if (!(data = X11DRV_get_win_data(hwnd)) &&
525 !(data = X11DRV_create_win_data(hwnd))) return FALSE;
527 if (!(vis = visual_from_fbconfig_id(fbconfig_id))) return FALSE;
529 if (data->whole_window)
531 Display *display = thread_display();
532 Window client = data->client_window;
534 if (vis->visualid != data->visualid)
536 client = create_client_window( display, data, vis );
537 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client, data->hwnd, fbconfig_id );
541 if (client) goto done;
545 w = data->client_rect.right - data->client_rect.left;
546 h = data->client_rect.bottom - data->client_rect.top;
551 #ifdef SONAME_LIBXCOMPOSITE
554 XSetWindowAttributes attrib;
555 static Window dummy_parent;
557 attrib.override_redirect = True;
560 dummy_parent = XCreateWindow( gdi_display, root_window, -1, -1, 1, 1, 0, screen_depth,
561 InputOutput, visual, CWOverrideRedirect, &attrib );
562 XMapWindow( gdi_display, dummy_parent );
564 data->colormap = XCreateColormap(gdi_display, dummy_parent, vis->visual,
565 (vis->class == PseudoColor ||
566 vis->class == GrayScale ||
567 vis->class == DirectColor) ?
568 AllocAll : AllocNone);
569 attrib.colormap = data->colormap;
570 XInstallColormap(gdi_display, attrib.colormap);
572 if(data->gl_drawable) XDestroyWindow(gdi_display, data->gl_drawable);
573 data->gl_drawable = XCreateWindow(gdi_display, dummy_parent, 0, 0, w, h, 0,
574 vis->depth, InputOutput, vis->visual,
575 CWColormap | CWOverrideRedirect,
577 if(data->gl_drawable)
579 pXCompositeRedirectWindow(gdi_display, data->gl_drawable,
580 CompositeRedirectManual);
581 XMapWindow(gdi_display, data->gl_drawable);
584 XFlush( gdi_display );
589 WARN("XComposite is not available, using GLXPixmap hack\n");
591 if(data->pixmap) XFreePixmap(gdi_display, data->pixmap);
592 data->pixmap = XCreatePixmap(gdi_display, root_window, w, h, vis->depth);
599 if(data->gl_drawable) destroy_glxpixmap(gdi_display, data->gl_drawable);
600 data->gl_drawable = create_glxpixmap(gdi_display, vis, data->pixmap);
601 if(!data->gl_drawable)
603 XFreePixmap(gdi_display, data->pixmap);
607 XFlush( gdi_display );
608 if (data->pixmap) SetPropA(hwnd, pixmap_prop, (HANDLE)data->pixmap);
611 if (!data->gl_drawable) return FALSE;
613 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
614 data->gl_drawable, fbconfig_id);
615 SetPropA(hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
618 data->fbconfig_id = fbconfig_id;
619 SetPropA(hwnd, fbconfig_id_prop, (HANDLE)data->fbconfig_id);
620 /* force DCE invalidation */
621 SetWindowPos( hwnd, 0, 0, 0, 0, 0,
622 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE |
623 SWP_NOREDRAW | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_STATECHANGED);
627 /***********************************************************************
630 static void sync_gl_drawable(struct x11drv_win_data *data)
632 int w = data->client_rect.right - data->client_rect.left;
633 int h = data->client_rect.bottom - data->client_rect.top;
641 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data->gl_drawable, w, h);
642 #ifdef SONAME_LIBXCOMPOSITE
645 XMoveResizeWindow(gdi_display, data->gl_drawable, 0, 0, w, h);
650 if (!(vis = visual_from_fbconfig_id(data->fbconfig_id))) return;
652 pix = XCreatePixmap(gdi_display, root_window, w, h, vis->depth);
655 ERR("Failed to create pixmap for offscreen rendering\n");
660 glxp = create_glxpixmap(gdi_display, vis, pix);
663 ERR("Failed to create drawable for offscreen rendering\n");
664 XFreePixmap(gdi_display, pix);
671 mark_drawable_dirty(data->gl_drawable, glxp);
673 XFreePixmap(gdi_display, data->pixmap);
674 destroy_glxpixmap(gdi_display, data->gl_drawable);
675 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp, data->gl_drawable );
678 data->gl_drawable = glxp;
680 XFlush( gdi_display );
682 SetPropA(data->hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
683 SetPropA(data->hwnd, pixmap_prop, (HANDLE)data->pixmap);
687 /***********************************************************************
690 * fill the window changes structure
692 static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
696 if (old->right - old->left != new->right - new->left )
698 if ((changes->width = new->right - new->left) <= 0) changes->width = 1;
699 else if (changes->width > 65535) changes->width = 65535;
702 if (old->bottom - old->top != new->bottom - new->top)
704 if ((changes->height = new->bottom - new->top) <= 0) changes->height = 1;
705 else if (changes->height > 65535) changes->height = 65535;
708 if (old->left != new->left)
710 changes->x = new->left;
713 if (old->top != new->top)
715 changes->y = new->top;
722 /***********************************************************************
725 static Window create_icon_window( Display *display, struct x11drv_win_data *data )
727 XSetWindowAttributes attr;
729 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
730 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
731 attr.bit_gravity = NorthWestGravity;
732 attr.backing_store = NotUseful/*WhenMapped*/;
733 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
735 data->icon_window = XCreateWindow( display, root_window, 0, 0,
736 GetSystemMetrics( SM_CXICON ),
737 GetSystemMetrics( SM_CYICON ),
740 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
741 XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd );
742 XFlush( display ); /* make sure the window exists before we start painting to it */
744 TRACE( "created %lx\n", data->icon_window );
745 SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window );
746 return data->icon_window;
751 /***********************************************************************
752 * destroy_icon_window
754 static void destroy_icon_window( Display *display, struct x11drv_win_data *data )
756 if (!data->icon_window) return;
757 XDeleteContext( display, data->icon_window, winContext );
758 XDestroyWindow( display, data->icon_window );
759 data->icon_window = 0;
760 RemovePropA( data->hwnd, icon_window_prop );
764 /***********************************************************************
767 * Return the bitmap bits in ARGB format. Helper for setting icon hints.
769 static unsigned long *get_bitmap_argb( HDC hdc, HBITMAP color, HBITMAP mask, unsigned int *size )
771 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
772 BITMAPINFO *info = (BITMAPINFO *)buffer;
774 unsigned int *ptr, *bits = NULL;
775 unsigned char *mask_bits = NULL;
776 int i, j, has_alpha = 0;
778 if (!GetObjectW( color, sizeof(bm), &bm )) return NULL;
779 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
780 info->bmiHeader.biWidth = bm.bmWidth;
781 info->bmiHeader.biHeight = -bm.bmHeight;
782 info->bmiHeader.biPlanes = 1;
783 info->bmiHeader.biBitCount = 32;
784 info->bmiHeader.biCompression = BI_RGB;
785 info->bmiHeader.biSizeImage = bm.bmWidth * bm.bmHeight * 4;
786 info->bmiHeader.biXPelsPerMeter = 0;
787 info->bmiHeader.biYPelsPerMeter = 0;
788 info->bmiHeader.biClrUsed = 0;
789 info->bmiHeader.biClrImportant = 0;
790 *size = bm.bmWidth * bm.bmHeight + 2;
791 if (!(bits = HeapAlloc( GetProcessHeap(), 0, *size * sizeof(long) ))) goto failed;
792 if (!GetDIBits( hdc, color, 0, bm.bmHeight, bits + 2, info, DIB_RGB_COLORS )) goto failed;
794 bits[0] = bm.bmWidth;
795 bits[1] = bm.bmHeight;
797 for (i = 0; i < bm.bmWidth * bm.bmHeight; i++)
798 if ((has_alpha = (bits[i + 2] & 0xff000000) != 0)) break;
802 unsigned int width_bytes = (bm.bmWidth + 31) / 32 * 4;
803 /* generate alpha channel from the mask */
804 info->bmiHeader.biBitCount = 1;
805 info->bmiHeader.biSizeImage = width_bytes * bm.bmHeight;
806 if (!(mask_bits = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage ))) goto failed;
807 if (!GetDIBits( hdc, mask, 0, bm.bmHeight, mask_bits, info, DIB_RGB_COLORS )) goto failed;
809 for (i = 0; i < bm.bmHeight; i++)
810 for (j = 0; j < bm.bmWidth; j++, ptr++)
811 if (!((mask_bits[i * width_bytes + j / 8] << (j % 8)) & 0x80)) *ptr |= 0xff000000;
812 HeapFree( GetProcessHeap(), 0, mask_bits );
815 /* convert to array of longs */
816 if (bits && sizeof(long) > sizeof(int))
817 for (i = *size - 1; i >= 0; i--) ((unsigned long *)bits)[i] = bits[i];
819 return (unsigned long *)bits;
822 HeapFree( GetProcessHeap(), 0, bits );
823 HeapFree( GetProcessHeap(), 0, mask_bits );
828 /***********************************************************************
829 * create_icon_pixmaps
831 static BOOL create_icon_pixmaps( HDC hdc, const ICONINFO *icon, struct x11drv_win_data *data )
833 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
834 BITMAPINFO *info = (BITMAPINFO *)buffer;
836 struct gdi_image_bits bits;
837 Pixmap color_pixmap = 0, mask_pixmap = 0;
844 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
845 info->bmiHeader.biBitCount = 0;
846 if (!(lines = GetDIBits( hdc, icon->hbmColor, 0, 0, NULL, info, DIB_RGB_COLORS ))) goto failed;
847 if (!(bits.ptr = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage ))) goto failed;
848 if (!GetDIBits( hdc, icon->hbmColor, 0, lines, bits.ptr, info, DIB_RGB_COLORS )) goto failed;
851 vis.depth = screen_depth;
852 vis.visualid = visual->visualid;
853 vis.class = visual->class;
854 vis.red_mask = visual->red_mask;
855 vis.green_mask = visual->green_mask;
856 vis.blue_mask = visual->blue_mask;
857 color_pixmap = create_pixmap_from_image( hdc, &vis, info, &bits, DIB_RGB_COLORS );
858 HeapFree( GetProcessHeap(), 0, bits.ptr );
860 if (!color_pixmap) goto failed;
862 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
863 info->bmiHeader.biBitCount = 0;
864 if (!(lines = GetDIBits( hdc, icon->hbmMask, 0, 0, NULL, info, DIB_RGB_COLORS ))) goto failed;
865 if (!(bits.ptr = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage ))) goto failed;
866 if (!GetDIBits( hdc, icon->hbmMask, 0, lines, bits.ptr, info, DIB_RGB_COLORS )) goto failed;
868 /* invert the mask */
869 for (i = 0; i < info->bmiHeader.biSizeImage / sizeof(DWORD); i++) ((DWORD *)bits.ptr)[i] ^= ~0u;
872 mask_pixmap = create_pixmap_from_image( hdc, &vis, info, &bits, DIB_RGB_COLORS );
873 HeapFree( GetProcessHeap(), 0, bits.ptr );
875 if (!mask_pixmap) goto failed;
877 data->icon_pixmap = color_pixmap;
878 data->icon_mask = mask_pixmap;
882 if (color_pixmap) XFreePixmap( gdi_display, color_pixmap );
883 if (mask_pixmap) XFreePixmap( gdi_display, mask_pixmap );
884 HeapFree( GetProcessHeap(), 0, bits.ptr );
889 /***********************************************************************
892 * Set the icon wm hints
894 static void set_icon_hints( Display *display, struct x11drv_win_data *data,
895 HICON icon_big, HICON icon_small )
897 XWMHints *hints = data->wm_hints;
901 icon_big = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 );
902 if (!icon_big) icon_big = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON );
906 icon_small = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_SMALL, 0 );
907 if (!icon_small) icon_small = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICONSM );
910 if (data->icon_pixmap) XFreePixmap( gdi_display, data->icon_pixmap );
911 if (data->icon_mask) XFreePixmap( gdi_display, data->icon_mask );
912 data->icon_pixmap = data->icon_mask = 0;
916 if (!data->icon_window) create_icon_window( display, data );
917 hints->icon_window = data->icon_window;
918 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
922 ICONINFO ii, ii_small;
927 if (!GetIconInfo(icon_big, &ii)) return;
929 hDC = CreateCompatibleDC(0);
930 bits = get_bitmap_argb( hDC, ii.hbmColor, ii.hbmMask, &size );
931 if (bits && GetIconInfo( icon_small, &ii_small ))
933 unsigned int size_small;
934 unsigned long *bits_small, *new;
936 if ((bits_small = get_bitmap_argb( hDC, ii_small.hbmColor, ii_small.hbmMask, &size_small )) &&
937 (bits_small[0] != bits[0] || bits_small[1] != bits[1])) /* size must be different */
939 if ((new = HeapReAlloc( GetProcessHeap(), 0, bits,
940 (size + size_small) * sizeof(unsigned long) )))
943 memcpy( bits + size, bits_small, size_small * sizeof(unsigned long) );
947 HeapFree( GetProcessHeap(), 0, bits_small );
948 DeleteObject( ii_small.hbmColor );
949 DeleteObject( ii_small.hbmMask );
952 XChangeProperty( display, data->whole_window, x11drv_atom(_NET_WM_ICON),
953 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)bits, size );
955 XDeleteProperty( display, data->whole_window, x11drv_atom(_NET_WM_ICON) );
956 HeapFree( GetProcessHeap(), 0, bits );
958 if (create_icon_pixmaps( hDC, &ii, data ))
960 hints->icon_pixmap = data->icon_pixmap;
961 hints->icon_mask = data->icon_mask;
962 hints->flags |= IconPixmapHint | IconMaskHint;
964 destroy_icon_window( display, data );
965 hints->flags &= ~IconWindowHint;
967 DeleteObject( ii.hbmColor );
968 DeleteObject( ii.hbmMask );
974 /***********************************************************************
977 * set the window size hints
979 static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style )
981 XSizeHints* size_hints;
983 if (!(size_hints = XAllocSizeHints())) return;
985 size_hints->win_gravity = StaticGravity;
986 size_hints->flags |= PWinGravity;
988 /* don't update size hints if window is not in normal state */
989 if (!(style & (WS_MINIMIZE | WS_MAXIMIZE)))
991 if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */
993 size_hints->x = data->whole_rect.left;
994 size_hints->y = data->whole_rect.top;
995 size_hints->flags |= PPosition;
997 else size_hints->win_gravity = NorthWestGravity;
999 if (!is_window_resizable( data, style ))
1001 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
1002 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
1003 if (size_hints->max_width <= 0 ||size_hints->max_height <= 0)
1004 size_hints->max_width = size_hints->max_height = 1;
1005 size_hints->min_width = size_hints->max_width;
1006 size_hints->min_height = size_hints->max_height;
1007 size_hints->flags |= PMinSize | PMaxSize;
1010 XSetWMNormalHints( display, data->whole_window, size_hints );
1011 XFree( size_hints );
1015 /***********************************************************************
1018 static void set_mwm_hints( Display *display, struct x11drv_win_data *data, DWORD style, DWORD ex_style )
1022 if (data->hwnd == GetDesktopWindow())
1024 if (is_desktop_fullscreen()) mwm_hints.decorations = 0;
1025 else mwm_hints.decorations = MWM_DECOR_TITLE | MWM_DECOR_BORDER | MWM_DECOR_MENU | MWM_DECOR_MINIMIZE;
1026 mwm_hints.functions = MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE | MWM_FUNC_CLOSE;
1030 mwm_hints.decorations = get_mwm_decorations( data, style, ex_style );
1031 mwm_hints.functions = MWM_FUNC_MOVE;
1032 if (is_window_resizable( data, style )) mwm_hints.functions |= MWM_FUNC_RESIZE;
1033 if (!(style & WS_DISABLED))
1035 if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
1036 if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
1037 if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
1041 TRACE( "%p setting mwm hints to %lx,%lx (style %x exstyle %x)\n",
1042 data->hwnd, mwm_hints.decorations, mwm_hints.functions, style, ex_style );
1044 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
1045 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
1046 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
1047 (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
1051 /***********************************************************************
1054 * get the name of the current process for setting class hints
1056 static char *get_process_name(void)
1062 WCHAR module[MAX_PATH];
1063 DWORD len = GetModuleFileNameW( 0, module, MAX_PATH );
1064 if (len && len < MAX_PATH)
1067 WCHAR *p, *appname = module;
1069 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
1070 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
1071 len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL );
1072 if ((ptr = HeapAlloc( GetProcessHeap(), 0, len )))
1074 WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL );
1083 /***********************************************************************
1084 * set_initial_wm_hints
1086 * Set the window manager hints that don't change over the lifetime of a window.
1088 static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data )
1092 Atom dndVersion = WINE_XDND_VERSION;
1093 XClassHint *class_hints;
1094 char *process_name = get_process_name();
1098 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
1099 protocols[i++] = x11drv_atom(_NET_WM_PING);
1100 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
1101 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
1102 XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
1105 if ((class_hints = XAllocClassHint()))
1107 static char wine[] = "Wine";
1109 class_hints->res_name = process_name;
1110 class_hints->res_class = wine;
1111 XSetClassHint( display, data->whole_window, class_hints );
1112 XFree( class_hints );
1115 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
1116 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
1117 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
1119 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
1120 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
1122 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
1123 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
1125 update_user_time( 0 ); /* make sure that the user time window exists */
1126 if (user_time_window)
1127 XChangeProperty( display, data->whole_window, x11drv_atom(_NET_WM_USER_TIME_WINDOW),
1128 XA_WINDOW, 32, PropModeReplace, (unsigned char *)&user_time_window, 1 );
1130 data->wm_hints = XAllocWMHints();
1133 data->wm_hints->flags = 0;
1134 set_icon_hints( display, data, 0, 0 );
1139 /***********************************************************************
1140 * get_owner_whole_window
1142 * Retrieve an owner's window, creating it if necessary.
1144 static Window get_owner_whole_window( HWND owner, BOOL force_managed )
1146 struct x11drv_win_data *data;
1148 if (!owner) return 0;
1150 if (!(data = X11DRV_get_win_data( owner )))
1152 if (GetWindowThreadProcessId( owner, NULL ) != GetCurrentThreadId() ||
1153 !(data = X11DRV_create_win_data( owner )))
1154 return (Window)GetPropA( owner, whole_window_prop );
1156 else if (!data->managed && force_managed) /* make it managed */
1158 SetWindowPos( owner, 0, 0, 0, 0, 0,
1159 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE |
1160 SWP_NOREDRAW | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_STATECHANGED );
1162 return data->whole_window;
1166 /***********************************************************************
1169 * Set the window manager hints for a newly-created window
1171 static void set_wm_hints( Display *display, struct x11drv_win_data *data )
1173 Window group_leader = data->whole_window;
1174 Window owner_win = 0;
1176 DWORD style, ex_style;
1179 if (data->hwnd == GetDesktopWindow())
1181 /* force some styles for the desktop to get the correct decorations */
1182 style = WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
1183 ex_style = WS_EX_APPWINDOW;
1188 style = GetWindowLongW( data->hwnd, GWL_STYLE );
1189 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
1190 owner = GetWindow( data->hwnd, GW_OWNER );
1191 if ((owner_win = get_owner_whole_window( owner, data->managed ))) group_leader = owner_win;
1194 if (owner_win) XSetTransientForHint( display, data->whole_window, owner_win );
1197 set_size_hints( display, data, style );
1198 set_mwm_hints( display, data, style, ex_style );
1200 /* Only use dialog type for owned popups. Metacity allows making fullscreen
1201 * only normal windows, and doesn't handle correctly TRANSIENT_FOR hint for
1202 * dialogs owned by fullscreen windows.
1204 if (((style & WS_POPUP) || (ex_style & WS_EX_DLGMODALFRAME)) && owner) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
1205 else window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
1207 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
1208 XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1);
1213 data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint;
1214 data->wm_hints->input = !use_take_focus && !(style & WS_DISABLED);
1215 data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
1216 data->wm_hints->window_group = group_leader;
1217 XSetWMHints( display, data->whole_window, data->wm_hints );
1222 /***********************************************************************
1225 Window init_clip_window(void)
1227 struct x11drv_thread_data *data = x11drv_init_thread_data();
1229 if (!data->clip_window &&
1230 (data->clip_window = (Window)GetPropA( GetDesktopWindow(), clip_window_prop )))
1232 XSelectInput( data->display, data->clip_window, StructureNotifyMask );
1234 return data->clip_window;
1238 /***********************************************************************
1241 void update_user_time( Time time )
1243 if (!user_time_window)
1245 Window win = XCreateWindow( gdi_display, root_window, -1, -1, 1, 1, 0, 0, InputOnly,
1246 DefaultVisual(gdi_display,DefaultScreen(gdi_display)), 0, NULL );
1247 if (InterlockedCompareExchangePointer( (void **)&user_time_window, (void *)win, 0 ))
1248 XDestroyWindow( gdi_display, win );
1249 TRACE( "user time window %lx\n", user_time_window );
1253 XLockDisplay( gdi_display );
1254 if (!last_user_time || (long)(time - last_user_time) > 0)
1256 last_user_time = time;
1257 XChangeProperty( gdi_display, user_time_window, x11drv_atom(_NET_WM_USER_TIME),
1258 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&time, 1 );
1260 XUnlockDisplay( gdi_display );
1263 /***********************************************************************
1264 * update_net_wm_states
1266 void update_net_wm_states( Display *display, struct x11drv_win_data *data )
1268 static const unsigned int state_atoms[NB_NET_WM_STATES] =
1270 XATOM__NET_WM_STATE_FULLSCREEN,
1271 XATOM__NET_WM_STATE_ABOVE,
1272 XATOM__NET_WM_STATE_MAXIMIZED_VERT,
1273 XATOM__NET_WM_STATE_SKIP_PAGER,
1274 XATOM__NET_WM_STATE_SKIP_TASKBAR
1277 DWORD i, style, ex_style, new_state = 0;
1279 if (!data->managed) return;
1280 if (data->whole_window == root_window) return;
1282 style = GetWindowLongW( data->hwnd, GWL_STYLE );
1283 if (is_window_rect_fullscreen( &data->whole_rect ))
1285 if ((style & WS_MAXIMIZE) && (style & WS_CAPTION) == WS_CAPTION)
1286 new_state |= (1 << NET_WM_STATE_MAXIMIZED);
1287 else if (!(style & WS_MINIMIZE))
1288 new_state |= (1 << NET_WM_STATE_FULLSCREEN);
1290 else if (style & WS_MAXIMIZE)
1291 new_state |= (1 << NET_WM_STATE_MAXIMIZED);
1293 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
1294 if (ex_style & WS_EX_TOPMOST)
1295 new_state |= (1 << NET_WM_STATE_ABOVE);
1296 if (ex_style & (WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE))
1297 new_state |= (1 << NET_WM_STATE_SKIP_TASKBAR) | (1 << NET_WM_STATE_SKIP_PAGER);
1298 if (!(ex_style & WS_EX_APPWINDOW) && GetWindow( data->hwnd, GW_OWNER ))
1299 new_state |= (1 << NET_WM_STATE_SKIP_TASKBAR);
1301 if (!data->mapped) /* set the _NET_WM_STATE atom directly */
1303 Atom atoms[NB_NET_WM_STATES+1];
1306 for (i = count = 0; i < NB_NET_WM_STATES; i++)
1308 if (!(new_state & (1 << i))) continue;
1309 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
1310 i, data->hwnd, data->whole_window );
1311 atoms[count++] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM];
1312 if (state_atoms[i] == XATOM__NET_WM_STATE_MAXIMIZED_VERT)
1313 atoms[count++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ);
1315 XChangeProperty( display, data->whole_window, x11drv_atom(_NET_WM_STATE), XA_ATOM,
1316 32, PropModeReplace, (unsigned char *)atoms, count );
1318 else /* ask the window manager to do it for us */
1322 xev.xclient.type = ClientMessage;
1323 xev.xclient.window = data->whole_window;
1324 xev.xclient.message_type = x11drv_atom(_NET_WM_STATE);
1325 xev.xclient.serial = 0;
1326 xev.xclient.display = display;
1327 xev.xclient.send_event = True;
1328 xev.xclient.format = 32;
1329 xev.xclient.data.l[3] = 1;
1331 for (i = 0; i < NB_NET_WM_STATES; i++)
1333 if (!((data->net_wm_state ^ new_state) & (1 << i))) continue; /* unchanged */
1335 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1336 i, data->hwnd, data->whole_window,
1337 (new_state & (1 << i)) != 0, (data->net_wm_state & (1 << i)) != 0 );
1339 xev.xclient.data.l[0] = (new_state & (1 << i)) ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1340 xev.xclient.data.l[1] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM];
1341 xev.xclient.data.l[2] = ((state_atoms[i] == XATOM__NET_WM_STATE_MAXIMIZED_VERT) ?
1342 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ) : 0);
1343 XSendEvent( display, root_window, False,
1344 SubstructureRedirectMask | SubstructureNotifyMask, &xev );
1347 data->net_wm_state = new_state;
1351 /***********************************************************************
1354 static void set_xembed_flags( Display *display, struct x11drv_win_data *data, unsigned long flags )
1356 unsigned long info[2];
1358 if (!data->whole_window) return;
1360 info[0] = 0; /* protocol version */
1362 XChangeProperty( display, data->whole_window, x11drv_atom(_XEMBED_INFO),
1363 x11drv_atom(_XEMBED_INFO), 32, PropModeReplace, (unsigned char*)info, 2 );
1367 /***********************************************************************
1370 static void map_window( Display *display, struct x11drv_win_data *data, DWORD new_style )
1372 TRACE( "win %p/%lx\n", data->hwnd, data->whole_window );
1374 remove_startup_notification( display, data->whole_window );
1376 wait_for_withdrawn_state( display, data, TRUE );
1378 if (!data->embedded)
1380 update_net_wm_states( display, data );
1381 sync_window_style( display, data );
1382 XMapWindow( display, data->whole_window );
1384 else set_xembed_flags( display, data, XEMBED_MAPPED );
1386 data->mapped = TRUE;
1387 data->iconic = (new_style & WS_MINIMIZE) != 0;
1391 /***********************************************************************
1394 static void unmap_window( Display *display, struct x11drv_win_data *data )
1396 TRACE( "win %p/%lx\n", data->hwnd, data->whole_window );
1398 if (!data->embedded)
1400 wait_for_withdrawn_state( display, data, FALSE );
1401 if (data->managed) XWithdrawWindow( display, data->whole_window, DefaultScreen(display) );
1402 else XUnmapWindow( display, data->whole_window );
1404 else set_xembed_flags( display, data, 0 );
1406 data->mapped = FALSE;
1407 data->net_wm_state = 0;
1411 /***********************************************************************
1412 * make_window_embedded
1414 void make_window_embedded( Display *display, struct x11drv_win_data *data )
1416 BOOL was_mapped = data->mapped;
1417 /* the window cannot be mapped before being embedded */
1418 if (data->mapped) unmap_window( display, data );
1420 data->embedded = TRUE;
1421 data->managed = TRUE;
1422 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1423 sync_window_style( display, data );
1426 map_window( display, data, 0 );
1428 set_xembed_flags( display, data, 0 );
1432 /***********************************************************************
1433 * X11DRV_window_to_X_rect
1435 * Convert a rect from client to X window coordinates
1437 static void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect )
1441 if (!data->managed) return;
1442 if (IsRectEmpty( rect )) return;
1444 get_x11_rect_offset( data, &rc );
1446 rect->left -= rc.left;
1447 rect->right -= rc.right;
1448 rect->top -= rc.top;
1449 rect->bottom -= rc.bottom;
1450 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1451 if (rect->left >= rect->right) rect->right = rect->left + 1;
1455 /***********************************************************************
1456 * X11DRV_X_to_window_rect
1458 * Opposite of X11DRV_window_to_X_rect
1460 void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect )
1464 if (!data->managed) return;
1465 if (IsRectEmpty( rect )) return;
1467 get_x11_rect_offset( data, &rc );
1469 rect->left += rc.left;
1470 rect->right += rc.right;
1471 rect->top += rc.top;
1472 rect->bottom += rc.bottom;
1473 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1474 if (rect->left >= rect->right) rect->right = rect->left + 1;
1478 /***********************************************************************
1479 * sync_window_position
1481 * Synchronize the X window position with the Windows one
1483 static void sync_window_position( Display *display, struct x11drv_win_data *data,
1484 UINT swp_flags, const RECT *old_window_rect,
1485 const RECT *old_whole_rect, const RECT *old_client_rect )
1487 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
1488 DWORD ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
1489 XWindowChanges changes;
1490 unsigned int mask = 0;
1492 if (data->managed && data->iconic) return;
1494 /* resizing a managed maximized window is not allowed */
1495 if (!(style & WS_MAXIMIZE) || !data->managed)
1497 changes.width = data->whole_rect.right - data->whole_rect.left;
1498 changes.height = data->whole_rect.bottom - data->whole_rect.top;
1499 /* if window rect is empty force size to 1x1 */
1500 if (changes.width <= 0 || changes.height <= 0) changes.width = changes.height = 1;
1501 if (changes.width > 65535) changes.width = 65535;
1502 if (changes.height > 65535) changes.height = 65535;
1503 mask |= CWWidth | CWHeight;
1506 /* only the size is allowed to change for the desktop window */
1507 if (data->whole_window != root_window)
1509 changes.x = data->whole_rect.left - virtual_screen_rect.left;
1510 changes.y = data->whole_rect.top - virtual_screen_rect.top;
1514 if (!(swp_flags & SWP_NOZORDER) || (swp_flags & SWP_SHOWWINDOW))
1516 /* find window that this one must be after */
1517 HWND prev = GetWindow( data->hwnd, GW_HWNDPREV );
1518 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
1519 prev = GetWindow( prev, GW_HWNDPREV );
1520 if (!prev) /* top child */
1522 changes.stack_mode = Above;
1523 mask |= CWStackMode;
1525 /* should use stack_mode Below but most window managers don't get it right */
1526 /* and Above with a sibling doesn't work so well either, so we ignore it */
1529 set_size_hints( display, data, style );
1530 set_mwm_hints( display, data, style, ex_style );
1531 data->configure_serial = NextRequest( display );
1532 XReconfigureWMWindow( display, data->whole_window,
1533 DefaultScreen(display), mask, &changes );
1534 #ifdef HAVE_LIBXSHAPE
1535 if (IsRectEmpty( old_window_rect ) != IsRectEmpty( &data->window_rect ))
1536 sync_window_region( display, data, (HRGN)1 );
1539 int old_x_offset = old_window_rect->left - old_whole_rect->left;
1540 int old_y_offset = old_window_rect->top - old_whole_rect->top;
1541 int new_x_offset = data->window_rect.left - data->whole_rect.left;
1542 int new_y_offset = data->window_rect.top - data->whole_rect.top;
1543 if (old_x_offset != new_x_offset || old_y_offset != new_y_offset)
1544 XShapeOffsetShape( display, data->whole_window, ShapeBounding,
1545 new_x_offset - old_x_offset, new_y_offset - old_y_offset );
1549 TRACE( "win %p/%lx pos %d,%d,%dx%d after %lx changes=%x serial=%lu\n",
1550 data->hwnd, data->whole_window, data->whole_rect.left, data->whole_rect.top,
1551 data->whole_rect.right - data->whole_rect.left,
1552 data->whole_rect.bottom - data->whole_rect.top,
1553 changes.sibling, mask, data->configure_serial );
1557 /***********************************************************************
1558 * sync_client_position
1560 * Synchronize the X client window position with the Windows one
1562 static void sync_client_position( Display *display, struct x11drv_win_data *data,
1563 UINT swp_flags, const RECT *old_client_rect,
1564 const RECT *old_whole_rect )
1567 XWindowChanges changes;
1568 RECT old = *old_client_rect;
1569 RECT new = data->client_rect;
1571 OffsetRect( &old, -old_whole_rect->left, -old_whole_rect->top );
1572 OffsetRect( &new, -data->whole_rect.left, -data->whole_rect.top );
1573 if (!(mask = get_window_changes( &changes, &old, &new ))) return;
1575 if (data->client_window)
1577 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1578 data->client_window, new.left, new.top,
1579 new.right - new.left, new.bottom - new.top, mask );
1580 XConfigureWindow( display, data->client_window, mask, &changes );
1583 if (data->gl_drawable && (mask & (CWWidth|CWHeight))) sync_gl_drawable( data );
1587 /***********************************************************************
1590 * Move the window bits when a window is moved.
1592 static void move_window_bits( struct x11drv_win_data *data, const RECT *old_rect, const RECT *new_rect,
1593 const RECT *old_client_rect )
1595 RECT src_rect = *old_rect;
1596 RECT dst_rect = *new_rect;
1597 HDC hdc_src, hdc_dst;
1602 if (!data->whole_window)
1604 OffsetRect( &dst_rect, -data->window_rect.left, -data->window_rect.top );
1605 parent = GetAncestor( data->hwnd, GA_PARENT );
1606 hdc_src = GetDCEx( parent, 0, DCX_CACHE );
1607 hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE | DCX_WINDOW );
1611 OffsetRect( &dst_rect, -data->client_rect.left, -data->client_rect.top );
1612 /* make src rect relative to the old position of the window */
1613 OffsetRect( &src_rect, -old_client_rect->left, -old_client_rect->top );
1614 if (dst_rect.left == src_rect.left && dst_rect.top == src_rect.top) return;
1615 hdc_src = hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE );
1618 rgn = CreateRectRgnIndirect( &dst_rect );
1619 SelectClipRgn( hdc_dst, rgn );
1620 DeleteObject( rgn );
1621 ExcludeUpdateRgn( hdc_dst, data->hwnd );
1623 code = X11DRV_START_EXPOSURES;
1624 ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1626 TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n",
1627 data->hwnd, data->whole_window, data->client_window,
1628 wine_dbgstr_rect(&src_rect), wine_dbgstr_rect(&dst_rect) );
1629 BitBlt( hdc_dst, dst_rect.left, dst_rect.top,
1630 dst_rect.right - dst_rect.left, dst_rect.bottom - dst_rect.top,
1631 hdc_src, src_rect.left, src_rect.top, SRCCOPY );
1634 code = X11DRV_END_EXPOSURES;
1635 ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, sizeof(rgn), (LPSTR)&rgn );
1637 ReleaseDC( data->hwnd, hdc_dst );
1638 if (hdc_src != hdc_dst) ReleaseDC( parent, hdc_src );
1642 if (!data->whole_window)
1644 /* map region to client rect since we are using DCX_WINDOW */
1645 OffsetRgn( rgn, data->window_rect.left - data->client_rect.left,
1646 data->window_rect.top - data->client_rect.top );
1647 RedrawWindow( data->hwnd, NULL, rgn,
1648 RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ALLCHILDREN );
1650 else RedrawWindow( data->hwnd, NULL, rgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
1651 DeleteObject( rgn );
1656 /**********************************************************************
1657 * create_whole_window
1659 * Create the whole X window for a given window
1661 static Window create_whole_window( Display *display, struct x11drv_win_data *data )
1664 XSetWindowAttributes attr;
1668 DWORD layered_flags;
1671 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1673 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1674 data->managed = TRUE;
1675 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1678 if ((win_rgn = CreateRectRgn( 0, 0, 0, 0 )) &&
1679 GetWindowRgn( data->hwnd, win_rgn ) == ERROR)
1681 DeleteObject( win_rgn );
1684 data->shaped = (win_rgn != 0);
1686 mask = get_window_attributes( display, data, &attr );
1688 data->whole_rect = data->window_rect;
1689 X11DRV_window_to_X_rect( data, &data->whole_rect );
1690 if (!(cx = data->whole_rect.right - data->whole_rect.left)) cx = 1;
1691 else if (cx > 65535) cx = 65535;
1692 if (!(cy = data->whole_rect.bottom - data->whole_rect.top)) cy = 1;
1693 else if (cy > 65535) cy = 65535;
1695 data->whole_window = XCreateWindow( display, root_window,
1696 data->whole_rect.left - virtual_screen_rect.left,
1697 data->whole_rect.top - virtual_screen_rect.top,
1698 cx, cy, 0, screen_depth, InputOutput,
1699 visual, mask, &attr );
1700 if (!data->whole_window) goto done;
1702 if (!create_client_window( display, data, NULL ))
1704 XDestroyWindow( display, data->whole_window );
1705 data->whole_window = 0;
1709 set_initial_wm_hints( display, data );
1710 set_wm_hints( display, data );
1712 XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
1713 SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
1715 /* set the window text */
1716 if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
1717 sync_window_text( display, data->whole_window, text );
1719 /* set the window region */
1720 if (win_rgn || IsRectEmpty( &data->window_rect )) sync_window_region( display, data, win_rgn );
1722 /* set the window opacity */
1723 if (!GetLayeredWindowAttributes( data->hwnd, &key, &alpha, &layered_flags )) layered_flags = 0;
1724 sync_window_opacity( display, data->whole_window, key, alpha, layered_flags );
1726 init_clip_window(); /* make sure the clip window is initialized in this thread */
1728 XFlush( display ); /* make sure the window exists before we start painting to it */
1730 sync_window_cursor( data->whole_window );
1733 if (win_rgn) DeleteObject( win_rgn );
1734 return data->whole_window;
1738 /**********************************************************************
1739 * destroy_whole_window
1741 * Destroy the whole X window for a given window.
1743 static void destroy_whole_window( Display *display, struct x11drv_win_data *data, BOOL already_destroyed )
1745 if (!data->whole_window)
1749 Window xwin = (Window)GetPropA( data->hwnd, foreign_window_prop );
1752 if (!already_destroyed) XSelectInput( display, xwin, 0 );
1753 XDeleteContext( display, xwin, winContext );
1754 RemovePropA( data->hwnd, foreign_window_prop );
1761 TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1762 XDeleteContext( display, data->whole_window, winContext );
1763 XDeleteContext( display, data->client_window, winContext );
1764 if (!already_destroyed) XDestroyWindow( display, data->whole_window );
1765 data->whole_window = data->client_window = 0;
1766 data->wm_state = WithdrawnState;
1767 data->net_wm_state = 0;
1768 data->mapped = FALSE;
1771 XUnsetICFocus( data->xic );
1772 XDestroyIC( data->xic );
1775 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1777 XFree( data->wm_hints );
1778 data->wm_hints = NULL;
1779 RemovePropA( data->hwnd, whole_window_prop );
1780 RemovePropA( data->hwnd, client_window_prop );
1784 /*****************************************************************
1785 * SetWindowText (X11DRV.@)
1787 void CDECL X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
1791 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(gdi_display))
1793 Display *display = thread_init_display();
1794 sync_window_text( display, win, text );
1799 /***********************************************************************
1800 * SetWindowStyle (X11DRV.@)
1802 * Update the X state of a window to reflect a style change
1804 void CDECL X11DRV_SetWindowStyle( HWND hwnd, INT offset, STYLESTRUCT *style )
1806 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1809 if (hwnd == GetDesktopWindow()) return;
1810 changed = style->styleNew ^ style->styleOld;
1812 /* if WS_VISIBLE was set through WM_SETREDRAW, map the window if it's the first time */
1813 if (offset == GWL_STYLE && (changed & WS_VISIBLE) && (style->styleNew & WS_VISIBLE) && !data)
1815 if (!(data = X11DRV_create_win_data( hwnd ))) return;
1817 if (data->whole_window && is_window_rect_mapped( &data->window_rect ))
1819 Display *display = thread_display();
1820 set_wm_hints( display, data );
1821 if (!data->mapped) map_window( display, data, style->styleNew );
1824 if (!data || !data->whole_window) return;
1826 if (offset == GWL_STYLE && (changed & WS_DISABLED))
1827 set_wm_hints( thread_display(), data );
1829 if (offset == GWL_EXSTYLE && (changed & WS_EX_LAYERED)) /* changing WS_EX_LAYERED resets attributes */
1830 sync_window_opacity( thread_display(), data->whole_window, 0, 0, 0 );
1834 /***********************************************************************
1835 * DestroyWindow (X11DRV.@)
1837 void CDECL X11DRV_DestroyWindow( HWND hwnd )
1839 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1840 struct x11drv_win_data *data;
1842 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1846 destroy_glxpixmap(gdi_display, data->gl_drawable);
1847 XFreePixmap(gdi_display, data->pixmap);
1849 else if (data->gl_drawable)
1851 XDestroyWindow(gdi_display, data->gl_drawable);
1854 destroy_whole_window( thread_data->display, data, FALSE );
1855 destroy_icon_window( thread_data->display, data );
1857 if (data->colormap) XFreeColormap( thread_data->display, data->colormap );
1859 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
1860 if (thread_data->last_xic_hwnd == hwnd) thread_data->last_xic_hwnd = 0;
1861 if (data->icon_pixmap) XFreePixmap( gdi_display, data->icon_pixmap );
1862 if (data->icon_mask) XFreePixmap( gdi_display, data->icon_mask );
1863 XDeleteContext( thread_data->display, (XID)hwnd, win_data_context );
1864 HeapFree( GetProcessHeap(), 0, data );
1868 /***********************************************************************
1869 * X11DRV_DestroyNotify
1871 void X11DRV_DestroyNotify( HWND hwnd, XEvent *event )
1873 Display *display = event->xdestroywindow.display;
1874 struct x11drv_win_data *data;
1876 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1877 if (!data->embedded) FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window );
1879 destroy_whole_window( display, data, TRUE );
1880 if (data->embedded) SendMessageW( hwnd, WM_CLOSE, 0, 0 );
1884 static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
1886 struct x11drv_win_data *data;
1888 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
1891 XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
1897 /* initialize the desktop window id in the desktop manager process */
1898 static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd )
1900 struct x11drv_win_data *data;
1902 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1903 data->whole_window = data->client_window = root_window;
1904 data->managed = TRUE;
1905 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1906 SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
1907 SetPropA( data->hwnd, client_window_prop, (HANDLE)root_window );
1908 set_initial_wm_hints( display, data );
1912 /**********************************************************************
1913 * CreateDesktopWindow (X11DRV.@)
1915 BOOL CDECL X11DRV_CreateDesktopWindow( HWND hwnd )
1917 unsigned int width, height;
1919 /* retrieve the real size of the desktop */
1920 SERVER_START_REQ( get_window_rectangles )
1922 req->handle = wine_server_user_handle( hwnd );
1923 req->relative = COORDS_CLIENT;
1924 wine_server_call( req );
1925 width = reply->window.right;
1926 height = reply->window.bottom;
1930 if (!width && !height) /* not initialized yet */
1932 SERVER_START_REQ( set_window_pos )
1934 req->handle = wine_server_user_handle( hwnd );
1936 req->flags = SWP_NOZORDER;
1937 req->window.left = virtual_screen_rect.left;
1938 req->window.top = virtual_screen_rect.top;
1939 req->window.right = virtual_screen_rect.right;
1940 req->window.bottom = virtual_screen_rect.bottom;
1941 req->client = req->window;
1942 wine_server_call( req );
1948 Window win = (Window)GetPropA( hwnd, whole_window_prop );
1949 if (win && win != root_window) X11DRV_init_desktop( win, width, height );
1955 /**********************************************************************
1956 * CreateWindow (X11DRV.@)
1958 BOOL CDECL X11DRV_CreateWindow( HWND hwnd )
1960 if (hwnd == GetDesktopWindow())
1962 struct x11drv_thread_data *data = x11drv_init_thread_data();
1963 XSetWindowAttributes attr;
1965 if (root_window != DefaultRootWindow( gdi_display ))
1967 /* the desktop win data can't be created lazily */
1968 if (!create_desktop_win_data( data->display, hwnd )) return FALSE;
1971 /* create the cursor clipping window */
1972 attr.override_redirect = TRUE;
1973 attr.event_mask = StructureNotifyMask | FocusChangeMask;
1974 data->clip_window = XCreateWindow( data->display, root_window, 0, 0, 1, 1, 0, 0,
1975 InputOnly, visual, CWOverrideRedirect | CWEventMask, &attr );
1976 XFlush( data->display );
1977 SetPropA( hwnd, clip_window_prop, (HANDLE)data->clip_window );
1983 /***********************************************************************
1984 * X11DRV_get_win_data
1986 * Return the X11 data structure associated with a window.
1988 struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1990 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1993 if (!thread_data) return NULL;
1994 if (!hwnd) return NULL;
1995 if (XFindContext( thread_data->display, (XID)hwnd, win_data_context, &data )) data = NULL;
1996 return (struct x11drv_win_data *)data;
2000 /***********************************************************************
2001 * X11DRV_create_win_data
2003 * Create an X11 data window structure for an existing window.
2005 struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd )
2008 struct x11drv_win_data *data;
2011 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
2013 /* don't create win data for HWND_MESSAGE windows */
2014 if (parent != GetDesktopWindow() && !GetAncestor( parent, GA_PARENT )) return NULL;
2016 display = thread_init_display();
2017 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
2019 GetWindowRect( hwnd, &data->window_rect );
2020 MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 );
2021 data->whole_rect = data->window_rect;
2022 GetClientRect( hwnd, &data->client_rect );
2023 MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 );
2025 if (parent == GetDesktopWindow())
2027 if (!create_whole_window( display, data ))
2029 HeapFree( GetProcessHeap(), 0, data );
2032 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
2033 hwnd, data->whole_window, data->client_window, wine_dbgstr_rect( &data->window_rect ),
2034 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
2040 /* window procedure for foreign windows */
2041 static LRESULT WINAPI foreign_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2045 case WM_WINDOWPOSCHANGED:
2046 update_systray_balloon_position();
2048 case WM_PARENTNOTIFY:
2049 if (LOWORD(wparam) == WM_DESTROY)
2051 TRACE( "%p: got parent notify destroy for win %lx\n", hwnd, lparam );
2052 PostMessageW( hwnd, WM_CLOSE, 0, 0 ); /* so that we come back here once the child is gone */
2056 if (GetWindow( hwnd, GW_CHILD )) return 0; /* refuse to die if we still have children */
2059 return DefWindowProcW( hwnd, msg, wparam, lparam );
2063 /***********************************************************************
2064 * create_foreign_window
2066 * Create a foreign window for the specified X window and its ancestors
2068 HWND create_foreign_window( Display *display, Window xwin )
2070 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};
2071 static BOOL class_registered;
2072 struct x11drv_win_data *data;
2074 Window xparent, xroot;
2076 unsigned int nchildren;
2077 XWindowAttributes attr;
2078 DWORD style = WS_CLIPCHILDREN;
2080 if (!class_registered)
2084 memset( &class, 0, sizeof(class) );
2085 class.cbSize = sizeof(class);
2086 class.lpfnWndProc = foreign_window_proc;
2087 class.lpszClassName = classW;
2088 if (!RegisterClassExW( &class ) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
2090 ERR( "Could not register foreign window class\n" );
2093 class_registered = TRUE;
2096 if (XFindContext( display, xwin, winContext, (char **)&hwnd )) hwnd = 0;
2097 if (hwnd) return hwnd; /* already created */
2099 XSelectInput( display, xwin, StructureNotifyMask );
2100 if (!XGetWindowAttributes( display, xwin, &attr ) ||
2101 !XQueryTree( display, xwin, &xroot, &xparent, &xchildren, &nchildren ))
2103 XSelectInput( display, xwin, 0 );
2108 if (xparent == xroot)
2110 parent = GetDesktopWindow();
2112 attr.x += virtual_screen_rect.left;
2113 attr.y += virtual_screen_rect.top;
2117 parent = create_foreign_window( display, xparent );
2121 hwnd = CreateWindowW( classW, NULL, style, attr.x, attr.y, attr.width, attr.height,
2122 parent, 0, 0, NULL );
2124 if (!(data = alloc_win_data( display, hwnd )))
2126 DestroyWindow( hwnd );
2129 SetRect( &data->window_rect, attr.x, attr.y, attr.x + attr.width, attr.y + attr.height );
2130 data->whole_rect = data->client_rect = data->window_rect;
2131 data->whole_window = data->client_window = 0;
2132 data->embedded = TRUE;
2133 data->mapped = TRUE;
2135 SetPropA( hwnd, foreign_window_prop, (HANDLE)xwin );
2136 XSaveContext( display, xwin, winContext, (char *)data->hwnd );
2138 ShowWindow( hwnd, SW_SHOW );
2140 TRACE( "win %lx parent %p style %08x %s -> hwnd %p\n",
2141 xwin, parent, style, wine_dbgstr_rect(&data->window_rect), hwnd );
2147 /***********************************************************************
2148 * X11DRV_get_whole_window
2150 * Return the X window associated with the full area of a window
2152 Window X11DRV_get_whole_window( HWND hwnd )
2154 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2158 if (hwnd == GetDesktopWindow()) return root_window;
2159 return (Window)GetPropA( hwnd, whole_window_prop );
2161 return data->whole_window;
2165 /***********************************************************************
2166 * X11DRV_get_client_window
2168 * Return the X window associated with the client area of a window
2170 static Window X11DRV_get_client_window( HWND hwnd )
2172 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2176 if (hwnd == GetDesktopWindow()) return root_window;
2177 return (Window)GetPropA( hwnd, client_window_prop );
2179 return data->client_window;
2183 /***********************************************************************
2186 * Return the X input context associated with a window
2188 XIC X11DRV_get_ic( HWND hwnd )
2190 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2193 if (!data) return 0;
2195 x11drv_thread_data()->last_xic_hwnd = hwnd;
2196 if (data->xic) return data->xic;
2197 if (!(xim = x11drv_thread_data()->xim)) return 0;
2198 return X11DRV_CreateIC( xim, data );
2202 /***********************************************************************
2203 * X11DRV_GetDC (X11DRV.@)
2205 void CDECL X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect,
2206 const RECT *top_rect, DWORD flags )
2208 struct x11drv_escape_set_drawable escape;
2209 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2212 escape.code = X11DRV_SET_DRAWABLE;
2213 escape.mode = IncludeInferiors;
2214 escape.fbconfig_id = 0;
2215 escape.gl_drawable = 0;
2217 escape.gl_type = DC_GL_NONE;
2219 escape.dc_rect.left = win_rect->left - top_rect->left;
2220 escape.dc_rect.top = win_rect->top - top_rect->top;
2221 escape.dc_rect.right = win_rect->right - top_rect->left;
2222 escape.dc_rect.bottom = win_rect->bottom - top_rect->top;
2226 escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop );
2227 /* GL draws to the client area even for window DCs */
2228 escape.gl_drawable = data ? data->client_window : X11DRV_get_client_window( hwnd );
2229 if (data && IsIconic( hwnd ) && data->icon_window)
2231 escape.drawable = data->icon_window;
2233 else if (flags & DCX_WINDOW)
2234 escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd );
2236 escape.drawable = escape.gl_drawable;
2238 if (escape.gl_drawable) escape.gl_type = DC_GL_WINDOW;
2239 /* special case: when repainting the root window, clip out top-level windows */
2240 if (data && data->whole_window == root_window) escape.mode = ClipByChildren;
2244 /* find the first ancestor that has a drawable */
2245 for (parent = hwnd; parent && parent != top; parent = GetAncestor( parent, GA_PARENT ))
2246 if ((escape.drawable = X11DRV_get_client_window( parent ))) break;
2248 if (escape.drawable)
2250 POINT pt = { 0, 0 };
2251 MapWindowPoints( top, parent, &pt, 1 );
2252 OffsetRect( &escape.dc_rect, pt.x, pt.y );
2254 else escape.drawable = X11DRV_get_client_window( top );
2256 escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop );
2257 escape.gl_drawable = data ? data->gl_drawable : (Drawable)GetPropA( hwnd, gl_drawable_prop );
2258 escape.pixmap = data ? data->pixmap : (Pixmap)GetPropA( hwnd, pixmap_prop );
2259 if (escape.gl_drawable) escape.gl_type = escape.pixmap ? DC_GL_PIXMAP_WIN : DC_GL_CHILD_WIN;
2260 if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren;
2263 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2267 /***********************************************************************
2268 * X11DRV_ReleaseDC (X11DRV.@)
2270 void CDECL X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
2272 struct x11drv_escape_set_drawable escape;
2274 escape.code = X11DRV_SET_DRAWABLE;
2275 escape.drawable = root_window;
2276 escape.mode = IncludeInferiors;
2277 SetRect( &escape.dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left,
2278 virtual_screen_rect.bottom - virtual_screen_rect.top );
2279 OffsetRect( &escape.dc_rect, -virtual_screen_rect.left, -virtual_screen_rect.top );
2280 escape.fbconfig_id = 0;
2281 escape.gl_drawable = 0;
2283 escape.gl_type = DC_GL_NONE;
2284 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2288 /***********************************************************************
2289 * SetCapture (X11DRV.@)
2291 void CDECL X11DRV_SetCapture( HWND hwnd, UINT flags )
2293 struct x11drv_thread_data *thread_data = x11drv_thread_data();
2295 if (!thread_data) return;
2296 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
2300 Window grab_win = X11DRV_get_client_window( GetAncestor( hwnd, GA_ROOT ) );
2302 if (!grab_win) return;
2303 XFlush( gdi_display );
2304 XGrabPointer( thread_data->display, grab_win, False,
2305 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
2306 GrabModeAsync, GrabModeAsync, None, None, CurrentTime );
2307 thread_data->grab_window = grab_win;
2309 else /* release capture */
2311 XFlush( gdi_display );
2312 XUngrabPointer( thread_data->display, CurrentTime );
2313 XFlush( thread_data->display );
2314 thread_data->grab_window = None;
2319 /*****************************************************************
2320 * SetParent (X11DRV.@)
2322 void CDECL X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
2324 Display *display = thread_display();
2325 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2328 if (parent == old_parent) return;
2329 if (data->embedded) return;
2331 if (parent != GetDesktopWindow()) /* a child window */
2333 if (old_parent == GetDesktopWindow())
2335 /* destroy the old X windows */
2336 destroy_whole_window( display, data, FALSE );
2337 destroy_icon_window( display, data );
2340 data->managed = FALSE;
2341 RemovePropA( data->hwnd, managed_prop );
2345 else /* new top level window */
2347 /* FIXME: we ignore errors since we can't really recover anyway */
2348 create_whole_window( display, data );
2353 /*****************************************************************
2354 * SetFocus (X11DRV.@)
2358 void CDECL X11DRV_SetFocus( HWND hwnd )
2360 Display *display = thread_display();
2361 struct x11drv_win_data *data;
2362 XWindowChanges changes;
2365 if (!(hwnd = GetAncestor( hwnd, GA_ROOT ))) return;
2366 if (!(data = X11DRV_get_win_data( hwnd ))) return;
2367 if (data->managed || !data->whole_window) return;
2369 if (EVENT_x11_time_to_win32_time(0))
2370 /* ICCCM says don't use CurrentTime, so try to use last message time if possible */
2371 /* FIXME: this is not entirely correct */
2372 timestamp = GetMessageTime() - EVENT_x11_time_to_win32_time(0);
2374 timestamp = CurrentTime;
2376 /* Set X focus and install colormap */
2377 changes.stack_mode = Above;
2378 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
2379 XSetInputFocus( display, data->whole_window, RevertToParent, timestamp );
2383 /***********************************************************************
2384 * WindowPosChanging (X11DRV.@)
2386 void CDECL X11DRV_WindowPosChanging( HWND hwnd, HWND insert_after, UINT swp_flags,
2387 const RECT *window_rect, const RECT *client_rect, RECT *visible_rect )
2389 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2390 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
2394 /* create the win data if the window is being made visible */
2395 if (!(style & WS_VISIBLE) && !(swp_flags & SWP_SHOWWINDOW)) return;
2396 if (!(data = X11DRV_create_win_data( hwnd ))) return;
2399 /* check if we need to switch the window to managed */
2400 if (!data->managed && data->whole_window && is_window_managed( hwnd, swp_flags, window_rect ))
2402 TRACE( "making win %p/%lx managed\n", hwnd, data->whole_window );
2403 if (data->mapped) unmap_window( thread_display(), data );
2404 data->managed = TRUE;
2405 SetPropA( hwnd, managed_prop, (HANDLE)1 );
2408 *visible_rect = *window_rect;
2409 X11DRV_window_to_X_rect( data, visible_rect );
2413 /***********************************************************************
2414 * WindowPosChanged (X11DRV.@)
2416 void CDECL X11DRV_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_flags,
2417 const RECT *rectWindow, const RECT *rectClient,
2418 const RECT *visible_rect, const RECT *valid_rects )
2420 struct x11drv_thread_data *thread_data;
2422 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2423 DWORD new_style = GetWindowLongW( hwnd, GWL_STYLE );
2424 RECT old_window_rect, old_whole_rect, old_client_rect;
2429 thread_data = x11drv_thread_data();
2430 display = thread_data->display;
2432 old_window_rect = data->window_rect;
2433 old_whole_rect = data->whole_rect;
2434 old_client_rect = data->client_rect;
2435 data->window_rect = *rectWindow;
2436 data->whole_rect = *visible_rect;
2437 data->client_rect = *rectClient;
2439 TRACE( "win %p window %s client %s style %08x flags %08x\n",
2440 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style, swp_flags );
2442 if (!IsRectEmpty( &valid_rects[0] ))
2444 int x_offset = old_whole_rect.left - data->whole_rect.left;
2445 int y_offset = old_whole_rect.top - data->whole_rect.top;
2447 /* if all that happened is that the whole window moved, copy everything */
2448 if (!(swp_flags & SWP_FRAMECHANGED) &&
2449 old_whole_rect.right - data->whole_rect.right == x_offset &&
2450 old_whole_rect.bottom - data->whole_rect.bottom == y_offset &&
2451 old_client_rect.left - data->client_rect.left == x_offset &&
2452 old_client_rect.right - data->client_rect.right == x_offset &&
2453 old_client_rect.top - data->client_rect.top == y_offset &&
2454 old_client_rect.bottom - data->client_rect.bottom == y_offset &&
2455 !memcmp( &valid_rects[0], &data->client_rect, sizeof(RECT) ))
2457 /* if we have an X window the bits will be moved by the X server */
2458 if (!data->whole_window && (x_offset != 0 || y_offset != 0))
2459 move_window_bits( data, &old_whole_rect, &data->whole_rect, &old_client_rect );
2462 move_window_bits( data, &valid_rects[1], &valid_rects[0], &old_client_rect );
2465 XFlush( gdi_display ); /* make sure painting is done before we move the window */
2467 sync_client_position( display, data, swp_flags, &old_client_rect, &old_whole_rect );
2469 if (!data->whole_window) return;
2471 /* check if we are currently processing an event relevant to this window */
2473 if (thread_data->current_event && thread_data->current_event->xany.window == data->whole_window)
2474 event_type = thread_data->current_event->type;
2476 if (event_type != ConfigureNotify && event_type != PropertyNotify &&
2477 event_type != GravityNotify && event_type != ReparentNotify)
2478 event_type = 0; /* ignore other events */
2480 if (data->mapped && event_type != ReparentNotify)
2482 if (((swp_flags & SWP_HIDEWINDOW) && !(new_style & WS_VISIBLE)) ||
2484 !is_window_rect_mapped( rectWindow ) && is_window_rect_mapped( &old_window_rect )))
2486 unmap_window( display, data );
2487 if (is_window_rect_fullscreen( &old_window_rect )) reset_clipping_window();
2491 /* don't change position if we are about to minimize or maximize a managed window */
2493 !(data->managed && (swp_flags & SWP_STATECHANGED) && (new_style & (WS_MINIMIZE|WS_MAXIMIZE))))
2494 sync_window_position( display, data, swp_flags,
2495 &old_window_rect, &old_whole_rect, &old_client_rect );
2497 if ((new_style & WS_VISIBLE) &&
2498 ((new_style & WS_MINIMIZE) || is_window_rect_mapped( rectWindow )))
2500 if (!data->mapped || (swp_flags & (SWP_FRAMECHANGED|SWP_STATECHANGED)))
2501 set_wm_hints( display, data );
2505 map_window( display, data, new_style );
2507 else if ((swp_flags & SWP_STATECHANGED) && (!data->iconic != !(new_style & WS_MINIMIZE)))
2509 data->iconic = (new_style & WS_MINIMIZE) != 0;
2510 TRACE( "changing win %p iconic state to %u\n", data->hwnd, data->iconic );
2512 XIconifyWindow( display, data->whole_window, DefaultScreen(display) );
2513 else if (is_window_rect_mapped( rectWindow ))
2514 XMapWindow( display, data->whole_window );
2515 update_net_wm_states( display, data );
2517 else if (!event_type)
2519 update_net_wm_states( display, data );
2523 XFlush( display ); /* make sure changes are done before we start painting again */
2527 /***********************************************************************
2528 * ShowWindow (X11DRV.@)
2530 UINT CDECL X11DRV_ShowWindow( HWND hwnd, INT cmd, RECT *rect, UINT swp )
2533 unsigned int width, height, border, depth;
2535 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
2536 struct x11drv_thread_data *thread_data = x11drv_thread_data();
2537 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2539 if (!data || !data->whole_window || !data->managed || !data->mapped || data->iconic) return swp;
2540 if (style & WS_MINIMIZE) return swp;
2541 if (IsRectEmpty( rect )) return swp;
2543 /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */
2545 if (!thread_data->current_event || thread_data->current_event->xany.window != data->whole_window)
2548 if (thread_data->current_event->type != ConfigureNotify &&
2549 thread_data->current_event->type != PropertyNotify)
2552 TRACE( "win %p/%lx cmd %d at %s flags %08x\n",
2553 hwnd, data->whole_window, cmd, wine_dbgstr_rect(rect), swp );
2555 XGetGeometry( thread_data->display, data->whole_window,
2556 &root, &x, &y, &width, &height, &border, &depth );
2557 XTranslateCoordinates( thread_data->display, data->whole_window, root, 0, 0, &x, &y, &top );
2560 rect->right = x + width;
2561 rect->bottom = y + height;
2562 OffsetRect( rect, virtual_screen_rect.left, virtual_screen_rect.top );
2563 X11DRV_X_to_window_rect( data, rect );
2564 return swp & ~(SWP_NOMOVE | SWP_NOCLIENTMOVE | SWP_NOSIZE | SWP_NOCLIENTSIZE);
2568 /**********************************************************************
2569 * SetWindowIcon (X11DRV.@)
2571 * hIcon or hIconSm has changed (or is being initialised for the
2572 * first time). Complete the X11 driver-specific initialisation
2573 * and set the window hints.
2575 * This is not entirely correct, may need to create
2576 * an icon window and set the pixmap as a background
2578 void CDECL X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
2580 Display *display = thread_display();
2581 struct x11drv_win_data *data;
2584 if (!(data = X11DRV_get_win_data( hwnd ))) return;
2585 if (!data->whole_window) return;
2586 if (!data->managed) return;
2590 if (type == ICON_BIG) set_icon_hints( display, data, icon, 0 );
2591 else set_icon_hints( display, data, 0, icon );
2592 XSetWMHints( display, data->whole_window, data->wm_hints );
2597 /***********************************************************************
2598 * SetWindowRgn (X11DRV.@)
2600 * Assign specified region to window (for non-rectangular windows)
2602 int CDECL X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
2604 struct x11drv_win_data *data;
2606 if ((data = X11DRV_get_win_data( hwnd )))
2608 sync_window_region( thread_display(), data, hrgn );
2610 else if (X11DRV_get_whole_window( hwnd ))
2612 SendMessageW( hwnd, WM_X11DRV_SET_WIN_REGION, 0, 0 );
2618 /***********************************************************************
2619 * SetLayeredWindowAttributes (X11DRV.@)
2621 * Set transparency attributes for a layered window.
2623 void CDECL X11DRV_SetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags )
2625 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2629 if (data->whole_window)
2630 sync_window_opacity( thread_display(), data->whole_window, key, alpha, flags );
2634 Window win = X11DRV_get_whole_window( hwnd );
2635 if (win) sync_window_opacity( gdi_display, win, key, alpha, flags );
2640 /**********************************************************************
2641 * X11DRV_WindowMessage (X11DRV.@)
2643 LRESULT CDECL X11DRV_WindowMessage( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
2645 struct x11drv_win_data *data;
2649 case WM_X11DRV_ACQUIRE_SELECTION:
2650 return X11DRV_AcquireClipboard( hwnd );
2651 case WM_X11DRV_SET_WIN_FORMAT:
2652 return set_win_format( hwnd, (XID)wp );
2653 case WM_X11DRV_SET_WIN_REGION:
2654 if ((data = X11DRV_get_win_data( hwnd ))) sync_window_region( thread_display(), data, (HRGN)1 );
2656 case WM_X11DRV_RESIZE_DESKTOP:
2657 X11DRV_resize_desktop( LOWORD(lp), HIWORD(lp) );
2659 case WM_X11DRV_SET_CURSOR:
2660 if ((data = X11DRV_get_win_data( hwnd )) && data->whole_window)
2661 set_window_cursor( data->whole_window, (HCURSOR)lp );
2662 else if (hwnd == x11drv_thread_data()->clip_hwnd)
2663 set_window_cursor( x11drv_thread_data()->clip_window, (HCURSOR)lp );
2665 case WM_X11DRV_CLIP_CURSOR:
2666 return clip_cursor_notify( hwnd, (HWND)lp );
2668 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg, hwnd, wp, lp );
2674 /***********************************************************************
2675 * is_netwm_supported
2677 static BOOL is_netwm_supported( Display *display, Atom atom )
2679 static Atom *net_supported;
2680 static int net_supported_count = -1;
2683 if (net_supported_count == -1)
2687 unsigned long count, remaining;
2689 if (!XGetWindowProperty( display, DefaultRootWindow(display), x11drv_atom(_NET_SUPPORTED), 0,
2690 ~0UL, False, XA_ATOM, &type, &format, &count,
2691 &remaining, (unsigned char **)&net_supported ))
2692 net_supported_count = get_property_size( format, count ) / sizeof(Atom);
2694 net_supported_count = 0;
2697 for (i = 0; i < net_supported_count; i++)
2698 if (net_supported[i] == atom) return TRUE;
2703 /***********************************************************************
2704 * SysCommand (X11DRV.@)
2706 * Perform WM_SYSCOMMAND handling.
2708 LRESULT CDECL X11DRV_SysCommand( HWND hwnd, WPARAM wparam, LPARAM lparam )
2710 WPARAM hittest = wparam & 0x0f;
2712 Display *display = thread_display();
2713 struct x11drv_win_data *data;
2715 if (!(data = X11DRV_get_win_data( hwnd ))) return -1;
2716 if (!data->whole_window || !data->managed || !data->mapped) return -1;
2718 switch (wparam & 0xfff0)
2721 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
2722 else dir = _NET_WM_MOVERESIZE_MOVE;
2725 /* windows without WS_THICKFRAME are not resizable through the window manager */
2726 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) return -1;
2730 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
2731 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
2732 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
2733 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
2734 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
2735 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
2736 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
2737 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
2738 default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break;
2743 /* prevent a simple ALT press+release from activating the system menu,
2744 * as that can get confusing on managed windows */
2745 if ((WCHAR)lparam) return -1; /* got an explicit char */
2746 if (GetMenu( hwnd )) return -1; /* window has a real menu */
2747 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_SYSMENU)) return -1; /* no system menu */
2748 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam, lparam );
2755 if (IsZoomed(hwnd)) return -1;
2757 if (!is_netwm_supported( display, x11drv_atom(_NET_WM_MOVERESIZE) ))
2759 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
2763 move_resize_window( display, data, dir );