Fix managed state of some windows.
[wine.git] / dlls / x11drv / window.c
blobe35866b6cb2ef5ea34f8cee58389ee969d1cc220
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 )
286 X11DRV_WND_DATA *data = wndPtr->pDriverData;
287 HICON hIcon = (HICON)GetClassLongA( wndPtr->hwndSelf, GCL_HICON );
289 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
290 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
291 data->hWMIconBitmap = 0;
292 data->hWMIconMask = 0;
294 if (!(wndPtr->dwExStyle & WS_EX_MANAGED))
296 destroy_icon_window( display, wndPtr );
297 hints->flags &= ~(IconPixmapHint | IconMaskHint | IconWindowHint);
299 else if (!hIcon)
301 if (!data->icon_window) create_icon_window( display, wndPtr );
302 hints->icon_window = data->icon_window;
303 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
305 else
307 HBITMAP hbmOrig;
308 RECT rcMask;
309 BITMAP bmMask;
310 ICONINFO ii;
311 HDC hDC;
313 GetIconInfo(hIcon, &ii);
315 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
316 rcMask.top = 0;
317 rcMask.left = 0;
318 rcMask.right = bmMask.bmWidth;
319 rcMask.bottom = bmMask.bmHeight;
321 hDC = CreateCompatibleDC(0);
322 hbmOrig = SelectObject(hDC, ii.hbmMask);
323 InvertRect(hDC, &rcMask);
324 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
325 SelectObject(hDC, hbmOrig);
326 DeleteDC(hDC);
328 data->hWMIconBitmap = ii.hbmColor;
329 data->hWMIconMask = ii.hbmMask;
331 hints->icon_pixmap = X11DRV_BITMAP_Pixmap(data->hWMIconBitmap);
332 hints->icon_mask = X11DRV_BITMAP_Pixmap(data->hWMIconMask);
333 destroy_icon_window( display, wndPtr );
334 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
339 /***********************************************************************
340 * set_size_hints
342 * set the window size hints
344 static void set_size_hints( Display *display, WND *win )
346 XSizeHints* size_hints;
347 struct x11drv_win_data *data = win->pDriverData;
349 if ((size_hints = XAllocSizeHints()))
351 size_hints->win_gravity = StaticGravity;
352 size_hints->x = data->whole_rect.left;
353 size_hints->y = data->whole_rect.top;
354 size_hints->flags = PWinGravity | PPosition;
356 if (HAS_DLGFRAME( win->dwStyle, win->dwExStyle ))
358 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
359 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
360 size_hints->min_width = size_hints->max_width;
361 size_hints->min_height = size_hints->max_height;
362 size_hints->flags |= PMinSize | PMaxSize;
364 XSetWMNormalHints( display, data->whole_window, size_hints );
365 XFree( size_hints );
370 /***********************************************************************
371 * X11DRV_set_wm_hints
373 * Set the window manager hints for a newly-created window
375 void X11DRV_set_wm_hints( Display *display, WND *win )
377 struct x11drv_win_data *data = win->pDriverData;
378 Window group_leader;
379 XClassHint *class_hints;
380 XWMHints* wm_hints;
381 Atom protocols[3];
382 MwmHints mwm_hints;
383 Atom dndVersion = 4;
384 int i;
386 wine_tsx11_lock();
388 /* wm protocols */
389 i = 0;
390 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
391 protocols[i++] = x11drv_atom(_NET_WM_PING);
392 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
393 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
394 XA_ATOM, 32, PropModeReplace, (char *)protocols, i );
396 /* class hints */
397 if ((class_hints = XAllocClassHint()))
399 class_hints->res_name = "wine";
400 class_hints->res_class = "Wine";
401 XSetClassHint( display, data->whole_window, class_hints );
402 XFree( class_hints );
405 /* transient for hint */
406 if (win->owner)
408 Window owner_win = X11DRV_get_whole_window( win->owner );
409 XSetTransientForHint( display, data->whole_window, owner_win );
410 group_leader = owner_win;
412 else group_leader = data->whole_window;
414 /* size hints */
415 set_size_hints( display, win );
417 /* systray properties (KDE only for now) */
418 if (win->dwExStyle & WS_EX_TRAYWINDOW)
420 int val = 1;
421 XChangeProperty( display, data->whole_window, x11drv_atom(KWM_DOCKWINDOW),
422 x11drv_atom(KWM_DOCKWINDOW), 32, PropModeReplace, (char*)&val, 1 );
423 XChangeProperty( display, data->whole_window, x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR),
424 XA_WINDOW, 32, PropModeReplace, (char*)&data->whole_window, 1 );
427 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
428 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
429 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
430 i = getpid();
431 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
432 XA_CARDINAL, 32, PropModeReplace, (char *)&i, 1);
434 /* map WS_EX_TOOLWINDOW to _NET_WM_WINDOW_TYPE_UTILITY */
435 if (win->dwExStyle & WS_EX_TOOLWINDOW)
437 Atom a = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
438 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
439 XA_ATOM, 32, PropModeReplace, (char*)&a, 1);
442 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
443 mwm_hints.functions = 0;
444 if ((win->dwStyle & WS_CAPTION) == WS_CAPTION) mwm_hints.functions |= MWM_FUNC_MOVE;
445 if (win->dwStyle & WS_THICKFRAME) mwm_hints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
446 if (win->dwStyle & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
447 if (win->dwStyle & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
448 if (win->dwStyle & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
449 mwm_hints.decorations = 0;
450 if ((win->dwStyle & WS_CAPTION) == WS_CAPTION) mwm_hints.decorations |= MWM_DECOR_TITLE;
451 if (win->dwExStyle & WS_EX_DLGMODALFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER;
452 else if (win->dwStyle & WS_THICKFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
453 else if ((win->dwStyle & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER;
454 else if (win->dwStyle & WS_BORDER) mwm_hints.decorations |= MWM_DECOR_BORDER;
455 else if (!(win->dwStyle & (WS_CHILD|WS_POPUP))) mwm_hints.decorations |= MWM_DECOR_BORDER;
456 if (win->dwStyle & WS_SYSMENU) mwm_hints.decorations |= MWM_DECOR_MENU;
457 if (win->dwStyle & WS_MINIMIZEBOX) mwm_hints.decorations |= MWM_DECOR_MINIMIZE;
458 if (win->dwStyle & WS_MAXIMIZEBOX) mwm_hints.decorations |= MWM_DECOR_MAXIMIZE;
460 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
461 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
462 (char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
464 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
465 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
467 wm_hints = XAllocWMHints();
468 wine_tsx11_unlock();
470 /* wm hints */
471 if (wm_hints)
473 wm_hints->flags = InputHint | StateHint | WindowGroupHint;
474 wm_hints->input = !(win->dwStyle & WS_DISABLED);
476 set_icon_hints( display, win, wm_hints );
478 wm_hints->initial_state = (win->dwStyle & WS_MINIMIZE) ? IconicState : NormalState;
479 wm_hints->window_group = group_leader;
481 wine_tsx11_lock();
482 XSetWMHints( display, data->whole_window, wm_hints );
483 XFree(wm_hints);
484 wine_tsx11_unlock();
489 /***********************************************************************
490 * X11DRV_set_iconic_state
492 * Set the X11 iconic state according to the window style.
494 void X11DRV_set_iconic_state( WND *win )
496 Display *display = thread_display();
497 struct x11drv_win_data *data = win->pDriverData;
498 XWMHints* wm_hints;
499 BOOL iconic = IsIconic( win->hwndSelf );
501 wine_tsx11_lock();
503 if (iconic) XUnmapWindow( display, data->client_window );
504 else if (is_client_window_mapped( win )) XMapWindow( display, data->client_window );
506 if (!(wm_hints = XGetWMHints( display, data->whole_window ))) wm_hints = XAllocWMHints();
507 wm_hints->flags |= StateHint | IconPositionHint;
508 wm_hints->initial_state = iconic ? IconicState : NormalState;
509 wm_hints->icon_x = win->rectWindow.left;
510 wm_hints->icon_y = win->rectWindow.top;
511 XSetWMHints( display, data->whole_window, wm_hints );
513 if (win->dwStyle & WS_VISIBLE)
515 if (iconic)
516 XIconifyWindow( display, data->whole_window, DefaultScreen(display) );
517 else
518 if (!IsRectEmpty( &win->rectWindow )) XMapWindow( display, data->whole_window );
521 XFree(wm_hints);
522 wine_tsx11_unlock();
526 /***********************************************************************
527 * X11DRV_window_to_X_rect
529 * Convert a rect from client to X window coordinates
531 void X11DRV_window_to_X_rect( WND *win, RECT *rect )
533 RECT rc;
535 if (!(win->dwExStyle & WS_EX_MANAGED)) return;
536 if (IsRectEmpty( rect )) return;
538 rc.top = rc.bottom = rc.left = rc.right = 0;
540 AdjustWindowRectEx( &rc, win->dwStyle & ~(WS_HSCROLL|WS_VSCROLL), FALSE, win->dwExStyle );
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;
551 /***********************************************************************
552 * X11DRV_X_to_window_rect
554 * Opposite of X11DRV_window_to_X_rect
556 void X11DRV_X_to_window_rect( WND *win, RECT *rect )
558 if (!(win->dwExStyle & WS_EX_MANAGED)) return;
559 if (IsRectEmpty( rect )) return;
561 AdjustWindowRectEx( rect, win->dwStyle & ~(WS_HSCROLL|WS_VSCROLL), FALSE, win->dwExStyle );
563 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
564 if (rect->left >= rect->right) rect->right = rect->left + 1;
568 /***********************************************************************
569 * X11DRV_sync_whole_window_position
571 * Synchronize the X whole window position with the Windows one
573 int X11DRV_sync_whole_window_position( Display *display, WND *win, int zorder )
575 XWindowChanges changes;
576 int mask;
577 struct x11drv_win_data *data = win->pDriverData;
578 RECT whole_rect = win->rectWindow;
580 X11DRV_window_to_X_rect( win, &whole_rect );
581 mask = get_window_changes( &changes, &data->whole_rect, &whole_rect );
583 if (zorder)
585 if (is_window_top_level( win ))
587 /* find window that this one must be after */
588 HWND prev = GetWindow( win->hwndSelf, GW_HWNDPREV );
589 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
590 prev = GetWindow( prev, GW_HWNDPREV );
591 if (!prev) /* top child */
593 changes.stack_mode = Above;
594 mask |= CWStackMode;
596 else
598 /* should use stack_mode Below but most window managers don't get it right */
599 /* so move it above the next one in Z order */
600 HWND next = GetWindow( win->hwndSelf, GW_HWNDNEXT );
601 while (next && !(GetWindowLongW( next, GWL_STYLE ) & WS_VISIBLE))
602 next = GetWindow( next, GW_HWNDNEXT );
603 if (next)
605 changes.stack_mode = Above;
606 changes.sibling = X11DRV_get_whole_window(next);
607 mask |= CWStackMode | CWSibling;
611 else
613 HWND next = GetWindow( win->hwndSelf, GW_HWNDNEXT );
615 if (win->parent == GetDesktopWindow() &&
616 root_window != DefaultRootWindow(display))
618 /* in desktop mode we need the sibling to belong to the same process */
619 while (next)
621 WND *ptr = WIN_GetPtr( next );
622 if (ptr != WND_OTHER_PROCESS)
624 WIN_ReleasePtr( ptr );
625 break;
627 next = GetWindow( next, GW_HWNDNEXT );
631 if (!next) /* bottom child */
633 changes.stack_mode = Below;
634 mask |= CWStackMode;
636 else
638 changes.stack_mode = Above;
639 changes.sibling = X11DRV_get_whole_window(next);
640 mask |= CWStackMode | CWSibling;
645 data->whole_rect = whole_rect;
647 if (mask)
649 TRACE( "setting win %lx pos %ld,%ld,%ldx%ld after %lx changes=%x\n",
650 data->whole_window, whole_rect.left, whole_rect.top,
651 whole_rect.right - whole_rect.left, whole_rect.bottom - whole_rect.top,
652 changes.sibling, mask );
653 wine_tsx11_lock();
654 XSync( gdi_display, False ); /* flush graphics operations before moving the window */
655 if (is_window_top_level( win ))
657 if (mask & (CWWidth|CWHeight)) set_size_hints( display, win );
658 XReconfigureWMWindow( display, data->whole_window,
659 DefaultScreen(display), mask, &changes );
661 else XConfigureWindow( display, data->whole_window, mask, &changes );
662 wine_tsx11_unlock();
664 return mask;
668 /***********************************************************************
669 * X11DRV_sync_client_window_position
671 * Synchronize the X client window position with the Windows one
673 int X11DRV_sync_client_window_position( Display *display, WND *win )
675 XWindowChanges changes;
676 int mask;
677 struct x11drv_win_data *data = win->pDriverData;
678 RECT client_rect = win->rectClient;
680 OffsetRect( &client_rect, -data->whole_rect.left, -data->whole_rect.top );
682 if ((mask = get_window_changes( &changes, &data->client_rect, &client_rect )))
684 BOOL was_mapped = is_client_window_mapped( win );
686 TRACE( "setting win %lx pos %ld,%ld,%ldx%ld (was %ld,%ld,%ldx%ld) after %lx changes=%x\n",
687 data->client_window, client_rect.left, client_rect.top,
688 client_rect.right - client_rect.left, client_rect.bottom - client_rect.top,
689 data->client_rect.left, data->client_rect.top,
690 data->client_rect.right - data->client_rect.left,
691 data->client_rect.bottom - data->client_rect.top,
692 changes.sibling, mask );
693 data->client_rect = client_rect;
694 wine_tsx11_lock();
695 XSync( gdi_display, False ); /* flush graphics operations before moving the window */
696 if (was_mapped && !is_client_window_mapped( win ))
697 XUnmapWindow( display, data->client_window );
698 XConfigureWindow( display, data->client_window, mask, &changes );
699 if (!was_mapped && is_client_window_mapped( win ))
700 XMapWindow( display, data->client_window );
701 wine_tsx11_unlock();
703 return mask;
707 /***********************************************************************
708 * X11DRV_register_window
710 * Associate an X window to a HWND.
712 void X11DRV_register_window( Display *display, HWND hwnd, struct x11drv_win_data *data )
714 wine_tsx11_lock();
715 XSaveContext( display, data->whole_window, winContext, (char *)hwnd );
716 XSaveContext( display, data->client_window, winContext, (char *)hwnd );
717 wine_tsx11_unlock();
721 /**********************************************************************
722 * create_desktop
724 static void create_desktop( Display *display, WND *wndPtr )
726 X11DRV_WND_DATA *data = wndPtr->pDriverData;
728 wine_tsx11_lock();
729 winContext = XUniqueContext();
730 XInternAtoms( display, (char **)atom_names, NB_XATOMS - FIRST_XATOM, False, X11DRV_Atoms );
731 wine_tsx11_unlock();
733 whole_window_atom = MAKEINTATOMA( GlobalAddAtomA( "__wine_x11_whole_window" ));
734 client_window_atom = MAKEINTATOMA( GlobalAddAtomA( "__wine_x11_client_window" ));
735 icon_window_atom = MAKEINTATOMA( GlobalAddAtomA( "__wine_x11_icon_window" ));
737 data->whole_window = data->client_window = root_window;
738 data->whole_rect = data->client_rect = wndPtr->rectWindow;
740 SetPropA( wndPtr->hwndSelf, whole_window_atom, (HANDLE)root_window );
741 SetPropA( wndPtr->hwndSelf, client_window_atom, (HANDLE)root_window );
742 SetPropA( wndPtr->hwndSelf, "__wine_x11_visual_id", (HANDLE)XVisualIDFromVisual(visual) );
744 X11DRV_InitClipboard();
746 if (root_window != DefaultRootWindow(display)) X11DRV_create_desktop_thread();
750 /**********************************************************************
751 * create_whole_window
753 * Create the whole X window for a given window
755 static Window create_whole_window( Display *display, WND *win )
757 struct x11drv_win_data *data = win->pDriverData;
758 int cx, cy, mask;
759 XSetWindowAttributes attr;
760 Window parent;
761 RECT rect;
762 BOOL is_top_level = is_window_top_level( win );
764 rect = win->rectWindow;
765 X11DRV_window_to_X_rect( win, &rect );
767 if (!(cx = rect.right - rect.left)) cx = 1;
768 if (!(cy = rect.bottom - rect.top)) cy = 1;
770 parent = X11DRV_get_client_window( win->parent );
772 wine_tsx11_lock();
774 mask = get_window_attributes( display, win, &attr );
776 /* set the attributes that don't change over the lifetime of the window */
777 attr.bit_gravity = ForgetGravity;
778 attr.win_gravity = NorthWestGravity;
779 attr.backing_store = NotUseful/*WhenMapped*/;
780 mask |= CWBitGravity | CWWinGravity | CWBackingStore;
782 data->whole_rect = rect;
783 data->whole_window = XCreateWindow( display, parent, rect.left, rect.top, cx, cy,
784 0, screen_depth, InputOutput, visual,
785 mask, &attr );
787 if (!data->whole_window)
789 wine_tsx11_unlock();
790 return 0;
793 if (is_top_level)
795 XIM xim = x11drv_thread_data()->xim;
796 if (xim) data->xic = XCreateIC( xim,
797 XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
798 XNClientWindow, data->whole_window,
799 XNFocusWindow, data->whole_window,
800 0 );
803 /* non-maximized child must be at bottom of Z order */
804 if ((win->dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
806 XWindowChanges changes;
807 changes.stack_mode = Below;
808 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
811 wine_tsx11_unlock();
813 if (is_top_level) X11DRV_set_wm_hints( display, win );
815 return data->whole_window;
819 /**********************************************************************
820 * create_client_window
822 * Create the client window for a given window
824 static Window create_client_window( Display *display, WND *win )
826 struct x11drv_win_data *data = win->pDriverData;
827 RECT rect = data->whole_rect;
828 XSetWindowAttributes attr;
830 OffsetRect( &rect, -data->whole_rect.left, -data->whole_rect.top );
831 data->client_rect = rect;
833 attr.event_mask = (ExposureMask | PointerMotionMask |
834 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
835 attr.bit_gravity = (win->clsStyle & (CS_VREDRAW | CS_HREDRAW)) ?
836 ForgetGravity : NorthWestGravity;
837 attr.backing_store = NotUseful/*WhenMapped*/;
839 wine_tsx11_lock();
840 data->client_window = XCreateWindow( display, data->whole_window, 0, 0,
841 max( rect.right - rect.left, 1 ),
842 max( rect.bottom - rect.top, 1 ),
843 0, screen_depth,
844 InputOutput, visual,
845 CWEventMask | CWBitGravity | CWBackingStore, &attr );
846 if (data->client_window && is_client_window_mapped( win ))
847 XMapWindow( display, data->client_window );
848 wine_tsx11_unlock();
849 return data->client_window;
853 /*****************************************************************
854 * SetWindowText (X11DRV.@)
856 BOOL X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
858 Display *display = thread_display();
859 UINT count;
860 char *buffer;
861 char *utf8_buffer;
862 Window win;
863 XTextProperty prop;
865 if ((win = X11DRV_get_whole_window( hwnd )))
867 /* allocate new buffer for window text */
868 count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
869 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count )))
871 ERR("Not enough memory for window text\n");
872 return FALSE;
874 WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
876 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
877 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
879 ERR("Not enough memory for window text in UTF-8\n");
880 return FALSE;
882 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
884 wine_tsx11_lock();
885 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
887 XSetWMName( display, win, &prop );
888 XSetWMIconName( display, win, &prop );
889 XFree( prop.value );
892 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
893 according to the standard
894 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
896 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
897 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
898 wine_tsx11_unlock();
900 HeapFree( GetProcessHeap(), 0, utf8_buffer );
901 HeapFree( GetProcessHeap(), 0, buffer );
903 return TRUE;
907 /***********************************************************************
908 * DestroyWindow (X11DRV.@)
910 BOOL X11DRV_DestroyWindow( HWND hwnd )
912 struct x11drv_thread_data *thread_data = x11drv_thread_data();
913 Display *display = thread_data->display;
914 WND *wndPtr = WIN_GetPtr( hwnd );
915 X11DRV_WND_DATA *data = wndPtr->pDriverData;
917 if (!data) goto done;
919 if (data->whole_window)
921 TRACE( "win %p xwin %lx/%lx\n", hwnd, data->whole_window, data->client_window );
922 if (thread_data->cursor_window == data->whole_window) thread_data->cursor_window = None;
923 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
924 wine_tsx11_lock();
925 XSync( gdi_display, False ); /* flush any reference to this drawable in GDI queue */
926 XDeleteContext( display, data->whole_window, winContext );
927 XDeleteContext( display, data->client_window, winContext );
928 XDestroyWindow( display, data->whole_window ); /* this destroys client too */
929 if (data->xic)
931 XUnsetICFocus( data->xic );
932 XDestroyIC( data->xic );
934 destroy_icon_window( display, wndPtr );
935 wine_tsx11_unlock();
938 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
939 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
940 HeapFree( GetProcessHeap(), 0, data );
941 wndPtr->pDriverData = NULL;
942 done:
943 WIN_ReleasePtr( wndPtr );
944 return TRUE;
948 /**********************************************************************
949 * CreateWindow (X11DRV.@)
951 BOOL X11DRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode )
953 Display *display = thread_display();
954 WND *wndPtr;
955 struct x11drv_win_data *data;
956 RECT rect;
957 CBT_CREATEWNDA cbtc;
958 BOOL ret = FALSE;
960 if (cs->cx > 65535)
962 ERR( "invalid window width %d\n", cs->cx );
963 cs->cx = 65535;
965 if (cs->cy > 65535)
967 ERR( "invalid window height %d\n", cs->cx );
968 cs->cy = 65535;
971 if (!(data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data)))) return FALSE;
972 data->whole_window = 0;
973 data->client_window = 0;
974 data->icon_window = 0;
975 data->xic = 0;
976 data->hWMIconBitmap = 0;
977 data->hWMIconMask = 0;
979 wndPtr = WIN_GetPtr( hwnd );
980 wndPtr->pDriverData = data;
982 /* initialize the dimensions before sending WM_GETMINMAXINFO */
983 SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy );
984 WIN_SetRectangles( hwnd, &rect, &rect );
986 if (!wndPtr->parent)
988 create_desktop( display, wndPtr );
989 WIN_ReleasePtr( wndPtr );
990 return TRUE;
993 if (!create_whole_window( display, wndPtr )) goto failed;
994 if (!create_client_window( display, wndPtr )) goto failed;
995 wine_tsx11_lock();
996 XSync( display, False );
997 wine_tsx11_unlock();
999 SetPropA( hwnd, whole_window_atom, (HANDLE)data->whole_window );
1000 SetPropA( hwnd, client_window_atom, (HANDLE)data->client_window );
1002 /* Call the WH_CBT hook */
1003 cbtc.lpcs = cs;
1004 cbtc.hwndInsertAfter = HWND_TOP;
1005 if (HOOK_CallHooks( WH_CBT, HCBT_CREATEWND, (WPARAM)hwnd, (LPARAM)&cbtc, unicode ))
1007 TRACE("CBT-hook returned !0\n");
1008 goto failed;
1011 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
1012 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
1014 POINT maxSize, maxPos, minTrack, maxTrack;
1016 WIN_ReleasePtr( wndPtr );
1017 WINPOS_GetMinMaxInfo( hwnd, &maxSize, &maxPos, &minTrack, &maxTrack);
1018 if (maxSize.x < cs->cx) cs->cx = maxSize.x;
1019 if (maxSize.y < cs->cy) cs->cy = maxSize.y;
1020 if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
1021 if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
1022 if (cs->cx < 0) cs->cx = 0;
1023 if (cs->cy < 0) cs->cy = 0;
1025 if (!(wndPtr = WIN_GetPtr( hwnd ))) return FALSE;
1026 SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy );
1027 WIN_SetRectangles( hwnd, &rect, &rect );
1028 X11DRV_sync_whole_window_position( display, wndPtr, 0 );
1030 WIN_ReleasePtr( wndPtr );
1032 /* send WM_NCCREATE */
1033 TRACE( "hwnd %p cs %d,%d %dx%d\n", hwnd, cs->x, cs->y, cs->cx, cs->cy );
1034 if (unicode)
1035 ret = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
1036 else
1037 ret = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
1038 if (!ret)
1040 WARN("aborted by WM_xxCREATE!\n");
1041 return FALSE;
1044 if (!(wndPtr = WIN_GetPtr(hwnd))) return FALSE;
1046 X11DRV_sync_window_style( display, wndPtr );
1048 /* send WM_NCCALCSIZE */
1049 rect = wndPtr->rectWindow;
1050 WIN_ReleasePtr( wndPtr );
1051 SendMessageW( hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&rect );
1053 if (!(wndPtr = WIN_GetPtr(hwnd))) return FALSE;
1054 if (rect.left > rect.right || rect.top > rect.bottom) rect = wndPtr->rectWindow;
1055 WIN_SetRectangles( hwnd, &wndPtr->rectWindow, &rect );
1056 X11DRV_sync_client_window_position( display, wndPtr );
1057 X11DRV_register_window( display, hwnd, data );
1059 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",
1060 hwnd, wndPtr->rectWindow.left, wndPtr->rectWindow.top,
1061 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom,
1062 wndPtr->rectClient.left, wndPtr->rectClient.top,
1063 wndPtr->rectClient.right, wndPtr->rectClient.bottom,
1064 data->whole_rect.left, data->whole_rect.top,
1065 data->whole_rect.right, data->whole_rect.bottom,
1066 data->client_rect.left, data->client_rect.top,
1067 data->client_rect.right, data->client_rect.bottom,
1068 (unsigned int)data->whole_window, (unsigned int)data->client_window );
1070 if ((wndPtr->dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
1071 WIN_LinkWindow( hwnd, wndPtr->parent, HWND_BOTTOM );
1072 else
1073 WIN_LinkWindow( hwnd, wndPtr->parent, HWND_TOP );
1075 WIN_ReleasePtr( wndPtr );
1077 if (unicode)
1078 ret = (SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
1079 else
1080 ret = (SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
1082 if (!ret)
1084 WIN_UnlinkWindow( hwnd );
1085 return FALSE;
1088 /* Send the size messages */
1090 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return FALSE;
1091 if (!(wndPtr->flags & WIN_NEED_SIZE))
1093 /* send it anyway */
1094 if (((wndPtr->rectClient.right-wndPtr->rectClient.left) <0)
1095 ||((wndPtr->rectClient.bottom-wndPtr->rectClient.top)<0))
1096 WARN("sending bogus WM_SIZE message 0x%08lx\n",
1097 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1098 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1099 SendMessageW( hwnd, WM_SIZE, SIZE_RESTORED,
1100 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1101 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1102 SendMessageW( hwnd, WM_MOVE, 0,
1103 MAKELONG( wndPtr->rectClient.left, wndPtr->rectClient.top ) );
1106 /* Show the window, maximizing or minimizing if needed */
1108 if (wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE))
1110 extern UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect ); /*FIXME*/
1112 RECT newPos;
1113 UINT swFlag = (wndPtr->dwStyle & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE;
1114 WIN_SetStyle( hwnd, wndPtr->dwStyle & ~(WS_MAXIMIZE | WS_MINIMIZE) );
1115 WINPOS_MinMaximize( hwnd, swFlag, &newPos );
1116 swFlag = ((wndPtr->dwStyle & WS_CHILD) || GetActiveWindow())
1117 ? SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED
1118 : SWP_NOZORDER | SWP_FRAMECHANGED;
1119 SetWindowPos( hwnd, 0, newPos.left, newPos.top,
1120 newPos.right, newPos.bottom, swFlag );
1123 /* if the window was made visible set create struct flag so that
1124 * we do a proper ShowWindow later on */
1125 if (wndPtr->dwStyle & WS_VISIBLE) cs->style |= WS_VISIBLE;
1127 WIN_ReleaseWndPtr( wndPtr );
1128 return TRUE;
1131 failed:
1132 X11DRV_DestroyWindow( hwnd );
1133 if (wndPtr) WIN_ReleasePtr( wndPtr );
1134 return FALSE;
1138 /***********************************************************************
1139 * X11DRV_get_client_window
1141 * Return the X window associated with the client area of a window
1143 Window X11DRV_get_client_window( HWND hwnd )
1145 Window ret = 0;
1146 WND *win = WIN_GetPtr( hwnd );
1148 if (win == WND_OTHER_PROCESS)
1149 return (Window)GetPropA( hwnd, client_window_atom );
1151 if (win)
1153 struct x11drv_win_data *data = win->pDriverData;
1154 ret = data->client_window;
1155 WIN_ReleasePtr( win );
1157 return ret;
1161 /***********************************************************************
1162 * X11DRV_get_whole_window
1164 * Return the X window associated with the full area of a window
1166 Window X11DRV_get_whole_window( HWND hwnd )
1168 Window ret = 0;
1169 WND *win = WIN_GetPtr( hwnd );
1171 if (win == WND_OTHER_PROCESS)
1172 return (Window)GetPropA( hwnd, whole_window_atom );
1174 if (win)
1176 struct x11drv_win_data *data = win->pDriverData;
1177 ret = data->whole_window;
1178 WIN_ReleasePtr( win );
1180 return ret;
1184 /***********************************************************************
1185 * X11DRV_get_ic
1187 * Return the X input context associated with a window
1189 XIC X11DRV_get_ic( HWND hwnd )
1191 XIC ret = 0;
1192 WND *win = WIN_GetPtr( hwnd );
1194 if (win && win != WND_OTHER_PROCESS)
1196 struct x11drv_win_data *data = win->pDriverData;
1197 ret = data->xic;
1198 WIN_ReleasePtr( win );
1200 return ret;
1204 /*****************************************************************
1205 * SetParent (X11DRV.@)
1207 HWND X11DRV_SetParent( HWND hwnd, HWND parent )
1209 Display *display = thread_display();
1210 WND *wndPtr;
1211 HWND retvalue;
1213 /* Windows hides the window first, then shows it again
1214 * including the WM_SHOWWINDOW messages and all */
1215 BOOL was_visible = ShowWindow( hwnd, SW_HIDE );
1217 if (!IsWindow( parent )) return 0;
1218 if (!(wndPtr = WIN_GetPtr(hwnd)) || wndPtr == WND_OTHER_PROCESS) return 0;
1220 retvalue = wndPtr->parent; /* old parent */
1221 if (parent != retvalue)
1223 struct x11drv_win_data *data = wndPtr->pDriverData;
1225 WIN_LinkWindow( hwnd, parent, HWND_TOP );
1227 if (parent != GetDesktopWindow()) /* a child window */
1229 if (!(wndPtr->dwStyle & WS_CHILD))
1231 HMENU menu = (HMENU)SetWindowLongW( hwnd, GWL_ID, 0 );
1232 if (menu) DestroyMenu( menu );
1236 if (is_window_top_level( wndPtr )) X11DRV_set_wm_hints( display, wndPtr );
1237 wine_tsx11_lock();
1238 X11DRV_sync_window_style( display, wndPtr );
1239 XReparentWindow( display, data->whole_window, X11DRV_get_client_window(parent),
1240 data->whole_rect.left, data->whole_rect.top );
1241 wine_tsx11_unlock();
1243 WIN_ReleasePtr( wndPtr );
1245 /* SetParent additionally needs to make hwnd the topmost window
1246 in the x-order and send the expected WM_WINDOWPOSCHANGING and
1247 WM_WINDOWPOSCHANGED notification messages.
1249 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0,
1250 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | (was_visible ? SWP_SHOWWINDOW : 0) );
1251 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1252 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
1254 return retvalue;
1258 /*****************************************************************
1259 * SetFocus (X11DRV.@)
1261 * Set the X focus.
1262 * Explicit colormap management seems to work only with OLVWM.
1264 void X11DRV_SetFocus( HWND hwnd )
1266 Display *display = thread_display();
1267 XWindowAttributes win_attr;
1268 Window win;
1270 /* Only mess with the X focus if there's */
1271 /* no desktop window and if the window is not managed by the WM. */
1272 if (root_window != DefaultRootWindow(display)) return;
1274 if (!hwnd) /* If setting the focus to 0, uninstall the colormap */
1276 wine_tsx11_lock();
1277 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1278 XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1279 wine_tsx11_unlock();
1280 return;
1283 hwnd = GetAncestor( hwnd, GA_ROOT );
1284 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MANAGED) return;
1285 if (!(win = X11DRV_get_whole_window( hwnd ))) return;
1287 /* Set X focus and install colormap */
1288 wine_tsx11_lock();
1289 if (XGetWindowAttributes( display, win, &win_attr ) &&
1290 (win_attr.map_state == IsViewable))
1292 /* If window is not viewable, don't change anything */
1294 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1295 /* FIXME: this is not entirely correct */
1296 XSetInputFocus( display, win, RevertToParent,
1297 /*CurrentTime*/ GetMessageTime() + X11DRV_server_startticks );
1298 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1299 XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1301 wine_tsx11_unlock();
1305 /**********************************************************************
1306 * SetWindowIcon (X11DRV.@)
1308 * hIcon or hIconSm has changed (or is being initialised for the
1309 * first time). Complete the X11 driver-specific initialisation
1310 * and set the window hints.
1312 * This is not entirely correct, may need to create
1313 * an icon window and set the pixmap as a background
1315 HICON X11DRV_SetWindowIcon( HWND hwnd, HICON icon, BOOL small )
1317 WND *wndPtr;
1318 Display *display = thread_display();
1319 HICON old = (HICON)SetClassLongW(hwnd, small ? GCL_HICONSM : GCL_HICON, (LONG)icon );
1321 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE |
1322 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1324 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return old;
1326 if (wndPtr->dwExStyle & WS_EX_MANAGED)
1328 Window win = get_whole_window(wndPtr);
1329 XWMHints* wm_hints;
1331 wine_tsx11_lock();
1332 if (!(wm_hints = XGetWMHints( display, win ))) wm_hints = XAllocWMHints();
1333 wine_tsx11_unlock();
1334 if (wm_hints)
1336 set_icon_hints( display, wndPtr, wm_hints );
1337 wine_tsx11_lock();
1338 XSetWMHints( display, win, wm_hints );
1339 XFree( wm_hints );
1340 wine_tsx11_unlock();
1343 WIN_ReleasePtr( wndPtr );
1344 return old;