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 #ifndef DEFAULTMANAGED
100 /* set to 1 to enable default managed instead of default not managed */
101 #define DEFAULTMANAGED 0
104 /* activated windows are managed */
105 if (!(swp_flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
))) return TRUE
;
106 if (hwnd
== GetActiveWindow()) return TRUE
;
107 /* windows with caption are managed */
108 if ((style
& WS_CAPTION
) == WS_CAPTION
) return TRUE
;
109 /* windows with thick frame are managed */
110 if (style
& WS_THICKFRAME
) return TRUE
;
112 if (style
& WS_POPUP
)
114 /* popup with sysmenu == caption are managed */
115 if (style
& WS_SYSMENU
) return TRUE
;
116 /* full-screen popup windows are managed */
117 if (window_rect
->left
<= 0 && window_rect
->right
>= screen_width
&&
118 window_rect
->top
<= 0 && window_rect
->bottom
>= screen_height
)
121 /* all other popups are not managed */
125 /* application windows are managed */
126 ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
127 if (ex_style
& WS_EX_APPWINDOW
) return TRUE
;
129 /* default: managed */
132 /* default: not managed */
139 /***********************************************************************
140 * X11DRV_is_window_rect_mapped
142 * Check if the X whole window should be mapped based on its rectangle
144 static BOOL
is_window_rect_mapped( const RECT
*rect
)
146 /* don't map if rect is empty */
147 if (IsRectEmpty( rect
)) return FALSE
;
149 /* don't map if rect is off-screen */
150 if (rect
->left
>= virtual_screen_rect
.right
||
151 rect
->top
>= virtual_screen_rect
.bottom
||
152 rect
->right
<= virtual_screen_rect
.left
||
153 rect
->bottom
<= virtual_screen_rect
.top
)
160 /***********************************************************************
161 * is_window_resizable
163 * Check if window should be made resizable by the window manager
165 static inline BOOL
is_window_resizable( struct x11drv_win_data
*data
, DWORD style
)
167 if (style
& WS_THICKFRAME
) return TRUE
;
168 /* Metacity needs the window to be resizable to make it fullscreen */
169 return (data
->whole_rect
.left
<= 0 && data
->whole_rect
.right
>= screen_width
&&
170 data
->whole_rect
.top
<= 0 && data
->whole_rect
.bottom
>= screen_height
);
174 /***********************************************************************
177 static HWND
get_window_owner( HWND hwnd
)
180 HWND owner
= GetWindow( hwnd
, GW_OWNER
);
181 /* ignore the zero-size owners used by Delphi apps */
182 if (owner
&& GetWindowRect( owner
, &rect
) && IsRectEmpty( &rect
)) owner
= 0;
187 /***********************************************************************
188 * get_mwm_decorations
190 static unsigned long get_mwm_decorations( struct x11drv_win_data
*data
,
191 DWORD style
, DWORD ex_style
)
193 unsigned long ret
= 0;
195 if (!decorated_mode
) return 0;
197 if (IsRectEmpty( &data
->window_rect
)) return 0;
198 if (data
->shaped
) return 0;
200 if (ex_style
& WS_EX_TOOLWINDOW
) return 0;
202 if ((style
& WS_CAPTION
) == WS_CAPTION
)
204 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
205 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
206 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
207 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
209 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
210 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
211 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
216 /***********************************************************************
217 * get_x11_rect_offset
219 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
221 static void get_x11_rect_offset( struct x11drv_win_data
*data
, RECT
*rect
)
223 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
226 rect
->top
= rect
->bottom
= rect
->left
= rect
->right
= 0;
228 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
229 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
230 decor
= get_mwm_decorations( data
, style
, ex_style
);
232 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
233 if (decor
& MWM_DECOR_BORDER
)
235 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
236 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
239 AdjustWindowRectEx( rect
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
243 /***********************************************************************
244 * get_window_attributes
246 * Fill the window attributes structure for an X window.
248 static int get_window_attributes( Display
*display
, struct x11drv_win_data
*data
,
249 XSetWindowAttributes
*attr
)
251 attr
->override_redirect
= !data
->managed
;
252 attr
->colormap
= X11DRV_PALETTE_PaletteXColormap
;
253 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
254 attr
->cursor
= x11drv_thread_data()->cursor
;
255 attr
->bit_gravity
= NorthWestGravity
;
256 attr
->win_gravity
= StaticGravity
;
257 attr
->backing_store
= NotUseful
;
258 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
259 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
260 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
| KeymapStateMask
);
261 if (data
->managed
) attr
->event_mask
|= StructureNotifyMask
| PropertyChangeMask
;
263 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
| CWCursor
|
264 CWEventMask
| CWBitGravity
| CWBackingStore
);
268 /***********************************************************************
269 * create_client_window
271 static Window
create_client_window( Display
*display
, struct x11drv_win_data
*data
, XVisualInfo
*vis
)
274 XSetWindowAttributes attr
;
276 Visual
*client_visual
= vis
? vis
->visual
: visual
;
278 attr
.bit_gravity
= NorthWestGravity
;
279 attr
.win_gravity
= NorthWestGravity
;
280 attr
.backing_store
= NotUseful
;
281 attr
.event_mask
= (ExposureMask
| PointerMotionMask
|
282 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
283 mask
= CWEventMask
| CWBitGravity
| CWWinGravity
| CWBackingStore
;
285 if ((cx
= data
->client_rect
.right
- data
->client_rect
.left
) <= 0) cx
= 1;
286 if ((cy
= data
->client_rect
.bottom
- data
->client_rect
.top
) <= 0) cy
= 1;
292 attr
.colormap
= XCreateColormap( display
, root_window
, vis
->visual
,
293 (vis
->class == PseudoColor
|| vis
->class == GrayScale
||
294 vis
->class == DirectColor
) ? AllocAll
: AllocNone
);
298 client
= XCreateWindow( display
, data
->whole_window
,
299 data
->client_rect
.left
- data
->whole_rect
.left
,
300 data
->client_rect
.top
- data
->whole_rect
.top
,
301 cx
, cy
, 0, screen_depth
, InputOutput
,
302 client_visual
, mask
, &attr
);
309 if (data
->client_window
)
311 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
312 if (thread_data
->cursor_window
== data
->client_window
) thread_data
->cursor_window
= None
;
313 XDeleteContext( display
, data
->client_window
, winContext
);
314 XDestroyWindow( display
, data
->client_window
);
316 data
->client_window
= client
;
317 data
->visualid
= XVisualIDFromVisual( client_visual
);
319 if (data
->colormap
) XFreeColormap( display
, data
->colormap
);
320 data
->colormap
= vis
? attr
.colormap
: 0;
322 XMapWindow( display
, data
->client_window
);
323 XSaveContext( display
, data
->client_window
, winContext
, (char *)data
->hwnd
);
326 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)data
->client_window
);
327 return data
->client_window
;
331 /***********************************************************************
334 * Change the X window attributes when the window style has changed.
336 static void sync_window_style( Display
*display
, struct x11drv_win_data
*data
)
338 if (data
->whole_window
!= root_window
)
340 XSetWindowAttributes attr
;
341 int mask
= get_window_attributes( display
, data
, &attr
);
344 XChangeWindowAttributes( display
, data
->whole_window
, mask
, &attr
);
350 /***********************************************************************
353 * Update the X11 window region.
355 static void sync_window_region( Display
*display
, struct x11drv_win_data
*data
, HRGN win_region
)
357 #ifdef HAVE_LIBXSHAPE
358 HRGN hrgn
= win_region
;
360 if (!data
->whole_window
) return;
361 data
->shaped
= FALSE
;
363 if (hrgn
== (HRGN
)1) /* hack: win_region == 1 means retrieve region from server */
365 if (!(hrgn
= CreateRectRgn( 0, 0, 0, 0 ))) return;
366 if (GetWindowRgn( data
->hwnd
, hrgn
) == ERROR
)
368 DeleteObject( hrgn
);
376 XShapeCombineMask( display
, data
->whole_window
, ShapeBounding
, 0, 0, None
, ShapeSet
);
381 RGNDATA
*pRegionData
= X11DRV_GetRegionData( hrgn
, 0 );
385 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
386 data
->window_rect
.left
- data
->whole_rect
.left
,
387 data
->window_rect
.top
- data
->whole_rect
.top
,
388 (XRectangle
*)pRegionData
->Buffer
,
389 pRegionData
->rdh
.nCount
, ShapeSet
, YXBanded
);
391 HeapFree(GetProcessHeap(), 0, pRegionData
);
395 if (hrgn
&& hrgn
!= win_region
) DeleteObject( hrgn
);
396 #endif /* HAVE_LIBXSHAPE */
400 /***********************************************************************
403 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
406 char *buffer
, *utf8_buffer
;
409 /* allocate new buffer for window text */
410 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
411 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
412 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
414 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
415 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
417 HeapFree( GetProcessHeap(), 0, buffer
);
420 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
423 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
425 XSetWMName( display
, win
, &prop
);
426 XSetWMIconName( display
, win
, &prop
);
430 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
431 according to the standard
432 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
434 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
435 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
438 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
439 HeapFree( GetProcessHeap(), 0, buffer
);
443 /***********************************************************************
446 static BOOL
set_win_format( HWND hwnd
, XID fbconfig_id
)
448 struct x11drv_win_data
*data
;
452 if (!(data
= X11DRV_get_win_data(hwnd
)) &&
453 !(data
= X11DRV_create_win_data(hwnd
))) return FALSE
;
455 if (!(vis
= visual_from_fbconfig_id(fbconfig_id
))) return FALSE
;
457 if (data
->whole_window
)
459 Display
*display
= thread_display();
460 Window client
= data
->client_window
;
462 if (vis
->visualid
!= data
->visualid
)
464 client
= create_client_window( display
, data
, vis
);
465 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client
, data
->hwnd
, fbconfig_id
);
471 if (client
) goto done
;
475 w
= data
->client_rect
.right
- data
->client_rect
.left
;
476 h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
481 #ifdef SONAME_LIBXCOMPOSITE
484 XSetWindowAttributes attrib
;
485 static Window dummy_parent
;
488 attrib
.override_redirect
= True
;
491 dummy_parent
= XCreateWindow( gdi_display
, root_window
, -1, -1, 1, 1, 0, screen_depth
,
492 InputOutput
, visual
, CWOverrideRedirect
, &attrib
);
493 XMapWindow( gdi_display
, dummy_parent
);
495 data
->colormap
= XCreateColormap(gdi_display
, dummy_parent
, vis
->visual
,
496 (vis
->class == PseudoColor
||
497 vis
->class == GrayScale
||
498 vis
->class == DirectColor
) ?
499 AllocAll
: AllocNone
);
500 attrib
.colormap
= data
->colormap
;
501 XInstallColormap(gdi_display
, attrib
.colormap
);
503 if(data
->gl_drawable
) XDestroyWindow(gdi_display
, data
->gl_drawable
);
504 data
->gl_drawable
= XCreateWindow(gdi_display
, dummy_parent
, -w
, 0, w
, h
, 0,
505 vis
->depth
, InputOutput
, vis
->visual
,
506 CWColormap
| CWOverrideRedirect
,
508 if(data
->gl_drawable
)
510 pXCompositeRedirectWindow(gdi_display
, data
->gl_drawable
,
511 CompositeRedirectManual
);
512 XMapWindow(gdi_display
, data
->gl_drawable
);
515 XFlush( gdi_display
);
521 WARN("XComposite is not available, using GLXPixmap hack\n");
525 if(data
->pixmap
) XFreePixmap(gdi_display
, data
->pixmap
);
526 data
->pixmap
= XCreatePixmap(gdi_display
, root_window
, w
, h
, vis
->depth
);
534 if(data
->gl_drawable
) destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
535 data
->gl_drawable
= create_glxpixmap(gdi_display
, vis
, data
->pixmap
);
536 if(!data
->gl_drawable
)
538 XFreePixmap(gdi_display
, data
->pixmap
);
542 XFlush( gdi_display
);
544 if (data
->pixmap
) SetPropA(hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
547 if (!data
->gl_drawable
) return FALSE
;
549 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
550 data
->gl_drawable
, fbconfig_id
);
551 SetPropA(hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
554 data
->fbconfig_id
= fbconfig_id
;
555 SetPropA(hwnd
, fbconfig_id_prop
, (HANDLE
)data
->fbconfig_id
);
556 /* force DCE invalidation */
557 SetWindowPos( hwnd
, 0, 0, 0, 0, 0,
558 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOMOVE
|
559 SWP_NOREDRAW
| SWP_DEFERERASE
| SWP_NOSENDCHANGING
| SWP_STATECHANGED
);
563 /***********************************************************************
566 static void sync_gl_drawable(struct x11drv_win_data
*data
)
568 int w
= data
->client_rect
.right
- data
->client_rect
.left
;
569 int h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
577 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
578 #ifdef SONAME_LIBXCOMPOSITE
582 XMoveResizeWindow(gdi_display
, data
->gl_drawable
, -w
, 0, w
, h
);
588 if (!(vis
= visual_from_fbconfig_id(data
->fbconfig_id
))) return;
591 pix
= XCreatePixmap(gdi_display
, root_window
, w
, h
, vis
->depth
);
594 ERR("Failed to create pixmap for offscreen rendering\n");
600 glxp
= create_glxpixmap(gdi_display
, vis
, pix
);
603 ERR("Failed to create drawable for offscreen rendering\n");
604 XFreePixmap(gdi_display
, pix
);
612 mark_drawable_dirty(data
->gl_drawable
, glxp
);
614 XFreePixmap(gdi_display
, data
->pixmap
);
615 destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
616 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp
, data
->gl_drawable
);
619 data
->gl_drawable
= glxp
;
621 XFlush( gdi_display
);
624 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
625 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
629 /***********************************************************************
632 * fill the window changes structure
634 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
638 if (old
->right
- old
->left
!= new->right
- new->left
)
640 if ((changes
->width
= new->right
- new->left
) <= 0) changes
->width
= 1;
643 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
645 if ((changes
->height
= new->bottom
- new->top
) <= 0) changes
->height
= 1;
648 if (old
->left
!= new->left
)
650 changes
->x
= new->left
;
653 if (old
->top
!= new->top
)
655 changes
->y
= new->top
;
662 /***********************************************************************
665 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
667 XSetWindowAttributes attr
;
669 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
670 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
671 attr
.bit_gravity
= NorthWestGravity
;
672 attr
.backing_store
= NotUseful
/*WhenMapped*/;
673 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
676 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
677 GetSystemMetrics( SM_CXICON
),
678 GetSystemMetrics( SM_CYICON
),
681 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
682 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
683 XFlush( display
); /* make sure the window exists before we start painting to it */
686 TRACE( "created %lx\n", data
->icon_window
);
687 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
688 return data
->icon_window
;
693 /***********************************************************************
694 * destroy_icon_window
696 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
698 if (!data
->icon_window
) return;
699 if (x11drv_thread_data()->cursor_window
== data
->icon_window
)
700 x11drv_thread_data()->cursor_window
= None
;
702 XDeleteContext( display
, data
->icon_window
, winContext
);
703 XDestroyWindow( display
, data
->icon_window
);
704 data
->icon_window
= 0;
706 RemovePropA( data
->hwnd
, icon_window_prop
);
710 /***********************************************************************
713 * Set the icon wm hints
715 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
, HICON hIcon
)
717 XWMHints
*hints
= data
->wm_hints
;
719 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
720 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
721 data
->hWMIconBitmap
= 0;
722 data
->hWMIconMask
= 0;
726 if (!data
->icon_window
) create_icon_window( display
, data
);
727 hints
->icon_window
= data
->icon_window
;
728 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
738 GetIconInfo(hIcon
, &ii
);
740 GetObjectA(ii
.hbmMask
, sizeof(bmMask
), &bmMask
);
743 rcMask
.right
= bmMask
.bmWidth
;
744 rcMask
.bottom
= bmMask
.bmHeight
;
746 hDC
= CreateCompatibleDC(0);
747 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
748 InvertRect(hDC
, &rcMask
);
749 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
750 SelectObject(hDC
, hbmOrig
);
753 data
->hWMIconBitmap
= ii
.hbmColor
;
754 data
->hWMIconMask
= ii
.hbmMask
;
756 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
757 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
758 destroy_icon_window( display
, data
);
759 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
764 /***********************************************************************
767 * set the window size hints
769 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
771 XSizeHints
* size_hints
;
773 if (!(size_hints
= XAllocSizeHints())) return;
775 size_hints
->win_gravity
= StaticGravity
;
776 size_hints
->flags
|= PWinGravity
;
778 /* don't update size hints if window is not in normal state */
779 if (!(style
& (WS_MINIMIZE
| WS_MAXIMIZE
)))
781 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
783 size_hints
->x
= data
->whole_rect
.left
;
784 size_hints
->y
= data
->whole_rect
.top
;
785 size_hints
->flags
|= PPosition
;
788 if (!is_window_resizable( data
, style
))
790 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
791 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
792 size_hints
->min_width
= size_hints
->max_width
;
793 size_hints
->min_height
= size_hints
->max_height
;
794 size_hints
->flags
|= PMinSize
| PMaxSize
;
797 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
802 /***********************************************************************
805 * get the name of the current process for setting class hints
807 static char *get_process_name(void)
813 WCHAR module
[MAX_PATH
];
814 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
815 if (len
&& len
< MAX_PATH
)
818 WCHAR
*p
, *appname
= module
;
820 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
821 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
822 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
823 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
825 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
834 /***********************************************************************
835 * set_initial_wm_hints
837 * Set the window manager hints that don't change over the lifetime of a window.
839 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
844 XClassHint
*class_hints
;
845 char *process_name
= get_process_name();
851 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
852 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
853 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
854 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
855 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
858 if ((class_hints
= XAllocClassHint()))
860 static char wine
[] = "Wine";
862 class_hints
->res_name
= process_name
;
863 class_hints
->res_class
= wine
;
864 XSetClassHint( display
, data
->whole_window
, class_hints
);
865 XFree( class_hints
);
868 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
869 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
870 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
872 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
873 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
875 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
876 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
878 data
->wm_hints
= XAllocWMHints();
883 HICON icon
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_BIG
, 0 );
884 if (!icon
) icon
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
);
885 data
->wm_hints
->flags
= 0;
886 set_icon_hints( display
, data
, icon
);
891 /***********************************************************************
894 * Set the window manager hints for a newly-created window
896 static void set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
901 DWORD style
, ex_style
;
904 if (data
->hwnd
== GetDesktopWindow())
906 /* force some styles for the desktop to get the correct decorations */
907 style
= WS_POPUP
| WS_VISIBLE
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
908 ex_style
= WS_EX_APPWINDOW
;
913 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
914 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
915 owner
= get_window_owner( data
->hwnd
);
918 /* transient for hint */
921 Window owner_win
= X11DRV_get_whole_window( owner
);
923 XSetTransientForHint( display
, data
->whole_window
, owner_win
);
925 group_leader
= owner_win
;
927 else group_leader
= data
->whole_window
;
932 set_size_hints( display
, data
, style
);
934 /* set the WM_WINDOW_TYPE */
935 if (style
& WS_THICKFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
936 else if (ex_style
& WS_EX_APPWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
937 else if (style
& WS_DLGFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
938 else if (ex_style
& WS_EX_DLGMODALFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
939 else if ((style
& WS_POPUP
) && owner
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
940 #if 0 /* many window managers don't handle utility windows very well */
941 else if (ex_style
& WS_EX_TOOLWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY
);
943 else window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
945 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
946 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
948 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
949 mwm_hints
.decorations
= get_mwm_decorations( data
, style
, ex_style
);
950 mwm_hints
.functions
= MWM_FUNC_MOVE
;
951 if (is_window_resizable( data
, style
)) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
952 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
953 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
954 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
956 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
957 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
958 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
963 data
->wm_hints
->flags
|= InputHint
| StateHint
| WindowGroupHint
;
964 data
->wm_hints
->input
= !(style
& WS_DISABLED
);
965 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
966 data
->wm_hints
->window_group
= group_leader
;
967 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
974 /***********************************************************************
975 * update_net_wm_states
977 void update_net_wm_states( Display
*display
, struct x11drv_win_data
*data
)
979 static const unsigned int state_atoms
[NB_NET_WM_STATES
] =
981 XATOM__NET_WM_STATE_FULLSCREEN
,
982 XATOM__NET_WM_STATE_ABOVE
,
983 XATOM__NET_WM_STATE_MAXIMIZED_VERT
,
984 XATOM__NET_WM_STATE_SKIP_PAGER
,
985 XATOM__NET_WM_STATE_SKIP_TASKBAR
988 DWORD i
, style
, ex_style
, new_state
= 0;
990 if (!data
->managed
) return;
991 if (data
->whole_window
== root_window
) return;
993 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
994 if (data
->whole_rect
.left
<= 0 && data
->whole_rect
.right
>= screen_width
&&
995 data
->whole_rect
.top
<= 0 && data
->whole_rect
.bottom
>= screen_height
)
997 if ((style
& WS_MAXIMIZE
) && (style
& WS_CAPTION
) == WS_CAPTION
)
998 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
999 else if (!(style
& WS_MINIMIZE
))
1000 new_state
|= (1 << NET_WM_STATE_FULLSCREEN
);
1002 else if (style
& WS_MAXIMIZE
)
1003 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
1005 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
1006 if (ex_style
& WS_EX_TOPMOST
)
1007 new_state
|= (1 << NET_WM_STATE_ABOVE
);
1008 if (ex_style
& WS_EX_TOOLWINDOW
)
1009 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
) | (1 << NET_WM_STATE_SKIP_PAGER
);
1010 if (!(ex_style
& WS_EX_APPWINDOW
) && get_window_owner( data
->hwnd
))
1011 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
);
1013 if (!data
->mapped
) /* set the _NET_WM_STATE atom directly */
1015 Atom atoms
[NB_NET_WM_STATES
+1];
1018 for (i
= count
= 0; i
< NB_NET_WM_STATES
; i
++)
1020 if (!(new_state
& (1 << i
))) continue;
1021 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
1022 i
, data
->hwnd
, data
->whole_window
);
1023 atoms
[count
++] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
1024 if (state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
)
1025 atoms
[count
++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
);
1028 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_STATE
), XA_ATOM
,
1029 32, PropModeReplace
, (unsigned char *)atoms
, count
);
1030 wine_tsx11_unlock();
1032 else /* ask the window manager to do it for us */
1036 xev
.xclient
.type
= ClientMessage
;
1037 xev
.xclient
.window
= data
->whole_window
;
1038 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
1039 xev
.xclient
.serial
= 0;
1040 xev
.xclient
.display
= display
;
1041 xev
.xclient
.send_event
= True
;
1042 xev
.xclient
.format
= 32;
1043 xev
.xclient
.data
.l
[3] = 1;
1045 for (i
= 0; i
< NB_NET_WM_STATES
; i
++)
1047 if (!((data
->net_wm_state
^ new_state
) & (1 << i
))) continue; /* unchanged */
1049 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1050 i
, data
->hwnd
, data
->whole_window
,
1051 (new_state
& (1 << i
)) != 0, (data
->net_wm_state
& (1 << i
)) != 0 );
1053 xev
.xclient
.data
.l
[0] = (new_state
& (1 << i
)) ? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
1054 xev
.xclient
.data
.l
[1] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
1055 xev
.xclient
.data
.l
[2] = ((state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
) ?
1056 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
) : 0);
1058 XSendEvent( display
, root_window
, False
,
1059 SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
1060 wine_tsx11_unlock();
1063 data
->net_wm_state
= new_state
;
1067 /***********************************************************************
1070 static void set_xembed_flags( Display
*display
, struct x11drv_win_data
*data
, unsigned long flags
)
1072 unsigned long info
[2];
1074 info
[0] = 0; /* protocol version */
1077 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_XEMBED_INFO
),
1078 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
, (unsigned char*)info
, 2 );
1079 wine_tsx11_unlock();
1083 /***********************************************************************
1086 static void map_window( Display
*display
, struct x11drv_win_data
*data
, DWORD new_style
)
1088 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1090 wait_for_withdrawn_state( display
, data
, TRUE
);
1092 if (!data
->embedded
)
1094 update_net_wm_states( display
, data
);
1095 sync_window_style( display
, data
);
1097 XMapWindow( display
, data
->whole_window
);
1098 wine_tsx11_unlock();
1100 else set_xembed_flags( display
, data
, XEMBED_MAPPED
);
1102 data
->mapped
= TRUE
;
1103 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
1107 /***********************************************************************
1110 static void unmap_window( Display
*display
, struct x11drv_win_data
*data
)
1112 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1114 if (!data
->embedded
)
1116 wait_for_withdrawn_state( display
, data
, FALSE
);
1118 if (data
->managed
) XWithdrawWindow( display
, data
->whole_window
, DefaultScreen(display
) );
1119 else XUnmapWindow( display
, data
->whole_window
);
1120 wine_tsx11_unlock();
1122 else set_xembed_flags( display
, data
, 0 );
1124 data
->mapped
= FALSE
;
1125 data
->net_wm_state
= 0;
1129 /***********************************************************************
1130 * make_window_embedded
1132 void make_window_embedded( Display
*display
, struct x11drv_win_data
*data
)
1136 /* the window cannot be mapped before being embedded */
1137 unmap_window( display
, data
);
1138 data
->embedded
= TRUE
;
1139 map_window( display
, data
, 0 );
1143 data
->embedded
= TRUE
;
1144 set_xembed_flags( display
, data
, 0 );
1149 /***********************************************************************
1150 * X11DRV_window_to_X_rect
1152 * Convert a rect from client to X window coordinates
1154 void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1158 if (!data
->managed
) return;
1159 if (IsRectEmpty( rect
)) return;
1161 get_x11_rect_offset( data
, &rc
);
1163 rect
->left
-= rc
.left
;
1164 rect
->right
-= rc
.right
;
1165 rect
->top
-= rc
.top
;
1166 rect
->bottom
-= rc
.bottom
;
1167 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1168 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1172 /***********************************************************************
1173 * X11DRV_X_to_window_rect
1175 * Opposite of X11DRV_window_to_X_rect
1177 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1181 if (!data
->managed
) return;
1182 if (IsRectEmpty( rect
)) return;
1184 get_x11_rect_offset( data
, &rc
);
1186 rect
->left
+= rc
.left
;
1187 rect
->right
+= rc
.right
;
1188 rect
->top
+= rc
.top
;
1189 rect
->bottom
+= rc
.bottom
;
1190 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1191 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1195 /***********************************************************************
1196 * sync_window_position
1198 * Synchronize the X window position with the Windows one
1200 static void sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
1201 UINT swp_flags
, const RECT
*old_client_rect
,
1202 const RECT
*old_whole_rect
)
1204 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1205 XWindowChanges changes
;
1206 unsigned int mask
= 0;
1208 if (data
->managed
&& data
->iconic
) return;
1210 /* resizing a managed maximized window is not allowed */
1211 if (!(style
& WS_MAXIMIZE
) || !data
->managed
)
1213 if ((changes
.width
= data
->whole_rect
.right
- data
->whole_rect
.left
) <= 0) changes
.width
= 1;
1214 if ((changes
.height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
) <= 0) changes
.height
= 1;
1215 mask
|= CWWidth
| CWHeight
;
1218 /* only the size is allowed to change for the desktop window */
1219 if (data
->whole_window
!= root_window
)
1221 changes
.x
= data
->whole_rect
.left
- virtual_screen_rect
.left
;
1222 changes
.y
= data
->whole_rect
.top
- virtual_screen_rect
.top
;
1226 if (!(swp_flags
& SWP_NOZORDER
) || (swp_flags
& SWP_SHOWWINDOW
))
1228 /* find window that this one must be after */
1229 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
1230 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
1231 prev
= GetWindow( prev
, GW_HWNDPREV
);
1232 if (!prev
) /* top child */
1234 changes
.stack_mode
= Above
;
1235 mask
|= CWStackMode
;
1237 /* should use stack_mode Below but most window managers don't get it right */
1238 /* and Above with a sibling doesn't work so well either, so we ignore it */
1241 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
1242 data
->hwnd
, data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1243 data
->whole_rect
.right
- data
->whole_rect
.left
,
1244 data
->whole_rect
.bottom
- data
->whole_rect
.top
, changes
.sibling
, mask
);
1247 set_size_hints( display
, data
, style
);
1248 XReconfigureWMWindow( display
, data
->whole_window
,
1249 DefaultScreen(display
), mask
, &changes
);
1250 wine_tsx11_unlock();
1254 /***********************************************************************
1255 * sync_client_position
1257 * Synchronize the X client window position with the Windows one
1259 static void sync_client_position( Display
*display
, struct x11drv_win_data
*data
,
1260 UINT swp_flags
, const RECT
*old_client_rect
,
1261 const RECT
*old_whole_rect
)
1264 XWindowChanges changes
;
1265 RECT old
= *old_client_rect
;
1266 RECT
new = data
->client_rect
;
1268 OffsetRect( &old
, -old_whole_rect
->left
, -old_whole_rect
->top
);
1269 OffsetRect( &new, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
1270 if (!(mask
= get_window_changes( &changes
, &old
, &new ))) return;
1272 if (data
->client_window
)
1274 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1275 data
->client_window
, new.left
, new.top
,
1276 new.right
- new.left
, new.bottom
- new.top
, mask
);
1278 XConfigureWindow( display
, data
->client_window
, mask
, &changes
);
1279 wine_tsx11_unlock();
1282 if (data
->gl_drawable
&& (mask
& (CWWidth
|CWHeight
))) sync_gl_drawable( data
);
1286 /***********************************************************************
1289 * Move the window bits when a window is moved.
1291 static void move_window_bits( struct x11drv_win_data
*data
, const RECT
*old_rect
, const RECT
*new_rect
,
1292 const RECT
*old_client_rect
)
1294 RECT src_rect
= *old_rect
;
1295 RECT dst_rect
= *new_rect
;
1296 HDC hdc_src
, hdc_dst
;
1301 if (!data
->whole_window
)
1303 OffsetRect( &dst_rect
, -data
->window_rect
.left
, -data
->window_rect
.top
);
1304 parent
= GetAncestor( data
->hwnd
, GA_PARENT
);
1305 hdc_src
= GetDCEx( parent
, 0, DCX_CACHE
);
1306 hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
1310 OffsetRect( &dst_rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
1311 /* make src rect relative to the old position of the window */
1312 OffsetRect( &src_rect
, -old_client_rect
->left
, -old_client_rect
->top
);
1313 if (dst_rect
.left
== src_rect
.left
&& dst_rect
.top
== src_rect
.top
) return;
1314 hdc_src
= hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
);
1317 code
= X11DRV_START_EXPOSURES
;
1318 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
1320 TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n",
1321 data
->hwnd
, data
->whole_window
, data
->client_window
,
1322 wine_dbgstr_rect(&src_rect
), wine_dbgstr_rect(&dst_rect
) );
1323 BitBlt( hdc_dst
, dst_rect
.left
, dst_rect
.top
,
1324 dst_rect
.right
- dst_rect
.left
, dst_rect
.bottom
- dst_rect
.top
,
1325 hdc_src
, src_rect
.left
, src_rect
.top
, SRCCOPY
);
1327 code
= X11DRV_END_EXPOSURES
;
1328 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, sizeof(rgn
), (LPSTR
)&rgn
);
1330 ReleaseDC( data
->hwnd
, hdc_dst
);
1331 if (hdc_src
!= hdc_dst
) ReleaseDC( parent
, hdc_src
);
1335 if (!data
->whole_window
)
1337 /* map region to client rect since we are using DCX_WINDOW */
1338 OffsetRgn( rgn
, data
->window_rect
.left
- data
->client_rect
.left
,
1339 data
->window_rect
.top
- data
->client_rect
.top
);
1340 RedrawWindow( data
->hwnd
, NULL
, rgn
,
1341 RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
1343 else RedrawWindow( data
->hwnd
, NULL
, rgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1344 DeleteObject( rgn
);
1349 /**********************************************************************
1350 * create_whole_window
1352 * Create the whole X window for a given window
1354 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1357 XSetWindowAttributes attr
;
1360 if (!(cx
= data
->window_rect
.right
- data
->window_rect
.left
)) cx
= 1;
1361 if (!(cy
= data
->window_rect
.bottom
- data
->window_rect
.top
)) cy
= 1;
1363 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1365 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1366 data
->managed
= TRUE
;
1367 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1370 mask
= get_window_attributes( display
, data
, &attr
);
1374 data
->whole_rect
= data
->window_rect
;
1375 data
->whole_window
= XCreateWindow( display
, root_window
,
1376 data
->window_rect
.left
- virtual_screen_rect
.left
,
1377 data
->window_rect
.top
- virtual_screen_rect
.top
,
1378 cx
, cy
, 0, screen_depth
, InputOutput
,
1379 visual
, mask
, &attr
);
1381 if (data
->whole_window
) XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1382 wine_tsx11_unlock();
1384 if (!data
->whole_window
) return 0;
1386 if (!create_client_window( display
, data
, NULL
))
1389 XDeleteContext( display
, data
->whole_window
, winContext
);
1390 XDestroyWindow( display
, data
->whole_window
);
1391 data
->whole_window
= 0;
1392 wine_tsx11_unlock();
1396 set_initial_wm_hints( display
, data
);
1397 set_wm_hints( display
, data
);
1399 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1401 /* set the window text */
1402 if (!InternalGetWindowText( data
->hwnd
, text
, sizeof(text
)/sizeof(WCHAR
) )) text
[0] = 0;
1403 sync_window_text( display
, data
->whole_window
, text
);
1405 /* set the window region */
1406 sync_window_region( display
, data
, (HRGN
)1 );
1409 XFlush( display
); /* make sure the window exists before we start painting to it */
1410 wine_tsx11_unlock();
1411 return data
->whole_window
;
1415 /**********************************************************************
1416 * destroy_whole_window
1418 * Destroy the whole X window for a given window.
1420 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
, BOOL already_destroyed
)
1422 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1424 if (!data
->whole_window
) return;
1426 TRACE( "win %p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1427 if (thread_data
->cursor_window
== data
->whole_window
||
1428 thread_data
->cursor_window
== data
->client_window
)
1429 thread_data
->cursor_window
= None
;
1431 XDeleteContext( display
, data
->whole_window
, winContext
);
1432 XDeleteContext( display
, data
->client_window
, winContext
);
1433 if (!already_destroyed
) XDestroyWindow( display
, data
->whole_window
);
1434 data
->whole_window
= data
->client_window
= 0;
1435 data
->wm_state
= WithdrawnState
;
1436 data
->net_wm_state
= 0;
1437 data
->mapped
= FALSE
;
1440 XUnsetICFocus( data
->xic
);
1441 XDestroyIC( data
->xic
);
1444 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1446 XFree( data
->wm_hints
);
1447 data
->wm_hints
= NULL
;
1448 wine_tsx11_unlock();
1449 RemovePropA( data
->hwnd
, whole_window_prop
);
1450 RemovePropA( data
->hwnd
, client_window_prop
);
1454 /*****************************************************************
1455 * SetWindowText (X11DRV.@)
1457 void X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1461 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(gdi_display
))
1463 Display
*display
= thread_init_display();
1464 sync_window_text( display
, win
, text
);
1469 /***********************************************************************
1470 * SetWindowStyle (X11DRV.@)
1472 * Update the X state of a window to reflect a style change
1474 void X11DRV_SetWindowStyle( HWND hwnd
, DWORD old_style
)
1476 struct x11drv_win_data
*data
;
1477 DWORD new_style
, changed
;
1479 if (hwnd
== GetDesktopWindow()) return;
1480 new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1481 changed
= new_style
^ old_style
;
1483 if ((changed
& WS_VISIBLE
) && (new_style
& WS_VISIBLE
))
1485 /* we don't unmap windows, that causes trouble with the window manager */
1486 if (!(data
= X11DRV_get_win_data( hwnd
)) &&
1487 !(data
= X11DRV_create_win_data( hwnd
))) return;
1489 if (data
->whole_window
&& is_window_rect_mapped( &data
->window_rect
))
1491 Display
*display
= thread_display();
1492 set_wm_hints( display
, data
);
1493 if (!data
->mapped
) map_window( display
, data
, new_style
);
1497 if (changed
& WS_DISABLED
)
1499 data
= X11DRV_get_win_data( hwnd
);
1500 if (data
&& data
->wm_hints
)
1503 data
->wm_hints
->input
= !(new_style
& WS_DISABLED
);
1504 XSetWMHints( thread_display(), data
->whole_window
, data
->wm_hints
);
1505 wine_tsx11_unlock();
1511 /***********************************************************************
1512 * DestroyWindow (X11DRV.@)
1514 void X11DRV_DestroyWindow( HWND hwnd
)
1516 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1517 struct x11drv_win_data
*data
;
1519 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1524 destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
1525 XFreePixmap(gdi_display
, data
->pixmap
);
1526 wine_tsx11_unlock();
1528 else if (data
->gl_drawable
)
1531 XDestroyWindow(gdi_display
, data
->gl_drawable
);
1532 wine_tsx11_unlock();
1535 destroy_whole_window( thread_data
->display
, data
, FALSE
);
1536 destroy_icon_window( thread_data
->display
, data
);
1541 XFreeColormap( thread_data
->display
, data
->colormap
);
1542 wine_tsx11_unlock();
1545 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1546 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1547 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1549 XDeleteContext( thread_data
->display
, (XID
)hwnd
, win_data_context
);
1550 wine_tsx11_unlock();
1551 HeapFree( GetProcessHeap(), 0, data
);
1555 /***********************************************************************
1556 * X11DRV_DestroyNotify
1558 void X11DRV_DestroyNotify( HWND hwnd
, XEvent
*event
)
1560 Display
*display
= event
->xdestroywindow
.display
;
1561 struct x11drv_win_data
*data
;
1563 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1565 FIXME( "window %p/%lx destroyed from the outside\n", hwnd
, data
->whole_window
);
1566 destroy_whole_window( display
, data
, TRUE
);
1570 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1572 struct x11drv_win_data
*data
;
1574 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
1578 if (!winContext
) winContext
= XUniqueContext();
1579 if (!win_data_context
) win_data_context
= XUniqueContext();
1580 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1581 wine_tsx11_unlock();
1587 /* initialize the desktop window id in the desktop manager process */
1588 static struct x11drv_win_data
*create_desktop_win_data( Display
*display
, HWND hwnd
)
1590 struct x11drv_win_data
*data
;
1592 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1593 data
->whole_window
= data
->client_window
= root_window
;
1594 data
->managed
= TRUE
;
1595 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1596 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1597 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)root_window
);
1598 set_initial_wm_hints( display
, data
);
1602 /**********************************************************************
1603 * CreateDesktopWindow (X11DRV.@)
1605 BOOL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1607 unsigned int width
, height
;
1609 /* retrieve the real size of the desktop */
1610 SERVER_START_REQ( get_window_rectangles
)
1613 wine_server_call( req
);
1614 width
= reply
->window
.right
- reply
->window
.left
;
1615 height
= reply
->window
.bottom
- reply
->window
.top
;
1619 if (!width
&& !height
) /* not initialized yet */
1621 SERVER_START_REQ( set_window_pos
)
1625 req
->flags
= SWP_NOZORDER
;
1626 req
->window
.left
= virtual_screen_rect
.left
;
1627 req
->window
.top
= virtual_screen_rect
.top
;
1628 req
->window
.right
= virtual_screen_rect
.right
;
1629 req
->window
.bottom
= virtual_screen_rect
.bottom
;
1630 req
->client
= req
->window
;
1631 wine_server_call( req
);
1637 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1638 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1644 /**********************************************************************
1645 * CreateWindow (X11DRV.@)
1647 BOOL
X11DRV_CreateWindow( HWND hwnd
)
1649 if (hwnd
== GetDesktopWindow() && root_window
!= DefaultRootWindow( gdi_display
))
1651 Display
*display
= thread_init_display();
1653 /* the desktop win data can't be created lazily */
1654 if (!create_desktop_win_data( display
, hwnd
)) return FALSE
;
1660 /***********************************************************************
1661 * X11DRV_get_win_data
1663 * Return the X11 data structure associated with a window.
1665 struct x11drv_win_data
*X11DRV_get_win_data( HWND hwnd
)
1667 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1670 if (!thread_data
) return NULL
;
1671 if (!hwnd
) return NULL
;
1672 if (XFindContext( thread_data
->display
, (XID
)hwnd
, win_data_context
, &data
)) data
= NULL
;
1673 return (struct x11drv_win_data
*)data
;
1677 /***********************************************************************
1678 * X11DRV_create_win_data
1680 * Create an X11 data window structure for an existing window.
1682 struct x11drv_win_data
*X11DRV_create_win_data( HWND hwnd
)
1685 struct x11drv_win_data
*data
;
1688 if (!(parent
= GetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop */
1690 /* don't create win data for HWND_MESSAGE windows */
1691 if (parent
!= GetDesktopWindow() && !GetAncestor( parent
, GA_PARENT
)) return NULL
;
1693 display
= thread_init_display();
1694 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1696 GetWindowRect( hwnd
, &data
->window_rect
);
1697 MapWindowPoints( 0, parent
, (POINT
*)&data
->window_rect
, 2 );
1698 data
->whole_rect
= data
->window_rect
;
1699 GetClientRect( hwnd
, &data
->client_rect
);
1700 MapWindowPoints( hwnd
, parent
, (POINT
*)&data
->client_rect
, 2 );
1702 if (parent
== GetDesktopWindow())
1704 if (!create_whole_window( display
, data
))
1706 HeapFree( GetProcessHeap(), 0, data
);
1709 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1710 hwnd
, data
->whole_window
, data
->client_window
, wine_dbgstr_rect( &data
->window_rect
),
1711 wine_dbgstr_rect( &data
->whole_rect
), wine_dbgstr_rect( &data
->client_rect
));
1717 /***********************************************************************
1718 * X11DRV_get_whole_window
1720 * Return the X window associated with the full area of a window
1722 Window
X11DRV_get_whole_window( HWND hwnd
)
1724 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1728 if (hwnd
== GetDesktopWindow()) return root_window
;
1729 return (Window
)GetPropA( hwnd
, whole_window_prop
);
1731 return data
->whole_window
;
1735 /***********************************************************************
1736 * X11DRV_get_client_window
1738 * Return the X window associated with the client area of a window
1740 Window
X11DRV_get_client_window( HWND hwnd
)
1742 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1746 if (hwnd
== GetDesktopWindow()) return root_window
;
1747 return (Window
)GetPropA( hwnd
, client_window_prop
);
1749 return data
->client_window
;
1753 /***********************************************************************
1756 * Return the X input context associated with a window
1758 XIC
X11DRV_get_ic( HWND hwnd
)
1760 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1763 if (!data
) return 0;
1764 if (data
->xic
) return data
->xic
;
1765 if (!(xim
= x11drv_thread_data()->xim
)) return 0;
1766 return X11DRV_CreateIC( xim
, data
);
1770 /***********************************************************************
1771 * X11DRV_GetDC (X11DRV.@)
1773 void X11DRV_GetDC( HDC hdc
, HWND hwnd
, HWND top
, const RECT
*win_rect
,
1774 const RECT
*top_rect
, DWORD flags
)
1776 struct x11drv_escape_set_drawable escape
;
1777 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1779 escape
.code
= X11DRV_SET_DRAWABLE
;
1780 escape
.mode
= IncludeInferiors
;
1781 escape
.fbconfig_id
= 0;
1782 escape
.gl_drawable
= 0;
1784 escape
.gl_copy
= FALSE
;
1786 if (top
== hwnd
&& data
&& IsIconic( hwnd
) && data
->icon_window
)
1788 escape
.drawable
= data
->icon_window
;
1790 else if (top
== hwnd
)
1792 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1793 /* GL draws to the client area even for window DCs */
1794 escape
.gl_drawable
= data
? data
->client_window
: X11DRV_get_client_window( hwnd
);
1795 if (flags
& DCX_WINDOW
)
1796 escape
.drawable
= data
? data
->whole_window
: X11DRV_get_whole_window( hwnd
);
1798 escape
.drawable
= escape
.gl_drawable
;
1802 escape
.drawable
= X11DRV_get_client_window( top
);
1803 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1804 escape
.gl_drawable
= data
? data
->gl_drawable
: (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
1805 escape
.pixmap
= data
? data
->pixmap
: (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
1806 escape
.gl_copy
= (escape
.gl_drawable
!= 0);
1807 if (flags
& DCX_CLIPCHILDREN
) escape
.mode
= ClipByChildren
;
1810 escape
.dc_rect
.left
= win_rect
->left
- top_rect
->left
;
1811 escape
.dc_rect
.top
= win_rect
->top
- top_rect
->top
;
1812 escape
.dc_rect
.right
= win_rect
->right
- top_rect
->left
;
1813 escape
.dc_rect
.bottom
= win_rect
->bottom
- top_rect
->top
;
1814 escape
.drawable_rect
.left
= top_rect
->left
;
1815 escape
.drawable_rect
.top
= top_rect
->top
;
1816 escape
.drawable_rect
.right
= top_rect
->right
;
1817 escape
.drawable_rect
.bottom
= top_rect
->bottom
;
1819 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1823 /***********************************************************************
1824 * X11DRV_ReleaseDC (X11DRV.@)
1826 void X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
1828 struct x11drv_escape_set_drawable escape
;
1830 escape
.code
= X11DRV_SET_DRAWABLE
;
1831 escape
.drawable
= root_window
;
1832 escape
.mode
= IncludeInferiors
;
1833 escape
.drawable_rect
= virtual_screen_rect
;
1834 SetRect( &escape
.dc_rect
, 0, 0, virtual_screen_rect
.right
- virtual_screen_rect
.left
,
1835 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
);
1836 escape
.fbconfig_id
= 0;
1837 escape
.gl_drawable
= 0;
1839 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1843 /***********************************************************************
1844 * SetCapture (X11DRV.@)
1846 void X11DRV_SetCapture( HWND hwnd
, UINT flags
)
1848 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1850 if (!thread_data
) return;
1851 if (!(flags
& (GUI_INMOVESIZE
| GUI_INMENUMODE
))) return;
1855 Window grab_win
= X11DRV_get_client_window( GetAncestor( hwnd
, GA_ROOT
) );
1857 if (!grab_win
) return;
1859 XFlush( gdi_display
);
1860 XGrabPointer( thread_data
->display
, grab_win
, False
,
1861 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1862 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
);
1863 wine_tsx11_unlock();
1864 thread_data
->grab_window
= grab_win
;
1866 else /* release capture */
1869 XFlush( gdi_display
);
1870 XUngrabPointer( thread_data
->display
, CurrentTime
);
1871 wine_tsx11_unlock();
1872 thread_data
->grab_window
= None
;
1877 /*****************************************************************
1878 * SetParent (X11DRV.@)
1880 void X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
1882 Display
*display
= thread_display();
1883 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1886 if (parent
== old_parent
) return;
1888 if (parent
!= GetDesktopWindow()) /* a child window */
1890 if (old_parent
== GetDesktopWindow())
1892 /* destroy the old X windows */
1893 destroy_whole_window( display
, data
, FALSE
);
1894 destroy_icon_window( display
, data
);
1897 data
->managed
= FALSE
;
1898 RemovePropA( data
->hwnd
, managed_prop
);
1902 else /* new top level window */
1904 /* FIXME: we ignore errors since we can't really recover anyway */
1905 create_whole_window( display
, data
);
1910 /*****************************************************************
1911 * SetFocus (X11DRV.@)
1915 void X11DRV_SetFocus( HWND hwnd
)
1917 Display
*display
= thread_display();
1918 struct x11drv_win_data
*data
;
1919 XWindowChanges changes
;
1921 if (!(hwnd
= GetAncestor( hwnd
, GA_ROOT
))) return;
1922 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1923 if (data
->managed
|| !data
->whole_window
) return;
1925 /* Set X focus and install colormap */
1927 changes
.stack_mode
= Above
;
1928 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
1929 if (root_window
== DefaultRootWindow(display
))
1931 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1932 /* FIXME: this is not entirely correct */
1933 XSetInputFocus( display
, data
->whole_window
, RevertToParent
,
1935 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1937 wine_tsx11_unlock();
1941 /***********************************************************************
1942 * WindowPosChanging (X11DRV.@)
1944 void X11DRV_WindowPosChanging( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
1945 const RECT
*window_rect
, const RECT
*client_rect
, RECT
*visible_rect
)
1947 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1948 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1952 /* create the win data if the window is being made visible */
1953 if (!(style
& WS_VISIBLE
) && !(swp_flags
& SWP_SHOWWINDOW
)) return;
1954 if (!(data
= X11DRV_create_win_data( hwnd
))) return;
1957 /* check if we need to switch the window to managed */
1958 if (!data
->managed
&& data
->whole_window
&& is_window_managed( hwnd
, swp_flags
, window_rect
))
1960 TRACE( "making win %p/%lx managed\n", hwnd
, data
->whole_window
);
1961 if (data
->mapped
) unmap_window( thread_display(), data
);
1962 data
->managed
= TRUE
;
1963 SetPropA( hwnd
, managed_prop
, (HANDLE
)1 );
1966 *visible_rect
= *window_rect
;
1967 X11DRV_window_to_X_rect( data
, visible_rect
);
1971 /***********************************************************************
1972 * WindowPosChanged (X11DRV.@)
1974 void X11DRV_WindowPosChanged( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
1975 const RECT
*rectWindow
, const RECT
*rectClient
,
1976 const RECT
*visible_rect
, const RECT
*valid_rects
)
1978 struct x11drv_thread_data
*thread_data
;
1980 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1981 DWORD new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1982 RECT old_whole_rect
, old_client_rect
;
1987 thread_data
= x11drv_thread_data();
1988 display
= thread_data
->display
;
1990 old_whole_rect
= data
->whole_rect
;
1991 old_client_rect
= data
->client_rect
;
1992 data
->window_rect
= *rectWindow
;
1993 data
->whole_rect
= *visible_rect
;
1994 data
->client_rect
= *rectClient
;
1996 TRACE( "win %p window %s client %s style %08x flags %08x\n",
1997 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
, swp_flags
);
1999 if (!IsRectEmpty( &valid_rects
[0] ))
2001 int x_offset
= old_whole_rect
.left
- data
->whole_rect
.left
;
2002 int y_offset
= old_whole_rect
.top
- data
->whole_rect
.top
;
2004 /* if all that happened is that the whole window moved, copy everything */
2005 if (!(swp_flags
& SWP_FRAMECHANGED
) &&
2006 old_whole_rect
.right
- data
->whole_rect
.right
== x_offset
&&
2007 old_whole_rect
.bottom
- data
->whole_rect
.bottom
== y_offset
&&
2008 old_client_rect
.left
- data
->client_rect
.left
== x_offset
&&
2009 old_client_rect
.right
- data
->client_rect
.right
== x_offset
&&
2010 old_client_rect
.top
- data
->client_rect
.top
== y_offset
&&
2011 old_client_rect
.bottom
- data
->client_rect
.bottom
== y_offset
&&
2012 !memcmp( &valid_rects
[0], &data
->client_rect
, sizeof(RECT
) ))
2014 /* if we have an X window the bits will be moved by the X server */
2015 if (!data
->whole_window
)
2016 move_window_bits( data
, &old_whole_rect
, &data
->whole_rect
, &old_client_rect
);
2019 move_window_bits( data
, &valid_rects
[1], &valid_rects
[0], &old_client_rect
);
2023 XFlush( gdi_display
); /* make sure painting is done before we move the window */
2024 wine_tsx11_unlock();
2026 sync_client_position( display
, data
, swp_flags
, &old_client_rect
, &old_whole_rect
);
2028 if (!data
->whole_window
) return;
2030 /* check if we are currently processing an event relevant to this window */
2032 if (thread_data
->current_event
&& thread_data
->current_event
->xany
.window
== data
->whole_window
)
2033 event_type
= thread_data
->current_event
->type
;
2035 if (event_type
!= ConfigureNotify
&& event_type
!= PropertyNotify
)
2036 event_type
= 0; /* ignore other events */
2040 if (((swp_flags
& SWP_HIDEWINDOW
) && !(new_style
& WS_VISIBLE
)) ||
2041 (!event_type
&& !is_window_rect_mapped( rectWindow
)))
2042 unmap_window( display
, data
);
2045 /* don't change position if we are about to minimize or maximize a managed window */
2047 !(data
->managed
&& (swp_flags
& SWP_STATECHANGED
) && (new_style
& (WS_MINIMIZE
|WS_MAXIMIZE
))))
2048 sync_window_position( display
, data
, swp_flags
, &old_client_rect
, &old_whole_rect
);
2050 if ((new_style
& WS_VISIBLE
) &&
2051 ((new_style
& WS_MINIMIZE
) || is_window_rect_mapped( rectWindow
)))
2053 if (!data
->mapped
|| (swp_flags
& (SWP_FRAMECHANGED
|SWP_STATECHANGED
)))
2054 set_wm_hints( display
, data
);
2058 map_window( display
, data
, new_style
);
2060 else if ((swp_flags
& SWP_STATECHANGED
) && (!data
->iconic
!= !(new_style
& WS_MINIMIZE
)))
2062 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
2063 TRACE( "changing win %p iconic state to %u\n", data
->hwnd
, data
->iconic
);
2066 XIconifyWindow( display
, data
->whole_window
, DefaultScreen(display
) );
2067 else if (is_window_rect_mapped( rectWindow
))
2068 XMapWindow( display
, data
->whole_window
);
2069 wine_tsx11_unlock();
2070 update_net_wm_states( display
, data
);
2072 else if (!event_type
)
2074 update_net_wm_states( display
, data
);
2079 XFlush( display
); /* make sure changes are done before we start painting again */
2080 wine_tsx11_unlock();
2084 /***********************************************************************
2085 * ShowWindow (X11DRV.@)
2087 UINT
X11DRV_ShowWindow( HWND hwnd
, INT cmd
, RECT
*rect
, UINT swp
)
2090 unsigned int width
, height
, border
, depth
;
2092 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2093 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2094 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2096 if (!data
|| !data
->whole_window
|| !data
->managed
|| !data
->mapped
|| data
->iconic
) return swp
;
2097 if (style
& WS_MINIMIZE
) return swp
;
2099 /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */
2101 if (!thread_data
->current_event
|| thread_data
->current_event
->xany
.window
!= data
->whole_window
)
2104 if (thread_data
->current_event
->type
!= ConfigureNotify
&&
2105 thread_data
->current_event
->type
!= PropertyNotify
)
2108 TRACE( "win %p/%lx cmd %d at %s flags %08x\n",
2109 hwnd
, data
->whole_window
, cmd
, wine_dbgstr_rect(rect
), swp
);
2112 XGetGeometry( thread_data
->display
, data
->whole_window
,
2113 &root
, &x
, &y
, &width
, &height
, &border
, &depth
);
2114 XTranslateCoordinates( thread_data
->display
, data
->whole_window
, root
, 0, 0, &x
, &y
, &top
);
2115 wine_tsx11_unlock();
2118 rect
->right
= x
+ width
;
2119 rect
->bottom
= y
+ height
;
2120 OffsetRect( rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
2121 X11DRV_X_to_window_rect( data
, rect
);
2122 return swp
& ~(SWP_NOMOVE
| SWP_NOCLIENTMOVE
| SWP_NOSIZE
| SWP_NOCLIENTSIZE
);
2126 /**********************************************************************
2127 * SetWindowIcon (X11DRV.@)
2129 * hIcon or hIconSm has changed (or is being initialised for the
2130 * first time). Complete the X11 driver-specific initialisation
2131 * and set the window hints.
2133 * This is not entirely correct, may need to create
2134 * an icon window and set the pixmap as a background
2136 void X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
2138 Display
*display
= thread_display();
2139 struct x11drv_win_data
*data
;
2141 if (type
!= ICON_BIG
) return; /* nothing to do here */
2143 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
2144 if (!data
->whole_window
) return;
2145 if (!data
->managed
) return;
2149 set_icon_hints( display
, data
, icon
);
2151 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
2152 wine_tsx11_unlock();
2157 /***********************************************************************
2158 * SetWindowRgn (X11DRV.@)
2160 * Assign specified region to window (for non-rectangular windows)
2162 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
2164 struct x11drv_win_data
*data
;
2166 if ((data
= X11DRV_get_win_data( hwnd
)))
2168 sync_window_region( thread_display(), data
, hrgn
);
2170 else if (X11DRV_get_whole_window( hwnd
))
2172 SendMessageW( hwnd
, WM_X11DRV_SET_WIN_REGION
, 0, 0 );
2178 /**********************************************************************
2179 * X11DRV_WindowMessage (X11DRV.@)
2181 LRESULT
X11DRV_WindowMessage( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2183 struct x11drv_win_data
*data
;
2187 case WM_X11DRV_ACQUIRE_SELECTION
:
2188 return X11DRV_AcquireClipboard( hwnd
);
2189 case WM_X11DRV_DELETE_WINDOW
:
2190 return SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0 );
2191 case WM_X11DRV_SET_WIN_FORMAT
:
2192 return set_win_format( hwnd
, (XID
)wp
);
2193 case WM_X11DRV_SET_WIN_REGION
:
2194 if ((data
= X11DRV_get_win_data( hwnd
))) sync_window_region( thread_display(), data
, (HRGN
)1 );
2196 case WM_X11DRV_RESIZE_DESKTOP
:
2197 X11DRV_resize_desktop( LOWORD(lp
), HIWORD(lp
) );
2200 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg
, hwnd
, wp
, lp
);
2206 /***********************************************************************
2207 * is_netwm_supported
2209 static BOOL
is_netwm_supported( Display
*display
, Atom atom
)
2211 static Atom
*net_supported
;
2212 static int net_supported_count
= -1;
2216 if (net_supported_count
== -1)
2220 unsigned long count
, remaining
;
2222 if (!XGetWindowProperty( display
, DefaultRootWindow(display
), x11drv_atom(_NET_SUPPORTED
), 0,
2223 ~0UL, False
, XA_ATOM
, &type
, &format
, &count
,
2224 &remaining
, (unsigned char **)&net_supported
))
2225 net_supported_count
= get_property_size( format
, count
) / sizeof(Atom
);
2227 net_supported_count
= 0;
2229 wine_tsx11_unlock();
2231 for (i
= 0; i
< net_supported_count
; i
++)
2232 if (net_supported
[i
] == atom
) return TRUE
;
2237 /***********************************************************************
2238 * SysCommand (X11DRV.@)
2240 * Perform WM_SYSCOMMAND handling.
2242 LRESULT
X11DRV_SysCommand( HWND hwnd
, WPARAM wparam
, LPARAM lparam
)
2244 WPARAM hittest
= wparam
& 0x0f;
2248 Display
*display
= thread_display();
2249 struct x11drv_win_data
*data
;
2251 if (!(data
= X11DRV_get_win_data( hwnd
))) return -1;
2252 if (!data
->whole_window
|| !data
->managed
|| !data
->mapped
) return -1;
2254 switch (wparam
& 0xfff0)
2257 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
2258 else dir
= _NET_WM_MOVERESIZE_MOVE
;
2261 /* windows without WS_THICKFRAME are not resizable through the window manager */
2262 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_THICKFRAME
)) return -1;
2266 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
2267 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
2268 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
2269 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
2270 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
2271 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
2272 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
2273 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
2274 default: dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
; break;
2279 /* prevent a simple ALT press+release from activating the system menu,
2280 * as that can get confusing on managed windows */
2281 if ((WCHAR
)lparam
) return -1; /* got an explicit char */
2282 if (GetMenu( hwnd
)) return -1; /* window has a real menu */
2283 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_SYSMENU
)) return -1; /* no system menu */
2284 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam
, lparam
);
2291 if (IsZoomed(hwnd
)) return -1;
2293 if (!is_netwm_supported( display
, x11drv_atom(_NET_WM_MOVERESIZE
) ))
2295 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
2299 dwPoint
= GetMessagePos();
2300 x
= (short)LOWORD(dwPoint
);
2301 y
= (short)HIWORD(dwPoint
);
2303 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd
, x
, y
, dir
);
2305 xev
.xclient
.type
= ClientMessage
;
2306 xev
.xclient
.window
= X11DRV_get_whole_window(hwnd
);
2307 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_MOVERESIZE
);
2308 xev
.xclient
.serial
= 0;
2309 xev
.xclient
.display
= display
;
2310 xev
.xclient
.send_event
= True
;
2311 xev
.xclient
.format
= 32;
2312 xev
.xclient
.data
.l
[0] = x
; /* x coord */
2313 xev
.xclient
.data
.l
[1] = y
; /* y coord */
2314 xev
.xclient
.data
.l
[2] = dir
; /* direction */
2315 xev
.xclient
.data
.l
[3] = 1; /* button */
2316 xev
.xclient
.data
.l
[4] = 0; /* unused */
2318 /* need to ungrab the pointer that may have been automatically grabbed
2319 * with a ButtonPress event */
2321 XUngrabPointer( display
, CurrentTime
);
2322 XSendEvent(display
, root_window
, False
, SubstructureNotifyMask
, &xev
);
2323 wine_tsx11_unlock();