Make full-screen popup windows managed.
[wine/hacks.git] / dlls / x11drv / window.c
blob133a48cd0ab385a7841ef6c742c51653415b310a
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 /* full-screen popup windows are managed */
133 if ((win->dwStyle & WS_POPUP) &&
134 (win->rectWindow.right-win->rectWindow.left) == screen_width &&
135 (win->rectWindow.bottom-win->rectWindow.top) == screen_height)
137 return TRUE;
139 /* default: not managed */
140 return FALSE;
144 /***********************************************************************
145 * is_client_window_mapped
147 * Check if the X client window should be mapped
149 inline static BOOL is_client_window_mapped( WND *win )
151 struct x11drv_win_data *data = win->pDriverData;
152 return !(win->dwStyle & WS_MINIMIZE) && !IsRectEmpty( &data->client_rect );
156 /***********************************************************************
157 * get_window_attributes
159 * Fill the window attributes structure for an X window.
161 static int get_window_attributes( Display *display, WND *win, XSetWindowAttributes *attr )
163 BOOL is_top_level = is_window_top_level( win );
164 BOOL managed = is_top_level && is_window_managed( win );
166 if (managed) WIN_SetExStyle( win->hwndSelf, win->dwExStyle | WS_EX_MANAGED );
167 else WIN_SetExStyle( win->hwndSelf, win->dwExStyle & ~WS_EX_MANAGED );
169 attr->override_redirect = !managed;
170 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
171 attr->save_under = ((win->clsStyle & CS_SAVEBITS) != 0);
172 attr->cursor = x11drv_thread_data()->cursor;
173 attr->event_mask = (ExposureMask | PointerMotionMask |
174 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
176 if (is_window_top_level( win ))
177 attr->event_mask |= (KeyPressMask | KeyReleaseMask | StructureNotifyMask |
178 FocusChangeMask | KeymapStateMask);
180 return (CWOverrideRedirect | CWSaveUnder | CWEventMask | CWColormap | CWCursor);
184 /***********************************************************************
185 * X11DRV_sync_window_style
187 * Change the X window attributes when the window style has changed.
189 void X11DRV_sync_window_style( Display *display, WND *win )
191 XSetWindowAttributes attr;
192 int mask;
194 wine_tsx11_lock();
195 mask = get_window_attributes( display, win, &attr );
196 XChangeWindowAttributes( display, get_whole_window(win), mask, &attr );
197 wine_tsx11_unlock();
201 /***********************************************************************
202 * get_window_changes
204 * fill the window changes structure
206 static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
208 int mask = 0;
210 if (old->right - old->left != new->right - new->left )
212 if (!(changes->width = new->right - new->left)) changes->width = 1;
213 mask |= CWWidth;
215 if (old->bottom - old->top != new->bottom - new->top)
217 if (!(changes->height = new->bottom - new->top)) changes->height = 1;
218 mask |= CWHeight;
220 if (old->left != new->left)
222 changes->x = new->left;
223 mask |= CWX;
225 if (old->top != new->top)
227 changes->y = new->top;
228 mask |= CWY;
230 return mask;
234 /***********************************************************************
235 * create_icon_window
237 static Window create_icon_window( Display *display, WND *win )
239 struct x11drv_win_data *data = win->pDriverData;
240 XSetWindowAttributes attr;
242 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
243 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
244 attr.bit_gravity = NorthWestGravity;
245 attr.backing_store = NotUseful/*WhenMapped*/;
246 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
248 wine_tsx11_lock();
249 data->icon_window = XCreateWindow( display, root_window, 0, 0,
250 GetSystemMetrics( SM_CXICON ),
251 GetSystemMetrics( SM_CYICON ),
252 0, screen_depth,
253 InputOutput, visual,
254 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
255 XSaveContext( display, data->icon_window, winContext, (char *)win->hwndSelf );
256 wine_tsx11_unlock();
258 TRACE( "created %lx\n", data->icon_window );
259 SetPropA( win->hwndSelf, icon_window_atom, (HANDLE)data->icon_window );
260 return data->icon_window;
265 /***********************************************************************
266 * destroy_icon_window
268 inline static void destroy_icon_window( Display *display, WND *win )
270 struct x11drv_win_data *data = win->pDriverData;
272 if (!data->icon_window) return;
273 if (x11drv_thread_data()->cursor_window == data->icon_window)
274 x11drv_thread_data()->cursor_window = None;
275 wine_tsx11_lock();
276 XDeleteContext( display, data->icon_window, winContext );
277 XDestroyWindow( display, data->icon_window );
278 data->icon_window = 0;
279 wine_tsx11_unlock();
280 RemovePropA( win->hwndSelf, icon_window_atom );
284 /***********************************************************************
285 * set_icon_hints
287 * Set the icon wm hints
289 static void set_icon_hints( Display *display, WND *wndPtr, XWMHints *hints, HICON hIcon )
291 X11DRV_WND_DATA *data = wndPtr->pDriverData;
293 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
294 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
295 data->hWMIconBitmap = 0;
296 data->hWMIconMask = 0;
298 if (!(wndPtr->dwExStyle & WS_EX_MANAGED))
300 destroy_icon_window( display, wndPtr );
301 hints->flags &= ~(IconPixmapHint | IconMaskHint | IconWindowHint);
303 else if (!hIcon)
305 if (!data->icon_window) create_icon_window( display, wndPtr );
306 hints->icon_window = data->icon_window;
307 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
309 else
311 HBITMAP hbmOrig;
312 RECT rcMask;
313 BITMAP bmMask;
314 ICONINFO ii;
315 HDC hDC;
317 GetIconInfo(hIcon, &ii);
319 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
320 rcMask.top = 0;
321 rcMask.left = 0;
322 rcMask.right = bmMask.bmWidth;
323 rcMask.bottom = bmMask.bmHeight;
325 hDC = CreateCompatibleDC(0);
326 hbmOrig = SelectObject(hDC, ii.hbmMask);
327 InvertRect(hDC, &rcMask);
328 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
329 SelectObject(hDC, hbmOrig);
330 DeleteDC(hDC);
332 data->hWMIconBitmap = ii.hbmColor;
333 data->hWMIconMask = ii.hbmMask;
335 hints->icon_pixmap = X11DRV_BITMAP_Pixmap(data->hWMIconBitmap);
336 hints->icon_mask = X11DRV_BITMAP_Pixmap(data->hWMIconMask);
337 destroy_icon_window( display, wndPtr );
338 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
343 /***********************************************************************
344 * set_size_hints
346 * set the window size hints
348 static void set_size_hints( Display *display, WND *win )
350 XSizeHints* size_hints;
351 struct x11drv_win_data *data = win->pDriverData;
353 if ((size_hints = XAllocSizeHints()))
355 size_hints->win_gravity = StaticGravity;
356 size_hints->x = data->whole_rect.left;
357 size_hints->y = data->whole_rect.top;
358 size_hints->flags = PWinGravity | PPosition;
360 if (HAS_DLGFRAME( win->dwStyle, win->dwExStyle ))
362 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
363 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
364 size_hints->min_width = size_hints->max_width;
365 size_hints->min_height = size_hints->max_height;
366 size_hints->flags |= PMinSize | PMaxSize;
368 XSetWMNormalHints( display, data->whole_window, size_hints );
369 XFree( size_hints );
374 /***********************************************************************
375 * X11DRV_set_wm_hints
377 * Set the window manager hints for a newly-created window
379 void X11DRV_set_wm_hints( Display *display, WND *win )
381 struct x11drv_win_data *data = win->pDriverData;
382 Window group_leader;
383 XClassHint *class_hints;
384 XWMHints* wm_hints;
385 Atom protocols[3];
386 MwmHints mwm_hints;
387 Atom dndVersion = 4;
388 int i;
390 wine_tsx11_lock();
392 /* wm protocols */
393 i = 0;
394 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
395 protocols[i++] = x11drv_atom(_NET_WM_PING);
396 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
397 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
398 XA_ATOM, 32, PropModeReplace, (char *)protocols, i );
400 /* class hints */
401 if ((class_hints = XAllocClassHint()))
403 class_hints->res_name = "wine";
404 class_hints->res_class = "Wine";
405 XSetClassHint( display, data->whole_window, class_hints );
406 XFree( class_hints );
409 /* transient for hint */
410 if (win->owner)
412 Window owner_win = X11DRV_get_whole_window( win->owner );
413 XSetTransientForHint( display, data->whole_window, owner_win );
414 group_leader = owner_win;
416 else group_leader = data->whole_window;
418 /* size hints */
419 set_size_hints( display, win );
421 /* systray properties (KDE only for now) */
422 if (win->dwExStyle & WS_EX_TRAYWINDOW)
424 int val = 1;
425 XChangeProperty( display, data->whole_window, x11drv_atom(KWM_DOCKWINDOW),
426 x11drv_atom(KWM_DOCKWINDOW), 32, PropModeReplace, (char*)&val, 1 );
427 XChangeProperty( display, data->whole_window, x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR),
428 XA_WINDOW, 32, PropModeReplace, (char*)&data->whole_window, 1 );
431 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
432 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
433 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
434 i = getpid();
435 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
436 XA_CARDINAL, 32, PropModeReplace, (char *)&i, 1);
438 /* map WS_EX_TOOLWINDOW to _NET_WM_WINDOW_TYPE_UTILITY */
439 if (win->dwExStyle & WS_EX_TOOLWINDOW)
441 Atom a = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
442 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
443 XA_ATOM, 32, PropModeReplace, (char*)&a, 1);
446 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
447 mwm_hints.functions = 0;
448 if ((win->dwStyle & WS_CAPTION) == WS_CAPTION) mwm_hints.functions |= MWM_FUNC_MOVE;
449 if (win->dwStyle & WS_THICKFRAME) mwm_hints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
450 if (win->dwStyle & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
451 if (win->dwStyle & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
452 if (win->dwStyle & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
453 mwm_hints.decorations = 0;
454 if ((win->dwStyle & WS_CAPTION) == WS_CAPTION) mwm_hints.decorations |= MWM_DECOR_TITLE;
455 if (win->dwExStyle & WS_EX_DLGMODALFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER;
456 else if (win->dwStyle & WS_THICKFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
457 else if ((win->dwStyle & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) mwm_hints.decorations |= MWM_DECOR_BORDER;
458 else if (win->dwStyle & WS_BORDER) mwm_hints.decorations |= MWM_DECOR_BORDER;
459 else if (!(win->dwStyle & (WS_CHILD|WS_POPUP))) mwm_hints.decorations |= MWM_DECOR_BORDER;
460 if (win->dwStyle & WS_SYSMENU) mwm_hints.decorations |= MWM_DECOR_MENU;
461 if (win->dwStyle & WS_MINIMIZEBOX) mwm_hints.decorations |= MWM_DECOR_MINIMIZE;
462 if (win->dwStyle & WS_MAXIMIZEBOX) mwm_hints.decorations |= MWM_DECOR_MAXIMIZE;
464 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
465 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
466 (char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
468 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
469 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
471 wm_hints = XAllocWMHints();
472 wine_tsx11_unlock();
474 /* wm hints */
475 if (wm_hints)
477 wm_hints->flags = InputHint | StateHint | WindowGroupHint;
478 wm_hints->input = !(win->dwStyle & WS_DISABLED);
480 set_icon_hints( display, win, wm_hints, (HICON)GetClassLongA( win->hwndSelf, GCL_HICON ));
482 wm_hints->initial_state = (win->dwStyle & WS_MINIMIZE) ? IconicState : NormalState;
483 wm_hints->window_group = group_leader;
485 wine_tsx11_lock();
486 XSetWMHints( display, data->whole_window, wm_hints );
487 XFree(wm_hints);
488 wine_tsx11_unlock();
493 /***********************************************************************
494 * X11DRV_set_iconic_state
496 * Set the X11 iconic state according to the window style.
498 void X11DRV_set_iconic_state( WND *win )
500 Display *display = thread_display();
501 struct x11drv_win_data *data = win->pDriverData;
502 XWMHints* wm_hints;
503 BOOL iconic = IsIconic( win->hwndSelf );
505 wine_tsx11_lock();
507 if (iconic) XUnmapWindow( display, data->client_window );
508 else if (is_client_window_mapped( win )) XMapWindow( display, data->client_window );
510 if (!(wm_hints = XGetWMHints( display, data->whole_window ))) wm_hints = XAllocWMHints();
511 wm_hints->flags |= StateHint | IconPositionHint;
512 wm_hints->initial_state = iconic ? IconicState : NormalState;
513 wm_hints->icon_x = win->rectWindow.left;
514 wm_hints->icon_y = win->rectWindow.top;
515 XSetWMHints( display, data->whole_window, wm_hints );
517 if (win->dwStyle & WS_VISIBLE)
519 if (iconic)
520 XIconifyWindow( display, data->whole_window, DefaultScreen(display) );
521 else
522 if (!IsRectEmpty( &win->rectWindow )) XMapWindow( display, data->whole_window );
525 XFree(wm_hints);
526 wine_tsx11_unlock();
530 /***********************************************************************
531 * X11DRV_window_to_X_rect
533 * Convert a rect from client to X window coordinates
535 void X11DRV_window_to_X_rect( WND *win, RECT *rect )
537 RECT rc;
539 if (!(win->dwExStyle & WS_EX_MANAGED)) return;
540 if (IsRectEmpty( rect )) return;
542 rc.top = rc.bottom = rc.left = rc.right = 0;
544 AdjustWindowRectEx( &rc, win->dwStyle & ~(WS_HSCROLL|WS_VSCROLL), FALSE, win->dwExStyle );
546 rect->left -= rc.left;
547 rect->right -= rc.right;
548 rect->top -= rc.top;
549 rect->bottom -= rc.bottom;
550 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
551 if (rect->left >= rect->right) rect->right = rect->left + 1;
555 /***********************************************************************
556 * X11DRV_X_to_window_rect
558 * Opposite of X11DRV_window_to_X_rect
560 void X11DRV_X_to_window_rect( WND *win, RECT *rect )
562 if (!(win->dwExStyle & WS_EX_MANAGED)) return;
563 if (IsRectEmpty( rect )) return;
565 AdjustWindowRectEx( rect, win->dwStyle & ~(WS_HSCROLL|WS_VSCROLL), FALSE, win->dwExStyle );
567 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
568 if (rect->left >= rect->right) rect->right = rect->left + 1;
572 /***********************************************************************
573 * X11DRV_sync_whole_window_position
575 * Synchronize the X whole window position with the Windows one
577 int X11DRV_sync_whole_window_position( Display *display, WND *win, int zorder )
579 XWindowChanges changes;
580 int mask;
581 struct x11drv_win_data *data = win->pDriverData;
582 RECT whole_rect = win->rectWindow;
584 X11DRV_window_to_X_rect( win, &whole_rect );
585 mask = get_window_changes( &changes, &data->whole_rect, &whole_rect );
587 if (zorder)
589 if (is_window_top_level( win ))
591 /* find window that this one must be after */
592 HWND prev = GetWindow( win->hwndSelf, GW_HWNDPREV );
593 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
594 prev = GetWindow( prev, GW_HWNDPREV );
595 if (!prev) /* top child */
597 changes.stack_mode = Above;
598 mask |= CWStackMode;
600 else
602 /* should use stack_mode Below but most window managers don't get it right */
603 /* so move it above the next one in Z order */
604 HWND next = GetWindow( win->hwndSelf, GW_HWNDNEXT );
605 while (next && !(GetWindowLongW( next, GWL_STYLE ) & WS_VISIBLE))
606 next = GetWindow( next, GW_HWNDNEXT );
607 if (next)
609 changes.stack_mode = Above;
610 changes.sibling = X11DRV_get_whole_window(next);
611 mask |= CWStackMode | CWSibling;
615 else
617 HWND next = GetWindow( win->hwndSelf, GW_HWNDNEXT );
619 if (win->parent == GetDesktopWindow() &&
620 root_window != DefaultRootWindow(display))
622 /* in desktop mode we need the sibling to belong to the same process */
623 while (next)
625 WND *ptr = WIN_GetPtr( next );
626 if (ptr != WND_OTHER_PROCESS)
628 WIN_ReleasePtr( ptr );
629 break;
631 next = GetWindow( next, GW_HWNDNEXT );
635 if (!next) /* bottom child */
637 changes.stack_mode = Below;
638 mask |= CWStackMode;
640 else
642 changes.stack_mode = Above;
643 changes.sibling = X11DRV_get_whole_window(next);
644 mask |= CWStackMode | CWSibling;
649 data->whole_rect = whole_rect;
651 if (mask)
653 TRACE( "setting win %lx pos %ld,%ld,%ldx%ld after %lx changes=%x\n",
654 data->whole_window, whole_rect.left, whole_rect.top,
655 whole_rect.right - whole_rect.left, whole_rect.bottom - whole_rect.top,
656 changes.sibling, mask );
657 wine_tsx11_lock();
658 XSync( gdi_display, False ); /* flush graphics operations before moving the window */
659 if (is_window_top_level( win ))
661 if (mask & (CWWidth|CWHeight)) set_size_hints( display, win );
662 XReconfigureWMWindow( display, data->whole_window,
663 DefaultScreen(display), mask, &changes );
665 else XConfigureWindow( display, data->whole_window, mask, &changes );
666 wine_tsx11_unlock();
668 return mask;
672 /***********************************************************************
673 * X11DRV_sync_client_window_position
675 * Synchronize the X client window position with the Windows one
677 int X11DRV_sync_client_window_position( Display *display, WND *win )
679 XWindowChanges changes;
680 int mask;
681 struct x11drv_win_data *data = win->pDriverData;
682 RECT client_rect = win->rectClient;
684 OffsetRect( &client_rect, -data->whole_rect.left, -data->whole_rect.top );
686 if ((mask = get_window_changes( &changes, &data->client_rect, &client_rect )))
688 BOOL was_mapped = is_client_window_mapped( win );
690 TRACE( "setting win %lx pos %ld,%ld,%ldx%ld (was %ld,%ld,%ldx%ld) after %lx changes=%x\n",
691 data->client_window, client_rect.left, client_rect.top,
692 client_rect.right - client_rect.left, client_rect.bottom - client_rect.top,
693 data->client_rect.left, data->client_rect.top,
694 data->client_rect.right - data->client_rect.left,
695 data->client_rect.bottom - data->client_rect.top,
696 changes.sibling, mask );
697 data->client_rect = client_rect;
698 wine_tsx11_lock();
699 XSync( gdi_display, False ); /* flush graphics operations before moving the window */
700 if (was_mapped && !is_client_window_mapped( win ))
701 XUnmapWindow( display, data->client_window );
702 XConfigureWindow( display, data->client_window, mask, &changes );
703 if (!was_mapped && is_client_window_mapped( win ))
704 XMapWindow( display, data->client_window );
705 wine_tsx11_unlock();
707 return mask;
711 /***********************************************************************
712 * X11DRV_register_window
714 * Associate an X window to a HWND.
716 void X11DRV_register_window( Display *display, HWND hwnd, struct x11drv_win_data *data )
718 wine_tsx11_lock();
719 XSaveContext( display, data->whole_window, winContext, (char *)hwnd );
720 XSaveContext( display, data->client_window, winContext, (char *)hwnd );
721 wine_tsx11_unlock();
725 /**********************************************************************
726 * create_desktop
728 static void create_desktop( Display *display, WND *wndPtr )
730 X11DRV_WND_DATA *data = wndPtr->pDriverData;
732 wine_tsx11_lock();
733 winContext = XUniqueContext();
734 XInternAtoms( display, (char **)atom_names, NB_XATOMS - FIRST_XATOM, False, X11DRV_Atoms );
735 wine_tsx11_unlock();
737 whole_window_atom = MAKEINTATOMA( GlobalAddAtomA( "__wine_x11_whole_window" ));
738 client_window_atom = MAKEINTATOMA( GlobalAddAtomA( "__wine_x11_client_window" ));
739 icon_window_atom = MAKEINTATOMA( GlobalAddAtomA( "__wine_x11_icon_window" ));
741 data->whole_window = data->client_window = root_window;
742 data->whole_rect = data->client_rect = wndPtr->rectWindow;
744 SetPropA( wndPtr->hwndSelf, whole_window_atom, (HANDLE)root_window );
745 SetPropA( wndPtr->hwndSelf, client_window_atom, (HANDLE)root_window );
746 SetPropA( wndPtr->hwndSelf, "__wine_x11_visual_id", (HANDLE)XVisualIDFromVisual(visual) );
748 X11DRV_InitClipboard();
750 if (root_window != DefaultRootWindow(display)) X11DRV_create_desktop_thread();
754 /**********************************************************************
755 * create_whole_window
757 * Create the whole X window for a given window
759 static Window create_whole_window( Display *display, WND *win )
761 struct x11drv_win_data *data = win->pDriverData;
762 int cx, cy, mask;
763 XSetWindowAttributes attr;
764 Window parent;
765 RECT rect;
766 BOOL is_top_level = is_window_top_level( win );
768 rect = win->rectWindow;
769 X11DRV_window_to_X_rect( win, &rect );
771 if (!(cx = rect.right - rect.left)) cx = 1;
772 if (!(cy = rect.bottom - rect.top)) cy = 1;
774 parent = X11DRV_get_client_window( win->parent );
776 wine_tsx11_lock();
778 mask = get_window_attributes( display, win, &attr );
780 /* set the attributes that don't change over the lifetime of the window */
781 attr.bit_gravity = ForgetGravity;
782 attr.win_gravity = NorthWestGravity;
783 attr.backing_store = NotUseful/*WhenMapped*/;
784 mask |= CWBitGravity | CWWinGravity | CWBackingStore;
786 data->whole_rect = rect;
787 data->whole_window = XCreateWindow( display, parent, rect.left, rect.top, cx, cy,
788 0, screen_depth, InputOutput, visual,
789 mask, &attr );
791 if (!data->whole_window)
793 wine_tsx11_unlock();
794 return 0;
797 /* non-maximized child must be at bottom of Z order */
798 if ((win->dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
800 XWindowChanges changes;
801 changes.stack_mode = Below;
802 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
805 wine_tsx11_unlock();
807 if (is_top_level)
809 XIM xim = x11drv_thread_data()->xim;
810 if (xim) data->xic = X11DRV_CreateIC( xim, display, data->whole_window );
811 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 );