comctl32: A couple fixes for tab icon offsets.
[wine] / dlls / x11drv / window.c
1 /*
2  * Window related functions
3  *
4  * Copyright 1993, 1994, 1995, 1996, 2001 Alexandre Julliard
5  * Copyright 1993 David Metcalfe
6  * Copyright 1995, 1996 Alex Korobka
7  *
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.
12  *
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.
17  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "config.h"
24
25 #include <stdarg.h>
26 #include <stdlib.h>
27 #ifdef HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
30
31 #include <X11/Xlib.h>
32 #include <X11/Xresource.h>
33 #include <X11/Xutil.h>
34
35 #include "windef.h"
36 #include "winbase.h"
37 #include "wingdi.h"
38 #include "winreg.h"
39 #include "winuser.h"
40 #include "wine/unicode.h"
41
42 #include "x11drv.h"
43 #include "wine/debug.h"
44 #include "wine/server.h"
45 #include "win.h"
46 #include "winpos.h"
47 #include "mwm.h"
48
49 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
50
51 /* X context to associate a hwnd to an X window */
52 XContext winContext = 0;
53
54 /* X context to associate a struct x11drv_win_data to an hwnd */
55 static XContext win_data_context;
56
57 static const char whole_window_prop[] = "__wine_x11_whole_window";
58 static const char icon_window_prop[]  = "__wine_x11_icon_window";
59 static const char managed_prop[]      = "__wine_x11_managed";
60 static const char visual_id_prop[]    = "__wine_x11_visual_id";
61
62 /***********************************************************************
63  *              is_window_managed
64  *
65  * Check if a given window should be managed
66  */
67 inline static BOOL is_window_managed( HWND hwnd )
68 {
69     DWORD style, ex_style;
70
71     if (!managed_mode) return FALSE;
72     /* tray window is always managed */
73     ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE );
74     if (ex_style & WS_EX_TRAYWINDOW) return TRUE;
75     /* child windows are not managed */
76     style = GetWindowLongW( hwnd, GWL_STYLE );
77     if (style & WS_CHILD) return FALSE;
78     /* windows with caption are managed */
79     if ((style & WS_CAPTION) == WS_CAPTION) return TRUE;
80     /* tool windows are not managed  */
81     if (ex_style & WS_EX_TOOLWINDOW) return FALSE;
82     /* windows with thick frame are managed */
83     if (style & WS_THICKFRAME) return TRUE;
84     /* application windows are managed */
85     if (ex_style & WS_EX_APPWINDOW) return TRUE;
86     /* full-screen popup windows are managed */
87     if (style & WS_POPUP)
88     {
89         RECT rect;
90         GetWindowRect( hwnd, &rect );
91         if ((rect.right - rect.left) == screen_width && (rect.bottom - rect.top) == screen_height)
92             return TRUE;
93     }
94     /* default: not managed */
95     return FALSE;
96 }
97
98
99 /***********************************************************************
100  *              X11DRV_is_window_rect_mapped
101  *
102  * Check if the X whole window should be mapped based on its rectangle
103  */
104 BOOL X11DRV_is_window_rect_mapped( const RECT *rect )
105 {
106     /* don't map if rect is empty */
107     if (IsRectEmpty( rect )) return FALSE;
108
109     /* don't map if rect is off-screen */
110     if (rect->left >= (int)screen_width || rect->top >= (int)screen_height) return FALSE;
111     if (rect->right < 0 || rect->bottom < 0) return FALSE;
112
113     return TRUE;
114 }
115
116
117 /***********************************************************************
118  *              get_window_attributes
119  *
120  * Fill the window attributes structure for an X window.
121  */
122 static int get_window_attributes( struct x11drv_win_data *data, XSetWindowAttributes *attr )
123 {
124     if (!data->managed && !using_wine_desktop && is_window_managed( data->hwnd ))
125     {
126         data->managed = TRUE;
127         SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
128     }
129     attr->override_redirect = !data->managed;
130     attr->colormap          = X11DRV_PALETTE_PaletteXColormap;
131     attr->save_under        = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0);
132     attr->cursor            = x11drv_thread_data()->cursor;
133     return (CWOverrideRedirect | CWSaveUnder | CWColormap | CWCursor);
134 }
135
136
137 /***********************************************************************
138  *              X11DRV_sync_window_style
139  *
140  * Change the X window attributes when the window style has changed.
141  */
142 void X11DRV_sync_window_style( Display *display, struct x11drv_win_data *data )
143 {
144     XSetWindowAttributes attr;
145     int mask = get_window_attributes( data, &attr );
146
147     wine_tsx11_lock();
148     if (data->whole_window != DefaultRootWindow(display))
149         XChangeWindowAttributes( display, data->whole_window, mask, &attr );
150     wine_tsx11_unlock();
151 }
152
153
154 /***********************************************************************
155  *              get_window_changes
156  *
157  * fill the window changes structure
158  */
159 static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
160 {
161     int mask = 0;
162
163     if (old->right - old->left != new->right - new->left )
164     {
165         if (!(changes->width = new->right - new->left)) changes->width = 1;
166         mask |= CWWidth;
167     }
168     if (old->bottom - old->top != new->bottom - new->top)
169     {
170         if (!(changes->height = new->bottom - new->top)) changes->height = 1;
171         mask |= CWHeight;
172     }
173     if (old->left != new->left)
174     {
175         changes->x = new->left;
176         mask |= CWX;
177     }
178     if (old->top != new->top)
179     {
180         changes->y = new->top;
181         mask |= CWY;
182     }
183     return mask;
184 }
185
186
187 /***********************************************************************
188  *              create_icon_window
189  */
190 static Window create_icon_window( Display *display, struct x11drv_win_data *data )
191 {
192     XSetWindowAttributes attr;
193
194     attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
195                        ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
196     attr.bit_gravity = NorthWestGravity;
197     attr.backing_store = NotUseful/*WhenMapped*/;
198     attr.colormap      = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
199
200     wine_tsx11_lock();
201     data->icon_window = XCreateWindow( display, root_window, 0, 0,
202                                        GetSystemMetrics( SM_CXICON ),
203                                        GetSystemMetrics( SM_CYICON ),
204                                        0, screen_depth,
205                                        InputOutput, visual,
206                                        CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
207     XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd );
208     wine_tsx11_unlock();
209
210     TRACE( "created %lx\n", data->icon_window );
211     SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window );
212     return data->icon_window;
213 }
214
215
216
217 /***********************************************************************
218  *              destroy_icon_window
219  */
220 static void destroy_icon_window( Display *display, struct x11drv_win_data *data )
221 {
222     if (!data->icon_window) return;
223     if (x11drv_thread_data()->cursor_window == data->icon_window)
224         x11drv_thread_data()->cursor_window = None;
225     wine_tsx11_lock();
226     XDeleteContext( display, data->icon_window, winContext );
227     XDestroyWindow( display, data->icon_window );
228     data->icon_window = 0;
229     wine_tsx11_unlock();
230     RemovePropA( data->hwnd, icon_window_prop );
231 }
232
233
234 /***********************************************************************
235  *              set_icon_hints
236  *
237  * Set the icon wm hints
238  */
239 static void set_icon_hints( Display *display, struct x11drv_win_data *data,
240                             XWMHints *hints, HICON hIcon )
241 {
242     if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
243     if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
244     data->hWMIconBitmap = 0;
245     data->hWMIconMask = 0;
246
247     if (!data->managed)
248     {
249         destroy_icon_window( display, data );
250         hints->flags &= ~(IconPixmapHint | IconMaskHint | IconWindowHint);
251     }
252     else if (!hIcon)
253     {
254         if (!data->icon_window) create_icon_window( display, data );
255         hints->icon_window = data->icon_window;
256         hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
257     }
258     else
259     {
260         HBITMAP hbmOrig;
261         RECT rcMask;
262         BITMAP bmMask;
263         ICONINFO ii;
264         HDC hDC;
265
266         GetIconInfo(hIcon, &ii);
267
268         GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
269         rcMask.top    = 0;
270         rcMask.left   = 0;
271         rcMask.right  = bmMask.bmWidth;
272         rcMask.bottom = bmMask.bmHeight;
273
274         hDC = CreateCompatibleDC(0);
275         hbmOrig = SelectObject(hDC, ii.hbmMask);
276         InvertRect(hDC, &rcMask);
277         SelectObject(hDC, ii.hbmColor);  /* force the color bitmap to x11drv mode too */
278         SelectObject(hDC, hbmOrig);
279         DeleteDC(hDC);
280
281         data->hWMIconBitmap = ii.hbmColor;
282         data->hWMIconMask = ii.hbmMask;
283
284         hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap);
285         hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask);
286         destroy_icon_window( display, data );
287         hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
288     }
289 }
290
291
292 /***********************************************************************
293  *              set_size_hints
294  *
295  * set the window size hints
296  */
297 static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style )
298 {
299     XSizeHints* size_hints;
300
301     if ((size_hints = XAllocSizeHints()))
302     {
303         size_hints->win_gravity = StaticGravity;
304         size_hints->x = data->whole_rect.left;
305         size_hints->y = data->whole_rect.top;
306         size_hints->flags = PWinGravity | PPosition;
307
308         if ( !(style & WS_THICKFRAME) )
309         {
310             size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
311             size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
312             size_hints->min_width = size_hints->max_width;
313             size_hints->min_height = size_hints->max_height;
314             size_hints->flags |= PMinSize | PMaxSize;
315         }
316         XSetWMNormalHints( display, data->whole_window, size_hints );
317         XFree( size_hints );
318     }
319 }
320
321
322 /***********************************************************************
323  *              get_process_name
324  *
325  * get the name of the current process for setting class hints
326  */
327 static char *get_process_name(void)
328 {
329     static char *name;
330
331     if (!name)
332     {
333         WCHAR module[MAX_PATH];
334         DWORD len = GetModuleFileNameW( 0, module, MAX_PATH );
335         if (len && len < MAX_PATH)
336         {
337             char *ptr;
338             WCHAR *p, *appname = module;
339
340             if ((p = strrchrW( appname, '/' ))) appname = p + 1;
341             if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
342             len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL );
343             if ((ptr = HeapAlloc( GetProcessHeap(), 0, len )))
344             {
345                 WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL );
346                 name = ptr;
347             }
348         }
349     }
350     return name;
351 }
352
353
354 /***********************************************************************
355  *              X11DRV_set_wm_hints
356  *
357  * Set the window manager hints for a newly-created window
358  */
359 void X11DRV_set_wm_hints( Display *display, struct x11drv_win_data *data )
360 {
361     Window group_leader;
362     XClassHint *class_hints;
363     XWMHints* wm_hints;
364     Atom protocols[3];
365     MwmHints mwm_hints;
366     Atom dndVersion = 4;
367     int i;
368     DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
369     DWORD ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
370     HWND owner = GetWindow( data->hwnd, GW_OWNER );
371     char *process_name = get_process_name();
372
373     /* transient for hint */
374     if (owner)
375     {
376         Window owner_win = X11DRV_get_whole_window( owner );
377         wine_tsx11_lock();
378         XSetTransientForHint( display, data->whole_window, owner_win );
379         wine_tsx11_unlock();
380         group_leader = owner_win;
381     }
382     else group_leader = data->whole_window;
383
384     wine_tsx11_lock();
385
386     /* wm protocols */
387     i = 0;
388     protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
389     protocols[i++] = x11drv_atom(_NET_WM_PING);
390     if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
391     XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
392                      XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
393
394     /* class hints */
395     if ((class_hints = XAllocClassHint()))
396     {
397         class_hints->res_name = process_name;
398         class_hints->res_class = "Wine";
399         XSetClassHint( display, data->whole_window, class_hints );
400         XFree( class_hints );
401     }
402
403     /* size hints */
404     set_size_hints( display, data, style );
405
406     /* systray properties (KDE only for now) */
407     if (ex_style & WS_EX_TRAYWINDOW)
408     {
409         int val = 1;
410         XChangeProperty( display, data->whole_window, x11drv_atom(KWM_DOCKWINDOW),
411                          x11drv_atom(KWM_DOCKWINDOW), 32, PropModeReplace, (unsigned char*)&val, 1 );
412         XChangeProperty( display, data->whole_window, x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR),
413                          XA_WINDOW, 32, PropModeReplace, (unsigned char*)&data->whole_window, 1 );
414     }
415
416     /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
417     XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
418     /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
419     i = getpid();
420     XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
421                     XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
422
423    /* map WS_EX_TOOLWINDOW to _NET_WM_WINDOW_TYPE_UTILITY */
424    if (ex_style & WS_EX_TOOLWINDOW)
425    {
426       Atom a = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
427       XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
428                       XA_ATOM, 32, PropModeReplace, (unsigned char*)&a, 1);
429    }
430
431     mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
432     mwm_hints.functions = 0;
433     if ((style & WS_CAPTION) == WS_CAPTION) mwm_hints.functions |= MWM_FUNC_MOVE;
434     if (style & WS_THICKFRAME) mwm_hints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
435     if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
436     if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
437     if (style & WS_SYSMENU)    mwm_hints.functions |= MWM_FUNC_CLOSE;
438     if (ex_style & WS_EX_APPWINDOW) mwm_hints.functions |= MWM_FUNC_MOVE;
439     mwm_hints.decorations = 0;
440     if ((style & WS_CAPTION) == WS_CAPTION) 
441     {
442         mwm_hints.decorations |= MWM_DECOR_TITLE;
443         if (style & WS_SYSMENU) mwm_hints.decorations |= MWM_DECOR_MENU;
444         if (style & WS_MINIMIZEBOX) mwm_hints.decorations |= MWM_DECOR_MINIMIZE;
445         if (style & WS_MAXIMIZEBOX) mwm_hints.decorations |= MWM_DECOR_MAXIMIZE;
446     }
447     if (ex_style & WS_EX_DLGMODALFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER;
448     else if (style & WS_THICKFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
449     else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER;
450     else if (style & WS_BORDER) mwm_hints.decorations |= MWM_DECOR_BORDER;
451     else if (!(style & (WS_CHILD|WS_POPUP))) mwm_hints.decorations |= MWM_DECOR_BORDER;
452
453     XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
454                      x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
455                      (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
456
457     XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
458                      XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
459
460     wm_hints = XAllocWMHints();
461     wine_tsx11_unlock();
462
463     /* wm hints */
464     if (wm_hints)
465     {
466         wm_hints->flags = InputHint | StateHint | WindowGroupHint;
467         wm_hints->input = !(style & WS_DISABLED);
468
469         set_icon_hints( display, data, wm_hints,
470                         (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON ) );
471
472         wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
473         wm_hints->window_group = group_leader;
474
475         wine_tsx11_lock();
476         XSetWMHints( display, data->whole_window, wm_hints );
477         XFree(wm_hints);
478         wine_tsx11_unlock();
479     }
480 }
481
482
483 /***********************************************************************
484  *              X11DRV_set_iconic_state
485  *
486  * Set the X11 iconic state according to the window style.
487  */
488 void X11DRV_set_iconic_state( HWND hwnd )
489 {
490     Display *display = thread_display();
491     struct x11drv_win_data *data;
492     RECT rect;
493     XWMHints* wm_hints;
494     DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
495     BOOL iconic = (style & WS_MINIMIZE) != 0;
496
497     if (!(data = X11DRV_get_win_data( hwnd ))) return;
498     if (!data->whole_window) return;
499
500     GetWindowRect( hwnd, &rect );
501
502     wine_tsx11_lock();
503
504     if (!(wm_hints = XGetWMHints( display, data->whole_window ))) wm_hints = XAllocWMHints();
505     wm_hints->flags |= StateHint | IconPositionHint;
506     wm_hints->initial_state = iconic ? IconicState : NormalState;
507     wm_hints->icon_x = rect.left;
508     wm_hints->icon_y = rect.top;
509     XSetWMHints( display, data->whole_window, wm_hints );
510
511     if (style & WS_VISIBLE)
512     {
513         if (iconic)
514             XIconifyWindow( display, data->whole_window, DefaultScreen(display) );
515         else
516             if (X11DRV_is_window_rect_mapped( &rect ))
517                 XMapWindow( display, data->whole_window );
518     }
519
520     XFree(wm_hints);
521     wine_tsx11_unlock();
522 }
523
524
525 /***********************************************************************
526  *              X11DRV_window_to_X_rect
527  *
528  * Convert a rect from client to X window coordinates
529  */
530 void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect )
531 {
532     RECT rc;
533
534     if (!data->managed) return;
535     if (IsRectEmpty( rect )) return;
536
537     rc.top = rc.bottom = rc.left = rc.right = 0;
538
539     AdjustWindowRectEx( &rc, GetWindowLongW( data->hwnd, GWL_STYLE ) & ~(WS_HSCROLL|WS_VSCROLL),
540                         FALSE, GetWindowLongW( data->hwnd, GWL_EXSTYLE ) );
541
542     rect->left   -= rc.left;
543     rect->right  -= rc.right;
544     rect->top    -= rc.top;
545     rect->bottom -= rc.bottom;
546     if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
547     if (rect->left >= rect->right) rect->right = rect->left + 1;
548 }
549
550
551 /***********************************************************************
552  *              X11DRV_X_to_window_rect
553  *
554  * Opposite of X11DRV_window_to_X_rect
555  */
556 void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect )
557 {
558     if (!data->managed) return;
559     if (IsRectEmpty( rect )) return;
560
561     AdjustWindowRectEx( rect, GetWindowLongW( data->hwnd, GWL_STYLE ) & ~(WS_HSCROLL|WS_VSCROLL),
562                         FALSE, GetWindowLongW( data->hwnd, GWL_EXSTYLE ));
563
564     if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
565     if (rect->left >= rect->right) rect->right = rect->left + 1;
566 }
567
568
569 /***********************************************************************
570  *              X11DRV_sync_window_position
571  *
572  * Synchronize the X window position with the Windows one
573  */
574 void X11DRV_sync_window_position( Display *display, struct x11drv_win_data *data,
575                                   UINT swp_flags, const RECT *new_client_rect,
576                                   const RECT *new_whole_rect )
577 {
578     XWindowChanges changes;
579     int mask;
580     RECT old_whole_rect;
581
582     old_whole_rect = data->whole_rect;
583     data->whole_rect = *new_whole_rect;
584
585     data->client_rect = *new_client_rect;
586     OffsetRect( &data->client_rect, -data->whole_rect.left, -data->whole_rect.top );
587
588     if (!data->whole_window) return;
589     if (swp_flags & SWP_WINE_NOHOSTMOVE) return;
590
591     mask = get_window_changes( &changes, &old_whole_rect, &data->whole_rect );
592
593     if (!(swp_flags & SWP_NOZORDER))
594     {
595         /* find window that this one must be after */
596         HWND prev = GetWindow( data->hwnd, GW_HWNDPREV );
597         while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
598             prev = GetWindow( prev, GW_HWNDPREV );
599         if (!prev)  /* top child */
600         {
601             changes.stack_mode = Above;
602             mask |= CWStackMode;
603         }
604         else
605         {
606             /* should use stack_mode Below but most window managers don't get it right */
607             /* so move it above the next one in Z order */
608             HWND next = GetWindow( data->hwnd, GW_HWNDNEXT );
609             while (next && !(GetWindowLongW( next, GWL_STYLE ) & WS_VISIBLE))
610                 next = GetWindow( next, GW_HWNDNEXT );
611             if (next)
612             {
613                 changes.stack_mode = Above;
614                 changes.sibling = X11DRV_get_whole_window(next);
615                 mask |= CWStackMode | CWSibling;
616             }
617         }
618     }
619
620     if (mask)
621     {
622         DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
623
624         TRACE( "setting win %lx pos %ld,%ld,%ldx%ld after %lx changes=%x\n",
625                data->whole_window, data->whole_rect.left, data->whole_rect.top,
626                data->whole_rect.right - data->whole_rect.left,
627                data->whole_rect.bottom - data->whole_rect.top, changes.sibling, mask );
628
629         wine_tsx11_lock();
630         XSync( gdi_display, False );  /* flush graphics operations before moving the window */
631         if (mask & (CWWidth|CWHeight)) set_size_hints( display, data, style );
632         XReconfigureWMWindow( display, data->whole_window,
633                               DefaultScreen(display), mask, &changes );
634         wine_tsx11_unlock();
635     }
636 }
637
638
639 /**********************************************************************
640  *              create_whole_window
641  *
642  * Create the whole X window for a given window
643  */
644 static Window create_whole_window( Display *display, struct x11drv_win_data *data, DWORD style )
645 {
646     int cx, cy, mask;
647     XSetWindowAttributes attr;
648     XIM xim;
649     RECT rect;
650
651     rect = data->window_rect;
652     X11DRV_window_to_X_rect( data, &rect );
653
654     if (!(cx = rect.right - rect.left)) cx = 1;
655     if (!(cy = rect.bottom - rect.top)) cy = 1;
656
657     mask = get_window_attributes( data, &attr );
658
659     /* set the attributes that don't change over the lifetime of the window */
660     attr.bit_gravity   = NorthWestGravity;
661     attr.backing_store = NotUseful;
662     attr.event_mask    = (ExposureMask | PointerMotionMask |
663                           ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
664                           KeyPressMask | KeyReleaseMask | StructureNotifyMask |
665                           FocusChangeMask | KeymapStateMask);
666     mask |= CWBitGravity | CWBackingStore | CWEventMask;
667
668     wine_tsx11_lock();
669
670     data->whole_rect = rect;
671     data->whole_window = XCreateWindow( display, root_window, rect.left, rect.top, cx, cy,
672                                         0, screen_depth, InputOutput, visual,
673                                         mask, &attr );
674
675     if (!data->whole_window)
676     {
677         wine_tsx11_unlock();
678         return 0;
679     }
680     XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
681
682     /* non-maximized child must be at bottom of Z order */
683     if ((style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
684     {
685         XWindowChanges changes;
686         changes.stack_mode = Below;
687         XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
688     }
689     XSync( display, False );  /* FIXME: should not be needed */
690
691     wine_tsx11_unlock();
692
693     xim = x11drv_thread_data()->xim;
694     if (xim) data->xic = X11DRV_CreateIC( xim, display, data->whole_window );
695
696     X11DRV_set_wm_hints( display, data );
697
698     SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
699     return data->whole_window;
700 }
701
702
703 /**********************************************************************
704  *              destroy_whole_window
705  *
706  * Destroy the whole X window for a given window.
707  */
708 static void destroy_whole_window( Display *display, struct x11drv_win_data *data )
709 {
710     struct x11drv_thread_data *thread_data = x11drv_thread_data();
711
712     if (!data->whole_window) return;
713
714     TRACE( "win %p xwin %lx\n", data->hwnd, data->whole_window );
715     if (thread_data->cursor_window == data->whole_window) thread_data->cursor_window = None;
716     wine_tsx11_lock();
717     XSync( gdi_display, False );  /* flush any reference to this drawable in GDI queue */
718     XDeleteContext( display, data->whole_window, winContext );
719     if (data->whole_window != DefaultRootWindow(display))
720         XDestroyWindow( display, data->whole_window );
721     data->whole_window = 0;
722     if (data->xic)
723     {
724         XUnsetICFocus( data->xic );
725         XDestroyIC( data->xic );
726     }
727     wine_tsx11_unlock();
728     RemovePropA( data->hwnd, whole_window_prop );
729 }
730
731
732 /*****************************************************************
733  *              SetWindowText   (X11DRV.@)
734  */
735 void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
736 {
737     Display *display = thread_display();
738     UINT count;
739     char *buffer;
740     char *utf8_buffer;
741     Window win;
742     XTextProperty prop;
743
744     if ((win = X11DRV_get_whole_window( hwnd )))
745     {
746         /* allocate new buffer for window text */
747         count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
748         if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count )))
749         {
750             ERR("Not enough memory for window text\n");
751             return;
752         }
753         WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
754
755         count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
756         if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
757         {
758             ERR("Not enough memory for window text in UTF-8\n");
759             HeapFree( GetProcessHeap(), 0, buffer );
760             return;
761         }
762         WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
763
764         wine_tsx11_lock();
765         if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
766         {
767             XSetWMName( display, win, &prop );
768             XSetWMIconName( display, win, &prop );
769             XFree( prop.value );
770         }
771         /*
772         Implements a NET_WM UTF-8 title. It should be without a trailing \0,
773         according to the standard
774         ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
775         */
776         XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
777                          8, PropModeReplace, (unsigned char *) utf8_buffer, count);
778         wine_tsx11_unlock();
779
780         HeapFree( GetProcessHeap(), 0, utf8_buffer );
781         HeapFree( GetProcessHeap(), 0, buffer );
782     }
783 }
784
785
786 /***********************************************************************
787  *              DestroyWindow   (X11DRV.@)
788  */
789 void X11DRV_DestroyWindow( HWND hwnd )
790 {
791     struct x11drv_thread_data *thread_data = x11drv_thread_data();
792     Display *display = thread_data->display;
793     struct x11drv_win_data *data;
794
795     if (!(data = X11DRV_get_win_data( hwnd ))) return;
796
797     free_window_dce( data );
798     destroy_whole_window( display, data );
799     destroy_icon_window( display, data );
800
801     if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
802     if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
803     if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
804     wine_tsx11_lock();
805     XDeleteContext( display, (XID)hwnd, win_data_context );
806     wine_tsx11_unlock();
807     HeapFree( GetProcessHeap(), 0, data );
808 }
809
810
811 static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
812 {
813     struct x11drv_win_data *data;
814
815     if ((data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data))))
816     {
817         data->hwnd          = hwnd;
818         data->whole_window  = 0;
819         data->icon_window   = 0;
820         data->xic           = 0;
821         data->managed       = FALSE;
822         data->dce           = NULL;
823         data->hWMIconBitmap = 0;
824         data->hWMIconMask   = 0;
825
826         wine_tsx11_lock();
827         if (!winContext) winContext = XUniqueContext();
828         if (!win_data_context) win_data_context = XUniqueContext();
829         XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
830         wine_tsx11_unlock();
831     }
832     return data;
833 }
834
835
836 /**********************************************************************
837  *              CreateDesktopWindow   (X11DRV.@)
838  */
839 BOOL X11DRV_CreateDesktopWindow( HWND hwnd )
840 {
841     Display *display = thread_display();
842     VisualID visualid;
843     struct x11drv_win_data *data;
844     RECT rect;
845
846     if (!(data = alloc_win_data( display, hwnd ))) return FALSE;
847     data->whole_window = root_window;
848
849     SetRect( &rect, 0, 0, screen_width, screen_height );
850     X11DRV_set_window_pos( hwnd, 0, &rect, &rect, SWP_NOZORDER, NULL );
851
852     wine_tsx11_lock();
853     visualid = XVisualIDFromVisual(visual);
854     wine_tsx11_unlock();
855
856     SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
857     SetPropA( data->hwnd, visual_id_prop, (HANDLE)visualid );
858
859     if (root_window != DefaultRootWindow(display) && !desktop_tid) X11DRV_create_desktop_thread();
860
861     return TRUE;
862 }
863
864
865 /**********************************************************************
866  *              CreateWindow   (X11DRV.@)
867  */
868 BOOL X11DRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode )
869 {
870     Display *display = thread_display();
871     WND *wndPtr;
872     struct x11drv_win_data *data;
873     HWND insert_after;
874     RECT rect;
875     DWORD style;
876     CBT_CREATEWNDA cbtc;
877     CREATESTRUCTA cbcs;
878     BOOL ret = FALSE;
879
880     if (!(data = alloc_win_data( display, hwnd ))) return FALSE;
881
882     if (cs->cx > 65535)
883     {
884         ERR( "invalid window width %d\n", cs->cx );
885         cs->cx = 65535;
886     }
887     if (cs->cy > 65535)
888     {
889         ERR( "invalid window height %d\n", cs->cy );
890         cs->cy = 65535;
891     }
892     if (cs->cx < 0)
893     {
894         ERR( "invalid window width %d\n", cs->cx );
895         cs->cx = 0;
896     }
897     if (cs->cy < 0)
898     {
899         ERR( "invalid window height %d\n", cs->cy );
900         cs->cy = 0;
901     }
902
903     /* initialize the dimensions before sending WM_GETMINMAXINFO */
904     SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy );
905     X11DRV_set_window_pos( hwnd, 0, &rect, &rect, SWP_NOZORDER, NULL );
906
907     /* create an X window if it's a top level window */
908     if (GetAncestor( hwnd, GA_PARENT ) == GetDesktopWindow())
909     {
910         if (!create_whole_window( display, data, cs->style )) goto failed;
911     }
912
913     /* get class or window DC if needed */
914     alloc_window_dce( data );
915
916     /* Call the WH_CBT hook */
917
918     /* the window style passed to the hook must be the real window style,
919      * rather than just the window style that the caller to CreateWindowEx
920      * passed in, so we have to copy the original CREATESTRUCT and get the
921      * the real style. */
922     cbcs = *cs;
923     cbcs.style = GetWindowLongW(hwnd, GWL_STYLE);
924
925     cbtc.lpcs = &cbcs;
926     cbtc.hwndInsertAfter = HWND_TOP;
927     if (HOOK_CallHooks( WH_CBT, HCBT_CREATEWND, (WPARAM)hwnd, (LPARAM)&cbtc, unicode ))
928     {
929         TRACE("CBT-hook returned !0\n");
930         goto failed;
931     }
932
933     /* Send the WM_GETMINMAXINFO message and fix the size if needed */
934     if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
935     {
936         POINT maxSize, maxPos, minTrack, maxTrack;
937
938         WINPOS_GetMinMaxInfo( hwnd, &maxSize, &maxPos, &minTrack, &maxTrack);
939         if (maxSize.x < cs->cx) cs->cx = maxSize.x;
940         if (maxSize.y < cs->cy) cs->cy = maxSize.y;
941         if (cs->cx < 0) cs->cx = 0;
942         if (cs->cy < 0) cs->cy = 0;
943
944         SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy );
945         if (!X11DRV_set_window_pos( hwnd, 0, &rect, &rect, SWP_NOZORDER, NULL )) return FALSE;
946     }
947
948     /* send WM_NCCREATE */
949     TRACE( "hwnd %p cs %d,%d %dx%d\n", hwnd, cs->x, cs->y, cs->cx, cs->cy );
950     if (unicode)
951         ret = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
952     else
953         ret = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
954     if (!ret)
955     {
956         WARN("aborted by WM_xxCREATE!\n");
957         return FALSE;
958     }
959
960     /* make sure the window is still valid */
961     if (!(data = X11DRV_get_win_data( hwnd ))) return FALSE;
962     if (data->whole_window) X11DRV_sync_window_style( display, data );
963
964     /* send WM_NCCALCSIZE */
965     rect = data->window_rect;
966     SendMessageW( hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&rect );
967
968     if (!(wndPtr = WIN_GetPtr(hwnd))) return FALSE;
969
970     /* yes, even if the CBT hook was called with HWND_TOP */
971     insert_after = ((wndPtr->dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) ? HWND_BOTTOM : HWND_TOP;
972
973     X11DRV_set_window_pos( hwnd, insert_after, &wndPtr->rectWindow, &rect, 0, NULL );
974
975     TRACE( "win %p window %ld,%ld,%ld,%ld client %ld,%ld,%ld,%ld whole %ld,%ld,%ld,%ld X client %ld,%ld,%ld,%ld xwin %x\n",
976            hwnd, wndPtr->rectWindow.left, wndPtr->rectWindow.top,
977            wndPtr->rectWindow.right, wndPtr->rectWindow.bottom,
978            wndPtr->rectClient.left, wndPtr->rectClient.top,
979            wndPtr->rectClient.right, wndPtr->rectClient.bottom,
980            data->whole_rect.left, data->whole_rect.top,
981            data->whole_rect.right, data->whole_rect.bottom,
982            data->client_rect.left, data->client_rect.top,
983            data->client_rect.right, data->client_rect.bottom,
984            (unsigned int)data->whole_window );
985
986     WIN_ReleasePtr( wndPtr );
987
988     if (unicode)
989         ret = (SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
990     else
991         ret = (SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
992
993     if (!ret) return FALSE;
994
995     NotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_WINDOW, 0);
996
997     /* Send the size messages */
998
999     if (!(wndPtr = WIN_GetPtr(hwnd)) || wndPtr == WND_OTHER_PROCESS) return FALSE;
1000     if (!(wndPtr->flags & WIN_NEED_SIZE))
1001     {
1002         RECT rect = wndPtr->rectClient;
1003         WIN_ReleasePtr( wndPtr );
1004         /* send it anyway */
1005         if (((rect.right-rect.left) <0) ||((rect.bottom-rect.top)<0))
1006             WARN("sending bogus WM_SIZE message 0x%08lx\n",
1007                  MAKELONG(rect.right-rect.left, rect.bottom-rect.top));
1008         SendMessageW( hwnd, WM_SIZE, SIZE_RESTORED,
1009                       MAKELONG(rect.right-rect.left, rect.bottom-rect.top));
1010         SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( rect.left, rect.top ) );
1011     }
1012     else WIN_ReleasePtr( wndPtr );
1013
1014     /* Show the window, maximizing or minimizing if needed */
1015
1016     style = GetWindowLongW( hwnd, GWL_STYLE );
1017     if (style & (WS_MINIMIZE | WS_MAXIMIZE))
1018     {
1019         extern UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect ); /*FIXME*/
1020
1021         RECT newPos;
1022         UINT swFlag = (style & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE;
1023         WIN_SetStyle( hwnd, 0, WS_MAXIMIZE | WS_MINIMIZE );
1024         WINPOS_MinMaximize( hwnd, swFlag, &newPos );
1025
1026         swFlag = SWP_FRAMECHANGED | SWP_NOZORDER; /* Frame always gets changed */
1027         if (!(style & WS_VISIBLE) || (style & WS_CHILD) || GetActiveWindow()) swFlag |= SWP_NOACTIVATE;
1028
1029         SetWindowPos( hwnd, 0, newPos.left, newPos.top,
1030                       newPos.right, newPos.bottom, swFlag );
1031     }
1032
1033     return TRUE;
1034
1035  failed:
1036     X11DRV_DestroyWindow( hwnd );
1037     return FALSE;
1038 }
1039
1040
1041 /***********************************************************************
1042  *              X11DRV_get_win_data
1043  *
1044  * Return the X11 data structure associated with a window.
1045  */
1046 struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1047 {
1048     char *data;
1049
1050     if (!hwnd || XFindContext( thread_display(), (XID)hwnd, win_data_context, &data )) data = NULL;
1051     return (struct x11drv_win_data *)data;
1052 }
1053
1054
1055 /***********************************************************************
1056  *              X11DRV_get_whole_window
1057  *
1058  * Return the X window associated with the full area of a window
1059  */
1060 Window X11DRV_get_whole_window( HWND hwnd )
1061 {
1062     struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1063
1064     if (!data) return (Window)GetPropA( hwnd, whole_window_prop );
1065     return data->whole_window;
1066 }
1067
1068
1069 /***********************************************************************
1070  *              X11DRV_get_ic
1071  *
1072  * Return the X input context associated with a window
1073  */
1074 XIC X11DRV_get_ic( HWND hwnd )
1075 {
1076     struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1077
1078     if (!data) return 0;
1079     return data->xic;
1080 }
1081
1082
1083 /*****************************************************************
1084  *              SetParent   (X11DRV.@)
1085  */
1086 HWND X11DRV_SetParent( HWND hwnd, HWND parent )
1087 {
1088     Display *display = thread_display();
1089     WND *wndPtr;
1090     BOOL ret;
1091     HWND old_parent = 0;
1092
1093     /* Windows hides the window first, then shows it again
1094      * including the WM_SHOWWINDOW messages and all */
1095     BOOL was_visible = ShowWindow( hwnd, SW_HIDE );
1096
1097     wndPtr = WIN_GetPtr( hwnd );
1098     if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return 0;
1099
1100     SERVER_START_REQ( set_parent )
1101     {
1102         req->handle = hwnd;
1103         req->parent = parent;
1104         if ((ret = !wine_server_call( req )))
1105         {
1106             old_parent = reply->old_parent;
1107             wndPtr->parent = parent = reply->full_parent;
1108         }
1109
1110     }
1111     SERVER_END_REQ;
1112     WIN_ReleasePtr( wndPtr );
1113     if (!ret) return 0;
1114
1115     if (parent != old_parent)
1116     {
1117         struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1118
1119         if (!data) return 0;
1120
1121         if (parent != GetDesktopWindow()) /* a child window */
1122         {
1123             if (old_parent == GetDesktopWindow())
1124             {
1125                 /* destroy the old X windows */
1126                 destroy_whole_window( display, data );
1127                 destroy_icon_window( display, data );
1128                 if (data->managed)
1129                 {
1130                     data->managed = FALSE;
1131                     RemovePropA( data->hwnd, managed_prop );
1132                 }
1133             }
1134         }
1135         else  /* new top level window */
1136         {
1137             /* FIXME: we ignore errors since we can't really recover anyway */
1138             create_whole_window( display, data, GetWindowLongW( hwnd, GWL_STYLE ) );
1139         }
1140     }
1141
1142     /* SetParent additionally needs to make hwnd the topmost window
1143        in the x-order and send the expected WM_WINDOWPOSCHANGING and
1144        WM_WINDOWPOSCHANGED notification messages.
1145     */
1146     SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0,
1147                   SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | (was_visible ? SWP_SHOWWINDOW : 0) );
1148     /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1149      * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
1150
1151     return old_parent;
1152 }
1153
1154
1155 /*****************************************************************
1156  *              SetFocus   (X11DRV.@)
1157  *
1158  * Set the X focus.
1159  * Explicit colormap management seems to work only with OLVWM.
1160  */
1161 void X11DRV_SetFocus( HWND hwnd )
1162 {
1163     Display *display = thread_display();
1164     struct x11drv_win_data *data;
1165     XWindowAttributes win_attr;
1166
1167     /* Only mess with the X focus if there's */
1168     /* no desktop window and if the window is not managed by the WM. */
1169     if (root_window != DefaultRootWindow(display)) return;
1170
1171     if (!hwnd)  /* If setting the focus to 0, uninstall the colormap */
1172     {
1173         wine_tsx11_lock();
1174         if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1175             XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1176         wine_tsx11_unlock();
1177         return;
1178     }
1179
1180     hwnd = GetAncestor( hwnd, GA_ROOT );
1181
1182     if (!(data = X11DRV_get_win_data( hwnd ))) return;
1183     if (data->managed || !data->whole_window) return;
1184
1185     /* Set X focus and install colormap */
1186     wine_tsx11_lock();
1187     if (XGetWindowAttributes( display, data->whole_window, &win_attr ) &&
1188         (win_attr.map_state == IsViewable))
1189     {
1190         /* If window is not viewable, don't change anything */
1191
1192         /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1193         /* FIXME: this is not entirely correct */
1194         XSetInputFocus( display, data->whole_window, RevertToParent,
1195                         /* CurrentTime */
1196                         GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1197         if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1198             XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1199     }
1200     wine_tsx11_unlock();
1201 }
1202
1203
1204 /**********************************************************************
1205  *              SetWindowIcon (X11DRV.@)
1206  *
1207  * hIcon or hIconSm has changed (or is being initialised for the
1208  * first time). Complete the X11 driver-specific initialisation
1209  * and set the window hints.
1210  *
1211  * This is not entirely correct, may need to create
1212  * an icon window and set the pixmap as a background
1213  */
1214 void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
1215 {
1216     Display *display = thread_display();
1217     struct x11drv_win_data *data;
1218     XWMHints* wm_hints;
1219
1220     if (type != ICON_BIG) return;  /* nothing to do here */
1221
1222     if (!(data = X11DRV_get_win_data( hwnd ))) return;
1223     if (!data->whole_window) return;
1224     if (!data->managed) return;
1225
1226     wine_tsx11_lock();
1227     if (!(wm_hints = XGetWMHints( display, data->whole_window ))) wm_hints = XAllocWMHints();
1228     wine_tsx11_unlock();
1229     if (wm_hints)
1230     {
1231         set_icon_hints( display, data, wm_hints, icon );
1232         wine_tsx11_lock();
1233         XSetWMHints( display, data->whole_window, wm_hints );
1234         XFree( wm_hints );
1235         wine_tsx11_unlock();
1236     }
1237 }