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 extern int usexcomposite;
69 /***********************************************************************
72 * Check if a given window should be managed
74 BOOL is_window_managed( HWND hwnd, UINT swp_flags, const RECT *window_rect )
76 DWORD style, ex_style;
78 if (!managed_mode) return FALSE;
80 /* child windows are not managed */
81 style = GetWindowLongW( hwnd, GWL_STYLE );
82 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD) return FALSE;
83 /* activated windows are managed */
84 if (!(swp_flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) return TRUE;
85 if (hwnd == GetActiveWindow()) return TRUE;
86 /* windows with caption are managed */
87 if ((style & WS_CAPTION) == WS_CAPTION) return TRUE;
88 /* tool windows are not managed */
89 ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE );
90 if (ex_style & WS_EX_TOOLWINDOW) return FALSE;
91 /* windows with thick frame are managed */
92 if (style & WS_THICKFRAME) return TRUE;
93 /* application windows are managed */
94 if (ex_style & WS_EX_APPWINDOW) return TRUE;
97 /* popup with sysmenu == caption are managed */
98 if (style & WS_SYSMENU) return TRUE;
99 /* full-screen popup windows are managed */
100 if (window_rect->left <= 0 && window_rect->right >= screen_width &&
101 window_rect->top <= 0 && window_rect->bottom >= screen_height)
104 /* default: not managed */
109 /***********************************************************************
110 * X11DRV_is_window_rect_mapped
112 * Check if the X whole window should be mapped based on its rectangle
114 BOOL X11DRV_is_window_rect_mapped( const RECT *rect )
116 /* don't map if rect is empty */
117 if (IsRectEmpty( rect )) return FALSE;
119 /* don't map if rect is off-screen */
120 if (rect->left >= virtual_screen_rect.right ||
121 rect->top >= virtual_screen_rect.bottom ||
122 rect->right <= virtual_screen_rect.left ||
123 rect->bottom <= virtual_screen_rect.top)
130 /***********************************************************************
131 * is_window_resizable
133 * Check if window should be made resizable by the window manager
135 static inline BOOL is_window_resizable( struct x11drv_win_data *data, DWORD style )
137 if (style & WS_THICKFRAME) return TRUE;
138 /* Metacity needs the window to be resizable to make it fullscreen */
139 return (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width &&
140 data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height);
144 /***********************************************************************
145 * get_mwm_decorations
147 static unsigned long get_mwm_decorations( DWORD style, DWORD ex_style )
149 unsigned long ret = 0;
151 if (ex_style & WS_EX_TOOLWINDOW) return 0;
153 if ((style & WS_CAPTION) == WS_CAPTION)
155 ret |= MWM_DECOR_TITLE | MWM_DECOR_BORDER;
156 if (style & WS_SYSMENU) ret |= MWM_DECOR_MENU;
157 if (style & WS_MINIMIZEBOX) ret |= MWM_DECOR_MINIMIZE;
158 if (style & WS_MAXIMIZEBOX) ret |= MWM_DECOR_MAXIMIZE;
160 if (ex_style & WS_EX_DLGMODALFRAME) ret |= MWM_DECOR_BORDER;
161 else if (style & WS_THICKFRAME) ret |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
162 else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) ret |= MWM_DECOR_BORDER;
167 /***********************************************************************
168 * get_x11_rect_offset
170 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
172 static void get_x11_rect_offset( struct x11drv_win_data *data, RECT *rect )
174 DWORD style, ex_style, style_mask = 0, ex_style_mask = 0;
177 rect->top = rect->bottom = rect->left = rect->right = 0;
179 style = GetWindowLongW( data->hwnd, GWL_STYLE );
180 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
181 decor = get_mwm_decorations( style, ex_style );
183 if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION;
184 if (decor & MWM_DECOR_BORDER)
186 style_mask |= WS_DLGFRAME | WS_THICKFRAME;
187 ex_style_mask |= WS_EX_DLGMODALFRAME;
190 AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask );
194 /***********************************************************************
195 * get_window_attributes
197 * Fill the window attributes structure for an X window.
199 static int get_window_attributes( Display *display, struct x11drv_win_data *data,
200 XSetWindowAttributes *attr )
202 attr->override_redirect = !data->managed;
203 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
204 attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0);
205 attr->cursor = x11drv_thread_data()->cursor;
206 attr->bit_gravity = NorthWestGravity;
207 attr->backing_store = NotUseful;
208 attr->event_mask = (ExposureMask | PointerMotionMask |
209 ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
210 KeyPressMask | KeyReleaseMask | FocusChangeMask | KeymapStateMask);
211 if (data->managed) attr->event_mask |= StructureNotifyMask | PropertyChangeMask;
213 return (CWOverrideRedirect | CWSaveUnder | CWColormap | CWCursor |
214 CWEventMask | CWBitGravity | CWBackingStore);
218 /***********************************************************************
219 * create_client_window
221 static Window create_client_window( Display *display, struct x11drv_win_data *data, XVisualInfo *vis )
224 XSetWindowAttributes attr;
227 attr.bit_gravity = NorthWestGravity;
228 attr.win_gravity = NorthWestGravity;
229 attr.backing_store = NotUseful;
230 attr.event_mask = (ExposureMask | PointerMotionMask |
231 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
232 mask = CWEventMask | CWBitGravity | CWWinGravity | CWBackingStore;
234 if ((cx = data->client_rect.right - data->client_rect.left) <= 0) cx = 1;
235 if ((cy = data->client_rect.bottom - data->client_rect.top) <= 0) cy = 1;
241 attr.colormap = XCreateColormap( display, root_window, vis->visual,
242 (vis->class == PseudoColor || vis->class == GrayScale ||
243 vis->class == DirectColor) ? AllocAll : AllocNone );
247 client = XCreateWindow( display, data->whole_window,
248 data->client_rect.left - data->whole_rect.left,
249 data->client_rect.top - data->whole_rect.top,
250 cx, cy, 0, screen_depth, InputOutput,
251 vis ? vis->visual : visual, mask, &attr );
258 if (data->client_window)
260 struct x11drv_thread_data *thread_data = x11drv_thread_data();
261 if (thread_data->cursor_window == data->client_window) thread_data->cursor_window = None;
262 XDeleteContext( display, data->client_window, winContext );
263 XDestroyWindow( display, data->client_window );
265 data->client_window = client;
267 if (data->colormap) XFreeColormap( display, data->colormap );
268 data->colormap = vis ? attr.colormap : 0;
270 XMapWindow( display, data->client_window );
271 XSaveContext( display, data->client_window, winContext, (char *)data->hwnd );
274 SetPropA( data->hwnd, client_window_prop, (HANDLE)data->client_window );
275 return data->client_window;
279 /***********************************************************************
280 * X11DRV_sync_window_style
282 * Change the X window attributes when the window style has changed.
284 void X11DRV_sync_window_style( Display *display, struct x11drv_win_data *data )
286 if (data->whole_window != root_window)
288 XSetWindowAttributes attr;
289 int mask = get_window_attributes( display, data, &attr );
292 XChangeWindowAttributes( display, data->whole_window, mask, &attr );
298 /***********************************************************************
301 * Update the X11 window region.
303 static void sync_window_region( Display *display, struct x11drv_win_data *data, HRGN hrgn )
305 #ifdef HAVE_LIBXSHAPE
306 if (!data->whole_window) return;
311 XShapeCombineMask( display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet );
316 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
320 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
321 data->window_rect.left - data->whole_rect.left,
322 data->window_rect.top - data->whole_rect.top,
323 (XRectangle *)pRegionData->Buffer,
324 pRegionData->rdh.nCount, ShapeSet, YXBanded );
326 HeapFree(GetProcessHeap(), 0, pRegionData);
329 #endif /* HAVE_LIBXSHAPE */
333 /***********************************************************************
336 static void sync_window_text( Display *display, Window win, const WCHAR *text )
339 char *buffer, *utf8_buffer;
342 /* allocate new buffer for window text */
343 count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
344 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) return;
345 WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
347 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
348 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
350 HeapFree( GetProcessHeap(), 0, buffer );
353 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
356 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
358 XSetWMName( display, win, &prop );
359 XSetWMIconName( display, win, &prop );
363 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
364 according to the standard
365 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
367 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
368 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
371 HeapFree( GetProcessHeap(), 0, utf8_buffer );
372 HeapFree( GetProcessHeap(), 0, buffer );
376 /***********************************************************************
377 * X11DRV_set_win_format
379 BOOL X11DRV_set_win_format( HWND hwnd, XID fbconfig_id )
381 Display *display = thread_display();
382 struct x11drv_win_data *data;
386 if (!(data = X11DRV_get_win_data(hwnd)) &&
387 !(data = X11DRV_create_win_data(hwnd))) return FALSE;
389 if (data->fbconfig_id) return FALSE; /* can't change it twice */
392 vis = visual_from_fbconfig_id(fbconfig_id);
394 if (!vis) return FALSE;
396 if (data->whole_window)
398 Window client = data->client_window;
400 if (vis->visualid != XVisualIDFromVisual(visual))
402 client = create_client_window( display, data, vis );
403 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client, data->hwnd, fbconfig_id );
408 if (client) goto done;
412 w = data->client_rect.right - data->client_rect.left;
413 h = data->client_rect.bottom - data->client_rect.top;
418 #ifdef SONAME_LIBXCOMPOSITE
421 XSetWindowAttributes attrib;
422 Window parent = X11DRV_get_whole_window( GetAncestor( hwnd, GA_ROOT ));
424 if (!parent) parent = root_window;
426 data->colormap = XCreateColormap(display, parent, vis->visual,
427 (vis->class == PseudoColor ||
428 vis->class == GrayScale ||
429 vis->class == DirectColor) ?
430 AllocAll : AllocNone);
431 attrib.override_redirect = True;
432 attrib.colormap = data->colormap;
433 XInstallColormap(gdi_display, attrib.colormap);
435 data->gl_drawable = XCreateWindow(display, parent, -w, 0, w, h, 0,
436 vis->depth, InputOutput, vis->visual,
437 CWColormap | CWOverrideRedirect,
439 if(data->gl_drawable)
441 pXCompositeRedirectWindow(display, data->gl_drawable,
442 CompositeRedirectManual);
443 XMapWindow(display, data->gl_drawable);
451 WARN("XComposite is not available, using GLXPixmap hack\n");
454 data->pixmap = XCreatePixmap(display, root_window, w, h, vis->depth);
462 data->gl_drawable = create_glxpixmap(display, vis, data->pixmap);
463 if(!data->gl_drawable)
465 XFreePixmap(display, data->pixmap);
470 if (data->pixmap) SetPropA(hwnd, pixmap_prop, (HANDLE)data->pixmap);
473 if (!data->gl_drawable) return FALSE;
475 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
476 data->gl_drawable, fbconfig_id);
477 SetPropA(hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
480 data->fbconfig_id = fbconfig_id;
481 SetPropA(hwnd, fbconfig_id_prop, (HANDLE)data->fbconfig_id);
485 WIN_invalidate_dce( hwnd, NULL );
489 /***********************************************************************
492 static void sync_gl_drawable(Display *display, struct x11drv_win_data *data)
494 int w = data->client_rect.right - data->client_rect.left;
495 int h = data->client_rect.bottom - data->client_rect.top;
503 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data->gl_drawable, w, h);
504 #ifdef SONAME_LIBXCOMPOSITE
508 XMoveResizeWindow(display, data->gl_drawable, -w, 0, w, h);
516 vis = visual_from_fbconfig_id(data->fbconfig_id);
523 pix = XCreatePixmap(display, root_window, w, h, vis->depth);
526 ERR("Failed to create pixmap for offscreen rendering\n");
532 glxp = create_glxpixmap(display, vis, pix);
535 ERR("Failed to create drawable for offscreen rendering\n");
536 XFreePixmap(display, pix);
544 mark_drawable_dirty(data->gl_drawable, glxp);
546 XFreePixmap(display, data->pixmap);
547 destroy_glxpixmap(display, data->gl_drawable);
550 data->gl_drawable = glxp;
554 SetPropA(data->hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
555 SetPropA(data->hwnd, pixmap_prop, (HANDLE)data->pixmap);
559 /***********************************************************************
562 * fill the window changes structure
564 static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
568 if (old->right - old->left != new->right - new->left )
570 if ((changes->width = new->right - new->left) <= 0) changes->width = 1;
573 if (old->bottom - old->top != new->bottom - new->top)
575 if ((changes->height = new->bottom - new->top) <= 0) changes->height = 1;
578 if (old->left != new->left)
580 changes->x = new->left;
583 if (old->top != new->top)
585 changes->y = new->top;
592 /***********************************************************************
595 static Window create_icon_window( Display *display, struct x11drv_win_data *data )
597 XSetWindowAttributes attr;
599 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
600 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
601 attr.bit_gravity = NorthWestGravity;
602 attr.backing_store = NotUseful/*WhenMapped*/;
603 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
606 data->icon_window = XCreateWindow( display, root_window, 0, 0,
607 GetSystemMetrics( SM_CXICON ),
608 GetSystemMetrics( SM_CYICON ),
611 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
612 XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd );
613 XFlush( display ); /* make sure the window exists before we start painting to it */
616 TRACE( "created %lx\n", data->icon_window );
617 SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window );
618 return data->icon_window;
623 /***********************************************************************
624 * destroy_icon_window
626 static void destroy_icon_window( Display *display, struct x11drv_win_data *data )
628 if (!data->icon_window) return;
629 if (x11drv_thread_data()->cursor_window == data->icon_window)
630 x11drv_thread_data()->cursor_window = None;
632 XDeleteContext( display, data->icon_window, winContext );
633 XDestroyWindow( display, data->icon_window );
634 data->icon_window = 0;
636 RemovePropA( data->hwnd, icon_window_prop );
640 /***********************************************************************
643 * Set the icon wm hints
645 static void set_icon_hints( Display *display, struct x11drv_win_data *data, HICON hIcon )
647 XWMHints *hints = data->wm_hints;
649 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
650 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
651 data->hWMIconBitmap = 0;
652 data->hWMIconMask = 0;
656 if (!data->icon_window) create_icon_window( display, data );
657 hints->icon_window = data->icon_window;
658 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
668 GetIconInfo(hIcon, &ii);
670 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
673 rcMask.right = bmMask.bmWidth;
674 rcMask.bottom = bmMask.bmHeight;
676 hDC = CreateCompatibleDC(0);
677 hbmOrig = SelectObject(hDC, ii.hbmMask);
678 InvertRect(hDC, &rcMask);
679 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
680 SelectObject(hDC, hbmOrig);
683 data->hWMIconBitmap = ii.hbmColor;
684 data->hWMIconMask = ii.hbmMask;
686 hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap);
687 hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask);
688 destroy_icon_window( display, data );
689 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
694 /***********************************************************************
697 * set the window size hints
699 static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style )
701 XSizeHints* size_hints;
703 if (!(size_hints = XAllocSizeHints())) return;
705 /* don't update size hints if window is not in normal state */
706 if (!(style & (WS_MINIMIZE | WS_MAXIMIZE)))
708 if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */
710 size_hints->win_gravity = StaticGravity;
711 size_hints->x = data->whole_rect.left;
712 size_hints->y = data->whole_rect.top;
713 size_hints->flags |= PWinGravity | PPosition;
716 if (!is_window_resizable( data, style ))
718 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
719 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
720 size_hints->min_width = size_hints->max_width;
721 size_hints->min_height = size_hints->max_height;
722 size_hints->flags |= PMinSize | PMaxSize;
725 XSetWMNormalHints( display, data->whole_window, size_hints );
730 /***********************************************************************
733 * get the name of the current process for setting class hints
735 static char *get_process_name(void)
741 WCHAR module[MAX_PATH];
742 DWORD len = GetModuleFileNameW( 0, module, MAX_PATH );
743 if (len && len < MAX_PATH)
746 WCHAR *p, *appname = module;
748 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
749 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
750 len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL );
751 if ((ptr = HeapAlloc( GetProcessHeap(), 0, len )))
753 WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL );
762 /***********************************************************************
763 * set_initial_wm_hints
765 * Set the window manager hints that don't change over the lifetime of a window.
767 static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data )
772 XClassHint *class_hints;
773 char *process_name = get_process_name();
779 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
780 protocols[i++] = x11drv_atom(_NET_WM_PING);
781 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
782 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
783 XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
786 if ((class_hints = XAllocClassHint()))
788 static char wine[] = "Wine";
790 class_hints->res_name = process_name;
791 class_hints->res_class = wine;
792 XSetClassHint( display, data->whole_window, class_hints );
793 XFree( class_hints );
796 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
797 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
798 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
800 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
801 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
803 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
804 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
806 data->wm_hints = XAllocWMHints();
811 HICON icon = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 );
812 if (!icon) icon = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON );
813 data->wm_hints->flags = 0;
814 set_icon_hints( display, data, icon );
819 /***********************************************************************
820 * X11DRV_set_wm_hints
822 * Set the window manager hints for a newly-created window
824 void X11DRV_set_wm_hints( Display *display, struct x11drv_win_data *data )
829 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
830 DWORD ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
831 HWND owner = GetWindow( data->hwnd, GW_OWNER );
833 if (data->hwnd == GetDesktopWindow())
835 /* force some styles for the desktop to get the correct decorations */
836 style |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
840 /* transient for hint */
843 Window owner_win = X11DRV_get_whole_window( owner );
845 XSetTransientForHint( display, data->whole_window, owner_win );
847 group_leader = owner_win;
849 else group_leader = data->whole_window;
854 set_size_hints( display, data, style );
856 /* set the WM_WINDOW_TYPE */
857 window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
858 if (style & WS_THICKFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
859 else if (style & WS_DLGFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
860 else if (ex_style & WS_EX_DLGMODALFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
861 #if 0 /* many window managers don't handle utility windows very well */
862 else if (ex_style & WS_EX_TOOLWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
865 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
866 XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1);
868 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
869 mwm_hints.decorations = get_mwm_decorations( style, ex_style );
870 mwm_hints.functions = MWM_FUNC_MOVE;
871 if (is_window_resizable( data, style )) mwm_hints.functions |= MWM_FUNC_RESIZE;
872 if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
873 if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
874 if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
876 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
877 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
878 (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
883 data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint;
884 data->wm_hints->input = !(style & WS_DISABLED);
885 data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
886 data->wm_hints->window_group = group_leader;
887 XSetWMHints( display, data->whole_window, data->wm_hints );
894 /***********************************************************************
895 * X11DRV_window_to_X_rect
897 * Convert a rect from client to X window coordinates
899 void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect )
903 if (!data->managed) return;
904 if (IsRectEmpty( rect )) return;
906 get_x11_rect_offset( data, &rc );
908 rect->left -= rc.left;
909 rect->right -= rc.right;
911 rect->bottom -= rc.bottom;
912 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
913 if (rect->left >= rect->right) rect->right = rect->left + 1;
917 /***********************************************************************
918 * X11DRV_X_to_window_rect
920 * Opposite of X11DRV_window_to_X_rect
922 void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect )
926 if (!data->managed) return;
927 if (IsRectEmpty( rect )) return;
929 get_x11_rect_offset( data, &rc );
931 rect->left += rc.left;
932 rect->right += rc.right;
934 rect->bottom += rc.bottom;
935 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
936 if (rect->left >= rect->right) rect->right = rect->left + 1;
940 /***********************************************************************
941 * X11DRV_sync_window_position
943 * Synchronize the X window position with the Windows one
945 void X11DRV_sync_window_position( Display *display, struct x11drv_win_data *data,
946 UINT swp_flags, const RECT *old_client_rect,
947 const RECT *old_whole_rect )
949 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
950 XWindowChanges changes;
951 int mask = CWWidth | CWHeight;
953 if (data->managed && data->iconic) return;
955 if ((changes.width = data->whole_rect.right - data->whole_rect.left) <= 0) changes.width = 1;
956 if ((changes.height = data->whole_rect.bottom - data->whole_rect.top) <= 0) changes.height = 1;
958 /* only the size is allowed to change for the desktop window */
959 if (data->whole_window != root_window)
961 changes.x = data->whole_rect.left - virtual_screen_rect.left;
962 changes.y = data->whole_rect.top - virtual_screen_rect.top;
966 if (!(swp_flags & SWP_NOZORDER))
968 /* find window that this one must be after */
969 HWND prev = GetWindow( data->hwnd, GW_HWNDPREV );
970 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
971 prev = GetWindow( prev, GW_HWNDPREV );
972 if (!prev) /* top child */
974 changes.stack_mode = Above;
977 /* should use stack_mode Below but most window managers don't get it right */
978 /* and Above with a sibling doesn't work so well either, so we ignore it */
981 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
982 data->hwnd, data->whole_window, data->whole_rect.left, data->whole_rect.top,
983 data->whole_rect.right - data->whole_rect.left,
984 data->whole_rect.bottom - data->whole_rect.top, changes.sibling, mask );
987 set_size_hints( display, data, style );
988 XReconfigureWMWindow( display, data->whole_window,
989 DefaultScreen(display), mask, &changes );
994 /***********************************************************************
995 * X11DRV_sync_client_position
997 * Synchronize the X client window position with the Windows one
999 void X11DRV_sync_client_position( Display *display, struct x11drv_win_data *data,
1000 UINT swp_flags, const RECT *old_client_rect,
1001 const RECT *old_whole_rect )
1004 XWindowChanges changes;
1005 RECT old = *old_client_rect;
1006 RECT new = data->client_rect;
1008 OffsetRect( &old, -old_whole_rect->left, -old_whole_rect->top );
1009 OffsetRect( &new, -data->whole_rect.left, -data->whole_rect.top );
1010 if (!(mask = get_window_changes( &changes, &old, &new ))) return;
1012 if (data->client_window)
1014 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1015 data->client_window, new.left, new.top,
1016 new.right - new.left, new.bottom - new.top, mask );
1018 XConfigureWindow( display, data->client_window, mask, &changes );
1019 wine_tsx11_unlock();
1022 if (data->gl_drawable && (mask & (CWWidth|CWHeight))) sync_gl_drawable( display, data );
1024 /* make sure the changes get to the server before we start painting */
1025 if (data->client_window || data->gl_drawable)
1029 wine_tsx11_unlock();
1034 /**********************************************************************
1035 * create_whole_window
1037 * Create the whole X window for a given window
1039 static Window create_whole_window( Display *display, struct x11drv_win_data *data )
1042 XSetWindowAttributes attr;
1047 if (!(cx = data->window_rect.right - data->window_rect.left)) cx = 1;
1048 if (!(cy = data->window_rect.bottom - data->window_rect.top)) cy = 1;
1050 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1052 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1053 data->managed = TRUE;
1054 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1057 mask = get_window_attributes( display, data, &attr );
1061 data->whole_rect = data->window_rect;
1062 data->whole_window = XCreateWindow( display, root_window,
1063 data->window_rect.left - virtual_screen_rect.left,
1064 data->window_rect.top - virtual_screen_rect.top,
1065 cx, cy, 0, screen_depth, InputOutput,
1066 visual, mask, &attr );
1068 if (data->whole_window) XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
1069 wine_tsx11_unlock();
1071 if (!data->whole_window) return 0;
1073 if (!create_client_window( display, data, NULL ))
1076 XDeleteContext( display, data->whole_window, winContext );
1077 XDestroyWindow( display, data->whole_window );
1078 data->whole_window = 0;
1079 wine_tsx11_unlock();
1083 xim = x11drv_thread_data()->xim;
1084 if (xim) data->xic = X11DRV_CreateIC( xim, display, data->whole_window );
1086 set_initial_wm_hints( display, data );
1087 X11DRV_set_wm_hints( display, data );
1089 SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
1091 /* set the window text */
1092 if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
1093 sync_window_text( display, data->whole_window, text );
1095 /* set the window region */
1096 if ((hrgn = CreateRectRgn( 0, 0, 0, 0 )))
1098 if (GetWindowRgn( data->hwnd, hrgn ) != ERROR) sync_window_region( display, data, hrgn );
1099 DeleteObject( hrgn );
1102 XFlush( display ); /* make sure the window exists before we start painting to it */
1103 wine_tsx11_unlock();
1104 return data->whole_window;
1108 /**********************************************************************
1109 * destroy_whole_window
1111 * Destroy the whole X window for a given window.
1113 static void destroy_whole_window( Display *display, struct x11drv_win_data *data, BOOL already_destroyed )
1115 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1117 if (!data->whole_window) return;
1119 TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1120 if (thread_data->cursor_window == data->whole_window ||
1121 thread_data->cursor_window == data->client_window)
1122 thread_data->cursor_window = None;
1124 XDeleteContext( display, data->whole_window, winContext );
1125 XDeleteContext( display, data->client_window, winContext );
1126 if (!already_destroyed) XDestroyWindow( display, data->whole_window );
1127 data->whole_window = data->client_window = 0;
1128 data->wm_state = WithdrawnState;
1129 data->net_wm_state = 0;
1130 data->mapped = FALSE;
1133 XUnsetICFocus( data->xic );
1134 XDestroyIC( data->xic );
1137 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1139 XFree( data->wm_hints );
1140 data->wm_hints = NULL;
1141 wine_tsx11_unlock();
1142 RemovePropA( data->hwnd, whole_window_prop );
1143 RemovePropA( data->hwnd, client_window_prop );
1147 /*****************************************************************
1148 * SetWindowText (X11DRV.@)
1150 void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
1152 Display *display = thread_display();
1155 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display))
1156 sync_window_text( display, win, text );
1160 /***********************************************************************
1161 * DestroyWindow (X11DRV.@)
1163 void X11DRV_DestroyWindow( HWND hwnd )
1165 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1166 Display *display = thread_data->display;
1167 struct x11drv_win_data *data;
1169 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1173 destroy_glxpixmap(display, data->gl_drawable);
1175 XFreePixmap(display, data->pixmap);
1176 wine_tsx11_unlock();
1178 else if (data->gl_drawable)
1181 XDestroyWindow(display, data->gl_drawable);
1182 wine_tsx11_unlock();
1185 destroy_whole_window( display, data, FALSE );
1186 destroy_icon_window( display, data );
1191 XFreeColormap( display, data->colormap );
1192 wine_tsx11_unlock();
1195 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
1196 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
1197 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
1199 XDeleteContext( display, (XID)hwnd, win_data_context );
1200 wine_tsx11_unlock();
1201 HeapFree( GetProcessHeap(), 0, data );
1205 /***********************************************************************
1206 * X11DRV_DestroyNotify
1208 void X11DRV_DestroyNotify( HWND hwnd, XEvent *event )
1210 Display *display = event->xdestroywindow.display;
1211 struct x11drv_win_data *data;
1213 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1215 FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window );
1216 destroy_whole_window( display, data, TRUE );
1220 static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
1222 struct x11drv_win_data *data;
1224 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
1228 if (!winContext) winContext = XUniqueContext();
1229 if (!win_data_context) win_data_context = XUniqueContext();
1230 XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
1231 wine_tsx11_unlock();
1237 /* initialize the desktop window id in the desktop manager process */
1238 static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd )
1240 struct x11drv_win_data *data;
1243 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1245 visualid = XVisualIDFromVisual(visual);
1246 wine_tsx11_unlock();
1247 data->whole_window = data->client_window = root_window;
1248 data->managed = TRUE;
1249 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1250 SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
1251 SetPropA( data->hwnd, client_window_prop, (HANDLE)root_window );
1252 set_initial_wm_hints( display, data );
1256 /**********************************************************************
1257 * CreateDesktopWindow (X11DRV.@)
1259 BOOL X11DRV_CreateDesktopWindow( HWND hwnd )
1261 unsigned int width, height;
1263 /* retrieve the real size of the desktop */
1264 SERVER_START_REQ( get_window_rectangles )
1267 wine_server_call( req );
1268 width = reply->window.right - reply->window.left;
1269 height = reply->window.bottom - reply->window.top;
1273 if (!width && !height) /* not initialized yet */
1275 SERVER_START_REQ( set_window_pos )
1279 req->flags = SWP_NOZORDER;
1280 req->window.left = virtual_screen_rect.left;
1281 req->window.top = virtual_screen_rect.top;
1282 req->window.right = virtual_screen_rect.right;
1283 req->window.bottom = virtual_screen_rect.bottom;
1284 req->client = req->window;
1285 wine_server_call( req );
1291 Window win = (Window)GetPropA( hwnd, whole_window_prop );
1292 if (win && win != root_window) X11DRV_init_desktop( win, width, height );
1298 /**********************************************************************
1299 * CreateWindow (X11DRV.@)
1301 BOOL X11DRV_CreateWindow( HWND hwnd )
1303 Display *display = thread_display();
1305 if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( display ))
1307 /* the desktop win data can't be created lazily */
1308 if (!create_desktop_win_data( display, hwnd )) return FALSE;
1314 /***********************************************************************
1315 * X11DRV_get_win_data
1317 * Return the X11 data structure associated with a window.
1319 struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1323 if (!hwnd || XFindContext( thread_display(), (XID)hwnd, win_data_context, &data )) data = NULL;
1324 return (struct x11drv_win_data *)data;
1328 /***********************************************************************
1329 * X11DRV_create_win_data
1331 * Create an X11 data window structure for an existing window.
1333 struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd )
1335 Display *display = thread_display();
1336 struct x11drv_win_data *data;
1339 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
1340 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1342 GetWindowRect( hwnd, &data->window_rect );
1343 MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 );
1344 data->whole_rect = data->window_rect;
1345 GetClientRect( hwnd, &data->client_rect );
1346 MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 );
1348 if (parent == GetDesktopWindow())
1350 if (!create_whole_window( display, data ))
1352 HeapFree( GetProcessHeap(), 0, data );
1355 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1356 hwnd, data->whole_window, data->client_window, wine_dbgstr_rect( &data->window_rect ),
1357 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
1363 /***********************************************************************
1364 * X11DRV_get_whole_window
1366 * Return the X window associated with the full area of a window
1368 Window X11DRV_get_whole_window( HWND hwnd )
1370 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1374 if (hwnd == GetDesktopWindow()) return root_window;
1375 return (Window)GetPropA( hwnd, whole_window_prop );
1377 return data->whole_window;
1381 /***********************************************************************
1382 * X11DRV_get_client_window
1384 * Return the X window associated with the client area of a window
1386 Window X11DRV_get_client_window( HWND hwnd )
1388 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1392 if (hwnd == GetDesktopWindow()) return root_window;
1393 return (Window)GetPropA( hwnd, client_window_prop );
1395 return data->client_window;
1399 /***********************************************************************
1402 * Return the X input context associated with a window
1404 XIC X11DRV_get_ic( HWND hwnd )
1406 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1408 if (!data) return 0;
1413 /***********************************************************************
1414 * X11DRV_GetDC (X11DRV.@)
1416 void X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect,
1417 const RECT *top_rect, DWORD flags )
1419 struct x11drv_escape_set_drawable escape;
1420 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1422 escape.code = X11DRV_SET_DRAWABLE;
1423 escape.mode = IncludeInferiors;
1424 escape.fbconfig_id = 0;
1425 escape.gl_drawable = 0;
1428 if (top == hwnd && data && IsIconic( hwnd ) && data->icon_window)
1430 escape.drawable = data->icon_window;
1432 else if (top == hwnd && (flags & DCX_WINDOW))
1434 escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd );
1438 escape.drawable = X11DRV_get_client_window( top );
1439 escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop );
1440 escape.gl_drawable = data ? data->gl_drawable : (Drawable)GetPropA( hwnd, gl_drawable_prop );
1441 escape.pixmap = data ? data->pixmap : (Pixmap)GetPropA( hwnd, pixmap_prop );
1442 if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren;
1445 escape.dc_rect.left = win_rect->left - top_rect->left;
1446 escape.dc_rect.top = win_rect->top - top_rect->top;
1447 escape.dc_rect.right = win_rect->right - top_rect->left;
1448 escape.dc_rect.bottom = win_rect->bottom - top_rect->top;
1449 escape.drawable_rect.left = top_rect->left;
1450 escape.drawable_rect.top = top_rect->top;
1451 escape.drawable_rect.right = top_rect->right;
1452 escape.drawable_rect.bottom = top_rect->bottom;
1454 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1458 /***********************************************************************
1459 * X11DRV_ReleaseDC (X11DRV.@)
1461 void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
1463 struct x11drv_escape_set_drawable escape;
1465 escape.code = X11DRV_SET_DRAWABLE;
1466 escape.drawable = root_window;
1467 escape.mode = IncludeInferiors;
1468 escape.drawable_rect = virtual_screen_rect;
1469 SetRect( &escape.dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left,
1470 virtual_screen_rect.bottom - virtual_screen_rect.top );
1471 escape.fbconfig_id = 0;
1472 escape.gl_drawable = 0;
1474 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1478 /***********************************************************************
1479 * SetCapture (X11DRV.@)
1481 void X11DRV_SetCapture( HWND hwnd, UINT flags )
1483 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1485 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
1489 Window grab_win = X11DRV_get_client_window( GetAncestor( hwnd, GA_ROOT ) );
1491 if (!grab_win) return;
1493 XFlush( gdi_display );
1494 XGrabPointer( thread_data->display, grab_win, False,
1495 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1496 GrabModeAsync, GrabModeAsync, None, None, CurrentTime );
1497 wine_tsx11_unlock();
1498 thread_data->grab_window = grab_win;
1500 else /* release capture */
1503 XFlush( gdi_display );
1504 XUngrabPointer( thread_data->display, CurrentTime );
1505 wine_tsx11_unlock();
1506 thread_data->grab_window = None;
1511 /*****************************************************************
1512 * SetParent (X11DRV.@)
1514 void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
1516 Display *display = thread_display();
1517 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1520 if (parent == old_parent) return;
1522 if (parent != GetDesktopWindow()) /* a child window */
1524 if (old_parent == GetDesktopWindow())
1526 /* destroy the old X windows */
1527 destroy_whole_window( display, data, FALSE );
1528 destroy_icon_window( display, data );
1531 data->managed = FALSE;
1532 RemovePropA( data->hwnd, managed_prop );
1536 else /* new top level window */
1538 /* FIXME: we ignore errors since we can't really recover anyway */
1539 create_whole_window( display, data );
1544 /*****************************************************************
1545 * SetFocus (X11DRV.@)
1548 * Explicit colormap management seems to work only with OLVWM.
1550 void X11DRV_SetFocus( HWND hwnd )
1552 Display *display = thread_display();
1553 struct x11drv_win_data *data;
1554 XWindowChanges changes;
1556 /* If setting the focus to 0, uninstall the colormap */
1557 if (!hwnd && root_window == DefaultRootWindow(display))
1560 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1561 XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1562 wine_tsx11_unlock();
1566 hwnd = GetAncestor( hwnd, GA_ROOT );
1568 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1569 if (data->managed || !data->whole_window) return;
1571 /* Set X focus and install colormap */
1573 changes.stack_mode = Above;
1574 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
1575 if (root_window == DefaultRootWindow(display))
1577 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1578 /* FIXME: this is not entirely correct */
1579 XSetInputFocus( display, data->whole_window, RevertToParent,
1581 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1582 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1583 XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1585 wine_tsx11_unlock();
1589 /**********************************************************************
1590 * SetWindowIcon (X11DRV.@)
1592 * hIcon or hIconSm has changed (or is being initialised for the
1593 * first time). Complete the X11 driver-specific initialisation
1594 * and set the window hints.
1596 * This is not entirely correct, may need to create
1597 * an icon window and set the pixmap as a background
1599 void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
1601 Display *display = thread_display();
1602 struct x11drv_win_data *data;
1604 if (type != ICON_BIG) return; /* nothing to do here */
1606 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1607 if (!data->whole_window) return;
1608 if (!data->managed) return;
1612 set_icon_hints( display, data, icon );
1614 XSetWMHints( display, data->whole_window, data->wm_hints );
1615 wine_tsx11_unlock();
1620 /***********************************************************************
1621 * SetWindowRgn (X11DRV.@)
1623 * Assign specified region to window (for non-rectangular windows)
1625 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1627 struct x11drv_win_data *data;
1629 if ((data = X11DRV_get_win_data( hwnd )))
1631 sync_window_region( thread_display(), data, hrgn );
1633 else if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
1635 FIXME( "not supported on other thread window %p\n", hwnd );
1636 SetLastError( ERROR_INVALID_WINDOW_HANDLE );