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 );
615 TRACE( "created %lx\n", data->icon_window );
616 SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window );
617 return data->icon_window;
622 /***********************************************************************
623 * destroy_icon_window
625 static void destroy_icon_window( Display *display, struct x11drv_win_data *data )
627 if (!data->icon_window) return;
628 if (x11drv_thread_data()->cursor_window == data->icon_window)
629 x11drv_thread_data()->cursor_window = None;
631 XDeleteContext( display, data->icon_window, winContext );
632 XDestroyWindow( display, data->icon_window );
633 data->icon_window = 0;
635 RemovePropA( data->hwnd, icon_window_prop );
639 /***********************************************************************
642 * Set the icon wm hints
644 static void set_icon_hints( Display *display, struct x11drv_win_data *data, HICON hIcon )
646 XWMHints *hints = data->wm_hints;
648 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
649 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
650 data->hWMIconBitmap = 0;
651 data->hWMIconMask = 0;
655 if (!data->icon_window) create_icon_window( display, data );
656 hints->icon_window = data->icon_window;
657 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
667 GetIconInfo(hIcon, &ii);
669 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
672 rcMask.right = bmMask.bmWidth;
673 rcMask.bottom = bmMask.bmHeight;
675 hDC = CreateCompatibleDC(0);
676 hbmOrig = SelectObject(hDC, ii.hbmMask);
677 InvertRect(hDC, &rcMask);
678 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
679 SelectObject(hDC, hbmOrig);
682 data->hWMIconBitmap = ii.hbmColor;
683 data->hWMIconMask = ii.hbmMask;
685 hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap);
686 hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask);
687 destroy_icon_window( display, data );
688 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
693 /***********************************************************************
696 * set the window size hints
698 static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style )
700 XSizeHints* size_hints;
702 if (!(size_hints = XAllocSizeHints())) return;
704 /* don't update size hints if window is not in normal state */
705 if (!(style & (WS_MINIMIZE | WS_MAXIMIZE)))
707 if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */
709 size_hints->win_gravity = StaticGravity;
710 size_hints->x = data->whole_rect.left;
711 size_hints->y = data->whole_rect.top;
712 size_hints->flags |= PWinGravity | PPosition;
715 if (!is_window_resizable( data, style ))
717 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
718 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
719 size_hints->min_width = size_hints->max_width;
720 size_hints->min_height = size_hints->max_height;
721 size_hints->flags |= PMinSize | PMaxSize;
724 XSetWMNormalHints( display, data->whole_window, size_hints );
729 /***********************************************************************
732 * get the name of the current process for setting class hints
734 static char *get_process_name(void)
740 WCHAR module[MAX_PATH];
741 DWORD len = GetModuleFileNameW( 0, module, MAX_PATH );
742 if (len && len < MAX_PATH)
745 WCHAR *p, *appname = module;
747 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
748 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
749 len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL );
750 if ((ptr = HeapAlloc( GetProcessHeap(), 0, len )))
752 WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL );
761 /***********************************************************************
762 * set_initial_wm_hints
764 * Set the window manager hints that don't change over the lifetime of a window.
766 static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data )
771 XClassHint *class_hints;
772 char *process_name = get_process_name();
778 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
779 protocols[i++] = x11drv_atom(_NET_WM_PING);
780 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
781 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
782 XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
785 if ((class_hints = XAllocClassHint()))
787 static char wine[] = "Wine";
789 class_hints->res_name = process_name;
790 class_hints->res_class = wine;
791 XSetClassHint( display, data->whole_window, class_hints );
792 XFree( class_hints );
795 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
796 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
797 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
799 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
800 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
802 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
803 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
805 data->wm_hints = XAllocWMHints();
810 HICON icon = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 );
811 if (!icon) icon = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON );
812 data->wm_hints->flags = 0;
813 set_icon_hints( display, data, icon );
818 /***********************************************************************
819 * X11DRV_set_wm_hints
821 * Set the window manager hints for a newly-created window
823 void X11DRV_set_wm_hints( Display *display, struct x11drv_win_data *data )
828 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
829 DWORD ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
830 HWND owner = GetWindow( data->hwnd, GW_OWNER );
832 if (data->hwnd == GetDesktopWindow())
834 /* force some styles for the desktop to get the correct decorations */
835 style |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
839 /* transient for hint */
842 Window owner_win = X11DRV_get_whole_window( owner );
844 XSetTransientForHint( display, data->whole_window, owner_win );
846 group_leader = owner_win;
848 else group_leader = data->whole_window;
853 set_size_hints( display, data, style );
855 /* set the WM_WINDOW_TYPE */
856 window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
857 if (style & WS_THICKFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
858 else if (style & WS_DLGFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
859 else if (ex_style & WS_EX_DLGMODALFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
860 #if 0 /* many window managers don't handle utility windows very well */
861 else if (ex_style & WS_EX_TOOLWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
864 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
865 XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1);
867 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
868 mwm_hints.decorations = get_mwm_decorations( style, ex_style );
869 mwm_hints.functions = MWM_FUNC_MOVE;
870 if (is_window_resizable( data, style )) mwm_hints.functions |= MWM_FUNC_RESIZE;
871 if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
872 if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
873 if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
875 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
876 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
877 (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
882 data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint;
883 data->wm_hints->input = !(style & WS_DISABLED);
884 data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
885 data->wm_hints->window_group = group_leader;
886 XSetWMHints( display, data->whole_window, data->wm_hints );
893 /***********************************************************************
894 * X11DRV_window_to_X_rect
896 * Convert a rect from client to X window coordinates
898 void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect )
902 if (!data->managed) return;
903 if (IsRectEmpty( rect )) return;
905 get_x11_rect_offset( data, &rc );
907 rect->left -= rc.left;
908 rect->right -= rc.right;
910 rect->bottom -= rc.bottom;
911 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
912 if (rect->left >= rect->right) rect->right = rect->left + 1;
916 /***********************************************************************
917 * X11DRV_X_to_window_rect
919 * Opposite of X11DRV_window_to_X_rect
921 void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect )
925 if (!data->managed) return;
926 if (IsRectEmpty( rect )) return;
928 get_x11_rect_offset( data, &rc );
930 rect->left += rc.left;
931 rect->right += rc.right;
933 rect->bottom += rc.bottom;
934 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
935 if (rect->left >= rect->right) rect->right = rect->left + 1;
939 /***********************************************************************
940 * X11DRV_sync_window_position
942 * Synchronize the X window position with the Windows one
944 void X11DRV_sync_window_position( Display *display, struct x11drv_win_data *data,
945 UINT swp_flags, const RECT *old_client_rect,
946 const RECT *old_whole_rect )
948 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
949 XWindowChanges changes;
950 int mask = CWWidth | CWHeight;
952 if (data->managed && data->iconic) return;
954 if ((changes.width = data->whole_rect.right - data->whole_rect.left) <= 0) changes.width = 1;
955 if ((changes.height = data->whole_rect.bottom - data->whole_rect.top) <= 0) changes.height = 1;
957 /* only the size is allowed to change for the desktop window */
958 if (data->whole_window != root_window)
960 changes.x = data->whole_rect.left - virtual_screen_rect.left;
961 changes.y = data->whole_rect.top - virtual_screen_rect.top;
965 if (!(swp_flags & SWP_NOZORDER))
967 /* find window that this one must be after */
968 HWND prev = GetWindow( data->hwnd, GW_HWNDPREV );
969 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
970 prev = GetWindow( prev, GW_HWNDPREV );
971 if (!prev) /* top child */
973 changes.stack_mode = Above;
976 /* should use stack_mode Below but most window managers don't get it right */
977 /* and Above with a sibling doesn't work so well either, so we ignore it */
980 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
981 data->hwnd, data->whole_window, data->whole_rect.left, data->whole_rect.top,
982 data->whole_rect.right - data->whole_rect.left,
983 data->whole_rect.bottom - data->whole_rect.top, changes.sibling, mask );
986 set_size_hints( display, data, style );
987 XReconfigureWMWindow( display, data->whole_window,
988 DefaultScreen(display), mask, &changes );
993 /***********************************************************************
994 * X11DRV_sync_client_position
996 * Synchronize the X client window position with the Windows one
998 void X11DRV_sync_client_position( Display *display, struct x11drv_win_data *data,
999 UINT swp_flags, const RECT *old_client_rect,
1000 const RECT *old_whole_rect )
1003 XWindowChanges changes;
1004 RECT old = *old_client_rect;
1005 RECT new = data->client_rect;
1007 OffsetRect( &old, -old_whole_rect->left, -old_whole_rect->top );
1008 OffsetRect( &new, -data->whole_rect.left, -data->whole_rect.top );
1009 if (!(mask = get_window_changes( &changes, &old, &new ))) return;
1011 if (data->client_window)
1013 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1014 data->client_window, new.left, new.top,
1015 new.right - new.left, new.bottom - new.top, mask );
1017 XConfigureWindow( display, data->client_window, mask, &changes );
1018 wine_tsx11_unlock();
1021 if (data->gl_drawable && (mask & (CWWidth|CWHeight))) sync_gl_drawable( display, data );
1023 /* make sure the changes get to the server before we start painting */
1024 if (data->client_window || data->gl_drawable)
1028 wine_tsx11_unlock();
1033 /**********************************************************************
1034 * create_whole_window
1036 * Create the whole X window for a given window
1038 static Window create_whole_window( Display *display, struct x11drv_win_data *data )
1041 XSetWindowAttributes attr;
1046 if (!(cx = data->window_rect.right - data->window_rect.left)) cx = 1;
1047 if (!(cy = data->window_rect.bottom - data->window_rect.top)) cy = 1;
1049 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1051 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1052 data->managed = TRUE;
1053 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1056 mask = get_window_attributes( display, data, &attr );
1060 data->whole_rect = data->window_rect;
1061 data->whole_window = XCreateWindow( display, root_window,
1062 data->window_rect.left - virtual_screen_rect.left,
1063 data->window_rect.top - virtual_screen_rect.top,
1064 cx, cy, 0, screen_depth, InputOutput,
1065 visual, mask, &attr );
1067 if (data->whole_window) XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
1068 wine_tsx11_unlock();
1070 if (!data->whole_window) return 0;
1072 if (!create_client_window( display, data, NULL ))
1075 XDeleteContext( display, data->whole_window, winContext );
1076 XDestroyWindow( display, data->whole_window );
1077 data->whole_window = 0;
1078 wine_tsx11_unlock();
1082 xim = x11drv_thread_data()->xim;
1083 if (xim) data->xic = X11DRV_CreateIC( xim, display, data->whole_window );
1085 set_initial_wm_hints( display, data );
1086 X11DRV_set_wm_hints( display, data );
1088 SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
1090 /* set the window text */
1091 if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
1092 sync_window_text( display, data->whole_window, text );
1094 /* set the window region */
1095 if ((hrgn = CreateRectRgn( 0, 0, 0, 0 )))
1097 if (GetWindowRgn( data->hwnd, hrgn ) != ERROR) sync_window_region( display, data, hrgn );
1098 DeleteObject( hrgn );
1100 return data->whole_window;
1104 /**********************************************************************
1105 * destroy_whole_window
1107 * Destroy the whole X window for a given window.
1109 static void destroy_whole_window( Display *display, struct x11drv_win_data *data, BOOL already_destroyed )
1111 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1113 if (!data->whole_window) return;
1115 TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1116 if (thread_data->cursor_window == data->whole_window ||
1117 thread_data->cursor_window == data->client_window)
1118 thread_data->cursor_window = None;
1120 XDeleteContext( display, data->whole_window, winContext );
1121 XDeleteContext( display, data->client_window, winContext );
1122 if (!already_destroyed) XDestroyWindow( display, data->whole_window );
1123 data->whole_window = data->client_window = 0;
1124 data->wm_state = WithdrawnState;
1125 data->net_wm_state = 0;
1126 data->mapped = FALSE;
1129 XUnsetICFocus( data->xic );
1130 XDestroyIC( data->xic );
1133 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1135 XFree( data->wm_hints );
1136 data->wm_hints = NULL;
1137 wine_tsx11_unlock();
1138 RemovePropA( data->hwnd, whole_window_prop );
1139 RemovePropA( data->hwnd, client_window_prop );
1143 /*****************************************************************
1144 * SetWindowText (X11DRV.@)
1146 void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
1148 Display *display = thread_display();
1151 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display))
1152 sync_window_text( display, win, text );
1156 /***********************************************************************
1157 * DestroyWindow (X11DRV.@)
1159 void X11DRV_DestroyWindow( HWND hwnd )
1161 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1162 Display *display = thread_data->display;
1163 struct x11drv_win_data *data;
1165 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1169 destroy_glxpixmap(display, data->gl_drawable);
1171 XFreePixmap(display, data->pixmap);
1172 wine_tsx11_unlock();
1174 else if (data->gl_drawable)
1177 XDestroyWindow(display, data->gl_drawable);
1178 wine_tsx11_unlock();
1181 destroy_whole_window( display, data, FALSE );
1182 destroy_icon_window( display, data );
1187 XFreeColormap( display, data->colormap );
1188 wine_tsx11_unlock();
1191 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
1192 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
1193 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
1195 XDeleteContext( display, (XID)hwnd, win_data_context );
1196 wine_tsx11_unlock();
1197 HeapFree( GetProcessHeap(), 0, data );
1201 /***********************************************************************
1202 * X11DRV_DestroyNotify
1204 void X11DRV_DestroyNotify( HWND hwnd, XEvent *event )
1206 Display *display = event->xdestroywindow.display;
1207 struct x11drv_win_data *data;
1209 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1211 FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window );
1212 destroy_whole_window( display, data, TRUE );
1216 static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
1218 struct x11drv_win_data *data;
1220 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
1224 if (!winContext) winContext = XUniqueContext();
1225 if (!win_data_context) win_data_context = XUniqueContext();
1226 XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
1227 wine_tsx11_unlock();
1233 /* initialize the desktop window id in the desktop manager process */
1234 static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd )
1236 struct x11drv_win_data *data;
1239 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1241 visualid = XVisualIDFromVisual(visual);
1242 wine_tsx11_unlock();
1243 data->whole_window = data->client_window = root_window;
1244 data->managed = TRUE;
1245 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1246 SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
1247 SetPropA( data->hwnd, client_window_prop, (HANDLE)root_window );
1248 set_initial_wm_hints( display, data );
1252 /**********************************************************************
1253 * CreateDesktopWindow (X11DRV.@)
1255 BOOL X11DRV_CreateDesktopWindow( HWND hwnd )
1257 unsigned int width, height;
1259 /* retrieve the real size of the desktop */
1260 SERVER_START_REQ( get_window_rectangles )
1263 wine_server_call( req );
1264 width = reply->window.right - reply->window.left;
1265 height = reply->window.bottom - reply->window.top;
1269 if (!width && !height) /* not initialized yet */
1271 SERVER_START_REQ( set_window_pos )
1275 req->flags = SWP_NOZORDER;
1276 req->window.left = virtual_screen_rect.left;
1277 req->window.top = virtual_screen_rect.top;
1278 req->window.right = virtual_screen_rect.right;
1279 req->window.bottom = virtual_screen_rect.bottom;
1280 req->client = req->window;
1281 wine_server_call( req );
1287 Window win = (Window)GetPropA( hwnd, whole_window_prop );
1288 if (win && win != root_window) X11DRV_init_desktop( win, width, height );
1294 /**********************************************************************
1295 * CreateWindow (X11DRV.@)
1297 BOOL X11DRV_CreateWindow( HWND hwnd )
1299 Display *display = thread_display();
1301 if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( display ))
1303 /* the desktop win data can't be created lazily */
1304 if (!create_desktop_win_data( display, hwnd )) return FALSE;
1310 /***********************************************************************
1311 * X11DRV_get_win_data
1313 * Return the X11 data structure associated with a window.
1315 struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1319 if (!hwnd || XFindContext( thread_display(), (XID)hwnd, win_data_context, &data )) data = NULL;
1320 return (struct x11drv_win_data *)data;
1324 /***********************************************************************
1325 * X11DRV_create_win_data
1327 * Create an X11 data window structure for an existing window.
1329 struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd )
1331 Display *display = thread_display();
1332 struct x11drv_win_data *data;
1335 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
1336 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1338 GetWindowRect( hwnd, &data->window_rect );
1339 MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 );
1340 data->whole_rect = data->window_rect;
1341 GetClientRect( hwnd, &data->client_rect );
1342 MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 );
1344 if (parent == GetDesktopWindow())
1346 if (!create_whole_window( display, data ))
1348 HeapFree( GetProcessHeap(), 0, data );
1351 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1352 hwnd, data->whole_window, data->client_window, wine_dbgstr_rect( &data->window_rect ),
1353 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
1359 /***********************************************************************
1360 * X11DRV_get_whole_window
1362 * Return the X window associated with the full area of a window
1364 Window X11DRV_get_whole_window( HWND hwnd )
1366 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1370 if (hwnd == GetDesktopWindow()) return root_window;
1371 return (Window)GetPropA( hwnd, whole_window_prop );
1373 return data->whole_window;
1377 /***********************************************************************
1378 * X11DRV_get_client_window
1380 * Return the X window associated with the client area of a window
1382 Window X11DRV_get_client_window( HWND hwnd )
1384 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1388 if (hwnd == GetDesktopWindow()) return root_window;
1389 return (Window)GetPropA( hwnd, client_window_prop );
1391 return data->client_window;
1395 /***********************************************************************
1398 * Return the X input context associated with a window
1400 XIC X11DRV_get_ic( HWND hwnd )
1402 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1404 if (!data) return 0;
1409 /***********************************************************************
1410 * X11DRV_GetDC (X11DRV.@)
1412 void X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect,
1413 const RECT *top_rect, DWORD flags )
1415 struct x11drv_escape_set_drawable escape;
1416 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1418 escape.code = X11DRV_SET_DRAWABLE;
1419 escape.mode = IncludeInferiors;
1420 escape.fbconfig_id = 0;
1421 escape.gl_drawable = 0;
1424 if (top == hwnd && data && IsIconic( hwnd ) && data->icon_window)
1426 escape.drawable = data->icon_window;
1428 else if (top == hwnd && (flags & DCX_WINDOW))
1430 escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd );
1434 escape.drawable = X11DRV_get_client_window( top );
1435 escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop );
1436 escape.gl_drawable = data ? data->gl_drawable : (Drawable)GetPropA( hwnd, gl_drawable_prop );
1437 escape.pixmap = data ? data->pixmap : (Pixmap)GetPropA( hwnd, pixmap_prop );
1438 if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren;
1441 escape.dc_rect.left = win_rect->left - top_rect->left;
1442 escape.dc_rect.top = win_rect->top - top_rect->top;
1443 escape.dc_rect.right = win_rect->right - top_rect->left;
1444 escape.dc_rect.bottom = win_rect->bottom - top_rect->top;
1445 escape.drawable_rect.left = top_rect->left;
1446 escape.drawable_rect.top = top_rect->top;
1447 escape.drawable_rect.right = top_rect->right;
1448 escape.drawable_rect.bottom = top_rect->bottom;
1450 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1454 /***********************************************************************
1455 * X11DRV_ReleaseDC (X11DRV.@)
1457 void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
1459 struct x11drv_escape_set_drawable escape;
1461 escape.code = X11DRV_SET_DRAWABLE;
1462 escape.drawable = root_window;
1463 escape.mode = IncludeInferiors;
1464 escape.drawable_rect = virtual_screen_rect;
1465 SetRect( &escape.dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left,
1466 virtual_screen_rect.bottom - virtual_screen_rect.top );
1467 escape.fbconfig_id = 0;
1468 escape.gl_drawable = 0;
1470 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1474 /***********************************************************************
1475 * SetCapture (X11DRV.@)
1477 void X11DRV_SetCapture( HWND hwnd, UINT flags )
1479 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1481 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
1485 Window grab_win = X11DRV_get_client_window( GetAncestor( hwnd, GA_ROOT ) );
1487 if (!grab_win) return;
1489 XFlush( gdi_display );
1490 XGrabPointer( thread_data->display, grab_win, False,
1491 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1492 GrabModeAsync, GrabModeAsync, None, None, CurrentTime );
1493 wine_tsx11_unlock();
1494 thread_data->grab_window = grab_win;
1496 else /* release capture */
1499 XFlush( gdi_display );
1500 XUngrabPointer( thread_data->display, CurrentTime );
1501 wine_tsx11_unlock();
1502 thread_data->grab_window = None;
1507 /*****************************************************************
1508 * SetParent (X11DRV.@)
1510 void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
1512 Display *display = thread_display();
1513 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1516 if (parent == old_parent) return;
1518 if (parent != GetDesktopWindow()) /* a child window */
1520 if (old_parent == GetDesktopWindow())
1522 /* destroy the old X windows */
1523 destroy_whole_window( display, data, FALSE );
1524 destroy_icon_window( display, data );
1527 data->managed = FALSE;
1528 RemovePropA( data->hwnd, managed_prop );
1532 else /* new top level window */
1534 /* FIXME: we ignore errors since we can't really recover anyway */
1535 create_whole_window( display, data );
1540 /*****************************************************************
1541 * SetFocus (X11DRV.@)
1544 * Explicit colormap management seems to work only with OLVWM.
1546 void X11DRV_SetFocus( HWND hwnd )
1548 Display *display = thread_display();
1549 struct x11drv_win_data *data;
1550 XWindowChanges changes;
1552 /* If setting the focus to 0, uninstall the colormap */
1553 if (!hwnd && root_window == DefaultRootWindow(display))
1556 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1557 XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1558 wine_tsx11_unlock();
1562 hwnd = GetAncestor( hwnd, GA_ROOT );
1564 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1565 if (data->managed || !data->whole_window) return;
1567 /* Set X focus and install colormap */
1569 changes.stack_mode = Above;
1570 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
1571 if (root_window == DefaultRootWindow(display))
1573 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1574 /* FIXME: this is not entirely correct */
1575 XSetInputFocus( display, data->whole_window, RevertToParent,
1577 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1578 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1579 XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1581 wine_tsx11_unlock();
1585 /**********************************************************************
1586 * SetWindowIcon (X11DRV.@)
1588 * hIcon or hIconSm has changed (or is being initialised for the
1589 * first time). Complete the X11 driver-specific initialisation
1590 * and set the window hints.
1592 * This is not entirely correct, may need to create
1593 * an icon window and set the pixmap as a background
1595 void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
1597 Display *display = thread_display();
1598 struct x11drv_win_data *data;
1600 if (type != ICON_BIG) return; /* nothing to do here */
1602 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1603 if (!data->whole_window) return;
1604 if (!data->managed) return;
1608 set_icon_hints( display, data, icon );
1610 XSetWMHints( display, data->whole_window, data->wm_hints );
1611 wine_tsx11_unlock();
1616 /***********************************************************************
1617 * SetWindowRgn (X11DRV.@)
1619 * Assign specified region to window (for non-rectangular windows)
1621 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1623 struct x11drv_win_data *data;
1625 if ((data = X11DRV_get_win_data( hwnd )))
1627 sync_window_region( thread_display(), data, hrgn );
1629 else if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
1631 FIXME( "not supported on other thread window %p\n", hwnd );
1632 SetLastError( ERROR_INVALID_WINDOW_HANDLE );