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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include <X11/Xresource.h>
34 #include <X11/Xutil.h>
36 #include <X11/extensions/shape.h>
37 #endif /* HAVE_LIBXSHAPE */
43 #include "wine/unicode.h"
46 #include "xcomposite.h"
47 #include "wine/debug.h"
48 #include "wine/server.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
54 /* X context to associate a hwnd to an X window */
55 XContext winContext = 0;
57 /* X context to associate a struct x11drv_win_data to an hwnd */
58 static XContext win_data_context;
60 static const char whole_window_prop[] = "__wine_x11_whole_window";
61 static const char icon_window_prop[] = "__wine_x11_icon_window";
62 static const char fbconfig_id_prop[] = "__wine_x11_fbconfig_id";
63 static const char gl_drawable_prop[] = "__wine_x11_gl_drawable";
64 static const char pixmap_prop[] = "__wine_x11_pixmap";
65 static const char managed_prop[] = "__wine_x11_managed";
66 static const char visual_id_prop[] = "__wine_x11_visual_id";
68 /* for XDG systray icons */
69 #define SYSTEM_TRAY_REQUEST_DOCK 0
71 extern int usexcomposite;
73 /***********************************************************************
76 * Check if a given window should be managed
78 BOOL is_window_managed( HWND hwnd, UINT swp_flags, const RECT *window_rect )
80 DWORD style, ex_style;
82 /* child windows are not managed */
83 style = GetWindowLongW( hwnd, GWL_STYLE );
84 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD) return FALSE;
85 /* activated windows are managed */
86 if (!(swp_flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) return TRUE;
87 if (hwnd == GetActiveWindow()) return TRUE;
88 /* windows with caption are managed */
89 if ((style & WS_CAPTION) == WS_CAPTION) return TRUE;
90 /* tool windows are not managed */
91 ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE );
92 if (ex_style & WS_EX_TOOLWINDOW) return FALSE;
93 /* windows with thick frame are managed */
94 if (style & WS_THICKFRAME) return TRUE;
95 /* application windows are managed */
96 if (ex_style & WS_EX_APPWINDOW) return TRUE;
99 /* popup with sysmenu == caption are managed */
100 if (style & WS_SYSMENU) return TRUE;
101 /* full-screen popup windows are managed */
102 if ((window_rect->right - window_rect->left) == screen_width &&
103 (window_rect->bottom - window_rect->top) == screen_height)
106 /* default: not managed */
111 /***********************************************************************
112 * X11DRV_is_window_rect_mapped
114 * Check if the X whole window should be mapped based on its rectangle
116 BOOL X11DRV_is_window_rect_mapped( const RECT *rect )
118 /* don't map if rect is empty */
119 if (IsRectEmpty( rect )) return FALSE;
121 /* don't map if rect is off-screen */
122 if (rect->left >= virtual_screen_rect.right ||
123 rect->top >= virtual_screen_rect.bottom ||
124 rect->right <= virtual_screen_rect.left ||
125 rect->bottom <= virtual_screen_rect.top)
132 /***********************************************************************
133 * get_mwm_decorations
135 static unsigned long get_mwm_decorations( DWORD style, DWORD ex_style )
137 unsigned long ret = 0;
139 if (ex_style & WS_EX_TOOLWINDOW) return 0;
141 if ((style & WS_CAPTION) == WS_CAPTION)
143 ret |= MWM_DECOR_TITLE | MWM_DECOR_BORDER;
144 if (style & WS_SYSMENU) ret |= MWM_DECOR_MENU;
145 if (style & WS_MINIMIZEBOX) ret |= MWM_DECOR_MINIMIZE;
146 if (style & WS_MAXIMIZEBOX) ret |= MWM_DECOR_MAXIMIZE;
148 if (ex_style & WS_EX_DLGMODALFRAME) ret |= MWM_DECOR_BORDER;
149 else if (style & WS_THICKFRAME) ret |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
150 else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) ret |= MWM_DECOR_BORDER;
155 /***********************************************************************
156 * get_x11_rect_offset
158 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
160 static void get_x11_rect_offset( struct x11drv_win_data *data, RECT *rect )
162 DWORD style, ex_style, style_mask = 0, ex_style_mask = 0;
165 rect->top = rect->bottom = rect->left = rect->right = 0;
167 style = GetWindowLongW( data->hwnd, GWL_STYLE );
168 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
169 decor = get_mwm_decorations( style, ex_style );
171 if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION;
172 if (decor & MWM_DECOR_BORDER)
174 style_mask |= WS_DLGFRAME | WS_THICKFRAME;
175 ex_style_mask |= WS_EX_DLGMODALFRAME;
178 AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask );
182 /***********************************************************************
183 * get_window_attributes
185 * Fill the window attributes structure for an X window.
187 static int get_window_attributes( Display *display, struct x11drv_win_data *data,
188 XSetWindowAttributes *attr )
190 attr->override_redirect = !data->managed;
191 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
192 attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0);
193 attr->cursor = x11drv_thread_data()->cursor;
194 attr->bit_gravity = NorthWestGravity;
195 attr->backing_store = NotUseful;
196 attr->event_mask = (ExposureMask | PointerMotionMask |
197 ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
198 KeyPressMask | KeyReleaseMask | FocusChangeMask | KeymapStateMask);
199 if (data->managed) attr->event_mask |= StructureNotifyMask;
201 return (CWOverrideRedirect | CWSaveUnder | CWColormap | CWCursor |
202 CWEventMask | CWBitGravity | CWBackingStore);
206 /***********************************************************************
207 * X11DRV_sync_window_style
209 * Change the X window attributes when the window style has changed.
211 void X11DRV_sync_window_style( Display *display, struct x11drv_win_data *data )
213 if (data->whole_window != root_window)
215 XSetWindowAttributes attr;
216 int mask = get_window_attributes( display, data, &attr );
219 XChangeWindowAttributes( display, data->whole_window, mask, &attr );
225 /***********************************************************************
228 * Update the X11 window region.
230 static void sync_window_region( Display *display, struct x11drv_win_data *data, HRGN hrgn )
232 #ifdef HAVE_LIBXSHAPE
233 if (!data->whole_window) return;
238 XShapeCombineMask( display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet );
243 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
247 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
248 data->window_rect.left - data->whole_rect.left,
249 data->window_rect.top - data->whole_rect.top,
250 (XRectangle *)pRegionData->Buffer,
251 pRegionData->rdh.nCount, ShapeSet, YXBanded );
253 HeapFree(GetProcessHeap(), 0, pRegionData);
256 #endif /* HAVE_LIBXSHAPE */
260 /***********************************************************************
263 static void sync_window_text( Display *display, Window win, const WCHAR *text )
266 char *buffer, *utf8_buffer;
269 /* allocate new buffer for window text */
270 count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
271 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) return;
272 WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
274 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
275 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
277 HeapFree( GetProcessHeap(), 0, buffer );
280 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
283 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
285 XSetWMName( display, win, &prop );
286 XSetWMIconName( display, win, &prop );
290 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
291 according to the standard
292 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
294 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
295 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
298 HeapFree( GetProcessHeap(), 0, utf8_buffer );
299 HeapFree( GetProcessHeap(), 0, buffer );
303 /***********************************************************************
304 * X11DRV_set_win_format
306 BOOL X11DRV_set_win_format( HWND hwnd, XID fbconfig_id )
308 Display *display = thread_display();
309 struct x11drv_win_data *data;
315 if (!(data = X11DRV_get_win_data(hwnd)) &&
316 !(data = X11DRV_create_win_data(hwnd))) return FALSE;
320 vis = visual_from_fbconfig_id(fbconfig_id);
327 if(data->whole_window && vis->visualid == XVisualIDFromVisual(visual))
329 TRACE("Whole window available and visual match, rendering onscreen\n");
335 parent = data->whole_window;
339 next_hwnd = GetAncestor(next_hwnd, GA_PARENT);
342 ERR("Could not find parent HWND with a drawable!\n");
345 parent = X11DRV_get_whole_window(next_hwnd);
348 w = data->client_rect.right - data->client_rect.left;
349 h = data->client_rect.bottom - data->client_rect.top;
355 #ifdef SONAME_LIBXCOMPOSITE
358 XSetWindowAttributes attrib;
360 attrib.override_redirect = True;
361 attrib.colormap = XCreateColormap(display, parent, vis->visual,
362 (vis->class == PseudoColor ||
363 vis->class == GrayScale ||
364 vis->class == DirectColor) ?
365 AllocAll : AllocNone);
366 XInstallColormap(gdi_display, attrib.colormap);
368 data->gl_drawable = XCreateWindow(display, parent, -w, 0, w, h, 0,
369 vis->depth, InputOutput, vis->visual,
370 CWColormap | CWOverrideRedirect,
372 if(data->gl_drawable)
374 pXCompositeRedirectWindow(display, data->gl_drawable,
375 CompositeRedirectManual);
376 XMapWindow(display, data->gl_drawable);
382 WARN("XComposite is not available, using GLXPixmap hack\n");
384 data->pixmap = XCreatePixmap(display, parent, w, h, vis->depth);
387 ERR("Failed to create pixmap for offscreen rendering\n");
393 data->gl_drawable = create_glxpixmap(display, vis, data->pixmap);
394 if(!data->gl_drawable)
396 XFreePixmap(display, data->pixmap);
401 if(!data->gl_drawable)
403 ERR("Failed to create drawable for offscreen rendering\n");
415 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
416 data->gl_drawable, fbconfig_id);
418 data->fbconfig_id = fbconfig_id;
419 SetPropA(hwnd, fbconfig_id_prop, (HANDLE)data->fbconfig_id);
420 SetPropA(hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
421 SetPropA(hwnd, pixmap_prop, (HANDLE)data->pixmap);
422 invalidate_dce( hwnd, &data->window_rect );
426 /***********************************************************************
427 * X11DRV_sync_gl_drawable
429 void X11DRV_sync_gl_drawable(Display *display, struct x11drv_win_data *data)
431 int w = data->client_rect.right - data->client_rect.left;
432 int h = data->client_rect.bottom - data->client_rect.top;
439 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data->gl_drawable, w, h);
440 #ifdef SONAME_LIBXCOMPOSITE
444 XMoveResizeWindow(display, data->gl_drawable, -w, 0, w, h);
450 parent = data->whole_window;
451 next_hwnd = data->hwnd;
454 next_hwnd = GetAncestor(next_hwnd, GA_PARENT);
457 ERR("Could not find parent HWND with a drawable!\n");
460 parent = X11DRV_get_whole_window(next_hwnd);
465 vis = visual_from_fbconfig_id(data->fbconfig_id);
472 pix = XCreatePixmap(display, parent, w, h, vis->depth);
475 ERR("Failed to create pixmap for offscreen rendering\n");
481 glxp = create_glxpixmap(display, vis, pix);
484 ERR("Failed to create drawable for offscreen rendering\n");
485 XFreePixmap(display, pix);
493 mark_drawable_dirty(data->gl_drawable, glxp);
495 XFreePixmap(display, data->pixmap);
496 destroy_glxpixmap(display, data->gl_drawable);
499 data->gl_drawable = glxp;
504 SetPropA(data->hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
505 SetPropA(data->hwnd, pixmap_prop, (HANDLE)data->pixmap);
506 invalidate_dce( data->hwnd, &data->window_rect );
510 /***********************************************************************
513 * fill the window changes structure
515 static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
519 if (old->right - old->left != new->right - new->left )
521 if (!(changes->width = new->right - new->left)) changes->width = 1;
524 if (old->bottom - old->top != new->bottom - new->top)
526 if (!(changes->height = new->bottom - new->top)) changes->height = 1;
529 if (old->left != new->left)
531 changes->x = new->left;
534 if (old->top != new->top)
536 changes->y = new->top;
543 /***********************************************************************
546 static Window create_icon_window( Display *display, struct x11drv_win_data *data )
548 XSetWindowAttributes attr;
550 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
551 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
552 attr.bit_gravity = NorthWestGravity;
553 attr.backing_store = NotUseful/*WhenMapped*/;
554 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
557 data->icon_window = XCreateWindow( display, root_window, 0, 0,
558 GetSystemMetrics( SM_CXICON ),
559 GetSystemMetrics( SM_CYICON ),
562 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
563 XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd );
566 TRACE( "created %lx\n", data->icon_window );
567 SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window );
568 return data->icon_window;
573 /***********************************************************************
574 * destroy_icon_window
576 static void destroy_icon_window( Display *display, struct x11drv_win_data *data )
578 if (!data->icon_window) return;
579 if (x11drv_thread_data()->cursor_window == data->icon_window)
580 x11drv_thread_data()->cursor_window = None;
582 XDeleteContext( display, data->icon_window, winContext );
583 XDestroyWindow( display, data->icon_window );
584 data->icon_window = 0;
586 RemovePropA( data->hwnd, icon_window_prop );
590 /***********************************************************************
593 * Set the icon wm hints
595 static void set_icon_hints( Display *display, struct x11drv_win_data *data, HICON hIcon )
597 XWMHints *hints = data->wm_hints;
599 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
600 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
601 data->hWMIconBitmap = 0;
602 data->hWMIconMask = 0;
606 if (!data->icon_window) create_icon_window( display, data );
607 hints->icon_window = data->icon_window;
608 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
618 GetIconInfo(hIcon, &ii);
620 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
623 rcMask.right = bmMask.bmWidth;
624 rcMask.bottom = bmMask.bmHeight;
626 hDC = CreateCompatibleDC(0);
627 hbmOrig = SelectObject(hDC, ii.hbmMask);
628 InvertRect(hDC, &rcMask);
629 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
630 SelectObject(hDC, hbmOrig);
633 data->hWMIconBitmap = ii.hbmColor;
634 data->hWMIconMask = ii.hbmMask;
636 hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap);
637 hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask);
638 destroy_icon_window( display, data );
639 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
643 /***********************************************************************
644 * wine_make_systray_window (X11DRV.@)
646 * Docks the given X window with the NETWM system tray.
648 void X11DRV_make_systray_window( HWND hwnd )
650 static Atom systray_atom;
651 Display *display = thread_display();
652 struct x11drv_win_data *data;
653 Window systray_window;
655 if (!(data = X11DRV_get_win_data( hwnd )) &&
656 !(data = X11DRV_create_win_data( hwnd ))) return;
661 if (DefaultScreen( display ) == 0)
662 systray_atom = x11drv_atom(_NET_SYSTEM_TRAY_S0);
665 char systray_buffer[29]; /* strlen(_NET_SYSTEM_TRAY_S4294967295)+1 */
666 sprintf( systray_buffer, "_NET_SYSTEM_TRAY_S%u", DefaultScreen( display ) );
667 systray_atom = XInternAtom( display, systray_buffer, False );
670 systray_window = XGetSelectionOwner( display, systray_atom );
673 TRACE("Docking tray icon %p\n", data->hwnd);
675 if (systray_window != None)
678 unsigned long info[2];
680 /* Put the window offscreen so it isn't mapped. The window _cannot_ be
681 * mapped if we intend to dock with an XEMBED tray. If the window is
682 * mapped when we dock, it may become visible as a child of the root
683 * window after it docks, which isn't the proper behavior.
685 * For more information on this problem, see
686 * http://standards.freedesktop.org/xembed-spec/latest/ar01s04.html */
688 SetWindowPos( data->hwnd, NULL, virtual_screen_rect.right + 1, virtual_screen_rect.bottom + 1,
689 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE );
691 /* set XEMBED protocol data on the window */
692 info[0] = 0; /* protocol version */
693 info[1] = 1; /* mapped = true */
696 XChangeProperty( display, data->whole_window,
697 x11drv_atom(_XEMBED_INFO),
698 x11drv_atom(_XEMBED_INFO), 32, PropModeReplace,
699 (unsigned char*)info, 2 );
702 /* send the docking request message */
703 ZeroMemory( &ev, sizeof(ev) );
704 ev.xclient.type = ClientMessage;
705 ev.xclient.window = systray_window;
706 ev.xclient.message_type = x11drv_atom( _NET_SYSTEM_TRAY_OPCODE );
707 ev.xclient.format = 32;
708 ev.xclient.data.l[0] = CurrentTime;
709 ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
710 ev.xclient.data.l[2] = data->whole_window;
711 ev.xclient.data.l[3] = 0;
712 ev.xclient.data.l[4] = 0;
715 XSendEvent( display, systray_window, False, NoEventMask, &ev );
723 /* fall back to he KDE hints if the WM doesn't support XEMBED'ed
727 XChangeProperty( display, data->whole_window,
728 x11drv_atom(KWM_DOCKWINDOW),
729 x11drv_atom(KWM_DOCKWINDOW), 32, PropModeReplace,
730 (unsigned char*)&val, 1 );
731 XChangeProperty( display, data->whole_window,
732 x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR),
733 XA_WINDOW, 32, PropModeReplace,
734 (unsigned char*)&data->whole_window, 1 );
740 /***********************************************************************
743 * set the window size hints
745 static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style )
747 XSizeHints* size_hints;
749 if ((size_hints = XAllocSizeHints()))
751 size_hints->flags = 0;
753 if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */
755 size_hints->win_gravity = StaticGravity;
756 size_hints->x = data->whole_rect.left;
757 size_hints->y = data->whole_rect.top;
758 size_hints->flags |= PWinGravity | PPosition;
761 if ( !(style & WS_THICKFRAME) )
763 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
764 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
765 size_hints->min_width = size_hints->max_width;
766 size_hints->min_height = size_hints->max_height;
767 size_hints->flags |= PMinSize | PMaxSize;
769 XSetWMNormalHints( display, data->whole_window, size_hints );
775 /***********************************************************************
778 * get the name of the current process for setting class hints
780 static char *get_process_name(void)
786 WCHAR module[MAX_PATH];
787 DWORD len = GetModuleFileNameW( 0, module, MAX_PATH );
788 if (len && len < MAX_PATH)
791 WCHAR *p, *appname = module;
793 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
794 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
795 len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL );
796 if ((ptr = HeapAlloc( GetProcessHeap(), 0, len )))
798 WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL );
807 /***********************************************************************
808 * set_initial_wm_hints
810 * Set the window manager hints that don't change over the lifetime of a window.
812 static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data )
817 XClassHint *class_hints;
818 char *process_name = get_process_name();
824 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
825 protocols[i++] = x11drv_atom(_NET_WM_PING);
826 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
827 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
828 XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
831 if ((class_hints = XAllocClassHint()))
833 static char wine[] = "Wine";
835 class_hints->res_name = process_name;
836 class_hints->res_class = wine;
837 XSetClassHint( display, data->whole_window, class_hints );
838 XFree( class_hints );
841 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
842 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
843 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
845 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
846 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
848 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
849 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
851 data->wm_hints = XAllocWMHints();
856 HICON icon = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 );
857 if (!icon) icon = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON );
858 data->wm_hints->flags = 0;
859 set_icon_hints( display, data, icon );
864 /***********************************************************************
865 * X11DRV_set_wm_hints
867 * Set the window manager hints for a newly-created window
869 void X11DRV_set_wm_hints( Display *display, struct x11drv_win_data *data )
874 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
875 DWORD ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
876 HWND owner = GetWindow( data->hwnd, GW_OWNER );
878 if (data->hwnd == GetDesktopWindow())
880 /* force some styles for the desktop to get the correct decorations */
881 style |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
885 /* transient for hint */
888 Window owner_win = X11DRV_get_whole_window( owner );
890 XSetTransientForHint( display, data->whole_window, owner_win );
892 group_leader = owner_win;
894 else group_leader = data->whole_window;
899 set_size_hints( display, data, style );
901 /* set the WM_WINDOW_TYPE */
902 window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
903 if (ex_style & WS_EX_TOOLWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
904 else if (style & WS_THICKFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
905 else if (style & WS_DLGFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
906 else if (ex_style & WS_EX_DLGMODALFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
908 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
909 XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1);
911 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
912 mwm_hints.decorations = get_mwm_decorations( style, ex_style );
913 mwm_hints.functions = MWM_FUNC_MOVE;
914 if (style & WS_THICKFRAME) mwm_hints.functions |= MWM_FUNC_RESIZE;
915 if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
916 if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
917 if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
919 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
920 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
921 (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
926 data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint;
927 data->wm_hints->input = !(style & WS_DISABLED);
928 data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
929 data->wm_hints->window_group = group_leader;
930 XSetWMHints( display, data->whole_window, data->wm_hints );
937 /***********************************************************************
938 * X11DRV_set_iconic_state
940 * Set the X11 iconic state according to the window style.
942 void X11DRV_set_iconic_state( HWND hwnd )
944 Display *display = thread_display();
945 struct x11drv_win_data *data;
947 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
948 BOOL iconic = (style & WS_MINIMIZE) != 0;
950 if (!(data = X11DRV_get_win_data( hwnd ))) return;
951 if (!data->whole_window) return;
953 GetWindowRect( hwnd, &rect );
959 data->wm_hints->flags |= StateHint | IconPositionHint;
960 data->wm_hints->initial_state = iconic ? IconicState : NormalState;
961 data->wm_hints->icon_x = rect.left - virtual_screen_rect.left;
962 data->wm_hints->icon_y = rect.top - virtual_screen_rect.top;
963 XSetWMHints( display, data->whole_window, data->wm_hints );
969 XIconifyWindow( display, data->whole_window, DefaultScreen(display) );
971 if (X11DRV_is_window_rect_mapped( &rect ))
972 XMapWindow( display, data->whole_window );
979 /***********************************************************************
980 * X11DRV_window_to_X_rect
982 * Convert a rect from client to X window coordinates
984 void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect )
988 if (!data->managed) return;
989 if (IsRectEmpty( rect )) return;
991 get_x11_rect_offset( data, &rc );
993 rect->left -= rc.left;
994 rect->right -= rc.right;
996 rect->bottom -= rc.bottom;
997 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
998 if (rect->left >= rect->right) rect->right = rect->left + 1;
1002 /***********************************************************************
1003 * X11DRV_X_to_window_rect
1005 * Opposite of X11DRV_window_to_X_rect
1007 void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect )
1011 if (!data->managed) return;
1012 if (IsRectEmpty( rect )) return;
1014 get_x11_rect_offset( data, &rc );
1016 rect->left += rc.left;
1017 rect->right += rc.right;
1018 rect->top += rc.top;
1019 rect->bottom += rc.bottom;
1020 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1021 if (rect->left >= rect->right) rect->right = rect->left + 1;
1025 /***********************************************************************
1026 * X11DRV_sync_window_position
1028 * Synchronize the X window position with the Windows one
1030 void X11DRV_sync_window_position( Display *display, struct x11drv_win_data *data,
1031 UINT swp_flags, const RECT *old_client_rect,
1032 const RECT *old_whole_rect )
1034 XWindowChanges changes;
1035 int mask = get_window_changes( &changes, old_whole_rect, &data->whole_rect );
1037 if (!(swp_flags & SWP_NOZORDER))
1039 /* find window that this one must be after */
1040 HWND prev = GetWindow( data->hwnd, GW_HWNDPREV );
1041 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
1042 prev = GetWindow( prev, GW_HWNDPREV );
1043 if (!prev) /* top child */
1045 changes.stack_mode = Above;
1046 mask |= CWStackMode;
1050 /* should use stack_mode Below but most window managers don't get it right */
1051 /* so move it above the next one in Z order */
1052 HWND next = GetWindow( data->hwnd, GW_HWNDNEXT );
1053 while (next && !(GetWindowLongW( next, GWL_STYLE ) & WS_VISIBLE))
1054 next = GetWindow( next, GW_HWNDNEXT );
1057 changes.stack_mode = Above;
1058 changes.sibling = X11DRV_get_whole_window(next);
1059 mask |= CWStackMode | CWSibling;
1064 /* only the size is allowed to change for the desktop window */
1065 if (data->whole_window == root_window) mask &= CWWidth | CWHeight;
1069 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
1071 TRACE( "setting win %lx pos %d,%d,%dx%d after %lx changes=%x\n",
1072 data->whole_window, data->whole_rect.left, data->whole_rect.top,
1073 data->whole_rect.right - data->whole_rect.left,
1074 data->whole_rect.bottom - data->whole_rect.top, changes.sibling, mask );
1077 if (mask & (CWWidth|CWHeight)) set_size_hints( display, data, style );
1078 if (mask & CWX) changes.x -= virtual_screen_rect.left;
1079 if (mask & CWY) changes.y -= virtual_screen_rect.top;
1080 XReconfigureWMWindow( display, data->whole_window,
1081 DefaultScreen(display), mask, &changes );
1082 wine_tsx11_unlock();
1087 /**********************************************************************
1088 * create_whole_window
1090 * Create the whole X window for a given window
1092 static Window create_whole_window( Display *display, struct x11drv_win_data *data )
1095 XSetWindowAttributes attr;
1100 if (!(cx = data->window_rect.right - data->window_rect.left)) cx = 1;
1101 if (!(cy = data->window_rect.bottom - data->window_rect.top)) cy = 1;
1103 mask = get_window_attributes( display, data, &attr );
1107 data->whole_rect = data->window_rect;
1108 data->whole_window = XCreateWindow( display, root_window,
1109 data->window_rect.left - virtual_screen_rect.left,
1110 data->window_rect.top - virtual_screen_rect.top,
1111 cx, cy, 0, screen_depth, InputOutput,
1112 visual, mask, &attr );
1114 if (!data->whole_window)
1116 wine_tsx11_unlock();
1119 XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
1120 wine_tsx11_unlock();
1122 xim = x11drv_thread_data()->xim;
1123 if (xim) data->xic = X11DRV_CreateIC( xim, display, data->whole_window );
1125 set_initial_wm_hints( display, data );
1126 X11DRV_set_wm_hints( display, data );
1128 SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
1130 /* set the window text */
1131 if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
1132 sync_window_text( display, data->whole_window, text );
1134 /* set the window region */
1135 if ((hrgn = CreateRectRgn( 0, 0, 0, 0 )))
1137 if (GetWindowRgn( data->hwnd, hrgn ) != ERROR) sync_window_region( display, data, hrgn );
1138 DeleteObject( hrgn );
1140 return data->whole_window;
1144 /**********************************************************************
1145 * destroy_whole_window
1147 * Destroy the whole X window for a given window.
1149 static void destroy_whole_window( Display *display, struct x11drv_win_data *data )
1151 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1153 if (!data->whole_window) return;
1155 TRACE( "win %p xwin %lx\n", data->hwnd, data->whole_window );
1156 if (thread_data->cursor_window == data->whole_window) thread_data->cursor_window = None;
1158 XDeleteContext( display, data->whole_window, winContext );
1159 XDestroyWindow( display, data->whole_window );
1160 data->whole_window = 0;
1163 XUnsetICFocus( data->xic );
1164 XDestroyIC( data->xic );
1166 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1168 XFree( data->wm_hints );
1169 data->wm_hints = NULL;
1170 wine_tsx11_unlock();
1171 RemovePropA( data->hwnd, whole_window_prop );
1175 /*****************************************************************
1176 * SetWindowText (X11DRV.@)
1178 void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
1180 Display *display = thread_display();
1183 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display))
1184 sync_window_text( display, win, text );
1188 /***********************************************************************
1189 * DestroyWindow (X11DRV.@)
1191 void X11DRV_DestroyWindow( HWND hwnd )
1193 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1194 Display *display = thread_data->display;
1195 struct x11drv_win_data *data;
1197 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1201 destroy_glxpixmap(display, data->gl_drawable);
1203 XFreePixmap(display, data->pixmap);
1204 wine_tsx11_unlock();
1206 else if (data->gl_drawable)
1209 XDestroyWindow(display, data->gl_drawable);
1210 wine_tsx11_unlock();
1213 free_window_dce( data );
1214 destroy_whole_window( display, data );
1215 destroy_icon_window( display, data );
1217 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
1218 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
1219 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
1221 XDeleteContext( display, (XID)hwnd, win_data_context );
1222 wine_tsx11_unlock();
1223 HeapFree( GetProcessHeap(), 0, data );
1227 static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
1229 struct x11drv_win_data *data;
1231 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
1235 if (!winContext) winContext = XUniqueContext();
1236 if (!win_data_context) win_data_context = XUniqueContext();
1237 XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
1238 wine_tsx11_unlock();
1244 /* initialize the desktop window id in the desktop manager process */
1245 static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd )
1247 struct x11drv_win_data *data;
1250 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1252 visualid = XVisualIDFromVisual(visual);
1253 wine_tsx11_unlock();
1254 data->whole_window = root_window;
1255 data->managed = TRUE;
1256 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1257 SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
1258 SetPropA( data->hwnd, visual_id_prop, (HANDLE)visualid );
1259 set_initial_wm_hints( display, data );
1263 /**********************************************************************
1264 * CreateDesktopWindow (X11DRV.@)
1266 BOOL X11DRV_CreateDesktopWindow( HWND hwnd )
1268 unsigned int width, height;
1270 /* retrieve the real size of the desktop */
1271 SERVER_START_REQ( get_window_rectangles )
1274 wine_server_call( req );
1275 width = reply->window.right - reply->window.left;
1276 height = reply->window.bottom - reply->window.top;
1280 if (!width && !height) /* not initialized yet */
1282 SERVER_START_REQ( set_window_pos )
1286 req->flags = SWP_NOZORDER;
1287 req->window.left = virtual_screen_rect.left;
1288 req->window.top = virtual_screen_rect.top;
1289 req->window.right = virtual_screen_rect.right;
1290 req->window.bottom = virtual_screen_rect.bottom;
1291 req->client = req->window;
1292 wine_server_call( req );
1298 Window win = (Window)GetPropA( hwnd, whole_window_prop );
1299 if (win && win != root_window) X11DRV_init_desktop( win, width, height );
1305 /**********************************************************************
1306 * CreateWindow (X11DRV.@)
1308 BOOL X11DRV_CreateWindow( HWND hwnd, CREATESTRUCTA *cs, BOOL unicode )
1310 Display *display = thread_display();
1315 CBT_CREATEWNDA cbtc;
1318 INT cx = cs->cx, cy = cs->cy;
1320 if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( display ))
1322 /* the desktop win data can't be created lazily */
1323 if (!create_desktop_win_data( display, hwnd )) return FALSE;
1326 /* Call the WH_CBT hook */
1328 /* the window style passed to the hook must be the real window style,
1329 * rather than just the window style that the caller to CreateWindowEx
1330 * passed in, so we have to copy the original CREATESTRUCT and get the
1331 * the real style. */
1333 cbcs.style = GetWindowLongW(hwnd, GWL_STYLE);
1336 cbtc.hwndInsertAfter = HWND_TOP;
1337 if (HOOK_CallHooks( WH_CBT, HCBT_CREATEWND, (WPARAM)hwnd, (LPARAM)&cbtc, unicode ))
1339 TRACE("CBT-hook returned !0\n");
1343 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
1344 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
1346 POINT maxSize, maxPos, minTrack, maxTrack;
1348 WINPOS_GetMinMaxInfo( hwnd, &maxSize, &maxPos, &minTrack, &maxTrack);
1349 if (maxTrack.x < cx) cx = maxTrack.x;
1350 if (maxTrack.y < cy) cy = maxTrack.y;
1355 SetRect( &rect, cs->x, cs->y, cs->x + cx, cs->y + cy );
1356 if (!X11DRV_SetWindowPos( hwnd, 0, &rect, &rect, SWP_NOZORDER | SWP_NOACTIVATE, NULL ))
1359 /* send WM_NCCREATE */
1360 TRACE( "hwnd %p cs %d,%d %dx%d\n", hwnd, cs->x, cs->y, cs->cx, cs->cy );
1362 ret = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
1364 ret = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
1367 WARN("aborted by WM_xxCREATE!\n");
1371 /* make sure the window is still valid */
1372 if (!(wndPtr = WIN_GetPtr(hwnd))) return FALSE;
1374 /* send WM_NCCALCSIZE */
1375 rect = wndPtr->rectWindow;
1376 WIN_ReleasePtr( wndPtr );
1377 SendMessageW( hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&rect );
1379 if (!(wndPtr = WIN_GetPtr(hwnd))) return FALSE;
1381 /* yes, even if the CBT hook was called with HWND_TOP */
1382 insert_after = (wndPtr->dwStyle & WS_CHILD) ? HWND_BOTTOM : HWND_TOP;
1384 X11DRV_SetWindowPos( hwnd, insert_after, &wndPtr->rectWindow, &rect, SWP_NOACTIVATE, NULL );
1386 WIN_ReleasePtr( wndPtr );
1389 ret = (SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
1391 ret = (SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
1393 if (!ret) return FALSE;
1395 NotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_WINDOW, 0);
1397 /* Send the size messages */
1399 if (!(wndPtr = WIN_GetPtr(hwnd)) || wndPtr == WND_OTHER_PROCESS) return FALSE;
1400 if (!(wndPtr->flags & WIN_NEED_SIZE))
1402 RECT rect = wndPtr->rectClient;
1403 WIN_ReleasePtr( wndPtr );
1404 /* send it anyway */
1405 if (((rect.right-rect.left) <0) ||((rect.bottom-rect.top)<0))
1406 WARN("sending bogus WM_SIZE message 0x%08x\n",
1407 MAKELONG(rect.right-rect.left, rect.bottom-rect.top));
1408 SendMessageW( hwnd, WM_SIZE, SIZE_RESTORED,
1409 MAKELONG(rect.right-rect.left, rect.bottom-rect.top));
1410 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( rect.left, rect.top ) );
1412 else WIN_ReleasePtr( wndPtr );
1414 /* Show the window, maximizing or minimizing if needed */
1416 style = GetWindowLongW( hwnd, GWL_STYLE );
1417 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
1419 extern UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect ); /*FIXME*/
1422 UINT swFlag = (style & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE;
1423 WIN_SetStyle( hwnd, 0, WS_MAXIMIZE | WS_MINIMIZE );
1424 swFlag = WINPOS_MinMaximize( hwnd, swFlag, &newPos );
1426 swFlag |= SWP_FRAMECHANGED; /* Frame always gets changed */
1427 if (!(style & WS_VISIBLE) || (style & WS_CHILD) || GetActiveWindow()) swFlag |= SWP_NOACTIVATE;
1429 SetWindowPos( hwnd, 0, newPos.left, newPos.top,
1430 newPos.right, newPos.bottom, swFlag );
1436 X11DRV_DestroyWindow( hwnd );
1441 /***********************************************************************
1442 * X11DRV_get_win_data
1444 * Return the X11 data structure associated with a window.
1446 struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1450 if (!hwnd || XFindContext( thread_display(), (XID)hwnd, win_data_context, &data )) data = NULL;
1451 return (struct x11drv_win_data *)data;
1455 /***********************************************************************
1456 * X11DRV_create_win_data
1458 * Create an X11 data window structure for an existing window.
1460 struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd )
1462 Display *display = thread_display();
1463 struct x11drv_win_data *data;
1466 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
1467 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1469 GetWindowRect( hwnd, &data->window_rect );
1470 MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 );
1471 data->whole_rect = data->window_rect;
1472 GetClientRect( hwnd, &data->client_rect );
1473 MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 );
1475 if (parent == GetDesktopWindow())
1477 if (!create_whole_window( display, data ))
1479 HeapFree( GetProcessHeap(), 0, data );
1482 TRACE( "win %p/%lx window %s whole %s client %s\n",
1483 hwnd, data->whole_window, wine_dbgstr_rect( &data->window_rect ),
1484 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
1487 /* get class or window DC if needed */
1488 alloc_window_dce( data );
1493 /***********************************************************************
1494 * X11DRV_get_whole_window
1496 * Return the X window associated with the full area of a window
1498 Window X11DRV_get_whole_window( HWND hwnd )
1500 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1504 if (hwnd == GetDesktopWindow()) return root_window;
1505 return (Window)GetPropA( hwnd, whole_window_prop );
1507 return data->whole_window;
1511 /***********************************************************************
1512 * X11DRV_get_fbconfig_id
1514 * Return the GLXFBConfig ID of the drawable used by the window for
1515 * OpenGL rendering. This is 0 for windows without a pixel format set.
1517 XID X11DRV_get_fbconfig_id( HWND hwnd )
1519 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1521 if (!data) return (XID)GetPropA( hwnd, fbconfig_id_prop );
1522 return data->fbconfig_id;
1525 /***********************************************************************
1526 * X11DRV_get_gl_drawable
1528 * Return the GL drawable for this window.
1530 Drawable X11DRV_get_gl_drawable( HWND hwnd )
1532 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1534 if (!data) return (Drawable)GetPropA( hwnd, gl_drawable_prop );
1535 return data->gl_drawable;
1538 /***********************************************************************
1539 * X11DRV_get_gl_pixmap
1541 * Return the Pixmap associated with the GL drawable (if any) for this window.
1543 Pixmap X11DRV_get_gl_pixmap( HWND hwnd )
1545 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1547 if (!data) return (Pixmap)GetPropA( hwnd, pixmap_prop );
1548 return data->pixmap;
1552 /***********************************************************************
1555 * Return the X input context associated with a window
1557 XIC X11DRV_get_ic( HWND hwnd )
1559 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1561 if (!data) return 0;
1566 /*****************************************************************
1567 * SetParent (X11DRV.@)
1569 void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
1571 Display *display = thread_display();
1572 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1575 if (parent == old_parent) return;
1577 if (parent != GetDesktopWindow()) /* a child window */
1579 if (old_parent == GetDesktopWindow())
1581 /* destroy the old X windows */
1582 destroy_whole_window( display, data );
1583 destroy_icon_window( display, data );
1586 data->managed = FALSE;
1587 RemovePropA( data->hwnd, managed_prop );
1591 else /* new top level window */
1593 /* FIXME: we ignore errors since we can't really recover anyway */
1594 create_whole_window( display, data );
1599 /*****************************************************************
1600 * SetFocus (X11DRV.@)
1603 * Explicit colormap management seems to work only with OLVWM.
1605 void X11DRV_SetFocus( HWND hwnd )
1607 Display *display = thread_display();
1608 struct x11drv_win_data *data;
1609 XWindowAttributes win_attr;
1611 /* Only mess with the X focus if there's */
1612 /* no desktop window and if the window is not managed by the WM. */
1613 if (root_window != DefaultRootWindow(display)) return;
1615 if (!hwnd) /* If setting the focus to 0, uninstall the colormap */
1618 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1619 XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1620 wine_tsx11_unlock();
1624 hwnd = GetAncestor( hwnd, GA_ROOT );
1626 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1627 if (data->managed || !data->whole_window) return;
1629 /* Set X focus and install colormap */
1631 if (XGetWindowAttributes( display, data->whole_window, &win_attr ) &&
1632 (win_attr.map_state == IsViewable))
1634 /* If window is not viewable, don't change anything */
1636 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1637 /* FIXME: this is not entirely correct */
1638 XSetInputFocus( display, data->whole_window, RevertToParent,
1640 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1641 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1642 XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1644 wine_tsx11_unlock();
1648 /**********************************************************************
1649 * SetWindowIcon (X11DRV.@)
1651 * hIcon or hIconSm has changed (or is being initialised for the
1652 * first time). Complete the X11 driver-specific initialisation
1653 * and set the window hints.
1655 * This is not entirely correct, may need to create
1656 * an icon window and set the pixmap as a background
1658 void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
1660 Display *display = thread_display();
1661 struct x11drv_win_data *data;
1663 if (type != ICON_BIG) return; /* nothing to do here */
1665 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1666 if (!data->whole_window) return;
1667 if (!data->managed) return;
1671 set_icon_hints( display, data, icon );
1673 XSetWMHints( display, data->whole_window, data->wm_hints );
1674 wine_tsx11_unlock();
1679 /***********************************************************************
1680 * SetWindowRgn (X11DRV.@)
1682 * Assign specified region to window (for non-rectangular windows)
1684 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1686 struct x11drv_win_data *data;
1688 if ((data = X11DRV_get_win_data( hwnd )))
1690 sync_window_region( thread_display(), data, hrgn );
1691 invalidate_dce( hwnd, &data->window_rect );
1693 else if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
1695 FIXME( "not supported on other thread window %p\n", hwnd );
1696 SetLastError( ERROR_INVALID_WINDOW_HANDLE );