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 /* windows with thick frame are managed */
105 if (style
& WS_THICKFRAME
) return TRUE
;
106 if (style
& WS_POPUP
)
108 /* popup with sysmenu == caption are managed */
109 if (style
& WS_SYSMENU
) return TRUE
;
110 /* full-screen popup windows are managed */
111 if (window_rect
->left
<= 0 && window_rect
->right
>= screen_width
&&
112 window_rect
->top
<= 0 && window_rect
->bottom
>= screen_height
)
115 /* application windows are managed */
116 ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
117 if (ex_style
& WS_EX_APPWINDOW
) return TRUE
;
118 /* default: not managed */
123 /***********************************************************************
124 * X11DRV_is_window_rect_mapped
126 * Check if the X whole window should be mapped based on its rectangle
128 static BOOL
is_window_rect_mapped( const RECT
*rect
)
130 /* don't map if rect is empty */
131 if (IsRectEmpty( rect
)) return FALSE
;
133 /* don't map if rect is off-screen */
134 if (rect
->left
>= virtual_screen_rect
.right
||
135 rect
->top
>= virtual_screen_rect
.bottom
||
136 rect
->right
<= virtual_screen_rect
.left
||
137 rect
->bottom
<= virtual_screen_rect
.top
)
144 /***********************************************************************
145 * is_window_resizable
147 * Check if window should be made resizable by the window manager
149 static inline BOOL
is_window_resizable( struct x11drv_win_data
*data
, DWORD style
)
151 if (style
& WS_THICKFRAME
) return TRUE
;
152 /* Metacity needs the window to be resizable to make it fullscreen */
153 return (data
->whole_rect
.left
<= 0 && data
->whole_rect
.right
>= screen_width
&&
154 data
->whole_rect
.top
<= 0 && data
->whole_rect
.bottom
>= screen_height
);
158 /***********************************************************************
161 static HWND
get_window_owner( HWND hwnd
)
164 HWND owner
= GetWindow( hwnd
, GW_OWNER
);
165 /* ignore the zero-size owners used by Delphi apps */
166 if (owner
&& GetWindowRect( owner
, &rect
) && IsRectEmpty( &rect
)) owner
= 0;
171 /***********************************************************************
172 * get_mwm_decorations
174 static unsigned long get_mwm_decorations( struct x11drv_win_data
*data
,
175 DWORD style
, DWORD ex_style
)
177 unsigned long ret
= 0;
179 if (!decorated_mode
) return 0;
181 if (IsRectEmpty( &data
->window_rect
)) return 0;
182 if (data
->shaped
) return 0;
184 if (ex_style
& WS_EX_TOOLWINDOW
) return 0;
186 if ((style
& WS_CAPTION
) == WS_CAPTION
)
188 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
189 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
190 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
191 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
193 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
194 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
195 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
200 /***********************************************************************
201 * get_x11_rect_offset
203 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
205 static void get_x11_rect_offset( struct x11drv_win_data
*data
, RECT
*rect
)
207 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
210 rect
->top
= rect
->bottom
= rect
->left
= rect
->right
= 0;
212 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
213 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
214 decor
= get_mwm_decorations( data
, style
, ex_style
);
216 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
217 if (decor
& MWM_DECOR_BORDER
)
219 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
220 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
223 AdjustWindowRectEx( rect
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
227 /***********************************************************************
228 * get_window_attributes
230 * Fill the window attributes structure for an X window.
232 static int get_window_attributes( Display
*display
, struct x11drv_win_data
*data
,
233 XSetWindowAttributes
*attr
)
235 attr
->override_redirect
= !data
->managed
;
236 attr
->colormap
= X11DRV_PALETTE_PaletteXColormap
;
237 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
238 attr
->cursor
= x11drv_thread_data()->cursor
;
239 attr
->bit_gravity
= NorthWestGravity
;
240 attr
->win_gravity
= StaticGravity
;
241 attr
->backing_store
= NotUseful
;
242 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
243 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
244 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
| KeymapStateMask
);
245 if (data
->managed
) attr
->event_mask
|= StructureNotifyMask
| PropertyChangeMask
;
247 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
| CWCursor
|
248 CWEventMask
| CWBitGravity
| CWBackingStore
);
252 /***********************************************************************
253 * create_client_window
255 static Window
create_client_window( Display
*display
, struct x11drv_win_data
*data
, XVisualInfo
*vis
)
258 XSetWindowAttributes attr
;
260 Visual
*client_visual
= vis
? vis
->visual
: visual
;
262 attr
.bit_gravity
= NorthWestGravity
;
263 attr
.win_gravity
= NorthWestGravity
;
264 attr
.backing_store
= NotUseful
;
265 attr
.event_mask
= (ExposureMask
| PointerMotionMask
|
266 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
267 mask
= CWEventMask
| CWBitGravity
| CWWinGravity
| CWBackingStore
;
269 if ((cx
= data
->client_rect
.right
- data
->client_rect
.left
) <= 0) cx
= 1;
270 if ((cy
= data
->client_rect
.bottom
- data
->client_rect
.top
) <= 0) cy
= 1;
276 attr
.colormap
= XCreateColormap( display
, root_window
, vis
->visual
,
277 (vis
->class == PseudoColor
|| vis
->class == GrayScale
||
278 vis
->class == DirectColor
) ? AllocAll
: AllocNone
);
282 client
= XCreateWindow( display
, data
->whole_window
,
283 data
->client_rect
.left
- data
->whole_rect
.left
,
284 data
->client_rect
.top
- data
->whole_rect
.top
,
285 cx
, cy
, 0, screen_depth
, InputOutput
,
286 client_visual
, mask
, &attr
);
293 if (data
->client_window
)
295 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
296 if (thread_data
->cursor_window
== data
->client_window
) thread_data
->cursor_window
= None
;
297 XDeleteContext( display
, data
->client_window
, winContext
);
298 XDestroyWindow( display
, data
->client_window
);
300 data
->client_window
= client
;
301 data
->visualid
= XVisualIDFromVisual( client_visual
);
303 if (data
->colormap
) XFreeColormap( display
, data
->colormap
);
304 data
->colormap
= vis
? attr
.colormap
: 0;
306 XMapWindow( display
, data
->client_window
);
307 XSaveContext( display
, data
->client_window
, winContext
, (char *)data
->hwnd
);
310 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)data
->client_window
);
311 return data
->client_window
;
315 /***********************************************************************
318 * Change the X window attributes when the window style has changed.
320 static void sync_window_style( Display
*display
, struct x11drv_win_data
*data
)
322 if (data
->whole_window
!= root_window
)
324 XSetWindowAttributes attr
;
325 int mask
= get_window_attributes( display
, data
, &attr
);
328 XChangeWindowAttributes( display
, data
->whole_window
, mask
, &attr
);
334 /***********************************************************************
337 * Update the X11 window region.
339 static void sync_window_region( Display
*display
, struct x11drv_win_data
*data
, HRGN win_region
)
341 #ifdef HAVE_LIBXSHAPE
342 HRGN hrgn
= win_region
;
344 if (!data
->whole_window
) return;
345 data
->shaped
= FALSE
;
347 if (hrgn
== (HRGN
)1) /* hack: win_region == 1 means retrieve region from server */
349 if (!(hrgn
= CreateRectRgn( 0, 0, 0, 0 ))) return;
350 if (GetWindowRgn( data
->hwnd
, hrgn
) == ERROR
)
352 DeleteObject( hrgn
);
360 XShapeCombineMask( display
, data
->whole_window
, ShapeBounding
, 0, 0, None
, ShapeSet
);
365 RGNDATA
*pRegionData
= X11DRV_GetRegionData( hrgn
, 0 );
369 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
370 data
->window_rect
.left
- data
->whole_rect
.left
,
371 data
->window_rect
.top
- data
->whole_rect
.top
,
372 (XRectangle
*)pRegionData
->Buffer
,
373 pRegionData
->rdh
.nCount
, ShapeSet
, YXBanded
);
375 HeapFree(GetProcessHeap(), 0, pRegionData
);
379 if (hrgn
&& hrgn
!= win_region
) DeleteObject( hrgn
);
380 #endif /* HAVE_LIBXSHAPE */
384 /***********************************************************************
387 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
390 char *buffer
, *utf8_buffer
;
393 /* allocate new buffer for window text */
394 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
395 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
396 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
398 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
399 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
401 HeapFree( GetProcessHeap(), 0, buffer
);
404 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
407 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
409 XSetWMName( display
, win
, &prop
);
410 XSetWMIconName( display
, win
, &prop
);
414 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
415 according to the standard
416 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
418 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
419 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
422 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
423 HeapFree( GetProcessHeap(), 0, buffer
);
427 /***********************************************************************
430 static BOOL
set_win_format( HWND hwnd
, XID fbconfig_id
)
432 struct x11drv_win_data
*data
;
436 if (!(data
= X11DRV_get_win_data(hwnd
)) &&
437 !(data
= X11DRV_create_win_data(hwnd
))) return FALSE
;
439 if (!(vis
= visual_from_fbconfig_id(fbconfig_id
))) return FALSE
;
441 if (data
->whole_window
)
443 Display
*display
= thread_display();
444 Window client
= data
->client_window
;
446 if (vis
->visualid
!= data
->visualid
)
448 client
= create_client_window( display
, data
, vis
);
449 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client
, data
->hwnd
, fbconfig_id
);
455 if (client
) goto done
;
459 w
= data
->client_rect
.right
- data
->client_rect
.left
;
460 h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
465 #ifdef SONAME_LIBXCOMPOSITE
468 XSetWindowAttributes attrib
;
469 static Window dummy_parent
;
472 attrib
.override_redirect
= True
;
475 dummy_parent
= XCreateWindow( gdi_display
, root_window
, -1, -1, 1, 1, 0, screen_depth
,
476 InputOutput
, visual
, CWOverrideRedirect
, &attrib
);
477 XMapWindow( gdi_display
, dummy_parent
);
479 data
->colormap
= XCreateColormap(gdi_display
, dummy_parent
, vis
->visual
,
480 (vis
->class == PseudoColor
||
481 vis
->class == GrayScale
||
482 vis
->class == DirectColor
) ?
483 AllocAll
: AllocNone
);
484 attrib
.colormap
= data
->colormap
;
485 XInstallColormap(gdi_display
, attrib
.colormap
);
487 if(data
->gl_drawable
) XDestroyWindow(gdi_display
, data
->gl_drawable
);
488 data
->gl_drawable
= XCreateWindow(gdi_display
, dummy_parent
, -w
, 0, w
, h
, 0,
489 vis
->depth
, InputOutput
, vis
->visual
,
490 CWColormap
| CWOverrideRedirect
,
492 if(data
->gl_drawable
)
494 pXCompositeRedirectWindow(gdi_display
, data
->gl_drawable
,
495 CompositeRedirectManual
);
496 XMapWindow(gdi_display
, data
->gl_drawable
);
499 XFlush( gdi_display
);
505 WARN("XComposite is not available, using GLXPixmap hack\n");
509 if(data
->pixmap
) XFreePixmap(gdi_display
, data
->pixmap
);
510 data
->pixmap
= XCreatePixmap(gdi_display
, root_window
, w
, h
, vis
->depth
);
518 if(data
->gl_drawable
) destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
519 data
->gl_drawable
= create_glxpixmap(gdi_display
, vis
, data
->pixmap
);
520 if(!data
->gl_drawable
)
522 XFreePixmap(gdi_display
, data
->pixmap
);
526 XFlush( gdi_display
);
528 if (data
->pixmap
) SetPropA(hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
531 if (!data
->gl_drawable
) return FALSE
;
533 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
534 data
->gl_drawable
, fbconfig_id
);
535 SetPropA(hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
538 data
->fbconfig_id
= fbconfig_id
;
539 SetPropA(hwnd
, fbconfig_id_prop
, (HANDLE
)data
->fbconfig_id
);
540 /* force DCE invalidation */
541 SetWindowPos( hwnd
, 0, 0, 0, 0, 0,
542 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOMOVE
|
543 SWP_NOREDRAW
| SWP_DEFERERASE
| SWP_NOSENDCHANGING
| SWP_STATECHANGED
);
547 /***********************************************************************
550 static void sync_gl_drawable(struct x11drv_win_data
*data
)
552 int w
= data
->client_rect
.right
- data
->client_rect
.left
;
553 int h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
561 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
562 #ifdef SONAME_LIBXCOMPOSITE
566 XMoveResizeWindow(gdi_display
, data
->gl_drawable
, -w
, 0, w
, h
);
572 if (!(vis
= visual_from_fbconfig_id(data
->fbconfig_id
))) return;
575 pix
= XCreatePixmap(gdi_display
, root_window
, w
, h
, vis
->depth
);
578 ERR("Failed to create pixmap for offscreen rendering\n");
584 glxp
= create_glxpixmap(gdi_display
, vis
, pix
);
587 ERR("Failed to create drawable for offscreen rendering\n");
588 XFreePixmap(gdi_display
, pix
);
596 mark_drawable_dirty(data
->gl_drawable
, glxp
);
598 XFreePixmap(gdi_display
, data
->pixmap
);
599 destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
600 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp
, data
->gl_drawable
);
603 data
->gl_drawable
= glxp
;
605 XFlush( gdi_display
);
608 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
609 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
613 /***********************************************************************
616 * fill the window changes structure
618 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
622 if (old
->right
- old
->left
!= new->right
- new->left
)
624 if ((changes
->width
= new->right
- new->left
) <= 0) changes
->width
= 1;
627 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
629 if ((changes
->height
= new->bottom
- new->top
) <= 0) changes
->height
= 1;
632 if (old
->left
!= new->left
)
634 changes
->x
= new->left
;
637 if (old
->top
!= new->top
)
639 changes
->y
= new->top
;
646 /***********************************************************************
649 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
651 XSetWindowAttributes attr
;
653 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
654 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
655 attr
.bit_gravity
= NorthWestGravity
;
656 attr
.backing_store
= NotUseful
/*WhenMapped*/;
657 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
660 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
661 GetSystemMetrics( SM_CXICON
),
662 GetSystemMetrics( SM_CYICON
),
665 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
666 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
667 XFlush( display
); /* make sure the window exists before we start painting to it */
670 TRACE( "created %lx\n", data
->icon_window
);
671 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
672 return data
->icon_window
;
677 /***********************************************************************
678 * destroy_icon_window
680 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
682 if (!data
->icon_window
) return;
683 if (x11drv_thread_data()->cursor_window
== data
->icon_window
)
684 x11drv_thread_data()->cursor_window
= None
;
686 XDeleteContext( display
, data
->icon_window
, winContext
);
687 XDestroyWindow( display
, data
->icon_window
);
688 data
->icon_window
= 0;
690 RemovePropA( data
->hwnd
, icon_window_prop
);
694 /***********************************************************************
697 * Set the icon wm hints
699 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
, HICON hIcon
)
701 XWMHints
*hints
= data
->wm_hints
;
703 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
704 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
705 data
->hWMIconBitmap
= 0;
706 data
->hWMIconMask
= 0;
710 if (!data
->icon_window
) create_icon_window( display
, data
);
711 hints
->icon_window
= data
->icon_window
;
712 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
722 GetIconInfo(hIcon
, &ii
);
724 GetObjectA(ii
.hbmMask
, sizeof(bmMask
), &bmMask
);
727 rcMask
.right
= bmMask
.bmWidth
;
728 rcMask
.bottom
= bmMask
.bmHeight
;
730 hDC
= CreateCompatibleDC(0);
731 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
732 InvertRect(hDC
, &rcMask
);
733 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
734 SelectObject(hDC
, hbmOrig
);
737 data
->hWMIconBitmap
= ii
.hbmColor
;
738 data
->hWMIconMask
= ii
.hbmMask
;
740 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
741 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
742 destroy_icon_window( display
, data
);
743 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
748 /***********************************************************************
751 * set the window size hints
753 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
755 XSizeHints
* size_hints
;
757 if (!(size_hints
= XAllocSizeHints())) return;
759 size_hints
->win_gravity
= StaticGravity
;
760 size_hints
->flags
|= PWinGravity
;
762 /* don't update size hints if window is not in normal state */
763 if (!(style
& (WS_MINIMIZE
| WS_MAXIMIZE
)))
765 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
767 size_hints
->x
= data
->whole_rect
.left
;
768 size_hints
->y
= data
->whole_rect
.top
;
769 size_hints
->flags
|= PPosition
;
772 if (!is_window_resizable( data
, style
))
774 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
775 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
776 size_hints
->min_width
= size_hints
->max_width
;
777 size_hints
->min_height
= size_hints
->max_height
;
778 size_hints
->flags
|= PMinSize
| PMaxSize
;
781 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
786 /***********************************************************************
789 * get the name of the current process for setting class hints
791 static char *get_process_name(void)
797 WCHAR module
[MAX_PATH
];
798 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
799 if (len
&& len
< MAX_PATH
)
802 WCHAR
*p
, *appname
= module
;
804 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
805 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
806 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
807 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
809 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
818 /***********************************************************************
819 * set_initial_wm_hints
821 * Set the window manager hints that don't change over the lifetime of a window.
823 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
828 XClassHint
*class_hints
;
829 char *process_name
= get_process_name();
835 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
836 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
837 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
838 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
839 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
842 if ((class_hints
= XAllocClassHint()))
844 static char wine
[] = "Wine";
846 class_hints
->res_name
= process_name
;
847 class_hints
->res_class
= wine
;
848 XSetClassHint( display
, data
->whole_window
, class_hints
);
849 XFree( class_hints
);
852 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
853 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
854 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
856 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
857 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
859 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
860 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
862 data
->wm_hints
= XAllocWMHints();
867 HICON icon
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_BIG
, 0 );
868 if (!icon
) icon
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
);
869 data
->wm_hints
->flags
= 0;
870 set_icon_hints( display
, data
, icon
);
875 /***********************************************************************
878 * Set the window manager hints for a newly-created window
880 static void set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
885 DWORD style
, ex_style
;
888 if (data
->hwnd
== GetDesktopWindow())
890 /* force some styles for the desktop to get the correct decorations */
891 style
= WS_POPUP
| WS_VISIBLE
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
892 ex_style
= WS_EX_APPWINDOW
;
897 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
898 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
899 owner
= get_window_owner( data
->hwnd
);
902 /* transient for hint */
905 Window owner_win
= X11DRV_get_whole_window( owner
);
907 XSetTransientForHint( display
, data
->whole_window
, owner_win
);
909 group_leader
= owner_win
;
911 else group_leader
= data
->whole_window
;
916 set_size_hints( display
, data
, style
);
918 /* set the WM_WINDOW_TYPE */
919 if (style
& WS_THICKFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
920 else if (ex_style
& WS_EX_APPWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
921 else if (style
& WS_DLGFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
922 else if (ex_style
& WS_EX_DLGMODALFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
923 else if ((style
& WS_POPUP
) && owner
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
924 #if 0 /* many window managers don't handle utility windows very well */
925 else if (ex_style
& WS_EX_TOOLWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY
);
927 else window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
929 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
930 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
932 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
933 mwm_hints
.decorations
= get_mwm_decorations( data
, style
, ex_style
);
934 mwm_hints
.functions
= MWM_FUNC_MOVE
;
935 if (is_window_resizable( data
, style
)) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
936 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
937 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
938 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
940 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
941 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
942 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
947 data
->wm_hints
->flags
|= InputHint
| StateHint
| WindowGroupHint
;
948 data
->wm_hints
->input
= !(style
& WS_DISABLED
);
949 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
950 data
->wm_hints
->window_group
= group_leader
;
951 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
958 /***********************************************************************
959 * update_net_wm_states
961 void update_net_wm_states( Display
*display
, struct x11drv_win_data
*data
)
963 static const unsigned int state_atoms
[NB_NET_WM_STATES
] =
965 XATOM__NET_WM_STATE_FULLSCREEN
,
966 XATOM__NET_WM_STATE_ABOVE
,
967 XATOM__NET_WM_STATE_MAXIMIZED_VERT
,
968 XATOM__NET_WM_STATE_SKIP_PAGER
,
969 XATOM__NET_WM_STATE_SKIP_TASKBAR
972 DWORD i
, style
, ex_style
, new_state
= 0;
974 if (!data
->managed
) return;
975 if (data
->whole_window
== root_window
) return;
977 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
978 if (data
->whole_rect
.left
<= 0 && data
->whole_rect
.right
>= screen_width
&&
979 data
->whole_rect
.top
<= 0 && data
->whole_rect
.bottom
>= screen_height
)
981 if ((style
& WS_MAXIMIZE
) && (style
& WS_CAPTION
) == WS_CAPTION
)
982 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
983 else if (!(style
& WS_MINIMIZE
))
984 new_state
|= (1 << NET_WM_STATE_FULLSCREEN
);
986 else if (style
& WS_MAXIMIZE
)
987 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
989 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
990 if (ex_style
& WS_EX_TOPMOST
)
991 new_state
|= (1 << NET_WM_STATE_ABOVE
);
992 if (ex_style
& WS_EX_TOOLWINDOW
)
993 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
) | (1 << NET_WM_STATE_SKIP_PAGER
);
994 if (!(ex_style
& WS_EX_APPWINDOW
) && get_window_owner( data
->hwnd
))
995 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
);
997 if (!data
->mapped
) /* set the _NET_WM_STATE atom directly */
999 Atom atoms
[NB_NET_WM_STATES
+1];
1002 for (i
= count
= 0; i
< NB_NET_WM_STATES
; i
++)
1004 if (!(new_state
& (1 << i
))) continue;
1005 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
1006 i
, data
->hwnd
, data
->whole_window
);
1007 atoms
[count
++] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
1008 if (state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
)
1009 atoms
[count
++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
);
1012 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_STATE
), XA_ATOM
,
1013 32, PropModeReplace
, (unsigned char *)atoms
, count
);
1014 wine_tsx11_unlock();
1016 else /* ask the window manager to do it for us */
1020 xev
.xclient
.type
= ClientMessage
;
1021 xev
.xclient
.window
= data
->whole_window
;
1022 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
1023 xev
.xclient
.serial
= 0;
1024 xev
.xclient
.display
= display
;
1025 xev
.xclient
.send_event
= True
;
1026 xev
.xclient
.format
= 32;
1027 xev
.xclient
.data
.l
[3] = 1;
1029 for (i
= 0; i
< NB_NET_WM_STATES
; i
++)
1031 if (!((data
->net_wm_state
^ new_state
) & (1 << i
))) continue; /* unchanged */
1033 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1034 i
, data
->hwnd
, data
->whole_window
,
1035 (new_state
& (1 << i
)) != 0, (data
->net_wm_state
& (1 << i
)) != 0 );
1037 xev
.xclient
.data
.l
[0] = (new_state
& (1 << i
)) ? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
1038 xev
.xclient
.data
.l
[1] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
1039 xev
.xclient
.data
.l
[2] = ((state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
) ?
1040 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
) : 0);
1042 XSendEvent( display
, root_window
, False
,
1043 SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
1044 wine_tsx11_unlock();
1047 data
->net_wm_state
= new_state
;
1051 /***********************************************************************
1054 static void set_xembed_flags( Display
*display
, struct x11drv_win_data
*data
, unsigned long flags
)
1056 unsigned long info
[2];
1058 info
[0] = 0; /* protocol version */
1061 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_XEMBED_INFO
),
1062 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
, (unsigned char*)info
, 2 );
1063 wine_tsx11_unlock();
1067 /***********************************************************************
1070 static void map_window( Display
*display
, struct x11drv_win_data
*data
, DWORD new_style
)
1072 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1074 wait_for_withdrawn_state( display
, data
, TRUE
);
1076 if (!data
->embedded
)
1078 update_net_wm_states( display
, data
);
1079 sync_window_style( display
, data
);
1081 XMapWindow( display
, data
->whole_window
);
1082 wine_tsx11_unlock();
1084 else set_xembed_flags( display
, data
, XEMBED_MAPPED
);
1086 data
->mapped
= TRUE
;
1087 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
1091 /***********************************************************************
1094 static void unmap_window( Display
*display
, struct x11drv_win_data
*data
)
1096 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1098 if (!data
->embedded
)
1100 wait_for_withdrawn_state( display
, data
, FALSE
);
1102 if (data
->managed
) XWithdrawWindow( display
, data
->whole_window
, DefaultScreen(display
) );
1103 else XUnmapWindow( display
, data
->whole_window
);
1104 wine_tsx11_unlock();
1106 else set_xembed_flags( display
, data
, 0 );
1108 data
->mapped
= FALSE
;
1109 data
->net_wm_state
= 0;
1113 /***********************************************************************
1114 * make_window_embedded
1116 void make_window_embedded( Display
*display
, struct x11drv_win_data
*data
)
1120 /* the window cannot be mapped before being embedded */
1121 unmap_window( display
, data
);
1122 data
->embedded
= TRUE
;
1123 map_window( display
, data
, 0 );
1127 data
->embedded
= TRUE
;
1128 set_xembed_flags( display
, data
, 0 );
1133 /***********************************************************************
1134 * X11DRV_window_to_X_rect
1136 * Convert a rect from client to X window coordinates
1138 void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1142 if (!data
->managed
) return;
1143 if (IsRectEmpty( rect
)) return;
1145 get_x11_rect_offset( data
, &rc
);
1147 rect
->left
-= rc
.left
;
1148 rect
->right
-= rc
.right
;
1149 rect
->top
-= rc
.top
;
1150 rect
->bottom
-= rc
.bottom
;
1151 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1152 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1156 /***********************************************************************
1157 * X11DRV_X_to_window_rect
1159 * Opposite of X11DRV_window_to_X_rect
1161 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1165 if (!data
->managed
) return;
1166 if (IsRectEmpty( rect
)) return;
1168 get_x11_rect_offset( data
, &rc
);
1170 rect
->left
+= rc
.left
;
1171 rect
->right
+= rc
.right
;
1172 rect
->top
+= rc
.top
;
1173 rect
->bottom
+= rc
.bottom
;
1174 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1175 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1179 /***********************************************************************
1180 * sync_window_position
1182 * Synchronize the X window position with the Windows one
1184 static void sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
1185 UINT swp_flags
, const RECT
*old_client_rect
,
1186 const RECT
*old_whole_rect
)
1188 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1189 XWindowChanges changes
;
1190 unsigned int mask
= 0;
1192 if (data
->managed
&& data
->iconic
) return;
1194 /* resizing a managed maximized window is not allowed */
1195 if (!(style
& WS_MAXIMIZE
) || !data
->managed
)
1197 if ((changes
.width
= data
->whole_rect
.right
- data
->whole_rect
.left
) <= 0) changes
.width
= 1;
1198 if ((changes
.height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
) <= 0) changes
.height
= 1;
1199 mask
|= CWWidth
| CWHeight
;
1202 /* only the size is allowed to change for the desktop window */
1203 if (data
->whole_window
!= root_window
)
1205 changes
.x
= data
->whole_rect
.left
- virtual_screen_rect
.left
;
1206 changes
.y
= data
->whole_rect
.top
- virtual_screen_rect
.top
;
1210 if (!(swp_flags
& SWP_NOZORDER
) || (swp_flags
& SWP_SHOWWINDOW
))
1212 /* find window that this one must be after */
1213 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
1214 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
1215 prev
= GetWindow( prev
, GW_HWNDPREV
);
1216 if (!prev
) /* top child */
1218 changes
.stack_mode
= Above
;
1219 mask
|= CWStackMode
;
1221 /* should use stack_mode Below but most window managers don't get it right */
1222 /* and Above with a sibling doesn't work so well either, so we ignore it */
1225 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
1226 data
->hwnd
, data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1227 data
->whole_rect
.right
- data
->whole_rect
.left
,
1228 data
->whole_rect
.bottom
- data
->whole_rect
.top
, changes
.sibling
, mask
);
1231 set_size_hints( display
, data
, style
);
1232 XReconfigureWMWindow( display
, data
->whole_window
,
1233 DefaultScreen(display
), mask
, &changes
);
1234 wine_tsx11_unlock();
1238 /***********************************************************************
1239 * sync_client_position
1241 * Synchronize the X client window position with the Windows one
1243 static void sync_client_position( Display
*display
, struct x11drv_win_data
*data
,
1244 UINT swp_flags
, const RECT
*old_client_rect
,
1245 const RECT
*old_whole_rect
)
1248 XWindowChanges changes
;
1249 RECT old
= *old_client_rect
;
1250 RECT
new = data
->client_rect
;
1252 OffsetRect( &old
, -old_whole_rect
->left
, -old_whole_rect
->top
);
1253 OffsetRect( &new, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
1254 if (!(mask
= get_window_changes( &changes
, &old
, &new ))) return;
1256 if (data
->client_window
)
1258 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1259 data
->client_window
, new.left
, new.top
,
1260 new.right
- new.left
, new.bottom
- new.top
, mask
);
1262 XConfigureWindow( display
, data
->client_window
, mask
, &changes
);
1263 wine_tsx11_unlock();
1266 if (data
->gl_drawable
&& (mask
& (CWWidth
|CWHeight
))) sync_gl_drawable( data
);
1270 /***********************************************************************
1273 * Move the window bits when a window is moved.
1275 static void move_window_bits( struct x11drv_win_data
*data
, const RECT
*old_rect
, const RECT
*new_rect
,
1276 const RECT
*old_client_rect
)
1278 RECT src_rect
= *old_rect
;
1279 RECT dst_rect
= *new_rect
;
1280 HDC hdc_src
, hdc_dst
;
1285 if (!data
->whole_window
)
1287 OffsetRect( &dst_rect
, -data
->window_rect
.left
, -data
->window_rect
.top
);
1288 parent
= GetAncestor( data
->hwnd
, GA_PARENT
);
1289 hdc_src
= GetDCEx( parent
, 0, DCX_CACHE
);
1290 hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
1294 OffsetRect( &dst_rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
1295 /* make src rect relative to the old position of the window */
1296 OffsetRect( &src_rect
, -old_client_rect
->left
, -old_client_rect
->top
);
1297 if (dst_rect
.left
== src_rect
.left
&& dst_rect
.top
== src_rect
.top
) return;
1298 hdc_src
= hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
);
1301 code
= X11DRV_START_EXPOSURES
;
1302 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
1304 TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n",
1305 data
->hwnd
, data
->whole_window
, data
->client_window
,
1306 wine_dbgstr_rect(&src_rect
), wine_dbgstr_rect(&dst_rect
) );
1307 BitBlt( hdc_dst
, dst_rect
.left
, dst_rect
.top
,
1308 dst_rect
.right
- dst_rect
.left
, dst_rect
.bottom
- dst_rect
.top
,
1309 hdc_src
, src_rect
.left
, src_rect
.top
, SRCCOPY
);
1311 code
= X11DRV_END_EXPOSURES
;
1312 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, sizeof(rgn
), (LPSTR
)&rgn
);
1314 ReleaseDC( data
->hwnd
, hdc_dst
);
1315 if (hdc_src
!= hdc_dst
) ReleaseDC( parent
, hdc_src
);
1319 if (!data
->whole_window
)
1321 /* map region to client rect since we are using DCX_WINDOW */
1322 OffsetRgn( rgn
, data
->window_rect
.left
- data
->client_rect
.left
,
1323 data
->window_rect
.top
- data
->client_rect
.top
);
1324 RedrawWindow( data
->hwnd
, NULL
, rgn
,
1325 RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
1327 else RedrawWindow( data
->hwnd
, NULL
, rgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1328 DeleteObject( rgn
);
1333 /**********************************************************************
1334 * create_whole_window
1336 * Create the whole X window for a given window
1338 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1341 XSetWindowAttributes attr
;
1344 if (!(cx
= data
->window_rect
.right
- data
->window_rect
.left
)) cx
= 1;
1345 if (!(cy
= data
->window_rect
.bottom
- data
->window_rect
.top
)) cy
= 1;
1347 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1349 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1350 data
->managed
= TRUE
;
1351 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1354 mask
= get_window_attributes( display
, data
, &attr
);
1358 data
->whole_rect
= data
->window_rect
;
1359 data
->whole_window
= XCreateWindow( display
, root_window
,
1360 data
->window_rect
.left
- virtual_screen_rect
.left
,
1361 data
->window_rect
.top
- virtual_screen_rect
.top
,
1362 cx
, cy
, 0, screen_depth
, InputOutput
,
1363 visual
, mask
, &attr
);
1365 if (data
->whole_window
) XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1366 wine_tsx11_unlock();
1368 if (!data
->whole_window
) return 0;
1370 if (!create_client_window( display
, data
, NULL
))
1373 XDeleteContext( display
, data
->whole_window
, winContext
);
1374 XDestroyWindow( display
, data
->whole_window
);
1375 data
->whole_window
= 0;
1376 wine_tsx11_unlock();
1380 set_initial_wm_hints( display
, data
);
1381 set_wm_hints( display
, data
);
1383 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1385 /* set the window text */
1386 if (!InternalGetWindowText( data
->hwnd
, text
, sizeof(text
)/sizeof(WCHAR
) )) text
[0] = 0;
1387 sync_window_text( display
, data
->whole_window
, text
);
1389 /* set the window region */
1390 sync_window_region( display
, data
, (HRGN
)1 );
1393 XFlush( display
); /* make sure the window exists before we start painting to it */
1394 wine_tsx11_unlock();
1395 return data
->whole_window
;
1399 /**********************************************************************
1400 * destroy_whole_window
1402 * Destroy the whole X window for a given window.
1404 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
, BOOL already_destroyed
)
1406 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1408 if (!data
->whole_window
) return;
1410 TRACE( "win %p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1411 if (thread_data
->cursor_window
== data
->whole_window
||
1412 thread_data
->cursor_window
== data
->client_window
)
1413 thread_data
->cursor_window
= None
;
1415 XDeleteContext( display
, data
->whole_window
, winContext
);
1416 XDeleteContext( display
, data
->client_window
, winContext
);
1417 if (!already_destroyed
) XDestroyWindow( display
, data
->whole_window
);
1418 data
->whole_window
= data
->client_window
= 0;
1419 data
->wm_state
= WithdrawnState
;
1420 data
->net_wm_state
= 0;
1421 data
->mapped
= FALSE
;
1424 XUnsetICFocus( data
->xic
);
1425 XDestroyIC( data
->xic
);
1428 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1430 XFree( data
->wm_hints
);
1431 data
->wm_hints
= NULL
;
1432 wine_tsx11_unlock();
1433 RemovePropA( data
->hwnd
, whole_window_prop
);
1434 RemovePropA( data
->hwnd
, client_window_prop
);
1438 /*****************************************************************
1439 * SetWindowText (X11DRV.@)
1441 void X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1445 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(gdi_display
))
1447 Display
*display
= thread_init_display();
1448 sync_window_text( display
, win
, text
);
1453 /***********************************************************************
1454 * SetWindowStyle (X11DRV.@)
1456 * Update the X state of a window to reflect a style change
1458 void X11DRV_SetWindowStyle( HWND hwnd
, DWORD old_style
)
1460 struct x11drv_win_data
*data
;
1461 DWORD new_style
, changed
;
1463 if (hwnd
== GetDesktopWindow()) return;
1464 new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1465 changed
= new_style
^ old_style
;
1467 if ((changed
& WS_VISIBLE
) && (new_style
& WS_VISIBLE
))
1469 /* we don't unmap windows, that causes trouble with the window manager */
1470 if (!(data
= X11DRV_get_win_data( hwnd
)) &&
1471 !(data
= X11DRV_create_win_data( hwnd
))) return;
1473 if (data
->whole_window
&& is_window_rect_mapped( &data
->window_rect
))
1475 Display
*display
= thread_display();
1476 set_wm_hints( display
, data
);
1477 if (!data
->mapped
) map_window( display
, data
, new_style
);
1481 if (changed
& WS_DISABLED
)
1483 data
= X11DRV_get_win_data( hwnd
);
1484 if (data
&& data
->wm_hints
)
1487 data
->wm_hints
->input
= !(new_style
& WS_DISABLED
);
1488 XSetWMHints( thread_display(), data
->whole_window
, data
->wm_hints
);
1489 wine_tsx11_unlock();
1495 /***********************************************************************
1496 * DestroyWindow (X11DRV.@)
1498 void X11DRV_DestroyWindow( HWND hwnd
)
1500 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1501 struct x11drv_win_data
*data
;
1503 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1508 destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
1509 XFreePixmap(gdi_display
, data
->pixmap
);
1510 wine_tsx11_unlock();
1512 else if (data
->gl_drawable
)
1515 XDestroyWindow(gdi_display
, data
->gl_drawable
);
1516 wine_tsx11_unlock();
1519 destroy_whole_window( thread_data
->display
, data
, FALSE
);
1520 destroy_icon_window( thread_data
->display
, data
);
1525 XFreeColormap( thread_data
->display
, data
->colormap
);
1526 wine_tsx11_unlock();
1529 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1530 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1531 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1533 XDeleteContext( thread_data
->display
, (XID
)hwnd
, win_data_context
);
1534 wine_tsx11_unlock();
1535 HeapFree( GetProcessHeap(), 0, data
);
1539 /***********************************************************************
1540 * X11DRV_DestroyNotify
1542 void X11DRV_DestroyNotify( HWND hwnd
, XEvent
*event
)
1544 Display
*display
= event
->xdestroywindow
.display
;
1545 struct x11drv_win_data
*data
;
1547 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1549 FIXME( "window %p/%lx destroyed from the outside\n", hwnd
, data
->whole_window
);
1550 destroy_whole_window( display
, data
, TRUE
);
1554 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1556 struct x11drv_win_data
*data
;
1558 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
1562 if (!winContext
) winContext
= XUniqueContext();
1563 if (!win_data_context
) win_data_context
= XUniqueContext();
1564 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1565 wine_tsx11_unlock();
1571 /* initialize the desktop window id in the desktop manager process */
1572 static struct x11drv_win_data
*create_desktop_win_data( Display
*display
, HWND hwnd
)
1574 struct x11drv_win_data
*data
;
1576 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1577 data
->whole_window
= data
->client_window
= root_window
;
1578 data
->managed
= TRUE
;
1579 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1580 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1581 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)root_window
);
1582 set_initial_wm_hints( display
, data
);
1586 /**********************************************************************
1587 * CreateDesktopWindow (X11DRV.@)
1589 BOOL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1591 unsigned int width
, height
;
1593 /* retrieve the real size of the desktop */
1594 SERVER_START_REQ( get_window_rectangles
)
1597 wine_server_call( req
);
1598 width
= reply
->window
.right
- reply
->window
.left
;
1599 height
= reply
->window
.bottom
- reply
->window
.top
;
1603 if (!width
&& !height
) /* not initialized yet */
1605 SERVER_START_REQ( set_window_pos
)
1609 req
->flags
= SWP_NOZORDER
;
1610 req
->window
.left
= virtual_screen_rect
.left
;
1611 req
->window
.top
= virtual_screen_rect
.top
;
1612 req
->window
.right
= virtual_screen_rect
.right
;
1613 req
->window
.bottom
= virtual_screen_rect
.bottom
;
1614 req
->client
= req
->window
;
1615 wine_server_call( req
);
1621 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1622 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1628 /**********************************************************************
1629 * CreateWindow (X11DRV.@)
1631 BOOL
X11DRV_CreateWindow( HWND hwnd
)
1633 if (hwnd
== GetDesktopWindow() && root_window
!= DefaultRootWindow( gdi_display
))
1635 Display
*display
= thread_init_display();
1637 /* the desktop win data can't be created lazily */
1638 if (!create_desktop_win_data( display
, hwnd
)) return FALSE
;
1644 /***********************************************************************
1645 * X11DRV_get_win_data
1647 * Return the X11 data structure associated with a window.
1649 struct x11drv_win_data
*X11DRV_get_win_data( HWND hwnd
)
1651 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1654 if (!thread_data
) return NULL
;
1655 if (!hwnd
) return NULL
;
1656 if (XFindContext( thread_data
->display
, (XID
)hwnd
, win_data_context
, &data
)) data
= NULL
;
1657 return (struct x11drv_win_data
*)data
;
1661 /***********************************************************************
1662 * X11DRV_create_win_data
1664 * Create an X11 data window structure for an existing window.
1666 struct x11drv_win_data
*X11DRV_create_win_data( HWND hwnd
)
1669 struct x11drv_win_data
*data
;
1672 if (!(parent
= GetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop */
1674 /* don't create win data for HWND_MESSAGE windows */
1675 if (parent
!= GetDesktopWindow() && !GetAncestor( parent
, GA_PARENT
)) return NULL
;
1677 display
= thread_init_display();
1678 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1680 GetWindowRect( hwnd
, &data
->window_rect
);
1681 MapWindowPoints( 0, parent
, (POINT
*)&data
->window_rect
, 2 );
1682 data
->whole_rect
= data
->window_rect
;
1683 GetClientRect( hwnd
, &data
->client_rect
);
1684 MapWindowPoints( hwnd
, parent
, (POINT
*)&data
->client_rect
, 2 );
1686 if (parent
== GetDesktopWindow())
1688 if (!create_whole_window( display
, data
))
1690 HeapFree( GetProcessHeap(), 0, data
);
1693 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1694 hwnd
, data
->whole_window
, data
->client_window
, wine_dbgstr_rect( &data
->window_rect
),
1695 wine_dbgstr_rect( &data
->whole_rect
), wine_dbgstr_rect( &data
->client_rect
));
1701 /***********************************************************************
1702 * X11DRV_get_whole_window
1704 * Return the X window associated with the full area of a window
1706 Window
X11DRV_get_whole_window( HWND hwnd
)
1708 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1712 if (hwnd
== GetDesktopWindow()) return root_window
;
1713 return (Window
)GetPropA( hwnd
, whole_window_prop
);
1715 return data
->whole_window
;
1719 /***********************************************************************
1720 * X11DRV_get_client_window
1722 * Return the X window associated with the client area of a window
1724 Window
X11DRV_get_client_window( HWND hwnd
)
1726 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1730 if (hwnd
== GetDesktopWindow()) return root_window
;
1731 return (Window
)GetPropA( hwnd
, client_window_prop
);
1733 return data
->client_window
;
1737 /***********************************************************************
1740 * Return the X input context associated with a window
1742 XIC
X11DRV_get_ic( HWND hwnd
)
1744 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1747 if (!data
) return 0;
1748 if (data
->xic
) return data
->xic
;
1749 if (!(xim
= x11drv_thread_data()->xim
)) return 0;
1750 return X11DRV_CreateIC( xim
, data
);
1754 /***********************************************************************
1755 * X11DRV_GetDC (X11DRV.@)
1757 void X11DRV_GetDC( HDC hdc
, HWND hwnd
, HWND top
, const RECT
*win_rect
,
1758 const RECT
*top_rect
, DWORD flags
)
1760 struct x11drv_escape_set_drawable escape
;
1761 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1763 escape
.code
= X11DRV_SET_DRAWABLE
;
1764 escape
.mode
= IncludeInferiors
;
1765 escape
.fbconfig_id
= 0;
1766 escape
.gl_drawable
= 0;
1768 escape
.gl_copy
= FALSE
;
1770 if (top
== hwnd
&& data
&& IsIconic( hwnd
) && data
->icon_window
)
1772 escape
.drawable
= data
->icon_window
;
1774 else if (top
== hwnd
)
1776 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1777 /* GL draws to the client area even for window DCs */
1778 escape
.gl_drawable
= data
? data
->client_window
: X11DRV_get_client_window( hwnd
);
1779 if (flags
& DCX_WINDOW
)
1780 escape
.drawable
= data
? data
->whole_window
: X11DRV_get_whole_window( hwnd
);
1782 escape
.drawable
= escape
.gl_drawable
;
1786 escape
.drawable
= X11DRV_get_client_window( top
);
1787 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1788 escape
.gl_drawable
= data
? data
->gl_drawable
: (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
1789 escape
.pixmap
= data
? data
->pixmap
: (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
1790 escape
.gl_copy
= (escape
.gl_drawable
!= 0);
1791 if (flags
& DCX_CLIPCHILDREN
) escape
.mode
= ClipByChildren
;
1794 escape
.dc_rect
.left
= win_rect
->left
- top_rect
->left
;
1795 escape
.dc_rect
.top
= win_rect
->top
- top_rect
->top
;
1796 escape
.dc_rect
.right
= win_rect
->right
- top_rect
->left
;
1797 escape
.dc_rect
.bottom
= win_rect
->bottom
- top_rect
->top
;
1798 escape
.drawable_rect
.left
= top_rect
->left
;
1799 escape
.drawable_rect
.top
= top_rect
->top
;
1800 escape
.drawable_rect
.right
= top_rect
->right
;
1801 escape
.drawable_rect
.bottom
= top_rect
->bottom
;
1803 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1807 /***********************************************************************
1808 * X11DRV_ReleaseDC (X11DRV.@)
1810 void X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
1812 struct x11drv_escape_set_drawable escape
;
1814 escape
.code
= X11DRV_SET_DRAWABLE
;
1815 escape
.drawable
= root_window
;
1816 escape
.mode
= IncludeInferiors
;
1817 escape
.drawable_rect
= virtual_screen_rect
;
1818 SetRect( &escape
.dc_rect
, 0, 0, virtual_screen_rect
.right
- virtual_screen_rect
.left
,
1819 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
);
1820 escape
.fbconfig_id
= 0;
1821 escape
.gl_drawable
= 0;
1823 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1827 /***********************************************************************
1828 * SetCapture (X11DRV.@)
1830 void X11DRV_SetCapture( HWND hwnd
, UINT flags
)
1832 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1834 if (!thread_data
) return;
1835 if (!(flags
& (GUI_INMOVESIZE
| GUI_INMENUMODE
))) return;
1839 Window grab_win
= X11DRV_get_client_window( GetAncestor( hwnd
, GA_ROOT
) );
1841 if (!grab_win
) return;
1843 XFlush( gdi_display
);
1844 XGrabPointer( thread_data
->display
, grab_win
, False
,
1845 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1846 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
);
1847 wine_tsx11_unlock();
1848 thread_data
->grab_window
= grab_win
;
1850 else /* release capture */
1853 XFlush( gdi_display
);
1854 XUngrabPointer( thread_data
->display
, CurrentTime
);
1855 wine_tsx11_unlock();
1856 thread_data
->grab_window
= None
;
1861 /*****************************************************************
1862 * SetParent (X11DRV.@)
1864 void X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
1866 Display
*display
= thread_display();
1867 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1870 if (parent
== old_parent
) return;
1872 if (parent
!= GetDesktopWindow()) /* a child window */
1874 if (old_parent
== GetDesktopWindow())
1876 /* destroy the old X windows */
1877 destroy_whole_window( display
, data
, FALSE
);
1878 destroy_icon_window( display
, data
);
1881 data
->managed
= FALSE
;
1882 RemovePropA( data
->hwnd
, managed_prop
);
1886 else /* new top level window */
1888 /* FIXME: we ignore errors since we can't really recover anyway */
1889 create_whole_window( display
, data
);
1894 /*****************************************************************
1895 * SetFocus (X11DRV.@)
1899 void X11DRV_SetFocus( HWND hwnd
)
1901 Display
*display
= thread_display();
1902 struct x11drv_win_data
*data
;
1903 XWindowChanges changes
;
1905 if (!(hwnd
= GetAncestor( hwnd
, GA_ROOT
))) return;
1906 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1907 if (data
->managed
|| !data
->whole_window
) return;
1909 /* Set X focus and install colormap */
1911 changes
.stack_mode
= Above
;
1912 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
1913 if (root_window
== DefaultRootWindow(display
))
1915 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1916 /* FIXME: this is not entirely correct */
1917 XSetInputFocus( display
, data
->whole_window
, RevertToParent
,
1919 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1921 wine_tsx11_unlock();
1925 /***********************************************************************
1926 * WindowPosChanging (X11DRV.@)
1928 void X11DRV_WindowPosChanging( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
1929 const RECT
*window_rect
, const RECT
*client_rect
, RECT
*visible_rect
)
1931 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1932 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1936 /* create the win data if the window is being made visible */
1937 if (!(style
& WS_VISIBLE
) && !(swp_flags
& SWP_SHOWWINDOW
)) return;
1938 if (!(data
= X11DRV_create_win_data( hwnd
))) return;
1941 /* check if we need to switch the window to managed */
1942 if (!data
->managed
&& data
->whole_window
&& is_window_managed( hwnd
, swp_flags
, window_rect
))
1944 TRACE( "making win %p/%lx managed\n", hwnd
, data
->whole_window
);
1945 if (data
->mapped
) unmap_window( thread_display(), data
);
1946 data
->managed
= TRUE
;
1947 SetPropA( hwnd
, managed_prop
, (HANDLE
)1 );
1950 *visible_rect
= *window_rect
;
1951 X11DRV_window_to_X_rect( data
, visible_rect
);
1955 /***********************************************************************
1956 * WindowPosChanged (X11DRV.@)
1958 void X11DRV_WindowPosChanged( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
1959 const RECT
*rectWindow
, const RECT
*rectClient
,
1960 const RECT
*visible_rect
, const RECT
*valid_rects
)
1962 struct x11drv_thread_data
*thread_data
;
1964 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1965 DWORD new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1966 RECT old_whole_rect
, old_client_rect
;
1971 thread_data
= x11drv_thread_data();
1972 display
= thread_data
->display
;
1974 old_whole_rect
= data
->whole_rect
;
1975 old_client_rect
= data
->client_rect
;
1976 data
->window_rect
= *rectWindow
;
1977 data
->whole_rect
= *visible_rect
;
1978 data
->client_rect
= *rectClient
;
1980 TRACE( "win %p window %s client %s style %08x flags %08x\n",
1981 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
, swp_flags
);
1983 if (!IsRectEmpty( &valid_rects
[0] ))
1985 int x_offset
= old_whole_rect
.left
- data
->whole_rect
.left
;
1986 int y_offset
= old_whole_rect
.top
- data
->whole_rect
.top
;
1988 /* if all that happened is that the whole window moved, copy everything */
1989 if (!(swp_flags
& SWP_FRAMECHANGED
) &&
1990 old_whole_rect
.right
- data
->whole_rect
.right
== x_offset
&&
1991 old_whole_rect
.bottom
- data
->whole_rect
.bottom
== y_offset
&&
1992 old_client_rect
.left
- data
->client_rect
.left
== x_offset
&&
1993 old_client_rect
.right
- data
->client_rect
.right
== x_offset
&&
1994 old_client_rect
.top
- data
->client_rect
.top
== y_offset
&&
1995 old_client_rect
.bottom
- data
->client_rect
.bottom
== y_offset
&&
1996 !memcmp( &valid_rects
[0], &data
->client_rect
, sizeof(RECT
) ))
1998 /* if we have an X window the bits will be moved by the X server */
1999 if (!data
->whole_window
)
2000 move_window_bits( data
, &old_whole_rect
, &data
->whole_rect
, &old_client_rect
);
2003 move_window_bits( data
, &valid_rects
[1], &valid_rects
[0], &old_client_rect
);
2007 XFlush( gdi_display
); /* make sure painting is done before we move the window */
2008 wine_tsx11_unlock();
2010 sync_client_position( display
, data
, swp_flags
, &old_client_rect
, &old_whole_rect
);
2012 if (!data
->whole_window
) return;
2014 /* check if we are currently processing an event relevant to this window */
2016 if (thread_data
->current_event
&& thread_data
->current_event
->xany
.window
== data
->whole_window
)
2017 event_type
= thread_data
->current_event
->type
;
2019 if (event_type
!= ConfigureNotify
&& event_type
!= PropertyNotify
)
2020 event_type
= 0; /* ignore other events */
2024 if (((swp_flags
& SWP_HIDEWINDOW
) && !(new_style
& WS_VISIBLE
)) ||
2025 (!event_type
&& !is_window_rect_mapped( rectWindow
)))
2026 unmap_window( display
, data
);
2029 /* don't change position if we are about to minimize or maximize a managed window */
2031 !(data
->managed
&& (swp_flags
& SWP_STATECHANGED
) && (new_style
& (WS_MINIMIZE
|WS_MAXIMIZE
))))
2032 sync_window_position( display
, data
, swp_flags
, &old_client_rect
, &old_whole_rect
);
2034 if ((new_style
& WS_VISIBLE
) &&
2035 ((new_style
& WS_MINIMIZE
) || is_window_rect_mapped( rectWindow
)))
2037 if (!data
->mapped
|| (swp_flags
& (SWP_FRAMECHANGED
|SWP_STATECHANGED
)))
2038 set_wm_hints( display
, data
);
2042 map_window( display
, data
, new_style
);
2044 else if ((swp_flags
& SWP_STATECHANGED
) && (!data
->iconic
!= !(new_style
& WS_MINIMIZE
)))
2046 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
2047 TRACE( "changing win %p iconic state to %u\n", data
->hwnd
, data
->iconic
);
2050 XIconifyWindow( display
, data
->whole_window
, DefaultScreen(display
) );
2051 else if (is_window_rect_mapped( rectWindow
))
2052 XMapWindow( display
, data
->whole_window
);
2053 wine_tsx11_unlock();
2054 update_net_wm_states( display
, data
);
2056 else if (!event_type
)
2058 update_net_wm_states( display
, data
);
2063 XFlush( display
); /* make sure changes are done before we start painting again */
2064 wine_tsx11_unlock();
2068 /***********************************************************************
2069 * ShowWindow (X11DRV.@)
2071 UINT
X11DRV_ShowWindow( HWND hwnd
, INT cmd
, RECT
*rect
, UINT swp
)
2074 unsigned int width
, height
, border
, depth
;
2076 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2077 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2078 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2080 if (!data
|| !data
->whole_window
|| !data
->managed
|| !data
->mapped
|| data
->iconic
) return swp
;
2081 if (style
& WS_MINIMIZE
) return swp
;
2083 /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */
2085 if (!thread_data
->current_event
|| thread_data
->current_event
->xany
.window
!= data
->whole_window
)
2088 if (thread_data
->current_event
->type
!= ConfigureNotify
&&
2089 thread_data
->current_event
->type
!= PropertyNotify
)
2092 TRACE( "win %p/%lx cmd %d at %s flags %08x\n",
2093 hwnd
, data
->whole_window
, cmd
, wine_dbgstr_rect(rect
), swp
);
2096 XGetGeometry( thread_data
->display
, data
->whole_window
,
2097 &root
, &x
, &y
, &width
, &height
, &border
, &depth
);
2098 XTranslateCoordinates( thread_data
->display
, data
->whole_window
, root
, 0, 0, &x
, &y
, &top
);
2099 wine_tsx11_unlock();
2102 rect
->right
= x
+ width
;
2103 rect
->bottom
= y
+ height
;
2104 OffsetRect( rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
2105 X11DRV_X_to_window_rect( data
, rect
);
2106 return swp
& ~(SWP_NOMOVE
| SWP_NOCLIENTMOVE
| SWP_NOSIZE
| SWP_NOCLIENTSIZE
);
2110 /**********************************************************************
2111 * SetWindowIcon (X11DRV.@)
2113 * hIcon or hIconSm has changed (or is being initialised for the
2114 * first time). Complete the X11 driver-specific initialisation
2115 * and set the window hints.
2117 * This is not entirely correct, may need to create
2118 * an icon window and set the pixmap as a background
2120 void X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
2122 Display
*display
= thread_display();
2123 struct x11drv_win_data
*data
;
2125 if (type
!= ICON_BIG
) return; /* nothing to do here */
2127 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
2128 if (!data
->whole_window
) return;
2129 if (!data
->managed
) return;
2133 set_icon_hints( display
, data
, icon
);
2135 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
2136 wine_tsx11_unlock();
2141 /***********************************************************************
2142 * SetWindowRgn (X11DRV.@)
2144 * Assign specified region to window (for non-rectangular windows)
2146 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
2148 struct x11drv_win_data
*data
;
2150 if ((data
= X11DRV_get_win_data( hwnd
)))
2152 sync_window_region( thread_display(), data
, hrgn
);
2154 else if (X11DRV_get_whole_window( hwnd
))
2156 SendMessageW( hwnd
, WM_X11DRV_SET_WIN_REGION
, 0, 0 );
2162 /**********************************************************************
2163 * X11DRV_WindowMessage (X11DRV.@)
2165 LRESULT
X11DRV_WindowMessage( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2167 struct x11drv_win_data
*data
;
2171 case WM_X11DRV_ACQUIRE_SELECTION
:
2172 return X11DRV_AcquireClipboard( hwnd
);
2173 case WM_X11DRV_DELETE_WINDOW
:
2174 return SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0 );
2175 case WM_X11DRV_SET_WIN_FORMAT
:
2176 return set_win_format( hwnd
, (XID
)wp
);
2177 case WM_X11DRV_SET_WIN_REGION
:
2178 if ((data
= X11DRV_get_win_data( hwnd
))) sync_window_region( thread_display(), data
, (HRGN
)1 );
2180 case WM_X11DRV_RESIZE_DESKTOP
:
2181 X11DRV_resize_desktop( LOWORD(lp
), HIWORD(lp
) );
2184 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg
, hwnd
, wp
, lp
);
2190 /***********************************************************************
2191 * is_netwm_supported
2193 static BOOL
is_netwm_supported( Display
*display
, Atom atom
)
2195 static Atom
*net_supported
;
2196 static int net_supported_count
= -1;
2200 if (net_supported_count
== -1)
2204 unsigned long count
, remaining
;
2206 if (!XGetWindowProperty( display
, DefaultRootWindow(display
), x11drv_atom(_NET_SUPPORTED
), 0,
2207 ~0UL, False
, XA_ATOM
, &type
, &format
, &count
,
2208 &remaining
, (unsigned char **)&net_supported
))
2209 net_supported_count
= get_property_size( format
, count
) / sizeof(Atom
);
2211 net_supported_count
= 0;
2213 wine_tsx11_unlock();
2215 for (i
= 0; i
< net_supported_count
; i
++)
2216 if (net_supported
[i
] == atom
) return TRUE
;
2221 /***********************************************************************
2222 * SysCommand (X11DRV.@)
2224 * Perform WM_SYSCOMMAND handling.
2226 LRESULT
X11DRV_SysCommand( HWND hwnd
, WPARAM wparam
, LPARAM lparam
)
2228 WPARAM hittest
= wparam
& 0x0f;
2232 Display
*display
= thread_display();
2233 struct x11drv_win_data
*data
;
2235 if (!(data
= X11DRV_get_win_data( hwnd
))) return -1;
2236 if (!data
->whole_window
|| !data
->managed
|| !data
->mapped
) return -1;
2238 switch (wparam
& 0xfff0)
2241 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
2242 else dir
= _NET_WM_MOVERESIZE_MOVE
;
2245 /* windows without WS_THICKFRAME are not resizable through the window manager */
2246 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_THICKFRAME
)) return -1;
2250 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
2251 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
2252 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
2253 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
2254 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
2255 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
2256 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
2257 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
2258 default: dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
; break;
2263 /* prevent a simple ALT press+release from activating the system menu,
2264 * as that can get confusing on managed windows */
2265 if ((WCHAR
)lparam
) return -1; /* got an explicit char */
2266 if (GetMenu( hwnd
)) return -1; /* window has a real menu */
2267 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_SYSMENU
)) return -1; /* no system menu */
2268 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam
, lparam
);
2275 if (IsZoomed(hwnd
)) return -1;
2277 if (!is_netwm_supported( display
, x11drv_atom(_NET_WM_MOVERESIZE
) ))
2279 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
2283 dwPoint
= GetMessagePos();
2284 x
= (short)LOWORD(dwPoint
);
2285 y
= (short)HIWORD(dwPoint
);
2287 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd
, x
, y
, dir
);
2289 xev
.xclient
.type
= ClientMessage
;
2290 xev
.xclient
.window
= X11DRV_get_whole_window(hwnd
);
2291 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_MOVERESIZE
);
2292 xev
.xclient
.serial
= 0;
2293 xev
.xclient
.display
= display
;
2294 xev
.xclient
.send_event
= True
;
2295 xev
.xclient
.format
= 32;
2296 xev
.xclient
.data
.l
[0] = x
; /* x coord */
2297 xev
.xclient
.data
.l
[1] = y
; /* y coord */
2298 xev
.xclient
.data
.l
[2] = dir
; /* direction */
2299 xev
.xclient
.data
.l
[3] = 1; /* button */
2300 xev
.xclient
.data
.l
[4] = 0; /* unused */
2302 /* need to ungrab the pointer that may have been automatically grabbed
2303 * with a ButtonPress event */
2305 XUngrabPointer( display
, CurrentTime
);
2306 XSendEvent(display
, root_window
, False
, SubstructureNotifyMask
, &xev
);
2307 wine_tsx11_unlock();