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 /***********************************************************************
385 * sync_window_opacity
387 static void sync_window_opacity( Display
*display
, Window win
,
388 COLORREF key
, BYTE alpha
, DWORD flags
)
390 unsigned long opacity
= 0xffffffff;
392 if (flags
& LWA_ALPHA
) opacity
= (0xffffffff / 0xff) * alpha
;
394 if (flags
& LWA_COLORKEY
) FIXME("LWA_COLORKEY not supported\n");
397 if (opacity
== 0xffffffff)
398 XDeleteProperty( display
, win
, x11drv_atom(_NET_WM_WINDOW_OPACITY
) );
400 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_WINDOW_OPACITY
),
401 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&opacity
, 1 );
406 /***********************************************************************
409 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
412 char *buffer
, *utf8_buffer
;
415 /* allocate new buffer for window text */
416 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
417 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
418 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
420 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
421 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
423 HeapFree( GetProcessHeap(), 0, buffer
);
426 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
429 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
431 XSetWMName( display
, win
, &prop
);
432 XSetWMIconName( display
, win
, &prop
);
436 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
437 according to the standard
438 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
440 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
441 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
444 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
445 HeapFree( GetProcessHeap(), 0, buffer
);
449 /***********************************************************************
452 static BOOL
set_win_format( HWND hwnd
, XID fbconfig_id
)
454 struct x11drv_win_data
*data
;
458 if (!(data
= X11DRV_get_win_data(hwnd
)) &&
459 !(data
= X11DRV_create_win_data(hwnd
))) return FALSE
;
461 if (!(vis
= visual_from_fbconfig_id(fbconfig_id
))) return FALSE
;
463 if (data
->whole_window
)
465 Display
*display
= thread_display();
466 Window client
= data
->client_window
;
468 if (vis
->visualid
!= data
->visualid
)
470 client
= create_client_window( display
, data
, vis
);
471 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client
, data
->hwnd
, fbconfig_id
);
477 if (client
) goto done
;
481 w
= data
->client_rect
.right
- data
->client_rect
.left
;
482 h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
487 #ifdef SONAME_LIBXCOMPOSITE
490 XSetWindowAttributes attrib
;
491 static Window dummy_parent
;
494 attrib
.override_redirect
= True
;
497 dummy_parent
= XCreateWindow( gdi_display
, root_window
, -1, -1, 1, 1, 0, screen_depth
,
498 InputOutput
, visual
, CWOverrideRedirect
, &attrib
);
499 XMapWindow( gdi_display
, dummy_parent
);
501 data
->colormap
= XCreateColormap(gdi_display
, dummy_parent
, vis
->visual
,
502 (vis
->class == PseudoColor
||
503 vis
->class == GrayScale
||
504 vis
->class == DirectColor
) ?
505 AllocAll
: AllocNone
);
506 attrib
.colormap
= data
->colormap
;
507 XInstallColormap(gdi_display
, attrib
.colormap
);
509 if(data
->gl_drawable
) XDestroyWindow(gdi_display
, data
->gl_drawable
);
510 data
->gl_drawable
= XCreateWindow(gdi_display
, dummy_parent
, -w
, 0, w
, h
, 0,
511 vis
->depth
, InputOutput
, vis
->visual
,
512 CWColormap
| CWOverrideRedirect
,
514 if(data
->gl_drawable
)
516 pXCompositeRedirectWindow(gdi_display
, data
->gl_drawable
,
517 CompositeRedirectManual
);
518 XMapWindow(gdi_display
, data
->gl_drawable
);
521 XFlush( gdi_display
);
527 WARN("XComposite is not available, using GLXPixmap hack\n");
531 if(data
->pixmap
) XFreePixmap(gdi_display
, data
->pixmap
);
532 data
->pixmap
= XCreatePixmap(gdi_display
, root_window
, w
, h
, vis
->depth
);
540 if(data
->gl_drawable
) destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
541 data
->gl_drawable
= create_glxpixmap(gdi_display
, vis
, data
->pixmap
);
542 if(!data
->gl_drawable
)
544 XFreePixmap(gdi_display
, data
->pixmap
);
548 XFlush( gdi_display
);
550 if (data
->pixmap
) SetPropA(hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
553 if (!data
->gl_drawable
) return FALSE
;
555 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
556 data
->gl_drawable
, fbconfig_id
);
557 SetPropA(hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
560 data
->fbconfig_id
= fbconfig_id
;
561 SetPropA(hwnd
, fbconfig_id_prop
, (HANDLE
)data
->fbconfig_id
);
562 /* force DCE invalidation */
563 SetWindowPos( hwnd
, 0, 0, 0, 0, 0,
564 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOMOVE
|
565 SWP_NOREDRAW
| SWP_DEFERERASE
| SWP_NOSENDCHANGING
| SWP_STATECHANGED
);
569 /***********************************************************************
572 static void sync_gl_drawable(struct x11drv_win_data
*data
)
574 int w
= data
->client_rect
.right
- data
->client_rect
.left
;
575 int h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
583 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
584 #ifdef SONAME_LIBXCOMPOSITE
588 XMoveResizeWindow(gdi_display
, data
->gl_drawable
, -w
, 0, w
, h
);
594 if (!(vis
= visual_from_fbconfig_id(data
->fbconfig_id
))) return;
597 pix
= XCreatePixmap(gdi_display
, root_window
, w
, h
, vis
->depth
);
600 ERR("Failed to create pixmap for offscreen rendering\n");
606 glxp
= create_glxpixmap(gdi_display
, vis
, pix
);
609 ERR("Failed to create drawable for offscreen rendering\n");
610 XFreePixmap(gdi_display
, pix
);
618 mark_drawable_dirty(data
->gl_drawable
, glxp
);
620 XFreePixmap(gdi_display
, data
->pixmap
);
621 destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
622 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp
, data
->gl_drawable
);
625 data
->gl_drawable
= glxp
;
627 XFlush( gdi_display
);
630 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
631 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
635 /***********************************************************************
638 * fill the window changes structure
640 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
644 if (old
->right
- old
->left
!= new->right
- new->left
)
646 if ((changes
->width
= new->right
- new->left
) <= 0) changes
->width
= 1;
649 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
651 if ((changes
->height
= new->bottom
- new->top
) <= 0) changes
->height
= 1;
654 if (old
->left
!= new->left
)
656 changes
->x
= new->left
;
659 if (old
->top
!= new->top
)
661 changes
->y
= new->top
;
668 /***********************************************************************
671 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
673 XSetWindowAttributes attr
;
675 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
676 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
677 attr
.bit_gravity
= NorthWestGravity
;
678 attr
.backing_store
= NotUseful
/*WhenMapped*/;
679 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
682 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
683 GetSystemMetrics( SM_CXICON
),
684 GetSystemMetrics( SM_CYICON
),
687 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
688 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
689 XFlush( display
); /* make sure the window exists before we start painting to it */
692 TRACE( "created %lx\n", data
->icon_window
);
693 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
694 return data
->icon_window
;
699 /***********************************************************************
700 * destroy_icon_window
702 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
704 if (!data
->icon_window
) return;
705 if (x11drv_thread_data()->cursor_window
== data
->icon_window
)
706 x11drv_thread_data()->cursor_window
= None
;
708 XDeleteContext( display
, data
->icon_window
, winContext
);
709 XDestroyWindow( display
, data
->icon_window
);
710 data
->icon_window
= 0;
712 RemovePropA( data
->hwnd
, icon_window_prop
);
716 /***********************************************************************
719 * Set the icon wm hints
721 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
, HICON hIcon
)
723 XWMHints
*hints
= data
->wm_hints
;
725 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
726 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
727 data
->hWMIconBitmap
= 0;
728 data
->hWMIconMask
= 0;
732 if (!data
->icon_window
) create_icon_window( display
, data
);
733 hints
->icon_window
= data
->icon_window
;
734 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
744 GetIconInfo(hIcon
, &ii
);
746 GetObjectA(ii
.hbmMask
, sizeof(bmMask
), &bmMask
);
749 rcMask
.right
= bmMask
.bmWidth
;
750 rcMask
.bottom
= bmMask
.bmHeight
;
752 hDC
= CreateCompatibleDC(0);
753 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
754 InvertRect(hDC
, &rcMask
);
755 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
756 SelectObject(hDC
, hbmOrig
);
759 data
->hWMIconBitmap
= ii
.hbmColor
;
760 data
->hWMIconMask
= ii
.hbmMask
;
762 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
763 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
764 destroy_icon_window( display
, data
);
765 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
770 /***********************************************************************
773 * set the window size hints
775 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
777 XSizeHints
* size_hints
;
779 if (!(size_hints
= XAllocSizeHints())) return;
781 size_hints
->win_gravity
= StaticGravity
;
782 size_hints
->flags
|= PWinGravity
;
784 /* don't update size hints if window is not in normal state */
785 if (!(style
& (WS_MINIMIZE
| WS_MAXIMIZE
)))
787 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
789 size_hints
->x
= data
->whole_rect
.left
;
790 size_hints
->y
= data
->whole_rect
.top
;
791 size_hints
->flags
|= PPosition
;
794 if (!is_window_resizable( data
, style
))
796 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
797 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
798 size_hints
->min_width
= size_hints
->max_width
;
799 size_hints
->min_height
= size_hints
->max_height
;
800 size_hints
->flags
|= PMinSize
| PMaxSize
;
803 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
808 /***********************************************************************
811 * get the name of the current process for setting class hints
813 static char *get_process_name(void)
819 WCHAR module
[MAX_PATH
];
820 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
821 if (len
&& len
< MAX_PATH
)
824 WCHAR
*p
, *appname
= module
;
826 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
827 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
828 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
829 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
831 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
840 /***********************************************************************
841 * set_initial_wm_hints
843 * Set the window manager hints that don't change over the lifetime of a window.
845 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
850 XClassHint
*class_hints
;
851 char *process_name
= get_process_name();
857 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
858 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
859 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
860 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
861 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
864 if ((class_hints
= XAllocClassHint()))
866 static char wine
[] = "Wine";
868 class_hints
->res_name
= process_name
;
869 class_hints
->res_class
= wine
;
870 XSetClassHint( display
, data
->whole_window
, class_hints
);
871 XFree( class_hints
);
874 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
875 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
876 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
878 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
879 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
881 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
882 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
884 data
->wm_hints
= XAllocWMHints();
889 HICON icon
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_BIG
, 0 );
890 if (!icon
) icon
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
);
891 data
->wm_hints
->flags
= 0;
892 set_icon_hints( display
, data
, icon
);
897 /***********************************************************************
900 * Set the window manager hints for a newly-created window
902 static void set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
907 DWORD style
, ex_style
;
910 if (data
->hwnd
== GetDesktopWindow())
912 /* force some styles for the desktop to get the correct decorations */
913 style
= WS_POPUP
| WS_VISIBLE
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
914 ex_style
= WS_EX_APPWINDOW
;
919 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
920 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
921 owner
= get_window_owner( data
->hwnd
);
924 /* transient for hint */
927 Window owner_win
= X11DRV_get_whole_window( owner
);
929 XSetTransientForHint( display
, data
->whole_window
, owner_win
);
931 group_leader
= owner_win
;
933 else group_leader
= data
->whole_window
;
938 set_size_hints( display
, data
, style
);
940 /* set the WM_WINDOW_TYPE */
941 if (style
& WS_THICKFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
942 else if (ex_style
& WS_EX_APPWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
943 else if (style
& WS_DLGFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
944 else if (ex_style
& WS_EX_DLGMODALFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
945 else if ((style
& WS_POPUP
) && owner
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
946 #if 0 /* many window managers don't handle utility windows very well */
947 else if (ex_style
& WS_EX_TOOLWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY
);
949 else window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
951 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
952 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
954 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
955 mwm_hints
.decorations
= get_mwm_decorations( data
, style
, ex_style
);
956 mwm_hints
.functions
= MWM_FUNC_MOVE
;
957 if (is_window_resizable( data
, style
)) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
958 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
959 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
960 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
962 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
963 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
964 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
969 data
->wm_hints
->flags
|= InputHint
| StateHint
| WindowGroupHint
;
970 data
->wm_hints
->input
= !(style
& WS_DISABLED
);
971 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
972 data
->wm_hints
->window_group
= group_leader
;
973 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
980 /***********************************************************************
981 * update_net_wm_states
983 void update_net_wm_states( Display
*display
, struct x11drv_win_data
*data
)
985 static const unsigned int state_atoms
[NB_NET_WM_STATES
] =
987 XATOM__NET_WM_STATE_FULLSCREEN
,
988 XATOM__NET_WM_STATE_ABOVE
,
989 XATOM__NET_WM_STATE_MAXIMIZED_VERT
,
990 XATOM__NET_WM_STATE_SKIP_PAGER
,
991 XATOM__NET_WM_STATE_SKIP_TASKBAR
994 DWORD i
, style
, ex_style
, new_state
= 0;
996 if (!data
->managed
) return;
997 if (data
->whole_window
== root_window
) return;
999 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1000 if (data
->whole_rect
.left
<= 0 && data
->whole_rect
.right
>= screen_width
&&
1001 data
->whole_rect
.top
<= 0 && data
->whole_rect
.bottom
>= screen_height
)
1003 if ((style
& WS_MAXIMIZE
) && (style
& WS_CAPTION
) == WS_CAPTION
)
1004 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
1005 else if (!(style
& WS_MINIMIZE
))
1006 new_state
|= (1 << NET_WM_STATE_FULLSCREEN
);
1008 else if (style
& WS_MAXIMIZE
)
1009 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
1011 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
1012 if (ex_style
& WS_EX_TOPMOST
)
1013 new_state
|= (1 << NET_WM_STATE_ABOVE
);
1014 if (ex_style
& WS_EX_TOOLWINDOW
)
1015 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
) | (1 << NET_WM_STATE_SKIP_PAGER
);
1016 if (!(ex_style
& WS_EX_APPWINDOW
) && get_window_owner( data
->hwnd
))
1017 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
);
1019 if (!data
->mapped
) /* set the _NET_WM_STATE atom directly */
1021 Atom atoms
[NB_NET_WM_STATES
+1];
1024 for (i
= count
= 0; i
< NB_NET_WM_STATES
; i
++)
1026 if (!(new_state
& (1 << i
))) continue;
1027 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
1028 i
, data
->hwnd
, data
->whole_window
);
1029 atoms
[count
++] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
1030 if (state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
)
1031 atoms
[count
++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
);
1034 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_STATE
), XA_ATOM
,
1035 32, PropModeReplace
, (unsigned char *)atoms
, count
);
1036 wine_tsx11_unlock();
1038 else /* ask the window manager to do it for us */
1042 xev
.xclient
.type
= ClientMessage
;
1043 xev
.xclient
.window
= data
->whole_window
;
1044 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
1045 xev
.xclient
.serial
= 0;
1046 xev
.xclient
.display
= display
;
1047 xev
.xclient
.send_event
= True
;
1048 xev
.xclient
.format
= 32;
1049 xev
.xclient
.data
.l
[3] = 1;
1051 for (i
= 0; i
< NB_NET_WM_STATES
; i
++)
1053 if (!((data
->net_wm_state
^ new_state
) & (1 << i
))) continue; /* unchanged */
1055 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1056 i
, data
->hwnd
, data
->whole_window
,
1057 (new_state
& (1 << i
)) != 0, (data
->net_wm_state
& (1 << i
)) != 0 );
1059 xev
.xclient
.data
.l
[0] = (new_state
& (1 << i
)) ? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
1060 xev
.xclient
.data
.l
[1] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
1061 xev
.xclient
.data
.l
[2] = ((state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
) ?
1062 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
) : 0);
1064 XSendEvent( display
, root_window
, False
,
1065 SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
1066 wine_tsx11_unlock();
1069 data
->net_wm_state
= new_state
;
1073 /***********************************************************************
1076 static void set_xembed_flags( Display
*display
, struct x11drv_win_data
*data
, unsigned long flags
)
1078 unsigned long info
[2];
1080 info
[0] = 0; /* protocol version */
1083 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_XEMBED_INFO
),
1084 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
, (unsigned char*)info
, 2 );
1085 wine_tsx11_unlock();
1089 /***********************************************************************
1092 static void map_window( Display
*display
, struct x11drv_win_data
*data
, DWORD new_style
)
1094 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1096 wait_for_withdrawn_state( display
, data
, TRUE
);
1098 if (!data
->embedded
)
1100 update_net_wm_states( display
, data
);
1101 sync_window_style( display
, data
);
1103 XMapWindow( display
, data
->whole_window
);
1104 wine_tsx11_unlock();
1106 else set_xembed_flags( display
, data
, XEMBED_MAPPED
);
1108 data
->mapped
= TRUE
;
1109 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
1113 /***********************************************************************
1116 static void unmap_window( Display
*display
, struct x11drv_win_data
*data
)
1118 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1120 if (!data
->embedded
)
1122 wait_for_withdrawn_state( display
, data
, FALSE
);
1124 if (data
->managed
) XWithdrawWindow( display
, data
->whole_window
, DefaultScreen(display
) );
1125 else XUnmapWindow( display
, data
->whole_window
);
1126 wine_tsx11_unlock();
1128 else set_xembed_flags( display
, data
, 0 );
1130 data
->mapped
= FALSE
;
1131 data
->net_wm_state
= 0;
1135 /***********************************************************************
1136 * make_window_embedded
1138 void make_window_embedded( Display
*display
, struct x11drv_win_data
*data
)
1142 /* the window cannot be mapped before being embedded */
1143 unmap_window( display
, data
);
1144 data
->embedded
= TRUE
;
1145 map_window( display
, data
, 0 );
1149 data
->embedded
= TRUE
;
1150 set_xembed_flags( display
, data
, 0 );
1155 /***********************************************************************
1156 * X11DRV_window_to_X_rect
1158 * Convert a rect from client to X window coordinates
1160 void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1164 if (!data
->managed
) return;
1165 if (IsRectEmpty( rect
)) return;
1167 get_x11_rect_offset( data
, &rc
);
1169 rect
->left
-= rc
.left
;
1170 rect
->right
-= rc
.right
;
1171 rect
->top
-= rc
.top
;
1172 rect
->bottom
-= rc
.bottom
;
1173 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1174 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1178 /***********************************************************************
1179 * X11DRV_X_to_window_rect
1181 * Opposite of X11DRV_window_to_X_rect
1183 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1187 if (!data
->managed
) return;
1188 if (IsRectEmpty( rect
)) return;
1190 get_x11_rect_offset( data
, &rc
);
1192 rect
->left
+= rc
.left
;
1193 rect
->right
+= rc
.right
;
1194 rect
->top
+= rc
.top
;
1195 rect
->bottom
+= rc
.bottom
;
1196 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1197 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1201 /***********************************************************************
1202 * sync_window_position
1204 * Synchronize the X window position with the Windows one
1206 static void sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
1207 UINT swp_flags
, const RECT
*old_client_rect
,
1208 const RECT
*old_whole_rect
)
1210 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1211 XWindowChanges changes
;
1212 unsigned int mask
= 0;
1214 if (data
->managed
&& data
->iconic
) return;
1216 /* resizing a managed maximized window is not allowed */
1217 if (!(style
& WS_MAXIMIZE
) || !data
->managed
)
1219 changes
.width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
1220 changes
.height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
1221 /* if window rect is empty force size to 1x1 */
1222 if (changes
.width
<= 0 || changes
.height
<= 0) changes
.width
= changes
.height
= 1;
1223 mask
|= CWWidth
| CWHeight
;
1226 /* only the size is allowed to change for the desktop window */
1227 if (data
->whole_window
!= root_window
)
1229 changes
.x
= data
->whole_rect
.left
- virtual_screen_rect
.left
;
1230 changes
.y
= data
->whole_rect
.top
- virtual_screen_rect
.top
;
1234 if (!(swp_flags
& SWP_NOZORDER
) || (swp_flags
& SWP_SHOWWINDOW
))
1236 /* find window that this one must be after */
1237 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
1238 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
1239 prev
= GetWindow( prev
, GW_HWNDPREV
);
1240 if (!prev
) /* top child */
1242 changes
.stack_mode
= Above
;
1243 mask
|= CWStackMode
;
1245 /* should use stack_mode Below but most window managers don't get it right */
1246 /* and Above with a sibling doesn't work so well either, so we ignore it */
1249 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
1250 data
->hwnd
, data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1251 data
->whole_rect
.right
- data
->whole_rect
.left
,
1252 data
->whole_rect
.bottom
- data
->whole_rect
.top
, changes
.sibling
, mask
);
1255 set_size_hints( display
, data
, style
);
1256 XReconfigureWMWindow( display
, data
->whole_window
,
1257 DefaultScreen(display
), mask
, &changes
);
1258 wine_tsx11_unlock();
1262 /***********************************************************************
1263 * sync_client_position
1265 * Synchronize the X client window position with the Windows one
1267 static void sync_client_position( Display
*display
, struct x11drv_win_data
*data
,
1268 UINT swp_flags
, const RECT
*old_client_rect
,
1269 const RECT
*old_whole_rect
)
1272 XWindowChanges changes
;
1273 RECT old
= *old_client_rect
;
1274 RECT
new = data
->client_rect
;
1276 OffsetRect( &old
, -old_whole_rect
->left
, -old_whole_rect
->top
);
1277 OffsetRect( &new, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
1278 if (!(mask
= get_window_changes( &changes
, &old
, &new ))) return;
1280 if (data
->client_window
)
1282 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1283 data
->client_window
, new.left
, new.top
,
1284 new.right
- new.left
, new.bottom
- new.top
, mask
);
1286 XConfigureWindow( display
, data
->client_window
, mask
, &changes
);
1287 wine_tsx11_unlock();
1290 if (data
->gl_drawable
&& (mask
& (CWWidth
|CWHeight
))) sync_gl_drawable( data
);
1294 /***********************************************************************
1297 * Move the window bits when a window is moved.
1299 static void move_window_bits( struct x11drv_win_data
*data
, const RECT
*old_rect
, const RECT
*new_rect
,
1300 const RECT
*old_client_rect
)
1302 RECT src_rect
= *old_rect
;
1303 RECT dst_rect
= *new_rect
;
1304 HDC hdc_src
, hdc_dst
;
1309 if (!data
->whole_window
)
1311 OffsetRect( &dst_rect
, -data
->window_rect
.left
, -data
->window_rect
.top
);
1312 parent
= GetAncestor( data
->hwnd
, GA_PARENT
);
1313 hdc_src
= GetDCEx( parent
, 0, DCX_CACHE
);
1314 hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
1318 OffsetRect( &dst_rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
1319 /* make src rect relative to the old position of the window */
1320 OffsetRect( &src_rect
, -old_client_rect
->left
, -old_client_rect
->top
);
1321 if (dst_rect
.left
== src_rect
.left
&& dst_rect
.top
== src_rect
.top
) return;
1322 hdc_src
= hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
);
1325 code
= X11DRV_START_EXPOSURES
;
1326 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
1328 TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n",
1329 data
->hwnd
, data
->whole_window
, data
->client_window
,
1330 wine_dbgstr_rect(&src_rect
), wine_dbgstr_rect(&dst_rect
) );
1331 BitBlt( hdc_dst
, dst_rect
.left
, dst_rect
.top
,
1332 dst_rect
.right
- dst_rect
.left
, dst_rect
.bottom
- dst_rect
.top
,
1333 hdc_src
, src_rect
.left
, src_rect
.top
, SRCCOPY
);
1335 code
= X11DRV_END_EXPOSURES
;
1336 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, sizeof(rgn
), (LPSTR
)&rgn
);
1338 ReleaseDC( data
->hwnd
, hdc_dst
);
1339 if (hdc_src
!= hdc_dst
) ReleaseDC( parent
, hdc_src
);
1343 if (!data
->whole_window
)
1345 /* map region to client rect since we are using DCX_WINDOW */
1346 OffsetRgn( rgn
, data
->window_rect
.left
- data
->client_rect
.left
,
1347 data
->window_rect
.top
- data
->client_rect
.top
);
1348 RedrawWindow( data
->hwnd
, NULL
, rgn
,
1349 RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
1351 else RedrawWindow( data
->hwnd
, NULL
, rgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1352 DeleteObject( rgn
);
1357 /**********************************************************************
1358 * create_whole_window
1360 * Create the whole X window for a given window
1362 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1365 XSetWindowAttributes attr
;
1369 DWORD layered_flags
;
1371 if (!(cx
= data
->window_rect
.right
- data
->window_rect
.left
)) cx
= 1;
1372 if (!(cy
= data
->window_rect
.bottom
- data
->window_rect
.top
)) cy
= 1;
1374 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1376 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1377 data
->managed
= TRUE
;
1378 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1381 mask
= get_window_attributes( display
, data
, &attr
);
1385 data
->whole_rect
= data
->window_rect
;
1386 data
->whole_window
= XCreateWindow( display
, root_window
,
1387 data
->window_rect
.left
- virtual_screen_rect
.left
,
1388 data
->window_rect
.top
- virtual_screen_rect
.top
,
1389 cx
, cy
, 0, screen_depth
, InputOutput
,
1390 visual
, mask
, &attr
);
1392 if (data
->whole_window
) XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1393 wine_tsx11_unlock();
1395 if (!data
->whole_window
) return 0;
1397 if (!create_client_window( display
, data
, NULL
))
1400 XDeleteContext( display
, data
->whole_window
, winContext
);
1401 XDestroyWindow( display
, data
->whole_window
);
1402 data
->whole_window
= 0;
1403 wine_tsx11_unlock();
1407 set_initial_wm_hints( display
, data
);
1408 set_wm_hints( display
, data
);
1410 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1412 /* set the window text */
1413 if (!InternalGetWindowText( data
->hwnd
, text
, sizeof(text
)/sizeof(WCHAR
) )) text
[0] = 0;
1414 sync_window_text( display
, data
->whole_window
, text
);
1416 /* set the window region */
1417 sync_window_region( display
, data
, (HRGN
)1 );
1419 /* set the window opacity */
1420 if (!GetLayeredWindowAttributes( data
->hwnd
, &key
, &alpha
, &layered_flags
)) layered_flags
= 0;
1421 sync_window_opacity( display
, data
->whole_window
, key
, alpha
, layered_flags
);
1424 XFlush( display
); /* make sure the window exists before we start painting to it */
1425 wine_tsx11_unlock();
1426 return data
->whole_window
;
1430 /**********************************************************************
1431 * destroy_whole_window
1433 * Destroy the whole X window for a given window.
1435 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
, BOOL already_destroyed
)
1437 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1439 if (!data
->whole_window
) return;
1441 TRACE( "win %p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1442 if (thread_data
->cursor_window
== data
->whole_window
||
1443 thread_data
->cursor_window
== data
->client_window
)
1444 thread_data
->cursor_window
= None
;
1446 XDeleteContext( display
, data
->whole_window
, winContext
);
1447 XDeleteContext( display
, data
->client_window
, winContext
);
1448 if (!already_destroyed
) XDestroyWindow( display
, data
->whole_window
);
1449 data
->whole_window
= data
->client_window
= 0;
1450 data
->wm_state
= WithdrawnState
;
1451 data
->net_wm_state
= 0;
1452 data
->mapped
= FALSE
;
1455 XUnsetICFocus( data
->xic
);
1456 XDestroyIC( data
->xic
);
1459 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1461 XFree( data
->wm_hints
);
1462 data
->wm_hints
= NULL
;
1463 wine_tsx11_unlock();
1464 RemovePropA( data
->hwnd
, whole_window_prop
);
1465 RemovePropA( data
->hwnd
, client_window_prop
);
1469 /*****************************************************************
1470 * SetWindowText (X11DRV.@)
1472 void X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1476 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(gdi_display
))
1478 Display
*display
= thread_init_display();
1479 sync_window_text( display
, win
, text
);
1484 /***********************************************************************
1485 * SetWindowStyle (X11DRV.@)
1487 * Update the X state of a window to reflect a style change
1489 void X11DRV_SetWindowStyle( HWND hwnd
, INT offset
, STYLESTRUCT
*style
)
1491 struct x11drv_win_data
*data
;
1494 if (hwnd
== GetDesktopWindow()) return;
1495 changed
= style
->styleNew
^ style
->styleOld
;
1497 if (offset
== GWL_STYLE
&& (changed
& WS_VISIBLE
) && (style
->styleNew
& WS_VISIBLE
))
1499 /* we don't unmap windows, that causes trouble with the window manager */
1500 if (!(data
= X11DRV_get_win_data( hwnd
)) &&
1501 !(data
= X11DRV_create_win_data( hwnd
))) return;
1503 if (data
->whole_window
&& is_window_rect_mapped( &data
->window_rect
))
1505 Display
*display
= thread_display();
1506 set_wm_hints( display
, data
);
1507 if (!data
->mapped
) map_window( display
, data
, style
->styleNew
);
1511 if (offset
== GWL_STYLE
&& (changed
& WS_DISABLED
))
1513 data
= X11DRV_get_win_data( hwnd
);
1514 if (data
&& data
->wm_hints
)
1517 data
->wm_hints
->input
= !(style
->styleNew
& WS_DISABLED
);
1518 XSetWMHints( thread_display(), data
->whole_window
, data
->wm_hints
);
1519 wine_tsx11_unlock();
1523 if (offset
== GWL_EXSTYLE
&& (changed
& WS_EX_LAYERED
))
1525 /* changing WS_EX_LAYERED resets attributes */
1526 if ((data
= X11DRV_get_win_data( hwnd
)) && data
->whole_window
)
1527 sync_window_opacity( thread_display(), data
->whole_window
, 0, 0, 0 );
1532 /***********************************************************************
1533 * DestroyWindow (X11DRV.@)
1535 void X11DRV_DestroyWindow( HWND hwnd
)
1537 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1538 struct x11drv_win_data
*data
;
1540 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1545 destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
1546 XFreePixmap(gdi_display
, data
->pixmap
);
1547 wine_tsx11_unlock();
1549 else if (data
->gl_drawable
)
1552 XDestroyWindow(gdi_display
, data
->gl_drawable
);
1553 wine_tsx11_unlock();
1556 destroy_whole_window( thread_data
->display
, data
, FALSE
);
1557 destroy_icon_window( thread_data
->display
, data
);
1562 XFreeColormap( thread_data
->display
, data
->colormap
);
1563 wine_tsx11_unlock();
1566 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1567 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1568 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1570 XDeleteContext( thread_data
->display
, (XID
)hwnd
, win_data_context
);
1571 wine_tsx11_unlock();
1572 HeapFree( GetProcessHeap(), 0, data
);
1576 /***********************************************************************
1577 * X11DRV_DestroyNotify
1579 void X11DRV_DestroyNotify( HWND hwnd
, XEvent
*event
)
1581 Display
*display
= event
->xdestroywindow
.display
;
1582 struct x11drv_win_data
*data
;
1584 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1586 FIXME( "window %p/%lx destroyed from the outside\n", hwnd
, data
->whole_window
);
1587 destroy_whole_window( display
, data
, TRUE
);
1591 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1593 struct x11drv_win_data
*data
;
1595 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
1599 if (!winContext
) winContext
= XUniqueContext();
1600 if (!win_data_context
) win_data_context
= XUniqueContext();
1601 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1602 wine_tsx11_unlock();
1608 /* initialize the desktop window id in the desktop manager process */
1609 static struct x11drv_win_data
*create_desktop_win_data( Display
*display
, HWND hwnd
)
1611 struct x11drv_win_data
*data
;
1613 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1614 data
->whole_window
= data
->client_window
= root_window
;
1615 data
->managed
= TRUE
;
1616 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1617 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1618 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)root_window
);
1619 set_initial_wm_hints( display
, data
);
1623 /**********************************************************************
1624 * CreateDesktopWindow (X11DRV.@)
1626 BOOL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1628 unsigned int width
, height
;
1630 /* retrieve the real size of the desktop */
1631 SERVER_START_REQ( get_window_rectangles
)
1634 wine_server_call( req
);
1635 width
= reply
->window
.right
- reply
->window
.left
;
1636 height
= reply
->window
.bottom
- reply
->window
.top
;
1640 if (!width
&& !height
) /* not initialized yet */
1642 SERVER_START_REQ( set_window_pos
)
1646 req
->flags
= SWP_NOZORDER
;
1647 req
->window
.left
= virtual_screen_rect
.left
;
1648 req
->window
.top
= virtual_screen_rect
.top
;
1649 req
->window
.right
= virtual_screen_rect
.right
;
1650 req
->window
.bottom
= virtual_screen_rect
.bottom
;
1651 req
->client
= req
->window
;
1652 wine_server_call( req
);
1658 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1659 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1665 /**********************************************************************
1666 * CreateWindow (X11DRV.@)
1668 BOOL
X11DRV_CreateWindow( HWND hwnd
)
1670 if (hwnd
== GetDesktopWindow() && root_window
!= DefaultRootWindow( gdi_display
))
1672 Display
*display
= thread_init_display();
1674 /* the desktop win data can't be created lazily */
1675 if (!create_desktop_win_data( display
, hwnd
)) return FALSE
;
1681 /***********************************************************************
1682 * X11DRV_get_win_data
1684 * Return the X11 data structure associated with a window.
1686 struct x11drv_win_data
*X11DRV_get_win_data( HWND hwnd
)
1688 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1691 if (!thread_data
) return NULL
;
1692 if (!hwnd
) return NULL
;
1693 if (XFindContext( thread_data
->display
, (XID
)hwnd
, win_data_context
, &data
)) data
= NULL
;
1694 return (struct x11drv_win_data
*)data
;
1698 /***********************************************************************
1699 * X11DRV_create_win_data
1701 * Create an X11 data window structure for an existing window.
1703 struct x11drv_win_data
*X11DRV_create_win_data( HWND hwnd
)
1706 struct x11drv_win_data
*data
;
1709 if (!(parent
= GetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop */
1711 /* don't create win data for HWND_MESSAGE windows */
1712 if (parent
!= GetDesktopWindow() && !GetAncestor( parent
, GA_PARENT
)) return NULL
;
1714 display
= thread_init_display();
1715 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1717 GetWindowRect( hwnd
, &data
->window_rect
);
1718 MapWindowPoints( 0, parent
, (POINT
*)&data
->window_rect
, 2 );
1719 data
->whole_rect
= data
->window_rect
;
1720 GetClientRect( hwnd
, &data
->client_rect
);
1721 MapWindowPoints( hwnd
, parent
, (POINT
*)&data
->client_rect
, 2 );
1723 if (parent
== GetDesktopWindow())
1725 if (!create_whole_window( display
, data
))
1727 HeapFree( GetProcessHeap(), 0, data
);
1730 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1731 hwnd
, data
->whole_window
, data
->client_window
, wine_dbgstr_rect( &data
->window_rect
),
1732 wine_dbgstr_rect( &data
->whole_rect
), wine_dbgstr_rect( &data
->client_rect
));
1738 /***********************************************************************
1739 * X11DRV_get_whole_window
1741 * Return the X window associated with the full area of a window
1743 Window
X11DRV_get_whole_window( HWND hwnd
)
1745 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1749 if (hwnd
== GetDesktopWindow()) return root_window
;
1750 return (Window
)GetPropA( hwnd
, whole_window_prop
);
1752 return data
->whole_window
;
1756 /***********************************************************************
1757 * X11DRV_get_client_window
1759 * Return the X window associated with the client area of a window
1761 Window
X11DRV_get_client_window( HWND hwnd
)
1763 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1767 if (hwnd
== GetDesktopWindow()) return root_window
;
1768 return (Window
)GetPropA( hwnd
, client_window_prop
);
1770 return data
->client_window
;
1774 /***********************************************************************
1777 * Return the X input context associated with a window
1779 XIC
X11DRV_get_ic( HWND hwnd
)
1781 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1784 if (!data
) return 0;
1785 if (data
->xic
) return data
->xic
;
1786 if (!(xim
= x11drv_thread_data()->xim
)) return 0;
1787 return X11DRV_CreateIC( xim
, data
);
1791 /***********************************************************************
1792 * X11DRV_GetDC (X11DRV.@)
1794 void X11DRV_GetDC( HDC hdc
, HWND hwnd
, HWND top
, const RECT
*win_rect
,
1795 const RECT
*top_rect
, DWORD flags
)
1797 struct x11drv_escape_set_drawable escape
;
1798 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1800 escape
.code
= X11DRV_SET_DRAWABLE
;
1801 escape
.mode
= IncludeInferiors
;
1802 escape
.fbconfig_id
= 0;
1803 escape
.gl_drawable
= 0;
1805 escape
.gl_copy
= FALSE
;
1807 if (top
== hwnd
&& data
&& IsIconic( hwnd
) && data
->icon_window
)
1809 escape
.drawable
= data
->icon_window
;
1811 else if (top
== hwnd
)
1813 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1814 /* GL draws to the client area even for window DCs */
1815 escape
.gl_drawable
= data
? data
->client_window
: X11DRV_get_client_window( hwnd
);
1816 if (flags
& DCX_WINDOW
)
1817 escape
.drawable
= data
? data
->whole_window
: X11DRV_get_whole_window( hwnd
);
1819 escape
.drawable
= escape
.gl_drawable
;
1823 escape
.drawable
= X11DRV_get_client_window( top
);
1824 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1825 escape
.gl_drawable
= data
? data
->gl_drawable
: (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
1826 escape
.pixmap
= data
? data
->pixmap
: (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
1827 escape
.gl_copy
= (escape
.gl_drawable
!= 0);
1828 if (flags
& DCX_CLIPCHILDREN
) escape
.mode
= ClipByChildren
;
1831 escape
.dc_rect
.left
= win_rect
->left
- top_rect
->left
;
1832 escape
.dc_rect
.top
= win_rect
->top
- top_rect
->top
;
1833 escape
.dc_rect
.right
= win_rect
->right
- top_rect
->left
;
1834 escape
.dc_rect
.bottom
= win_rect
->bottom
- top_rect
->top
;
1835 escape
.drawable_rect
.left
= top_rect
->left
;
1836 escape
.drawable_rect
.top
= top_rect
->top
;
1837 escape
.drawable_rect
.right
= top_rect
->right
;
1838 escape
.drawable_rect
.bottom
= top_rect
->bottom
;
1840 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1844 /***********************************************************************
1845 * X11DRV_ReleaseDC (X11DRV.@)
1847 void X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
1849 struct x11drv_escape_set_drawable escape
;
1851 escape
.code
= X11DRV_SET_DRAWABLE
;
1852 escape
.drawable
= root_window
;
1853 escape
.mode
= IncludeInferiors
;
1854 escape
.drawable_rect
= virtual_screen_rect
;
1855 SetRect( &escape
.dc_rect
, 0, 0, virtual_screen_rect
.right
- virtual_screen_rect
.left
,
1856 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
);
1857 escape
.fbconfig_id
= 0;
1858 escape
.gl_drawable
= 0;
1860 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1864 /***********************************************************************
1865 * SetCapture (X11DRV.@)
1867 void X11DRV_SetCapture( HWND hwnd
, UINT flags
)
1869 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1871 if (!thread_data
) return;
1872 if (!(flags
& (GUI_INMOVESIZE
| GUI_INMENUMODE
))) return;
1876 Window grab_win
= X11DRV_get_client_window( GetAncestor( hwnd
, GA_ROOT
) );
1878 if (!grab_win
) return;
1880 XFlush( gdi_display
);
1881 XGrabPointer( thread_data
->display
, grab_win
, False
,
1882 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1883 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
);
1884 wine_tsx11_unlock();
1885 thread_data
->grab_window
= grab_win
;
1887 else /* release capture */
1890 XFlush( gdi_display
);
1891 XUngrabPointer( thread_data
->display
, CurrentTime
);
1892 wine_tsx11_unlock();
1893 thread_data
->grab_window
= None
;
1898 /*****************************************************************
1899 * SetParent (X11DRV.@)
1901 void X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
1903 Display
*display
= thread_display();
1904 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1907 if (parent
== old_parent
) return;
1909 if (parent
!= GetDesktopWindow()) /* a child window */
1911 if (old_parent
== GetDesktopWindow())
1913 /* destroy the old X windows */
1914 destroy_whole_window( display
, data
, FALSE
);
1915 destroy_icon_window( display
, data
);
1918 data
->managed
= FALSE
;
1919 RemovePropA( data
->hwnd
, managed_prop
);
1923 else /* new top level window */
1925 /* FIXME: we ignore errors since we can't really recover anyway */
1926 create_whole_window( display
, data
);
1931 /*****************************************************************
1932 * SetFocus (X11DRV.@)
1936 void X11DRV_SetFocus( HWND hwnd
)
1938 Display
*display
= thread_display();
1939 struct x11drv_win_data
*data
;
1940 XWindowChanges changes
;
1942 if (!(hwnd
= GetAncestor( hwnd
, GA_ROOT
))) return;
1943 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1944 if (data
->managed
|| !data
->whole_window
) return;
1946 /* Set X focus and install colormap */
1948 changes
.stack_mode
= Above
;
1949 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
1950 if (root_window
== DefaultRootWindow(display
))
1952 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1953 /* FIXME: this is not entirely correct */
1954 XSetInputFocus( display
, data
->whole_window
, RevertToParent
,
1956 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1958 wine_tsx11_unlock();
1962 /***********************************************************************
1963 * WindowPosChanging (X11DRV.@)
1965 void X11DRV_WindowPosChanging( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
1966 const RECT
*window_rect
, const RECT
*client_rect
, RECT
*visible_rect
)
1968 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1969 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1973 /* create the win data if the window is being made visible */
1974 if (!(style
& WS_VISIBLE
) && !(swp_flags
& SWP_SHOWWINDOW
)) return;
1975 if (!(data
= X11DRV_create_win_data( hwnd
))) return;
1978 /* check if we need to switch the window to managed */
1979 if (!data
->managed
&& data
->whole_window
&& is_window_managed( hwnd
, swp_flags
, window_rect
))
1981 TRACE( "making win %p/%lx managed\n", hwnd
, data
->whole_window
);
1982 if (data
->mapped
) unmap_window( thread_display(), data
);
1983 data
->managed
= TRUE
;
1984 SetPropA( hwnd
, managed_prop
, (HANDLE
)1 );
1987 *visible_rect
= *window_rect
;
1988 X11DRV_window_to_X_rect( data
, visible_rect
);
1992 /***********************************************************************
1993 * WindowPosChanged (X11DRV.@)
1995 void X11DRV_WindowPosChanged( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
1996 const RECT
*rectWindow
, const RECT
*rectClient
,
1997 const RECT
*visible_rect
, const RECT
*valid_rects
)
1999 struct x11drv_thread_data
*thread_data
;
2001 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2002 DWORD new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2003 RECT old_whole_rect
, old_client_rect
;
2008 thread_data
= x11drv_thread_data();
2009 display
= thread_data
->display
;
2011 old_whole_rect
= data
->whole_rect
;
2012 old_client_rect
= data
->client_rect
;
2013 data
->window_rect
= *rectWindow
;
2014 data
->whole_rect
= *visible_rect
;
2015 data
->client_rect
= *rectClient
;
2017 TRACE( "win %p window %s client %s style %08x flags %08x\n",
2018 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
, swp_flags
);
2020 if (!IsRectEmpty( &valid_rects
[0] ))
2022 int x_offset
= old_whole_rect
.left
- data
->whole_rect
.left
;
2023 int y_offset
= old_whole_rect
.top
- data
->whole_rect
.top
;
2025 /* if all that happened is that the whole window moved, copy everything */
2026 if (!(swp_flags
& SWP_FRAMECHANGED
) &&
2027 old_whole_rect
.right
- data
->whole_rect
.right
== x_offset
&&
2028 old_whole_rect
.bottom
- data
->whole_rect
.bottom
== y_offset
&&
2029 old_client_rect
.left
- data
->client_rect
.left
== x_offset
&&
2030 old_client_rect
.right
- data
->client_rect
.right
== x_offset
&&
2031 old_client_rect
.top
- data
->client_rect
.top
== y_offset
&&
2032 old_client_rect
.bottom
- data
->client_rect
.bottom
== y_offset
&&
2033 !memcmp( &valid_rects
[0], &data
->client_rect
, sizeof(RECT
) ))
2035 /* if we have an X window the bits will be moved by the X server */
2036 if (!data
->whole_window
)
2037 move_window_bits( data
, &old_whole_rect
, &data
->whole_rect
, &old_client_rect
);
2040 move_window_bits( data
, &valid_rects
[1], &valid_rects
[0], &old_client_rect
);
2044 XFlush( gdi_display
); /* make sure painting is done before we move the window */
2045 wine_tsx11_unlock();
2047 sync_client_position( display
, data
, swp_flags
, &old_client_rect
, &old_whole_rect
);
2049 if (!data
->whole_window
) return;
2051 /* check if we are currently processing an event relevant to this window */
2053 if (thread_data
->current_event
&& thread_data
->current_event
->xany
.window
== data
->whole_window
)
2054 event_type
= thread_data
->current_event
->type
;
2056 if (event_type
!= ConfigureNotify
&& event_type
!= PropertyNotify
)
2057 event_type
= 0; /* ignore other events */
2061 if (((swp_flags
& SWP_HIDEWINDOW
) && !(new_style
& WS_VISIBLE
)) ||
2062 (!event_type
&& !is_window_rect_mapped( rectWindow
)))
2063 unmap_window( display
, data
);
2066 /* don't change position if we are about to minimize or maximize a managed window */
2068 !(data
->managed
&& (swp_flags
& SWP_STATECHANGED
) && (new_style
& (WS_MINIMIZE
|WS_MAXIMIZE
))))
2069 sync_window_position( display
, data
, swp_flags
, &old_client_rect
, &old_whole_rect
);
2071 if ((new_style
& WS_VISIBLE
) &&
2072 ((new_style
& WS_MINIMIZE
) || is_window_rect_mapped( rectWindow
)))
2074 if (!data
->mapped
|| (swp_flags
& (SWP_FRAMECHANGED
|SWP_STATECHANGED
)))
2075 set_wm_hints( display
, data
);
2079 map_window( display
, data
, new_style
);
2081 else if ((swp_flags
& SWP_STATECHANGED
) && (!data
->iconic
!= !(new_style
& WS_MINIMIZE
)))
2083 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
2084 TRACE( "changing win %p iconic state to %u\n", data
->hwnd
, data
->iconic
);
2087 XIconifyWindow( display
, data
->whole_window
, DefaultScreen(display
) );
2088 else if (is_window_rect_mapped( rectWindow
))
2089 XMapWindow( display
, data
->whole_window
);
2090 wine_tsx11_unlock();
2091 update_net_wm_states( display
, data
);
2093 else if (!event_type
)
2095 update_net_wm_states( display
, data
);
2100 XFlush( display
); /* make sure changes are done before we start painting again */
2101 wine_tsx11_unlock();
2105 /***********************************************************************
2106 * ShowWindow (X11DRV.@)
2108 UINT
X11DRV_ShowWindow( HWND hwnd
, INT cmd
, RECT
*rect
, UINT swp
)
2111 unsigned int width
, height
, border
, depth
;
2113 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2114 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2115 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2117 if (!data
|| !data
->whole_window
|| !data
->managed
|| !data
->mapped
|| data
->iconic
) return swp
;
2118 if (style
& WS_MINIMIZE
) return swp
;
2119 if (IsRectEmpty( rect
)) return swp
;
2121 /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */
2123 if (!thread_data
->current_event
|| thread_data
->current_event
->xany
.window
!= data
->whole_window
)
2126 if (thread_data
->current_event
->type
!= ConfigureNotify
&&
2127 thread_data
->current_event
->type
!= PropertyNotify
)
2130 TRACE( "win %p/%lx cmd %d at %s flags %08x\n",
2131 hwnd
, data
->whole_window
, cmd
, wine_dbgstr_rect(rect
), swp
);
2134 XGetGeometry( thread_data
->display
, data
->whole_window
,
2135 &root
, &x
, &y
, &width
, &height
, &border
, &depth
);
2136 XTranslateCoordinates( thread_data
->display
, data
->whole_window
, root
, 0, 0, &x
, &y
, &top
);
2137 wine_tsx11_unlock();
2140 rect
->right
= x
+ width
;
2141 rect
->bottom
= y
+ height
;
2142 OffsetRect( rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
2143 X11DRV_X_to_window_rect( data
, rect
);
2144 return swp
& ~(SWP_NOMOVE
| SWP_NOCLIENTMOVE
| SWP_NOSIZE
| SWP_NOCLIENTSIZE
);
2148 /**********************************************************************
2149 * SetWindowIcon (X11DRV.@)
2151 * hIcon or hIconSm has changed (or is being initialised for the
2152 * first time). Complete the X11 driver-specific initialisation
2153 * and set the window hints.
2155 * This is not entirely correct, may need to create
2156 * an icon window and set the pixmap as a background
2158 void X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
2160 Display
*display
= thread_display();
2161 struct x11drv_win_data
*data
;
2163 if (type
!= ICON_BIG
) return; /* nothing to do here */
2165 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
2166 if (!data
->whole_window
) return;
2167 if (!data
->managed
) return;
2171 set_icon_hints( display
, data
, icon
);
2173 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
2174 wine_tsx11_unlock();
2179 /***********************************************************************
2180 * SetWindowRgn (X11DRV.@)
2182 * Assign specified region to window (for non-rectangular windows)
2184 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
2186 struct x11drv_win_data
*data
;
2188 if ((data
= X11DRV_get_win_data( hwnd
)))
2190 sync_window_region( thread_display(), data
, hrgn
);
2192 else if (X11DRV_get_whole_window( hwnd
))
2194 SendMessageW( hwnd
, WM_X11DRV_SET_WIN_REGION
, 0, 0 );
2200 /***********************************************************************
2201 * SetLayeredWindowAttributes (X11DRV.@)
2203 * Set transparency attributes for a layered window.
2205 void X11DRV_SetLayeredWindowAttributes( HWND hwnd
, COLORREF key
, BYTE alpha
, DWORD flags
)
2207 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2211 if (data
->whole_window
)
2212 sync_window_opacity( thread_display(), data
->whole_window
, key
, alpha
, flags
);
2216 Window win
= X11DRV_get_whole_window( hwnd
);
2217 if (win
) sync_window_opacity( gdi_display
, win
, key
, alpha
, flags
);
2222 /**********************************************************************
2223 * X11DRV_WindowMessage (X11DRV.@)
2225 LRESULT
X11DRV_WindowMessage( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2227 struct x11drv_win_data
*data
;
2231 case WM_X11DRV_ACQUIRE_SELECTION
:
2232 return X11DRV_AcquireClipboard( hwnd
);
2233 case WM_X11DRV_DELETE_WINDOW
:
2234 return SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0 );
2235 case WM_X11DRV_SET_WIN_FORMAT
:
2236 return set_win_format( hwnd
, (XID
)wp
);
2237 case WM_X11DRV_SET_WIN_REGION
:
2238 if ((data
= X11DRV_get_win_data( hwnd
))) sync_window_region( thread_display(), data
, (HRGN
)1 );
2240 case WM_X11DRV_RESIZE_DESKTOP
:
2241 X11DRV_resize_desktop( LOWORD(lp
), HIWORD(lp
) );
2244 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg
, hwnd
, wp
, lp
);
2250 /***********************************************************************
2251 * is_netwm_supported
2253 static BOOL
is_netwm_supported( Display
*display
, Atom atom
)
2255 static Atom
*net_supported
;
2256 static int net_supported_count
= -1;
2260 if (net_supported_count
== -1)
2264 unsigned long count
, remaining
;
2266 if (!XGetWindowProperty( display
, DefaultRootWindow(display
), x11drv_atom(_NET_SUPPORTED
), 0,
2267 ~0UL, False
, XA_ATOM
, &type
, &format
, &count
,
2268 &remaining
, (unsigned char **)&net_supported
))
2269 net_supported_count
= get_property_size( format
, count
) / sizeof(Atom
);
2271 net_supported_count
= 0;
2273 wine_tsx11_unlock();
2275 for (i
= 0; i
< net_supported_count
; i
++)
2276 if (net_supported
[i
] == atom
) return TRUE
;
2281 /***********************************************************************
2282 * SysCommand (X11DRV.@)
2284 * Perform WM_SYSCOMMAND handling.
2286 LRESULT
X11DRV_SysCommand( HWND hwnd
, WPARAM wparam
, LPARAM lparam
)
2288 WPARAM hittest
= wparam
& 0x0f;
2292 Display
*display
= thread_display();
2293 struct x11drv_win_data
*data
;
2295 if (!(data
= X11DRV_get_win_data( hwnd
))) return -1;
2296 if (!data
->whole_window
|| !data
->managed
|| !data
->mapped
) return -1;
2298 switch (wparam
& 0xfff0)
2301 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
2302 else dir
= _NET_WM_MOVERESIZE_MOVE
;
2305 /* windows without WS_THICKFRAME are not resizable through the window manager */
2306 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_THICKFRAME
)) return -1;
2310 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
2311 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
2312 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
2313 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
2314 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
2315 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
2316 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
2317 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
2318 default: dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
; break;
2323 /* prevent a simple ALT press+release from activating the system menu,
2324 * as that can get confusing on managed windows */
2325 if ((WCHAR
)lparam
) return -1; /* got an explicit char */
2326 if (GetMenu( hwnd
)) return -1; /* window has a real menu */
2327 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_SYSMENU
)) return -1; /* no system menu */
2328 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam
, lparam
);
2335 if (IsZoomed(hwnd
)) return -1;
2337 if (!is_netwm_supported( display
, x11drv_atom(_NET_WM_MOVERESIZE
) ))
2339 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
2343 dwPoint
= GetMessagePos();
2344 x
= (short)LOWORD(dwPoint
);
2345 y
= (short)HIWORD(dwPoint
);
2347 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd
, x
, y
, dir
);
2349 xev
.xclient
.type
= ClientMessage
;
2350 xev
.xclient
.window
= X11DRV_get_whole_window(hwnd
);
2351 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_MOVERESIZE
);
2352 xev
.xclient
.serial
= 0;
2353 xev
.xclient
.display
= display
;
2354 xev
.xclient
.send_event
= True
;
2355 xev
.xclient
.format
= 32;
2356 xev
.xclient
.data
.l
[0] = x
- virtual_screen_rect
.left
; /* x coord */
2357 xev
.xclient
.data
.l
[1] = y
- virtual_screen_rect
.top
; /* y coord */
2358 xev
.xclient
.data
.l
[2] = dir
; /* direction */
2359 xev
.xclient
.data
.l
[3] = 1; /* button */
2360 xev
.xclient
.data
.l
[4] = 0; /* unused */
2362 /* need to ungrab the pointer that may have been automatically grabbed
2363 * with a ButtonPress event */
2365 XUngrabPointer( display
, CurrentTime
);
2366 XSendEvent(display
, root_window
, False
, SubstructureNotifyMask
, &xev
);
2367 wine_tsx11_unlock();