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 (!decorated_mode) return ret;
153 if (ex_style & WS_EX_TOOLWINDOW) return 0;
155 if ((style & WS_CAPTION) == WS_CAPTION)
157 ret |= MWM_DECOR_TITLE | MWM_DECOR_BORDER;
158 if (style & WS_SYSMENU) ret |= MWM_DECOR_MENU;
159 if (style & WS_MINIMIZEBOX) ret |= MWM_DECOR_MINIMIZE;
160 if (style & WS_MAXIMIZEBOX) ret |= MWM_DECOR_MAXIMIZE;
162 if (ex_style & WS_EX_DLGMODALFRAME) ret |= MWM_DECOR_BORDER;
163 else if (style & WS_THICKFRAME) ret |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
164 else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) ret |= MWM_DECOR_BORDER;
169 /***********************************************************************
170 * get_x11_rect_offset
172 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
174 static void get_x11_rect_offset( struct x11drv_win_data *data, RECT *rect )
176 DWORD style, ex_style, style_mask = 0, ex_style_mask = 0;
179 rect->top = rect->bottom = rect->left = rect->right = 0;
181 style = GetWindowLongW( data->hwnd, GWL_STYLE );
182 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
183 decor = get_mwm_decorations( style, ex_style );
185 if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION;
186 if (decor & MWM_DECOR_BORDER)
188 style_mask |= WS_DLGFRAME | WS_THICKFRAME;
189 ex_style_mask |= WS_EX_DLGMODALFRAME;
192 AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask );
196 /***********************************************************************
197 * get_window_attributes
199 * Fill the window attributes structure for an X window.
201 static int get_window_attributes( Display *display, struct x11drv_win_data *data,
202 XSetWindowAttributes *attr )
204 attr->override_redirect = !data->managed;
205 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
206 attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0);
207 attr->cursor = x11drv_thread_data()->cursor;
208 attr->bit_gravity = NorthWestGravity;
209 attr->backing_store = NotUseful;
210 attr->event_mask = (ExposureMask | PointerMotionMask |
211 ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
212 KeyPressMask | KeyReleaseMask | FocusChangeMask | KeymapStateMask);
213 if (data->managed) attr->event_mask |= StructureNotifyMask | PropertyChangeMask;
215 return (CWOverrideRedirect | CWSaveUnder | CWColormap | CWCursor |
216 CWEventMask | CWBitGravity | CWBackingStore);
220 /***********************************************************************
221 * create_client_window
223 static Window create_client_window( Display *display, struct x11drv_win_data *data, XVisualInfo *vis )
226 XSetWindowAttributes attr;
229 attr.bit_gravity = NorthWestGravity;
230 attr.win_gravity = NorthWestGravity;
231 attr.backing_store = NotUseful;
232 attr.event_mask = (ExposureMask | PointerMotionMask |
233 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
234 mask = CWEventMask | CWBitGravity | CWWinGravity | CWBackingStore;
236 if ((cx = data->client_rect.right - data->client_rect.left) <= 0) cx = 1;
237 if ((cy = data->client_rect.bottom - data->client_rect.top) <= 0) cy = 1;
243 attr.colormap = XCreateColormap( display, root_window, vis->visual,
244 (vis->class == PseudoColor || vis->class == GrayScale ||
245 vis->class == DirectColor) ? AllocAll : AllocNone );
249 client = XCreateWindow( display, data->whole_window,
250 data->client_rect.left - data->whole_rect.left,
251 data->client_rect.top - data->whole_rect.top,
252 cx, cy, 0, screen_depth, InputOutput,
253 vis ? vis->visual : visual, mask, &attr );
260 if (data->client_window)
262 struct x11drv_thread_data *thread_data = x11drv_thread_data();
263 if (thread_data->cursor_window == data->client_window) thread_data->cursor_window = None;
264 XDeleteContext( display, data->client_window, winContext );
265 XDestroyWindow( display, data->client_window );
267 data->client_window = client;
269 if (data->colormap) XFreeColormap( display, data->colormap );
270 data->colormap = vis ? attr.colormap : 0;
272 XMapWindow( display, data->client_window );
273 XSaveContext( display, data->client_window, winContext, (char *)data->hwnd );
276 SetPropA( data->hwnd, client_window_prop, (HANDLE)data->client_window );
277 return data->client_window;
281 /***********************************************************************
282 * X11DRV_sync_window_style
284 * Change the X window attributes when the window style has changed.
286 void X11DRV_sync_window_style( Display *display, struct x11drv_win_data *data )
288 if (data->whole_window != root_window)
290 XSetWindowAttributes attr;
291 int mask = get_window_attributes( display, data, &attr );
294 XChangeWindowAttributes( display, data->whole_window, mask, &attr );
300 /***********************************************************************
303 * Update the X11 window region.
305 static void sync_window_region( Display *display, struct x11drv_win_data *data, HRGN hrgn )
307 #ifdef HAVE_LIBXSHAPE
308 if (!data->whole_window) return;
313 XShapeCombineMask( display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet );
318 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
322 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
323 data->window_rect.left - data->whole_rect.left,
324 data->window_rect.top - data->whole_rect.top,
325 (XRectangle *)pRegionData->Buffer,
326 pRegionData->rdh.nCount, ShapeSet, YXBanded );
328 HeapFree(GetProcessHeap(), 0, pRegionData);
331 #endif /* HAVE_LIBXSHAPE */
335 /***********************************************************************
338 static void sync_window_text( Display *display, Window win, const WCHAR *text )
341 char *buffer, *utf8_buffer;
344 /* allocate new buffer for window text */
345 count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
346 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) return;
347 WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
349 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
350 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
352 HeapFree( GetProcessHeap(), 0, buffer );
355 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
358 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
360 XSetWMName( display, win, &prop );
361 XSetWMIconName( display, win, &prop );
365 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
366 according to the standard
367 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
369 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
370 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
373 HeapFree( GetProcessHeap(), 0, utf8_buffer );
374 HeapFree( GetProcessHeap(), 0, buffer );
378 /***********************************************************************
379 * X11DRV_set_win_format
381 BOOL X11DRV_set_win_format( HWND hwnd, XID fbconfig_id )
383 Display *display = thread_display();
384 struct x11drv_win_data *data;
388 if (!(data = X11DRV_get_win_data(hwnd)) &&
389 !(data = X11DRV_create_win_data(hwnd))) return FALSE;
391 if (data->fbconfig_id) return FALSE; /* can't change it twice */
394 vis = visual_from_fbconfig_id(fbconfig_id);
396 if (!vis) return FALSE;
398 if (data->whole_window)
400 Window client = data->client_window;
402 if (vis->visualid != XVisualIDFromVisual(visual))
404 client = create_client_window( display, data, vis );
405 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client, data->hwnd, fbconfig_id );
410 if (client) goto done;
414 w = data->client_rect.right - data->client_rect.left;
415 h = data->client_rect.bottom - data->client_rect.top;
420 #ifdef SONAME_LIBXCOMPOSITE
423 XSetWindowAttributes attrib;
424 Window parent = X11DRV_get_whole_window( GetAncestor( hwnd, GA_ROOT ));
426 if (!parent) parent = root_window;
428 data->colormap = XCreateColormap(display, parent, vis->visual,
429 (vis->class == PseudoColor ||
430 vis->class == GrayScale ||
431 vis->class == DirectColor) ?
432 AllocAll : AllocNone);
433 attrib.override_redirect = True;
434 attrib.colormap = data->colormap;
435 XInstallColormap(gdi_display, attrib.colormap);
437 data->gl_drawable = XCreateWindow(display, parent, -w, 0, w, h, 0,
438 vis->depth, InputOutput, vis->visual,
439 CWColormap | CWOverrideRedirect,
441 if(data->gl_drawable)
443 pXCompositeRedirectWindow(display, data->gl_drawable,
444 CompositeRedirectManual);
445 XMapWindow(display, data->gl_drawable);
453 WARN("XComposite is not available, using GLXPixmap hack\n");
456 data->pixmap = XCreatePixmap(display, root_window, w, h, vis->depth);
464 data->gl_drawable = create_glxpixmap(display, vis, data->pixmap);
465 if(!data->gl_drawable)
467 XFreePixmap(display, data->pixmap);
472 if (data->pixmap) SetPropA(hwnd, pixmap_prop, (HANDLE)data->pixmap);
475 if (!data->gl_drawable) return FALSE;
477 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
478 data->gl_drawable, fbconfig_id);
479 SetPropA(hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
482 data->fbconfig_id = fbconfig_id;
483 SetPropA(hwnd, fbconfig_id_prop, (HANDLE)data->fbconfig_id);
487 WIN_invalidate_dce( hwnd, NULL );
491 /***********************************************************************
494 static void sync_gl_drawable(Display *display, struct x11drv_win_data *data)
496 int w = data->client_rect.right - data->client_rect.left;
497 int h = data->client_rect.bottom - data->client_rect.top;
505 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data->gl_drawable, w, h);
506 #ifdef SONAME_LIBXCOMPOSITE
510 XMoveResizeWindow(display, data->gl_drawable, -w, 0, w, h);
518 vis = visual_from_fbconfig_id(data->fbconfig_id);
525 pix = XCreatePixmap(display, root_window, w, h, vis->depth);
528 ERR("Failed to create pixmap for offscreen rendering\n");
534 glxp = create_glxpixmap(display, vis, pix);
537 ERR("Failed to create drawable for offscreen rendering\n");
538 XFreePixmap(display, pix);
546 mark_drawable_dirty(data->gl_drawable, glxp);
548 XFreePixmap(display, data->pixmap);
549 destroy_glxpixmap(display, data->gl_drawable);
552 data->gl_drawable = glxp;
557 SetPropA(data->hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
558 SetPropA(data->hwnd, pixmap_prop, (HANDLE)data->pixmap);
562 /***********************************************************************
565 * fill the window changes structure
567 static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
571 if (old->right - old->left != new->right - new->left )
573 if ((changes->width = new->right - new->left) <= 0) changes->width = 1;
576 if (old->bottom - old->top != new->bottom - new->top)
578 if ((changes->height = new->bottom - new->top) <= 0) changes->height = 1;
581 if (old->left != new->left)
583 changes->x = new->left;
586 if (old->top != new->top)
588 changes->y = new->top;
595 /***********************************************************************
598 static Window create_icon_window( Display *display, struct x11drv_win_data *data )
600 XSetWindowAttributes attr;
602 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
603 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
604 attr.bit_gravity = NorthWestGravity;
605 attr.backing_store = NotUseful/*WhenMapped*/;
606 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
609 data->icon_window = XCreateWindow( display, root_window, 0, 0,
610 GetSystemMetrics( SM_CXICON ),
611 GetSystemMetrics( SM_CYICON ),
614 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
615 XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd );
616 XFlush( display ); /* make sure the window exists before we start painting to it */
619 TRACE( "created %lx\n", data->icon_window );
620 SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window );
621 return data->icon_window;
626 /***********************************************************************
627 * destroy_icon_window
629 static void destroy_icon_window( Display *display, struct x11drv_win_data *data )
631 if (!data->icon_window) return;
632 if (x11drv_thread_data()->cursor_window == data->icon_window)
633 x11drv_thread_data()->cursor_window = None;
635 XDeleteContext( display, data->icon_window, winContext );
636 XDestroyWindow( display, data->icon_window );
637 data->icon_window = 0;
639 RemovePropA( data->hwnd, icon_window_prop );
643 /***********************************************************************
646 * Set the icon wm hints
648 static void set_icon_hints( Display *display, struct x11drv_win_data *data, HICON hIcon )
650 XWMHints *hints = data->wm_hints;
652 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
653 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
654 data->hWMIconBitmap = 0;
655 data->hWMIconMask = 0;
659 if (!data->icon_window) create_icon_window( display, data );
660 hints->icon_window = data->icon_window;
661 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
671 GetIconInfo(hIcon, &ii);
673 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
676 rcMask.right = bmMask.bmWidth;
677 rcMask.bottom = bmMask.bmHeight;
679 hDC = CreateCompatibleDC(0);
680 hbmOrig = SelectObject(hDC, ii.hbmMask);
681 InvertRect(hDC, &rcMask);
682 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
683 SelectObject(hDC, hbmOrig);
686 data->hWMIconBitmap = ii.hbmColor;
687 data->hWMIconMask = ii.hbmMask;
689 hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap);
690 hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask);
691 destroy_icon_window( display, data );
692 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
697 /***********************************************************************
700 * set the window size hints
702 static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style )
704 XSizeHints* size_hints;
706 if (!(size_hints = XAllocSizeHints())) return;
708 /* don't update size hints if window is not in normal state */
709 if (!(style & (WS_MINIMIZE | WS_MAXIMIZE)))
711 if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */
713 size_hints->win_gravity = StaticGravity;
714 size_hints->x = data->whole_rect.left;
715 size_hints->y = data->whole_rect.top;
716 size_hints->flags |= PWinGravity | PPosition;
719 if (!is_window_resizable( data, style ))
721 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
722 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
723 size_hints->min_width = size_hints->max_width;
724 size_hints->min_height = size_hints->max_height;
725 size_hints->flags |= PMinSize | PMaxSize;
728 XSetWMNormalHints( display, data->whole_window, size_hints );
733 /***********************************************************************
736 * get the name of the current process for setting class hints
738 static char *get_process_name(void)
744 WCHAR module[MAX_PATH];
745 DWORD len = GetModuleFileNameW( 0, module, MAX_PATH );
746 if (len && len < MAX_PATH)
749 WCHAR *p, *appname = module;
751 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
752 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
753 len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL );
754 if ((ptr = HeapAlloc( GetProcessHeap(), 0, len )))
756 WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL );
765 /***********************************************************************
766 * set_initial_wm_hints
768 * Set the window manager hints that don't change over the lifetime of a window.
770 static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data )
775 XClassHint *class_hints;
776 char *process_name = get_process_name();
782 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
783 protocols[i++] = x11drv_atom(_NET_WM_PING);
784 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
785 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
786 XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
789 if ((class_hints = XAllocClassHint()))
791 static char wine[] = "Wine";
793 class_hints->res_name = process_name;
794 class_hints->res_class = wine;
795 XSetClassHint( display, data->whole_window, class_hints );
796 XFree( class_hints );
799 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
800 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
801 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
803 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
804 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
806 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
807 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
809 data->wm_hints = XAllocWMHints();
814 HICON icon = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 );
815 if (!icon) icon = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON );
816 data->wm_hints->flags = 0;
817 set_icon_hints( display, data, icon );
822 /***********************************************************************
823 * X11DRV_set_wm_hints
825 * Set the window manager hints for a newly-created window
827 void X11DRV_set_wm_hints( Display *display, struct x11drv_win_data *data )
832 DWORD style, ex_style;
835 if (data->hwnd == GetDesktopWindow())
837 /* force some styles for the desktop to get the correct decorations */
838 style = WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
839 ex_style = WS_EX_APPWINDOW;
844 style = GetWindowLongW( data->hwnd, GWL_STYLE );
845 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
846 owner = GetWindow( data->hwnd, GW_OWNER );
849 /* transient for hint */
852 Window owner_win = X11DRV_get_whole_window( owner );
854 XSetTransientForHint( display, data->whole_window, owner_win );
856 group_leader = owner_win;
858 else group_leader = data->whole_window;
863 set_size_hints( display, data, style );
865 /* set the WM_WINDOW_TYPE */
866 if (style & WS_THICKFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
867 else if (ex_style & WS_EX_APPWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
868 else if (style & WS_DLGFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
869 else if (ex_style & WS_EX_DLGMODALFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
870 #if 0 /* many window managers don't handle utility windows very well */
871 else if (ex_style & WS_EX_TOOLWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
873 else window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
875 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
876 XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1);
878 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
879 mwm_hints.decorations = get_mwm_decorations( style, ex_style );
880 mwm_hints.functions = MWM_FUNC_MOVE;
881 if (is_window_resizable( data, style )) mwm_hints.functions |= MWM_FUNC_RESIZE;
882 if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
883 if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
884 if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
886 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
887 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
888 (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
893 data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint;
894 data->wm_hints->input = !(style & WS_DISABLED);
895 data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
896 data->wm_hints->window_group = group_leader;
897 XSetWMHints( display, data->whole_window, data->wm_hints );
904 /***********************************************************************
905 * X11DRV_window_to_X_rect
907 * Convert a rect from client to X window coordinates
909 void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect )
913 if (!data->managed) return;
914 if (IsRectEmpty( rect )) return;
916 get_x11_rect_offset( data, &rc );
918 rect->left -= rc.left;
919 rect->right -= rc.right;
921 rect->bottom -= rc.bottom;
922 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
923 if (rect->left >= rect->right) rect->right = rect->left + 1;
927 /***********************************************************************
928 * X11DRV_X_to_window_rect
930 * Opposite of X11DRV_window_to_X_rect
932 void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect )
936 if (!data->managed) return;
937 if (IsRectEmpty( rect )) return;
939 get_x11_rect_offset( data, &rc );
941 rect->left += rc.left;
942 rect->right += rc.right;
944 rect->bottom += rc.bottom;
945 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
946 if (rect->left >= rect->right) rect->right = rect->left + 1;
950 /***********************************************************************
951 * X11DRV_sync_window_position
953 * Synchronize the X window position with the Windows one
955 void X11DRV_sync_window_position( Display *display, struct x11drv_win_data *data,
956 UINT swp_flags, const RECT *old_client_rect,
957 const RECT *old_whole_rect )
959 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
960 XWindowChanges changes;
961 int mask = CWWidth | CWHeight;
963 if (data->managed && data->iconic) return;
965 if ((changes.width = data->whole_rect.right - data->whole_rect.left) <= 0) changes.width = 1;
966 if ((changes.height = data->whole_rect.bottom - data->whole_rect.top) <= 0) changes.height = 1;
968 /* only the size is allowed to change for the desktop window */
969 if (data->whole_window != root_window)
971 changes.x = data->whole_rect.left - virtual_screen_rect.left;
972 changes.y = data->whole_rect.top - virtual_screen_rect.top;
976 if (!(swp_flags & SWP_NOZORDER))
978 /* find window that this one must be after */
979 HWND prev = GetWindow( data->hwnd, GW_HWNDPREV );
980 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
981 prev = GetWindow( prev, GW_HWNDPREV );
982 if (!prev) /* top child */
984 changes.stack_mode = Above;
987 /* should use stack_mode Below but most window managers don't get it right */
988 /* and Above with a sibling doesn't work so well either, so we ignore it */
991 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
992 data->hwnd, data->whole_window, data->whole_rect.left, data->whole_rect.top,
993 data->whole_rect.right - data->whole_rect.left,
994 data->whole_rect.bottom - data->whole_rect.top, changes.sibling, mask );
997 set_size_hints( display, data, style );
998 XReconfigureWMWindow( display, data->whole_window,
999 DefaultScreen(display), mask, &changes );
1000 wine_tsx11_unlock();
1004 /***********************************************************************
1005 * X11DRV_sync_client_position
1007 * Synchronize the X client window position with the Windows one
1009 void X11DRV_sync_client_position( Display *display, struct x11drv_win_data *data,
1010 UINT swp_flags, const RECT *old_client_rect,
1011 const RECT *old_whole_rect )
1014 XWindowChanges changes;
1015 RECT old = *old_client_rect;
1016 RECT new = data->client_rect;
1018 OffsetRect( &old, -old_whole_rect->left, -old_whole_rect->top );
1019 OffsetRect( &new, -data->whole_rect.left, -data->whole_rect.top );
1020 if (!(mask = get_window_changes( &changes, &old, &new ))) return;
1022 if (data->client_window)
1024 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1025 data->client_window, new.left, new.top,
1026 new.right - new.left, new.bottom - new.top, mask );
1028 XConfigureWindow( display, data->client_window, mask, &changes );
1029 wine_tsx11_unlock();
1032 if (data->gl_drawable && (mask & (CWWidth|CWHeight))) sync_gl_drawable( display, data );
1036 /**********************************************************************
1037 * create_whole_window
1039 * Create the whole X window for a given window
1041 static Window create_whole_window( Display *display, struct x11drv_win_data *data )
1044 XSetWindowAttributes attr;
1048 if (!(cx = data->window_rect.right - data->window_rect.left)) cx = 1;
1049 if (!(cy = data->window_rect.bottom - data->window_rect.top)) cy = 1;
1051 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1053 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1054 data->managed = TRUE;
1055 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1058 mask = get_window_attributes( display, data, &attr );
1062 data->whole_rect = data->window_rect;
1063 data->whole_window = XCreateWindow( display, root_window,
1064 data->window_rect.left - virtual_screen_rect.left,
1065 data->window_rect.top - virtual_screen_rect.top,
1066 cx, cy, 0, screen_depth, InputOutput,
1067 visual, mask, &attr );
1069 if (data->whole_window) XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
1070 wine_tsx11_unlock();
1072 if (!data->whole_window) return 0;
1074 if (!create_client_window( display, data, NULL ))
1077 XDeleteContext( display, data->whole_window, winContext );
1078 XDestroyWindow( display, data->whole_window );
1079 data->whole_window = 0;
1080 wine_tsx11_unlock();
1084 set_initial_wm_hints( display, data );
1085 X11DRV_set_wm_hints( display, data );
1087 SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
1089 /* set the window text */
1090 if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
1091 sync_window_text( display, data->whole_window, text );
1093 /* set the window region */
1094 if ((hrgn = CreateRectRgn( 0, 0, 0, 0 )))
1096 if (GetWindowRgn( data->hwnd, hrgn ) != ERROR) sync_window_region( display, data, hrgn );
1097 DeleteObject( hrgn );
1100 XFlush( display ); /* make sure the window exists before we start painting to it */
1101 wine_tsx11_unlock();
1102 return data->whole_window;
1106 /**********************************************************************
1107 * destroy_whole_window
1109 * Destroy the whole X window for a given window.
1111 static void destroy_whole_window( Display *display, struct x11drv_win_data *data, BOOL already_destroyed )
1113 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1115 if (!data->whole_window) return;
1117 TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1118 if (thread_data->cursor_window == data->whole_window ||
1119 thread_data->cursor_window == data->client_window)
1120 thread_data->cursor_window = None;
1122 XDeleteContext( display, data->whole_window, winContext );
1123 XDeleteContext( display, data->client_window, winContext );
1124 if (!already_destroyed) XDestroyWindow( display, data->whole_window );
1125 data->whole_window = data->client_window = 0;
1126 data->wm_state = WithdrawnState;
1127 data->net_wm_state = 0;
1128 data->mapped = FALSE;
1131 XUnsetICFocus( data->xic );
1132 XDestroyIC( data->xic );
1135 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1137 XFree( data->wm_hints );
1138 data->wm_hints = NULL;
1139 wine_tsx11_unlock();
1140 RemovePropA( data->hwnd, whole_window_prop );
1141 RemovePropA( data->hwnd, client_window_prop );
1145 /*****************************************************************
1146 * SetWindowText (X11DRV.@)
1148 void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
1150 Display *display = thread_display();
1153 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display))
1154 sync_window_text( display, win, text );
1158 /***********************************************************************
1159 * DestroyWindow (X11DRV.@)
1161 void X11DRV_DestroyWindow( HWND hwnd )
1163 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1164 Display *display = thread_data->display;
1165 struct x11drv_win_data *data;
1167 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1171 destroy_glxpixmap(display, data->gl_drawable);
1173 XFreePixmap(display, data->pixmap);
1174 wine_tsx11_unlock();
1176 else if (data->gl_drawable)
1179 XDestroyWindow(display, data->gl_drawable);
1180 wine_tsx11_unlock();
1183 destroy_whole_window( display, data, FALSE );
1184 destroy_icon_window( display, data );
1189 XFreeColormap( display, data->colormap );
1190 wine_tsx11_unlock();
1193 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
1194 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
1195 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
1197 XDeleteContext( display, (XID)hwnd, win_data_context );
1198 wine_tsx11_unlock();
1199 HeapFree( GetProcessHeap(), 0, data );
1203 /***********************************************************************
1204 * X11DRV_DestroyNotify
1206 void X11DRV_DestroyNotify( HWND hwnd, XEvent *event )
1208 Display *display = event->xdestroywindow.display;
1209 struct x11drv_win_data *data;
1211 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1213 FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window );
1214 destroy_whole_window( display, data, TRUE );
1218 static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
1220 struct x11drv_win_data *data;
1222 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
1226 if (!winContext) winContext = XUniqueContext();
1227 if (!win_data_context) win_data_context = XUniqueContext();
1228 XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
1229 wine_tsx11_unlock();
1235 /* initialize the desktop window id in the desktop manager process */
1236 static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd )
1238 struct x11drv_win_data *data;
1241 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1243 visualid = XVisualIDFromVisual(visual);
1244 wine_tsx11_unlock();
1245 data->whole_window = data->client_window = root_window;
1246 data->managed = TRUE;
1247 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1248 SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
1249 SetPropA( data->hwnd, client_window_prop, (HANDLE)root_window );
1250 set_initial_wm_hints( display, data );
1254 /**********************************************************************
1255 * CreateDesktopWindow (X11DRV.@)
1257 BOOL X11DRV_CreateDesktopWindow( HWND hwnd )
1259 unsigned int width, height;
1261 /* retrieve the real size of the desktop */
1262 SERVER_START_REQ( get_window_rectangles )
1265 wine_server_call( req );
1266 width = reply->window.right - reply->window.left;
1267 height = reply->window.bottom - reply->window.top;
1271 if (!width && !height) /* not initialized yet */
1273 SERVER_START_REQ( set_window_pos )
1277 req->flags = SWP_NOZORDER;
1278 req->window.left = virtual_screen_rect.left;
1279 req->window.top = virtual_screen_rect.top;
1280 req->window.right = virtual_screen_rect.right;
1281 req->window.bottom = virtual_screen_rect.bottom;
1282 req->client = req->window;
1283 wine_server_call( req );
1289 Window win = (Window)GetPropA( hwnd, whole_window_prop );
1290 if (win && win != root_window) X11DRV_init_desktop( win, width, height );
1296 /**********************************************************************
1297 * CreateWindow (X11DRV.@)
1299 BOOL X11DRV_CreateWindow( HWND hwnd )
1301 Display *display = thread_display();
1303 if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( display ))
1305 /* the desktop win data can't be created lazily */
1306 if (!create_desktop_win_data( display, hwnd )) return FALSE;
1312 /***********************************************************************
1313 * X11DRV_get_win_data
1315 * Return the X11 data structure associated with a window.
1317 struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1321 if (!hwnd || XFindContext( thread_display(), (XID)hwnd, win_data_context, &data )) data = NULL;
1322 return (struct x11drv_win_data *)data;
1326 /***********************************************************************
1327 * X11DRV_create_win_data
1329 * Create an X11 data window structure for an existing window.
1331 struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd )
1333 Display *display = thread_display();
1334 struct x11drv_win_data *data;
1337 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
1338 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1340 GetWindowRect( hwnd, &data->window_rect );
1341 MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 );
1342 data->whole_rect = data->window_rect;
1343 GetClientRect( hwnd, &data->client_rect );
1344 MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 );
1346 if (parent == GetDesktopWindow())
1348 if (!create_whole_window( display, data ))
1350 HeapFree( GetProcessHeap(), 0, data );
1353 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1354 hwnd, data->whole_window, data->client_window, wine_dbgstr_rect( &data->window_rect ),
1355 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
1361 /***********************************************************************
1362 * X11DRV_get_whole_window
1364 * Return the X window associated with the full area of a window
1366 Window X11DRV_get_whole_window( HWND hwnd )
1368 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1372 if (hwnd == GetDesktopWindow()) return root_window;
1373 return (Window)GetPropA( hwnd, whole_window_prop );
1375 return data->whole_window;
1379 /***********************************************************************
1380 * X11DRV_get_client_window
1382 * Return the X window associated with the client area of a window
1384 Window X11DRV_get_client_window( HWND hwnd )
1386 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1390 if (hwnd == GetDesktopWindow()) return root_window;
1391 return (Window)GetPropA( hwnd, client_window_prop );
1393 return data->client_window;
1397 /***********************************************************************
1400 * Return the X input context associated with a window
1402 XIC X11DRV_get_ic( HWND hwnd )
1404 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1407 if (!data) return 0;
1408 if (data->xic) return data->xic;
1409 if (!(xim = x11drv_thread_data()->xim)) return 0;
1410 return X11DRV_CreateIC( xim, data );
1414 /***********************************************************************
1415 * X11DRV_GetDC (X11DRV.@)
1417 void X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect,
1418 const RECT *top_rect, DWORD flags )
1420 struct x11drv_escape_set_drawable escape;
1421 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1423 escape.code = X11DRV_SET_DRAWABLE;
1424 escape.mode = IncludeInferiors;
1425 escape.fbconfig_id = 0;
1426 escape.gl_drawable = 0;
1429 if (top == hwnd && data && IsIconic( hwnd ) && data->icon_window)
1431 escape.drawable = data->icon_window;
1433 else if (top == hwnd && (flags & DCX_WINDOW))
1435 escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd );
1439 escape.drawable = X11DRV_get_client_window( top );
1440 escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop );
1441 escape.gl_drawable = data ? data->gl_drawable : (Drawable)GetPropA( hwnd, gl_drawable_prop );
1442 escape.pixmap = data ? data->pixmap : (Pixmap)GetPropA( hwnd, pixmap_prop );
1443 if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren;
1446 escape.dc_rect.left = win_rect->left - top_rect->left;
1447 escape.dc_rect.top = win_rect->top - top_rect->top;
1448 escape.dc_rect.right = win_rect->right - top_rect->left;
1449 escape.dc_rect.bottom = win_rect->bottom - top_rect->top;
1450 escape.drawable_rect.left = top_rect->left;
1451 escape.drawable_rect.top = top_rect->top;
1452 escape.drawable_rect.right = top_rect->right;
1453 escape.drawable_rect.bottom = top_rect->bottom;
1455 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1459 /***********************************************************************
1460 * X11DRV_ReleaseDC (X11DRV.@)
1462 void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
1464 struct x11drv_escape_set_drawable escape;
1466 escape.code = X11DRV_SET_DRAWABLE;
1467 escape.drawable = root_window;
1468 escape.mode = IncludeInferiors;
1469 escape.drawable_rect = virtual_screen_rect;
1470 SetRect( &escape.dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left,
1471 virtual_screen_rect.bottom - virtual_screen_rect.top );
1472 escape.fbconfig_id = 0;
1473 escape.gl_drawable = 0;
1475 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1479 /***********************************************************************
1480 * SetCapture (X11DRV.@)
1482 void X11DRV_SetCapture( HWND hwnd, UINT flags )
1484 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1486 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
1490 Window grab_win = X11DRV_get_client_window( GetAncestor( hwnd, GA_ROOT ) );
1492 if (!grab_win) return;
1494 XFlush( gdi_display );
1495 XGrabPointer( thread_data->display, grab_win, False,
1496 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1497 GrabModeAsync, GrabModeAsync, None, None, CurrentTime );
1498 wine_tsx11_unlock();
1499 thread_data->grab_window = grab_win;
1501 else /* release capture */
1504 XFlush( gdi_display );
1505 XUngrabPointer( thread_data->display, CurrentTime );
1506 wine_tsx11_unlock();
1507 thread_data->grab_window = None;
1512 /*****************************************************************
1513 * SetParent (X11DRV.@)
1515 void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
1517 Display *display = thread_display();
1518 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1521 if (parent == old_parent) return;
1523 if (parent != GetDesktopWindow()) /* a child window */
1525 if (old_parent == GetDesktopWindow())
1527 /* destroy the old X windows */
1528 destroy_whole_window( display, data, FALSE );
1529 destroy_icon_window( display, data );
1532 data->managed = FALSE;
1533 RemovePropA( data->hwnd, managed_prop );
1537 else /* new top level window */
1539 /* FIXME: we ignore errors since we can't really recover anyway */
1540 create_whole_window( display, data );
1545 /*****************************************************************
1546 * SetFocus (X11DRV.@)
1549 * Explicit colormap management seems to work only with OLVWM.
1551 void X11DRV_SetFocus( HWND hwnd )
1553 Display *display = thread_display();
1554 struct x11drv_win_data *data;
1555 XWindowChanges changes;
1557 /* If setting the focus to 0, uninstall the colormap */
1558 if (!hwnd && root_window == DefaultRootWindow(display))
1561 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1562 XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1563 wine_tsx11_unlock();
1567 hwnd = GetAncestor( hwnd, GA_ROOT );
1569 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1570 if (data->managed || !data->whole_window) return;
1572 /* Set X focus and install colormap */
1574 changes.stack_mode = Above;
1575 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
1576 if (root_window == DefaultRootWindow(display))
1578 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1579 /* FIXME: this is not entirely correct */
1580 XSetInputFocus( display, data->whole_window, RevertToParent,
1582 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1583 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1584 XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1586 wine_tsx11_unlock();
1590 /**********************************************************************
1591 * SetWindowIcon (X11DRV.@)
1593 * hIcon or hIconSm has changed (or is being initialised for the
1594 * first time). Complete the X11 driver-specific initialisation
1595 * and set the window hints.
1597 * This is not entirely correct, may need to create
1598 * an icon window and set the pixmap as a background
1600 void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
1602 Display *display = thread_display();
1603 struct x11drv_win_data *data;
1605 if (type != ICON_BIG) return; /* nothing to do here */
1607 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1608 if (!data->whole_window) return;
1609 if (!data->managed) return;
1613 set_icon_hints( display, data, icon );
1615 XSetWMHints( display, data->whole_window, data->wm_hints );
1616 wine_tsx11_unlock();
1621 /***********************************************************************
1622 * SetWindowRgn (X11DRV.@)
1624 * Assign specified region to window (for non-rectangular windows)
1626 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1628 struct x11drv_win_data *data;
1630 if ((data = X11DRV_get_win_data( hwnd )))
1632 sync_window_region( thread_display(), data, hrgn );
1634 else if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
1636 FIXME( "not supported on other thread window %p\n", hwnd );
1637 SetLastError( ERROR_INVALID_WINDOW_HANDLE );