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 client_window_prop[]= "__wine_x11_client_window";
62 static const char icon_window_prop[] = "__wine_x11_icon_window";
63 static const char fbconfig_id_prop[] = "__wine_x11_fbconfig_id";
64 static const char gl_drawable_prop[] = "__wine_x11_gl_drawable";
65 static const char pixmap_prop[] = "__wine_x11_pixmap";
66 static const char managed_prop[] = "__wine_x11_managed";
67 static const char visual_id_prop[] = "__wine_x11_visual_id";
69 /* for XDG systray icons */
70 #define SYSTEM_TRAY_REQUEST_DOCK 0
72 extern int usexcomposite;
74 /***********************************************************************
77 * Check if a given window should be managed
79 BOOL is_window_managed( HWND hwnd, UINT swp_flags, const RECT *window_rect )
81 DWORD style, ex_style;
83 if (!managed_mode) return FALSE;
85 /* child windows are not managed */
86 style = GetWindowLongW( hwnd, GWL_STYLE );
87 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD) return FALSE;
88 /* activated windows are managed */
89 if (!(swp_flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) return TRUE;
90 if (hwnd == GetActiveWindow()) return TRUE;
91 /* windows with caption are managed */
92 if ((style & WS_CAPTION) == WS_CAPTION) return TRUE;
93 /* tool windows are not managed */
94 ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE );
95 if (ex_style & WS_EX_TOOLWINDOW) return FALSE;
96 /* windows with thick frame are managed */
97 if (style & WS_THICKFRAME) return TRUE;
98 /* application windows are managed */
99 if (ex_style & WS_EX_APPWINDOW) return TRUE;
100 if (style & WS_POPUP)
102 /* popup with sysmenu == caption are managed */
103 if (style & WS_SYSMENU) return TRUE;
104 /* full-screen popup windows are managed */
105 if ((window_rect->right - window_rect->left) == screen_width &&
106 (window_rect->bottom - window_rect->top) == screen_height)
109 /* default: not managed */
114 /***********************************************************************
115 * X11DRV_is_window_rect_mapped
117 * Check if the X whole window should be mapped based on its rectangle
119 BOOL X11DRV_is_window_rect_mapped( const RECT *rect )
121 /* don't map if rect is empty */
122 if (IsRectEmpty( rect )) return FALSE;
124 /* don't map if rect is off-screen */
125 if (rect->left >= virtual_screen_rect.right ||
126 rect->top >= virtual_screen_rect.bottom ||
127 rect->right <= virtual_screen_rect.left ||
128 rect->bottom <= virtual_screen_rect.top)
135 /***********************************************************************
136 * get_mwm_decorations
138 static unsigned long get_mwm_decorations( DWORD style, DWORD ex_style )
140 unsigned long ret = 0;
142 if (ex_style & WS_EX_TOOLWINDOW) return 0;
144 if ((style & WS_CAPTION) == WS_CAPTION)
146 ret |= MWM_DECOR_TITLE | MWM_DECOR_BORDER;
147 if (style & WS_SYSMENU) ret |= MWM_DECOR_MENU;
148 if (style & WS_MINIMIZEBOX) ret |= MWM_DECOR_MINIMIZE;
149 if (style & WS_MAXIMIZEBOX) ret |= MWM_DECOR_MAXIMIZE;
151 if (ex_style & WS_EX_DLGMODALFRAME) ret |= MWM_DECOR_BORDER;
152 else if (style & WS_THICKFRAME) ret |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
153 else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) ret |= MWM_DECOR_BORDER;
158 /***********************************************************************
159 * get_x11_rect_offset
161 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
163 static void get_x11_rect_offset( struct x11drv_win_data *data, RECT *rect )
165 DWORD style, ex_style, style_mask = 0, ex_style_mask = 0;
168 rect->top = rect->bottom = rect->left = rect->right = 0;
170 style = GetWindowLongW( data->hwnd, GWL_STYLE );
171 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
172 decor = get_mwm_decorations( style, ex_style );
174 if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION;
175 if (decor & MWM_DECOR_BORDER)
177 style_mask |= WS_DLGFRAME | WS_THICKFRAME;
178 ex_style_mask |= WS_EX_DLGMODALFRAME;
181 AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask );
185 /***********************************************************************
186 * get_window_attributes
188 * Fill the window attributes structure for an X window.
190 static int get_window_attributes( Display *display, struct x11drv_win_data *data,
191 XSetWindowAttributes *attr )
193 attr->override_redirect = !data->managed;
194 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
195 attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0);
196 attr->cursor = x11drv_thread_data()->cursor;
197 attr->bit_gravity = NorthWestGravity;
198 attr->backing_store = NotUseful;
199 attr->event_mask = (ExposureMask | PointerMotionMask |
200 ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
201 KeyPressMask | KeyReleaseMask | FocusChangeMask | KeymapStateMask);
202 if (data->managed) attr->event_mask |= StructureNotifyMask;
204 return (CWOverrideRedirect | CWSaveUnder | CWColormap | CWCursor |
205 CWEventMask | CWBitGravity | CWBackingStore);
209 /***********************************************************************
210 * X11DRV_sync_window_style
212 * Change the X window attributes when the window style has changed.
214 void X11DRV_sync_window_style( Display *display, struct x11drv_win_data *data )
216 if (data->whole_window != root_window)
218 XSetWindowAttributes attr;
219 int mask = get_window_attributes( display, data, &attr );
222 XChangeWindowAttributes( display, data->whole_window, mask, &attr );
228 /***********************************************************************
231 * Update the X11 window region.
233 static void sync_window_region( Display *display, struct x11drv_win_data *data, HRGN hrgn )
235 #ifdef HAVE_LIBXSHAPE
236 if (!data->whole_window) return;
241 XShapeCombineMask( display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet );
246 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
250 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
251 data->window_rect.left - data->whole_rect.left,
252 data->window_rect.top - data->whole_rect.top,
253 (XRectangle *)pRegionData->Buffer,
254 pRegionData->rdh.nCount, ShapeSet, YXBanded );
256 HeapFree(GetProcessHeap(), 0, pRegionData);
259 #endif /* HAVE_LIBXSHAPE */
263 /***********************************************************************
266 static void sync_window_text( Display *display, Window win, const WCHAR *text )
269 char *buffer, *utf8_buffer;
272 /* allocate new buffer for window text */
273 count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
274 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) return;
275 WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
277 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
278 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
280 HeapFree( GetProcessHeap(), 0, buffer );
283 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
286 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
288 XSetWMName( display, win, &prop );
289 XSetWMIconName( display, win, &prop );
293 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
294 according to the standard
295 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
297 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
298 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
301 HeapFree( GetProcessHeap(), 0, utf8_buffer );
302 HeapFree( GetProcessHeap(), 0, buffer );
306 /***********************************************************************
307 * X11DRV_set_win_format
309 BOOL X11DRV_set_win_format( HWND hwnd, XID fbconfig_id )
311 Display *display = thread_display();
312 struct x11drv_win_data *data;
318 if (!(data = X11DRV_get_win_data(hwnd)) &&
319 !(data = X11DRV_create_win_data(hwnd))) return FALSE;
323 vis = visual_from_fbconfig_id(fbconfig_id);
330 if(data->whole_window && vis->visualid == XVisualIDFromVisual(visual))
332 TRACE("Whole window available and visual match, rendering onscreen\n");
338 parent = data->whole_window;
342 next_hwnd = GetAncestor(next_hwnd, GA_PARENT);
345 ERR("Could not find parent HWND with a drawable!\n");
348 parent = X11DRV_get_whole_window(next_hwnd);
351 w = data->client_rect.right - data->client_rect.left;
352 h = data->client_rect.bottom - data->client_rect.top;
358 #ifdef SONAME_LIBXCOMPOSITE
361 XSetWindowAttributes attrib;
363 attrib.override_redirect = True;
364 attrib.colormap = XCreateColormap(display, parent, vis->visual,
365 (vis->class == PseudoColor ||
366 vis->class == GrayScale ||
367 vis->class == DirectColor) ?
368 AllocAll : AllocNone);
369 XInstallColormap(gdi_display, attrib.colormap);
371 data->gl_drawable = XCreateWindow(display, parent, -w, 0, w, h, 0,
372 vis->depth, InputOutput, vis->visual,
373 CWColormap | CWOverrideRedirect,
375 if(data->gl_drawable)
377 pXCompositeRedirectWindow(display, data->gl_drawable,
378 CompositeRedirectManual);
379 XMapWindow(display, data->gl_drawable);
385 WARN("XComposite is not available, using GLXPixmap hack\n");
387 data->pixmap = XCreatePixmap(display, parent, w, h, vis->depth);
390 ERR("Failed to create pixmap for offscreen rendering\n");
396 data->gl_drawable = create_glxpixmap(display, vis, data->pixmap);
397 if(!data->gl_drawable)
399 XFreePixmap(display, data->pixmap);
404 if(!data->gl_drawable)
406 ERR("Failed to create drawable for offscreen rendering\n");
418 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
419 data->gl_drawable, fbconfig_id);
421 data->fbconfig_id = fbconfig_id;
422 SetPropA(hwnd, fbconfig_id_prop, (HANDLE)data->fbconfig_id);
423 SetPropA(hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
424 SetPropA(hwnd, pixmap_prop, (HANDLE)data->pixmap);
425 invalidate_dce( hwnd, &data->window_rect );
429 /***********************************************************************
432 static void sync_gl_drawable(Display *display, struct x11drv_win_data *data)
434 int w = data->client_rect.right - data->client_rect.left;
435 int h = data->client_rect.bottom - data->client_rect.top;
442 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data->gl_drawable, w, h);
443 #ifdef SONAME_LIBXCOMPOSITE
447 XMoveResizeWindow(display, data->gl_drawable, -w, 0, w, h);
453 parent = data->whole_window;
454 next_hwnd = data->hwnd;
457 next_hwnd = GetAncestor(next_hwnd, GA_PARENT);
460 ERR("Could not find parent HWND with a drawable!\n");
463 parent = X11DRV_get_whole_window(next_hwnd);
468 vis = visual_from_fbconfig_id(data->fbconfig_id);
475 pix = XCreatePixmap(display, parent, w, h, vis->depth);
478 ERR("Failed to create pixmap for offscreen rendering\n");
484 glxp = create_glxpixmap(display, vis, pix);
487 ERR("Failed to create drawable for offscreen rendering\n");
488 XFreePixmap(display, pix);
496 mark_drawable_dirty(data->gl_drawable, glxp);
498 XFreePixmap(display, data->pixmap);
499 destroy_glxpixmap(display, data->gl_drawable);
502 data->gl_drawable = glxp;
506 SetPropA(data->hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
507 SetPropA(data->hwnd, pixmap_prop, (HANDLE)data->pixmap);
508 invalidate_dce( data->hwnd, &data->window_rect );
512 /***********************************************************************
515 * fill the window changes structure
517 static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
521 if (old->right - old->left != new->right - new->left )
523 if ((changes->width = new->right - new->left) <= 0) changes->width = 1;
526 if (old->bottom - old->top != new->bottom - new->top)
528 if ((changes->height = new->bottom - new->top) <= 0) changes->height = 1;
531 if (old->left != new->left)
533 changes->x = new->left;
536 if (old->top != new->top)
538 changes->y = new->top;
545 /***********************************************************************
548 static Window create_icon_window( Display *display, struct x11drv_win_data *data )
550 XSetWindowAttributes attr;
552 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
553 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
554 attr.bit_gravity = NorthWestGravity;
555 attr.backing_store = NotUseful/*WhenMapped*/;
556 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
559 data->icon_window = XCreateWindow( display, root_window, 0, 0,
560 GetSystemMetrics( SM_CXICON ),
561 GetSystemMetrics( SM_CYICON ),
564 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
565 XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd );
568 TRACE( "created %lx\n", data->icon_window );
569 SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window );
570 return data->icon_window;
575 /***********************************************************************
576 * destroy_icon_window
578 static void destroy_icon_window( Display *display, struct x11drv_win_data *data )
580 if (!data->icon_window) return;
581 if (x11drv_thread_data()->cursor_window == data->icon_window)
582 x11drv_thread_data()->cursor_window = None;
584 XDeleteContext( display, data->icon_window, winContext );
585 XDestroyWindow( display, data->icon_window );
586 data->icon_window = 0;
588 RemovePropA( data->hwnd, icon_window_prop );
592 /***********************************************************************
595 * Set the icon wm hints
597 static void set_icon_hints( Display *display, struct x11drv_win_data *data, HICON hIcon )
599 XWMHints *hints = data->wm_hints;
601 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
602 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
603 data->hWMIconBitmap = 0;
604 data->hWMIconMask = 0;
608 if (!data->icon_window) create_icon_window( display, data );
609 hints->icon_window = data->icon_window;
610 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
620 GetIconInfo(hIcon, &ii);
622 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
625 rcMask.right = bmMask.bmWidth;
626 rcMask.bottom = bmMask.bmHeight;
628 hDC = CreateCompatibleDC(0);
629 hbmOrig = SelectObject(hDC, ii.hbmMask);
630 InvertRect(hDC, &rcMask);
631 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
632 SelectObject(hDC, hbmOrig);
635 data->hWMIconBitmap = ii.hbmColor;
636 data->hWMIconMask = ii.hbmMask;
638 hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap);
639 hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask);
640 destroy_icon_window( display, data );
641 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
645 /***********************************************************************
646 * wine_make_systray_window (X11DRV.@)
648 * Docks the given X window with the NETWM system tray.
650 void X11DRV_make_systray_window( HWND hwnd )
652 static Atom systray_atom;
653 Display *display = thread_display();
654 struct x11drv_win_data *data;
655 Window systray_window;
657 if (!(data = X11DRV_get_win_data( hwnd )) &&
658 !(data = X11DRV_create_win_data( hwnd ))) return;
663 if (DefaultScreen( display ) == 0)
664 systray_atom = x11drv_atom(_NET_SYSTEM_TRAY_S0);
667 char systray_buffer[29]; /* strlen(_NET_SYSTEM_TRAY_S4294967295)+1 */
668 sprintf( systray_buffer, "_NET_SYSTEM_TRAY_S%u", DefaultScreen( display ) );
669 systray_atom = XInternAtom( display, systray_buffer, False );
672 systray_window = XGetSelectionOwner( display, systray_atom );
675 TRACE("Docking tray icon %p\n", data->hwnd);
677 if (systray_window != None)
680 unsigned long info[2];
682 /* Put the window offscreen so it isn't mapped. The window _cannot_ be
683 * mapped if we intend to dock with an XEMBED tray. If the window is
684 * mapped when we dock, it may become visible as a child of the root
685 * window after it docks, which isn't the proper behavior.
687 * For more information on this problem, see
688 * http://standards.freedesktop.org/xembed-spec/latest/ar01s04.html */
690 SetWindowPos( data->hwnd, NULL, virtual_screen_rect.right + 1, virtual_screen_rect.bottom + 1,
691 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE );
693 /* set XEMBED protocol data on the window */
694 info[0] = 0; /* protocol version */
695 info[1] = 1; /* mapped = true */
698 XChangeProperty( display, data->whole_window,
699 x11drv_atom(_XEMBED_INFO),
700 x11drv_atom(_XEMBED_INFO), 32, PropModeReplace,
701 (unsigned char*)info, 2 );
704 /* send the docking request message */
705 ZeroMemory( &ev, sizeof(ev) );
706 ev.xclient.type = ClientMessage;
707 ev.xclient.window = systray_window;
708 ev.xclient.message_type = x11drv_atom( _NET_SYSTEM_TRAY_OPCODE );
709 ev.xclient.format = 32;
710 ev.xclient.data.l[0] = CurrentTime;
711 ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
712 ev.xclient.data.l[2] = data->whole_window;
713 ev.xclient.data.l[3] = 0;
714 ev.xclient.data.l[4] = 0;
717 XSendEvent( display, systray_window, False, NoEventMask, &ev );
725 /* fall back to he KDE hints if the WM doesn't support XEMBED'ed
729 XChangeProperty( display, data->whole_window,
730 x11drv_atom(KWM_DOCKWINDOW),
731 x11drv_atom(KWM_DOCKWINDOW), 32, PropModeReplace,
732 (unsigned char*)&val, 1 );
733 XChangeProperty( display, data->whole_window,
734 x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR),
735 XA_WINDOW, 32, PropModeReplace,
736 (unsigned char*)&data->whole_window, 1 );
742 /***********************************************************************
745 * set the window size hints
747 static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style )
749 XSizeHints* size_hints;
751 if ((size_hints = XAllocSizeHints()))
753 size_hints->flags = 0;
755 if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */
757 size_hints->win_gravity = StaticGravity;
758 size_hints->x = data->whole_rect.left;
759 size_hints->y = data->whole_rect.top;
760 size_hints->flags |= PWinGravity | PPosition;
763 if ( !(style & WS_THICKFRAME) )
765 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
766 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
767 size_hints->min_width = size_hints->max_width;
768 size_hints->min_height = size_hints->max_height;
769 size_hints->flags |= PMinSize | PMaxSize;
771 XSetWMNormalHints( display, data->whole_window, size_hints );
777 /***********************************************************************
780 * get the name of the current process for setting class hints
782 static char *get_process_name(void)
788 WCHAR module[MAX_PATH];
789 DWORD len = GetModuleFileNameW( 0, module, MAX_PATH );
790 if (len && len < MAX_PATH)
793 WCHAR *p, *appname = module;
795 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
796 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
797 len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL );
798 if ((ptr = HeapAlloc( GetProcessHeap(), 0, len )))
800 WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL );
809 /***********************************************************************
810 * set_initial_wm_hints
812 * Set the window manager hints that don't change over the lifetime of a window.
814 static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data )
819 XClassHint *class_hints;
820 char *process_name = get_process_name();
826 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
827 protocols[i++] = x11drv_atom(_NET_WM_PING);
828 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
829 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
830 XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
833 if ((class_hints = XAllocClassHint()))
835 static char wine[] = "Wine";
837 class_hints->res_name = process_name;
838 class_hints->res_class = wine;
839 XSetClassHint( display, data->whole_window, class_hints );
840 XFree( class_hints );
843 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
844 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
845 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
847 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
848 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
850 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
851 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
853 data->wm_hints = XAllocWMHints();
858 HICON icon = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 );
859 if (!icon) icon = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON );
860 data->wm_hints->flags = 0;
861 set_icon_hints( display, data, icon );
866 /***********************************************************************
867 * X11DRV_set_wm_hints
869 * Set the window manager hints for a newly-created window
871 void X11DRV_set_wm_hints( Display *display, struct x11drv_win_data *data )
876 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
877 DWORD ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
878 HWND owner = GetWindow( data->hwnd, GW_OWNER );
880 if (data->hwnd == GetDesktopWindow())
882 /* force some styles for the desktop to get the correct decorations */
883 style |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
887 /* transient for hint */
890 Window owner_win = X11DRV_get_whole_window( owner );
892 XSetTransientForHint( display, data->whole_window, owner_win );
894 group_leader = owner_win;
896 else group_leader = data->whole_window;
901 set_size_hints( display, data, style );
903 /* set the WM_WINDOW_TYPE */
904 window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
905 if (ex_style & WS_EX_TOOLWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
906 else if (style & WS_THICKFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
907 else if (style & WS_DLGFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
908 else if (ex_style & WS_EX_DLGMODALFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
910 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
911 XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1);
913 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
914 mwm_hints.decorations = get_mwm_decorations( style, ex_style );
915 mwm_hints.functions = MWM_FUNC_MOVE;
916 if (style & WS_THICKFRAME) mwm_hints.functions |= MWM_FUNC_RESIZE;
917 if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
918 if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
919 if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
921 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
922 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
923 (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
928 data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint;
929 data->wm_hints->input = !(style & WS_DISABLED);
930 data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
931 data->wm_hints->window_group = group_leader;
932 XSetWMHints( display, data->whole_window, data->wm_hints );
939 /***********************************************************************
940 * X11DRV_set_iconic_state
942 * Set the X11 iconic state according to the window style.
944 void X11DRV_set_iconic_state( HWND hwnd )
946 Display *display = thread_display();
947 struct x11drv_win_data *data;
949 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
950 BOOL iconic = (style & WS_MINIMIZE) != 0;
952 if (!(data = X11DRV_get_win_data( hwnd ))) return;
953 if (!data->whole_window) return;
955 GetWindowRect( hwnd, &rect );
961 data->wm_hints->flags |= StateHint | IconPositionHint;
962 data->wm_hints->initial_state = iconic ? IconicState : NormalState;
963 data->wm_hints->icon_x = rect.left - virtual_screen_rect.left;
964 data->wm_hints->icon_y = rect.top - virtual_screen_rect.top;
965 XSetWMHints( display, data->whole_window, data->wm_hints );
971 XIconifyWindow( display, data->whole_window, DefaultScreen(display) );
973 if (X11DRV_is_window_rect_mapped( &rect ))
974 XMapWindow( display, data->whole_window );
981 /***********************************************************************
982 * X11DRV_window_to_X_rect
984 * Convert a rect from client to X window coordinates
986 void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect )
990 if (!data->managed) return;
991 if (IsRectEmpty( rect )) return;
993 get_x11_rect_offset( data, &rc );
995 rect->left -= rc.left;
996 rect->right -= rc.right;
998 rect->bottom -= rc.bottom;
999 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1000 if (rect->left >= rect->right) rect->right = rect->left + 1;
1004 /***********************************************************************
1005 * X11DRV_X_to_window_rect
1007 * Opposite of X11DRV_window_to_X_rect
1009 void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect )
1013 if (!data->managed) return;
1014 if (IsRectEmpty( rect )) return;
1016 get_x11_rect_offset( data, &rc );
1018 rect->left += rc.left;
1019 rect->right += rc.right;
1020 rect->top += rc.top;
1021 rect->bottom += rc.bottom;
1022 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1023 if (rect->left >= rect->right) rect->right = rect->left + 1;
1027 /***********************************************************************
1028 * X11DRV_sync_window_position
1030 * Synchronize the X window position with the Windows one
1032 void X11DRV_sync_window_position( Display *display, struct x11drv_win_data *data,
1033 UINT swp_flags, const RECT *old_client_rect,
1034 const RECT *old_whole_rect )
1036 XWindowChanges changes;
1037 int mask = get_window_changes( &changes, old_whole_rect, &data->whole_rect );
1039 if (!(swp_flags & SWP_NOZORDER))
1041 /* find window that this one must be after */
1042 HWND prev = GetWindow( data->hwnd, GW_HWNDPREV );
1043 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
1044 prev = GetWindow( prev, GW_HWNDPREV );
1045 if (!prev) /* top child */
1047 changes.stack_mode = Above;
1048 mask |= CWStackMode;
1052 /* should use stack_mode Below but most window managers don't get it right */
1053 /* so move it above the next one in Z order */
1054 HWND next = GetWindow( data->hwnd, GW_HWNDNEXT );
1055 while (next && !(GetWindowLongW( next, GWL_STYLE ) & WS_VISIBLE))
1056 next = GetWindow( next, GW_HWNDNEXT );
1059 changes.stack_mode = Above;
1060 changes.sibling = X11DRV_get_whole_window(next);
1061 mask |= CWStackMode | CWSibling;
1066 /* only the size is allowed to change for the desktop window */
1067 if (data->whole_window == root_window) mask &= CWWidth | CWHeight;
1071 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
1073 TRACE( "setting win %lx pos %d,%d,%dx%d after %lx changes=%x\n",
1074 data->whole_window, data->whole_rect.left, data->whole_rect.top,
1075 data->whole_rect.right - data->whole_rect.left,
1076 data->whole_rect.bottom - data->whole_rect.top, changes.sibling, mask );
1079 if (mask & (CWWidth|CWHeight)) set_size_hints( display, data, style );
1080 if (mask & CWX) changes.x -= virtual_screen_rect.left;
1081 if (mask & CWY) changes.y -= virtual_screen_rect.top;
1082 XReconfigureWMWindow( display, data->whole_window,
1083 DefaultScreen(display), mask, &changes );
1084 wine_tsx11_unlock();
1089 /***********************************************************************
1090 * X11DRV_sync_client_position
1092 * Synchronize the X client window position with the Windows one
1094 void X11DRV_sync_client_position( Display *display, struct x11drv_win_data *data,
1095 UINT swp_flags, const RECT *old_client_rect,
1096 const RECT *old_whole_rect )
1099 XWindowChanges changes;
1100 RECT old = *old_client_rect;
1101 RECT new = data->client_rect;
1103 OffsetRect( &old, -old_whole_rect->left, -old_whole_rect->top );
1104 OffsetRect( &new, -data->whole_rect.left, -data->whole_rect.top );
1105 if (!(mask = get_window_changes( &changes, &old, &new ))) return;
1107 if (data->client_window)
1109 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1110 data->client_window, new.left, new.top,
1111 new.right - new.left, new.bottom - new.top, mask );
1113 XConfigureWindow( display, data->client_window, mask, &changes );
1114 wine_tsx11_unlock();
1117 if (data->gl_drawable && (mask & (CWWidth|CWHeight))) sync_gl_drawable( display, data );
1119 /* make sure the changes get to the server before we start painting */
1120 if (data->client_window || data->gl_drawable)
1124 wine_tsx11_unlock();
1129 /**********************************************************************
1130 * create_whole_window
1132 * Create the whole X window for a given window
1134 static Window create_whole_window( Display *display, struct x11drv_win_data *data )
1137 XSetWindowAttributes attr;
1142 if (!(cx = data->window_rect.right - data->window_rect.left)) cx = 1;
1143 if (!(cy = data->window_rect.bottom - data->window_rect.top)) cy = 1;
1145 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1147 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1148 data->managed = TRUE;
1149 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1152 mask = get_window_attributes( display, data, &attr );
1156 data->whole_rect = data->window_rect;
1157 data->whole_window = XCreateWindow( display, root_window,
1158 data->window_rect.left - virtual_screen_rect.left,
1159 data->window_rect.top - virtual_screen_rect.top,
1160 cx, cy, 0, screen_depth, InputOutput,
1161 visual, mask, &attr );
1163 if (!data->whole_window)
1165 wine_tsx11_unlock();
1169 attr.bit_gravity = NorthWestGravity;
1170 attr.win_gravity = NorthWestGravity;
1171 attr.backing_store = NotUseful;
1172 attr.event_mask = (ExposureMask | PointerMotionMask |
1173 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
1174 mask = CWEventMask | CWBitGravity | CWWinGravity | CWBackingStore;
1176 if ((cx = data->client_rect.right - data->client_rect.left) <= 0) cx = 1;
1177 if ((cy = data->client_rect.bottom - data->client_rect.top) <= 0) cy = 1;
1179 data->client_window = XCreateWindow( display, data->whole_window,
1180 data->client_rect.left - data->window_rect.left,
1181 data->client_rect.top - data->window_rect.top,
1182 cx, cy, 0, screen_depth, InputOutput,
1183 visual, mask, &attr );
1184 if (!data->client_window)
1186 XDestroyWindow( display, data->whole_window );
1187 data->whole_window = 0;
1188 wine_tsx11_unlock();
1192 XMapWindow( display, data->client_window );
1193 XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
1194 XSaveContext( display, data->client_window, winContext, (char *)data->hwnd );
1195 wine_tsx11_unlock();
1197 xim = x11drv_thread_data()->xim;
1198 if (xim) data->xic = X11DRV_CreateIC( xim, display, data->whole_window );
1200 set_initial_wm_hints( display, data );
1201 X11DRV_set_wm_hints( display, data );
1203 SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
1204 SetPropA( data->hwnd, client_window_prop, (HANDLE)data->client_window );
1206 /* set the window text */
1207 if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
1208 sync_window_text( display, data->whole_window, text );
1210 /* set the window region */
1211 if ((hrgn = CreateRectRgn( 0, 0, 0, 0 )))
1213 if (GetWindowRgn( data->hwnd, hrgn ) != ERROR) sync_window_region( display, data, hrgn );
1214 DeleteObject( hrgn );
1216 return data->whole_window;
1220 /**********************************************************************
1221 * destroy_whole_window
1223 * Destroy the whole X window for a given window.
1225 static void destroy_whole_window( Display *display, struct x11drv_win_data *data )
1227 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1229 if (!data->whole_window) return;
1231 TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1232 if (thread_data->cursor_window == data->whole_window ||
1233 thread_data->cursor_window == data->client_window)
1234 thread_data->cursor_window = None;
1236 XDeleteContext( display, data->whole_window, winContext );
1237 XDeleteContext( display, data->client_window, winContext );
1238 XDestroyWindow( display, data->whole_window );
1239 data->whole_window = data->client_window = 0;
1242 XUnsetICFocus( data->xic );
1243 XDestroyIC( data->xic );
1245 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1247 XFree( data->wm_hints );
1248 data->wm_hints = NULL;
1249 wine_tsx11_unlock();
1250 RemovePropA( data->hwnd, whole_window_prop );
1251 RemovePropA( data->hwnd, client_window_prop );
1255 /*****************************************************************
1256 * SetWindowText (X11DRV.@)
1258 void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
1260 Display *display = thread_display();
1263 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display))
1264 sync_window_text( display, win, text );
1268 /***********************************************************************
1269 * DestroyWindow (X11DRV.@)
1271 void X11DRV_DestroyWindow( HWND hwnd )
1273 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1274 Display *display = thread_data->display;
1275 struct x11drv_win_data *data;
1277 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1281 destroy_glxpixmap(display, data->gl_drawable);
1283 XFreePixmap(display, data->pixmap);
1284 wine_tsx11_unlock();
1286 else if (data->gl_drawable)
1289 XDestroyWindow(display, data->gl_drawable);
1290 wine_tsx11_unlock();
1293 free_window_dce( data );
1294 destroy_whole_window( display, data );
1295 destroy_icon_window( display, data );
1297 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
1298 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
1299 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
1301 XDeleteContext( display, (XID)hwnd, win_data_context );
1302 wine_tsx11_unlock();
1303 HeapFree( GetProcessHeap(), 0, data );
1307 static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
1309 struct x11drv_win_data *data;
1311 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
1315 if (!winContext) winContext = XUniqueContext();
1316 if (!win_data_context) win_data_context = XUniqueContext();
1317 XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
1318 wine_tsx11_unlock();
1324 /* initialize the desktop window id in the desktop manager process */
1325 static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd )
1327 struct x11drv_win_data *data;
1330 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1332 visualid = XVisualIDFromVisual(visual);
1333 wine_tsx11_unlock();
1334 data->whole_window = data->client_window = root_window;
1335 data->managed = TRUE;
1336 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1337 SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
1338 SetPropA( data->hwnd, client_window_prop, (HANDLE)root_window );
1339 SetPropA( data->hwnd, visual_id_prop, (HANDLE)visualid );
1340 set_initial_wm_hints( display, data );
1344 /**********************************************************************
1345 * CreateDesktopWindow (X11DRV.@)
1347 BOOL X11DRV_CreateDesktopWindow( HWND hwnd )
1349 unsigned int width, height;
1351 /* retrieve the real size of the desktop */
1352 SERVER_START_REQ( get_window_rectangles )
1355 wine_server_call( req );
1356 width = reply->window.right - reply->window.left;
1357 height = reply->window.bottom - reply->window.top;
1361 if (!width && !height) /* not initialized yet */
1363 SERVER_START_REQ( set_window_pos )
1367 req->flags = SWP_NOZORDER;
1368 req->window.left = virtual_screen_rect.left;
1369 req->window.top = virtual_screen_rect.top;
1370 req->window.right = virtual_screen_rect.right;
1371 req->window.bottom = virtual_screen_rect.bottom;
1372 req->client = req->window;
1373 wine_server_call( req );
1379 Window win = (Window)GetPropA( hwnd, whole_window_prop );
1380 if (win && win != root_window) X11DRV_init_desktop( win, width, height );
1386 /**********************************************************************
1387 * CreateWindow (X11DRV.@)
1389 BOOL X11DRV_CreateWindow( HWND hwnd )
1391 Display *display = thread_display();
1394 if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( display ))
1396 /* the desktop win data can't be created lazily */
1397 if (!create_desktop_win_data( display, hwnd )) return FALSE;
1400 /* Show the window, maximizing or minimizing if needed */
1402 style = GetWindowLongW( hwnd, GWL_STYLE );
1403 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
1405 extern UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect ); /*FIXME*/
1408 UINT swFlag = (style & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE;
1409 WIN_SetStyle( hwnd, 0, WS_MAXIMIZE | WS_MINIMIZE );
1410 swFlag = WINPOS_MinMaximize( hwnd, swFlag, &newPos );
1412 swFlag |= SWP_FRAMECHANGED; /* Frame always gets changed */
1413 if (!(style & WS_VISIBLE) || (style & WS_CHILD) || GetActiveWindow()) swFlag |= SWP_NOACTIVATE;
1415 SetWindowPos( hwnd, 0, newPos.left, newPos.top,
1416 newPos.right, newPos.bottom, swFlag );
1423 /***********************************************************************
1424 * X11DRV_get_win_data
1426 * Return the X11 data structure associated with a window.
1428 struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1432 if (!hwnd || XFindContext( thread_display(), (XID)hwnd, win_data_context, &data )) data = NULL;
1433 return (struct x11drv_win_data *)data;
1437 /***********************************************************************
1438 * X11DRV_create_win_data
1440 * Create an X11 data window structure for an existing window.
1442 struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd )
1444 Display *display = thread_display();
1445 struct x11drv_win_data *data;
1448 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
1449 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1451 GetWindowRect( hwnd, &data->window_rect );
1452 MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 );
1453 data->whole_rect = data->window_rect;
1454 GetClientRect( hwnd, &data->client_rect );
1455 MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 );
1457 if (parent == GetDesktopWindow())
1459 if (!create_whole_window( display, data ))
1461 HeapFree( GetProcessHeap(), 0, data );
1464 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1465 hwnd, data->whole_window, data->client_window, wine_dbgstr_rect( &data->window_rect ),
1466 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
1469 /* get class or window DC if needed */
1470 alloc_window_dce( data );
1475 /***********************************************************************
1476 * X11DRV_get_whole_window
1478 * Return the X window associated with the full area of a window
1480 Window X11DRV_get_whole_window( HWND hwnd )
1482 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1486 if (hwnd == GetDesktopWindow()) return root_window;
1487 return (Window)GetPropA( hwnd, whole_window_prop );
1489 return data->whole_window;
1493 /***********************************************************************
1494 * X11DRV_get_client_window
1496 * Return the X window associated with the client area of a window
1498 Window X11DRV_get_client_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, client_window_prop );
1507 return data->client_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 XWindowChanges changes;
1611 /* If setting the focus to 0, uninstall the colormap */
1612 if (!hwnd && root_window == DefaultRootWindow(display))
1615 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1616 XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1617 wine_tsx11_unlock();
1621 hwnd = GetAncestor( hwnd, GA_ROOT );
1623 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1624 if (data->managed || !data->whole_window) return;
1626 /* Set X focus and install colormap */
1628 changes.stack_mode = Above;
1629 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
1630 if (root_window == DefaultRootWindow(display))
1632 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1633 /* FIXME: this is not entirely correct */
1634 XSetInputFocus( display, data->whole_window, RevertToParent,
1636 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1637 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1638 XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1640 wine_tsx11_unlock();
1644 /**********************************************************************
1645 * SetWindowIcon (X11DRV.@)
1647 * hIcon or hIconSm has changed (or is being initialised for the
1648 * first time). Complete the X11 driver-specific initialisation
1649 * and set the window hints.
1651 * This is not entirely correct, may need to create
1652 * an icon window and set the pixmap as a background
1654 void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
1656 Display *display = thread_display();
1657 struct x11drv_win_data *data;
1659 if (type != ICON_BIG) return; /* nothing to do here */
1661 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1662 if (!data->whole_window) return;
1663 if (!data->managed) return;
1667 set_icon_hints( display, data, icon );
1669 XSetWMHints( display, data->whole_window, data->wm_hints );
1670 wine_tsx11_unlock();
1675 /***********************************************************************
1676 * SetWindowRgn (X11DRV.@)
1678 * Assign specified region to window (for non-rectangular windows)
1680 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1682 struct x11drv_win_data *data;
1684 if ((data = X11DRV_get_win_data( hwnd )))
1686 sync_window_region( thread_display(), data, hrgn );
1687 invalidate_dce( hwnd, &data->window_rect );
1689 else if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
1691 FIXME( "not supported on other thread window %p\n", hwnd );
1692 SetLastError( ERROR_INVALID_WINDOW_HANDLE );