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 /* X context to associate a hwnd to an X window */
54 XContext winContext = 0;
56 /* X context to associate a struct x11drv_win_data to an hwnd */
57 static XContext win_data_context;
59 static const char whole_window_prop[] = "__wine_x11_whole_window";
60 static const char client_window_prop[]= "__wine_x11_client_window";
61 static const char icon_window_prop[] = "__wine_x11_icon_window";
62 static const char fbconfig_id_prop[] = "__wine_x11_fbconfig_id";
63 static const char gl_drawable_prop[] = "__wine_x11_gl_drawable";
64 static const char pixmap_prop[] = "__wine_x11_pixmap";
65 static const char managed_prop[] = "__wine_x11_managed";
67 /* for XDG systray icons */
68 #define SYSTEM_TRAY_REQUEST_DOCK 0
70 extern int usexcomposite;
72 /***********************************************************************
75 * Check if a given window should be managed
77 BOOL is_window_managed( HWND hwnd, UINT swp_flags, const RECT *window_rect )
79 DWORD style, ex_style;
81 if (!managed_mode) return FALSE;
83 /* child windows are not managed */
84 style = GetWindowLongW( hwnd, GWL_STYLE );
85 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD) return FALSE;
86 /* activated windows are managed */
87 if (!(swp_flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) return TRUE;
88 if (hwnd == GetActiveWindow()) return TRUE;
89 /* windows with caption are managed */
90 if ((style & WS_CAPTION) == WS_CAPTION) return TRUE;
91 /* tool windows are not managed */
92 ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE );
93 if (ex_style & WS_EX_TOOLWINDOW) return FALSE;
94 /* windows with thick frame are managed */
95 if (style & WS_THICKFRAME) return TRUE;
96 /* application windows are managed */
97 if (ex_style & WS_EX_APPWINDOW) return TRUE;
100 /* popup with sysmenu == caption are managed */
101 if (style & WS_SYSMENU) return TRUE;
102 /* full-screen popup windows are managed */
103 if (window_rect->left <= 0 && window_rect->right >= screen_width &&
104 window_rect->top <= 0 && window_rect->bottom >= screen_height)
107 /* default: not managed */
112 /***********************************************************************
113 * X11DRV_is_window_rect_mapped
115 * Check if the X whole window should be mapped based on its rectangle
117 BOOL X11DRV_is_window_rect_mapped( const RECT *rect )
119 /* don't map if rect is empty */
120 if (IsRectEmpty( rect )) return FALSE;
122 /* don't map if rect is off-screen */
123 if (rect->left >= virtual_screen_rect.right ||
124 rect->top >= virtual_screen_rect.bottom ||
125 rect->right <= virtual_screen_rect.left ||
126 rect->bottom <= virtual_screen_rect.top)
133 /***********************************************************************
134 * get_mwm_decorations
136 static unsigned long get_mwm_decorations( DWORD style, DWORD ex_style )
138 unsigned long ret = 0;
140 if (ex_style & WS_EX_TOOLWINDOW) return 0;
142 if ((style & WS_CAPTION) == WS_CAPTION)
144 ret |= MWM_DECOR_TITLE | MWM_DECOR_BORDER;
145 if (style & WS_SYSMENU) ret |= MWM_DECOR_MENU;
146 if (style & WS_MINIMIZEBOX) ret |= MWM_DECOR_MINIMIZE;
147 if (style & WS_MAXIMIZEBOX) ret |= MWM_DECOR_MAXIMIZE;
149 if (ex_style & WS_EX_DLGMODALFRAME) ret |= MWM_DECOR_BORDER;
150 else if (style & WS_THICKFRAME) ret |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
151 else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) ret |= MWM_DECOR_BORDER;
156 /***********************************************************************
157 * get_x11_rect_offset
159 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
161 static void get_x11_rect_offset( struct x11drv_win_data *data, RECT *rect )
163 DWORD style, ex_style, style_mask = 0, ex_style_mask = 0;
166 rect->top = rect->bottom = rect->left = rect->right = 0;
168 style = GetWindowLongW( data->hwnd, GWL_STYLE );
169 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
170 decor = get_mwm_decorations( style, ex_style );
172 if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION;
173 if (decor & MWM_DECOR_BORDER)
175 style_mask |= WS_DLGFRAME | WS_THICKFRAME;
176 ex_style_mask |= WS_EX_DLGMODALFRAME;
179 AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask );
183 /***********************************************************************
184 * get_window_attributes
186 * Fill the window attributes structure for an X window.
188 static int get_window_attributes( Display *display, struct x11drv_win_data *data,
189 XSetWindowAttributes *attr )
191 attr->override_redirect = !data->managed;
192 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
193 attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0);
194 attr->cursor = x11drv_thread_data()->cursor;
195 attr->bit_gravity = NorthWestGravity;
196 attr->backing_store = NotUseful;
197 attr->event_mask = (ExposureMask | PointerMotionMask |
198 ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
199 KeyPressMask | KeyReleaseMask | FocusChangeMask | KeymapStateMask);
200 if (data->managed) attr->event_mask |= StructureNotifyMask | PropertyChangeMask;
202 return (CWOverrideRedirect | CWSaveUnder | CWColormap | CWCursor |
203 CWEventMask | CWBitGravity | CWBackingStore);
207 /***********************************************************************
208 * create_client_window
210 static Window create_client_window( Display *display, struct x11drv_win_data *data, XVisualInfo *vis )
213 XSetWindowAttributes attr;
216 attr.bit_gravity = NorthWestGravity;
217 attr.win_gravity = NorthWestGravity;
218 attr.backing_store = NotUseful;
219 attr.event_mask = (ExposureMask | PointerMotionMask |
220 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
221 mask = CWEventMask | CWBitGravity | CWWinGravity | CWBackingStore;
223 if ((cx = data->client_rect.right - data->client_rect.left) <= 0) cx = 1;
224 if ((cy = data->client_rect.bottom - data->client_rect.top) <= 0) cy = 1;
230 attr.colormap = XCreateColormap( display, root_window, vis->visual,
231 (vis->class == PseudoColor || vis->class == GrayScale ||
232 vis->class == DirectColor) ? AllocAll : AllocNone );
236 client = XCreateWindow( display, data->whole_window,
237 data->client_rect.left - data->whole_rect.left,
238 data->client_rect.top - data->whole_rect.top,
239 cx, cy, 0, screen_depth, InputOutput,
240 vis ? vis->visual : visual, mask, &attr );
247 if (data->client_window)
249 struct x11drv_thread_data *thread_data = x11drv_thread_data();
250 if (thread_data->cursor_window == data->client_window) thread_data->cursor_window = None;
251 XDeleteContext( display, data->client_window, winContext );
252 XDestroyWindow( display, data->client_window );
254 data->client_window = client;
256 if (data->colormap) XFreeColormap( display, data->colormap );
257 data->colormap = vis ? attr.colormap : 0;
259 XMapWindow( display, data->client_window );
260 XSaveContext( display, data->client_window, winContext, (char *)data->hwnd );
263 SetPropA( data->hwnd, client_window_prop, (HANDLE)data->client_window );
264 return data->client_window;
268 /***********************************************************************
269 * X11DRV_sync_window_style
271 * Change the X window attributes when the window style has changed.
273 void X11DRV_sync_window_style( Display *display, struct x11drv_win_data *data )
275 if (data->whole_window != root_window)
277 XSetWindowAttributes attr;
278 int mask = get_window_attributes( display, data, &attr );
281 XChangeWindowAttributes( display, data->whole_window, mask, &attr );
287 /***********************************************************************
290 * Update the X11 window region.
292 static void sync_window_region( Display *display, struct x11drv_win_data *data, HRGN hrgn )
294 #ifdef HAVE_LIBXSHAPE
295 if (!data->whole_window) return;
300 XShapeCombineMask( display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet );
305 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
309 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
310 data->window_rect.left - data->whole_rect.left,
311 data->window_rect.top - data->whole_rect.top,
312 (XRectangle *)pRegionData->Buffer,
313 pRegionData->rdh.nCount, ShapeSet, YXBanded );
315 HeapFree(GetProcessHeap(), 0, pRegionData);
318 #endif /* HAVE_LIBXSHAPE */
322 /***********************************************************************
325 static void sync_window_text( Display *display, Window win, const WCHAR *text )
328 char *buffer, *utf8_buffer;
331 /* allocate new buffer for window text */
332 count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
333 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) return;
334 WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
336 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
337 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
339 HeapFree( GetProcessHeap(), 0, buffer );
342 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
345 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
347 XSetWMName( display, win, &prop );
348 XSetWMIconName( display, win, &prop );
352 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
353 according to the standard
354 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
356 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
357 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
360 HeapFree( GetProcessHeap(), 0, utf8_buffer );
361 HeapFree( GetProcessHeap(), 0, buffer );
365 /***********************************************************************
366 * X11DRV_set_win_format
368 BOOL X11DRV_set_win_format( HWND hwnd, XID fbconfig_id )
370 Display *display = thread_display();
371 struct x11drv_win_data *data;
375 if (!(data = X11DRV_get_win_data(hwnd)) &&
376 !(data = X11DRV_create_win_data(hwnd))) return FALSE;
378 if (data->fbconfig_id) return FALSE; /* can't change it twice */
381 vis = visual_from_fbconfig_id(fbconfig_id);
383 if (!vis) return FALSE;
385 if (data->whole_window)
387 Window client = data->client_window;
389 if (vis->visualid != XVisualIDFromVisual(visual))
391 client = create_client_window( display, data, vis );
392 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client, data->hwnd, fbconfig_id );
397 if (client) goto done;
401 w = data->client_rect.right - data->client_rect.left;
402 h = data->client_rect.bottom - data->client_rect.top;
407 #ifdef SONAME_LIBXCOMPOSITE
410 XSetWindowAttributes attrib;
411 Window parent = X11DRV_get_whole_window( GetAncestor( hwnd, GA_ROOT ));
413 if (!parent) parent = root_window;
415 data->colormap = XCreateColormap(display, parent, vis->visual,
416 (vis->class == PseudoColor ||
417 vis->class == GrayScale ||
418 vis->class == DirectColor) ?
419 AllocAll : AllocNone);
420 attrib.override_redirect = True;
421 attrib.colormap = data->colormap;
422 XInstallColormap(gdi_display, attrib.colormap);
424 data->gl_drawable = XCreateWindow(display, parent, -w, 0, w, h, 0,
425 vis->depth, InputOutput, vis->visual,
426 CWColormap | CWOverrideRedirect,
428 if(data->gl_drawable)
430 pXCompositeRedirectWindow(display, data->gl_drawable,
431 CompositeRedirectManual);
432 XMapWindow(display, data->gl_drawable);
440 WARN("XComposite is not available, using GLXPixmap hack\n");
443 data->pixmap = XCreatePixmap(display, root_window, w, h, vis->depth);
451 data->gl_drawable = create_glxpixmap(display, vis, data->pixmap);
452 if(!data->gl_drawable)
454 XFreePixmap(display, data->pixmap);
459 if (data->pixmap) SetPropA(hwnd, pixmap_prop, (HANDLE)data->pixmap);
462 if (!data->gl_drawable) return FALSE;
464 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
465 data->gl_drawable, fbconfig_id);
466 SetPropA(hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
469 data->fbconfig_id = fbconfig_id;
470 SetPropA(hwnd, fbconfig_id_prop, (HANDLE)data->fbconfig_id);
474 WIN_invalidate_dce( hwnd, NULL );
478 /***********************************************************************
481 static void sync_gl_drawable(Display *display, struct x11drv_win_data *data)
483 int w = data->client_rect.right - data->client_rect.left;
484 int h = data->client_rect.bottom - data->client_rect.top;
492 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data->gl_drawable, w, h);
493 #ifdef SONAME_LIBXCOMPOSITE
497 XMoveResizeWindow(display, data->gl_drawable, -w, 0, w, h);
505 vis = visual_from_fbconfig_id(data->fbconfig_id);
512 pix = XCreatePixmap(display, root_window, w, h, vis->depth);
515 ERR("Failed to create pixmap for offscreen rendering\n");
521 glxp = create_glxpixmap(display, vis, pix);
524 ERR("Failed to create drawable for offscreen rendering\n");
525 XFreePixmap(display, pix);
533 mark_drawable_dirty(data->gl_drawable, glxp);
535 XFreePixmap(display, data->pixmap);
536 destroy_glxpixmap(display, data->gl_drawable);
539 data->gl_drawable = glxp;
543 SetPropA(data->hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
544 SetPropA(data->hwnd, pixmap_prop, (HANDLE)data->pixmap);
548 /***********************************************************************
551 * fill the window changes structure
553 static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
557 if (old->right - old->left != new->right - new->left )
559 if ((changes->width = new->right - new->left) <= 0) changes->width = 1;
562 if (old->bottom - old->top != new->bottom - new->top)
564 if ((changes->height = new->bottom - new->top) <= 0) changes->height = 1;
567 if (old->left != new->left)
569 changes->x = new->left;
572 if (old->top != new->top)
574 changes->y = new->top;
581 /***********************************************************************
584 static Window create_icon_window( Display *display, struct x11drv_win_data *data )
586 XSetWindowAttributes attr;
588 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
589 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
590 attr.bit_gravity = NorthWestGravity;
591 attr.backing_store = NotUseful/*WhenMapped*/;
592 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
595 data->icon_window = XCreateWindow( display, root_window, 0, 0,
596 GetSystemMetrics( SM_CXICON ),
597 GetSystemMetrics( SM_CYICON ),
600 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
601 XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd );
604 TRACE( "created %lx\n", data->icon_window );
605 SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window );
606 return data->icon_window;
611 /***********************************************************************
612 * destroy_icon_window
614 static void destroy_icon_window( Display *display, struct x11drv_win_data *data )
616 if (!data->icon_window) return;
617 if (x11drv_thread_data()->cursor_window == data->icon_window)
618 x11drv_thread_data()->cursor_window = None;
620 XDeleteContext( display, data->icon_window, winContext );
621 XDestroyWindow( display, data->icon_window );
622 data->icon_window = 0;
624 RemovePropA( data->hwnd, icon_window_prop );
628 /***********************************************************************
631 * Set the icon wm hints
633 static void set_icon_hints( Display *display, struct x11drv_win_data *data, HICON hIcon )
635 XWMHints *hints = data->wm_hints;
637 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
638 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
639 data->hWMIconBitmap = 0;
640 data->hWMIconMask = 0;
644 if (!data->icon_window) create_icon_window( display, data );
645 hints->icon_window = data->icon_window;
646 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
656 GetIconInfo(hIcon, &ii);
658 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
661 rcMask.right = bmMask.bmWidth;
662 rcMask.bottom = bmMask.bmHeight;
664 hDC = CreateCompatibleDC(0);
665 hbmOrig = SelectObject(hDC, ii.hbmMask);
666 InvertRect(hDC, &rcMask);
667 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
668 SelectObject(hDC, hbmOrig);
671 data->hWMIconBitmap = ii.hbmColor;
672 data->hWMIconMask = ii.hbmMask;
674 hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap);
675 hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask);
676 destroy_icon_window( display, data );
677 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
681 /***********************************************************************
682 * wine_make_systray_window (X11DRV.@)
684 * Docks the given X window with the NETWM system tray.
686 void X11DRV_make_systray_window( HWND hwnd )
688 static Atom systray_atom;
689 Display *display = thread_display();
690 struct x11drv_win_data *data;
691 Window systray_window;
693 if (root_window != DefaultRootWindow(display)) return;
695 if (!(data = X11DRV_get_win_data( hwnd )) &&
696 !(data = X11DRV_create_win_data( hwnd ))) return;
701 if (DefaultScreen( display ) == 0)
702 systray_atom = x11drv_atom(_NET_SYSTEM_TRAY_S0);
705 char systray_buffer[29]; /* strlen(_NET_SYSTEM_TRAY_S4294967295)+1 */
706 sprintf( systray_buffer, "_NET_SYSTEM_TRAY_S%u", DefaultScreen( display ) );
707 systray_atom = XInternAtom( display, systray_buffer, False );
710 systray_window = XGetSelectionOwner( display, systray_atom );
713 TRACE("Docking tray icon %p\n", data->hwnd);
715 if (systray_window != None)
718 unsigned long info[2];
720 /* Put the window offscreen so it isn't mapped. The window _cannot_ be
721 * mapped if we intend to dock with an XEMBED tray. If the window is
722 * mapped when we dock, it may become visible as a child of the root
723 * window after it docks, which isn't the proper behavior.
725 * For more information on this problem, see
726 * http://standards.freedesktop.org/xembed-spec/latest/ar01s04.html */
728 SetWindowPos( data->hwnd, NULL, virtual_screen_rect.right + 1, virtual_screen_rect.bottom + 1,
729 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE );
731 /* set XEMBED protocol data on the window */
732 info[0] = 0; /* protocol version */
733 info[1] = 1; /* mapped = true */
736 XChangeProperty( display, data->whole_window,
737 x11drv_atom(_XEMBED_INFO),
738 x11drv_atom(_XEMBED_INFO), 32, PropModeReplace,
739 (unsigned char*)info, 2 );
742 /* send the docking request message */
743 ZeroMemory( &ev, sizeof(ev) );
744 ev.xclient.type = ClientMessage;
745 ev.xclient.window = systray_window;
746 ev.xclient.message_type = x11drv_atom( _NET_SYSTEM_TRAY_OPCODE );
747 ev.xclient.format = 32;
748 ev.xclient.data.l[0] = CurrentTime;
749 ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
750 ev.xclient.data.l[2] = data->whole_window;
751 ev.xclient.data.l[3] = 0;
752 ev.xclient.data.l[4] = 0;
755 XSendEvent( display, systray_window, False, NoEventMask, &ev );
763 /* fall back to he KDE hints if the WM doesn't support XEMBED'ed
767 XChangeProperty( display, data->whole_window,
768 x11drv_atom(KWM_DOCKWINDOW),
769 x11drv_atom(KWM_DOCKWINDOW), 32, PropModeReplace,
770 (unsigned char*)&val, 1 );
771 XChangeProperty( display, data->whole_window,
772 x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR),
773 XA_WINDOW, 32, PropModeReplace,
774 (unsigned char*)&data->whole_window, 1 );
780 /***********************************************************************
783 * set the window size hints
785 static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style )
787 XSizeHints* size_hints;
789 if ((size_hints = XAllocSizeHints()))
791 size_hints->flags = 0;
793 if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */
795 size_hints->win_gravity = StaticGravity;
796 size_hints->x = data->whole_rect.left;
797 size_hints->y = data->whole_rect.top;
798 size_hints->flags |= PWinGravity | PPosition;
801 if ( !(style & WS_THICKFRAME) )
803 /* If we restrict window resizing Metacity decides that it should
804 * disable fullscreen support for this window as well.
806 if (!(data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width &&
807 data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height))
809 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
810 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
811 size_hints->min_width = size_hints->max_width;
812 size_hints->min_height = size_hints->max_height;
813 size_hints->flags |= PMinSize | PMaxSize;
816 XSetWMNormalHints( display, data->whole_window, size_hints );
822 /***********************************************************************
825 * get the name of the current process for setting class hints
827 static char *get_process_name(void)
833 WCHAR module[MAX_PATH];
834 DWORD len = GetModuleFileNameW( 0, module, MAX_PATH );
835 if (len && len < MAX_PATH)
838 WCHAR *p, *appname = module;
840 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
841 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
842 len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL );
843 if ((ptr = HeapAlloc( GetProcessHeap(), 0, len )))
845 WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL );
854 /***********************************************************************
855 * set_initial_wm_hints
857 * Set the window manager hints that don't change over the lifetime of a window.
859 static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data )
864 XClassHint *class_hints;
865 char *process_name = get_process_name();
871 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
872 protocols[i++] = x11drv_atom(_NET_WM_PING);
873 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
874 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
875 XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
878 if ((class_hints = XAllocClassHint()))
880 static char wine[] = "Wine";
882 class_hints->res_name = process_name;
883 class_hints->res_class = wine;
884 XSetClassHint( display, data->whole_window, class_hints );
885 XFree( class_hints );
888 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
889 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
890 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
892 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
893 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
895 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
896 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
898 data->wm_hints = XAllocWMHints();
903 HICON icon = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 );
904 if (!icon) icon = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON );
905 data->wm_hints->flags = 0;
906 set_icon_hints( display, data, icon );
911 /***********************************************************************
912 * X11DRV_set_wm_hints
914 * Set the window manager hints for a newly-created window
916 void X11DRV_set_wm_hints( Display *display, struct x11drv_win_data *data )
921 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
922 DWORD ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
923 HWND owner = GetWindow( data->hwnd, GW_OWNER );
925 if (data->hwnd == GetDesktopWindow())
927 /* force some styles for the desktop to get the correct decorations */
928 style |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
932 /* transient for hint */
935 Window owner_win = X11DRV_get_whole_window( owner );
937 XSetTransientForHint( display, data->whole_window, owner_win );
939 group_leader = owner_win;
941 else group_leader = data->whole_window;
946 set_size_hints( display, data, style );
948 /* set the WM_WINDOW_TYPE */
949 window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
950 if (ex_style & WS_EX_TOOLWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
951 else if (style & WS_THICKFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
952 else if (style & WS_DLGFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
953 else if (ex_style & WS_EX_DLGMODALFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
955 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
956 XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1);
958 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
959 mwm_hints.decorations = get_mwm_decorations( style, ex_style );
960 mwm_hints.functions = MWM_FUNC_MOVE;
961 if (style & WS_THICKFRAME) mwm_hints.functions |= MWM_FUNC_RESIZE;
962 if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
963 if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
964 if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
966 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
967 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
968 (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
973 data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint;
974 data->wm_hints->input = !(style & WS_DISABLED);
975 data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
976 data->wm_hints->window_group = group_leader;
977 XSetWMHints( display, data->whole_window, data->wm_hints );
984 /***********************************************************************
985 * X11DRV_window_to_X_rect
987 * Convert a rect from client to X window coordinates
989 void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect )
993 if (!data->managed) return;
994 if (IsRectEmpty( rect )) return;
996 get_x11_rect_offset( data, &rc );
998 rect->left -= rc.left;
999 rect->right -= rc.right;
1000 rect->top -= rc.top;
1001 rect->bottom -= rc.bottom;
1002 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1003 if (rect->left >= rect->right) rect->right = rect->left + 1;
1007 /***********************************************************************
1008 * X11DRV_X_to_window_rect
1010 * Opposite of X11DRV_window_to_X_rect
1012 void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect )
1016 if (!data->managed) return;
1017 if (IsRectEmpty( rect )) return;
1019 get_x11_rect_offset( data, &rc );
1021 rect->left += rc.left;
1022 rect->right += rc.right;
1023 rect->top += rc.top;
1024 rect->bottom += rc.bottom;
1025 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1026 if (rect->left >= rect->right) rect->right = rect->left + 1;
1030 /***********************************************************************
1031 * X11DRV_sync_window_position
1033 * Synchronize the X window position with the Windows one
1035 void X11DRV_sync_window_position( Display *display, struct x11drv_win_data *data,
1036 UINT swp_flags, const RECT *old_client_rect,
1037 const RECT *old_whole_rect )
1039 XWindowChanges changes;
1040 int mask = get_window_changes( &changes, old_whole_rect, &data->whole_rect );
1042 if (!(swp_flags & SWP_NOZORDER))
1044 /* find window that this one must be after */
1045 HWND prev = GetWindow( data->hwnd, GW_HWNDPREV );
1046 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
1047 prev = GetWindow( prev, GW_HWNDPREV );
1048 if (!prev) /* top child */
1050 changes.stack_mode = Above;
1051 mask |= CWStackMode;
1053 /* should use stack_mode Below but most window managers don't get it right */
1054 /* and Above with a sibling doesn't work so well either, so we ignore it */
1057 /* only the size is allowed to change for the desktop window */
1058 if (data->whole_window == root_window) mask &= CWWidth | CWHeight;
1062 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
1064 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
1065 data->hwnd, data->whole_window, data->whole_rect.left, data->whole_rect.top,
1066 data->whole_rect.right - data->whole_rect.left,
1067 data->whole_rect.bottom - data->whole_rect.top, changes.sibling, mask );
1070 if (mask & (CWWidth|CWHeight)) set_size_hints( display, data, style );
1071 if (mask & CWX) changes.x -= virtual_screen_rect.left;
1072 if (mask & CWY) changes.y -= virtual_screen_rect.top;
1073 XReconfigureWMWindow( display, data->whole_window,
1074 DefaultScreen(display), mask, &changes );
1075 wine_tsx11_unlock();
1080 /***********************************************************************
1081 * X11DRV_sync_client_position
1083 * Synchronize the X client window position with the Windows one
1085 void X11DRV_sync_client_position( Display *display, struct x11drv_win_data *data,
1086 UINT swp_flags, const RECT *old_client_rect,
1087 const RECT *old_whole_rect )
1090 XWindowChanges changes;
1091 RECT old = *old_client_rect;
1092 RECT new = data->client_rect;
1094 OffsetRect( &old, -old_whole_rect->left, -old_whole_rect->top );
1095 OffsetRect( &new, -data->whole_rect.left, -data->whole_rect.top );
1096 if (!(mask = get_window_changes( &changes, &old, &new ))) return;
1098 if (data->client_window)
1100 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1101 data->client_window, new.left, new.top,
1102 new.right - new.left, new.bottom - new.top, mask );
1104 XConfigureWindow( display, data->client_window, mask, &changes );
1105 wine_tsx11_unlock();
1108 if (data->gl_drawable && (mask & (CWWidth|CWHeight))) sync_gl_drawable( display, data );
1110 /* make sure the changes get to the server before we start painting */
1111 if (data->client_window || data->gl_drawable)
1115 wine_tsx11_unlock();
1120 /**********************************************************************
1121 * create_whole_window
1123 * Create the whole X window for a given window
1125 static Window create_whole_window( Display *display, struct x11drv_win_data *data )
1128 XSetWindowAttributes attr;
1133 if (!(cx = data->window_rect.right - data->window_rect.left)) cx = 1;
1134 if (!(cy = data->window_rect.bottom - data->window_rect.top)) cy = 1;
1136 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1138 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1139 data->managed = TRUE;
1140 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1143 mask = get_window_attributes( display, data, &attr );
1147 data->whole_rect = data->window_rect;
1148 data->whole_window = XCreateWindow( display, root_window,
1149 data->window_rect.left - virtual_screen_rect.left,
1150 data->window_rect.top - virtual_screen_rect.top,
1151 cx, cy, 0, screen_depth, InputOutput,
1152 visual, mask, &attr );
1154 if (data->whole_window) XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
1155 wine_tsx11_unlock();
1157 if (!data->whole_window) return 0;
1159 if (!create_client_window( display, data, NULL ))
1162 XDeleteContext( display, data->whole_window, winContext );
1163 XDestroyWindow( display, data->whole_window );
1164 data->whole_window = 0;
1165 wine_tsx11_unlock();
1169 xim = x11drv_thread_data()->xim;
1170 if (xim) data->xic = X11DRV_CreateIC( xim, display, data->whole_window );
1172 set_initial_wm_hints( display, data );
1173 X11DRV_set_wm_hints( display, data );
1175 SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
1177 /* set the window text */
1178 if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
1179 sync_window_text( display, data->whole_window, text );
1181 /* set the window region */
1182 if ((hrgn = CreateRectRgn( 0, 0, 0, 0 )))
1184 if (GetWindowRgn( data->hwnd, hrgn ) != ERROR) sync_window_region( display, data, hrgn );
1185 DeleteObject( hrgn );
1187 return data->whole_window;
1191 /**********************************************************************
1192 * destroy_whole_window
1194 * Destroy the whole X window for a given window.
1196 static void destroy_whole_window( Display *display, struct x11drv_win_data *data, BOOL already_destroyed )
1198 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1200 if (!data->whole_window) return;
1202 TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1203 if (thread_data->cursor_window == data->whole_window ||
1204 thread_data->cursor_window == data->client_window)
1205 thread_data->cursor_window = None;
1207 XDeleteContext( display, data->whole_window, winContext );
1208 XDeleteContext( display, data->client_window, winContext );
1209 if (!already_destroyed) XDestroyWindow( display, data->whole_window );
1210 data->whole_window = data->client_window = 0;
1211 data->wm_state = WithdrawnState;
1212 data->net_wm_state = 0;
1213 data->mapped = FALSE;
1216 XUnsetICFocus( data->xic );
1217 XDestroyIC( data->xic );
1220 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1222 XFree( data->wm_hints );
1223 data->wm_hints = NULL;
1224 wine_tsx11_unlock();
1225 RemovePropA( data->hwnd, whole_window_prop );
1226 RemovePropA( data->hwnd, client_window_prop );
1230 /*****************************************************************
1231 * SetWindowText (X11DRV.@)
1233 void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
1235 Display *display = thread_display();
1238 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display))
1239 sync_window_text( display, win, text );
1243 /***********************************************************************
1244 * DestroyWindow (X11DRV.@)
1246 void X11DRV_DestroyWindow( HWND hwnd )
1248 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1249 Display *display = thread_data->display;
1250 struct x11drv_win_data *data;
1252 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1256 destroy_glxpixmap(display, data->gl_drawable);
1258 XFreePixmap(display, data->pixmap);
1259 wine_tsx11_unlock();
1261 else if (data->gl_drawable)
1264 XDestroyWindow(display, data->gl_drawable);
1265 wine_tsx11_unlock();
1268 destroy_whole_window( display, data, FALSE );
1269 destroy_icon_window( display, data );
1274 XFreeColormap( display, data->colormap );
1275 wine_tsx11_unlock();
1278 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
1279 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
1280 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
1282 XDeleteContext( display, (XID)hwnd, win_data_context );
1283 wine_tsx11_unlock();
1284 HeapFree( GetProcessHeap(), 0, data );
1288 /***********************************************************************
1289 * X11DRV_DestroyNotify
1291 void X11DRV_DestroyNotify( HWND hwnd, XEvent *event )
1293 Display *display = event->xdestroywindow.display;
1294 struct x11drv_win_data *data;
1296 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1298 FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window );
1299 destroy_whole_window( display, data, TRUE );
1303 static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
1305 struct x11drv_win_data *data;
1307 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
1311 if (!winContext) winContext = XUniqueContext();
1312 if (!win_data_context) win_data_context = XUniqueContext();
1313 XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
1314 wine_tsx11_unlock();
1320 /* initialize the desktop window id in the desktop manager process */
1321 static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd )
1323 struct x11drv_win_data *data;
1326 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1328 visualid = XVisualIDFromVisual(visual);
1329 wine_tsx11_unlock();
1330 data->whole_window = data->client_window = root_window;
1331 data->managed = TRUE;
1332 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1333 SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
1334 SetPropA( data->hwnd, client_window_prop, (HANDLE)root_window );
1335 set_initial_wm_hints( display, data );
1339 /**********************************************************************
1340 * CreateDesktopWindow (X11DRV.@)
1342 BOOL X11DRV_CreateDesktopWindow( HWND hwnd )
1344 unsigned int width, height;
1346 /* retrieve the real size of the desktop */
1347 SERVER_START_REQ( get_window_rectangles )
1350 wine_server_call( req );
1351 width = reply->window.right - reply->window.left;
1352 height = reply->window.bottom - reply->window.top;
1356 if (!width && !height) /* not initialized yet */
1358 SERVER_START_REQ( set_window_pos )
1362 req->flags = SWP_NOZORDER;
1363 req->window.left = virtual_screen_rect.left;
1364 req->window.top = virtual_screen_rect.top;
1365 req->window.right = virtual_screen_rect.right;
1366 req->window.bottom = virtual_screen_rect.bottom;
1367 req->client = req->window;
1368 wine_server_call( req );
1374 Window win = (Window)GetPropA( hwnd, whole_window_prop );
1375 if (win && win != root_window) X11DRV_init_desktop( win, width, height );
1381 /**********************************************************************
1382 * CreateWindow (X11DRV.@)
1384 BOOL X11DRV_CreateWindow( HWND hwnd )
1386 Display *display = thread_display();
1388 if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( display ))
1390 /* the desktop win data can't be created lazily */
1391 if (!create_desktop_win_data( display, hwnd )) return FALSE;
1397 /***********************************************************************
1398 * X11DRV_get_win_data
1400 * Return the X11 data structure associated with a window.
1402 struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1406 if (!hwnd || XFindContext( thread_display(), (XID)hwnd, win_data_context, &data )) data = NULL;
1407 return (struct x11drv_win_data *)data;
1411 /***********************************************************************
1412 * X11DRV_create_win_data
1414 * Create an X11 data window structure for an existing window.
1416 struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd )
1418 Display *display = thread_display();
1419 struct x11drv_win_data *data;
1422 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
1423 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1425 GetWindowRect( hwnd, &data->window_rect );
1426 MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 );
1427 data->whole_rect = data->window_rect;
1428 GetClientRect( hwnd, &data->client_rect );
1429 MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 );
1431 if (parent == GetDesktopWindow())
1433 if (!create_whole_window( display, data ))
1435 HeapFree( GetProcessHeap(), 0, data );
1438 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1439 hwnd, data->whole_window, data->client_window, wine_dbgstr_rect( &data->window_rect ),
1440 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
1446 /***********************************************************************
1447 * X11DRV_get_whole_window
1449 * Return the X window associated with the full area of a window
1451 Window X11DRV_get_whole_window( HWND hwnd )
1453 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1457 if (hwnd == GetDesktopWindow()) return root_window;
1458 return (Window)GetPropA( hwnd, whole_window_prop );
1460 return data->whole_window;
1464 /***********************************************************************
1465 * X11DRV_get_client_window
1467 * Return the X window associated with the client area of a window
1469 Window X11DRV_get_client_window( HWND hwnd )
1471 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1475 if (hwnd == GetDesktopWindow()) return root_window;
1476 return (Window)GetPropA( hwnd, client_window_prop );
1478 return data->client_window;
1482 /***********************************************************************
1485 * Return the X input context associated with a window
1487 XIC X11DRV_get_ic( HWND hwnd )
1489 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1491 if (!data) return 0;
1496 /***********************************************************************
1497 * X11DRV_GetDC (X11DRV.@)
1499 void X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect,
1500 const RECT *top_rect, DWORD flags )
1502 struct x11drv_escape_set_drawable escape;
1503 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1505 escape.code = X11DRV_SET_DRAWABLE;
1506 escape.mode = IncludeInferiors;
1507 escape.fbconfig_id = 0;
1508 escape.gl_drawable = 0;
1511 if (top == hwnd && data && IsIconic( hwnd ) && data->icon_window)
1513 escape.drawable = data->icon_window;
1515 else if (top == hwnd && (flags & DCX_WINDOW))
1517 escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd );
1521 escape.drawable = X11DRV_get_client_window( top );
1522 escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop );
1523 escape.gl_drawable = data ? data->gl_drawable : (Drawable)GetPropA( hwnd, gl_drawable_prop );
1524 escape.pixmap = data ? data->pixmap : (Pixmap)GetPropA( hwnd, pixmap_prop );
1525 if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren;
1528 escape.dc_rect.left = win_rect->left - top_rect->left;
1529 escape.dc_rect.top = win_rect->top - top_rect->top;
1530 escape.dc_rect.right = win_rect->right - top_rect->left;
1531 escape.dc_rect.bottom = win_rect->bottom - top_rect->top;
1532 escape.drawable_rect.left = top_rect->left;
1533 escape.drawable_rect.top = top_rect->top;
1534 escape.drawable_rect.right = top_rect->right;
1535 escape.drawable_rect.bottom = top_rect->bottom;
1537 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1541 /***********************************************************************
1542 * X11DRV_ReleaseDC (X11DRV.@)
1544 void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
1546 struct x11drv_escape_set_drawable escape;
1548 escape.code = X11DRV_SET_DRAWABLE;
1549 escape.drawable = root_window;
1550 escape.mode = IncludeInferiors;
1551 escape.drawable_rect = virtual_screen_rect;
1552 SetRect( &escape.dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left,
1553 virtual_screen_rect.bottom - virtual_screen_rect.top );
1554 escape.fbconfig_id = 0;
1555 escape.gl_drawable = 0;
1557 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1561 /***********************************************************************
1562 * SetCapture (X11DRV.@)
1564 void X11DRV_SetCapture( HWND hwnd, UINT flags )
1566 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1568 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
1572 Window grab_win = X11DRV_get_client_window( GetAncestor( hwnd, GA_ROOT ) );
1574 if (!grab_win) return;
1576 XFlush( gdi_display );
1577 XGrabPointer( thread_data->display, grab_win, False,
1578 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1579 GrabModeAsync, GrabModeAsync, None, None, CurrentTime );
1580 wine_tsx11_unlock();
1581 thread_data->grab_window = grab_win;
1583 else /* release capture */
1586 XFlush( gdi_display );
1587 XUngrabPointer( thread_data->display, CurrentTime );
1588 wine_tsx11_unlock();
1589 thread_data->grab_window = None;
1594 /*****************************************************************
1595 * SetParent (X11DRV.@)
1597 void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
1599 Display *display = thread_display();
1600 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1603 if (parent == old_parent) return;
1605 if (parent != GetDesktopWindow()) /* a child window */
1607 if (old_parent == GetDesktopWindow())
1609 /* destroy the old X windows */
1610 destroy_whole_window( display, data, FALSE );
1611 destroy_icon_window( display, data );
1614 data->managed = FALSE;
1615 RemovePropA( data->hwnd, managed_prop );
1619 else /* new top level window */
1621 /* FIXME: we ignore errors since we can't really recover anyway */
1622 create_whole_window( display, data );
1627 /*****************************************************************
1628 * SetFocus (X11DRV.@)
1631 * Explicit colormap management seems to work only with OLVWM.
1633 void X11DRV_SetFocus( HWND hwnd )
1635 Display *display = thread_display();
1636 struct x11drv_win_data *data;
1637 XWindowChanges changes;
1639 /* If setting the focus to 0, uninstall the colormap */
1640 if (!hwnd && root_window == DefaultRootWindow(display))
1643 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1644 XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1645 wine_tsx11_unlock();
1649 hwnd = GetAncestor( hwnd, GA_ROOT );
1651 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1652 if (data->managed || !data->whole_window) return;
1654 /* Set X focus and install colormap */
1656 changes.stack_mode = Above;
1657 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
1658 if (root_window == DefaultRootWindow(display))
1660 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1661 /* FIXME: this is not entirely correct */
1662 XSetInputFocus( display, data->whole_window, RevertToParent,
1664 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1665 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1666 XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1668 wine_tsx11_unlock();
1672 /**********************************************************************
1673 * SetWindowIcon (X11DRV.@)
1675 * hIcon or hIconSm has changed (or is being initialised for the
1676 * first time). Complete the X11 driver-specific initialisation
1677 * and set the window hints.
1679 * This is not entirely correct, may need to create
1680 * an icon window and set the pixmap as a background
1682 void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
1684 Display *display = thread_display();
1685 struct x11drv_win_data *data;
1687 if (type != ICON_BIG) return; /* nothing to do here */
1689 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1690 if (!data->whole_window) return;
1691 if (!data->managed) return;
1695 set_icon_hints( display, data, icon );
1697 XSetWMHints( display, data->whole_window, data->wm_hints );
1698 wine_tsx11_unlock();
1703 /***********************************************************************
1704 * SetWindowRgn (X11DRV.@)
1706 * Assign specified region to window (for non-rectangular windows)
1708 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1710 struct x11drv_win_data *data;
1712 if ((data = X11DRV_get_win_data( hwnd )))
1714 sync_window_region( thread_display(), data, hrgn );
1716 else if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
1718 FIXME( "not supported on other thread window %p\n", hwnd );
1719 SetLastError( ERROR_INVALID_WINDOW_HANDLE );