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 /* X context to associate a hwnd to an X window */
72 XContext winContext = 0;
74 /* X context to associate a struct x11drv_win_data to an hwnd */
75 static XContext win_data_context;
77 static const char whole_window_prop[] = "__wine_x11_whole_window";
78 static const char client_window_prop[]= "__wine_x11_client_window";
79 static const char icon_window_prop[] = "__wine_x11_icon_window";
80 static const char fbconfig_id_prop[] = "__wine_x11_fbconfig_id";
81 static const char gl_drawable_prop[] = "__wine_x11_gl_drawable";
82 static const char pixmap_prop[] = "__wine_x11_pixmap";
83 static const char managed_prop[] = "__wine_x11_managed";
85 /***********************************************************************
88 * Check if a given window should be managed
90 static BOOL is_window_managed( HWND hwnd, UINT swp_flags, const RECT *window_rect )
92 DWORD style, ex_style;
94 if (!managed_mode) return FALSE;
96 /* child windows are not managed */
97 style = GetWindowLongW( hwnd, GWL_STYLE );
98 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD) return FALSE;
99 /* activated windows are managed */
100 if (!(swp_flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) return TRUE;
101 if (hwnd == GetActiveWindow()) return TRUE;
102 /* windows with caption are managed */
103 if ((style & WS_CAPTION) == WS_CAPTION) return TRUE;
104 /* windows with thick frame are managed */
105 if (style & WS_THICKFRAME) return TRUE;
106 if (style & WS_POPUP)
108 /* popup with sysmenu == caption are managed */
109 if (style & WS_SYSMENU) return TRUE;
110 /* full-screen popup windows are managed */
111 if (window_rect->left <= 0 && window_rect->right >= screen_width &&
112 window_rect->top <= 0 && window_rect->bottom >= screen_height)
115 /* application windows are managed */
116 ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE );
117 if (ex_style & WS_EX_APPWINDOW) return TRUE;
118 /* default: not managed */
123 /***********************************************************************
124 * X11DRV_is_window_rect_mapped
126 * Check if the X whole window should be mapped based on its rectangle
128 static BOOL is_window_rect_mapped( const RECT *rect )
130 /* don't map if rect is empty */
131 if (IsRectEmpty( rect )) return FALSE;
133 /* don't map if rect is off-screen */
134 if (rect->left >= virtual_screen_rect.right ||
135 rect->top >= virtual_screen_rect.bottom ||
136 rect->right <= virtual_screen_rect.left ||
137 rect->bottom <= virtual_screen_rect.top)
144 /***********************************************************************
145 * is_window_resizable
147 * Check if window should be made resizable by the window manager
149 static inline BOOL is_window_resizable( struct x11drv_win_data *data, DWORD style )
151 if (style & WS_THICKFRAME) return TRUE;
152 /* Metacity needs the window to be resizable to make it fullscreen */
153 return (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width &&
154 data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height);
158 /***********************************************************************
161 static HWND get_window_owner( HWND hwnd )
164 HWND owner = GetWindow( hwnd, GW_OWNER );
165 /* ignore the zero-size owners used by Delphi apps */
166 if (owner && GetWindowRect( owner, &rect ) && IsRectEmpty( &rect )) owner = 0;
171 /***********************************************************************
172 * get_mwm_decorations
174 static unsigned long get_mwm_decorations( struct x11drv_win_data *data,
175 DWORD style, DWORD ex_style )
177 unsigned long ret = 0;
179 if (!decorated_mode) return 0;
181 if (IsRectEmpty( &data->window_rect )) return 0;
182 if (data->shaped) return 0;
184 if (ex_style & WS_EX_TOOLWINDOW) return 0;
186 if ((style & WS_CAPTION) == WS_CAPTION)
188 ret |= MWM_DECOR_TITLE | MWM_DECOR_BORDER;
189 if (style & WS_SYSMENU) ret |= MWM_DECOR_MENU;
190 if (style & WS_MINIMIZEBOX) ret |= MWM_DECOR_MINIMIZE;
191 if (style & WS_MAXIMIZEBOX) ret |= MWM_DECOR_MAXIMIZE;
193 if (ex_style & WS_EX_DLGMODALFRAME) ret |= MWM_DECOR_BORDER;
194 else if (style & WS_THICKFRAME) ret |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
195 else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) ret |= MWM_DECOR_BORDER;
200 /***********************************************************************
201 * get_x11_rect_offset
203 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
205 static void get_x11_rect_offset( struct x11drv_win_data *data, RECT *rect )
207 DWORD style, ex_style, style_mask = 0, ex_style_mask = 0;
210 rect->top = rect->bottom = rect->left = rect->right = 0;
212 style = GetWindowLongW( data->hwnd, GWL_STYLE );
213 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
214 decor = get_mwm_decorations( data, style, ex_style );
216 if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION;
217 if (decor & MWM_DECOR_BORDER)
219 style_mask |= WS_DLGFRAME | WS_THICKFRAME;
220 ex_style_mask |= WS_EX_DLGMODALFRAME;
223 AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask );
227 /***********************************************************************
228 * get_window_attributes
230 * Fill the window attributes structure for an X window.
232 static int get_window_attributes( Display *display, struct x11drv_win_data *data,
233 XSetWindowAttributes *attr )
235 attr->override_redirect = !data->managed;
236 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
237 attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0);
238 attr->cursor = x11drv_thread_data()->cursor;
239 attr->bit_gravity = NorthWestGravity;
240 attr->win_gravity = StaticGravity;
241 attr->backing_store = NotUseful;
242 attr->event_mask = (ExposureMask | PointerMotionMask |
243 ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
244 KeyPressMask | KeyReleaseMask | FocusChangeMask | KeymapStateMask);
245 if (data->managed) attr->event_mask |= StructureNotifyMask | PropertyChangeMask;
247 return (CWOverrideRedirect | CWSaveUnder | CWColormap | CWCursor |
248 CWEventMask | CWBitGravity | CWBackingStore);
252 /***********************************************************************
253 * create_client_window
255 static Window create_client_window( Display *display, struct x11drv_win_data *data, XVisualInfo *vis )
258 XSetWindowAttributes attr;
260 Visual *client_visual = vis ? vis->visual : visual;
262 attr.bit_gravity = NorthWestGravity;
263 attr.win_gravity = NorthWestGravity;
264 attr.backing_store = NotUseful;
265 attr.event_mask = (ExposureMask | PointerMotionMask |
266 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
267 mask = CWEventMask | CWBitGravity | CWWinGravity | CWBackingStore;
269 if ((cx = data->client_rect.right - data->client_rect.left) <= 0) cx = 1;
270 if ((cy = data->client_rect.bottom - data->client_rect.top) <= 0) cy = 1;
276 attr.colormap = XCreateColormap( display, root_window, vis->visual,
277 (vis->class == PseudoColor || vis->class == GrayScale ||
278 vis->class == DirectColor) ? AllocAll : AllocNone );
282 client = XCreateWindow( display, data->whole_window,
283 data->client_rect.left - data->whole_rect.left,
284 data->client_rect.top - data->whole_rect.top,
285 cx, cy, 0, screen_depth, InputOutput,
286 client_visual, mask, &attr );
293 if (data->client_window)
295 struct x11drv_thread_data *thread_data = x11drv_thread_data();
296 if (thread_data->cursor_window == data->client_window) thread_data->cursor_window = None;
297 XDeleteContext( display, data->client_window, winContext );
298 XDestroyWindow( display, data->client_window );
300 data->client_window = client;
301 data->visualid = XVisualIDFromVisual( client_visual );
303 if (data->colormap) XFreeColormap( display, data->colormap );
304 data->colormap = vis ? attr.colormap : 0;
306 XMapWindow( display, data->client_window );
307 XSaveContext( display, data->client_window, winContext, (char *)data->hwnd );
310 SetPropA( data->hwnd, client_window_prop, (HANDLE)data->client_window );
311 return data->client_window;
315 /***********************************************************************
318 * Change the X window attributes when the window style has changed.
320 static void sync_window_style( Display *display, struct x11drv_win_data *data )
322 if (data->whole_window != root_window)
324 XSetWindowAttributes attr;
325 int mask = get_window_attributes( display, data, &attr );
328 XChangeWindowAttributes( display, data->whole_window, mask, &attr );
334 /***********************************************************************
337 * Update the X11 window region.
339 static void sync_window_region( Display *display, struct x11drv_win_data *data, HRGN hrgn )
341 #ifdef HAVE_LIBXSHAPE
342 if (!data->whole_window) return;
343 data->shaped = FALSE;
348 XShapeCombineMask( display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet );
353 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
357 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
358 data->window_rect.left - data->whole_rect.left,
359 data->window_rect.top - data->whole_rect.top,
360 (XRectangle *)pRegionData->Buffer,
361 pRegionData->rdh.nCount, ShapeSet, YXBanded );
363 HeapFree(GetProcessHeap(), 0, pRegionData);
367 #endif /* HAVE_LIBXSHAPE */
371 /***********************************************************************
374 static void sync_window_text( Display *display, Window win, const WCHAR *text )
377 char *buffer, *utf8_buffer;
380 /* allocate new buffer for window text */
381 count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
382 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) return;
383 WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
385 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
386 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
388 HeapFree( GetProcessHeap(), 0, buffer );
391 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
394 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
396 XSetWMName( display, win, &prop );
397 XSetWMIconName( display, win, &prop );
401 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
402 according to the standard
403 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
405 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
406 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
409 HeapFree( GetProcessHeap(), 0, utf8_buffer );
410 HeapFree( GetProcessHeap(), 0, buffer );
414 /***********************************************************************
415 * X11DRV_set_win_format
417 BOOL X11DRV_set_win_format( HWND hwnd, XID fbconfig_id )
419 struct x11drv_win_data *data;
423 if (!(data = X11DRV_get_win_data(hwnd)) &&
424 !(data = X11DRV_create_win_data(hwnd))) return FALSE;
426 if (!(vis = visual_from_fbconfig_id(fbconfig_id))) return FALSE;
428 if (data->whole_window)
430 Display *display = thread_display();
431 Window client = data->client_window;
433 if (vis->visualid != data->visualid)
435 client = create_client_window( display, data, vis );
436 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client, data->hwnd, fbconfig_id );
442 if (client) goto done;
446 w = data->client_rect.right - data->client_rect.left;
447 h = data->client_rect.bottom - data->client_rect.top;
452 #ifdef SONAME_LIBXCOMPOSITE
455 XSetWindowAttributes attrib;
456 static Window dummy_parent;
459 attrib.override_redirect = True;
462 dummy_parent = XCreateWindow( gdi_display, root_window, -1, -1, 1, 1, 0, screen_depth,
463 InputOutput, visual, CWOverrideRedirect, &attrib );
464 XMapWindow( gdi_display, dummy_parent );
466 data->colormap = XCreateColormap(gdi_display, dummy_parent, vis->visual,
467 (vis->class == PseudoColor ||
468 vis->class == GrayScale ||
469 vis->class == DirectColor) ?
470 AllocAll : AllocNone);
471 attrib.colormap = data->colormap;
472 XInstallColormap(gdi_display, attrib.colormap);
474 if(data->gl_drawable) XDestroyWindow(gdi_display, data->gl_drawable);
475 data->gl_drawable = XCreateWindow(gdi_display, dummy_parent, -w, 0, w, h, 0,
476 vis->depth, InputOutput, vis->visual,
477 CWColormap | CWOverrideRedirect,
479 if(data->gl_drawable)
481 pXCompositeRedirectWindow(gdi_display, data->gl_drawable,
482 CompositeRedirectManual);
483 XMapWindow(gdi_display, data->gl_drawable);
486 XFlush( gdi_display );
492 WARN("XComposite is not available, using GLXPixmap hack\n");
496 if(data->pixmap) XFreePixmap(gdi_display, data->pixmap);
497 data->pixmap = XCreatePixmap(gdi_display, root_window, w, h, vis->depth);
505 if(data->gl_drawable) destroy_glxpixmap(gdi_display, data->gl_drawable);
506 data->gl_drawable = create_glxpixmap(gdi_display, vis, data->pixmap);
507 if(!data->gl_drawable)
509 XFreePixmap(gdi_display, data->pixmap);
513 XFlush( gdi_display );
515 if (data->pixmap) SetPropA(hwnd, pixmap_prop, (HANDLE)data->pixmap);
518 if (!data->gl_drawable) return FALSE;
520 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
521 data->gl_drawable, fbconfig_id);
522 SetPropA(hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
525 data->fbconfig_id = fbconfig_id;
526 SetPropA(hwnd, fbconfig_id_prop, (HANDLE)data->fbconfig_id);
527 /* force DCE invalidation */
528 SetWindowPos( hwnd, 0, 0, 0, 0, 0,
529 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE |
530 SWP_NOREDRAW | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_STATECHANGED);
534 /***********************************************************************
537 static void sync_gl_drawable(struct x11drv_win_data *data)
539 int w = data->client_rect.right - data->client_rect.left;
540 int h = data->client_rect.bottom - data->client_rect.top;
548 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data->gl_drawable, w, h);
549 #ifdef SONAME_LIBXCOMPOSITE
553 XMoveResizeWindow(gdi_display, data->gl_drawable, -w, 0, w, h);
559 if (!(vis = visual_from_fbconfig_id(data->fbconfig_id))) return;
562 pix = XCreatePixmap(gdi_display, root_window, w, h, vis->depth);
565 ERR("Failed to create pixmap for offscreen rendering\n");
571 glxp = create_glxpixmap(gdi_display, vis, pix);
574 ERR("Failed to create drawable for offscreen rendering\n");
575 XFreePixmap(gdi_display, pix);
583 mark_drawable_dirty(data->gl_drawable, glxp);
585 XFreePixmap(gdi_display, data->pixmap);
586 destroy_glxpixmap(gdi_display, data->gl_drawable);
587 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp, data->gl_drawable );
590 data->gl_drawable = glxp;
592 XFlush( gdi_display );
595 SetPropA(data->hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
596 SetPropA(data->hwnd, pixmap_prop, (HANDLE)data->pixmap);
600 /***********************************************************************
603 * fill the window changes structure
605 static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
609 if (old->right - old->left != new->right - new->left )
611 if ((changes->width = new->right - new->left) <= 0) changes->width = 1;
614 if (old->bottom - old->top != new->bottom - new->top)
616 if ((changes->height = new->bottom - new->top) <= 0) changes->height = 1;
619 if (old->left != new->left)
621 changes->x = new->left;
624 if (old->top != new->top)
626 changes->y = new->top;
633 /***********************************************************************
636 static Window create_icon_window( Display *display, struct x11drv_win_data *data )
638 XSetWindowAttributes attr;
640 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
641 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
642 attr.bit_gravity = NorthWestGravity;
643 attr.backing_store = NotUseful/*WhenMapped*/;
644 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
647 data->icon_window = XCreateWindow( display, root_window, 0, 0,
648 GetSystemMetrics( SM_CXICON ),
649 GetSystemMetrics( SM_CYICON ),
652 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
653 XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd );
654 XFlush( display ); /* make sure the window exists before we start painting to it */
657 TRACE( "created %lx\n", data->icon_window );
658 SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window );
659 return data->icon_window;
664 /***********************************************************************
665 * destroy_icon_window
667 static void destroy_icon_window( Display *display, struct x11drv_win_data *data )
669 if (!data->icon_window) return;
670 if (x11drv_thread_data()->cursor_window == data->icon_window)
671 x11drv_thread_data()->cursor_window = None;
673 XDeleteContext( display, data->icon_window, winContext );
674 XDestroyWindow( display, data->icon_window );
675 data->icon_window = 0;
677 RemovePropA( data->hwnd, icon_window_prop );
681 /***********************************************************************
684 * Set the icon wm hints
686 static void set_icon_hints( Display *display, struct x11drv_win_data *data, HICON hIcon )
688 XWMHints *hints = data->wm_hints;
690 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
691 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
692 data->hWMIconBitmap = 0;
693 data->hWMIconMask = 0;
697 if (!data->icon_window) create_icon_window( display, data );
698 hints->icon_window = data->icon_window;
699 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
709 GetIconInfo(hIcon, &ii);
711 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
714 rcMask.right = bmMask.bmWidth;
715 rcMask.bottom = bmMask.bmHeight;
717 hDC = CreateCompatibleDC(0);
718 hbmOrig = SelectObject(hDC, ii.hbmMask);
719 InvertRect(hDC, &rcMask);
720 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
721 SelectObject(hDC, hbmOrig);
724 data->hWMIconBitmap = ii.hbmColor;
725 data->hWMIconMask = ii.hbmMask;
727 hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap);
728 hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask);
729 destroy_icon_window( display, data );
730 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
735 /***********************************************************************
738 * set the window size hints
740 static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style )
742 XSizeHints* size_hints;
744 if (!(size_hints = XAllocSizeHints())) return;
746 size_hints->win_gravity = StaticGravity;
747 size_hints->flags |= PWinGravity;
749 /* don't update size hints if window is not in normal state */
750 if (!(style & (WS_MINIMIZE | WS_MAXIMIZE)))
752 if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */
754 size_hints->x = data->whole_rect.left;
755 size_hints->y = data->whole_rect.top;
756 size_hints->flags |= PPosition;
759 if (!is_window_resizable( data, style ))
761 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
762 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
763 size_hints->min_width = size_hints->max_width;
764 size_hints->min_height = size_hints->max_height;
765 size_hints->flags |= PMinSize | PMaxSize;
768 XSetWMNormalHints( display, data->whole_window, size_hints );
773 /***********************************************************************
776 * get the name of the current process for setting class hints
778 static char *get_process_name(void)
784 WCHAR module[MAX_PATH];
785 DWORD len = GetModuleFileNameW( 0, module, MAX_PATH );
786 if (len && len < MAX_PATH)
789 WCHAR *p, *appname = module;
791 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
792 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
793 len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL );
794 if ((ptr = HeapAlloc( GetProcessHeap(), 0, len )))
796 WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL );
805 /***********************************************************************
806 * set_initial_wm_hints
808 * Set the window manager hints that don't change over the lifetime of a window.
810 static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data )
815 XClassHint *class_hints;
816 char *process_name = get_process_name();
822 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
823 protocols[i++] = x11drv_atom(_NET_WM_PING);
824 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
825 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
826 XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
829 if ((class_hints = XAllocClassHint()))
831 static char wine[] = "Wine";
833 class_hints->res_name = process_name;
834 class_hints->res_class = wine;
835 XSetClassHint( display, data->whole_window, class_hints );
836 XFree( class_hints );
839 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
840 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
841 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
843 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
844 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
846 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
847 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
849 data->wm_hints = XAllocWMHints();
854 HICON icon = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 );
855 if (!icon) icon = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON );
856 data->wm_hints->flags = 0;
857 set_icon_hints( display, data, icon );
862 /***********************************************************************
865 * Set the window manager hints for a newly-created window
867 static void set_wm_hints( Display *display, struct x11drv_win_data *data )
872 DWORD style, ex_style;
875 if (data->hwnd == GetDesktopWindow())
877 /* force some styles for the desktop to get the correct decorations */
878 style = WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
879 ex_style = WS_EX_APPWINDOW;
884 style = GetWindowLongW( data->hwnd, GWL_STYLE );
885 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
886 owner = get_window_owner( data->hwnd );
889 /* transient for hint */
892 Window owner_win = X11DRV_get_whole_window( owner );
894 XSetTransientForHint( display, data->whole_window, owner_win );
896 group_leader = owner_win;
898 else group_leader = data->whole_window;
903 set_size_hints( display, data, style );
905 /* set the WM_WINDOW_TYPE */
906 if (style & WS_THICKFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
907 else if (ex_style & WS_EX_APPWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
908 else if (style & WS_DLGFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
909 else if (ex_style & WS_EX_DLGMODALFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
910 else if ((style & WS_POPUP) && owner) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
911 #if 0 /* many window managers don't handle utility windows very well */
912 else if (ex_style & WS_EX_TOOLWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
914 else window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
916 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
917 XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1);
919 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
920 mwm_hints.decorations = get_mwm_decorations( data, style, ex_style );
921 mwm_hints.functions = MWM_FUNC_MOVE;
922 if (is_window_resizable( data, style )) mwm_hints.functions |= MWM_FUNC_RESIZE;
923 if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
924 if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
925 if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
927 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
928 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
929 (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
934 data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint;
935 data->wm_hints->input = !(style & WS_DISABLED);
936 data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
937 data->wm_hints->window_group = group_leader;
938 XSetWMHints( display, data->whole_window, data->wm_hints );
945 /***********************************************************************
946 * update_net_wm_states
948 void update_net_wm_states( Display *display, struct x11drv_win_data *data )
950 static const unsigned int state_atoms[NB_NET_WM_STATES] =
952 XATOM__NET_WM_STATE_FULLSCREEN,
953 XATOM__NET_WM_STATE_ABOVE,
954 XATOM__NET_WM_STATE_MAXIMIZED_VERT,
955 XATOM__NET_WM_STATE_SKIP_PAGER,
956 XATOM__NET_WM_STATE_SKIP_TASKBAR
959 DWORD i, style, ex_style, new_state = 0;
961 if (!data->managed) return;
962 if (data->whole_window == root_window) return;
964 style = GetWindowLongW( data->hwnd, GWL_STYLE );
965 if (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width &&
966 data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height)
968 if ((style & WS_MAXIMIZE) && (style & WS_CAPTION) == WS_CAPTION)
969 new_state |= (1 << NET_WM_STATE_MAXIMIZED);
970 else if (!(style & WS_MINIMIZE))
971 new_state |= (1 << NET_WM_STATE_FULLSCREEN);
973 else if (style & WS_MAXIMIZE)
974 new_state |= (1 << NET_WM_STATE_MAXIMIZED);
976 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
977 if (ex_style & WS_EX_TOPMOST)
978 new_state |= (1 << NET_WM_STATE_ABOVE);
979 if (ex_style & WS_EX_TOOLWINDOW)
980 new_state |= (1 << NET_WM_STATE_SKIP_TASKBAR) | (1 << NET_WM_STATE_SKIP_PAGER);
981 if (!(ex_style & WS_EX_APPWINDOW) && get_window_owner( data->hwnd ))
982 new_state |= (1 << NET_WM_STATE_SKIP_TASKBAR);
984 if (!data->mapped) /* set the _NET_WM_STATE atom directly */
986 Atom atoms[NB_NET_WM_STATES+1];
989 for (i = count = 0; i < NB_NET_WM_STATES; i++)
991 if (!(new_state & (1 << i))) continue;
992 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
993 i, data->hwnd, data->whole_window );
994 atoms[count++] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM];
995 if (state_atoms[i] == XATOM__NET_WM_STATE_MAXIMIZED_VERT)
996 atoms[count++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ);
999 XChangeProperty( display, data->whole_window, x11drv_atom(_NET_WM_STATE), XA_ATOM,
1000 32, PropModeReplace, (unsigned char *)atoms, count );
1001 wine_tsx11_unlock();
1003 else /* ask the window manager to do it for us */
1007 xev.xclient.type = ClientMessage;
1008 xev.xclient.window = data->whole_window;
1009 xev.xclient.message_type = x11drv_atom(_NET_WM_STATE);
1010 xev.xclient.serial = 0;
1011 xev.xclient.display = display;
1012 xev.xclient.send_event = True;
1013 xev.xclient.format = 32;
1014 xev.xclient.data.l[3] = 1;
1016 for (i = 0; i < NB_NET_WM_STATES; i++)
1018 if (!((data->net_wm_state ^ new_state) & (1 << i))) continue; /* unchanged */
1020 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1021 i, data->hwnd, data->whole_window,
1022 (new_state & (1 << i)) != 0, (data->net_wm_state & (1 << i)) != 0 );
1024 xev.xclient.data.l[0] = (new_state & (1 << i)) ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1025 xev.xclient.data.l[1] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM];
1026 xev.xclient.data.l[2] = ((state_atoms[i] == XATOM__NET_WM_STATE_MAXIMIZED_VERT) ?
1027 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ) : 0);
1029 XSendEvent( display, root_window, False,
1030 SubstructureRedirectMask | SubstructureNotifyMask, &xev );
1031 wine_tsx11_unlock();
1034 data->net_wm_state = new_state;
1038 /***********************************************************************
1041 static void set_xembed_flags( Display *display, struct x11drv_win_data *data, unsigned long flags )
1043 unsigned long info[2];
1045 info[0] = 0; /* protocol version */
1048 XChangeProperty( display, data->whole_window, x11drv_atom(_XEMBED_INFO),
1049 x11drv_atom(_XEMBED_INFO), 32, PropModeReplace, (unsigned char*)info, 2 );
1050 wine_tsx11_unlock();
1054 /***********************************************************************
1057 static void map_window( Display *display, struct x11drv_win_data *data, DWORD new_style )
1059 TRACE( "win %p/%lx\n", data->hwnd, data->whole_window );
1061 wait_for_withdrawn_state( display, data, TRUE );
1063 if (!data->embedded)
1065 update_net_wm_states( display, data );
1066 sync_window_style( display, data );
1068 XMapWindow( display, data->whole_window );
1069 wine_tsx11_unlock();
1071 else set_xembed_flags( display, data, XEMBED_MAPPED );
1073 data->mapped = TRUE;
1074 data->iconic = (new_style & WS_MINIMIZE) != 0;
1078 /***********************************************************************
1081 static void unmap_window( Display *display, struct x11drv_win_data *data )
1083 TRACE( "win %p/%lx\n", data->hwnd, data->whole_window );
1085 if (!data->embedded)
1087 wait_for_withdrawn_state( display, data, FALSE );
1089 if (data->managed) XWithdrawWindow( display, data->whole_window, DefaultScreen(display) );
1090 else XUnmapWindow( display, data->whole_window );
1091 wine_tsx11_unlock();
1093 else set_xembed_flags( display, data, 0 );
1095 data->mapped = FALSE;
1096 data->net_wm_state = 0;
1100 /***********************************************************************
1101 * make_window_embedded
1103 void make_window_embedded( Display *display, struct x11drv_win_data *data )
1107 /* the window cannot be mapped before being embedded */
1108 unmap_window( display, data );
1109 data->embedded = TRUE;
1110 map_window( display, data, 0 );
1114 data->embedded = TRUE;
1115 set_xembed_flags( display, data, 0 );
1120 /***********************************************************************
1121 * X11DRV_window_to_X_rect
1123 * Convert a rect from client to X window coordinates
1125 void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect )
1129 if (!data->managed) return;
1130 if (IsRectEmpty( rect )) return;
1132 get_x11_rect_offset( data, &rc );
1134 rect->left -= rc.left;
1135 rect->right -= rc.right;
1136 rect->top -= rc.top;
1137 rect->bottom -= rc.bottom;
1138 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1139 if (rect->left >= rect->right) rect->right = rect->left + 1;
1143 /***********************************************************************
1144 * X11DRV_X_to_window_rect
1146 * Opposite of X11DRV_window_to_X_rect
1148 void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect )
1152 if (!data->managed) return;
1153 if (IsRectEmpty( rect )) return;
1155 get_x11_rect_offset( data, &rc );
1157 rect->left += rc.left;
1158 rect->right += rc.right;
1159 rect->top += rc.top;
1160 rect->bottom += rc.bottom;
1161 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1162 if (rect->left >= rect->right) rect->right = rect->left + 1;
1166 /***********************************************************************
1167 * sync_window_position
1169 * Synchronize the X window position with the Windows one
1171 static void sync_window_position( Display *display, struct x11drv_win_data *data,
1172 UINT swp_flags, const RECT *old_client_rect,
1173 const RECT *old_whole_rect )
1175 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
1176 XWindowChanges changes;
1177 unsigned int mask = 0;
1179 if (data->managed && data->iconic) return;
1181 /* resizing a managed maximized window is not allowed */
1182 if (!(style & WS_MAXIMIZE) || !data->managed)
1184 if ((changes.width = data->whole_rect.right - data->whole_rect.left) <= 0) changes.width = 1;
1185 if ((changes.height = data->whole_rect.bottom - data->whole_rect.top) <= 0) changes.height = 1;
1186 mask |= CWWidth | CWHeight;
1189 /* only the size is allowed to change for the desktop window */
1190 if (data->whole_window != root_window)
1192 changes.x = data->whole_rect.left - virtual_screen_rect.left;
1193 changes.y = data->whole_rect.top - virtual_screen_rect.top;
1197 if (!(swp_flags & SWP_NOZORDER))
1199 /* find window that this one must be after */
1200 HWND prev = GetWindow( data->hwnd, GW_HWNDPREV );
1201 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
1202 prev = GetWindow( prev, GW_HWNDPREV );
1203 if (!prev) /* top child */
1205 changes.stack_mode = Above;
1206 mask |= CWStackMode;
1208 /* should use stack_mode Below but most window managers don't get it right */
1209 /* and Above with a sibling doesn't work so well either, so we ignore it */
1212 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
1213 data->hwnd, data->whole_window, data->whole_rect.left, data->whole_rect.top,
1214 data->whole_rect.right - data->whole_rect.left,
1215 data->whole_rect.bottom - data->whole_rect.top, changes.sibling, mask );
1218 set_size_hints( display, data, style );
1219 XReconfigureWMWindow( display, data->whole_window,
1220 DefaultScreen(display), mask, &changes );
1221 wine_tsx11_unlock();
1225 /***********************************************************************
1226 * sync_client_position
1228 * Synchronize the X client window position with the Windows one
1230 static void sync_client_position( Display *display, struct x11drv_win_data *data,
1231 UINT swp_flags, const RECT *old_client_rect,
1232 const RECT *old_whole_rect )
1235 XWindowChanges changes;
1236 RECT old = *old_client_rect;
1237 RECT new = data->client_rect;
1239 OffsetRect( &old, -old_whole_rect->left, -old_whole_rect->top );
1240 OffsetRect( &new, -data->whole_rect.left, -data->whole_rect.top );
1241 if (!(mask = get_window_changes( &changes, &old, &new ))) return;
1243 if (data->client_window)
1245 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1246 data->client_window, new.left, new.top,
1247 new.right - new.left, new.bottom - new.top, mask );
1249 XConfigureWindow( display, data->client_window, mask, &changes );
1250 wine_tsx11_unlock();
1253 if (data->gl_drawable && (mask & (CWWidth|CWHeight))) sync_gl_drawable( data );
1257 /***********************************************************************
1260 * Move the window bits when a window is moved.
1262 static void move_window_bits( struct x11drv_win_data *data, const RECT *old_rect, const RECT *new_rect,
1263 const RECT *old_client_rect )
1265 RECT src_rect = *old_rect;
1266 RECT dst_rect = *new_rect;
1267 HDC hdc_src, hdc_dst;
1272 if (!data->whole_window)
1274 OffsetRect( &dst_rect, -data->window_rect.left, -data->window_rect.top );
1275 parent = GetAncestor( data->hwnd, GA_PARENT );
1276 hdc_src = GetDCEx( parent, 0, DCX_CACHE );
1277 hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE | DCX_WINDOW );
1281 OffsetRect( &dst_rect, -data->client_rect.left, -data->client_rect.top );
1282 /* make src rect relative to the old position of the window */
1283 OffsetRect( &src_rect, -old_client_rect->left, -old_client_rect->top );
1284 if (dst_rect.left == src_rect.left && dst_rect.top == src_rect.top) return;
1285 hdc_src = hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE );
1288 code = X11DRV_START_EXPOSURES;
1289 ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1291 TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n",
1292 data->hwnd, data->whole_window, data->client_window,
1293 wine_dbgstr_rect(&src_rect), wine_dbgstr_rect(&dst_rect) );
1294 BitBlt( hdc_dst, dst_rect.left, dst_rect.top,
1295 dst_rect.right - dst_rect.left, dst_rect.bottom - dst_rect.top,
1296 hdc_src, src_rect.left, src_rect.top, SRCCOPY );
1298 code = X11DRV_END_EXPOSURES;
1299 ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, sizeof(rgn), (LPSTR)&rgn );
1301 ReleaseDC( data->hwnd, hdc_dst );
1302 if (hdc_src != hdc_dst) ReleaseDC( parent, hdc_src );
1306 if (!data->whole_window)
1308 /* map region to client rect since we are using DCX_WINDOW */
1309 OffsetRgn( rgn, data->window_rect.left - data->client_rect.left,
1310 data->window_rect.top - data->client_rect.top );
1311 RedrawWindow( data->hwnd, NULL, rgn,
1312 RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ALLCHILDREN );
1314 else RedrawWindow( data->hwnd, NULL, rgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
1315 DeleteObject( rgn );
1320 /**********************************************************************
1321 * create_whole_window
1323 * Create the whole X window for a given window
1325 static Window create_whole_window( Display *display, struct x11drv_win_data *data )
1328 XSetWindowAttributes attr;
1332 if (!(cx = data->window_rect.right - data->window_rect.left)) cx = 1;
1333 if (!(cy = data->window_rect.bottom - data->window_rect.top)) cy = 1;
1335 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1337 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1338 data->managed = TRUE;
1339 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1342 mask = get_window_attributes( display, data, &attr );
1346 data->whole_rect = data->window_rect;
1347 data->whole_window = XCreateWindow( display, root_window,
1348 data->window_rect.left - virtual_screen_rect.left,
1349 data->window_rect.top - virtual_screen_rect.top,
1350 cx, cy, 0, screen_depth, InputOutput,
1351 visual, mask, &attr );
1353 if (data->whole_window) XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
1354 wine_tsx11_unlock();
1356 if (!data->whole_window) return 0;
1358 if (!create_client_window( display, data, NULL ))
1361 XDeleteContext( display, data->whole_window, winContext );
1362 XDestroyWindow( display, data->whole_window );
1363 data->whole_window = 0;
1364 wine_tsx11_unlock();
1368 set_initial_wm_hints( display, data );
1369 set_wm_hints( display, data );
1371 SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
1373 /* set the window text */
1374 if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
1375 sync_window_text( display, data->whole_window, text );
1377 /* set the window region */
1378 if ((hrgn = CreateRectRgn( 0, 0, 0, 0 )))
1380 if (GetWindowRgn( data->hwnd, hrgn ) != ERROR) sync_window_region( display, data, hrgn );
1381 DeleteObject( hrgn );
1384 XFlush( display ); /* make sure the window exists before we start painting to it */
1385 wine_tsx11_unlock();
1386 return data->whole_window;
1390 /**********************************************************************
1391 * destroy_whole_window
1393 * Destroy the whole X window for a given window.
1395 static void destroy_whole_window( Display *display, struct x11drv_win_data *data, BOOL already_destroyed )
1397 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1399 if (!data->whole_window) return;
1401 TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1402 if (thread_data->cursor_window == data->whole_window ||
1403 thread_data->cursor_window == data->client_window)
1404 thread_data->cursor_window = None;
1406 XDeleteContext( display, data->whole_window, winContext );
1407 XDeleteContext( display, data->client_window, winContext );
1408 if (!already_destroyed) XDestroyWindow( display, data->whole_window );
1409 data->whole_window = data->client_window = 0;
1410 data->wm_state = WithdrawnState;
1411 data->net_wm_state = 0;
1412 data->mapped = FALSE;
1415 XUnsetICFocus( data->xic );
1416 XDestroyIC( data->xic );
1419 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1421 XFree( data->wm_hints );
1422 data->wm_hints = NULL;
1423 wine_tsx11_unlock();
1424 RemovePropA( data->hwnd, whole_window_prop );
1425 RemovePropA( data->hwnd, client_window_prop );
1429 /*****************************************************************
1430 * SetWindowText (X11DRV.@)
1432 void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
1434 Display *display = thread_display();
1437 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display))
1438 sync_window_text( display, win, text );
1442 /***********************************************************************
1443 * SetWindowStyle (X11DRV.@)
1445 * Update the X state of a window to reflect a style change
1447 void X11DRV_SetWindowStyle( HWND hwnd, DWORD old_style )
1449 Display *display = thread_display();
1450 struct x11drv_win_data *data;
1451 DWORD new_style, changed;
1453 if (hwnd == GetDesktopWindow()) return;
1454 new_style = GetWindowLongW( hwnd, GWL_STYLE );
1455 changed = new_style ^ old_style;
1457 if ((changed & WS_VISIBLE) && (new_style & WS_VISIBLE))
1459 /* we don't unmap windows, that causes trouble with the window manager */
1460 if (!(data = X11DRV_get_win_data( hwnd )) &&
1461 !(data = X11DRV_create_win_data( hwnd ))) return;
1463 if (data->whole_window && is_window_rect_mapped( &data->window_rect ))
1465 set_wm_hints( display, data );
1466 if (!data->mapped) map_window( display, data, new_style );
1470 if (changed & WS_DISABLED)
1472 data = X11DRV_get_win_data( hwnd );
1473 if (data && data->wm_hints)
1476 data->wm_hints->input = !(new_style & WS_DISABLED);
1477 XSetWMHints( display, data->whole_window, data->wm_hints );
1478 wine_tsx11_unlock();
1484 /***********************************************************************
1485 * DestroyWindow (X11DRV.@)
1487 void X11DRV_DestroyWindow( HWND hwnd )
1489 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1490 struct x11drv_win_data *data;
1492 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1497 destroy_glxpixmap(gdi_display, data->gl_drawable);
1498 XFreePixmap(gdi_display, data->pixmap);
1499 wine_tsx11_unlock();
1501 else if (data->gl_drawable)
1504 XDestroyWindow(gdi_display, data->gl_drawable);
1505 wine_tsx11_unlock();
1508 destroy_whole_window( thread_data->display, data, FALSE );
1509 destroy_icon_window( thread_data->display, data );
1514 XFreeColormap( thread_data->display, data->colormap );
1515 wine_tsx11_unlock();
1518 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
1519 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
1520 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
1522 XDeleteContext( thread_data->display, (XID)hwnd, win_data_context );
1523 wine_tsx11_unlock();
1524 HeapFree( GetProcessHeap(), 0, data );
1528 /***********************************************************************
1529 * X11DRV_DestroyNotify
1531 void X11DRV_DestroyNotify( HWND hwnd, XEvent *event )
1533 Display *display = event->xdestroywindow.display;
1534 struct x11drv_win_data *data;
1536 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1538 FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window );
1539 destroy_whole_window( display, data, TRUE );
1543 static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
1545 struct x11drv_win_data *data;
1547 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
1551 if (!winContext) winContext = XUniqueContext();
1552 if (!win_data_context) win_data_context = XUniqueContext();
1553 XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
1554 wine_tsx11_unlock();
1560 /* initialize the desktop window id in the desktop manager process */
1561 static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd )
1563 struct x11drv_win_data *data;
1565 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1566 data->whole_window = data->client_window = root_window;
1567 data->managed = TRUE;
1568 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1569 SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
1570 SetPropA( data->hwnd, client_window_prop, (HANDLE)root_window );
1571 set_initial_wm_hints( display, data );
1575 /**********************************************************************
1576 * CreateDesktopWindow (X11DRV.@)
1578 BOOL X11DRV_CreateDesktopWindow( HWND hwnd )
1580 unsigned int width, height;
1582 /* retrieve the real size of the desktop */
1583 SERVER_START_REQ( get_window_rectangles )
1586 wine_server_call( req );
1587 width = reply->window.right - reply->window.left;
1588 height = reply->window.bottom - reply->window.top;
1592 if (!width && !height) /* not initialized yet */
1594 SERVER_START_REQ( set_window_pos )
1598 req->flags = SWP_NOZORDER;
1599 req->window.left = virtual_screen_rect.left;
1600 req->window.top = virtual_screen_rect.top;
1601 req->window.right = virtual_screen_rect.right;
1602 req->window.bottom = virtual_screen_rect.bottom;
1603 req->client = req->window;
1604 wine_server_call( req );
1610 Window win = (Window)GetPropA( hwnd, whole_window_prop );
1611 if (win && win != root_window) X11DRV_init_desktop( win, width, height );
1617 /**********************************************************************
1618 * CreateWindow (X11DRV.@)
1620 BOOL X11DRV_CreateWindow( HWND hwnd )
1622 Display *display = thread_display();
1624 if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( display ))
1626 /* the desktop win data can't be created lazily */
1627 if (!create_desktop_win_data( display, hwnd )) return FALSE;
1633 /***********************************************************************
1634 * X11DRV_get_win_data
1636 * Return the X11 data structure associated with a window.
1638 struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1640 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1643 if (!thread_data) return NULL;
1644 if (!hwnd) return NULL;
1645 if (XFindContext( thread_data->display, (XID)hwnd, win_data_context, &data )) data = NULL;
1646 return (struct x11drv_win_data *)data;
1650 /***********************************************************************
1651 * X11DRV_create_win_data
1653 * Create an X11 data window structure for an existing window.
1655 struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd )
1657 Display *display = thread_display();
1658 struct x11drv_win_data *data;
1661 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
1662 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1664 GetWindowRect( hwnd, &data->window_rect );
1665 MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 );
1666 data->whole_rect = data->window_rect;
1667 GetClientRect( hwnd, &data->client_rect );
1668 MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 );
1670 if (parent == GetDesktopWindow())
1672 if (!create_whole_window( display, data ))
1674 HeapFree( GetProcessHeap(), 0, data );
1677 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1678 hwnd, data->whole_window, data->client_window, wine_dbgstr_rect( &data->window_rect ),
1679 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
1685 /***********************************************************************
1686 * X11DRV_get_whole_window
1688 * Return the X window associated with the full area of a window
1690 Window X11DRV_get_whole_window( HWND hwnd )
1692 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1696 if (hwnd == GetDesktopWindow()) return root_window;
1697 return (Window)GetPropA( hwnd, whole_window_prop );
1699 return data->whole_window;
1703 /***********************************************************************
1704 * X11DRV_get_client_window
1706 * Return the X window associated with the client area of a window
1708 Window X11DRV_get_client_window( HWND hwnd )
1710 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1714 if (hwnd == GetDesktopWindow()) return root_window;
1715 return (Window)GetPropA( hwnd, client_window_prop );
1717 return data->client_window;
1721 /***********************************************************************
1724 * Return the X input context associated with a window
1726 XIC X11DRV_get_ic( HWND hwnd )
1728 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1731 if (!data) return 0;
1732 if (data->xic) return data->xic;
1733 if (!(xim = x11drv_thread_data()->xim)) return 0;
1734 return X11DRV_CreateIC( xim, data );
1738 /***********************************************************************
1739 * X11DRV_GetDC (X11DRV.@)
1741 void X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect,
1742 const RECT *top_rect, DWORD flags )
1744 struct x11drv_escape_set_drawable escape;
1745 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1747 escape.code = X11DRV_SET_DRAWABLE;
1748 escape.mode = IncludeInferiors;
1749 escape.fbconfig_id = 0;
1750 escape.gl_drawable = 0;
1752 escape.gl_copy = FALSE;
1754 if (top == hwnd && data && IsIconic( hwnd ) && data->icon_window)
1756 escape.drawable = data->icon_window;
1758 else if (top == hwnd)
1760 escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop );
1761 /* GL draws to the client area even for window DCs */
1762 escape.gl_drawable = data ? data->client_window : X11DRV_get_client_window( hwnd );
1763 if (flags & DCX_WINDOW)
1764 escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd );
1766 escape.drawable = escape.gl_drawable;
1770 escape.drawable = X11DRV_get_client_window( top );
1771 escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop );
1772 escape.gl_drawable = data ? data->gl_drawable : (Drawable)GetPropA( hwnd, gl_drawable_prop );
1773 escape.pixmap = data ? data->pixmap : (Pixmap)GetPropA( hwnd, pixmap_prop );
1774 escape.gl_copy = (escape.gl_drawable != 0);
1775 if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren;
1778 escape.dc_rect.left = win_rect->left - top_rect->left;
1779 escape.dc_rect.top = win_rect->top - top_rect->top;
1780 escape.dc_rect.right = win_rect->right - top_rect->left;
1781 escape.dc_rect.bottom = win_rect->bottom - top_rect->top;
1782 escape.drawable_rect.left = top_rect->left;
1783 escape.drawable_rect.top = top_rect->top;
1784 escape.drawable_rect.right = top_rect->right;
1785 escape.drawable_rect.bottom = top_rect->bottom;
1787 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1791 /***********************************************************************
1792 * X11DRV_ReleaseDC (X11DRV.@)
1794 void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
1796 struct x11drv_escape_set_drawable escape;
1798 escape.code = X11DRV_SET_DRAWABLE;
1799 escape.drawable = root_window;
1800 escape.mode = IncludeInferiors;
1801 escape.drawable_rect = virtual_screen_rect;
1802 SetRect( &escape.dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left,
1803 virtual_screen_rect.bottom - virtual_screen_rect.top );
1804 escape.fbconfig_id = 0;
1805 escape.gl_drawable = 0;
1807 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1811 /***********************************************************************
1812 * SetCapture (X11DRV.@)
1814 void X11DRV_SetCapture( HWND hwnd, UINT flags )
1816 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1818 if (!thread_data) return;
1819 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
1823 Window grab_win = X11DRV_get_client_window( GetAncestor( hwnd, GA_ROOT ) );
1825 if (!grab_win) return;
1827 XFlush( gdi_display );
1828 XGrabPointer( thread_data->display, grab_win, False,
1829 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1830 GrabModeAsync, GrabModeAsync, None, None, CurrentTime );
1831 wine_tsx11_unlock();
1832 thread_data->grab_window = grab_win;
1834 else /* release capture */
1837 XFlush( gdi_display );
1838 XUngrabPointer( thread_data->display, CurrentTime );
1839 wine_tsx11_unlock();
1840 thread_data->grab_window = None;
1845 /*****************************************************************
1846 * SetParent (X11DRV.@)
1848 void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
1850 Display *display = thread_display();
1851 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1854 if (parent == old_parent) return;
1856 if (parent != GetDesktopWindow()) /* a child window */
1858 if (old_parent == GetDesktopWindow())
1860 /* destroy the old X windows */
1861 destroy_whole_window( display, data, FALSE );
1862 destroy_icon_window( display, data );
1865 data->managed = FALSE;
1866 RemovePropA( data->hwnd, managed_prop );
1870 else /* new top level window */
1872 /* FIXME: we ignore errors since we can't really recover anyway */
1873 create_whole_window( display, data );
1878 /*****************************************************************
1879 * SetFocus (X11DRV.@)
1883 void X11DRV_SetFocus( HWND hwnd )
1885 Display *display = thread_display();
1886 struct x11drv_win_data *data;
1887 XWindowChanges changes;
1889 if (!(hwnd = GetAncestor( hwnd, GA_ROOT ))) return;
1890 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1891 if (data->managed || !data->whole_window) return;
1893 /* Set X focus and install colormap */
1895 changes.stack_mode = Above;
1896 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
1897 if (root_window == DefaultRootWindow(display))
1899 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1900 /* FIXME: this is not entirely correct */
1901 XSetInputFocus( display, data->whole_window, RevertToParent,
1903 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1905 wine_tsx11_unlock();
1909 /***********************************************************************
1910 * SetWindowPos (X11DRV.@)
1912 void X11DRV_SetWindowPos( HWND hwnd, HWND insert_after, UINT swp_flags,
1913 const RECT *rectWindow, const RECT *rectClient,
1914 const RECT *visible_rect, const RECT *valid_rects )
1916 struct x11drv_thread_data *thread_data = x11drv_init_thread_data();
1917 Display *display = thread_data->display;
1918 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1919 DWORD new_style = GetWindowLongW( hwnd, GWL_STYLE );
1920 RECT old_whole_rect, old_client_rect;
1925 /* create the win data if the window is being made visible */
1926 if (!(new_style & WS_VISIBLE)) return;
1927 if (!(data = X11DRV_create_win_data( hwnd ))) return;
1930 /* check if we need to switch the window to managed */
1931 if (!data->managed && data->whole_window && is_window_managed( hwnd, swp_flags, rectWindow ))
1933 TRACE( "making win %p/%lx managed\n", hwnd, data->whole_window );
1934 if (data->mapped) unmap_window( display, data );
1935 data->managed = TRUE;
1936 SetPropA( hwnd, managed_prop, (HANDLE)1 );
1939 old_whole_rect = data->whole_rect;
1940 old_client_rect = data->client_rect;
1941 data->window_rect = *rectWindow;
1942 data->whole_rect = *rectWindow;
1943 data->client_rect = *rectClient;
1944 X11DRV_window_to_X_rect( data, &data->whole_rect );
1945 if (memcmp( visible_rect, &data->whole_rect, sizeof(RECT) ))
1947 TRACE( "%p: need to update visible rect %s -> %s\n", hwnd,
1948 wine_dbgstr_rect(visible_rect), wine_dbgstr_rect(&data->whole_rect) );
1949 SERVER_START_REQ( set_window_visible_rect )
1952 req->flags = swp_flags;
1953 req->visible.left = data->whole_rect.left;
1954 req->visible.top = data->whole_rect.top;
1955 req->visible.right = data->whole_rect.right;
1956 req->visible.bottom = data->whole_rect.bottom;
1957 wine_server_call( req );
1962 TRACE( "win %p window %s client %s style %08x flags %08x\n",
1963 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style, swp_flags );
1965 if (!IsRectEmpty( &valid_rects[0] ))
1967 int x_offset = old_whole_rect.left - data->whole_rect.left;
1968 int y_offset = old_whole_rect.top - data->whole_rect.top;
1970 /* if all that happened is that the whole window moved, copy everything */
1971 if (!(swp_flags & SWP_FRAMECHANGED) &&
1972 old_whole_rect.right - data->whole_rect.right == x_offset &&
1973 old_whole_rect.bottom - data->whole_rect.bottom == y_offset &&
1974 old_client_rect.left - data->client_rect.left == x_offset &&
1975 old_client_rect.right - data->client_rect.right == x_offset &&
1976 old_client_rect.top - data->client_rect.top == y_offset &&
1977 old_client_rect.bottom - data->client_rect.bottom == y_offset &&
1978 !memcmp( &valid_rects[0], &data->client_rect, sizeof(RECT) ))
1980 /* if we have an X window the bits will be moved by the X server */
1981 if (!data->whole_window)
1982 move_window_bits( data, &old_whole_rect, &data->whole_rect, &old_client_rect );
1985 move_window_bits( data, &valid_rects[1], &valid_rects[0], &old_client_rect );
1989 XFlush( gdi_display ); /* make sure painting is done before we move the window */
1990 wine_tsx11_unlock();
1992 sync_client_position( display, data, swp_flags, &old_client_rect, &old_whole_rect );
1994 if (!data->whole_window) return;
1996 /* check if we are currently processing an event relevant to this window */
1998 if (thread_data->current_event && thread_data->current_event->xany.window == data->whole_window)
1999 event_type = thread_data->current_event->type;
2001 if (event_type != ConfigureNotify && event_type != PropertyNotify)
2002 event_type = 0; /* ignore other events */
2006 if (((swp_flags & SWP_HIDEWINDOW) && !(new_style & WS_VISIBLE)) ||
2007 (!event_type && !is_window_rect_mapped( rectWindow )))
2008 unmap_window( display, data );
2011 /* don't change position if we are about to minimize or maximize a managed window */
2013 !(data->managed && (swp_flags & SWP_STATECHANGED) && (new_style & (WS_MINIMIZE|WS_MAXIMIZE))))
2014 sync_window_position( display, data, swp_flags, &old_client_rect, &old_whole_rect );
2016 if ((new_style & WS_VISIBLE) &&
2017 ((new_style & WS_MINIMIZE) || is_window_rect_mapped( rectWindow )))
2019 if (!data->mapped || (swp_flags & (SWP_FRAMECHANGED|SWP_STATECHANGED)))
2020 set_wm_hints( display, data );
2024 map_window( display, data, new_style );
2026 else if ((swp_flags & SWP_STATECHANGED) && (!data->iconic != !(new_style & WS_MINIMIZE)))
2028 data->iconic = (new_style & WS_MINIMIZE) != 0;
2029 TRACE( "changing win %p iconic state to %u\n", data->hwnd, data->iconic );
2032 XIconifyWindow( display, data->whole_window, DefaultScreen(display) );
2033 else if (is_window_rect_mapped( rectWindow ))
2034 XMapWindow( display, data->whole_window );
2035 wine_tsx11_unlock();
2036 update_net_wm_states( display, data );
2038 else if (!event_type)
2040 update_net_wm_states( display, data );
2045 XFlush( display ); /* make sure changes are done before we start painting again */
2046 wine_tsx11_unlock();
2050 /**********************************************************************
2051 * SetWindowIcon (X11DRV.@)
2053 * hIcon or hIconSm has changed (or is being initialised for the
2054 * first time). Complete the X11 driver-specific initialisation
2055 * and set the window hints.
2057 * This is not entirely correct, may need to create
2058 * an icon window and set the pixmap as a background
2060 void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
2062 Display *display = thread_display();
2063 struct x11drv_win_data *data;
2065 if (type != ICON_BIG) return; /* nothing to do here */
2067 if (!(data = X11DRV_get_win_data( hwnd ))) return;
2068 if (!data->whole_window) return;
2069 if (!data->managed) return;
2073 set_icon_hints( display, data, icon );
2075 XSetWMHints( display, data->whole_window, data->wm_hints );
2076 wine_tsx11_unlock();
2081 /***********************************************************************
2082 * SetWindowRgn (X11DRV.@)
2084 * Assign specified region to window (for non-rectangular windows)
2086 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
2088 struct x11drv_win_data *data;
2090 if ((data = X11DRV_get_win_data( hwnd )))
2092 sync_window_region( thread_display(), data, hrgn );
2094 else if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
2096 FIXME( "not supported on other thread window %p\n", hwnd );
2097 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2105 /***********************************************************************
2106 * is_netwm_supported
2108 static BOOL is_netwm_supported( Display *display, Atom atom )
2110 static Atom *net_supported;
2111 static int net_supported_count = -1;
2115 if (net_supported_count == -1)
2119 unsigned long count, remaining;
2121 if (!XGetWindowProperty( display, DefaultRootWindow(display), x11drv_atom(_NET_SUPPORTED), 0,
2122 ~0UL, False, XA_ATOM, &type, &format, &count,
2123 &remaining, (unsigned char **)&net_supported ))
2124 net_supported_count = get_property_size( format, count ) / sizeof(Atom);
2126 net_supported_count = 0;
2128 wine_tsx11_unlock();
2130 for (i = 0; i < net_supported_count; i++)
2131 if (net_supported[i] == atom) return TRUE;
2136 /***********************************************************************
2137 * SysCommand (X11DRV.@)
2139 * Perform WM_SYSCOMMAND handling.
2141 LRESULT X11DRV_SysCommand( HWND hwnd, WPARAM wparam, LPARAM lparam )
2143 WPARAM hittest = wparam & 0x0f;
2147 Display *display = thread_display();
2148 struct x11drv_win_data *data;
2150 if (!(data = X11DRV_get_win_data( hwnd ))) return -1;
2151 if (!data->whole_window || !data->managed || !data->mapped) return -1;
2153 switch (wparam & 0xfff0)
2156 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
2157 else dir = _NET_WM_MOVERESIZE_MOVE;
2160 /* windows without WS_THICKFRAME are not resizable through the window manager */
2161 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) return -1;
2165 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
2166 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
2167 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
2168 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
2169 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
2170 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
2171 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
2172 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
2173 default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break;
2178 /* prevent a simple ALT press+release from activating the system menu,
2179 * as that can get confusing on managed windows */
2180 if ((WCHAR)lparam) return -1; /* got an explicit char */
2181 if (GetMenu( hwnd )) return -1; /* window has a real menu */
2182 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_SYSMENU)) return -1; /* no system menu */
2183 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam, lparam );
2190 if (IsZoomed(hwnd)) return -1;
2192 if (!is_netwm_supported( display, x11drv_atom(_NET_WM_MOVERESIZE) ))
2194 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
2198 dwPoint = GetMessagePos();
2199 x = (short)LOWORD(dwPoint);
2200 y = (short)HIWORD(dwPoint);
2202 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd, x, y, dir);
2204 xev.xclient.type = ClientMessage;
2205 xev.xclient.window = X11DRV_get_whole_window(hwnd);
2206 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
2207 xev.xclient.serial = 0;
2208 xev.xclient.display = display;
2209 xev.xclient.send_event = True;
2210 xev.xclient.format = 32;
2211 xev.xclient.data.l[0] = x; /* x coord */
2212 xev.xclient.data.l[1] = y; /* y coord */
2213 xev.xclient.data.l[2] = dir; /* direction */
2214 xev.xclient.data.l[3] = 1; /* button */
2215 xev.xclient.data.l[4] = 0; /* unused */
2217 /* need to ungrab the pointer that may have been automatically grabbed
2218 * with a ButtonPress event */
2220 XUngrabPointer( display, CurrentTime );
2221 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
2222 wine_tsx11_unlock();