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 #define _NET_WM_STATE_REMOVE 0
66 #define _NET_WM_STATE_ADD 1
67 #define _NET_WM_STATE_TOGGLE 2
69 #define SWP_AGG_NOPOSCHANGE (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
71 /* X context to associate a hwnd to an X window */
72 XContext winContext
= 0;
74 /* X context to associate a struct x11drv_win_data to an hwnd */
75 static XContext win_data_context
;
77 static const char whole_window_prop
[] = "__wine_x11_whole_window";
78 static const char client_window_prop
[]= "__wine_x11_client_window";
79 static const char icon_window_prop
[] = "__wine_x11_icon_window";
80 static const char fbconfig_id_prop
[] = "__wine_x11_fbconfig_id";
81 static const char gl_drawable_prop
[] = "__wine_x11_gl_drawable";
82 static const char pixmap_prop
[] = "__wine_x11_pixmap";
83 static const char managed_prop
[] = "__wine_x11_managed";
85 /***********************************************************************
88 * Check if a given window should be managed
90 static BOOL
is_window_managed( HWND hwnd
, UINT swp_flags
, const RECT
*window_rect
)
92 DWORD style
, ex_style
;
94 if (!managed_mode
) return FALSE
;
96 /* child windows are not managed */
97 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
98 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) return FALSE
;
99 /* activated windows are managed */
100 if (!(swp_flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
))) return TRUE
;
101 if (hwnd
== GetActiveWindow()) return TRUE
;
102 /* windows with caption are managed */
103 if ((style
& WS_CAPTION
) == WS_CAPTION
) return TRUE
;
104 /* tool windows are not managed */
105 ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
106 if (ex_style
& WS_EX_TOOLWINDOW
) return FALSE
;
107 /* windows with thick frame are managed */
108 if (style
& WS_THICKFRAME
) return TRUE
;
109 /* application windows are managed */
110 if (ex_style
& WS_EX_APPWINDOW
) return TRUE
;
111 if (style
& WS_POPUP
)
113 /* popup with sysmenu == caption are managed */
114 if (style
& WS_SYSMENU
) return TRUE
;
115 /* full-screen popup windows are managed */
116 if (window_rect
->left
<= 0 && window_rect
->right
>= screen_width
&&
117 window_rect
->top
<= 0 && window_rect
->bottom
>= screen_height
)
120 /* default: not managed */
125 /***********************************************************************
126 * X11DRV_is_window_rect_mapped
128 * Check if the X whole window should be mapped based on its rectangle
130 static BOOL
is_window_rect_mapped( const RECT
*rect
)
132 /* don't map if rect is off-screen */
133 if (rect
->left
>= virtual_screen_rect
.right
||
134 rect
->top
>= virtual_screen_rect
.bottom
||
135 rect
->right
<= virtual_screen_rect
.left
||
136 rect
->bottom
<= virtual_screen_rect
.top
)
143 /***********************************************************************
144 * is_window_resizable
146 * Check if window should be made resizable by the window manager
148 static inline BOOL
is_window_resizable( struct x11drv_win_data
*data
, DWORD style
)
150 if (style
& WS_THICKFRAME
) return TRUE
;
151 /* Metacity needs the window to be resizable to make it fullscreen */
152 return (data
->whole_rect
.left
<= 0 && data
->whole_rect
.right
>= screen_width
&&
153 data
->whole_rect
.top
<= 0 && data
->whole_rect
.bottom
>= screen_height
);
157 /***********************************************************************
158 * get_mwm_decorations
160 static unsigned long get_mwm_decorations( struct x11drv_win_data
*data
,
161 DWORD style
, DWORD ex_style
)
163 unsigned long ret
= 0;
165 if (!decorated_mode
) return 0;
167 if (IsRectEmpty( &data
->window_rect
)) return 0;
169 if (ex_style
& WS_EX_TOOLWINDOW
) return 0;
171 if ((style
& WS_CAPTION
) == WS_CAPTION
)
173 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
174 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
175 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
176 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
178 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
179 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
180 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
185 /***********************************************************************
186 * get_x11_rect_offset
188 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
190 static void get_x11_rect_offset( struct x11drv_win_data
*data
, RECT
*rect
)
192 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
195 rect
->top
= rect
->bottom
= rect
->left
= rect
->right
= 0;
197 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
198 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
199 decor
= get_mwm_decorations( data
, style
, ex_style
);
201 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
202 if (decor
& MWM_DECOR_BORDER
)
204 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
205 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
208 AdjustWindowRectEx( rect
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
212 /***********************************************************************
213 * get_window_attributes
215 * Fill the window attributes structure for an X window.
217 static int get_window_attributes( Display
*display
, struct x11drv_win_data
*data
,
218 XSetWindowAttributes
*attr
)
220 attr
->override_redirect
= !data
->managed
;
221 attr
->colormap
= X11DRV_PALETTE_PaletteXColormap
;
222 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
223 attr
->cursor
= x11drv_thread_data()->cursor
;
224 attr
->bit_gravity
= NorthWestGravity
;
225 attr
->win_gravity
= StaticGravity
;
226 attr
->backing_store
= NotUseful
;
227 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
228 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
229 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
| KeymapStateMask
);
230 if (data
->managed
) attr
->event_mask
|= StructureNotifyMask
| PropertyChangeMask
;
232 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
| CWCursor
|
233 CWEventMask
| CWBitGravity
| CWBackingStore
);
237 /***********************************************************************
238 * create_client_window
240 static Window
create_client_window( Display
*display
, struct x11drv_win_data
*data
, XVisualInfo
*vis
)
243 XSetWindowAttributes attr
;
246 attr
.bit_gravity
= NorthWestGravity
;
247 attr
.win_gravity
= NorthWestGravity
;
248 attr
.backing_store
= NotUseful
;
249 attr
.event_mask
= (ExposureMask
| PointerMotionMask
|
250 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
251 mask
= CWEventMask
| CWBitGravity
| CWWinGravity
| CWBackingStore
;
253 if ((cx
= data
->client_rect
.right
- data
->client_rect
.left
) <= 0) cx
= 1;
254 if ((cy
= data
->client_rect
.bottom
- data
->client_rect
.top
) <= 0) cy
= 1;
260 attr
.colormap
= XCreateColormap( display
, root_window
, vis
->visual
,
261 (vis
->class == PseudoColor
|| vis
->class == GrayScale
||
262 vis
->class == DirectColor
) ? AllocAll
: AllocNone
);
266 client
= XCreateWindow( display
, data
->whole_window
,
267 data
->client_rect
.left
- data
->whole_rect
.left
,
268 data
->client_rect
.top
- data
->whole_rect
.top
,
269 cx
, cy
, 0, screen_depth
, InputOutput
,
270 vis
? vis
->visual
: visual
, mask
, &attr
);
277 if (data
->client_window
)
279 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
280 if (thread_data
->cursor_window
== data
->client_window
) thread_data
->cursor_window
= None
;
281 XDeleteContext( display
, data
->client_window
, winContext
);
282 XDestroyWindow( display
, data
->client_window
);
284 data
->client_window
= client
;
286 if (data
->colormap
) XFreeColormap( display
, data
->colormap
);
287 data
->colormap
= vis
? attr
.colormap
: 0;
289 XMapWindow( display
, data
->client_window
);
290 XSaveContext( display
, data
->client_window
, winContext
, (char *)data
->hwnd
);
293 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)data
->client_window
);
294 return data
->client_window
;
298 /***********************************************************************
301 * Change the X window attributes when the window style has changed.
303 static void sync_window_style( Display
*display
, struct x11drv_win_data
*data
)
305 if (data
->whole_window
!= root_window
)
307 XSetWindowAttributes attr
;
308 int mask
= get_window_attributes( display
, data
, &attr
);
311 XChangeWindowAttributes( display
, data
->whole_window
, mask
, &attr
);
317 /***********************************************************************
320 * Update the X11 window region.
322 static void sync_window_region( Display
*display
, struct x11drv_win_data
*data
, HRGN hrgn
)
324 #ifdef HAVE_LIBXSHAPE
325 if (!data
->whole_window
) return;
330 XShapeCombineMask( display
, data
->whole_window
, ShapeBounding
, 0, 0, None
, ShapeSet
);
335 RGNDATA
*pRegionData
= X11DRV_GetRegionData( hrgn
, 0 );
339 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
340 data
->window_rect
.left
- data
->whole_rect
.left
,
341 data
->window_rect
.top
- data
->whole_rect
.top
,
342 (XRectangle
*)pRegionData
->Buffer
,
343 pRegionData
->rdh
.nCount
, ShapeSet
, YXBanded
);
345 HeapFree(GetProcessHeap(), 0, pRegionData
);
348 #endif /* HAVE_LIBXSHAPE */
352 /***********************************************************************
355 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
358 char *buffer
, *utf8_buffer
;
361 /* allocate new buffer for window text */
362 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
363 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
364 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
366 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
367 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
369 HeapFree( GetProcessHeap(), 0, buffer
);
372 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
375 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
377 XSetWMName( display
, win
, &prop
);
378 XSetWMIconName( display
, win
, &prop
);
382 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
383 according to the standard
384 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
386 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
387 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
390 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
391 HeapFree( GetProcessHeap(), 0, buffer
);
395 /***********************************************************************
396 * X11DRV_set_win_format
398 BOOL
X11DRV_set_win_format( HWND hwnd
, XID fbconfig_id
)
400 Display
*display
= thread_display();
401 struct x11drv_win_data
*data
;
405 if (!(data
= X11DRV_get_win_data(hwnd
)) &&
406 !(data
= X11DRV_create_win_data(hwnd
))) return FALSE
;
408 if (data
->fbconfig_id
) return FALSE
; /* can't change it twice */
411 vis
= visual_from_fbconfig_id(fbconfig_id
);
413 if (!vis
) return FALSE
;
415 if (data
->whole_window
)
417 Window client
= data
->client_window
;
419 if (vis
->visualid
!= XVisualIDFromVisual(visual
))
421 client
= create_client_window( display
, data
, vis
);
422 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client
, data
->hwnd
, fbconfig_id
);
427 if (client
) goto done
;
431 w
= data
->client_rect
.right
- data
->client_rect
.left
;
432 h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
437 #ifdef SONAME_LIBXCOMPOSITE
440 XSetWindowAttributes attrib
;
441 Window parent
= X11DRV_get_whole_window( GetAncestor( hwnd
, GA_ROOT
));
443 if (!parent
) parent
= root_window
;
445 data
->colormap
= XCreateColormap(display
, parent
, vis
->visual
,
446 (vis
->class == PseudoColor
||
447 vis
->class == GrayScale
||
448 vis
->class == DirectColor
) ?
449 AllocAll
: AllocNone
);
450 attrib
.override_redirect
= True
;
451 attrib
.colormap
= data
->colormap
;
452 XInstallColormap(gdi_display
, attrib
.colormap
);
454 data
->gl_drawable
= XCreateWindow(display
, parent
, -w
, 0, w
, h
, 0,
455 vis
->depth
, InputOutput
, vis
->visual
,
456 CWColormap
| CWOverrideRedirect
,
458 if(data
->gl_drawable
)
460 pXCompositeRedirectWindow(display
, data
->gl_drawable
,
461 CompositeRedirectManual
);
462 XMapWindow(display
, data
->gl_drawable
);
470 WARN("XComposite is not available, using GLXPixmap hack\n");
473 data
->pixmap
= XCreatePixmap(display
, root_window
, w
, h
, vis
->depth
);
481 data
->gl_drawable
= create_glxpixmap(display
, vis
, data
->pixmap
);
482 if(!data
->gl_drawable
)
484 XFreePixmap(display
, data
->pixmap
);
489 if (data
->pixmap
) SetPropA(hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
492 if (!data
->gl_drawable
) return FALSE
;
494 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
495 data
->gl_drawable
, fbconfig_id
);
496 SetPropA(hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
499 data
->fbconfig_id
= fbconfig_id
;
500 SetPropA(hwnd
, fbconfig_id_prop
, (HANDLE
)data
->fbconfig_id
);
504 /* force DCE invalidation */
505 SetWindowPos( hwnd
, 0, 0, 0, 0, 0,
506 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOMOVE
|
507 SWP_NOREDRAW
| SWP_NOSENDCHANGING
| SWP_STATECHANGED
);
511 /***********************************************************************
514 static void sync_gl_drawable(Display
*display
, struct x11drv_win_data
*data
)
516 int w
= data
->client_rect
.right
- data
->client_rect
.left
;
517 int h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
525 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
526 #ifdef SONAME_LIBXCOMPOSITE
530 XMoveResizeWindow(display
, data
->gl_drawable
, -w
, 0, w
, h
);
538 vis
= visual_from_fbconfig_id(data
->fbconfig_id
);
545 pix
= XCreatePixmap(display
, root_window
, w
, h
, vis
->depth
);
548 ERR("Failed to create pixmap for offscreen rendering\n");
554 glxp
= create_glxpixmap(display
, vis
, pix
);
557 ERR("Failed to create drawable for offscreen rendering\n");
558 XFreePixmap(display
, pix
);
566 mark_drawable_dirty(data
->gl_drawable
, glxp
);
568 XFreePixmap(display
, data
->pixmap
);
569 destroy_glxpixmap(display
, data
->gl_drawable
);
570 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp
, data
->gl_drawable
);
573 data
->gl_drawable
= glxp
;
578 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
579 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
583 /***********************************************************************
586 * fill the window changes structure
588 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
592 if (old
->right
- old
->left
!= new->right
- new->left
)
594 if ((changes
->width
= new->right
- new->left
) <= 0) changes
->width
= 1;
597 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
599 if ((changes
->height
= new->bottom
- new->top
) <= 0) changes
->height
= 1;
602 if (old
->left
!= new->left
)
604 changes
->x
= new->left
;
607 if (old
->top
!= new->top
)
609 changes
->y
= new->top
;
616 /***********************************************************************
619 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
621 XSetWindowAttributes attr
;
623 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
624 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
625 attr
.bit_gravity
= NorthWestGravity
;
626 attr
.backing_store
= NotUseful
/*WhenMapped*/;
627 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
630 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
631 GetSystemMetrics( SM_CXICON
),
632 GetSystemMetrics( SM_CYICON
),
635 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
636 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
637 XFlush( display
); /* make sure the window exists before we start painting to it */
640 TRACE( "created %lx\n", data
->icon_window
);
641 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
642 return data
->icon_window
;
647 /***********************************************************************
648 * destroy_icon_window
650 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
652 if (!data
->icon_window
) return;
653 if (x11drv_thread_data()->cursor_window
== data
->icon_window
)
654 x11drv_thread_data()->cursor_window
= None
;
656 XDeleteContext( display
, data
->icon_window
, winContext
);
657 XDestroyWindow( display
, data
->icon_window
);
658 data
->icon_window
= 0;
660 RemovePropA( data
->hwnd
, icon_window_prop
);
664 /***********************************************************************
667 * Set the icon wm hints
669 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
, HICON hIcon
)
671 XWMHints
*hints
= data
->wm_hints
;
673 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
674 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
675 data
->hWMIconBitmap
= 0;
676 data
->hWMIconMask
= 0;
680 if (!data
->icon_window
) create_icon_window( display
, data
);
681 hints
->icon_window
= data
->icon_window
;
682 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
692 GetIconInfo(hIcon
, &ii
);
694 GetObjectA(ii
.hbmMask
, sizeof(bmMask
), &bmMask
);
697 rcMask
.right
= bmMask
.bmWidth
;
698 rcMask
.bottom
= bmMask
.bmHeight
;
700 hDC
= CreateCompatibleDC(0);
701 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
702 InvertRect(hDC
, &rcMask
);
703 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
704 SelectObject(hDC
, hbmOrig
);
707 data
->hWMIconBitmap
= ii
.hbmColor
;
708 data
->hWMIconMask
= ii
.hbmMask
;
710 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
711 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
712 destroy_icon_window( display
, data
);
713 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
718 /***********************************************************************
721 * set the window size hints
723 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
725 XSizeHints
* size_hints
;
727 if (!(size_hints
= XAllocSizeHints())) return;
729 size_hints
->win_gravity
= StaticGravity
;
730 size_hints
->flags
|= PWinGravity
;
732 /* don't update size hints if window is not in normal state */
733 if (!(style
& (WS_MINIMIZE
| WS_MAXIMIZE
)))
735 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
737 size_hints
->x
= data
->whole_rect
.left
;
738 size_hints
->y
= data
->whole_rect
.top
;
739 size_hints
->flags
|= PPosition
;
742 if (!is_window_resizable( data
, style
))
744 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
745 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
746 size_hints
->min_width
= size_hints
->max_width
;
747 size_hints
->min_height
= size_hints
->max_height
;
748 size_hints
->flags
|= PMinSize
| PMaxSize
;
751 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
756 /***********************************************************************
759 * get the name of the current process for setting class hints
761 static char *get_process_name(void)
767 WCHAR module
[MAX_PATH
];
768 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
769 if (len
&& len
< MAX_PATH
)
772 WCHAR
*p
, *appname
= module
;
774 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
775 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
776 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
777 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
779 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
788 /***********************************************************************
789 * set_initial_wm_hints
791 * Set the window manager hints that don't change over the lifetime of a window.
793 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
798 XClassHint
*class_hints
;
799 char *process_name
= get_process_name();
805 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
806 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
807 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
808 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
809 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
812 if ((class_hints
= XAllocClassHint()))
814 static char wine
[] = "Wine";
816 class_hints
->res_name
= process_name
;
817 class_hints
->res_class
= wine
;
818 XSetClassHint( display
, data
->whole_window
, class_hints
);
819 XFree( class_hints
);
822 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
823 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
824 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
826 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
827 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
829 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
830 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
832 data
->wm_hints
= XAllocWMHints();
837 HICON icon
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_BIG
, 0 );
838 if (!icon
) icon
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
);
839 data
->wm_hints
->flags
= 0;
840 set_icon_hints( display
, data
, icon
);
845 /***********************************************************************
848 * Set the window manager hints for a newly-created window
850 static void set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
855 DWORD style
, ex_style
;
858 if (data
->hwnd
== GetDesktopWindow())
860 /* force some styles for the desktop to get the correct decorations */
861 style
= WS_POPUP
| WS_VISIBLE
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
862 ex_style
= WS_EX_APPWINDOW
;
867 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
868 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
869 owner
= GetWindow( data
->hwnd
, GW_OWNER
);
872 /* transient for hint */
875 Window owner_win
= X11DRV_get_whole_window( owner
);
877 XSetTransientForHint( display
, data
->whole_window
, owner_win
);
879 group_leader
= owner_win
;
881 else group_leader
= data
->whole_window
;
886 set_size_hints( display
, data
, style
);
888 /* set the WM_WINDOW_TYPE */
889 if (style
& WS_THICKFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
890 else if (ex_style
& WS_EX_APPWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
891 else if (style
& WS_DLGFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
892 else if (ex_style
& WS_EX_DLGMODALFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
893 else if ((style
& WS_POPUP
) && owner
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
894 #if 0 /* many window managers don't handle utility windows very well */
895 else if (ex_style
& WS_EX_TOOLWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY
);
897 else window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
899 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
900 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
902 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
903 mwm_hints
.decorations
= get_mwm_decorations( data
, style
, ex_style
);
904 mwm_hints
.functions
= MWM_FUNC_MOVE
;
905 if (is_window_resizable( data
, style
)) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
906 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
907 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
908 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
910 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
911 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
912 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
917 data
->wm_hints
->flags
|= InputHint
| StateHint
| WindowGroupHint
;
918 data
->wm_hints
->input
= !(style
& WS_DISABLED
);
919 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
920 data
->wm_hints
->window_group
= group_leader
;
921 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
928 /***********************************************************************
929 * update_net_wm_states
931 void update_net_wm_states( Display
*display
, struct x11drv_win_data
*data
)
933 static const unsigned int state_atoms
[NB_NET_WM_STATES
] =
935 XATOM__NET_WM_STATE_FULLSCREEN
,
936 XATOM__NET_WM_STATE_ABOVE
,
937 XATOM__NET_WM_STATE_MAXIMIZED_VERT
,
938 XATOM__NET_WM_STATE_SKIP_PAGER
,
939 XATOM__NET_WM_STATE_SKIP_TASKBAR
942 DWORD i
, style
, ex_style
, new_state
= 0;
944 if (!data
->managed
) return;
945 if (data
->whole_window
== root_window
) return;
947 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
948 if (data
->whole_rect
.left
<= 0 && data
->whole_rect
.right
>= screen_width
&&
949 data
->whole_rect
.top
<= 0 && data
->whole_rect
.bottom
>= screen_height
)
951 if ((style
& WS_MAXIMIZE
) && (style
& WS_CAPTION
) == WS_CAPTION
)
952 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
953 else if (!(style
& WS_MINIMIZE
))
954 new_state
|= (1 << NET_WM_STATE_FULLSCREEN
);
956 else if (style
& WS_MAXIMIZE
)
957 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
959 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
960 if (ex_style
& WS_EX_TOPMOST
)
961 new_state
|= (1 << NET_WM_STATE_ABOVE
);
962 if (ex_style
& WS_EX_TOOLWINDOW
)
963 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
) | (1 << NET_WM_STATE_SKIP_PAGER
);
964 if (!(ex_style
& WS_EX_APPWINDOW
) && GetWindow( data
->hwnd
, GW_OWNER
))
965 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
);
967 if (!data
->mapped
) /* set the _NET_WM_STATE atom directly */
969 Atom atoms
[NB_NET_WM_STATES
+1];
972 for (i
= count
= 0; i
< NB_NET_WM_STATES
; i
++)
974 if (!(new_state
& (1 << i
))) continue;
975 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
976 i
, data
->hwnd
, data
->whole_window
);
977 atoms
[count
++] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
978 if (state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
)
979 atoms
[count
++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
);
982 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_STATE
), XA_ATOM
,
983 32, PropModeReplace
, (unsigned char *)atoms
, count
);
986 else /* ask the window manager to do it for us */
990 xev
.xclient
.type
= ClientMessage
;
991 xev
.xclient
.window
= data
->whole_window
;
992 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
993 xev
.xclient
.serial
= 0;
994 xev
.xclient
.display
= display
;
995 xev
.xclient
.send_event
= True
;
996 xev
.xclient
.format
= 32;
997 xev
.xclient
.data
.l
[3] = 1;
999 for (i
= 0; i
< NB_NET_WM_STATES
; i
++)
1001 if (!((data
->net_wm_state
^ new_state
) & (1 << i
))) continue; /* unchanged */
1003 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1004 i
, data
->hwnd
, data
->whole_window
,
1005 (new_state
& (1 << i
)) != 0, (data
->net_wm_state
& (1 << i
)) != 0 );
1007 xev
.xclient
.data
.l
[0] = (new_state
& (1 << i
)) ? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
1008 xev
.xclient
.data
.l
[1] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
1009 xev
.xclient
.data
.l
[2] = ((state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
) ?
1010 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
) : 0);
1012 XSendEvent( display
, root_window
, False
,
1013 SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
1014 wine_tsx11_unlock();
1017 data
->net_wm_state
= new_state
;
1021 /***********************************************************************
1024 static void set_xembed_flags( Display
*display
, struct x11drv_win_data
*data
, unsigned long flags
)
1026 unsigned long info
[2];
1028 info
[0] = 0; /* protocol version */
1031 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_XEMBED_INFO
),
1032 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
, (unsigned char*)info
, 2 );
1033 wine_tsx11_unlock();
1037 /***********************************************************************
1040 static void map_window( Display
*display
, struct x11drv_win_data
*data
, DWORD new_style
)
1042 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1044 wait_for_withdrawn_state( display
, data
, TRUE
);
1046 if (!data
->embedded
)
1048 update_net_wm_states( display
, data
);
1049 sync_window_style( display
, data
);
1051 XMapWindow( display
, data
->whole_window
);
1052 wine_tsx11_unlock();
1054 else set_xembed_flags( display
, data
, XEMBED_MAPPED
);
1056 data
->mapped
= TRUE
;
1057 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
1061 /***********************************************************************
1064 static void unmap_window( Display
*display
, struct x11drv_win_data
*data
)
1066 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1068 if (!data
->embedded
)
1070 wait_for_withdrawn_state( display
, data
, FALSE
);
1072 if (data
->managed
) XWithdrawWindow( display
, data
->whole_window
, DefaultScreen(display
) );
1073 else XUnmapWindow( display
, data
->whole_window
);
1074 wine_tsx11_unlock();
1076 else set_xembed_flags( display
, data
, 0 );
1078 data
->mapped
= FALSE
;
1079 data
->net_wm_state
= 0;
1083 /***********************************************************************
1084 * make_window_embedded
1086 void make_window_embedded( Display
*display
, struct x11drv_win_data
*data
)
1090 /* the window cannot be mapped before being embedded */
1091 unmap_window( display
, data
);
1092 data
->embedded
= TRUE
;
1093 map_window( display
, data
, 0 );
1097 data
->embedded
= TRUE
;
1098 set_xembed_flags( display
, data
, 0 );
1103 /***********************************************************************
1104 * X11DRV_window_to_X_rect
1106 * Convert a rect from client to X window coordinates
1108 void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1112 if (!data
->managed
) return;
1113 if (IsRectEmpty( rect
)) return;
1115 get_x11_rect_offset( data
, &rc
);
1117 rect
->left
-= rc
.left
;
1118 rect
->right
-= rc
.right
;
1119 rect
->top
-= rc
.top
;
1120 rect
->bottom
-= rc
.bottom
;
1121 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1122 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1126 /***********************************************************************
1127 * X11DRV_X_to_window_rect
1129 * Opposite of X11DRV_window_to_X_rect
1131 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1135 if (!data
->managed
) return;
1136 if (IsRectEmpty( rect
)) return;
1138 get_x11_rect_offset( data
, &rc
);
1140 rect
->left
+= rc
.left
;
1141 rect
->right
+= rc
.right
;
1142 rect
->top
+= rc
.top
;
1143 rect
->bottom
+= rc
.bottom
;
1144 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1145 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1149 /***********************************************************************
1150 * sync_window_position
1152 * Synchronize the X window position with the Windows one
1154 static void sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
1155 UINT swp_flags
, const RECT
*old_client_rect
,
1156 const RECT
*old_whole_rect
)
1158 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1159 XWindowChanges changes
;
1160 unsigned int mask
= 0;
1162 if (data
->managed
&& data
->iconic
) return;
1164 /* resizing a managed maximized window is not allowed */
1165 if (!(style
& WS_MAXIMIZE
) || !data
->managed
)
1167 if ((changes
.width
= data
->whole_rect
.right
- data
->whole_rect
.left
) <= 0) changes
.width
= 1;
1168 if ((changes
.height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
) <= 0) changes
.height
= 1;
1169 mask
|= CWWidth
| CWHeight
;
1172 /* only the size is allowed to change for the desktop window */
1173 if (data
->whole_window
!= root_window
)
1175 changes
.x
= data
->whole_rect
.left
- virtual_screen_rect
.left
;
1176 changes
.y
= data
->whole_rect
.top
- virtual_screen_rect
.top
;
1180 if (!(swp_flags
& SWP_NOZORDER
))
1182 /* find window that this one must be after */
1183 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
1184 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
1185 prev
= GetWindow( prev
, GW_HWNDPREV
);
1186 if (!prev
) /* top child */
1188 changes
.stack_mode
= Above
;
1189 mask
|= CWStackMode
;
1191 /* should use stack_mode Below but most window managers don't get it right */
1192 /* and Above with a sibling doesn't work so well either, so we ignore it */
1195 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
1196 data
->hwnd
, data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1197 data
->whole_rect
.right
- data
->whole_rect
.left
,
1198 data
->whole_rect
.bottom
- data
->whole_rect
.top
, changes
.sibling
, mask
);
1201 set_size_hints( display
, data
, style
);
1202 XReconfigureWMWindow( display
, data
->whole_window
,
1203 DefaultScreen(display
), mask
, &changes
);
1204 wine_tsx11_unlock();
1208 /***********************************************************************
1209 * sync_client_position
1211 * Synchronize the X client window position with the Windows one
1213 static void sync_client_position( Display
*display
, struct x11drv_win_data
*data
,
1214 UINT swp_flags
, const RECT
*old_client_rect
,
1215 const RECT
*old_whole_rect
)
1218 XWindowChanges changes
;
1219 RECT old
= *old_client_rect
;
1220 RECT
new = data
->client_rect
;
1222 OffsetRect( &old
, -old_whole_rect
->left
, -old_whole_rect
->top
);
1223 OffsetRect( &new, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
1224 if (!(mask
= get_window_changes( &changes
, &old
, &new ))) return;
1226 if (data
->client_window
)
1228 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1229 data
->client_window
, new.left
, new.top
,
1230 new.right
- new.left
, new.bottom
- new.top
, mask
);
1232 XConfigureWindow( display
, data
->client_window
, mask
, &changes
);
1233 wine_tsx11_unlock();
1236 if (data
->gl_drawable
&& (mask
& (CWWidth
|CWHeight
))) sync_gl_drawable( display
, data
);
1240 /***********************************************************************
1243 * Move the window bits when a window is moved.
1245 static void move_window_bits( struct x11drv_win_data
*data
, const RECT
*old_rect
, const RECT
*new_rect
,
1246 const RECT
*old_client_rect
)
1248 RECT src_rect
= *old_rect
;
1249 RECT dst_rect
= *new_rect
;
1250 HDC hdc_src
, hdc_dst
;
1255 if (!data
->whole_window
)
1257 OffsetRect( &dst_rect
, -data
->window_rect
.left
, -data
->window_rect
.top
);
1258 parent
= GetAncestor( data
->hwnd
, GA_PARENT
);
1259 hdc_src
= GetDCEx( parent
, 0, DCX_CACHE
);
1260 hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
1264 OffsetRect( &dst_rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
1265 /* make src rect relative to the old position of the window */
1266 OffsetRect( &src_rect
, -old_client_rect
->left
, -old_client_rect
->top
);
1267 if (dst_rect
.left
== src_rect
.left
&& dst_rect
.top
== src_rect
.top
) return;
1268 hdc_src
= hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
);
1271 code
= X11DRV_START_EXPOSURES
;
1272 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
1274 TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n",
1275 data
->hwnd
, data
->whole_window
, data
->client_window
,
1276 wine_dbgstr_rect(&src_rect
), wine_dbgstr_rect(&dst_rect
) );
1277 BitBlt( hdc_dst
, dst_rect
.left
, dst_rect
.top
,
1278 dst_rect
.right
- dst_rect
.left
, dst_rect
.bottom
- dst_rect
.top
,
1279 hdc_src
, src_rect
.left
, src_rect
.top
, SRCCOPY
);
1281 code
= X11DRV_END_EXPOSURES
;
1282 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, sizeof(rgn
), (LPSTR
)&rgn
);
1284 ReleaseDC( data
->hwnd
, hdc_dst
);
1285 if (hdc_src
!= hdc_dst
) ReleaseDC( parent
, hdc_src
);
1289 if (!data
->whole_window
)
1291 /* map region to client rect since we are using DCX_WINDOW */
1292 OffsetRgn( rgn
, data
->window_rect
.left
- data
->client_rect
.left
,
1293 data
->window_rect
.top
- data
->client_rect
.top
);
1294 RedrawWindow( data
->hwnd
, NULL
, rgn
,
1295 RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
1297 else RedrawWindow( data
->hwnd
, NULL
, rgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1298 DeleteObject( rgn
);
1303 /**********************************************************************
1304 * create_whole_window
1306 * Create the whole X window for a given window
1308 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1311 XSetWindowAttributes attr
;
1315 if (!(cx
= data
->window_rect
.right
- data
->window_rect
.left
)) cx
= 1;
1316 if (!(cy
= data
->window_rect
.bottom
- data
->window_rect
.top
)) cy
= 1;
1318 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1320 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1321 data
->managed
= TRUE
;
1322 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1325 mask
= get_window_attributes( display
, data
, &attr
);
1329 data
->whole_rect
= data
->window_rect
;
1330 data
->whole_window
= XCreateWindow( display
, root_window
,
1331 data
->window_rect
.left
- virtual_screen_rect
.left
,
1332 data
->window_rect
.top
- virtual_screen_rect
.top
,
1333 cx
, cy
, 0, screen_depth
, InputOutput
,
1334 visual
, mask
, &attr
);
1336 if (data
->whole_window
) XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1337 wine_tsx11_unlock();
1339 if (!data
->whole_window
) return 0;
1341 if (!create_client_window( display
, data
, NULL
))
1344 XDeleteContext( display
, data
->whole_window
, winContext
);
1345 XDestroyWindow( display
, data
->whole_window
);
1346 data
->whole_window
= 0;
1347 wine_tsx11_unlock();
1351 set_initial_wm_hints( display
, data
);
1352 set_wm_hints( display
, data
);
1354 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1356 /* set the window text */
1357 if (!InternalGetWindowText( data
->hwnd
, text
, sizeof(text
)/sizeof(WCHAR
) )) text
[0] = 0;
1358 sync_window_text( display
, data
->whole_window
, text
);
1360 /* set the window region */
1361 if ((hrgn
= CreateRectRgn( 0, 0, 0, 0 )))
1363 if (GetWindowRgn( data
->hwnd
, hrgn
) != ERROR
) sync_window_region( display
, data
, hrgn
);
1364 DeleteObject( hrgn
);
1367 XFlush( display
); /* make sure the window exists before we start painting to it */
1368 wine_tsx11_unlock();
1369 return data
->whole_window
;
1373 /**********************************************************************
1374 * destroy_whole_window
1376 * Destroy the whole X window for a given window.
1378 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
, BOOL already_destroyed
)
1380 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1382 if (!data
->whole_window
) return;
1384 TRACE( "win %p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1385 if (thread_data
->cursor_window
== data
->whole_window
||
1386 thread_data
->cursor_window
== data
->client_window
)
1387 thread_data
->cursor_window
= None
;
1389 XDeleteContext( display
, data
->whole_window
, winContext
);
1390 XDeleteContext( display
, data
->client_window
, winContext
);
1391 if (!already_destroyed
) XDestroyWindow( display
, data
->whole_window
);
1392 data
->whole_window
= data
->client_window
= 0;
1393 data
->wm_state
= WithdrawnState
;
1394 data
->net_wm_state
= 0;
1395 data
->mapped
= FALSE
;
1398 XUnsetICFocus( data
->xic
);
1399 XDestroyIC( data
->xic
);
1402 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1404 XFree( data
->wm_hints
);
1405 data
->wm_hints
= NULL
;
1406 wine_tsx11_unlock();
1407 RemovePropA( data
->hwnd
, whole_window_prop
);
1408 RemovePropA( data
->hwnd
, client_window_prop
);
1412 /*****************************************************************
1413 * SetWindowText (X11DRV.@)
1415 void X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1417 Display
*display
= thread_display();
1420 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(display
))
1421 sync_window_text( display
, win
, text
);
1425 /***********************************************************************
1426 * SetWindowStyle (X11DRV.@)
1428 * Update the X state of a window to reflect a style change
1430 void X11DRV_SetWindowStyle( HWND hwnd
, DWORD old_style
)
1432 Display
*display
= thread_display();
1433 struct x11drv_win_data
*data
;
1434 DWORD new_style
, changed
;
1436 if (hwnd
== GetDesktopWindow()) return;
1437 new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1438 changed
= new_style
^ old_style
;
1440 if ((changed
& WS_VISIBLE
) && (new_style
& WS_VISIBLE
))
1442 /* we don't unmap windows, that causes trouble with the window manager */
1443 if (!(data
= X11DRV_get_win_data( hwnd
)) &&
1444 !(data
= X11DRV_create_win_data( hwnd
))) return;
1446 if (data
->whole_window
&& is_window_rect_mapped( &data
->window_rect
))
1448 set_wm_hints( display
, data
);
1449 if (!data
->mapped
) map_window( display
, data
, new_style
);
1453 if (changed
& WS_DISABLED
)
1455 data
= X11DRV_get_win_data( hwnd
);
1456 if (data
&& data
->wm_hints
)
1459 data
->wm_hints
->input
= !(new_style
& WS_DISABLED
);
1460 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
1461 wine_tsx11_unlock();
1467 /***********************************************************************
1468 * DestroyWindow (X11DRV.@)
1470 void X11DRV_DestroyWindow( HWND hwnd
)
1472 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1473 Display
*display
= thread_data
->display
;
1474 struct x11drv_win_data
*data
;
1476 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1480 destroy_glxpixmap(display
, data
->gl_drawable
);
1482 XFreePixmap(display
, data
->pixmap
);
1483 wine_tsx11_unlock();
1485 else if (data
->gl_drawable
)
1488 XDestroyWindow(display
, data
->gl_drawable
);
1489 wine_tsx11_unlock();
1492 destroy_whole_window( display
, data
, FALSE
);
1493 destroy_icon_window( display
, data
);
1498 XFreeColormap( display
, data
->colormap
);
1499 wine_tsx11_unlock();
1502 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1503 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1504 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1506 XDeleteContext( display
, (XID
)hwnd
, win_data_context
);
1507 wine_tsx11_unlock();
1508 HeapFree( GetProcessHeap(), 0, data
);
1512 /***********************************************************************
1513 * X11DRV_DestroyNotify
1515 void X11DRV_DestroyNotify( HWND hwnd
, XEvent
*event
)
1517 Display
*display
= event
->xdestroywindow
.display
;
1518 struct x11drv_win_data
*data
;
1520 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1522 FIXME( "window %p/%lx destroyed from the outside\n", hwnd
, data
->whole_window
);
1523 destroy_whole_window( display
, data
, TRUE
);
1527 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1529 struct x11drv_win_data
*data
;
1531 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
1535 if (!winContext
) winContext
= XUniqueContext();
1536 if (!win_data_context
) win_data_context
= XUniqueContext();
1537 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1538 wine_tsx11_unlock();
1544 /* initialize the desktop window id in the desktop manager process */
1545 static struct x11drv_win_data
*create_desktop_win_data( Display
*display
, HWND hwnd
)
1547 struct x11drv_win_data
*data
;
1550 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1552 visualid
= XVisualIDFromVisual(visual
);
1553 wine_tsx11_unlock();
1554 data
->whole_window
= data
->client_window
= root_window
;
1555 data
->managed
= TRUE
;
1556 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1557 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1558 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)root_window
);
1559 set_initial_wm_hints( display
, data
);
1563 /**********************************************************************
1564 * CreateDesktopWindow (X11DRV.@)
1566 BOOL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1568 unsigned int width
, height
;
1570 /* retrieve the real size of the desktop */
1571 SERVER_START_REQ( get_window_rectangles
)
1574 wine_server_call( req
);
1575 width
= reply
->window
.right
- reply
->window
.left
;
1576 height
= reply
->window
.bottom
- reply
->window
.top
;
1580 if (!width
&& !height
) /* not initialized yet */
1582 SERVER_START_REQ( set_window_pos
)
1586 req
->flags
= SWP_NOZORDER
;
1587 req
->window
.left
= virtual_screen_rect
.left
;
1588 req
->window
.top
= virtual_screen_rect
.top
;
1589 req
->window
.right
= virtual_screen_rect
.right
;
1590 req
->window
.bottom
= virtual_screen_rect
.bottom
;
1591 req
->client
= req
->window
;
1592 wine_server_call( req
);
1598 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1599 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1605 /**********************************************************************
1606 * CreateWindow (X11DRV.@)
1608 BOOL
X11DRV_CreateWindow( HWND hwnd
)
1610 Display
*display
= thread_display();
1612 if (hwnd
== GetDesktopWindow() && root_window
!= DefaultRootWindow( display
))
1614 /* the desktop win data can't be created lazily */
1615 if (!create_desktop_win_data( display
, hwnd
)) return FALSE
;
1621 /***********************************************************************
1622 * X11DRV_get_win_data
1624 * Return the X11 data structure associated with a window.
1626 struct x11drv_win_data
*X11DRV_get_win_data( HWND hwnd
)
1630 if (!hwnd
|| XFindContext( thread_display(), (XID
)hwnd
, win_data_context
, &data
)) data
= NULL
;
1631 return (struct x11drv_win_data
*)data
;
1635 /***********************************************************************
1636 * X11DRV_create_win_data
1638 * Create an X11 data window structure for an existing window.
1640 struct x11drv_win_data
*X11DRV_create_win_data( HWND hwnd
)
1642 Display
*display
= thread_display();
1643 struct x11drv_win_data
*data
;
1646 if (!(parent
= GetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop */
1647 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1649 GetWindowRect( hwnd
, &data
->window_rect
);
1650 MapWindowPoints( 0, parent
, (POINT
*)&data
->window_rect
, 2 );
1651 data
->whole_rect
= data
->window_rect
;
1652 GetClientRect( hwnd
, &data
->client_rect
);
1653 MapWindowPoints( hwnd
, parent
, (POINT
*)&data
->client_rect
, 2 );
1655 if (parent
== GetDesktopWindow())
1657 if (!create_whole_window( display
, data
))
1659 HeapFree( GetProcessHeap(), 0, data
);
1662 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1663 hwnd
, data
->whole_window
, data
->client_window
, wine_dbgstr_rect( &data
->window_rect
),
1664 wine_dbgstr_rect( &data
->whole_rect
), wine_dbgstr_rect( &data
->client_rect
));
1670 /***********************************************************************
1671 * X11DRV_get_whole_window
1673 * Return the X window associated with the full area of a window
1675 Window
X11DRV_get_whole_window( HWND hwnd
)
1677 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1681 if (hwnd
== GetDesktopWindow()) return root_window
;
1682 return (Window
)GetPropA( hwnd
, whole_window_prop
);
1684 return data
->whole_window
;
1688 /***********************************************************************
1689 * X11DRV_get_client_window
1691 * Return the X window associated with the client area of a window
1693 Window
X11DRV_get_client_window( HWND hwnd
)
1695 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1699 if (hwnd
== GetDesktopWindow()) return root_window
;
1700 return (Window
)GetPropA( hwnd
, client_window_prop
);
1702 return data
->client_window
;
1706 /***********************************************************************
1709 * Return the X input context associated with a window
1711 XIC
X11DRV_get_ic( HWND hwnd
)
1713 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1716 if (!data
) return 0;
1717 if (data
->xic
) return data
->xic
;
1718 if (!(xim
= x11drv_thread_data()->xim
)) return 0;
1719 return X11DRV_CreateIC( xim
, data
);
1723 /***********************************************************************
1724 * X11DRV_GetDC (X11DRV.@)
1726 void X11DRV_GetDC( HDC hdc
, HWND hwnd
, HWND top
, const RECT
*win_rect
,
1727 const RECT
*top_rect
, DWORD flags
)
1729 struct x11drv_escape_set_drawable escape
;
1730 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1732 escape
.code
= X11DRV_SET_DRAWABLE
;
1733 escape
.mode
= IncludeInferiors
;
1734 escape
.fbconfig_id
= 0;
1735 escape
.gl_drawable
= 0;
1738 if (top
== hwnd
&& data
&& IsIconic( hwnd
) && data
->icon_window
)
1740 escape
.drawable
= data
->icon_window
;
1742 else if (top
== hwnd
&& (flags
& DCX_WINDOW
))
1744 escape
.drawable
= data
? data
->whole_window
: X11DRV_get_whole_window( hwnd
);
1748 escape
.drawable
= X11DRV_get_client_window( top
);
1749 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1750 escape
.gl_drawable
= data
? data
->gl_drawable
: (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
1751 escape
.pixmap
= data
? data
->pixmap
: (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
1752 if (flags
& DCX_CLIPCHILDREN
) escape
.mode
= ClipByChildren
;
1755 escape
.dc_rect
.left
= win_rect
->left
- top_rect
->left
;
1756 escape
.dc_rect
.top
= win_rect
->top
- top_rect
->top
;
1757 escape
.dc_rect
.right
= win_rect
->right
- top_rect
->left
;
1758 escape
.dc_rect
.bottom
= win_rect
->bottom
- top_rect
->top
;
1759 escape
.drawable_rect
.left
= top_rect
->left
;
1760 escape
.drawable_rect
.top
= top_rect
->top
;
1761 escape
.drawable_rect
.right
= top_rect
->right
;
1762 escape
.drawable_rect
.bottom
= top_rect
->bottom
;
1764 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1768 /***********************************************************************
1769 * X11DRV_ReleaseDC (X11DRV.@)
1771 void X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
1773 struct x11drv_escape_set_drawable escape
;
1775 escape
.code
= X11DRV_SET_DRAWABLE
;
1776 escape
.drawable
= root_window
;
1777 escape
.mode
= IncludeInferiors
;
1778 escape
.drawable_rect
= virtual_screen_rect
;
1779 SetRect( &escape
.dc_rect
, 0, 0, virtual_screen_rect
.right
- virtual_screen_rect
.left
,
1780 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
);
1781 escape
.fbconfig_id
= 0;
1782 escape
.gl_drawable
= 0;
1784 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1788 /***********************************************************************
1789 * SetCapture (X11DRV.@)
1791 void X11DRV_SetCapture( HWND hwnd
, UINT flags
)
1793 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1795 if (!(flags
& (GUI_INMOVESIZE
| GUI_INMENUMODE
))) return;
1799 Window grab_win
= X11DRV_get_client_window( GetAncestor( hwnd
, GA_ROOT
) );
1801 if (!grab_win
) return;
1803 XFlush( gdi_display
);
1804 XGrabPointer( thread_data
->display
, grab_win
, False
,
1805 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1806 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
);
1807 wine_tsx11_unlock();
1808 thread_data
->grab_window
= grab_win
;
1810 else /* release capture */
1813 XFlush( gdi_display
);
1814 XUngrabPointer( thread_data
->display
, CurrentTime
);
1815 wine_tsx11_unlock();
1816 thread_data
->grab_window
= None
;
1821 /*****************************************************************
1822 * SetParent (X11DRV.@)
1824 void X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
1826 Display
*display
= thread_display();
1827 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1830 if (parent
== old_parent
) return;
1832 if (parent
!= GetDesktopWindow()) /* a child window */
1834 if (old_parent
== GetDesktopWindow())
1836 /* destroy the old X windows */
1837 destroy_whole_window( display
, data
, FALSE
);
1838 destroy_icon_window( display
, data
);
1841 data
->managed
= FALSE
;
1842 RemovePropA( data
->hwnd
, managed_prop
);
1846 else /* new top level window */
1848 /* FIXME: we ignore errors since we can't really recover anyway */
1849 create_whole_window( display
, data
);
1854 /*****************************************************************
1855 * SetFocus (X11DRV.@)
1858 * Explicit colormap management seems to work only with OLVWM.
1860 void X11DRV_SetFocus( HWND hwnd
)
1862 Display
*display
= thread_display();
1863 struct x11drv_win_data
*data
;
1864 XWindowChanges changes
;
1866 /* If setting the focus to 0, uninstall the colormap */
1867 if (!hwnd
&& root_window
== DefaultRootWindow(display
))
1870 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1871 XUninstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1872 wine_tsx11_unlock();
1876 hwnd
= GetAncestor( hwnd
, GA_ROOT
);
1878 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1879 if (data
->managed
|| !data
->whole_window
) return;
1881 /* Set X focus and install colormap */
1883 changes
.stack_mode
= Above
;
1884 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
1885 if (root_window
== DefaultRootWindow(display
))
1887 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1888 /* FIXME: this is not entirely correct */
1889 XSetInputFocus( display
, data
->whole_window
, RevertToParent
,
1891 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1892 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1893 XInstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1895 wine_tsx11_unlock();
1899 /***********************************************************************
1900 * SetWindowPos (X11DRV.@)
1902 void X11DRV_SetWindowPos( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
1903 const RECT
*rectWindow
, const RECT
*rectClient
,
1904 const RECT
*visible_rect
, const RECT
*valid_rects
)
1906 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1907 Display
*display
= thread_data
->display
;
1908 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1909 DWORD new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1910 RECT old_window_rect
, old_whole_rect
, old_client_rect
;
1915 /* create the win data if the window is being made visible */
1916 if (!(new_style
& WS_VISIBLE
)) return;
1917 if (!(data
= X11DRV_create_win_data( hwnd
))) return;
1920 /* check if we need to switch the window to managed */
1921 if (!data
->managed
&& data
->whole_window
&& is_window_managed( hwnd
, swp_flags
, rectWindow
))
1923 TRACE( "making win %p/%lx managed\n", hwnd
, data
->whole_window
);
1924 if (data
->mapped
) unmap_window( display
, data
);
1925 data
->managed
= TRUE
;
1926 SetPropA( hwnd
, managed_prop
, (HANDLE
)1 );
1929 old_window_rect
= data
->window_rect
;
1930 old_whole_rect
= data
->whole_rect
;
1931 old_client_rect
= data
->client_rect
;
1932 data
->window_rect
= *rectWindow
;
1933 data
->whole_rect
= *rectWindow
;
1934 data
->client_rect
= *rectClient
;
1935 X11DRV_window_to_X_rect( data
, &data
->whole_rect
);
1936 if (memcmp( visible_rect
, &data
->whole_rect
, sizeof(RECT
) ))
1938 TRACE( "%p: need to update visible rect %s -> %s\n", hwnd
,
1939 wine_dbgstr_rect(visible_rect
), wine_dbgstr_rect(&data
->whole_rect
) );
1940 SERVER_START_REQ( set_window_visible_rect
)
1943 req
->flags
= swp_flags
;
1944 req
->visible
.left
= data
->whole_rect
.left
;
1945 req
->visible
.top
= data
->whole_rect
.top
;
1946 req
->visible
.right
= data
->whole_rect
.right
;
1947 req
->visible
.bottom
= data
->whole_rect
.bottom
;
1948 wine_server_call( req
);
1953 TRACE( "win %p window %s client %s style %08x flags %08x\n",
1954 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
, swp_flags
);
1956 if (!IsRectEmpty( &valid_rects
[0] ))
1958 int x_offset
= old_whole_rect
.left
- data
->whole_rect
.left
;
1959 int y_offset
= old_whole_rect
.top
- data
->whole_rect
.top
;
1961 /* if all that happened is that the whole window moved, copy everything */
1962 if (!(swp_flags
& SWP_FRAMECHANGED
) &&
1963 old_whole_rect
.right
- data
->whole_rect
.right
== x_offset
&&
1964 old_whole_rect
.bottom
- data
->whole_rect
.bottom
== y_offset
&&
1965 old_client_rect
.left
- data
->client_rect
.left
== x_offset
&&
1966 old_client_rect
.right
- data
->client_rect
.right
== x_offset
&&
1967 old_client_rect
.top
- data
->client_rect
.top
== y_offset
&&
1968 old_client_rect
.bottom
- data
->client_rect
.bottom
== y_offset
&&
1969 !memcmp( &valid_rects
[0], &data
->client_rect
, sizeof(RECT
) ))
1971 /* if we have an X window the bits will be moved by the X server */
1972 if (!data
->whole_window
)
1973 move_window_bits( data
, &old_whole_rect
, &data
->whole_rect
, &old_client_rect
);
1976 move_window_bits( data
, &valid_rects
[1], &valid_rects
[0], &old_client_rect
);
1980 XFlush( gdi_display
); /* make sure painting is done before we move the window */
1981 wine_tsx11_unlock();
1983 sync_client_position( display
, data
, swp_flags
, &old_client_rect
, &old_whole_rect
);
1985 if (!data
->whole_window
) return;
1987 /* check if we are currently processing an event relevant to this window */
1989 if (thread_data
->current_event
&& thread_data
->current_event
->xany
.window
== data
->whole_window
)
1990 event_type
= thread_data
->current_event
->type
;
1992 if (event_type
!= ConfigureNotify
&& event_type
!= PropertyNotify
)
1993 event_type
= 0; /* ignore other events */
1995 if (data
->mapped
&& (!(new_style
& WS_VISIBLE
) ||
1996 (!event_type
&& !is_window_rect_mapped( rectWindow
))))
1997 unmap_window( display
, data
);
1999 /* don't change position if we are about to minimize or maximize a managed window */
2001 !(data
->managed
&& (swp_flags
& SWP_STATECHANGED
) && (new_style
& (WS_MINIMIZE
|WS_MAXIMIZE
))))
2002 sync_window_position( display
, data
, swp_flags
, &old_client_rect
, &old_whole_rect
);
2004 if ((new_style
& WS_VISIBLE
) &&
2005 ((new_style
& WS_MINIMIZE
) || is_window_rect_mapped( rectWindow
)))
2007 if (!data
->mapped
|| (swp_flags
& (SWP_FRAMECHANGED
|SWP_STATECHANGED
)))
2008 set_wm_hints( display
, data
);
2012 map_window( display
, data
, new_style
);
2014 else if ((swp_flags
& SWP_STATECHANGED
) && (!data
->iconic
!= !(new_style
& WS_MINIMIZE
)))
2016 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
2017 TRACE( "changing win %p iconic state to %u\n", data
->hwnd
, data
->iconic
);
2020 XIconifyWindow( display
, data
->whole_window
, DefaultScreen(display
) );
2021 else if (is_window_rect_mapped( rectWindow
))
2022 XMapWindow( display
, data
->whole_window
);
2023 wine_tsx11_unlock();
2024 update_net_wm_states( display
, data
);
2026 else if (!event_type
)
2028 update_net_wm_states( display
, data
);
2033 XFlush( display
); /* make sure changes are done before we start painting again */
2034 wine_tsx11_unlock();
2038 /**********************************************************************
2039 * SetWindowIcon (X11DRV.@)
2041 * hIcon or hIconSm has changed (or is being initialised for the
2042 * first time). Complete the X11 driver-specific initialisation
2043 * and set the window hints.
2045 * This is not entirely correct, may need to create
2046 * an icon window and set the pixmap as a background
2048 void X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
2050 Display
*display
= thread_display();
2051 struct x11drv_win_data
*data
;
2053 if (type
!= ICON_BIG
) return; /* nothing to do here */
2055 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
2056 if (!data
->whole_window
) return;
2057 if (!data
->managed
) return;
2061 set_icon_hints( display
, data
, icon
);
2063 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
2064 wine_tsx11_unlock();
2069 /***********************************************************************
2070 * SetWindowRgn (X11DRV.@)
2072 * Assign specified region to window (for non-rectangular windows)
2074 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
2076 struct x11drv_win_data
*data
;
2078 if ((data
= X11DRV_get_win_data( hwnd
)))
2080 sync_window_region( thread_display(), data
, hrgn
);
2082 else if (GetWindowThreadProcessId( hwnd
, NULL
) != GetCurrentThreadId())
2084 FIXME( "not supported on other thread window %p\n", hwnd
);
2085 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2093 /***********************************************************************
2094 * is_netwm_supported
2096 static BOOL
is_netwm_supported( Display
*display
, Atom atom
)
2098 static Atom
*net_supported
;
2099 static int net_supported_count
= -1;
2103 if (net_supported_count
== -1)
2107 unsigned long count
, remaining
;
2109 if (!XGetWindowProperty( display
, DefaultRootWindow(display
), x11drv_atom(_NET_SUPPORTED
), 0,
2110 ~0UL, False
, XA_ATOM
, &type
, &format
, &count
,
2111 &remaining
, (unsigned char **)&net_supported
))
2112 net_supported_count
= get_property_size( format
, count
) / sizeof(Atom
);
2114 net_supported_count
= 0;
2116 wine_tsx11_unlock();
2118 for (i
= 0; i
< net_supported_count
; i
++)
2119 if (net_supported
[i
] == atom
) return TRUE
;
2124 /***********************************************************************
2125 * SysCommand (X11DRV.@)
2127 * Perform WM_SYSCOMMAND handling.
2129 LRESULT
X11DRV_SysCommand( HWND hwnd
, WPARAM wparam
, LPARAM lparam
)
2131 WPARAM hittest
= wparam
& 0x0f;
2135 Display
*display
= thread_display();
2136 struct x11drv_win_data
*data
;
2138 if (!(data
= X11DRV_get_win_data( hwnd
))) return -1;
2139 if (!data
->whole_window
|| !data
->managed
|| !data
->mapped
) return -1;
2141 switch (wparam
& 0xfff0)
2144 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
2145 else dir
= _NET_WM_MOVERESIZE_MOVE
;
2148 /* windows without WS_THICKFRAME are not resizable through the window manager */
2149 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_THICKFRAME
)) return -1;
2153 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
2154 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
2155 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
2156 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
2157 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
2158 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
2159 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
2160 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
2161 default: dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
; break;
2166 /* prevent a simple ALT press+release from activating the system menu,
2167 * as that can get confusing on managed windows */
2168 if ((WCHAR
)lparam
) return -1; /* got an explicit char */
2169 if (GetMenu( hwnd
)) return -1; /* window has a real menu */
2170 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_SYSMENU
)) return -1; /* no system menu */
2171 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam
, lparam
);
2178 if (IsZoomed(hwnd
)) return -1;
2180 if (!is_netwm_supported( display
, x11drv_atom(_NET_WM_MOVERESIZE
) ))
2182 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
2186 dwPoint
= GetMessagePos();
2187 x
= (short)LOWORD(dwPoint
);
2188 y
= (short)HIWORD(dwPoint
);
2190 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd
, x
, y
, dir
);
2192 xev
.xclient
.type
= ClientMessage
;
2193 xev
.xclient
.window
= X11DRV_get_whole_window(hwnd
);
2194 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_MOVERESIZE
);
2195 xev
.xclient
.serial
= 0;
2196 xev
.xclient
.display
= display
;
2197 xev
.xclient
.send_event
= True
;
2198 xev
.xclient
.format
= 32;
2199 xev
.xclient
.data
.l
[0] = x
; /* x coord */
2200 xev
.xclient
.data
.l
[1] = y
; /* y coord */
2201 xev
.xclient
.data
.l
[2] = dir
; /* direction */
2202 xev
.xclient
.data
.l
[3] = 1; /* button */
2203 xev
.xclient
.data
.l
[4] = 0; /* unused */
2205 /* need to ungrab the pointer that may have been automatically grabbed
2206 * with a ButtonPress event */
2208 XUngrabPointer( display
, CurrentTime
);
2209 XSendEvent(display
, root_window
, False
, SubstructureNotifyMask
, &xev
);
2210 wine_tsx11_unlock();