Release 20040408.
[wine.git] / dlls / x11drv / window.c
blob7c7a6e1fbb716b748772f1e6f65de508fe843836
1 /*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "config.h"
25 #include <stdarg.h>
26 #include <stdlib.h>
27 #ifdef HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
31 #include <X11/Xlib.h>
32 #include <X11/Xresource.h>
33 #include <X11/Xutil.h>
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"
42 #include "wine/debug.h"
43 #include "x11drv.h"
44 #include "win.h"
45 #include "winpos.h"
46 #include "mwm.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
50 extern Pixmap X11DRV_BITMAP_Pixmap( HBITMAP );
52 /* X context to associate a hwnd to an X window */
53 XContext winContext = 0;
55 Atom X11DRV_Atoms[NB_XATOMS - FIRST_XATOM];
57 static const char * const atom_names[NB_XATOMS - FIRST_XATOM] =
59 "CLIPBOARD",
60 "COMPOUND_TEXT",
61 "MULTIPLE",
62 "SELECTION_DATA",
63 "TARGETS",
64 "TEXT",
65 "UTF8_STRING",
66 "RAW_ASCENT",
67 "RAW_DESCENT",
68 "RAW_CAP_HEIGHT",
69 "WM_PROTOCOLS",
70 "WM_DELETE_WINDOW",
71 "WM_TAKE_FOCUS",
72 "KWM_DOCKWINDOW",
73 "DndProtocol",
74 "DndSelection",
75 "_MOTIF_WM_HINTS",
76 "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR",
77 "_NET_WM_PID",
78 "_NET_WM_PING",
79 "_NET_WM_NAME",
80 "_NET_WM_WINDOW_TYPE",
81 "_NET_WM_WINDOW_TYPE_UTILITY",
82 "XdndAware",
83 "XdndEnter",
84 "XdndPosition",
85 "XdndStatus",
86 "XdndLeave",
87 "XdndFinished",
88 "XdndDrop",
89 "XdndActionCopy",
90 "XdndActionMove",
91 "XdndActionLink",
92 "XdndActionAsk",
93 "XdndActionPrivate",
94 "XdndSelection",
95 "XdndTarget",
96 "XdndTypeList",
97 "WCF_DIB",
98 "image/gif",
99 "text/html",
100 "text/plain",
101 "text/rtf",
102 "text/richtext"
105 static LPCSTR whole_window_atom;
106 static LPCSTR client_window_atom;
107 static LPCSTR icon_window_atom;
109 /***********************************************************************
110 * is_window_managed
112 * Check if a given window should be managed
114 inline static BOOL is_window_managed( WND *win )
116 if (!managed_mode) return FALSE;
117 /* tray window is always managed */
118 if (win->dwExStyle & WS_EX_TRAYWINDOW) return TRUE;
119 /* child windows are not managed */
120 if (win->dwStyle & WS_CHILD) return FALSE;
121 /* windows with caption are managed */
122 if ((win->dwStyle & WS_CAPTION) == WS_CAPTION) return TRUE;
123 /* tool windows are not managed */
124 if (win->dwExStyle & WS_EX_TOOLWINDOW) return FALSE;
125 /* windows with thick frame are managed */
126 if (win->dwStyle & WS_THICKFRAME) return TRUE;
127 /* application windows are managed */
128 if (win->dwExStyle & WS_EX_APPWINDOW) return TRUE;
129 /* full-screen popup windows are managed */
130 if ((win->dwStyle & WS_POPUP) &&
131 (win->rectWindow.right-win->rectWindow.left) == screen_width &&
132 (win->rectWindow.bottom-win->rectWindow.top) == screen_height)
134 return TRUE;
136 /* default: not managed */
137 return FALSE;
141 /***********************************************************************
142 * is_client_window_mapped
144 * Check if the X client window should be mapped
146 inline static BOOL is_client_window_mapped( WND *win )
148 struct x11drv_win_data *data = win->pDriverData;
149 return !(win->dwStyle & WS_MINIMIZE) && !IsRectEmpty( &data->client_rect );
153 /***********************************************************************
154 * get_window_attributes
156 * Fill the window attributes structure for an X window.
158 static int get_window_attributes( Display *display, WND *win, XSetWindowAttributes *attr )
160 BOOL is_top_level = is_window_top_level( win );
161 BOOL managed = is_top_level && is_window_managed( win );
163 if (managed) WIN_SetExStyle( win->hwndSelf, win->dwExStyle | WS_EX_MANAGED );
164 else WIN_SetExStyle( win->hwndSelf, win->dwExStyle & ~WS_EX_MANAGED );
166 attr->override_redirect = !managed;
167 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
168 attr->save_under = ((win->clsStyle & CS_SAVEBITS) != 0);
169 attr->cursor = x11drv_thread_data()->cursor;
170 attr->event_mask = (ExposureMask | PointerMotionMask |
171 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
173 if (is_window_top_level( win ))
174 attr->event_mask |= (KeyPressMask | KeyReleaseMask | StructureNotifyMask |
175 FocusChangeMask | KeymapStateMask);
177 return (CWOverrideRedirect | CWSaveUnder | CWEventMask | CWColormap | CWCursor);
181 /***********************************************************************
182 * X11DRV_sync_window_style
184 * Change the X window attributes when the window style has changed.
186 void X11DRV_sync_window_style( Display *display, WND *win )
188 XSetWindowAttributes attr;
189 int mask;
191 wine_tsx11_lock();
192 mask = get_window_attributes( display, win, &attr );
193 XChangeWindowAttributes( display, get_whole_window(win), mask, &attr );
194 wine_tsx11_unlock();
198 /***********************************************************************
199 * get_window_changes
201 * fill the window changes structure
203 static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
205 int mask = 0;
207 if (old->right - old->left != new->right - new->left )
209 if (!(changes->width = new->right - new->left)) changes->width = 1;
210 mask |= CWWidth;
212 if (old->bottom - old->top != new->bottom - new->top)
214 if (!(changes->height = new->bottom - new->top)) changes->height = 1;
215 mask |= CWHeight;
217 if (old->left != new->left)
219 changes->x = new->left;
220 mask |= CWX;
222 if (old->top != new->top)
224 changes->y = new->top;
225 mask |= CWY;
227 return mask;
231 /***********************************************************************
232 * create_icon_window
234 static Window create_icon_window( Display *display, WND *win )
236 struct x11drv_win_data *data = win->pDriverData;
237 XSetWindowAttributes attr;
239 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
240 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
241 attr.bit_gravity = NorthWestGravity;
242 attr.backing_store = NotUseful/*WhenMapped*/;
243 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
245 wine_tsx11_lock();
246 data->icon_window = XCreateWindow( display, root_window, 0, 0,
247 GetSystemMetrics( SM_CXICON ),
248 GetSystemMetrics( SM_CYICON ),
249 0, screen_depth,
250 InputOutput, visual,
251 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
252 XSaveContext( display, data->icon_window, winContext, (char *)win->hwndSelf );
253 wine_tsx11_unlock();
255 TRACE( "created %lx\n", data->icon_window );
256 SetPropA( win->hwndSelf, icon_window_atom, (HANDLE)data->icon_window );
257 return data->icon_window;
262 /***********************************************************************
263 * destroy_icon_window
265 inline static void destroy_icon_window( Display *display, WND *win )
267 struct x11drv_win_data *data = win->pDriverData;
269 if (!data->icon_window) return;
270 if (x11drv_thread_data()->cursor_window == data->icon_window)
271 x11drv_thread_data()->cursor_window = None;
272 wine_tsx11_lock();
273 XDeleteContext( display, data->icon_window, winContext );
274 XDestroyWindow( display, data->icon_window );
275 data->icon_window = 0;
276 wine_tsx11_unlock();
277 RemovePropA( win->hwndSelf, icon_window_atom );
281 /***********************************************************************
282 * set_icon_hints
284 * Set the icon wm hints
286 static void set_icon_hints( Display *display, WND *wndPtr, XWMHints *hints, HICON hIcon )
288 X11DRV_WND_DATA *data = wndPtr->pDriverData;
290 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
291 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
292 data->hWMIconBitmap = 0;
293 data->hWMIconMask = 0;
295 if (!(wndPtr->dwExStyle & WS_EX_MANAGED))
297 destroy_icon_window( display, wndPtr );
298 hints->flags &= ~(IconPixmapHint | IconMaskHint | IconWindowHint);
300 else if (!hIcon)
302 if (!data->icon_window) create_icon_window( display, wndPtr );
303 hints->icon_window = data->icon_window;
304 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
306 else
308 HBITMAP hbmOrig;
309 RECT rcMask;
310 BITMAP bmMask;
311 ICONINFO ii;
312 HDC hDC;
314 GetIconInfo(hIcon, &ii);
316 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
317 rcMask.top = 0;
318 rcMask.left = 0;
319 rcMask.right = bmMask.bmWidth;
320 rcMask.bottom = bmMask.bmHeight;
322 hDC = CreateCompatibleDC(0);
323 hbmOrig = SelectObject(hDC, ii.hbmMask);
324 InvertRect(hDC, &rcMask);
325 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
326 SelectObject(hDC, hbmOrig);
327 DeleteDC(hDC);
329 data->hWMIconBitmap = ii.hbmColor;
330 data->hWMIconMask = ii.hbmMask;
332 hints->icon_pixmap = X11DRV_BITMAP_Pixmap(data->hWMIconBitmap);
333 hints->icon_mask = X11DRV_BITMAP_Pixmap(data->hWMIconMask);
334 destroy_icon_window( display, wndPtr );
335 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
340 /***********************************************************************
341 * set_size_hints
343 * set the window size hints
345 static void set_size_hints( Display *display, WND *win )
347 XSizeHints* size_hints;
348 struct x11drv_win_data *data = win->pDriverData;
350 if ((size_hints = XAllocSizeHints()))
352 size_hints->win_gravity = StaticGravity;
353 size_hints->x = data->whole_rect.left;
354 size_hints->y = data->whole_rect.top;
355 size_hints->flags = PWinGravity | PPosition;
357 if ( !(win->dwStyle & WS_THICKFRAME) )
359 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
360 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
361 size_hints->min_width = size_hints->max_width;
362 size_hints->min_height = size_hints->max_height;
363 size_hints->flags |= PMinSize | PMaxSize;
365 XSetWMNormalHints( display, data->whole_window, size_hints );
366 XFree( size_hints );
371 /***********************************************************************
372 * X11DRV_set_wm_hints
374 * Set the window manager hints for a newly-created window
376 void X11DRV_set_wm_hints( Display *display, WND *win )
378 struct x11drv_win_data *data = win->pDriverData;
379 Window group_leader;
380 XClassHint *class_hints;
381 XWMHints* wm_hints;
382 Atom protocols[3];
383 MwmHints mwm_hints;
384 Atom dndVersion = 4;
385 int i;
387 wine_tsx11_lock();
389 /* wm protocols */
390 i = 0;
391 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
392 protocols[i++] = x11drv_atom(_NET_WM_PING);
393 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
394 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
395 XA_ATOM, 32, PropModeReplace, (char *)protocols, i );
397 /* class hints */
398 if ((class_hints = XAllocClassHint()))
400 class_hints->res_name = "wine";
401 class_hints->res_class = "Wine";
402 XSetClassHint( display, data->whole_window, class_hints );
403 XFree( class_hints );
406 /* transient for hint */
407 if (win->owner)
409 Window owner_win = X11DRV_get_whole_window( win->owner );
410 XSetTransientForHint( display, data->whole_window, owner_win );
411 group_leader = owner_win;
413 else group_leader = data->whole_window;
415 /* size hints */
416 set_size_hints( display, win );
418 /* systray properties (KDE only for now) */
419 if (win->dwExStyle & WS_EX_TRAYWINDOW)
421 int val = 1;
422 XChangeProperty( display, data->whole_window, x11drv_atom(KWM_DOCKWINDOW),
423 x11drv_atom(KWM_DOCKWINDOW), 32, PropModeReplace, (char*)&val, 1 );
424 XChangeProperty( display, data->whole_window, x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR),
425 XA_WINDOW, 32, PropModeReplace, (char*)&data->whole_window, 1 );
428 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
429 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
430 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
431 i = getpid();
432 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
433 XA_CARDINAL, 32, PropModeReplace, (char *)&i, 1);
435 /* map WS_EX_TOOLWINDOW to _NET_WM_WINDOW_TYPE_UTILITY */
436 if (win->dwExStyle & WS_EX_TOOLWINDOW)
438 Atom a = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
439 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
440 XA_ATOM, 32, PropModeReplace, (char*)&a, 1);
443 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
444 mwm_hints.functions = 0;
445 if ((win->dwStyle & WS_CAPTION) == WS_CAPTION) mwm_hints.functions |= MWM_FUNC_MOVE;
446 if (win->dwStyle & WS_THICKFRAME) mwm_hints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
447 if (win->dwStyle & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
448 if (win->dwStyle & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
449 if (win->dwStyle & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
450 mwm_hints.decorations = 0;
451 if ((win->dwStyle & WS_CAPTION) == WS_CAPTION) mwm_hints.decorations |= MWM_DECOR_TITLE;
452 if (win->dwExStyle & WS_EX_DLGMODALFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER;
453 else if (win->dwStyle & WS_THICKFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
454 else if ((win->dwStyle & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER;
455 else if (win->dwStyle & WS_BORDER) mwm_hints.decorations |= MWM_DECOR_BORDER;
456 else if (!(win->dwStyle & (WS_CHILD|WS_POPUP))) mwm_hints.decorations |= MWM_DECOR_BORDER;
457 if (win->dwStyle & WS_SYSMENU) mwm_hints.decorations |= MWM_DECOR_MENU;
458 if (win->dwStyle & WS_MINIMIZEBOX) mwm_hints.decorations |= MWM_DECOR_MINIMIZE;
459 if (win->dwStyle & WS_MAXIMIZEBOX) mwm_hints.decorations |= MWM_DECOR_MAXIMIZE;
461 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
462 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
463 (char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
465 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
466 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
468 wm_hints = XAllocWMHints();
469 wine_tsx11_unlock();
471 /* wm hints */
472 if (wm_hints)
474 wm_hints->flags = InputHint | StateHint | WindowGroupHint;
475 wm_hints->input = !(win->dwStyle & WS_DISABLED);
477 set_icon_hints( display, win, wm_hints, (HICON)GetClassLongA( win->hwndSelf, GCL_HICON ));
479 wm_hints->initial_state = (win->dwStyle & WS_MINIMIZE) ? IconicState : NormalState;
480 wm_hints->window_group = group_leader;
482 wine_tsx11_lock();
483 XSetWMHints( display, data->whole_window, wm_hints );
484 XFree(wm_hints);
485 wine_tsx11_unlock();
490 /***********************************************************************
491 * X11DRV_set_iconic_state
493 * Set the X11 iconic state according to the window style.
495 void X11DRV_set_iconic_state( WND *win )
497 Display *display = thread_display();
498 struct x11drv_win_data *data = win->pDriverData;
499 XWMHints* wm_hints;
500 BOOL iconic = IsIconic( win->hwndSelf );
502 wine_tsx11_lock();
504 if (iconic) XUnmapWindow( display, data->client_window );
505 else if (is_client_window_mapped( win )) XMapWindow( display, data->client_window );
507 if (!(wm_hints = XGetWMHints( display, data->whole_window ))) wm_hints = XAllocWMHints();
508 wm_hints->flags |= StateHint | IconPositionHint;
509 wm_hints->initial_state = iconic ? IconicState : NormalState;
510 wm_hints->icon_x = win->rectWindow.left;
511 wm_hints->icon_y = win->rectWindow.top;
512 XSetWMHints( display, data->whole_window, wm_hints );
514 if (win->dwStyle & WS_VISIBLE)
516 if (iconic)
517 XIconifyWindow( display, data->whole_window, DefaultScreen(display) );
518 else
519 if (!IsRectEmpty( &win->rectWindow )) XMapWindow( display, data->whole_window );
522 XFree(wm_hints);
523 wine_tsx11_unlock();
527 /***********************************************************************
528 * X11DRV_window_to_X_rect
530 * Convert a rect from client to X window coordinates
532 void X11DRV_window_to_X_rect( WND *win, RECT *rect )
534 RECT rc;
536 if (!(win->dwExStyle & WS_EX_MANAGED)) return;
537 if (IsRectEmpty( rect )) return;
539 rc.top = rc.bottom = rc.left = rc.right = 0;
541 AdjustWindowRectEx( &rc, win->dwStyle & ~(WS_HSCROLL|WS_VSCROLL), FALSE, win->dwExStyle );
543 rect->left -= rc.left;
544 rect->right -= rc.right;
545 rect->top -= rc.top;
546 rect->bottom -= rc.bottom;
547 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
548 if (rect->left >= rect->right) rect->right = rect->left + 1;
552 /***********************************************************************
553 * X11DRV_X_to_window_rect
555 * Opposite of X11DRV_window_to_X_rect
557 void X11DRV_X_to_window_rect( WND *win, RECT *rect )
559 if (!(win->dwExStyle & WS_EX_MANAGED)) return;
560 if (IsRectEmpty( rect )) return;
562 AdjustWindowRectEx( rect, win->dwStyle & ~(WS_HSCROLL|WS_VSCROLL), FALSE, win->dwExStyle );
564 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
565 if (rect->left >= rect->right) rect->right = rect->left + 1;
569 /***********************************************************************
570 * X11DRV_sync_whole_window_position
572 * Synchronize the X whole window position with the Windows one
574 int X11DRV_sync_whole_window_position( Display *display, WND *win, int zorder )
576 XWindowChanges changes;
577 int mask;
578 struct x11drv_win_data *data = win->pDriverData;
579 RECT whole_rect = win->rectWindow;
581 X11DRV_window_to_X_rect( win, &whole_rect );
582 mask = get_window_changes( &changes, &data->whole_rect, &whole_rect );
584 if (zorder)
586 if (is_window_top_level( win ))
588 /* find window that this one must be after */
589 HWND prev = GetWindow( win->hwndSelf, GW_HWNDPREV );
590 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
591 prev = GetWindow( prev, GW_HWNDPREV );
592 if (!prev) /* top child */
594 changes.stack_mode = Above;
595 mask |= CWStackMode;
597 else
599 /* should use stack_mode Below but most window managers don't get it right */
600 /* so move it above the next one in Z order */
601 HWND next = GetWindow( win->hwndSelf, GW_HWNDNEXT );
602 while (next && !(GetWindowLongW( next, GWL_STYLE ) & WS_VISIBLE))
603 next = GetWindow( next, GW_HWNDNEXT );
604 if (next)
606 changes.stack_mode = Above;
607 changes.sibling = X11DRV_get_whole_window(next);
608 mask |= CWStackMode | CWSibling;
612 else
614 HWND next = GetWindow( win->hwndSelf, GW_HWNDNEXT );
616 if (win->parent == GetDesktopWindow() &&
617 root_window != DefaultRootWindow(display))
619 /* in desktop mode we need the sibling to belong to the same process */
620 while (next)
622 WND *ptr = WIN_GetPtr( next );
623 if (ptr != WND_OTHER_PROCESS)
625 WIN_ReleasePtr( ptr );
626 break;
628 next = GetWindow( next, GW_HWNDNEXT );
632 if (!next) /* bottom child */
634 changes.stack_mode = Below;
635 mask |= CWStackMode;
637 else
639 changes.stack_mode = Above;
640 changes.sibling = X11DRV_get_whole_window(next);
641 mask |= CWStackMode | CWSibling;
646 data->whole_rect = whole_rect;
648 if (mask)
650 TRACE( "setting win %lx pos %ld,%ld,%ldx%ld after %lx changes=%x\n",
651 data->whole_window, whole_rect.left, whole_rect.top,
652 whole_rect.right - whole_rect.left, whole_rect.bottom - whole_rect.top,
653 changes.sibling, mask );
654 wine_tsx11_lock();
655 XSync( gdi_display, False ); /* flush graphics operations before moving the window */
656 if (is_window_top_level( win ))
658 if (mask & (CWWidth|CWHeight)) set_size_hints( display, win );
659 XReconfigureWMWindow( display, data->whole_window,
660 DefaultScreen(display), mask, &changes );
662 else XConfigureWindow( display, data->whole_window, mask, &changes );
663 wine_tsx11_unlock();
665 return mask;
669 /***********************************************************************
670 * X11DRV_sync_client_window_position
672 * Synchronize the X client window position with the Windows one
674 int X11DRV_sync_client_window_position( Display *display, WND *win )
676 XWindowChanges changes;
677 int mask;
678 struct x11drv_win_data *data = win->pDriverData;
679 RECT client_rect = win->rectClient;
681 OffsetRect( &client_rect, -data->whole_rect.left, -data->whole_rect.top );
683 if ((mask = get_window_changes( &changes, &data->client_rect, &client_rect )))
685 BOOL was_mapped = is_client_window_mapped( win );
687 TRACE( "setting win %lx pos %ld,%ld,%ldx%ld (was %ld,%ld,%ldx%ld) after %lx changes=%x\n",
688 data->client_window, client_rect.left, client_rect.top,
689 client_rect.right - client_rect.left, client_rect.bottom - client_rect.top,
690 data->client_rect.left, data->client_rect.top,
691 data->client_rect.right - data->client_rect.left,
692 data->client_rect.bottom - data->client_rect.top,
693 changes.sibling, mask );
694 data->client_rect = client_rect;
695 wine_tsx11_lock();
696 XSync( gdi_display, False ); /* flush graphics operations before moving the window */
697 if (was_mapped && !is_client_window_mapped( win ))
698 XUnmapWindow( display, data->client_window );
699 XConfigureWindow( display, data->client_window, mask, &changes );
700 if (!was_mapped && is_client_window_mapped( win ))
701 XMapWindow( display, data->client_window );
702 wine_tsx11_unlock();
704 return mask;
708 /***********************************************************************
709 * X11DRV_register_window
711 * Associate an X window to a HWND.
713 void X11DRV_register_window( Display *display, HWND hwnd, struct x11drv_win_data *data )
715 wine_tsx11_lock();
716 XSaveContext( display, data->whole_window, winContext, (char *)hwnd );
717 XSaveContext( display, data->client_window, winContext, (char *)hwnd );
718 wine_tsx11_unlock();
722 /**********************************************************************
723 * create_desktop
725 static void create_desktop( Display *display, WND *wndPtr )
727 X11DRV_WND_DATA *data = wndPtr->pDriverData;
729 wine_tsx11_lock();
730 winContext = XUniqueContext();
731 XInternAtoms( display, (char **)atom_names, NB_XATOMS - FIRST_XATOM, False, X11DRV_Atoms );
732 wine_tsx11_unlock();
734 whole_window_atom = MAKEINTATOMA( GlobalAddAtomA( "__wine_x11_whole_window" ));
735 client_window_atom = MAKEINTATOMA( GlobalAddAtomA( "__wine_x11_client_window" ));
736 icon_window_atom = MAKEINTATOMA( GlobalAddAtomA( "__wine_x11_icon_window" ));
738 data->whole_window = data->client_window = root_window;
739 data->whole_rect = data->client_rect = wndPtr->rectWindow;
741 SetPropA( wndPtr->hwndSelf, whole_window_atom, (HANDLE)root_window );
742 SetPropA( wndPtr->hwndSelf, client_window_atom, (HANDLE)root_window );
743 SetPropA( wndPtr->hwndSelf, "__wine_x11_visual_id", (HANDLE)XVisualIDFromVisual(visual) );
745 X11DRV_InitClipboard();
747 if (root_window != DefaultRootWindow(display)) X11DRV_create_desktop_thread();
751 /**********************************************************************
752 * create_whole_window
754 * Create the whole X window for a given window
756 static Window create_whole_window( Display *display, WND *win )
758 struct x11drv_win_data *data = win->pDriverData;
759 int cx, cy, mask;
760 XSetWindowAttributes attr;
761 Window parent;
762 RECT rect;
763 BOOL is_top_level = is_window_top_level( win );
765 rect = win->rectWindow;
766 X11DRV_window_to_X_rect( win, &rect );
768 if (!(cx = rect.right - rect.left)) cx = 1;
769 if (!(cy = rect.bottom - rect.top)) cy = 1;
771 parent = X11DRV_get_client_window( win->parent );
773 wine_tsx11_lock();
775 mask = get_window_attributes( display, win, &attr );
777 /* set the attributes that don't change over the lifetime of the window */
778 attr.bit_gravity = ForgetGravity;
779 attr.win_gravity = NorthWestGravity;
780 attr.backing_store = NotUseful/*WhenMapped*/;
781 mask |= CWBitGravity | CWWinGravity | CWBackingStore;
783 data->whole_rect = rect;
784 data->whole_window = XCreateWindow( display, parent, rect.left, rect.top, cx, cy,
785 0, screen_depth, InputOutput, visual,
786 mask, &attr );
788 if (!data->whole_window)
790 wine_tsx11_unlock();
791 return 0;
794 /* non-maximized child must be at bottom of Z order */
795 if ((win->dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
797 XWindowChanges changes;
798 changes.stack_mode = Below;
799 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
802 wine_tsx11_unlock();
804 if (is_top_level)
806 XIM xim = x11drv_thread_data()->xim;
807 if (xim) data->xic = X11DRV_CreateIC( xim, display, data->whole_window );
808 X11DRV_set_wm_hints( display, win );
811 return data->whole_window;
815 /**********************************************************************
816 * create_client_window
818 * Create the client window for a given window
820 static Window create_client_window( Display *display, WND *win )
822 struct x11drv_win_data *data = win->pDriverData;
823 RECT rect = data->whole_rect;
824 XSetWindowAttributes attr;
826 OffsetRect( &rect, -data->whole_rect.left, -data->whole_rect.top );
827 data->client_rect = rect;
829 attr.event_mask = (ExposureMask | PointerMotionMask |
830 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
831 attr.bit_gravity = (win->clsStyle & (CS_VREDRAW | CS_HREDRAW)) ?
832 ForgetGravity : NorthWestGravity;
833 attr.backing_store = NotUseful/*WhenMapped*/;
835 wine_tsx11_lock();
836 data->client_window = XCreateWindow( display, data->whole_window, 0, 0,
837 max( rect.right - rect.left, 1 ),
838 max( rect.bottom - rect.top, 1 ),
839 0, screen_depth,
840 InputOutput, visual,
841 CWEventMask | CWBitGravity | CWBackingStore, &attr );
842 if (data->client_window && is_client_window_mapped( win ))
843 XMapWindow( display, data->client_window );
844 wine_tsx11_unlock();
845 return data->client_window;
849 /*****************************************************************
850 * SetWindowText (X11DRV.@)
852 BOOL X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
854 Display *display = thread_display();
855 UINT count;
856 char *buffer;
857 char *utf8_buffer;
858 Window win;
859 XTextProperty prop;
861 if ((win = X11DRV_get_whole_window( hwnd )))
863 /* allocate new buffer for window text */
864 count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
865 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count )))
867 ERR("Not enough memory for window text\n");
868 return FALSE;
870 WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
872 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
873 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
875 ERR("Not enough memory for window text in UTF-8\n");
876 return FALSE;
878 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
880 wine_tsx11_lock();
881 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
883 XSetWMName( display, win, &prop );
884 XSetWMIconName( display, win, &prop );
885 XFree( prop.value );
888 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
889 according to the standard
890 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
892 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
893 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
894 wine_tsx11_unlock();
896 HeapFree( GetProcessHeap(), 0, utf8_buffer );
897 HeapFree( GetProcessHeap(), 0, buffer );
899 return TRUE;
903 /***********************************************************************
904 * DestroyWindow (X11DRV.@)
906 BOOL X11DRV_DestroyWindow( HWND hwnd )
908 struct x11drv_thread_data *thread_data = x11drv_thread_data();
909 Display *display = thread_data->display;
910 WND *wndPtr = WIN_GetPtr( hwnd );
911 X11DRV_WND_DATA *data = wndPtr->pDriverData;
913 if (!data) goto done;
915 if (data->whole_window)
917 TRACE( "win %p xwin %lx/%lx\n", hwnd, data->whole_window, data->client_window );
918 if (thread_data->cursor_window == data->whole_window) thread_data->cursor_window = None;
919 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
920 wine_tsx11_lock();
921 XSync( gdi_display, False ); /* flush any reference to this drawable in GDI queue */
922 XDeleteContext( display, data->whole_window, winContext );
923 XDeleteContext( display, data->client_window, winContext );
924 XDestroyWindow( display, data->whole_window ); /* this destroys client too */
925 if (data->xic)
927 XUnsetICFocus( data->xic );
928 XDestroyIC( data->xic );
930 destroy_icon_window( display, wndPtr );
931 wine_tsx11_unlock();
934 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
935 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
936 HeapFree( GetProcessHeap(), 0, data );
937 wndPtr->pDriverData = NULL;
938 done:
939 WIN_ReleasePtr( wndPtr );
940 return TRUE;
944 /**********************************************************************
945 * CreateWindow (X11DRV.@)
947 BOOL X11DRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode )
949 Display *display = thread_display();
950 WND *wndPtr;
951 struct x11drv_win_data *data;
952 RECT rect;
953 CBT_CREATEWNDA cbtc;
954 BOOL ret = FALSE;
956 if (cs->cx > 65535)
958 ERR( "invalid window width %d\n", cs->cx );
959 cs->cx = 65535;
961 if (cs->cy > 65535)
963 ERR( "invalid window height %d\n", cs->cx );
964 cs->cy = 65535;
967 if (!(data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data)))) return FALSE;
968 data->whole_window = 0;
969 data->client_window = 0;
970 data->icon_window = 0;
971 data->xic = 0;
972 data->hWMIconBitmap = 0;
973 data->hWMIconMask = 0;
975 wndPtr = WIN_GetPtr( hwnd );
976 wndPtr->pDriverData = data;
978 /* initialize the dimensions before sending WM_GETMINMAXINFO */
979 SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy );
980 WIN_SetRectangles( hwnd, &rect, &rect );
982 if (!wndPtr->parent)
984 create_desktop( display, wndPtr );
985 WIN_ReleasePtr( wndPtr );
986 return TRUE;
989 if (!create_whole_window( display, wndPtr )) goto failed;
990 if (!create_client_window( display, wndPtr )) goto failed;
991 wine_tsx11_lock();
992 XSync( display, False );
993 wine_tsx11_unlock();
995 SetPropA( hwnd, whole_window_atom, (HANDLE)data->whole_window );
996 SetPropA( hwnd, client_window_atom, (HANDLE)data->client_window );
998 /* Call the WH_CBT hook */
999 cbtc.lpcs = cs;
1000 cbtc.hwndInsertAfter = HWND_TOP;
1001 if (HOOK_CallHooks( WH_CBT, HCBT_CREATEWND, (WPARAM)hwnd, (LPARAM)&cbtc, unicode ))
1003 TRACE("CBT-hook returned !0\n");
1004 goto failed;
1007 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
1008 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
1010 POINT maxSize, maxPos, minTrack, maxTrack;
1012 WIN_ReleasePtr( wndPtr );
1013 WINPOS_GetMinMaxInfo( hwnd, &maxSize, &maxPos, &minTrack, &maxTrack);
1014 if (maxSize.x < cs->cx) cs->cx = maxSize.x;
1015 if (maxSize.y < cs->cy) cs->cy = maxSize.y;
1016 if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
1017 if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
1018 if (cs->cx < 0) cs->cx = 0;
1019 if (cs->cy < 0) cs->cy = 0;
1021 if (!(wndPtr = WIN_GetPtr( hwnd ))) return FALSE;
1022 SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy );
1023 WIN_SetRectangles( hwnd, &rect, &rect );
1024 X11DRV_sync_whole_window_position( display, wndPtr, 0 );
1026 WIN_ReleasePtr( wndPtr );
1028 /* send WM_NCCREATE */
1029 TRACE( "hwnd %p cs %d,%d %dx%d\n", hwnd, cs->x, cs->y, cs->cx, cs->cy );
1030 if (unicode)
1031 ret = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
1032 else
1033 ret = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
1034 if (!ret)
1036 WARN("aborted by WM_xxCREATE!\n");
1037 return FALSE;
1040 if (!(wndPtr = WIN_GetPtr(hwnd))) return FALSE;
1042 X11DRV_sync_window_style( display, wndPtr );
1044 /* send WM_NCCALCSIZE */
1045 rect = wndPtr->rectWindow;
1046 WIN_ReleasePtr( wndPtr );
1047 SendMessageW( hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&rect );
1049 if (!(wndPtr = WIN_GetPtr(hwnd))) return FALSE;
1050 if (rect.left > rect.right || rect.top > rect.bottom) rect = wndPtr->rectWindow;
1051 WIN_SetRectangles( hwnd, &wndPtr->rectWindow, &rect );
1052 X11DRV_sync_client_window_position( display, wndPtr );
1053 X11DRV_register_window( display, hwnd, data );
1055 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/%x\n",
1056 hwnd, wndPtr->rectWindow.left, wndPtr->rectWindow.top,
1057 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom,
1058 wndPtr->rectClient.left, wndPtr->rectClient.top,
1059 wndPtr->rectClient.right, wndPtr->rectClient.bottom,
1060 data->whole_rect.left, data->whole_rect.top,
1061 data->whole_rect.right, data->whole_rect.bottom,
1062 data->client_rect.left, data->client_rect.top,
1063 data->client_rect.right, data->client_rect.bottom,
1064 (unsigned int)data->whole_window, (unsigned int)data->client_window );
1066 if ((wndPtr->dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
1067 WIN_LinkWindow( hwnd, wndPtr->parent, HWND_BOTTOM );
1068 else
1069 WIN_LinkWindow( hwnd, wndPtr->parent, HWND_TOP );
1071 WIN_ReleasePtr( wndPtr );
1073 if (unicode)
1074 ret = (SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
1075 else
1076 ret = (SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
1078 if (!ret)
1080 WIN_UnlinkWindow( hwnd );
1081 return FALSE;
1084 /* Send the size messages */
1086 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return FALSE;
1087 if (!(wndPtr->flags & WIN_NEED_SIZE))
1089 /* send it anyway */
1090 if (((wndPtr->rectClient.right-wndPtr->rectClient.left) <0)
1091 ||((wndPtr->rectClient.bottom-wndPtr->rectClient.top)<0))
1092 WARN("sending bogus WM_SIZE message 0x%08lx\n",
1093 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1094 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1095 SendMessageW( hwnd, WM_SIZE, SIZE_RESTORED,
1096 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1097 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1098 SendMessageW( hwnd, WM_MOVE, 0,
1099 MAKELONG( wndPtr->rectClient.left, wndPtr->rectClient.top ) );
1102 /* Show the window, maximizing or minimizing if needed */
1104 if (wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE))
1106 extern UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect ); /*FIXME*/
1108 RECT newPos;
1109 UINT swFlag = (wndPtr->dwStyle & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE;
1110 WIN_SetStyle( hwnd, wndPtr->dwStyle & ~(WS_MAXIMIZE | WS_MINIMIZE) );
1111 WINPOS_MinMaximize( hwnd, swFlag, &newPos );
1112 swFlag = ((wndPtr->dwStyle & WS_CHILD) || GetActiveWindow())
1113 ? SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED
1114 : SWP_NOZORDER | SWP_FRAMECHANGED;
1115 SetWindowPos( hwnd, 0, newPos.left, newPos.top,
1116 newPos.right, newPos.bottom, swFlag );
1119 WIN_ReleaseWndPtr( wndPtr );
1120 return TRUE;
1122 failed:
1123 X11DRV_DestroyWindow( hwnd );
1124 if (wndPtr) WIN_ReleasePtr( wndPtr );
1125 return FALSE;
1129 /***********************************************************************
1130 * X11DRV_get_client_window
1132 * Return the X window associated with the client area of a window
1134 Window X11DRV_get_client_window( HWND hwnd )
1136 Window ret = 0;
1137 WND *win = WIN_GetPtr( hwnd );
1139 if (win == WND_OTHER_PROCESS)
1140 return (Window)GetPropA( hwnd, client_window_atom );
1142 if (win)
1144 struct x11drv_win_data *data = win->pDriverData;
1145 ret = data->client_window;
1146 WIN_ReleasePtr( win );
1148 return ret;
1152 /***********************************************************************
1153 * X11DRV_get_whole_window
1155 * Return the X window associated with the full area of a window
1157 Window X11DRV_get_whole_window( HWND hwnd )
1159 Window ret = 0;
1160 WND *win = WIN_GetPtr( hwnd );
1162 if (win == WND_OTHER_PROCESS)
1163 return (Window)GetPropA( hwnd, whole_window_atom );
1165 if (win)
1167 struct x11drv_win_data *data = win->pDriverData;
1168 ret = data->whole_window;
1169 WIN_ReleasePtr( win );
1171 return ret;
1175 /***********************************************************************
1176 * X11DRV_get_ic
1178 * Return the X input context associated with a window
1180 XIC X11DRV_get_ic( HWND hwnd )
1182 XIC ret = 0;
1183 WND *win = WIN_GetPtr( hwnd );
1185 if (win && win != WND_OTHER_PROCESS)
1187 struct x11drv_win_data *data = win->pDriverData;
1188 ret = data->xic;
1189 WIN_ReleasePtr( win );
1191 return ret;
1195 /*****************************************************************
1196 * SetParent (X11DRV.@)
1198 HWND X11DRV_SetParent( HWND hwnd, HWND parent )
1200 Display *display = thread_display();
1201 WND *wndPtr;
1202 HWND retvalue;
1204 /* Windows hides the window first, then shows it again
1205 * including the WM_SHOWWINDOW messages and all */
1206 BOOL was_visible = ShowWindow( hwnd, SW_HIDE );
1208 if (!IsWindow( parent )) return 0;
1209 if (!(wndPtr = WIN_GetPtr(hwnd)) || wndPtr == WND_OTHER_PROCESS) return 0;
1211 retvalue = wndPtr->parent; /* old parent */
1212 if (parent != retvalue)
1214 struct x11drv_win_data *data = wndPtr->pDriverData;
1216 WIN_LinkWindow( hwnd, parent, HWND_TOP );
1218 if (parent != GetDesktopWindow()) /* a child window */
1220 if (!(wndPtr->dwStyle & WS_CHILD))
1222 HMENU menu = (HMENU)SetWindowLongW( hwnd, GWL_ID, 0 );
1223 if (menu) DestroyMenu( menu );
1227 if (is_window_top_level( wndPtr )) X11DRV_set_wm_hints( display, wndPtr );
1228 wine_tsx11_lock();
1229 X11DRV_sync_window_style( display, wndPtr );
1230 XReparentWindow( display, data->whole_window, X11DRV_get_client_window(parent),
1231 data->whole_rect.left, data->whole_rect.top );
1232 wine_tsx11_unlock();
1234 WIN_ReleasePtr( wndPtr );
1236 /* SetParent additionally needs to make hwnd the topmost window
1237 in the x-order and send the expected WM_WINDOWPOSCHANGING and
1238 WM_WINDOWPOSCHANGED notification messages.
1240 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0,
1241 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | (was_visible ? SWP_SHOWWINDOW : 0) );
1242 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1243 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
1245 return retvalue;
1249 /*****************************************************************
1250 * SetFocus (X11DRV.@)
1252 * Set the X focus.
1253 * Explicit colormap management seems to work only with OLVWM.
1255 void X11DRV_SetFocus( HWND hwnd )
1257 Display *display = thread_display();
1258 XWindowAttributes win_attr;
1259 Window win;
1261 /* Only mess with the X focus if there's */
1262 /* no desktop window and if the window is not managed by the WM. */
1263 if (root_window != DefaultRootWindow(display)) return;
1265 if (!hwnd) /* If setting the focus to 0, uninstall the colormap */
1267 wine_tsx11_lock();
1268 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1269 XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1270 wine_tsx11_unlock();
1271 return;
1274 hwnd = GetAncestor( hwnd, GA_ROOT );
1275 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MANAGED) return;
1276 if (!(win = X11DRV_get_whole_window( hwnd ))) return;
1278 /* Set X focus and install colormap */
1279 wine_tsx11_lock();
1280 if (XGetWindowAttributes( display, win, &win_attr ) &&
1281 (win_attr.map_state == IsViewable))
1283 /* If window is not viewable, don't change anything */
1285 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1286 /* FIXME: this is not entirely correct */
1287 XSetInputFocus( display, win, RevertToParent,
1288 /*CurrentTime*/ GetMessageTime() + X11DRV_server_startticks );
1289 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1290 XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1292 wine_tsx11_unlock();
1296 /**********************************************************************
1297 * SetWindowIcon (X11DRV.@)
1299 * hIcon or hIconSm has changed (or is being initialised for the
1300 * first time). Complete the X11 driver-specific initialisation
1301 * and set the window hints.
1303 * This is not entirely correct, may need to create
1304 * an icon window and set the pixmap as a background
1306 void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
1308 WND *wndPtr;
1309 Display *display = thread_display();
1311 if (type != ICON_BIG) return; /* nothing to do here */
1313 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return;
1315 if (wndPtr->dwExStyle & WS_EX_MANAGED)
1317 Window win = get_whole_window(wndPtr);
1318 XWMHints* wm_hints;
1320 wine_tsx11_lock();
1321 if (!(wm_hints = XGetWMHints( display, win ))) wm_hints = XAllocWMHints();
1322 wine_tsx11_unlock();
1323 if (wm_hints)
1325 set_icon_hints( display, wndPtr, wm_hints, icon );
1326 wine_tsx11_lock();
1327 XSetWMHints( display, win, wm_hints );
1328 XFree( wm_hints );
1329 wine_tsx11_unlock();
1332 WIN_ReleasePtr( wndPtr );