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 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
54 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
55 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
56 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
57 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
58 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
59 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
60 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
61 #define _NET_WM_MOVERESIZE_MOVE 8
62 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9
63 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10
65 /* X context to associate a hwnd to an X window */
66 XContext winContext
= 0;
68 /* X context to associate a struct x11drv_win_data to an hwnd */
69 static XContext win_data_context
;
71 static const char whole_window_prop
[] = "__wine_x11_whole_window";
72 static const char client_window_prop
[]= "__wine_x11_client_window";
73 static const char icon_window_prop
[] = "__wine_x11_icon_window";
74 static const char fbconfig_id_prop
[] = "__wine_x11_fbconfig_id";
75 static const char gl_drawable_prop
[] = "__wine_x11_gl_drawable";
76 static const char pixmap_prop
[] = "__wine_x11_pixmap";
77 static const char managed_prop
[] = "__wine_x11_managed";
79 extern int usexcomposite
;
81 /***********************************************************************
84 * Check if a given window should be managed
86 BOOL
is_window_managed( HWND hwnd
, UINT swp_flags
, const RECT
*window_rect
)
88 DWORD style
, ex_style
;
90 if (!managed_mode
) return FALSE
;
92 /* child windows are not managed */
93 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
94 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) return FALSE
;
95 /* activated windows are managed */
96 if (!(swp_flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
))) return TRUE
;
97 if (hwnd
== GetActiveWindow()) return TRUE
;
98 /* windows with caption are managed */
99 if ((style
& WS_CAPTION
) == WS_CAPTION
) return TRUE
;
100 /* tool windows are not managed */
101 ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
102 if (ex_style
& WS_EX_TOOLWINDOW
) return FALSE
;
103 /* windows with thick frame are managed */
104 if (style
& WS_THICKFRAME
) return TRUE
;
105 /* application windows are managed */
106 if (ex_style
& WS_EX_APPWINDOW
) return TRUE
;
107 if (style
& WS_POPUP
)
109 /* popup with sysmenu == caption are managed */
110 if (style
& WS_SYSMENU
) return TRUE
;
111 /* full-screen popup windows are managed */
112 if (window_rect
->left
<= 0 && window_rect
->right
>= screen_width
&&
113 window_rect
->top
<= 0 && window_rect
->bottom
>= screen_height
)
116 /* default: not managed */
121 /***********************************************************************
122 * X11DRV_is_window_rect_mapped
124 * Check if the X whole window should be mapped based on its rectangle
126 BOOL
X11DRV_is_window_rect_mapped( const RECT
*rect
)
128 /* don't map if rect is off-screen */
129 if (rect
->left
>= virtual_screen_rect
.right
||
130 rect
->top
>= virtual_screen_rect
.bottom
||
131 rect
->right
<= virtual_screen_rect
.left
||
132 rect
->bottom
<= virtual_screen_rect
.top
)
139 /***********************************************************************
140 * is_window_resizable
142 * Check if window should be made resizable by the window manager
144 static inline BOOL
is_window_resizable( struct x11drv_win_data
*data
, DWORD style
)
146 if (style
& WS_THICKFRAME
) return TRUE
;
147 /* Metacity needs the window to be resizable to make it fullscreen */
148 return (data
->whole_rect
.left
<= 0 && data
->whole_rect
.right
>= screen_width
&&
149 data
->whole_rect
.top
<= 0 && data
->whole_rect
.bottom
>= screen_height
);
153 /***********************************************************************
154 * get_mwm_decorations
156 static unsigned long get_mwm_decorations( struct x11drv_win_data
*data
,
157 DWORD style
, DWORD ex_style
)
159 unsigned long ret
= 0;
161 if (!decorated_mode
) return 0;
163 if (IsRectEmpty( &data
->window_rect
)) return 0;
165 if (ex_style
& WS_EX_TOOLWINDOW
) return 0;
167 if ((style
& WS_CAPTION
) == WS_CAPTION
)
169 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
170 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
171 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
172 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
174 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
175 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
176 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
181 /***********************************************************************
182 * get_x11_rect_offset
184 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
186 static void get_x11_rect_offset( struct x11drv_win_data
*data
, RECT
*rect
)
188 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
191 rect
->top
= rect
->bottom
= rect
->left
= rect
->right
= 0;
193 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
194 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
195 decor
= get_mwm_decorations( data
, style
, ex_style
);
197 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
198 if (decor
& MWM_DECOR_BORDER
)
200 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
201 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
204 AdjustWindowRectEx( rect
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
208 /***********************************************************************
209 * get_window_attributes
211 * Fill the window attributes structure for an X window.
213 static int get_window_attributes( Display
*display
, struct x11drv_win_data
*data
,
214 XSetWindowAttributes
*attr
)
216 attr
->override_redirect
= !data
->managed
;
217 attr
->colormap
= X11DRV_PALETTE_PaletteXColormap
;
218 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
219 attr
->cursor
= x11drv_thread_data()->cursor
;
220 attr
->bit_gravity
= NorthWestGravity
;
221 attr
->backing_store
= NotUseful
;
222 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
223 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
224 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
| KeymapStateMask
);
225 if (data
->managed
) attr
->event_mask
|= StructureNotifyMask
| PropertyChangeMask
;
227 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
| CWCursor
|
228 CWEventMask
| CWBitGravity
| CWBackingStore
);
232 /***********************************************************************
233 * create_client_window
235 static Window
create_client_window( Display
*display
, struct x11drv_win_data
*data
, XVisualInfo
*vis
)
238 XSetWindowAttributes attr
;
241 attr
.bit_gravity
= NorthWestGravity
;
242 attr
.win_gravity
= NorthWestGravity
;
243 attr
.backing_store
= NotUseful
;
244 attr
.event_mask
= (ExposureMask
| PointerMotionMask
|
245 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
246 mask
= CWEventMask
| CWBitGravity
| CWWinGravity
| CWBackingStore
;
248 if ((cx
= data
->client_rect
.right
- data
->client_rect
.left
) <= 0) cx
= 1;
249 if ((cy
= data
->client_rect
.bottom
- data
->client_rect
.top
) <= 0) cy
= 1;
255 attr
.colormap
= XCreateColormap( display
, root_window
, vis
->visual
,
256 (vis
->class == PseudoColor
|| vis
->class == GrayScale
||
257 vis
->class == DirectColor
) ? AllocAll
: AllocNone
);
261 client
= XCreateWindow( display
, data
->whole_window
,
262 data
->client_rect
.left
- data
->whole_rect
.left
,
263 data
->client_rect
.top
- data
->whole_rect
.top
,
264 cx
, cy
, 0, screen_depth
, InputOutput
,
265 vis
? vis
->visual
: visual
, mask
, &attr
);
272 if (data
->client_window
)
274 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
275 if (thread_data
->cursor_window
== data
->client_window
) thread_data
->cursor_window
= None
;
276 XDeleteContext( display
, data
->client_window
, winContext
);
277 XDestroyWindow( display
, data
->client_window
);
279 data
->client_window
= client
;
281 if (data
->colormap
) XFreeColormap( display
, data
->colormap
);
282 data
->colormap
= vis
? attr
.colormap
: 0;
284 XMapWindow( display
, data
->client_window
);
285 XSaveContext( display
, data
->client_window
, winContext
, (char *)data
->hwnd
);
288 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)data
->client_window
);
289 return data
->client_window
;
293 /***********************************************************************
294 * X11DRV_sync_window_style
296 * Change the X window attributes when the window style has changed.
298 void X11DRV_sync_window_style( Display
*display
, struct x11drv_win_data
*data
)
300 if (data
->whole_window
!= root_window
)
302 XSetWindowAttributes attr
;
303 int mask
= get_window_attributes( display
, data
, &attr
);
306 XChangeWindowAttributes( display
, data
->whole_window
, mask
, &attr
);
312 /***********************************************************************
315 * Update the X11 window region.
317 static void sync_window_region( Display
*display
, struct x11drv_win_data
*data
, HRGN hrgn
)
319 #ifdef HAVE_LIBXSHAPE
320 if (!data
->whole_window
) return;
325 XShapeCombineMask( display
, data
->whole_window
, ShapeBounding
, 0, 0, None
, ShapeSet
);
330 RGNDATA
*pRegionData
= X11DRV_GetRegionData( hrgn
, 0 );
334 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
335 data
->window_rect
.left
- data
->whole_rect
.left
,
336 data
->window_rect
.top
- data
->whole_rect
.top
,
337 (XRectangle
*)pRegionData
->Buffer
,
338 pRegionData
->rdh
.nCount
, ShapeSet
, YXBanded
);
340 HeapFree(GetProcessHeap(), 0, pRegionData
);
343 #endif /* HAVE_LIBXSHAPE */
347 /***********************************************************************
350 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
353 char *buffer
, *utf8_buffer
;
356 /* allocate new buffer for window text */
357 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
358 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
359 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
361 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
362 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
364 HeapFree( GetProcessHeap(), 0, buffer
);
367 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
370 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
372 XSetWMName( display
, win
, &prop
);
373 XSetWMIconName( display
, win
, &prop
);
377 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
378 according to the standard
379 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
381 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
382 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
385 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
386 HeapFree( GetProcessHeap(), 0, buffer
);
390 /***********************************************************************
391 * X11DRV_set_win_format
393 BOOL
X11DRV_set_win_format( HWND hwnd
, XID fbconfig_id
)
395 Display
*display
= thread_display();
396 struct x11drv_win_data
*data
;
400 if (!(data
= X11DRV_get_win_data(hwnd
)) &&
401 !(data
= X11DRV_create_win_data(hwnd
))) return FALSE
;
403 if (data
->fbconfig_id
) return FALSE
; /* can't change it twice */
406 vis
= visual_from_fbconfig_id(fbconfig_id
);
408 if (!vis
) return FALSE
;
410 if (data
->whole_window
)
412 Window client
= data
->client_window
;
414 if (vis
->visualid
!= XVisualIDFromVisual(visual
))
416 client
= create_client_window( display
, data
, vis
);
417 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client
, data
->hwnd
, fbconfig_id
);
422 if (client
) goto done
;
426 w
= data
->client_rect
.right
- data
->client_rect
.left
;
427 h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
432 #ifdef SONAME_LIBXCOMPOSITE
435 XSetWindowAttributes attrib
;
436 Window parent
= X11DRV_get_whole_window( GetAncestor( hwnd
, GA_ROOT
));
438 if (!parent
) parent
= root_window
;
440 data
->colormap
= XCreateColormap(display
, parent
, vis
->visual
,
441 (vis
->class == PseudoColor
||
442 vis
->class == GrayScale
||
443 vis
->class == DirectColor
) ?
444 AllocAll
: AllocNone
);
445 attrib
.override_redirect
= True
;
446 attrib
.colormap
= data
->colormap
;
447 XInstallColormap(gdi_display
, attrib
.colormap
);
449 data
->gl_drawable
= XCreateWindow(display
, parent
, -w
, 0, w
, h
, 0,
450 vis
->depth
, InputOutput
, vis
->visual
,
451 CWColormap
| CWOverrideRedirect
,
453 if(data
->gl_drawable
)
455 pXCompositeRedirectWindow(display
, data
->gl_drawable
,
456 CompositeRedirectManual
);
457 XMapWindow(display
, data
->gl_drawable
);
465 WARN("XComposite is not available, using GLXPixmap hack\n");
468 data
->pixmap
= XCreatePixmap(display
, root_window
, w
, h
, vis
->depth
);
476 data
->gl_drawable
= create_glxpixmap(display
, vis
, data
->pixmap
);
477 if(!data
->gl_drawable
)
479 XFreePixmap(display
, data
->pixmap
);
484 if (data
->pixmap
) SetPropA(hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
487 if (!data
->gl_drawable
) return FALSE
;
489 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
490 data
->gl_drawable
, fbconfig_id
);
491 SetPropA(hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
494 data
->fbconfig_id
= fbconfig_id
;
495 SetPropA(hwnd
, fbconfig_id_prop
, (HANDLE
)data
->fbconfig_id
);
499 WIN_invalidate_dce( hwnd
, NULL
);
503 /***********************************************************************
506 static void sync_gl_drawable(Display
*display
, struct x11drv_win_data
*data
)
508 int w
= data
->client_rect
.right
- data
->client_rect
.left
;
509 int h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
517 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
518 #ifdef SONAME_LIBXCOMPOSITE
522 XMoveResizeWindow(display
, data
->gl_drawable
, -w
, 0, w
, h
);
530 vis
= visual_from_fbconfig_id(data
->fbconfig_id
);
537 pix
= XCreatePixmap(display
, root_window
, w
, h
, vis
->depth
);
540 ERR("Failed to create pixmap for offscreen rendering\n");
546 glxp
= create_glxpixmap(display
, vis
, pix
);
549 ERR("Failed to create drawable for offscreen rendering\n");
550 XFreePixmap(display
, pix
);
558 mark_drawable_dirty(data
->gl_drawable
, glxp
);
560 XFreePixmap(display
, data
->pixmap
);
561 destroy_glxpixmap(display
, data
->gl_drawable
);
564 data
->gl_drawable
= glxp
;
569 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
570 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
574 /***********************************************************************
577 * fill the window changes structure
579 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
583 if (old
->right
- old
->left
!= new->right
- new->left
)
585 if ((changes
->width
= new->right
- new->left
) <= 0) changes
->width
= 1;
588 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
590 if ((changes
->height
= new->bottom
- new->top
) <= 0) changes
->height
= 1;
593 if (old
->left
!= new->left
)
595 changes
->x
= new->left
;
598 if (old
->top
!= new->top
)
600 changes
->y
= new->top
;
607 /***********************************************************************
610 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
612 XSetWindowAttributes attr
;
614 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
615 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
616 attr
.bit_gravity
= NorthWestGravity
;
617 attr
.backing_store
= NotUseful
/*WhenMapped*/;
618 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
621 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
622 GetSystemMetrics( SM_CXICON
),
623 GetSystemMetrics( SM_CYICON
),
626 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
627 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
628 XFlush( display
); /* make sure the window exists before we start painting to it */
631 TRACE( "created %lx\n", data
->icon_window
);
632 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
633 return data
->icon_window
;
638 /***********************************************************************
639 * destroy_icon_window
641 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
643 if (!data
->icon_window
) return;
644 if (x11drv_thread_data()->cursor_window
== data
->icon_window
)
645 x11drv_thread_data()->cursor_window
= None
;
647 XDeleteContext( display
, data
->icon_window
, winContext
);
648 XDestroyWindow( display
, data
->icon_window
);
649 data
->icon_window
= 0;
651 RemovePropA( data
->hwnd
, icon_window_prop
);
655 /***********************************************************************
658 * Set the icon wm hints
660 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
, HICON hIcon
)
662 XWMHints
*hints
= data
->wm_hints
;
664 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
665 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
666 data
->hWMIconBitmap
= 0;
667 data
->hWMIconMask
= 0;
671 if (!data
->icon_window
) create_icon_window( display
, data
);
672 hints
->icon_window
= data
->icon_window
;
673 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
683 GetIconInfo(hIcon
, &ii
);
685 GetObjectA(ii
.hbmMask
, sizeof(bmMask
), &bmMask
);
688 rcMask
.right
= bmMask
.bmWidth
;
689 rcMask
.bottom
= bmMask
.bmHeight
;
691 hDC
= CreateCompatibleDC(0);
692 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
693 InvertRect(hDC
, &rcMask
);
694 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
695 SelectObject(hDC
, hbmOrig
);
698 data
->hWMIconBitmap
= ii
.hbmColor
;
699 data
->hWMIconMask
= ii
.hbmMask
;
701 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
702 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
703 destroy_icon_window( display
, data
);
704 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
709 /***********************************************************************
712 * set the window size hints
714 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
716 XSizeHints
* size_hints
;
718 if (!(size_hints
= XAllocSizeHints())) return;
720 /* don't update size hints if window is not in normal state */
721 if (!(style
& (WS_MINIMIZE
| WS_MAXIMIZE
)))
723 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
725 size_hints
->win_gravity
= StaticGravity
;
726 size_hints
->x
= data
->whole_rect
.left
;
727 size_hints
->y
= data
->whole_rect
.top
;
728 size_hints
->flags
|= PWinGravity
| PPosition
;
731 if (!is_window_resizable( data
, style
))
733 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
734 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
735 size_hints
->min_width
= size_hints
->max_width
;
736 size_hints
->min_height
= size_hints
->max_height
;
737 size_hints
->flags
|= PMinSize
| PMaxSize
;
740 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
745 /***********************************************************************
748 * get the name of the current process for setting class hints
750 static char *get_process_name(void)
756 WCHAR module
[MAX_PATH
];
757 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
758 if (len
&& len
< MAX_PATH
)
761 WCHAR
*p
, *appname
= module
;
763 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
764 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
765 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
766 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
768 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
777 /***********************************************************************
778 * set_initial_wm_hints
780 * Set the window manager hints that don't change over the lifetime of a window.
782 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
787 XClassHint
*class_hints
;
788 char *process_name
= get_process_name();
794 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
795 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
796 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
797 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
798 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
801 if ((class_hints
= XAllocClassHint()))
803 static char wine
[] = "Wine";
805 class_hints
->res_name
= process_name
;
806 class_hints
->res_class
= wine
;
807 XSetClassHint( display
, data
->whole_window
, class_hints
);
808 XFree( class_hints
);
811 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
812 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
813 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
815 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
816 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
818 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
819 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
821 data
->wm_hints
= XAllocWMHints();
826 HICON icon
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_BIG
, 0 );
827 if (!icon
) icon
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
);
828 data
->wm_hints
->flags
= 0;
829 set_icon_hints( display
, data
, icon
);
834 /***********************************************************************
835 * X11DRV_set_wm_hints
837 * Set the window manager hints for a newly-created window
839 void X11DRV_set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
844 DWORD style
, ex_style
;
847 if (data
->hwnd
== GetDesktopWindow())
849 /* force some styles for the desktop to get the correct decorations */
850 style
= WS_POPUP
| WS_VISIBLE
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
851 ex_style
= WS_EX_APPWINDOW
;
856 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
857 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
858 owner
= GetWindow( data
->hwnd
, GW_OWNER
);
861 /* transient for hint */
864 Window owner_win
= X11DRV_get_whole_window( owner
);
866 XSetTransientForHint( display
, data
->whole_window
, owner_win
);
868 group_leader
= owner_win
;
870 else group_leader
= data
->whole_window
;
875 set_size_hints( display
, data
, style
);
877 /* set the WM_WINDOW_TYPE */
878 if (style
& WS_THICKFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
879 else if (ex_style
& WS_EX_APPWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
880 else if (style
& WS_DLGFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
881 else if (ex_style
& WS_EX_DLGMODALFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
882 #if 0 /* many window managers don't handle utility windows very well */
883 else if (ex_style
& WS_EX_TOOLWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY
);
885 else window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
887 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
888 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
890 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
891 mwm_hints
.decorations
= get_mwm_decorations( data
, style
, ex_style
);
892 mwm_hints
.functions
= MWM_FUNC_MOVE
;
893 if (is_window_resizable( data
, style
)) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
894 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
895 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
896 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
898 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
899 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
900 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
905 data
->wm_hints
->flags
|= InputHint
| StateHint
| WindowGroupHint
;
906 data
->wm_hints
->input
= !(style
& WS_DISABLED
);
907 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
908 data
->wm_hints
->window_group
= group_leader
;
909 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
916 /***********************************************************************
917 * X11DRV_window_to_X_rect
919 * Convert a rect from client to X window coordinates
921 void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
925 if (!data
->managed
) return;
926 if (IsRectEmpty( rect
)) return;
928 get_x11_rect_offset( data
, &rc
);
930 rect
->left
-= rc
.left
;
931 rect
->right
-= rc
.right
;
933 rect
->bottom
-= rc
.bottom
;
934 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
935 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
939 /***********************************************************************
940 * X11DRV_X_to_window_rect
942 * Opposite of X11DRV_window_to_X_rect
944 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
948 if (!data
->managed
) return;
949 if (IsRectEmpty( rect
)) return;
951 get_x11_rect_offset( data
, &rc
);
953 rect
->left
+= rc
.left
;
954 rect
->right
+= rc
.right
;
956 rect
->bottom
+= rc
.bottom
;
957 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
958 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
962 /***********************************************************************
963 * X11DRV_sync_window_position
965 * Synchronize the X window position with the Windows one
967 void X11DRV_sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
968 UINT swp_flags
, const RECT
*old_client_rect
,
969 const RECT
*old_whole_rect
)
971 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
972 XWindowChanges changes
;
973 int mask
= CWWidth
| CWHeight
;
975 if (data
->managed
&& data
->iconic
) return;
977 if ((changes
.width
= data
->whole_rect
.right
- data
->whole_rect
.left
) <= 0) changes
.width
= 1;
978 if ((changes
.height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
) <= 0) changes
.height
= 1;
980 /* only the size is allowed to change for the desktop window */
981 if (data
->whole_window
!= root_window
)
983 changes
.x
= data
->whole_rect
.left
- virtual_screen_rect
.left
;
984 changes
.y
= data
->whole_rect
.top
- virtual_screen_rect
.top
;
988 if (!(swp_flags
& SWP_NOZORDER
))
990 /* find window that this one must be after */
991 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
992 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
993 prev
= GetWindow( prev
, GW_HWNDPREV
);
994 if (!prev
) /* top child */
996 changes
.stack_mode
= Above
;
999 /* should use stack_mode Below but most window managers don't get it right */
1000 /* and Above with a sibling doesn't work so well either, so we ignore it */
1003 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
1004 data
->hwnd
, data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1005 data
->whole_rect
.right
- data
->whole_rect
.left
,
1006 data
->whole_rect
.bottom
- data
->whole_rect
.top
, changes
.sibling
, mask
);
1009 set_size_hints( display
, data
, style
);
1010 XReconfigureWMWindow( display
, data
->whole_window
,
1011 DefaultScreen(display
), mask
, &changes
);
1012 wine_tsx11_unlock();
1016 /***********************************************************************
1017 * X11DRV_sync_client_position
1019 * Synchronize the X client window position with the Windows one
1021 void X11DRV_sync_client_position( Display
*display
, struct x11drv_win_data
*data
,
1022 UINT swp_flags
, const RECT
*old_client_rect
,
1023 const RECT
*old_whole_rect
)
1026 XWindowChanges changes
;
1027 RECT old
= *old_client_rect
;
1028 RECT
new = data
->client_rect
;
1030 OffsetRect( &old
, -old_whole_rect
->left
, -old_whole_rect
->top
);
1031 OffsetRect( &new, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
1032 if (!(mask
= get_window_changes( &changes
, &old
, &new ))) return;
1034 if (data
->client_window
)
1036 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1037 data
->client_window
, new.left
, new.top
,
1038 new.right
- new.left
, new.bottom
- new.top
, mask
);
1040 XConfigureWindow( display
, data
->client_window
, mask
, &changes
);
1041 wine_tsx11_unlock();
1044 if (data
->gl_drawable
&& (mask
& (CWWidth
|CWHeight
))) sync_gl_drawable( display
, data
);
1048 /**********************************************************************
1049 * create_whole_window
1051 * Create the whole X window for a given window
1053 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1056 XSetWindowAttributes attr
;
1060 if (!(cx
= data
->window_rect
.right
- data
->window_rect
.left
)) cx
= 1;
1061 if (!(cy
= data
->window_rect
.bottom
- data
->window_rect
.top
)) cy
= 1;
1063 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1065 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1066 data
->managed
= TRUE
;
1067 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1070 mask
= get_window_attributes( display
, data
, &attr
);
1074 data
->whole_rect
= data
->window_rect
;
1075 data
->whole_window
= XCreateWindow( display
, root_window
,
1076 data
->window_rect
.left
- virtual_screen_rect
.left
,
1077 data
->window_rect
.top
- virtual_screen_rect
.top
,
1078 cx
, cy
, 0, screen_depth
, InputOutput
,
1079 visual
, mask
, &attr
);
1081 if (data
->whole_window
) XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1082 wine_tsx11_unlock();
1084 if (!data
->whole_window
) return 0;
1086 if (!create_client_window( display
, data
, NULL
))
1089 XDeleteContext( display
, data
->whole_window
, winContext
);
1090 XDestroyWindow( display
, data
->whole_window
);
1091 data
->whole_window
= 0;
1092 wine_tsx11_unlock();
1096 set_initial_wm_hints( display
, data
);
1097 X11DRV_set_wm_hints( display
, data
);
1099 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1101 /* set the window text */
1102 if (!InternalGetWindowText( data
->hwnd
, text
, sizeof(text
)/sizeof(WCHAR
) )) text
[0] = 0;
1103 sync_window_text( display
, data
->whole_window
, text
);
1105 /* set the window region */
1106 if ((hrgn
= CreateRectRgn( 0, 0, 0, 0 )))
1108 if (GetWindowRgn( data
->hwnd
, hrgn
) != ERROR
) sync_window_region( display
, data
, hrgn
);
1109 DeleteObject( hrgn
);
1112 XFlush( display
); /* make sure the window exists before we start painting to it */
1113 wine_tsx11_unlock();
1114 return data
->whole_window
;
1118 /**********************************************************************
1119 * destroy_whole_window
1121 * Destroy the whole X window for a given window.
1123 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
, BOOL already_destroyed
)
1125 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1127 if (!data
->whole_window
) return;
1129 TRACE( "win %p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1130 if (thread_data
->cursor_window
== data
->whole_window
||
1131 thread_data
->cursor_window
== data
->client_window
)
1132 thread_data
->cursor_window
= None
;
1134 XDeleteContext( display
, data
->whole_window
, winContext
);
1135 XDeleteContext( display
, data
->client_window
, winContext
);
1136 if (!already_destroyed
) XDestroyWindow( display
, data
->whole_window
);
1137 data
->whole_window
= data
->client_window
= 0;
1138 data
->wm_state
= WithdrawnState
;
1139 data
->net_wm_state
= 0;
1140 data
->mapped
= FALSE
;
1143 XUnsetICFocus( data
->xic
);
1144 XDestroyIC( data
->xic
);
1147 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1149 XFree( data
->wm_hints
);
1150 data
->wm_hints
= NULL
;
1151 wine_tsx11_unlock();
1152 RemovePropA( data
->hwnd
, whole_window_prop
);
1153 RemovePropA( data
->hwnd
, client_window_prop
);
1157 /*****************************************************************
1158 * SetWindowText (X11DRV.@)
1160 void X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1162 Display
*display
= thread_display();
1165 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(display
))
1166 sync_window_text( display
, win
, text
);
1170 /***********************************************************************
1171 * DestroyWindow (X11DRV.@)
1173 void X11DRV_DestroyWindow( HWND hwnd
)
1175 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1176 Display
*display
= thread_data
->display
;
1177 struct x11drv_win_data
*data
;
1179 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1183 destroy_glxpixmap(display
, data
->gl_drawable
);
1185 XFreePixmap(display
, data
->pixmap
);
1186 wine_tsx11_unlock();
1188 else if (data
->gl_drawable
)
1191 XDestroyWindow(display
, data
->gl_drawable
);
1192 wine_tsx11_unlock();
1195 destroy_whole_window( display
, data
, FALSE
);
1196 destroy_icon_window( display
, data
);
1201 XFreeColormap( display
, data
->colormap
);
1202 wine_tsx11_unlock();
1205 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1206 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1207 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1209 XDeleteContext( display
, (XID
)hwnd
, win_data_context
);
1210 wine_tsx11_unlock();
1211 HeapFree( GetProcessHeap(), 0, data
);
1215 /***********************************************************************
1216 * X11DRV_DestroyNotify
1218 void X11DRV_DestroyNotify( HWND hwnd
, XEvent
*event
)
1220 Display
*display
= event
->xdestroywindow
.display
;
1221 struct x11drv_win_data
*data
;
1223 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1225 FIXME( "window %p/%lx destroyed from the outside\n", hwnd
, data
->whole_window
);
1226 destroy_whole_window( display
, data
, TRUE
);
1230 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1232 struct x11drv_win_data
*data
;
1234 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
1238 if (!winContext
) winContext
= XUniqueContext();
1239 if (!win_data_context
) win_data_context
= XUniqueContext();
1240 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1241 wine_tsx11_unlock();
1247 /* initialize the desktop window id in the desktop manager process */
1248 static struct x11drv_win_data
*create_desktop_win_data( Display
*display
, HWND hwnd
)
1250 struct x11drv_win_data
*data
;
1253 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1255 visualid
= XVisualIDFromVisual(visual
);
1256 wine_tsx11_unlock();
1257 data
->whole_window
= data
->client_window
= root_window
;
1258 data
->managed
= TRUE
;
1259 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1260 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1261 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)root_window
);
1262 set_initial_wm_hints( display
, data
);
1266 /**********************************************************************
1267 * CreateDesktopWindow (X11DRV.@)
1269 BOOL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1271 unsigned int width
, height
;
1273 /* retrieve the real size of the desktop */
1274 SERVER_START_REQ( get_window_rectangles
)
1277 wine_server_call( req
);
1278 width
= reply
->window
.right
- reply
->window
.left
;
1279 height
= reply
->window
.bottom
- reply
->window
.top
;
1283 if (!width
&& !height
) /* not initialized yet */
1285 SERVER_START_REQ( set_window_pos
)
1289 req
->flags
= SWP_NOZORDER
;
1290 req
->window
.left
= virtual_screen_rect
.left
;
1291 req
->window
.top
= virtual_screen_rect
.top
;
1292 req
->window
.right
= virtual_screen_rect
.right
;
1293 req
->window
.bottom
= virtual_screen_rect
.bottom
;
1294 req
->client
= req
->window
;
1295 wine_server_call( req
);
1301 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1302 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1308 /**********************************************************************
1309 * CreateWindow (X11DRV.@)
1311 BOOL
X11DRV_CreateWindow( HWND hwnd
)
1313 Display
*display
= thread_display();
1315 if (hwnd
== GetDesktopWindow() && root_window
!= DefaultRootWindow( display
))
1317 /* the desktop win data can't be created lazily */
1318 if (!create_desktop_win_data( display
, hwnd
)) return FALSE
;
1324 /***********************************************************************
1325 * X11DRV_get_win_data
1327 * Return the X11 data structure associated with a window.
1329 struct x11drv_win_data
*X11DRV_get_win_data( HWND hwnd
)
1333 if (!hwnd
|| XFindContext( thread_display(), (XID
)hwnd
, win_data_context
, &data
)) data
= NULL
;
1334 return (struct x11drv_win_data
*)data
;
1338 /***********************************************************************
1339 * X11DRV_create_win_data
1341 * Create an X11 data window structure for an existing window.
1343 struct x11drv_win_data
*X11DRV_create_win_data( HWND hwnd
)
1345 Display
*display
= thread_display();
1346 struct x11drv_win_data
*data
;
1349 if (!(parent
= GetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop */
1350 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1352 GetWindowRect( hwnd
, &data
->window_rect
);
1353 MapWindowPoints( 0, parent
, (POINT
*)&data
->window_rect
, 2 );
1354 data
->whole_rect
= data
->window_rect
;
1355 GetClientRect( hwnd
, &data
->client_rect
);
1356 MapWindowPoints( hwnd
, parent
, (POINT
*)&data
->client_rect
, 2 );
1358 if (parent
== GetDesktopWindow())
1360 if (!create_whole_window( display
, data
))
1362 HeapFree( GetProcessHeap(), 0, data
);
1365 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1366 hwnd
, data
->whole_window
, data
->client_window
, wine_dbgstr_rect( &data
->window_rect
),
1367 wine_dbgstr_rect( &data
->whole_rect
), wine_dbgstr_rect( &data
->client_rect
));
1373 /***********************************************************************
1374 * X11DRV_get_whole_window
1376 * Return the X window associated with the full area of a window
1378 Window
X11DRV_get_whole_window( HWND hwnd
)
1380 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1384 if (hwnd
== GetDesktopWindow()) return root_window
;
1385 return (Window
)GetPropA( hwnd
, whole_window_prop
);
1387 return data
->whole_window
;
1391 /***********************************************************************
1392 * X11DRV_get_client_window
1394 * Return the X window associated with the client area of a window
1396 Window
X11DRV_get_client_window( HWND hwnd
)
1398 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1402 if (hwnd
== GetDesktopWindow()) return root_window
;
1403 return (Window
)GetPropA( hwnd
, client_window_prop
);
1405 return data
->client_window
;
1409 /***********************************************************************
1412 * Return the X input context associated with a window
1414 XIC
X11DRV_get_ic( HWND hwnd
)
1416 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1419 if (!data
) return 0;
1420 if (data
->xic
) return data
->xic
;
1421 if (!(xim
= x11drv_thread_data()->xim
)) return 0;
1422 return X11DRV_CreateIC( xim
, data
);
1426 /***********************************************************************
1427 * X11DRV_GetDC (X11DRV.@)
1429 void X11DRV_GetDC( HDC hdc
, HWND hwnd
, HWND top
, const RECT
*win_rect
,
1430 const RECT
*top_rect
, DWORD flags
)
1432 struct x11drv_escape_set_drawable escape
;
1433 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1435 escape
.code
= X11DRV_SET_DRAWABLE
;
1436 escape
.mode
= IncludeInferiors
;
1437 escape
.fbconfig_id
= 0;
1438 escape
.gl_drawable
= 0;
1441 if (top
== hwnd
&& data
&& IsIconic( hwnd
) && data
->icon_window
)
1443 escape
.drawable
= data
->icon_window
;
1445 else if (top
== hwnd
&& (flags
& DCX_WINDOW
))
1447 escape
.drawable
= data
? data
->whole_window
: X11DRV_get_whole_window( hwnd
);
1451 escape
.drawable
= X11DRV_get_client_window( top
);
1452 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1453 escape
.gl_drawable
= data
? data
->gl_drawable
: (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
1454 escape
.pixmap
= data
? data
->pixmap
: (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
1455 if (flags
& DCX_CLIPCHILDREN
) escape
.mode
= ClipByChildren
;
1458 escape
.dc_rect
.left
= win_rect
->left
- top_rect
->left
;
1459 escape
.dc_rect
.top
= win_rect
->top
- top_rect
->top
;
1460 escape
.dc_rect
.right
= win_rect
->right
- top_rect
->left
;
1461 escape
.dc_rect
.bottom
= win_rect
->bottom
- top_rect
->top
;
1462 escape
.drawable_rect
.left
= top_rect
->left
;
1463 escape
.drawable_rect
.top
= top_rect
->top
;
1464 escape
.drawable_rect
.right
= top_rect
->right
;
1465 escape
.drawable_rect
.bottom
= top_rect
->bottom
;
1467 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1471 /***********************************************************************
1472 * X11DRV_ReleaseDC (X11DRV.@)
1474 void X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
1476 struct x11drv_escape_set_drawable escape
;
1478 escape
.code
= X11DRV_SET_DRAWABLE
;
1479 escape
.drawable
= root_window
;
1480 escape
.mode
= IncludeInferiors
;
1481 escape
.drawable_rect
= virtual_screen_rect
;
1482 SetRect( &escape
.dc_rect
, 0, 0, virtual_screen_rect
.right
- virtual_screen_rect
.left
,
1483 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
);
1484 escape
.fbconfig_id
= 0;
1485 escape
.gl_drawable
= 0;
1487 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1491 /***********************************************************************
1492 * SetCapture (X11DRV.@)
1494 void X11DRV_SetCapture( HWND hwnd
, UINT flags
)
1496 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1498 if (!(flags
& (GUI_INMOVESIZE
| GUI_INMENUMODE
))) return;
1502 Window grab_win
= X11DRV_get_client_window( GetAncestor( hwnd
, GA_ROOT
) );
1504 if (!grab_win
) return;
1506 XFlush( gdi_display
);
1507 XGrabPointer( thread_data
->display
, grab_win
, False
,
1508 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1509 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
);
1510 wine_tsx11_unlock();
1511 thread_data
->grab_window
= grab_win
;
1513 else /* release capture */
1516 XFlush( gdi_display
);
1517 XUngrabPointer( thread_data
->display
, CurrentTime
);
1518 wine_tsx11_unlock();
1519 thread_data
->grab_window
= None
;
1524 /*****************************************************************
1525 * SetParent (X11DRV.@)
1527 void X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
1529 Display
*display
= thread_display();
1530 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1533 if (parent
== old_parent
) return;
1535 if (parent
!= GetDesktopWindow()) /* a child window */
1537 if (old_parent
== GetDesktopWindow())
1539 /* destroy the old X windows */
1540 destroy_whole_window( display
, data
, FALSE
);
1541 destroy_icon_window( display
, data
);
1544 data
->managed
= FALSE
;
1545 RemovePropA( data
->hwnd
, managed_prop
);
1549 else /* new top level window */
1551 /* FIXME: we ignore errors since we can't really recover anyway */
1552 create_whole_window( display
, data
);
1557 /*****************************************************************
1558 * SetFocus (X11DRV.@)
1561 * Explicit colormap management seems to work only with OLVWM.
1563 void X11DRV_SetFocus( HWND hwnd
)
1565 Display
*display
= thread_display();
1566 struct x11drv_win_data
*data
;
1567 XWindowChanges changes
;
1569 /* If setting the focus to 0, uninstall the colormap */
1570 if (!hwnd
&& root_window
== DefaultRootWindow(display
))
1573 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1574 XUninstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1575 wine_tsx11_unlock();
1579 hwnd
= GetAncestor( hwnd
, GA_ROOT
);
1581 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1582 if (data
->managed
|| !data
->whole_window
) return;
1584 /* Set X focus and install colormap */
1586 changes
.stack_mode
= Above
;
1587 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
1588 if (root_window
== DefaultRootWindow(display
))
1590 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1591 /* FIXME: this is not entirely correct */
1592 XSetInputFocus( display
, data
->whole_window
, RevertToParent
,
1594 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1595 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1596 XInstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1598 wine_tsx11_unlock();
1602 /**********************************************************************
1603 * SetWindowIcon (X11DRV.@)
1605 * hIcon or hIconSm has changed (or is being initialised for the
1606 * first time). Complete the X11 driver-specific initialisation
1607 * and set the window hints.
1609 * This is not entirely correct, may need to create
1610 * an icon window and set the pixmap as a background
1612 void X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
1614 Display
*display
= thread_display();
1615 struct x11drv_win_data
*data
;
1617 if (type
!= ICON_BIG
) return; /* nothing to do here */
1619 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1620 if (!data
->whole_window
) return;
1621 if (!data
->managed
) return;
1625 set_icon_hints( display
, data
, icon
);
1627 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
1628 wine_tsx11_unlock();
1633 /***********************************************************************
1634 * SetWindowRgn (X11DRV.@)
1636 * Assign specified region to window (for non-rectangular windows)
1638 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
1640 struct x11drv_win_data
*data
;
1642 if ((data
= X11DRV_get_win_data( hwnd
)))
1644 sync_window_region( thread_display(), data
, hrgn
);
1646 else if (GetWindowThreadProcessId( hwnd
, NULL
) != GetCurrentThreadId())
1648 FIXME( "not supported on other thread window %p\n", hwnd
);
1649 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1657 /***********************************************************************
1658 * is_netwm_supported
1660 static BOOL
is_netwm_supported( Display
*display
, Atom atom
)
1662 static Atom
*net_supported
;
1663 static int net_supported_count
= -1;
1667 if (net_supported_count
== -1)
1671 unsigned long count
, remaining
;
1673 if (!XGetWindowProperty( display
, DefaultRootWindow(display
), x11drv_atom(_NET_SUPPORTED
), 0,
1674 ~0UL, False
, XA_ATOM
, &type
, &format
, &count
,
1675 &remaining
, (unsigned char **)&net_supported
))
1676 net_supported_count
= get_property_size( format
, count
) / sizeof(Atom
);
1678 net_supported_count
= 0;
1680 wine_tsx11_unlock();
1682 for (i
= 0; i
< net_supported_count
; i
++)
1683 if (net_supported
[i
] == atom
) return TRUE
;
1688 /***********************************************************************
1689 * SysCommand (X11DRV.@)
1691 * Perform WM_SYSCOMMAND handling.
1693 LRESULT
X11DRV_SysCommand( HWND hwnd
, WPARAM wparam
, LPARAM lparam
)
1695 WPARAM hittest
= wparam
& 0x0f;
1699 Display
*display
= thread_display();
1700 struct x11drv_win_data
*data
;
1702 if (!(data
= X11DRV_get_win_data( hwnd
))) return -1;
1703 if (!data
->whole_window
|| !data
->managed
|| !data
->mapped
) return -1;
1705 switch (wparam
& 0xfff0)
1708 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
1709 else dir
= _NET_WM_MOVERESIZE_MOVE
;
1712 /* windows without WS_THICKFRAME are not resizable through the window manager */
1713 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_THICKFRAME
)) return -1;
1717 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
1718 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
1719 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
1720 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
1721 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
1722 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
1723 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
1724 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
1725 default: dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
; break;
1730 /* prevent a simple ALT press+release from activating the system menu,
1731 * as that can get confusing on managed windows */
1732 if ((WCHAR
)lparam
) return -1; /* got an explicit char */
1733 if (GetMenu( hwnd
)) return -1; /* window has a real menu */
1734 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_SYSMENU
)) return -1; /* no system menu */
1735 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam
, lparam
);
1742 if (IsZoomed(hwnd
)) return -1;
1744 if (!is_netwm_supported( display
, x11drv_atom(_NET_WM_MOVERESIZE
) ))
1746 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
1750 dwPoint
= GetMessagePos();
1751 x
= (short)LOWORD(dwPoint
);
1752 y
= (short)HIWORD(dwPoint
);
1754 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd
, x
, y
, dir
);
1756 xev
.xclient
.type
= ClientMessage
;
1757 xev
.xclient
.window
= X11DRV_get_whole_window(hwnd
);
1758 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_MOVERESIZE
);
1759 xev
.xclient
.serial
= 0;
1760 xev
.xclient
.display
= display
;
1761 xev
.xclient
.send_event
= True
;
1762 xev
.xclient
.format
= 32;
1763 xev
.xclient
.data
.l
[0] = x
; /* x coord */
1764 xev
.xclient
.data
.l
[1] = y
; /* y coord */
1765 xev
.xclient
.data
.l
[2] = dir
; /* direction */
1766 xev
.xclient
.data
.l
[3] = 1; /* button */
1767 xev
.xclient
.data
.l
[4] = 0; /* unused */
1769 /* need to ungrab the pointer that may have been automatically grabbed
1770 * with a ButtonPress event */
1772 XUngrabPointer( display
, CurrentTime
);
1773 XSendEvent(display
, root_window
, False
, SubstructureNotifyMask
, &xev
);
1774 wine_tsx11_unlock();