Store window icons in the window structure so that WM_SETICON can do
[wine/multimedia.git] / dlls / x11drv / window.c
blob6f402366ed3d6343f66c47a7ea4520fd59120982
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 #define HAS_DLGFRAME(style,exStyle) \
53 (((exStyle) & WS_EX_DLGMODALFRAME) || \
54 (((style) & WS_DLGFRAME) && !((style) & WS_THICKFRAME)))
56 /* X context to associate a hwnd to an X window */
57 XContext winContext = 0;
59 Atom X11DRV_Atoms[NB_XATOMS - FIRST_XATOM];
61 static const char * const atom_names[NB_XATOMS - FIRST_XATOM] =
63 "CLIPBOARD",
64 "COMPOUND_TEXT",
65 "MULTIPLE",
66 "SELECTION_DATA",
67 "TARGETS",
68 "TEXT",
69 "UTF8_STRING",
70 "RAW_ASCENT",
71 "RAW_DESCENT",
72 "RAW_CAP_HEIGHT",
73 "WM_PROTOCOLS",
74 "WM_DELETE_WINDOW",
75 "WM_TAKE_FOCUS",
76 "KWM_DOCKWINDOW",
77 "DndProtocol",
78 "DndSelection",
79 "_MOTIF_WM_HINTS",
80 "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR",
81 "_NET_WM_PID",
82 "_NET_WM_PING",
83 "_NET_WM_NAME",
84 "_NET_WM_WINDOW_TYPE",
85 "_NET_WM_WINDOW_TYPE_UTILITY",
86 "XdndAware",
87 "XdndEnter",
88 "XdndPosition",
89 "XdndStatus",
90 "XdndLeave",
91 "XdndFinished",
92 "XdndDrop",
93 "XdndActionCopy",
94 "XdndActionMove",
95 "XdndActionLink",
96 "XdndActionAsk",
97 "XdndActionPrivate",
98 "XdndSelection",
99 "XdndTarget",
100 "XdndTypeList",
101 "image/gif",
102 "text/html",
103 "text/plain",
104 "text/rtf",
105 "text/richtext"
108 static LPCSTR whole_window_atom;
109 static LPCSTR client_window_atom;
110 static LPCSTR icon_window_atom;
112 /***********************************************************************
113 * is_window_managed
115 * Check if a given window should be managed
117 inline static BOOL is_window_managed( WND *win )
119 if (!managed_mode) return FALSE;
120 /* tray window is always managed */
121 if (win->dwExStyle & WS_EX_TRAYWINDOW) return TRUE;
122 /* child windows are not managed */
123 if (win->dwStyle & WS_CHILD) return FALSE;
124 /* windows with caption are managed */
125 if ((win->dwStyle & WS_CAPTION) == WS_CAPTION) return TRUE;
126 /* tool windows are not managed */
127 if (win->dwExStyle & WS_EX_TOOLWINDOW) return FALSE;
128 /* windows with thick frame are managed */
129 if (win->dwStyle & WS_THICKFRAME) return TRUE;
130 /* application windows are managed */
131 if (win->dwExStyle & WS_EX_APPWINDOW) return TRUE;
132 /* popup windows that aren't owned are managed */
133 if ((win->dwStyle & WS_POPUP) && !win->owner) return TRUE;
134 /* default: not managed */
135 return FALSE;
139 /***********************************************************************
140 * is_client_window_mapped
142 * Check if the X client window should be mapped
144 inline static BOOL is_client_window_mapped( WND *win )
146 struct x11drv_win_data *data = win->pDriverData;
147 return !(win->dwStyle & WS_MINIMIZE) && !IsRectEmpty( &data->client_rect );
151 /***********************************************************************
152 * get_window_attributes
154 * Fill the window attributes structure for an X window.
156 static int get_window_attributes( Display *display, WND *win, XSetWindowAttributes *attr )
158 BOOL is_top_level = is_window_top_level( win );
159 BOOL managed = is_top_level && is_window_managed( win );
161 if (managed) WIN_SetExStyle( win->hwndSelf, win->dwExStyle | WS_EX_MANAGED );
162 else WIN_SetExStyle( win->hwndSelf, win->dwExStyle & ~WS_EX_MANAGED );
164 attr->override_redirect = !managed;
165 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
166 attr->save_under = ((win->clsStyle & CS_SAVEBITS) != 0);
167 attr->cursor = x11drv_thread_data()->cursor;
168 attr->event_mask = (ExposureMask | PointerMotionMask |
169 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
171 if (is_window_top_level( win ))
172 attr->event_mask |= (KeyPressMask | KeyReleaseMask | StructureNotifyMask |
173 FocusChangeMask | KeymapStateMask);
175 return (CWOverrideRedirect | CWSaveUnder | CWEventMask | CWColormap | CWCursor);
179 /***********************************************************************
180 * X11DRV_sync_window_style
182 * Change the X window attributes when the window style has changed.
184 void X11DRV_sync_window_style( Display *display, WND *win )
186 XSetWindowAttributes attr;
187 int mask;
189 wine_tsx11_lock();
190 mask = get_window_attributes( display, win, &attr );
191 XChangeWindowAttributes( display, get_whole_window(win), mask, &attr );
192 wine_tsx11_unlock();
196 /***********************************************************************
197 * get_window_changes
199 * fill the window changes structure
201 static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
203 int mask = 0;
205 if (old->right - old->left != new->right - new->left )
207 if (!(changes->width = new->right - new->left)) changes->width = 1;
208 mask |= CWWidth;
210 if (old->bottom - old->top != new->bottom - new->top)
212 if (!(changes->height = new->bottom - new->top)) changes->height = 1;
213 mask |= CWHeight;
215 if (old->left != new->left)
217 changes->x = new->left;
218 mask |= CWX;
220 if (old->top != new->top)
222 changes->y = new->top;
223 mask |= CWY;
225 return mask;
229 /***********************************************************************
230 * create_icon_window
232 static Window create_icon_window( Display *display, WND *win )
234 struct x11drv_win_data *data = win->pDriverData;
235 XSetWindowAttributes attr;
237 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
238 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
239 attr.bit_gravity = NorthWestGravity;
240 attr.backing_store = NotUseful/*WhenMapped*/;
241 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
243 wine_tsx11_lock();
244 data->icon_window = XCreateWindow( display, root_window, 0, 0,
245 GetSystemMetrics( SM_CXICON ),
246 GetSystemMetrics( SM_CYICON ),
247 0, screen_depth,
248 InputOutput, visual,
249 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
250 XSaveContext( display, data->icon_window, winContext, (char *)win->hwndSelf );
251 wine_tsx11_unlock();
253 TRACE( "created %lx\n", data->icon_window );
254 SetPropA( win->hwndSelf, icon_window_atom, (HANDLE)data->icon_window );
255 return data->icon_window;
260 /***********************************************************************
261 * destroy_icon_window
263 inline static void destroy_icon_window( Display *display, WND *win )
265 struct x11drv_win_data *data = win->pDriverData;
267 if (!data->icon_window) return;
268 if (x11drv_thread_data()->cursor_window == data->icon_window)
269 x11drv_thread_data()->cursor_window = None;
270 wine_tsx11_lock();
271 XDeleteContext( display, data->icon_window, winContext );
272 XDestroyWindow( display, data->icon_window );
273 data->icon_window = 0;
274 wine_tsx11_unlock();
275 RemovePropA( win->hwndSelf, icon_window_atom );
279 /***********************************************************************
280 * set_icon_hints
282 * Set the icon wm hints
284 static void set_icon_hints( Display *display, WND *wndPtr, XWMHints *hints, HICON hIcon )
286 X11DRV_WND_DATA *data = wndPtr->pDriverData;
288 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
289 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
290 data->hWMIconBitmap = 0;
291 data->hWMIconMask = 0;
293 if (!(wndPtr->dwExStyle & WS_EX_MANAGED))
295 destroy_icon_window( display, wndPtr );
296 hints->flags &= ~(IconPixmapHint | IconMaskHint | IconWindowHint);
298 else if (!hIcon)
300 if (!data->icon_window) create_icon_window( display, wndPtr );
301 hints->icon_window = data->icon_window;
302 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
304 else
306 HBITMAP hbmOrig;
307 RECT rcMask;
308 BITMAP bmMask;
309 ICONINFO ii;
310 HDC hDC;
312 GetIconInfo(hIcon, &ii);
314 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
315 rcMask.top = 0;
316 rcMask.left = 0;
317 rcMask.right = bmMask.bmWidth;
318 rcMask.bottom = bmMask.bmHeight;
320 hDC = CreateCompatibleDC(0);
321 hbmOrig = SelectObject(hDC, ii.hbmMask);
322 InvertRect(hDC, &rcMask);
323 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
324 SelectObject(hDC, hbmOrig);
325 DeleteDC(hDC);
327 data->hWMIconBitmap = ii.hbmColor;
328 data->hWMIconMask = ii.hbmMask;
330 hints->icon_pixmap = X11DRV_BITMAP_Pixmap(data->hWMIconBitmap);
331 hints->icon_mask = X11DRV_BITMAP_Pixmap(data->hWMIconMask);
332 destroy_icon_window( display, wndPtr );
333 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
338 /***********************************************************************
339 * set_size_hints
341 * set the window size hints
343 static void set_size_hints( Display *display, WND *win )
345 XSizeHints* size_hints;
346 struct x11drv_win_data *data = win->pDriverData;
348 if ((size_hints = XAllocSizeHints()))
350 size_hints->win_gravity = StaticGravity;
351 size_hints->x = data->whole_rect.left;
352 size_hints->y = data->whole_rect.top;
353 size_hints->flags = PWinGravity | PPosition;
355 if (HAS_DLGFRAME( win->dwStyle, win->dwExStyle ))
357 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
358 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
359 size_hints->min_width = size_hints->max_width;
360 size_hints->min_height = size_hints->max_height;
361 size_hints->flags |= PMinSize | PMaxSize;
363 XSetWMNormalHints( display, data->whole_window, size_hints );
364 XFree( size_hints );
369 /***********************************************************************
370 * X11DRV_set_wm_hints
372 * Set the window manager hints for a newly-created window
374 void X11DRV_set_wm_hints( Display *display, WND *win )
376 struct x11drv_win_data *data = win->pDriverData;
377 Window group_leader;
378 XClassHint *class_hints;
379 XWMHints* wm_hints;
380 Atom protocols[3];
381 MwmHints mwm_hints;
382 Atom dndVersion = 4;
383 int i;
385 wine_tsx11_lock();
387 /* wm protocols */
388 i = 0;
389 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
390 protocols[i++] = x11drv_atom(_NET_WM_PING);
391 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
392 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
393 XA_ATOM, 32, PropModeReplace, (char *)protocols, i );
395 /* class hints */
396 if ((class_hints = XAllocClassHint()))
398 class_hints->res_name = "wine";
399 class_hints->res_class = "Wine";
400 XSetClassHint( display, data->whole_window, class_hints );
401 XFree( class_hints );
404 /* transient for hint */
405 if (win->owner)
407 Window owner_win = X11DRV_get_whole_window( win->owner );
408 XSetTransientForHint( display, data->whole_window, owner_win );
409 group_leader = owner_win;
411 else group_leader = data->whole_window;
413 /* size hints */
414 set_size_hints( display, win );
416 /* systray properties (KDE only for now) */
417 if (win->dwExStyle & WS_EX_TRAYWINDOW)
419 int val = 1;
420 XChangeProperty( display, data->whole_window, x11drv_atom(KWM_DOCKWINDOW),
421 x11drv_atom(KWM_DOCKWINDOW), 32, PropModeReplace, (char*)&val, 1 );
422 XChangeProperty( display, data->whole_window, x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR),
423 XA_WINDOW, 32, PropModeReplace, (char*)&data->whole_window, 1 );
426 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
427 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
428 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
429 i = getpid();
430 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
431 XA_CARDINAL, 32, PropModeReplace, (char *)&i, 1);
433 /* map WS_EX_TOOLWINDOW to _NET_WM_WINDOW_TYPE_UTILITY */
434 if (win->dwExStyle & WS_EX_TOOLWINDOW)
436 Atom a = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
437 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
438 XA_ATOM, 32, PropModeReplace, (char*)&a, 1);
441 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
442 mwm_hints.functions = 0;
443 if ((win->dwStyle & WS_CAPTION) == WS_CAPTION) mwm_hints.functions |= MWM_FUNC_MOVE;
444 if (win->dwStyle & WS_THICKFRAME) mwm_hints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
445 if (win->dwStyle & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
446 if (win->dwStyle & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
447 if (win->dwStyle & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
448 mwm_hints.decorations = 0;
449 if ((win->dwStyle & WS_CAPTION) == WS_CAPTION) mwm_hints.decorations |= MWM_DECOR_TITLE;
450 if (win->dwExStyle & WS_EX_DLGMODALFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER;
451 else if (win->dwStyle & WS_THICKFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
452 else if ((win->dwStyle & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER;
453 else if (win->dwStyle & WS_BORDER) mwm_hints.decorations |= MWM_DECOR_BORDER;
454 else if (!(win->dwStyle & (WS_CHILD|WS_POPUP))) mwm_hints.decorations |= MWM_DECOR_BORDER;
455 if (win->dwStyle & WS_SYSMENU) mwm_hints.decorations |= MWM_DECOR_MENU;
456 if (win->dwStyle & WS_MINIMIZEBOX) mwm_hints.decorations |= MWM_DECOR_MINIMIZE;
457 if (win->dwStyle & WS_MAXIMIZEBOX) mwm_hints.decorations |= MWM_DECOR_MAXIMIZE;
459 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
460 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
461 (char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
463 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
464 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
466 wm_hints = XAllocWMHints();
467 wine_tsx11_unlock();
469 /* wm hints */
470 if (wm_hints)
472 wm_hints->flags = InputHint | StateHint | WindowGroupHint;
473 wm_hints->input = !(win->dwStyle & WS_DISABLED);
475 set_icon_hints( display, win, wm_hints, (HICON)GetClassLongA( win->hwndSelf, GCL_HICON ));
477 wm_hints->initial_state = (win->dwStyle & WS_MINIMIZE) ? IconicState : NormalState;
478 wm_hints->window_group = group_leader;
480 wine_tsx11_lock();
481 XSetWMHints( display, data->whole_window, wm_hints );
482 XFree(wm_hints);
483 wine_tsx11_unlock();
488 /***********************************************************************
489 * X11DRV_set_iconic_state
491 * Set the X11 iconic state according to the window style.
493 void X11DRV_set_iconic_state( WND *win )
495 Display *display = thread_display();
496 struct x11drv_win_data *data = win->pDriverData;
497 XWMHints* wm_hints;
498 BOOL iconic = IsIconic( win->hwndSelf );
500 wine_tsx11_lock();
502 if (iconic) XUnmapWindow( display, data->client_window );
503 else if (is_client_window_mapped( win )) XMapWindow( display, data->client_window );
505 if (!(wm_hints = XGetWMHints( display, data->whole_window ))) wm_hints = XAllocWMHints();
506 wm_hints->flags |= StateHint | IconPositionHint;
507 wm_hints->initial_state = iconic ? IconicState : NormalState;
508 wm_hints->icon_x = win->rectWindow.left;
509 wm_hints->icon_y = win->rectWindow.top;
510 XSetWMHints( display, data->whole_window, wm_hints );
512 if (win->dwStyle & WS_VISIBLE)
514 if (iconic)
515 XIconifyWindow( display, data->whole_window, DefaultScreen(display) );
516 else
517 if (!IsRectEmpty( &win->rectWindow )) XMapWindow( display, data->whole_window );
520 XFree(wm_hints);
521 wine_tsx11_unlock();
525 /***********************************************************************
526 * X11DRV_window_to_X_rect
528 * Convert a rect from client to X window coordinates
530 void X11DRV_window_to_X_rect( WND *win, RECT *rect )
532 RECT rc;
534 if (!(win->dwExStyle & WS_EX_MANAGED)) return;
535 if (IsRectEmpty( rect )) return;
537 rc.top = rc.bottom = rc.left = rc.right = 0;
539 AdjustWindowRectEx( &rc, win->dwStyle & ~(WS_HSCROLL|WS_VSCROLL), FALSE, win->dwExStyle );
541 rect->left -= rc.left;
542 rect->right -= rc.right;
543 rect->top -= rc.top;
544 rect->bottom -= rc.bottom;
545 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
546 if (rect->left >= rect->right) rect->right = rect->left + 1;
550 /***********************************************************************
551 * X11DRV_X_to_window_rect
553 * Opposite of X11DRV_window_to_X_rect
555 void X11DRV_X_to_window_rect( WND *win, RECT *rect )
557 if (!(win->dwExStyle & WS_EX_MANAGED)) return;
558 if (IsRectEmpty( rect )) return;
560 AdjustWindowRectEx( rect, win->dwStyle & ~(WS_HSCROLL|WS_VSCROLL), FALSE, win->dwExStyle );
562 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
563 if (rect->left >= rect->right) rect->right = rect->left + 1;
567 /***********************************************************************
568 * X11DRV_sync_whole_window_position
570 * Synchronize the X whole window position with the Windows one
572 int X11DRV_sync_whole_window_position( Display *display, WND *win, int zorder )
574 XWindowChanges changes;
575 int mask;
576 struct x11drv_win_data *data = win->pDriverData;
577 RECT whole_rect = win->rectWindow;
579 X11DRV_window_to_X_rect( win, &whole_rect );
580 mask = get_window_changes( &changes, &data->whole_rect, &whole_rect );
582 if (zorder)
584 if (is_window_top_level( win ))
586 /* find window that this one must be after */
587 HWND prev = GetWindow( win->hwndSelf, GW_HWNDPREV );
588 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
589 prev = GetWindow( prev, GW_HWNDPREV );
590 if (!prev) /* top child */
592 changes.stack_mode = Above;
593 mask |= CWStackMode;
595 else
597 /* should use stack_mode Below but most window managers don't get it right */
598 /* so move it above the next one in Z order */
599 HWND next = GetWindow( win->hwndSelf, GW_HWNDNEXT );
600 while (next && !(GetWindowLongW( next, GWL_STYLE ) & WS_VISIBLE))
601 next = GetWindow( next, GW_HWNDNEXT );
602 if (next)
604 changes.stack_mode = Above;
605 changes.sibling = X11DRV_get_whole_window(next);
606 mask |= CWStackMode | CWSibling;
610 else
612 HWND next = GetWindow( win->hwndSelf, GW_HWNDNEXT );
614 if (win->parent == GetDesktopWindow() &&
615 root_window != DefaultRootWindow(display))
617 /* in desktop mode we need the sibling to belong to the same process */
618 while (next)
620 WND *ptr = WIN_GetPtr( next );
621 if (ptr != WND_OTHER_PROCESS)
623 WIN_ReleasePtr( ptr );
624 break;
626 next = GetWindow( next, GW_HWNDNEXT );
630 if (!next) /* bottom child */
632 changes.stack_mode = Below;
633 mask |= CWStackMode;
635 else
637 changes.stack_mode = Above;
638 changes.sibling = X11DRV_get_whole_window(next);
639 mask |= CWStackMode | CWSibling;
644 data->whole_rect = whole_rect;
646 if (mask)
648 TRACE( "setting win %lx pos %ld,%ld,%ldx%ld after %lx changes=%x\n",
649 data->whole_window, whole_rect.left, whole_rect.top,
650 whole_rect.right - whole_rect.left, whole_rect.bottom - whole_rect.top,
651 changes.sibling, mask );
652 wine_tsx11_lock();
653 XSync( gdi_display, False ); /* flush graphics operations before moving the window */
654 if (is_window_top_level( win ))
656 if (mask & (CWWidth|CWHeight)) set_size_hints( display, win );
657 XReconfigureWMWindow( display, data->whole_window,
658 DefaultScreen(display), mask, &changes );
660 else XConfigureWindow( display, data->whole_window, mask, &changes );
661 wine_tsx11_unlock();
663 return mask;
667 /***********************************************************************
668 * X11DRV_sync_client_window_position
670 * Synchronize the X client window position with the Windows one
672 int X11DRV_sync_client_window_position( Display *display, WND *win )
674 XWindowChanges changes;
675 int mask;
676 struct x11drv_win_data *data = win->pDriverData;
677 RECT client_rect = win->rectClient;
679 OffsetRect( &client_rect, -data->whole_rect.left, -data->whole_rect.top );
681 if ((mask = get_window_changes( &changes, &data->client_rect, &client_rect )))
683 BOOL was_mapped = is_client_window_mapped( win );
685 TRACE( "setting win %lx pos %ld,%ld,%ldx%ld (was %ld,%ld,%ldx%ld) after %lx changes=%x\n",
686 data->client_window, client_rect.left, client_rect.top,
687 client_rect.right - client_rect.left, client_rect.bottom - client_rect.top,
688 data->client_rect.left, data->client_rect.top,
689 data->client_rect.right - data->client_rect.left,
690 data->client_rect.bottom - data->client_rect.top,
691 changes.sibling, mask );
692 data->client_rect = client_rect;
693 wine_tsx11_lock();
694 XSync( gdi_display, False ); /* flush graphics operations before moving the window */
695 if (was_mapped && !is_client_window_mapped( win ))
696 XUnmapWindow( display, data->client_window );
697 XConfigureWindow( display, data->client_window, mask, &changes );
698 if (!was_mapped && is_client_window_mapped( win ))
699 XMapWindow( display, data->client_window );
700 wine_tsx11_unlock();
702 return mask;
706 /***********************************************************************
707 * X11DRV_register_window
709 * Associate an X window to a HWND.
711 void X11DRV_register_window( Display *display, HWND hwnd, struct x11drv_win_data *data )
713 wine_tsx11_lock();
714 XSaveContext( display, data->whole_window, winContext, (char *)hwnd );
715 XSaveContext( display, data->client_window, winContext, (char *)hwnd );
716 wine_tsx11_unlock();
720 /**********************************************************************
721 * create_desktop
723 static void create_desktop( Display *display, WND *wndPtr )
725 X11DRV_WND_DATA *data = wndPtr->pDriverData;
727 wine_tsx11_lock();
728 winContext = XUniqueContext();
729 XInternAtoms( display, (char **)atom_names, NB_XATOMS - FIRST_XATOM, False, X11DRV_Atoms );
730 wine_tsx11_unlock();
732 whole_window_atom = MAKEINTATOMA( GlobalAddAtomA( "__wine_x11_whole_window" ));
733 client_window_atom = MAKEINTATOMA( GlobalAddAtomA( "__wine_x11_client_window" ));
734 icon_window_atom = MAKEINTATOMA( GlobalAddAtomA( "__wine_x11_icon_window" ));
736 data->whole_window = data->client_window = root_window;
737 data->whole_rect = data->client_rect = wndPtr->rectWindow;
739 SetPropA( wndPtr->hwndSelf, whole_window_atom, (HANDLE)root_window );
740 SetPropA( wndPtr->hwndSelf, client_window_atom, (HANDLE)root_window );
741 SetPropA( wndPtr->hwndSelf, "__wine_x11_visual_id", (HANDLE)XVisualIDFromVisual(visual) );
743 X11DRV_InitClipboard();
745 if (root_window != DefaultRootWindow(display)) X11DRV_create_desktop_thread();
749 /**********************************************************************
750 * create_whole_window
752 * Create the whole X window for a given window
754 static Window create_whole_window( Display *display, WND *win )
756 struct x11drv_win_data *data = win->pDriverData;
757 int cx, cy, mask;
758 XSetWindowAttributes attr;
759 Window parent;
760 RECT rect;
761 BOOL is_top_level = is_window_top_level( win );
763 rect = win->rectWindow;
764 X11DRV_window_to_X_rect( win, &rect );
766 if (!(cx = rect.right - rect.left)) cx = 1;
767 if (!(cy = rect.bottom - rect.top)) cy = 1;
769 parent = X11DRV_get_client_window( win->parent );
771 wine_tsx11_lock();
773 mask = get_window_attributes( display, win, &attr );
775 /* set the attributes that don't change over the lifetime of the window */
776 attr.bit_gravity = ForgetGravity;
777 attr.win_gravity = NorthWestGravity;
778 attr.backing_store = NotUseful/*WhenMapped*/;
779 mask |= CWBitGravity | CWWinGravity | CWBackingStore;
781 data->whole_rect = rect;
782 data->whole_window = XCreateWindow( display, parent, rect.left, rect.top, cx, cy,
783 0, screen_depth, InputOutput, visual,
784 mask, &attr );
786 if (!data->whole_window)
788 wine_tsx11_unlock();
789 return 0;
792 if (is_top_level)
794 XIM xim = x11drv_thread_data()->xim;
795 if (xim) data->xic = XCreateIC( xim,
796 XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
797 XNClientWindow, data->whole_window,
798 XNFocusWindow, data->whole_window,
799 0 );
802 /* non-maximized child must be at bottom of Z order */
803 if ((win->dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
805 XWindowChanges changes;
806 changes.stack_mode = Below;
807 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
810 wine_tsx11_unlock();
812 if (is_top_level) X11DRV_set_wm_hints( display, win );
814 return data->whole_window;
818 /**********************************************************************
819 * create_client_window
821 * Create the client window for a given window
823 static Window create_client_window( Display *display, WND *win )
825 struct x11drv_win_data *data = win->pDriverData;
826 RECT rect = data->whole_rect;
827 XSetWindowAttributes attr;
829 OffsetRect( &rect, -data->whole_rect.left, -data->whole_rect.top );
830 data->client_rect = rect;
832 attr.event_mask = (ExposureMask | PointerMotionMask |
833 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
834 attr.bit_gravity = (win->clsStyle & (CS_VREDRAW | CS_HREDRAW)) ?
835 ForgetGravity : NorthWestGravity;
836 attr.backing_store = NotUseful/*WhenMapped*/;
838 wine_tsx11_lock();
839 data->client_window = XCreateWindow( display, data->whole_window, 0, 0,
840 max( rect.right - rect.left, 1 ),
841 max( rect.bottom - rect.top, 1 ),
842 0, screen_depth,
843 InputOutput, visual,
844 CWEventMask | CWBitGravity | CWBackingStore, &attr );
845 if (data->client_window && is_client_window_mapped( win ))
846 XMapWindow( display, data->client_window );
847 wine_tsx11_unlock();
848 return data->client_window;
852 /*****************************************************************
853 * SetWindowText (X11DRV.@)
855 BOOL X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
857 Display *display = thread_display();
858 UINT count;
859 char *buffer;
860 char *utf8_buffer;
861 Window win;
862 XTextProperty prop;
864 if ((win = X11DRV_get_whole_window( hwnd )))
866 /* allocate new buffer for window text */
867 count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
868 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count )))
870 ERR("Not enough memory for window text\n");
871 return FALSE;
873 WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
875 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
876 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
878 ERR("Not enough memory for window text in UTF-8\n");
879 return FALSE;
881 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
883 wine_tsx11_lock();
884 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
886 XSetWMName( display, win, &prop );
887 XSetWMIconName( display, win, &prop );
888 XFree( prop.value );
891 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
892 according to the standard
893 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
895 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
896 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
897 wine_tsx11_unlock();
899 HeapFree( GetProcessHeap(), 0, utf8_buffer );
900 HeapFree( GetProcessHeap(), 0, buffer );
902 return TRUE;
906 /***********************************************************************
907 * DestroyWindow (X11DRV.@)
909 BOOL X11DRV_DestroyWindow( HWND hwnd )
911 struct x11drv_thread_data *thread_data = x11drv_thread_data();
912 Display *display = thread_data->display;
913 WND *wndPtr = WIN_GetPtr( hwnd );
914 X11DRV_WND_DATA *data = wndPtr->pDriverData;
916 if (!data) goto done;
918 if (data->whole_window)
920 TRACE( "win %p xwin %lx/%lx\n", hwnd, data->whole_window, data->client_window );
921 if (thread_data->cursor_window == data->whole_window) thread_data->cursor_window = None;
922 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
923 wine_tsx11_lock();
924 XSync( gdi_display, False ); /* flush any reference to this drawable in GDI queue */
925 XDeleteContext( display, data->whole_window, winContext );
926 XDeleteContext( display, data->client_window, winContext );
927 XDestroyWindow( display, data->whole_window ); /* this destroys client too */
928 if (data->xic)
930 XUnsetICFocus( data->xic );
931 XDestroyIC( data->xic );
933 destroy_icon_window( display, wndPtr );
934 wine_tsx11_unlock();
937 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
938 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
939 HeapFree( GetProcessHeap(), 0, data );
940 wndPtr->pDriverData = NULL;
941 done:
942 WIN_ReleasePtr( wndPtr );
943 return TRUE;
947 /**********************************************************************
948 * CreateWindow (X11DRV.@)
950 BOOL X11DRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode )
952 Display *display = thread_display();
953 WND *wndPtr;
954 struct x11drv_win_data *data;
955 RECT rect;
956 CBT_CREATEWNDA cbtc;
957 BOOL ret = FALSE;
959 if (cs->cx > 65535)
961 ERR( "invalid window width %d\n", cs->cx );
962 cs->cx = 65535;
964 if (cs->cy > 65535)
966 ERR( "invalid window height %d\n", cs->cx );
967 cs->cy = 65535;
970 if (!(data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data)))) return FALSE;
971 data->whole_window = 0;
972 data->client_window = 0;
973 data->icon_window = 0;
974 data->xic = 0;
975 data->hWMIconBitmap = 0;
976 data->hWMIconMask = 0;
978 wndPtr = WIN_GetPtr( hwnd );
979 wndPtr->pDriverData = data;
981 /* initialize the dimensions before sending WM_GETMINMAXINFO */
982 SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy );
983 WIN_SetRectangles( hwnd, &rect, &rect );
985 if (!wndPtr->parent)
987 create_desktop( display, wndPtr );
988 WIN_ReleasePtr( wndPtr );
989 return TRUE;
992 if (!create_whole_window( display, wndPtr )) goto failed;
993 if (!create_client_window( display, wndPtr )) goto failed;
994 wine_tsx11_lock();
995 XSync( display, False );
996 wine_tsx11_unlock();
998 SetPropA( hwnd, whole_window_atom, (HANDLE)data->whole_window );
999 SetPropA( hwnd, client_window_atom, (HANDLE)data->client_window );
1001 /* Call the WH_CBT hook */
1002 cbtc.lpcs = cs;
1003 cbtc.hwndInsertAfter = HWND_TOP;
1004 if (HOOK_CallHooks( WH_CBT, HCBT_CREATEWND, (WPARAM)hwnd, (LPARAM)&cbtc, unicode ))
1006 TRACE("CBT-hook returned !0\n");
1007 goto failed;
1010 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
1011 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
1013 POINT maxSize, maxPos, minTrack, maxTrack;
1015 WIN_ReleasePtr( wndPtr );
1016 WINPOS_GetMinMaxInfo( hwnd, &maxSize, &maxPos, &minTrack, &maxTrack);
1017 if (maxSize.x < cs->cx) cs->cx = maxSize.x;
1018 if (maxSize.y < cs->cy) cs->cy = maxSize.y;
1019 if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
1020 if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
1021 if (cs->cx < 0) cs->cx = 0;
1022 if (cs->cy < 0) cs->cy = 0;
1024 if (!(wndPtr = WIN_GetPtr( hwnd ))) return FALSE;
1025 SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy );
1026 WIN_SetRectangles( hwnd, &rect, &rect );
1027 X11DRV_sync_whole_window_position( display, wndPtr, 0 );
1029 WIN_ReleasePtr( wndPtr );
1031 /* send WM_NCCREATE */
1032 TRACE( "hwnd %p cs %d,%d %dx%d\n", hwnd, cs->x, cs->y, cs->cx, cs->cy );
1033 if (unicode)
1034 ret = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
1035 else
1036 ret = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
1037 if (!ret)
1039 WARN("aborted by WM_xxCREATE!\n");
1040 return FALSE;
1043 if (!(wndPtr = WIN_GetPtr(hwnd))) return FALSE;
1045 X11DRV_sync_window_style( display, wndPtr );
1047 /* send WM_NCCALCSIZE */
1048 rect = wndPtr->rectWindow;
1049 WIN_ReleasePtr( wndPtr );
1050 SendMessageW( hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&rect );
1052 if (!(wndPtr = WIN_GetPtr(hwnd))) return FALSE;
1053 if (rect.left > rect.right || rect.top > rect.bottom) rect = wndPtr->rectWindow;
1054 WIN_SetRectangles( hwnd, &wndPtr->rectWindow, &rect );
1055 X11DRV_sync_client_window_position( display, wndPtr );
1056 X11DRV_register_window( display, hwnd, data );
1058 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",
1059 hwnd, wndPtr->rectWindow.left, wndPtr->rectWindow.top,
1060 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom,
1061 wndPtr->rectClient.left, wndPtr->rectClient.top,
1062 wndPtr->rectClient.right, wndPtr->rectClient.bottom,
1063 data->whole_rect.left, data->whole_rect.top,
1064 data->whole_rect.right, data->whole_rect.bottom,
1065 data->client_rect.left, data->client_rect.top,
1066 data->client_rect.right, data->client_rect.bottom,
1067 (unsigned int)data->whole_window, (unsigned int)data->client_window );
1069 if ((wndPtr->dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
1070 WIN_LinkWindow( hwnd, wndPtr->parent, HWND_BOTTOM );
1071 else
1072 WIN_LinkWindow( hwnd, wndPtr->parent, HWND_TOP );
1074 WIN_ReleasePtr( wndPtr );
1076 if (unicode)
1077 ret = (SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
1078 else
1079 ret = (SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
1081 if (!ret)
1083 WIN_UnlinkWindow( hwnd );
1084 return FALSE;
1087 /* Send the size messages */
1089 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return FALSE;
1090 if (!(wndPtr->flags & WIN_NEED_SIZE))
1092 /* send it anyway */
1093 if (((wndPtr->rectClient.right-wndPtr->rectClient.left) <0)
1094 ||((wndPtr->rectClient.bottom-wndPtr->rectClient.top)<0))
1095 WARN("sending bogus WM_SIZE message 0x%08lx\n",
1096 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1097 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1098 SendMessageW( hwnd, WM_SIZE, SIZE_RESTORED,
1099 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1100 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1101 SendMessageW( hwnd, WM_MOVE, 0,
1102 MAKELONG( wndPtr->rectClient.left, wndPtr->rectClient.top ) );
1105 /* Show the window, maximizing or minimizing if needed */
1107 if (wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE))
1109 extern UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect ); /*FIXME*/
1111 RECT newPos;
1112 UINT swFlag = (wndPtr->dwStyle & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE;
1113 WIN_SetStyle( hwnd, wndPtr->dwStyle & ~(WS_MAXIMIZE | WS_MINIMIZE) );
1114 WINPOS_MinMaximize( hwnd, swFlag, &newPos );
1115 swFlag = ((wndPtr->dwStyle & WS_CHILD) || GetActiveWindow())
1116 ? SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED
1117 : SWP_NOZORDER | SWP_FRAMECHANGED;
1118 SetWindowPos( hwnd, 0, newPos.left, newPos.top,
1119 newPos.right, newPos.bottom, swFlag );
1122 /* if the window was made visible set create struct flag so that
1123 * we do a proper ShowWindow later on */
1124 if (wndPtr->dwStyle & WS_VISIBLE) cs->style |= WS_VISIBLE;
1126 WIN_ReleaseWndPtr( wndPtr );
1127 return TRUE;
1130 failed:
1131 X11DRV_DestroyWindow( hwnd );
1132 if (wndPtr) WIN_ReleasePtr( wndPtr );
1133 return FALSE;
1137 /***********************************************************************
1138 * X11DRV_get_client_window
1140 * Return the X window associated with the client area of a window
1142 Window X11DRV_get_client_window( HWND hwnd )
1144 Window ret = 0;
1145 WND *win = WIN_GetPtr( hwnd );
1147 if (win == WND_OTHER_PROCESS)
1148 return (Window)GetPropA( hwnd, client_window_atom );
1150 if (win)
1152 struct x11drv_win_data *data = win->pDriverData;
1153 ret = data->client_window;
1154 WIN_ReleasePtr( win );
1156 return ret;
1160 /***********************************************************************
1161 * X11DRV_get_whole_window
1163 * Return the X window associated with the full area of a window
1165 Window X11DRV_get_whole_window( HWND hwnd )
1167 Window ret = 0;
1168 WND *win = WIN_GetPtr( hwnd );
1170 if (win == WND_OTHER_PROCESS)
1171 return (Window)GetPropA( hwnd, whole_window_atom );
1173 if (win)
1175 struct x11drv_win_data *data = win->pDriverData;
1176 ret = data->whole_window;
1177 WIN_ReleasePtr( win );
1179 return ret;
1183 /***********************************************************************
1184 * X11DRV_get_ic
1186 * Return the X input context associated with a window
1188 XIC X11DRV_get_ic( HWND hwnd )
1190 XIC ret = 0;
1191 WND *win = WIN_GetPtr( hwnd );
1193 if (win && win != WND_OTHER_PROCESS)
1195 struct x11drv_win_data *data = win->pDriverData;
1196 ret = data->xic;
1197 WIN_ReleasePtr( win );
1199 return ret;
1203 /*****************************************************************
1204 * SetParent (X11DRV.@)
1206 HWND X11DRV_SetParent( HWND hwnd, HWND parent )
1208 Display *display = thread_display();
1209 WND *wndPtr;
1210 HWND retvalue;
1212 /* Windows hides the window first, then shows it again
1213 * including the WM_SHOWWINDOW messages and all */
1214 BOOL was_visible = ShowWindow( hwnd, SW_HIDE );
1216 if (!IsWindow( parent )) return 0;
1217 if (!(wndPtr = WIN_GetPtr(hwnd)) || wndPtr == WND_OTHER_PROCESS) return 0;
1219 retvalue = wndPtr->parent; /* old parent */
1220 if (parent != retvalue)
1222 struct x11drv_win_data *data = wndPtr->pDriverData;
1224 WIN_LinkWindow( hwnd, parent, HWND_TOP );
1226 if (parent != GetDesktopWindow()) /* a child window */
1228 if (!(wndPtr->dwStyle & WS_CHILD))
1230 HMENU menu = (HMENU)SetWindowLongW( hwnd, GWL_ID, 0 );
1231 if (menu) DestroyMenu( menu );
1235 if (is_window_top_level( wndPtr )) X11DRV_set_wm_hints( display, wndPtr );
1236 wine_tsx11_lock();
1237 X11DRV_sync_window_style( display, wndPtr );
1238 XReparentWindow( display, data->whole_window, X11DRV_get_client_window(parent),
1239 data->whole_rect.left, data->whole_rect.top );
1240 wine_tsx11_unlock();
1242 WIN_ReleasePtr( wndPtr );
1244 /* SetParent additionally needs to make hwnd the topmost window
1245 in the x-order and send the expected WM_WINDOWPOSCHANGING and
1246 WM_WINDOWPOSCHANGED notification messages.
1248 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0,
1249 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | (was_visible ? SWP_SHOWWINDOW : 0) );
1250 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1251 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
1253 return retvalue;
1257 /*****************************************************************
1258 * SetFocus (X11DRV.@)
1260 * Set the X focus.
1261 * Explicit colormap management seems to work only with OLVWM.
1263 void X11DRV_SetFocus( HWND hwnd )
1265 Display *display = thread_display();
1266 XWindowAttributes win_attr;
1267 Window win;
1269 /* Only mess with the X focus if there's */
1270 /* no desktop window and if the window is not managed by the WM. */
1271 if (root_window != DefaultRootWindow(display)) return;
1273 if (!hwnd) /* If setting the focus to 0, uninstall the colormap */
1275 wine_tsx11_lock();
1276 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1277 XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1278 wine_tsx11_unlock();
1279 return;
1282 hwnd = GetAncestor( hwnd, GA_ROOT );
1283 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MANAGED) return;
1284 if (!(win = X11DRV_get_whole_window( hwnd ))) return;
1286 /* Set X focus and install colormap */
1287 wine_tsx11_lock();
1288 if (XGetWindowAttributes( display, win, &win_attr ) &&
1289 (win_attr.map_state == IsViewable))
1291 /* If window is not viewable, don't change anything */
1293 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1294 /* FIXME: this is not entirely correct */
1295 XSetInputFocus( display, win, RevertToParent,
1296 /*CurrentTime*/ GetMessageTime() + X11DRV_server_startticks );
1297 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1298 XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1300 wine_tsx11_unlock();
1304 /**********************************************************************
1305 * SetWindowIcon (X11DRV.@)
1307 * hIcon or hIconSm has changed (or is being initialised for the
1308 * first time). Complete the X11 driver-specific initialisation
1309 * and set the window hints.
1311 * This is not entirely correct, may need to create
1312 * an icon window and set the pixmap as a background
1314 void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
1316 WND *wndPtr;
1317 Display *display = thread_display();
1319 if (type != ICON_BIG) return; /* nothing to do here */
1321 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return;
1323 if (wndPtr->dwExStyle & WS_EX_MANAGED)
1325 Window win = get_whole_window(wndPtr);
1326 XWMHints* wm_hints;
1328 wine_tsx11_lock();
1329 if (!(wm_hints = XGetWMHints( display, win ))) wm_hints = XAllocWMHints();
1330 wine_tsx11_unlock();
1331 if (wm_hints)
1333 set_icon_hints( display, wndPtr, wm_hints, icon );
1334 wine_tsx11_lock();
1335 XSetWMHints( display, win, wm_hints );
1336 XFree( wm_hints );
1337 wine_tsx11_unlock();
1340 WIN_ReleasePtr( wndPtr );