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"
51 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
53 /* X context to associate a hwnd to an X window */
54 XContext winContext
= 0;
56 /* X context to associate a struct x11drv_win_data to an hwnd */
57 static XContext win_data_context
;
59 static const char whole_window_prop
[] = "__wine_x11_whole_window";
60 static const char client_window_prop
[]= "__wine_x11_client_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";
67 /* for XDG systray icons */
68 #define SYSTEM_TRAY_REQUEST_DOCK 0
70 extern int usexcomposite
;
72 /***********************************************************************
75 * Check if a given window should be managed
77 BOOL
is_window_managed( HWND hwnd
, UINT swp_flags
, const RECT
*window_rect
)
79 DWORD style
, ex_style
;
81 if (!managed_mode
) return FALSE
;
83 /* child windows are not managed */
84 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
85 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) return FALSE
;
86 #ifndef DEFAULTMANAGED
87 /* set to 1 to enable default managed instead of default not managed */
88 #define DEFAULTMANAGED 0
91 /* activated windows are managed */
92 if (!(swp_flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
))) return TRUE
;
93 if (hwnd
== GetActiveWindow()) return TRUE
;
94 /* windows with caption are managed */
95 if ((style
& WS_CAPTION
) == WS_CAPTION
) return TRUE
;
96 /* tool windows are not managed */
97 ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
98 if (ex_style
& WS_EX_TOOLWINDOW
) return FALSE
;
99 /* windows with thick frame are managed */
100 if (style
& WS_THICKFRAME
) return TRUE
;
101 /* application windows are managed */
102 if (ex_style
& WS_EX_APPWINDOW
) return TRUE
;
104 if (style
& WS_POPUP
)
106 /* popup with sysmenu == caption are managed */
107 if (style
& WS_SYSMENU
) return TRUE
;
108 /* full-screen popup windows are managed */
109 if (window_rect
->left
<= 0 && window_rect
->right
>= screen_width
&&
110 window_rect
->top
<= 0 && window_rect
->bottom
>= screen_height
)
113 /* all other popups are not managed */
118 /* default: managed */
121 /* default: not managed */
128 /***********************************************************************
129 * X11DRV_is_window_rect_mapped
131 * Check if the X whole window should be mapped based on its rectangle
133 BOOL
X11DRV_is_window_rect_mapped( const RECT
*rect
)
135 /* don't map if rect is empty */
136 if (IsRectEmpty( rect
)) return FALSE
;
138 /* don't map if rect is off-screen */
139 if (rect
->left
>= virtual_screen_rect
.right
||
140 rect
->top
>= virtual_screen_rect
.bottom
||
141 rect
->right
<= virtual_screen_rect
.left
||
142 rect
->bottom
<= virtual_screen_rect
.top
)
149 /***********************************************************************
150 * get_mwm_decorations
152 static unsigned long get_mwm_decorations( DWORD style
, DWORD ex_style
)
154 unsigned long ret
= 0;
156 if (ex_style
& WS_EX_TOOLWINDOW
) return 0;
158 if ((style
& WS_CAPTION
) == WS_CAPTION
)
160 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
161 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
162 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
163 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
165 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
166 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
167 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
172 /***********************************************************************
173 * get_x11_rect_offset
175 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
177 static void get_x11_rect_offset( struct x11drv_win_data
*data
, RECT
*rect
)
179 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
182 rect
->top
= rect
->bottom
= rect
->left
= rect
->right
= 0;
184 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
185 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
186 decor
= get_mwm_decorations( style
, ex_style
);
188 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
189 if (decor
& MWM_DECOR_BORDER
)
191 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
192 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
195 AdjustWindowRectEx( rect
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
199 /***********************************************************************
200 * get_window_attributes
202 * Fill the window attributes structure for an X window.
204 static int get_window_attributes( Display
*display
, struct x11drv_win_data
*data
,
205 XSetWindowAttributes
*attr
)
207 attr
->override_redirect
= !data
->managed
;
208 attr
->colormap
= X11DRV_PALETTE_PaletteXColormap
;
209 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
210 attr
->cursor
= x11drv_thread_data()->cursor
;
211 attr
->bit_gravity
= NorthWestGravity
;
212 attr
->backing_store
= NotUseful
;
213 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
214 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
215 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
| KeymapStateMask
);
216 if (data
->managed
) attr
->event_mask
|= StructureNotifyMask
| PropertyChangeMask
;
218 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
| CWCursor
|
219 CWEventMask
| CWBitGravity
| CWBackingStore
);
223 /***********************************************************************
224 * create_client_window
226 static Window
create_client_window( Display
*display
, struct x11drv_win_data
*data
, XVisualInfo
*vis
)
229 XSetWindowAttributes attr
;
232 attr
.bit_gravity
= NorthWestGravity
;
233 attr
.win_gravity
= NorthWestGravity
;
234 attr
.backing_store
= NotUseful
;
235 attr
.event_mask
= (ExposureMask
| PointerMotionMask
|
236 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
237 mask
= CWEventMask
| CWBitGravity
| CWWinGravity
| CWBackingStore
;
239 if ((cx
= data
->client_rect
.right
- data
->client_rect
.left
) <= 0) cx
= 1;
240 if ((cy
= data
->client_rect
.bottom
- data
->client_rect
.top
) <= 0) cy
= 1;
246 attr
.colormap
= XCreateColormap( display
, root_window
, vis
->visual
,
247 (vis
->class == PseudoColor
|| vis
->class == GrayScale
||
248 vis
->class == DirectColor
) ? AllocAll
: AllocNone
);
252 client
= XCreateWindow( display
, data
->whole_window
,
253 data
->client_rect
.left
- data
->whole_rect
.left
,
254 data
->client_rect
.top
- data
->whole_rect
.top
,
255 cx
, cy
, 0, screen_depth
, InputOutput
,
256 vis
? vis
->visual
: visual
, mask
, &attr
);
263 if (data
->client_window
)
265 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
266 if (thread_data
->cursor_window
== data
->client_window
) thread_data
->cursor_window
= None
;
267 XDeleteContext( display
, data
->client_window
, winContext
);
268 XDestroyWindow( display
, data
->client_window
);
270 data
->client_window
= client
;
272 if (data
->colormap
) XFreeColormap( display
, data
->colormap
);
273 data
->colormap
= vis
? attr
.colormap
: 0;
275 XMapWindow( display
, data
->client_window
);
276 XSaveContext( display
, data
->client_window
, winContext
, (char *)data
->hwnd
);
279 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)data
->client_window
);
280 return data
->client_window
;
284 /***********************************************************************
285 * X11DRV_sync_window_style
287 * Change the X window attributes when the window style has changed.
289 void X11DRV_sync_window_style( Display
*display
, struct x11drv_win_data
*data
)
291 if (data
->whole_window
!= root_window
)
293 XSetWindowAttributes attr
;
294 int mask
= get_window_attributes( display
, data
, &attr
);
297 XChangeWindowAttributes( display
, data
->whole_window
, mask
, &attr
);
303 /***********************************************************************
306 * Update the X11 window region.
308 static void sync_window_region( Display
*display
, struct x11drv_win_data
*data
, HRGN hrgn
)
310 #ifdef HAVE_LIBXSHAPE
311 if (!data
->whole_window
) return;
316 XShapeCombineMask( display
, data
->whole_window
, ShapeBounding
, 0, 0, None
, ShapeSet
);
321 RGNDATA
*pRegionData
= X11DRV_GetRegionData( hrgn
, 0 );
325 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
326 data
->window_rect
.left
- data
->whole_rect
.left
,
327 data
->window_rect
.top
- data
->whole_rect
.top
,
328 (XRectangle
*)pRegionData
->Buffer
,
329 pRegionData
->rdh
.nCount
, ShapeSet
, YXBanded
);
331 HeapFree(GetProcessHeap(), 0, pRegionData
);
334 #endif /* HAVE_LIBXSHAPE */
338 /***********************************************************************
341 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
344 char *buffer
, *utf8_buffer
;
347 /* allocate new buffer for window text */
348 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
349 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
350 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
352 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
353 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
355 HeapFree( GetProcessHeap(), 0, buffer
);
358 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
361 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
363 XSetWMName( display
, win
, &prop
);
364 XSetWMIconName( display
, win
, &prop
);
368 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
369 according to the standard
370 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
372 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
373 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
376 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
377 HeapFree( GetProcessHeap(), 0, buffer
);
381 /***********************************************************************
382 * X11DRV_set_win_format
384 BOOL
X11DRV_set_win_format( HWND hwnd
, XID fbconfig_id
)
386 Display
*display
= thread_display();
387 struct x11drv_win_data
*data
;
391 if (!(data
= X11DRV_get_win_data(hwnd
)) &&
392 !(data
= X11DRV_create_win_data(hwnd
))) return FALSE
;
394 if (data
->fbconfig_id
) return FALSE
; /* can't change it twice */
397 vis
= visual_from_fbconfig_id(fbconfig_id
);
399 if (!vis
) return FALSE
;
401 if (data
->whole_window
)
403 Window client
= data
->client_window
;
405 if (vis
->visualid
!= XVisualIDFromVisual(visual
))
407 client
= create_client_window( display
, data
, vis
);
408 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client
, data
->hwnd
, fbconfig_id
);
413 if (client
) goto done
;
417 w
= data
->client_rect
.right
- data
->client_rect
.left
;
418 h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
423 #ifdef SONAME_LIBXCOMPOSITE
426 XSetWindowAttributes attrib
;
427 Window parent
= X11DRV_get_whole_window( GetAncestor( hwnd
, GA_ROOT
));
429 if (!parent
) parent
= root_window
;
431 data
->colormap
= XCreateColormap(display
, parent
, vis
->visual
,
432 (vis
->class == PseudoColor
||
433 vis
->class == GrayScale
||
434 vis
->class == DirectColor
) ?
435 AllocAll
: AllocNone
);
436 attrib
.override_redirect
= True
;
437 attrib
.colormap
= data
->colormap
;
438 XInstallColormap(gdi_display
, attrib
.colormap
);
440 data
->gl_drawable
= XCreateWindow(display
, parent
, -w
, 0, w
, h
, 0,
441 vis
->depth
, InputOutput
, vis
->visual
,
442 CWColormap
| CWOverrideRedirect
,
444 if(data
->gl_drawable
)
446 pXCompositeRedirectWindow(display
, data
->gl_drawable
,
447 CompositeRedirectManual
);
448 XMapWindow(display
, data
->gl_drawable
);
456 WARN("XComposite is not available, using GLXPixmap hack\n");
459 data
->pixmap
= XCreatePixmap(display
, root_window
, w
, h
, vis
->depth
);
467 data
->gl_drawable
= create_glxpixmap(display
, vis
, data
->pixmap
);
468 if(!data
->gl_drawable
)
470 XFreePixmap(display
, data
->pixmap
);
475 if (data
->pixmap
) SetPropA(hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
478 if (!data
->gl_drawable
) return FALSE
;
480 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
481 data
->gl_drawable
, fbconfig_id
);
482 SetPropA(hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
485 data
->fbconfig_id
= fbconfig_id
;
486 SetPropA(hwnd
, fbconfig_id_prop
, (HANDLE
)data
->fbconfig_id
);
490 WIN_invalidate_dce( hwnd
, NULL
);
494 /***********************************************************************
497 static void sync_gl_drawable(Display
*display
, struct x11drv_win_data
*data
)
499 int w
= data
->client_rect
.right
- data
->client_rect
.left
;
500 int h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
508 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
509 #ifdef SONAME_LIBXCOMPOSITE
513 XMoveResizeWindow(display
, data
->gl_drawable
, -w
, 0, w
, h
);
521 vis
= visual_from_fbconfig_id(data
->fbconfig_id
);
528 pix
= XCreatePixmap(display
, root_window
, w
, h
, vis
->depth
);
531 ERR("Failed to create pixmap for offscreen rendering\n");
537 glxp
= create_glxpixmap(display
, vis
, pix
);
540 ERR("Failed to create drawable for offscreen rendering\n");
541 XFreePixmap(display
, pix
);
549 mark_drawable_dirty(data
->gl_drawable
, glxp
);
551 XFreePixmap(display
, data
->pixmap
);
552 destroy_glxpixmap(display
, data
->gl_drawable
);
555 data
->gl_drawable
= glxp
;
559 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
560 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
564 /***********************************************************************
567 * fill the window changes structure
569 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
573 if (old
->right
- old
->left
!= new->right
- new->left
)
575 if ((changes
->width
= new->right
- new->left
) <= 0) changes
->width
= 1;
578 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
580 if ((changes
->height
= new->bottom
- new->top
) <= 0) changes
->height
= 1;
583 if (old
->left
!= new->left
)
585 changes
->x
= new->left
;
588 if (old
->top
!= new->top
)
590 changes
->y
= new->top
;
597 /***********************************************************************
600 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
602 XSetWindowAttributes attr
;
604 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
605 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
606 attr
.bit_gravity
= NorthWestGravity
;
607 attr
.backing_store
= NotUseful
/*WhenMapped*/;
608 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
611 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
612 GetSystemMetrics( SM_CXICON
),
613 GetSystemMetrics( SM_CYICON
),
616 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
617 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
620 TRACE( "created %lx\n", data
->icon_window
);
621 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
622 return data
->icon_window
;
627 /***********************************************************************
628 * destroy_icon_window
630 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
632 if (!data
->icon_window
) return;
633 if (x11drv_thread_data()->cursor_window
== data
->icon_window
)
634 x11drv_thread_data()->cursor_window
= None
;
636 XDeleteContext( display
, data
->icon_window
, winContext
);
637 XDestroyWindow( display
, data
->icon_window
);
638 data
->icon_window
= 0;
640 RemovePropA( data
->hwnd
, icon_window_prop
);
644 /***********************************************************************
647 * Set the icon wm hints
649 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
, HICON hIcon
)
651 XWMHints
*hints
= data
->wm_hints
;
653 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
654 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
655 data
->hWMIconBitmap
= 0;
656 data
->hWMIconMask
= 0;
660 if (!data
->icon_window
) create_icon_window( display
, data
);
661 hints
->icon_window
= data
->icon_window
;
662 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
672 GetIconInfo(hIcon
, &ii
);
674 GetObjectA(ii
.hbmMask
, sizeof(bmMask
), &bmMask
);
677 rcMask
.right
= bmMask
.bmWidth
;
678 rcMask
.bottom
= bmMask
.bmHeight
;
680 hDC
= CreateCompatibleDC(0);
681 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
682 InvertRect(hDC
, &rcMask
);
683 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
684 SelectObject(hDC
, hbmOrig
);
687 data
->hWMIconBitmap
= ii
.hbmColor
;
688 data
->hWMIconMask
= ii
.hbmMask
;
690 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
691 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
692 destroy_icon_window( display
, data
);
693 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
697 /***********************************************************************
698 * wine_make_systray_window (X11DRV.@)
700 * Docks the given X window with the NETWM system tray.
702 void X11DRV_make_systray_window( HWND hwnd
)
704 static Atom systray_atom
;
705 Display
*display
= thread_display();
706 struct x11drv_win_data
*data
;
707 Window systray_window
;
709 if (!(data
= X11DRV_get_win_data( hwnd
)) &&
710 !(data
= X11DRV_create_win_data( hwnd
))) return;
715 if (DefaultScreen( display
) == 0)
716 systray_atom
= x11drv_atom(_NET_SYSTEM_TRAY_S0
);
719 char systray_buffer
[29]; /* strlen(_NET_SYSTEM_TRAY_S4294967295)+1 */
720 sprintf( systray_buffer
, "_NET_SYSTEM_TRAY_S%u", DefaultScreen( display
) );
721 systray_atom
= XInternAtom( display
, systray_buffer
, False
);
724 systray_window
= XGetSelectionOwner( display
, systray_atom
);
727 TRACE("Docking tray icon %p\n", data
->hwnd
);
729 if (systray_window
!= None
)
732 unsigned long info
[2];
734 /* Put the window offscreen so it isn't mapped. The window _cannot_ be
735 * mapped if we intend to dock with an XEMBED tray. If the window is
736 * mapped when we dock, it may become visible as a child of the root
737 * window after it docks, which isn't the proper behavior.
739 * For more information on this problem, see
740 * http://standards.freedesktop.org/xembed-spec/latest/ar01s04.html */
742 SetWindowPos( data
->hwnd
, NULL
, virtual_screen_rect
.right
+ 1, virtual_screen_rect
.bottom
+ 1,
743 0, 0, SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
745 /* set XEMBED protocol data on the window */
746 info
[0] = 0; /* protocol version */
747 info
[1] = 1; /* mapped = true */
750 XChangeProperty( display
, data
->whole_window
,
751 x11drv_atom(_XEMBED_INFO
),
752 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
,
753 (unsigned char*)info
, 2 );
756 /* send the docking request message */
757 ZeroMemory( &ev
, sizeof(ev
) );
758 ev
.xclient
.type
= ClientMessage
;
759 ev
.xclient
.window
= systray_window
;
760 ev
.xclient
.message_type
= x11drv_atom( _NET_SYSTEM_TRAY_OPCODE
);
761 ev
.xclient
.format
= 32;
762 ev
.xclient
.data
.l
[0] = CurrentTime
;
763 ev
.xclient
.data
.l
[1] = SYSTEM_TRAY_REQUEST_DOCK
;
764 ev
.xclient
.data
.l
[2] = data
->whole_window
;
765 ev
.xclient
.data
.l
[3] = 0;
766 ev
.xclient
.data
.l
[4] = 0;
769 XSendEvent( display
, systray_window
, False
, NoEventMask
, &ev
);
777 /* fall back to he KDE hints if the WM doesn't support XEMBED'ed
781 XChangeProperty( display
, data
->whole_window
,
782 x11drv_atom(KWM_DOCKWINDOW
),
783 x11drv_atom(KWM_DOCKWINDOW
), 32, PropModeReplace
,
784 (unsigned char*)&val
, 1 );
785 XChangeProperty( display
, data
->whole_window
,
786 x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR
),
787 XA_WINDOW
, 32, PropModeReplace
,
788 (unsigned char*)&data
->whole_window
, 1 );
794 /***********************************************************************
797 * set the window size hints
799 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
801 XSizeHints
* size_hints
;
803 if ((size_hints
= XAllocSizeHints()))
805 size_hints
->flags
= 0;
807 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
809 size_hints
->win_gravity
= StaticGravity
;
810 size_hints
->x
= data
->whole_rect
.left
;
811 size_hints
->y
= data
->whole_rect
.top
;
812 size_hints
->flags
|= PWinGravity
| PPosition
;
815 if ( !(style
& WS_THICKFRAME
) )
817 /* If we restrict window resizing Metacity decides that it should
818 * disable fullscreen support for this window as well.
820 if (!(data
->whole_rect
.left
<= 0 && data
->whole_rect
.right
>= screen_width
&&
821 data
->whole_rect
.top
<= 0 && data
->whole_rect
.bottom
>= screen_height
))
823 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
824 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
825 size_hints
->min_width
= size_hints
->max_width
;
826 size_hints
->min_height
= size_hints
->max_height
;
827 size_hints
->flags
|= PMinSize
| PMaxSize
;
830 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
836 /***********************************************************************
839 * get the name of the current process for setting class hints
841 static char *get_process_name(void)
847 WCHAR module
[MAX_PATH
];
848 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
849 if (len
&& len
< MAX_PATH
)
852 WCHAR
*p
, *appname
= module
;
854 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
855 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
856 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
857 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
859 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
868 /***********************************************************************
869 * set_initial_wm_hints
871 * Set the window manager hints that don't change over the lifetime of a window.
873 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
878 XClassHint
*class_hints
;
879 char *process_name
= get_process_name();
885 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
886 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
887 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
888 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
889 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
892 if ((class_hints
= XAllocClassHint()))
894 static char wine
[] = "Wine";
896 class_hints
->res_name
= process_name
;
897 class_hints
->res_class
= wine
;
898 XSetClassHint( display
, data
->whole_window
, class_hints
);
899 XFree( class_hints
);
902 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
903 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
904 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
906 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
907 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
909 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
910 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
912 data
->wm_hints
= XAllocWMHints();
917 HICON icon
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_BIG
, 0 );
918 if (!icon
) icon
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
);
919 data
->wm_hints
->flags
= 0;
920 set_icon_hints( display
, data
, icon
);
925 /***********************************************************************
926 * X11DRV_set_wm_hints
928 * Set the window manager hints for a newly-created window
930 void X11DRV_set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
935 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
936 DWORD ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
937 HWND owner
= GetWindow( data
->hwnd
, GW_OWNER
);
939 if (data
->hwnd
== GetDesktopWindow())
941 /* force some styles for the desktop to get the correct decorations */
942 style
|= WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
946 /* transient for hint */
949 Window owner_win
= X11DRV_get_whole_window( owner
);
951 XSetTransientForHint( display
, data
->whole_window
, owner_win
);
953 group_leader
= owner_win
;
955 else group_leader
= data
->whole_window
;
960 set_size_hints( display
, data
, style
);
962 /* set the WM_WINDOW_TYPE */
963 window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
964 if (ex_style
& WS_EX_TOOLWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY
);
965 else if (style
& WS_THICKFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
966 else if (style
& WS_DLGFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
967 else if (ex_style
& WS_EX_DLGMODALFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
969 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
970 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
972 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
973 mwm_hints
.decorations
= get_mwm_decorations( style
, ex_style
);
974 mwm_hints
.functions
= MWM_FUNC_MOVE
;
975 if (style
& WS_THICKFRAME
) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
976 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
977 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
978 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
980 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
981 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
982 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
987 data
->wm_hints
->flags
|= InputHint
| StateHint
| WindowGroupHint
;
988 data
->wm_hints
->input
= !(style
& WS_DISABLED
);
989 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
990 data
->wm_hints
->window_group
= group_leader
;
991 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
998 /***********************************************************************
999 * X11DRV_window_to_X_rect
1001 * Convert a rect from client to X window coordinates
1003 void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1007 if (!data
->managed
) return;
1008 if (IsRectEmpty( rect
)) return;
1010 get_x11_rect_offset( data
, &rc
);
1012 rect
->left
-= rc
.left
;
1013 rect
->right
-= rc
.right
;
1014 rect
->top
-= rc
.top
;
1015 rect
->bottom
-= rc
.bottom
;
1016 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1017 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1021 /***********************************************************************
1022 * X11DRV_X_to_window_rect
1024 * Opposite of X11DRV_window_to_X_rect
1026 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1030 if (!data
->managed
) return;
1031 if (IsRectEmpty( rect
)) return;
1033 get_x11_rect_offset( data
, &rc
);
1035 rect
->left
+= rc
.left
;
1036 rect
->right
+= rc
.right
;
1037 rect
->top
+= rc
.top
;
1038 rect
->bottom
+= rc
.bottom
;
1039 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1040 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1044 /***********************************************************************
1045 * X11DRV_sync_window_position
1047 * Synchronize the X window position with the Windows one
1049 void X11DRV_sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
1050 UINT swp_flags
, const RECT
*old_client_rect
,
1051 const RECT
*old_whole_rect
)
1053 XWindowChanges changes
;
1054 int mask
= get_window_changes( &changes
, old_whole_rect
, &data
->whole_rect
);
1056 if (!(swp_flags
& SWP_NOZORDER
))
1058 /* find window that this one must be after */
1059 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
1060 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
1061 prev
= GetWindow( prev
, GW_HWNDPREV
);
1062 if (!prev
) /* top child */
1064 changes
.stack_mode
= Above
;
1065 mask
|= CWStackMode
;
1069 /* should use stack_mode Below but most window managers don't get it right */
1070 /* so move it above the next one in Z order */
1071 HWND next
= GetWindow( data
->hwnd
, GW_HWNDNEXT
);
1072 while (next
&& !(GetWindowLongW( next
, GWL_STYLE
) & WS_VISIBLE
))
1073 next
= GetWindow( next
, GW_HWNDNEXT
);
1076 changes
.stack_mode
= Above
;
1077 changes
.sibling
= X11DRV_get_whole_window(next
);
1078 mask
|= CWStackMode
| CWSibling
;
1083 /* only the size is allowed to change for the desktop window */
1084 if (data
->whole_window
== root_window
) mask
&= CWWidth
| CWHeight
;
1088 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1090 TRACE( "setting win %lx pos %d,%d,%dx%d after %lx changes=%x\n",
1091 data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1092 data
->whole_rect
.right
- data
->whole_rect
.left
,
1093 data
->whole_rect
.bottom
- data
->whole_rect
.top
, changes
.sibling
, mask
);
1096 if (mask
& (CWWidth
|CWHeight
)) set_size_hints( display
, data
, style
);
1097 if (mask
& CWX
) changes
.x
-= virtual_screen_rect
.left
;
1098 if (mask
& CWY
) changes
.y
-= virtual_screen_rect
.top
;
1099 XReconfigureWMWindow( display
, data
->whole_window
,
1100 DefaultScreen(display
), mask
, &changes
);
1101 wine_tsx11_unlock();
1106 /***********************************************************************
1107 * X11DRV_sync_client_position
1109 * Synchronize the X client window position with the Windows one
1111 void X11DRV_sync_client_position( Display
*display
, struct x11drv_win_data
*data
,
1112 UINT swp_flags
, const RECT
*old_client_rect
,
1113 const RECT
*old_whole_rect
)
1116 XWindowChanges changes
;
1117 RECT old
= *old_client_rect
;
1118 RECT
new = data
->client_rect
;
1120 OffsetRect( &old
, -old_whole_rect
->left
, -old_whole_rect
->top
);
1121 OffsetRect( &new, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
1122 if (!(mask
= get_window_changes( &changes
, &old
, &new ))) return;
1124 if (data
->client_window
)
1126 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1127 data
->client_window
, new.left
, new.top
,
1128 new.right
- new.left
, new.bottom
- new.top
, mask
);
1130 XConfigureWindow( display
, data
->client_window
, mask
, &changes
);
1131 wine_tsx11_unlock();
1134 if (data
->gl_drawable
&& (mask
& (CWWidth
|CWHeight
))) sync_gl_drawable( display
, data
);
1136 /* make sure the changes get to the server before we start painting */
1137 if (data
->client_window
|| data
->gl_drawable
)
1141 wine_tsx11_unlock();
1146 /**********************************************************************
1147 * create_whole_window
1149 * Create the whole X window for a given window
1151 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1154 XSetWindowAttributes attr
;
1159 if (!(cx
= data
->window_rect
.right
- data
->window_rect
.left
)) cx
= 1;
1160 if (!(cy
= data
->window_rect
.bottom
- data
->window_rect
.top
)) cy
= 1;
1162 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1164 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1165 data
->managed
= TRUE
;
1166 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1169 mask
= get_window_attributes( display
, data
, &attr
);
1173 data
->whole_rect
= data
->window_rect
;
1174 data
->whole_window
= XCreateWindow( display
, root_window
,
1175 data
->window_rect
.left
- virtual_screen_rect
.left
,
1176 data
->window_rect
.top
- virtual_screen_rect
.top
,
1177 cx
, cy
, 0, screen_depth
, InputOutput
,
1178 visual
, mask
, &attr
);
1180 if (data
->whole_window
) XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1181 wine_tsx11_unlock();
1183 if (!data
->whole_window
) return 0;
1185 if (!create_client_window( display
, data
, NULL
))
1188 XDeleteContext( display
, data
->whole_window
, winContext
);
1189 XDestroyWindow( display
, data
->whole_window
);
1190 data
->whole_window
= 0;
1191 wine_tsx11_unlock();
1195 xim
= x11drv_thread_data()->xim
;
1196 if (xim
) data
->xic
= X11DRV_CreateIC( xim
, display
, data
->whole_window
);
1198 set_initial_wm_hints( display
, data
);
1199 X11DRV_set_wm_hints( display
, data
);
1201 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1203 /* set the window text */
1204 if (!InternalGetWindowText( data
->hwnd
, text
, sizeof(text
)/sizeof(WCHAR
) )) text
[0] = 0;
1205 sync_window_text( display
, data
->whole_window
, text
);
1207 /* set the window region */
1208 if ((hrgn
= CreateRectRgn( 0, 0, 0, 0 )))
1210 if (GetWindowRgn( data
->hwnd
, hrgn
) != ERROR
) sync_window_region( display
, data
, hrgn
);
1211 DeleteObject( hrgn
);
1213 return data
->whole_window
;
1217 /**********************************************************************
1218 * destroy_whole_window
1220 * Destroy the whole X window for a given window.
1222 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
, BOOL already_destroyed
)
1224 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1226 if (!data
->whole_window
) return;
1228 TRACE( "win %p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1229 if (thread_data
->cursor_window
== data
->whole_window
||
1230 thread_data
->cursor_window
== data
->client_window
)
1231 thread_data
->cursor_window
= None
;
1233 XDeleteContext( display
, data
->whole_window
, winContext
);
1234 XDeleteContext( display
, data
->client_window
, winContext
);
1235 if (!already_destroyed
) XDestroyWindow( display
, data
->whole_window
);
1236 data
->whole_window
= data
->client_window
= 0;
1237 data
->wm_state
= WithdrawnState
;
1238 data
->net_wm_state
= 0;
1239 data
->mapped
= FALSE
;
1242 XUnsetICFocus( data
->xic
);
1243 XDestroyIC( data
->xic
);
1246 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1248 XFree( data
->wm_hints
);
1249 data
->wm_hints
= NULL
;
1250 wine_tsx11_unlock();
1251 RemovePropA( data
->hwnd
, whole_window_prop
);
1252 RemovePropA( data
->hwnd
, client_window_prop
);
1256 /*****************************************************************
1257 * SetWindowText (X11DRV.@)
1259 void X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1261 Display
*display
= thread_display();
1264 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(display
))
1265 sync_window_text( display
, win
, text
);
1269 /***********************************************************************
1270 * DestroyWindow (X11DRV.@)
1272 void X11DRV_DestroyWindow( HWND hwnd
)
1274 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1275 Display
*display
= thread_data
->display
;
1276 struct x11drv_win_data
*data
;
1278 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1282 destroy_glxpixmap(display
, data
->gl_drawable
);
1284 XFreePixmap(display
, data
->pixmap
);
1285 wine_tsx11_unlock();
1287 else if (data
->gl_drawable
)
1290 XDestroyWindow(display
, data
->gl_drawable
);
1291 wine_tsx11_unlock();
1294 destroy_whole_window( display
, data
, FALSE
);
1295 destroy_icon_window( display
, data
);
1300 XFreeColormap( display
, data
->colormap
);
1301 wine_tsx11_unlock();
1304 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1305 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1306 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1308 XDeleteContext( display
, (XID
)hwnd
, win_data_context
);
1309 wine_tsx11_unlock();
1310 HeapFree( GetProcessHeap(), 0, data
);
1314 /***********************************************************************
1315 * X11DRV_DestroyNotify
1317 void X11DRV_DestroyNotify( HWND hwnd
, XEvent
*event
)
1319 Display
*display
= event
->xdestroywindow
.display
;
1320 struct x11drv_win_data
*data
;
1322 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1324 FIXME( "window %p/%lx destroyed from the outside\n", hwnd
, data
->whole_window
);
1325 destroy_whole_window( display
, data
, TRUE
);
1329 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1331 struct x11drv_win_data
*data
;
1333 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
1337 if (!winContext
) winContext
= XUniqueContext();
1338 if (!win_data_context
) win_data_context
= XUniqueContext();
1339 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1340 wine_tsx11_unlock();
1346 /* initialize the desktop window id in the desktop manager process */
1347 static struct x11drv_win_data
*create_desktop_win_data( Display
*display
, HWND hwnd
)
1349 struct x11drv_win_data
*data
;
1352 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1354 visualid
= XVisualIDFromVisual(visual
);
1355 wine_tsx11_unlock();
1356 data
->whole_window
= data
->client_window
= root_window
;
1357 data
->managed
= TRUE
;
1358 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1359 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1360 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)root_window
);
1361 set_initial_wm_hints( display
, data
);
1365 /**********************************************************************
1366 * CreateDesktopWindow (X11DRV.@)
1368 BOOL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1370 unsigned int width
, height
;
1372 /* retrieve the real size of the desktop */
1373 SERVER_START_REQ( get_window_rectangles
)
1376 wine_server_call( req
);
1377 width
= reply
->window
.right
- reply
->window
.left
;
1378 height
= reply
->window
.bottom
- reply
->window
.top
;
1382 if (!width
&& !height
) /* not initialized yet */
1384 SERVER_START_REQ( set_window_pos
)
1388 req
->flags
= SWP_NOZORDER
;
1389 req
->window
.left
= virtual_screen_rect
.left
;
1390 req
->window
.top
= virtual_screen_rect
.top
;
1391 req
->window
.right
= virtual_screen_rect
.right
;
1392 req
->window
.bottom
= virtual_screen_rect
.bottom
;
1393 req
->client
= req
->window
;
1394 wine_server_call( req
);
1400 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1401 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1407 /**********************************************************************
1408 * CreateWindow (X11DRV.@)
1410 BOOL
X11DRV_CreateWindow( HWND hwnd
)
1412 Display
*display
= thread_display();
1414 if (hwnd
== GetDesktopWindow() && root_window
!= DefaultRootWindow( display
))
1416 /* the desktop win data can't be created lazily */
1417 if (!create_desktop_win_data( display
, hwnd
)) return FALSE
;
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
));
1472 /***********************************************************************
1473 * X11DRV_get_whole_window
1475 * Return the X window associated with the full area of a window
1477 Window
X11DRV_get_whole_window( HWND hwnd
)
1479 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1483 if (hwnd
== GetDesktopWindow()) return root_window
;
1484 return (Window
)GetPropA( hwnd
, whole_window_prop
);
1486 return data
->whole_window
;
1490 /***********************************************************************
1491 * X11DRV_get_client_window
1493 * Return the X window associated with the client area of a window
1495 Window
X11DRV_get_client_window( HWND hwnd
)
1497 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1501 if (hwnd
== GetDesktopWindow()) return root_window
;
1502 return (Window
)GetPropA( hwnd
, client_window_prop
);
1504 return data
->client_window
;
1508 /***********************************************************************
1511 * Return the X input context associated with a window
1513 XIC
X11DRV_get_ic( HWND hwnd
)
1515 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1517 if (!data
) return 0;
1522 /***********************************************************************
1523 * X11DRV_GetDC (X11DRV.@)
1525 void X11DRV_GetDC( HDC hdc
, HWND hwnd
, HWND top
, const RECT
*win_rect
,
1526 const RECT
*top_rect
, DWORD flags
)
1528 struct x11drv_escape_set_drawable escape
;
1529 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1531 escape
.code
= X11DRV_SET_DRAWABLE
;
1532 escape
.mode
= IncludeInferiors
;
1533 escape
.fbconfig_id
= 0;
1534 escape
.gl_drawable
= 0;
1537 if (top
== hwnd
&& data
&& IsIconic( hwnd
) && data
->icon_window
)
1539 escape
.drawable
= data
->icon_window
;
1541 else if (top
== hwnd
&& (flags
& DCX_WINDOW
))
1543 escape
.drawable
= data
? data
->whole_window
: X11DRV_get_whole_window( hwnd
);
1547 escape
.drawable
= X11DRV_get_client_window( top
);
1548 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1549 escape
.gl_drawable
= data
? data
->gl_drawable
: (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
1550 escape
.pixmap
= data
? data
->pixmap
: (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
1553 escape
.dc_rect
.left
= win_rect
->left
- top_rect
->left
;
1554 escape
.dc_rect
.top
= win_rect
->top
- top_rect
->top
;
1555 escape
.dc_rect
.right
= win_rect
->right
- top_rect
->left
;
1556 escape
.dc_rect
.bottom
= win_rect
->bottom
- top_rect
->top
;
1557 escape
.drawable_rect
.left
= top_rect
->left
;
1558 escape
.drawable_rect
.top
= top_rect
->top
;
1559 escape
.drawable_rect
.right
= top_rect
->right
;
1560 escape
.drawable_rect
.bottom
= top_rect
->bottom
;
1562 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1566 /***********************************************************************
1567 * X11DRV_ReleaseDC (X11DRV.@)
1569 void X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
1571 struct x11drv_escape_set_drawable escape
;
1573 escape
.code
= X11DRV_SET_DRAWABLE
;
1574 escape
.drawable
= root_window
;
1575 escape
.mode
= IncludeInferiors
;
1576 escape
.drawable_rect
= virtual_screen_rect
;
1577 SetRect( &escape
.dc_rect
, 0, 0, virtual_screen_rect
.right
- virtual_screen_rect
.left
,
1578 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
);
1579 escape
.fbconfig_id
= 0;
1580 escape
.gl_drawable
= 0;
1582 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1586 /***********************************************************************
1587 * SetCapture (X11DRV.@)
1589 void X11DRV_SetCapture( HWND hwnd
, UINT flags
)
1591 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1593 if (!(flags
& GUI_INMOVESIZE
)) return;
1597 Window grab_win
= X11DRV_get_client_window( GetAncestor( hwnd
, GA_ROOT
) );
1599 if (!grab_win
) return;
1601 XFlush( gdi_display
);
1602 XGrabPointer( thread_data
->display
, grab_win
, False
,
1603 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1604 GrabModeAsync
, GrabModeAsync
, root_window
, None
, CurrentTime
);
1605 wine_tsx11_unlock();
1606 thread_data
->grab_window
= grab_win
;
1608 else /* release capture */
1611 XFlush( gdi_display
);
1612 XUngrabPointer( thread_data
->display
, CurrentTime
);
1613 wine_tsx11_unlock();
1614 thread_data
->grab_window
= None
;
1619 /*****************************************************************
1620 * SetParent (X11DRV.@)
1622 void X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
1624 Display
*display
= thread_display();
1625 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1628 if (parent
== old_parent
) return;
1630 if (parent
!= GetDesktopWindow()) /* a child window */
1632 if (old_parent
== GetDesktopWindow())
1634 /* destroy the old X windows */
1635 destroy_whole_window( display
, data
, FALSE
);
1636 destroy_icon_window( display
, data
);
1639 data
->managed
= FALSE
;
1640 RemovePropA( data
->hwnd
, managed_prop
);
1644 else /* new top level window */
1646 /* FIXME: we ignore errors since we can't really recover anyway */
1647 create_whole_window( display
, data
);
1652 /*****************************************************************
1653 * SetFocus (X11DRV.@)
1656 * Explicit colormap management seems to work only with OLVWM.
1658 void X11DRV_SetFocus( HWND hwnd
)
1660 Display
*display
= thread_display();
1661 struct x11drv_win_data
*data
;
1662 XWindowChanges changes
;
1664 /* If setting the focus to 0, uninstall the colormap */
1665 if (!hwnd
&& root_window
== DefaultRootWindow(display
))
1668 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1669 XUninstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1670 wine_tsx11_unlock();
1674 hwnd
= GetAncestor( hwnd
, GA_ROOT
);
1676 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1677 if (data
->managed
|| !data
->whole_window
) return;
1679 /* Set X focus and install colormap */
1681 changes
.stack_mode
= Above
;
1682 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
1683 if (root_window
== DefaultRootWindow(display
))
1685 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1686 /* FIXME: this is not entirely correct */
1687 XSetInputFocus( display
, data
->whole_window
, RevertToParent
,
1689 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1690 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1691 XInstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1693 wine_tsx11_unlock();
1697 /**********************************************************************
1698 * SetWindowIcon (X11DRV.@)
1700 * hIcon or hIconSm has changed (or is being initialised for the
1701 * first time). Complete the X11 driver-specific initialisation
1702 * and set the window hints.
1704 * This is not entirely correct, may need to create
1705 * an icon window and set the pixmap as a background
1707 void X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
1709 Display
*display
= thread_display();
1710 struct x11drv_win_data
*data
;
1712 if (type
!= ICON_BIG
) return; /* nothing to do here */
1714 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1715 if (!data
->whole_window
) return;
1716 if (!data
->managed
) return;
1720 set_icon_hints( display
, data
, icon
);
1722 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
1723 wine_tsx11_unlock();
1728 /***********************************************************************
1729 * SetWindowRgn (X11DRV.@)
1731 * Assign specified region to window (for non-rectangular windows)
1733 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
1735 struct x11drv_win_data
*data
;
1737 if ((data
= X11DRV_get_win_data( hwnd
)))
1739 sync_window_region( thread_display(), data
, hrgn
);
1741 else if (GetWindowThreadProcessId( hwnd
, NULL
) != GetCurrentThreadId())
1743 FIXME( "not supported on other thread window %p\n", hwnd
);
1744 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);