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";
86 /***********************************************************************
87 * http://standards.freedesktop.org/startup-notification-spec
89 static void remove_startup_notification(Display
*display
, Window window
)
91 static LONG startup_notification_removed
= 0;
100 if (InterlockedCompareExchange(&startup_notification_removed
, 1, 0) != 0)
103 if (GetEnvironmentVariableA("DESKTOP_STARTUP_ID", id
, sizeof(id
)) == 0)
105 SetEnvironmentVariableA("DESKTOP_STARTUP_ID", NULL
);
107 pos
= snprintf(message
, sizeof(message
), "remove: ID=");
108 message
[pos
++] = '"';
109 for (i
= 0; id
[i
] && pos
< sizeof(message
) - 2; i
++)
111 if (id
[i
] == '"' || id
[i
] == '\\')
112 message
[pos
++] = '\\';
113 message
[pos
++] = id
[i
];
115 message
[pos
++] = '"';
116 message
[pos
++] = '\0';
118 xevent
.xclient
.type
= ClientMessage
;
119 xevent
.xclient
.message_type
= x11drv_atom(_NET_STARTUP_INFO_BEGIN
);
120 xevent
.xclient
.display
= display
;
121 xevent
.xclient
.window
= window
;
122 xevent
.xclient
.format
= 8;
125 srclen
= strlen(src
) + 1;
133 memset(&xevent
.xclient
.data
.b
[0], 0, 20);
134 memcpy(&xevent
.xclient
.data
.b
[0], src
, msglen
);
138 XSendEvent( display
, DefaultRootWindow( display
), False
, PropertyChangeMask
, &xevent
);
139 xevent
.xclient
.message_type
= x11drv_atom(_NET_STARTUP_INFO
);
145 struct has_popup_result
151 static BOOL CALLBACK
has_popup( HWND hwnd
, LPARAM lparam
)
153 struct has_popup_result
*result
= (struct has_popup_result
*)lparam
;
155 if (hwnd
== result
->hwnd
) return FALSE
; /* popups are always above owner */
156 result
->found
= (GetWindow( hwnd
, GW_OWNER
) == result
->hwnd
);
157 return !result
->found
;
160 static BOOL
has_owned_popups( HWND hwnd
)
162 struct has_popup_result result
;
165 result
.found
= FALSE
;
166 EnumWindows( has_popup
, (LPARAM
)&result
);
170 /***********************************************************************
173 * Check if a given window should be managed
175 static BOOL
is_window_managed( HWND hwnd
, UINT swp_flags
, const RECT
*window_rect
)
177 DWORD style
, ex_style
;
179 if (!managed_mode
) return FALSE
;
181 /* child windows are not managed */
182 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
183 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) return FALSE
;
184 /* activated windows are managed */
185 if (!(swp_flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
))) return TRUE
;
186 if (hwnd
== GetActiveWindow()) return TRUE
;
187 /* windows with caption are managed */
188 if ((style
& WS_CAPTION
) == WS_CAPTION
) return TRUE
;
189 /* windows with thick frame are managed */
190 if (style
& WS_THICKFRAME
) return TRUE
;
191 if (style
& WS_POPUP
)
196 /* popup with sysmenu == caption are managed */
197 if (style
& WS_SYSMENU
) return TRUE
;
198 /* full-screen popup windows are managed */
199 hmon
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
);
200 mi
.cbSize
= sizeof( mi
);
201 GetMonitorInfoW( hmon
, &mi
);
202 if (window_rect
->left
<= mi
.rcWork
.left
&& window_rect
->right
>= mi
.rcWork
.right
&&
203 window_rect
->top
<= mi
.rcWork
.top
&& window_rect
->bottom
>= mi
.rcWork
.bottom
)
206 /* application windows are managed */
207 ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
208 if (ex_style
& WS_EX_APPWINDOW
) return TRUE
;
209 /* windows that own popups are managed */
210 if (has_owned_popups( hwnd
)) return TRUE
;
211 /* default: not managed */
216 /***********************************************************************
217 * is_window_rect_mapped
219 * Check if the X whole window should be mapped based on its rectangle
221 static BOOL
is_window_rect_mapped( const RECT
*rect
)
223 /* don't map if rect is off-screen */
224 if (rect
->left
>= virtual_screen_rect
.right
||
225 rect
->top
>= virtual_screen_rect
.bottom
||
226 rect
->right
<= virtual_screen_rect
.left
||
227 rect
->bottom
<= virtual_screen_rect
.top
)
234 /***********************************************************************
235 * is_window_resizable
237 * Check if window should be made resizable by the window manager
239 static inline BOOL
is_window_resizable( struct x11drv_win_data
*data
, DWORD style
)
241 if (style
& WS_THICKFRAME
) return TRUE
;
242 /* Metacity needs the window to be resizable to make it fullscreen */
243 return (data
->whole_rect
.left
<= 0 && data
->whole_rect
.right
>= screen_width
&&
244 data
->whole_rect
.top
<= 0 && data
->whole_rect
.bottom
>= screen_height
);
248 /***********************************************************************
249 * get_mwm_decorations
251 static unsigned long get_mwm_decorations( struct x11drv_win_data
*data
,
252 DWORD style
, DWORD ex_style
)
254 unsigned long ret
= 0;
256 if (!decorated_mode
) return 0;
258 if (IsRectEmpty( &data
->window_rect
)) return 0;
259 if (data
->shaped
) return 0;
261 if (ex_style
& WS_EX_TOOLWINDOW
) return 0;
263 if ((style
& WS_CAPTION
) == WS_CAPTION
)
265 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
266 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
267 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
268 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
270 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
271 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
272 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
277 /***********************************************************************
278 * get_x11_rect_offset
280 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
282 static void get_x11_rect_offset( struct x11drv_win_data
*data
, RECT
*rect
)
284 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
287 rect
->top
= rect
->bottom
= rect
->left
= rect
->right
= 0;
289 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
290 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
291 decor
= get_mwm_decorations( data
, style
, ex_style
);
293 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
294 if (decor
& MWM_DECOR_BORDER
)
296 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
297 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
300 AdjustWindowRectEx( rect
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
304 /***********************************************************************
305 * get_window_attributes
307 * Fill the window attributes structure for an X window.
309 static int get_window_attributes( Display
*display
, struct x11drv_win_data
*data
,
310 XSetWindowAttributes
*attr
)
312 attr
->override_redirect
= !data
->managed
;
313 attr
->colormap
= X11DRV_PALETTE_PaletteXColormap
;
314 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
315 attr
->bit_gravity
= NorthWestGravity
;
316 attr
->win_gravity
= StaticGravity
;
317 attr
->backing_store
= NotUseful
;
318 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
319 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
320 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
|
321 KeymapStateMask
| StructureNotifyMask
);
322 if (data
->managed
) attr
->event_mask
|= PropertyChangeMask
;
324 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
|
325 CWEventMask
| CWBitGravity
| CWBackingStore
);
329 /***********************************************************************
330 * create_client_window
332 static Window
create_client_window( Display
*display
, struct x11drv_win_data
*data
, XVisualInfo
*vis
)
335 XSetWindowAttributes attr
;
337 Visual
*client_visual
= vis
? vis
->visual
: visual
;
339 attr
.bit_gravity
= NorthWestGravity
;
340 attr
.win_gravity
= NorthWestGravity
;
341 attr
.backing_store
= NotUseful
;
342 attr
.event_mask
= (ExposureMask
| PointerMotionMask
|
343 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
344 mask
= CWEventMask
| CWBitGravity
| CWWinGravity
| CWBackingStore
;
346 if ((cx
= data
->client_rect
.right
- data
->client_rect
.left
) <= 0) cx
= 1;
347 else if (cx
> 65535) cx
= 65535;
348 if ((cy
= data
->client_rect
.bottom
- data
->client_rect
.top
) <= 0) cy
= 1;
349 else if (cy
> 65535) cy
= 65535;
355 attr
.colormap
= XCreateColormap( display
, root_window
, vis
->visual
,
356 (vis
->class == PseudoColor
|| vis
->class == GrayScale
||
357 vis
->class == DirectColor
) ? AllocAll
: AllocNone
);
361 client
= XCreateWindow( display
, data
->whole_window
,
362 data
->client_rect
.left
- data
->whole_rect
.left
,
363 data
->client_rect
.top
- data
->whole_rect
.top
,
364 cx
, cy
, 0, screen_depth
, InputOutput
,
365 client_visual
, mask
, &attr
);
372 if (data
->client_window
)
374 XDeleteContext( display
, data
->client_window
, winContext
);
375 XDestroyWindow( display
, data
->client_window
);
377 data
->client_window
= client
;
378 data
->visualid
= XVisualIDFromVisual( client_visual
);
380 if (data
->colormap
) XFreeColormap( display
, data
->colormap
);
381 data
->colormap
= vis
? attr
.colormap
: 0;
383 XMapWindow( display
, data
->client_window
);
384 XSaveContext( display
, data
->client_window
, winContext
, (char *)data
->hwnd
);
387 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)data
->client_window
);
388 return data
->client_window
;
392 /***********************************************************************
395 * Change the X window attributes when the window style has changed.
397 static void sync_window_style( Display
*display
, struct x11drv_win_data
*data
)
399 if (data
->whole_window
!= root_window
)
401 XSetWindowAttributes attr
;
402 int mask
= get_window_attributes( display
, data
, &attr
);
405 XChangeWindowAttributes( display
, data
->whole_window
, mask
, &attr
);
411 /***********************************************************************
414 static void sync_window_cursor( struct x11drv_win_data
*data
)
418 SERVER_START_REQ( set_cursor
)
421 wine_server_call( req
);
422 cursor
= reply
->prev_count
>= 0 ? wine_server_ptr_handle( reply
->prev_handle
) : 0;
426 set_window_cursor( data
->hwnd
, cursor
);
430 /***********************************************************************
433 * Update the X11 window region.
435 static void sync_window_region( Display
*display
, struct x11drv_win_data
*data
, HRGN win_region
)
437 #ifdef HAVE_LIBXSHAPE
438 HRGN hrgn
= win_region
;
440 if (!data
->whole_window
) return;
441 data
->shaped
= FALSE
;
443 if (IsRectEmpty( &data
->window_rect
)) /* set an empty shape */
445 static XRectangle empty_rect
;
447 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
, 0, 0,
448 &empty_rect
, 1, ShapeSet
, YXBanded
);
453 if (hrgn
== (HRGN
)1) /* hack: win_region == 1 means retrieve region from server */
455 if (!(hrgn
= CreateRectRgn( 0, 0, 0, 0 ))) return;
456 if (GetWindowRgn( data
->hwnd
, hrgn
) == ERROR
)
458 DeleteObject( hrgn
);
466 XShapeCombineMask( display
, data
->whole_window
, ShapeBounding
, 0, 0, None
, ShapeSet
);
471 RGNDATA
*pRegionData
= X11DRV_GetRegionData( hrgn
, 0 );
475 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
476 data
->window_rect
.left
- data
->whole_rect
.left
,
477 data
->window_rect
.top
- data
->whole_rect
.top
,
478 (XRectangle
*)pRegionData
->Buffer
,
479 pRegionData
->rdh
.nCount
, ShapeSet
, YXBanded
);
481 HeapFree(GetProcessHeap(), 0, pRegionData
);
485 if (hrgn
&& hrgn
!= win_region
) DeleteObject( hrgn
);
486 #endif /* HAVE_LIBXSHAPE */
490 /***********************************************************************
491 * sync_window_opacity
493 static void sync_window_opacity( Display
*display
, Window win
,
494 COLORREF key
, BYTE alpha
, DWORD flags
)
496 unsigned long opacity
= 0xffffffff;
498 if (flags
& LWA_ALPHA
) opacity
= (0xffffffff / 0xff) * alpha
;
500 if (flags
& LWA_COLORKEY
) FIXME("LWA_COLORKEY not supported\n");
503 if (opacity
== 0xffffffff)
504 XDeleteProperty( display
, win
, x11drv_atom(_NET_WM_WINDOW_OPACITY
) );
506 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_WINDOW_OPACITY
),
507 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&opacity
, 1 );
512 /***********************************************************************
515 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
518 char *buffer
, *utf8_buffer
;
521 /* allocate new buffer for window text */
522 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
523 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
524 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
526 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
527 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
529 HeapFree( GetProcessHeap(), 0, buffer
);
532 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
535 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
537 XSetWMName( display
, win
, &prop
);
538 XSetWMIconName( display
, win
, &prop
);
542 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
543 according to the standard
544 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
546 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
547 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
550 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
551 HeapFree( GetProcessHeap(), 0, buffer
);
555 /***********************************************************************
558 static BOOL
set_win_format( HWND hwnd
, XID fbconfig_id
)
560 struct x11drv_win_data
*data
;
564 if (!(data
= X11DRV_get_win_data(hwnd
)) &&
565 !(data
= X11DRV_create_win_data(hwnd
))) return FALSE
;
567 if (!(vis
= visual_from_fbconfig_id(fbconfig_id
))) return FALSE
;
569 if (data
->whole_window
)
571 Display
*display
= thread_display();
572 Window client
= data
->client_window
;
574 if (vis
->visualid
!= data
->visualid
)
576 client
= create_client_window( display
, data
, vis
);
577 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client
, data
->hwnd
, fbconfig_id
);
583 if (client
) goto done
;
587 w
= data
->client_rect
.right
- data
->client_rect
.left
;
588 h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
593 #ifdef SONAME_LIBXCOMPOSITE
596 XSetWindowAttributes attrib
;
597 static Window dummy_parent
;
600 attrib
.override_redirect
= True
;
603 dummy_parent
= XCreateWindow( gdi_display
, root_window
, -1, -1, 1, 1, 0, screen_depth
,
604 InputOutput
, visual
, CWOverrideRedirect
, &attrib
);
605 XMapWindow( gdi_display
, dummy_parent
);
607 data
->colormap
= XCreateColormap(gdi_display
, dummy_parent
, vis
->visual
,
608 (vis
->class == PseudoColor
||
609 vis
->class == GrayScale
||
610 vis
->class == DirectColor
) ?
611 AllocAll
: AllocNone
);
612 attrib
.colormap
= data
->colormap
;
613 XInstallColormap(gdi_display
, attrib
.colormap
);
615 if(data
->gl_drawable
) XDestroyWindow(gdi_display
, data
->gl_drawable
);
616 data
->gl_drawable
= XCreateWindow(gdi_display
, dummy_parent
, -w
, 0, w
, h
, 0,
617 vis
->depth
, InputOutput
, vis
->visual
,
618 CWColormap
| CWOverrideRedirect
,
620 if(data
->gl_drawable
)
622 pXCompositeRedirectWindow(gdi_display
, data
->gl_drawable
,
623 CompositeRedirectManual
);
624 XMapWindow(gdi_display
, data
->gl_drawable
);
627 XFlush( gdi_display
);
633 WARN("XComposite is not available, using GLXPixmap hack\n");
637 if(data
->pixmap
) XFreePixmap(gdi_display
, data
->pixmap
);
638 data
->pixmap
= XCreatePixmap(gdi_display
, root_window
, w
, h
, vis
->depth
);
646 if(data
->gl_drawable
) destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
647 data
->gl_drawable
= create_glxpixmap(gdi_display
, vis
, data
->pixmap
);
648 if(!data
->gl_drawable
)
650 XFreePixmap(gdi_display
, data
->pixmap
);
654 XFlush( gdi_display
);
656 if (data
->pixmap
) SetPropA(hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
659 if (!data
->gl_drawable
) return FALSE
;
661 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
662 data
->gl_drawable
, fbconfig_id
);
663 SetPropA(hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
666 data
->fbconfig_id
= fbconfig_id
;
667 SetPropA(hwnd
, fbconfig_id_prop
, (HANDLE
)data
->fbconfig_id
);
668 /* force DCE invalidation */
669 SetWindowPos( hwnd
, 0, 0, 0, 0, 0,
670 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOMOVE
|
671 SWP_NOREDRAW
| SWP_DEFERERASE
| SWP_NOSENDCHANGING
| SWP_STATECHANGED
);
675 /***********************************************************************
678 static void sync_gl_drawable(struct x11drv_win_data
*data
)
680 int w
= data
->client_rect
.right
- data
->client_rect
.left
;
681 int h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
689 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
690 #ifdef SONAME_LIBXCOMPOSITE
694 XMoveResizeWindow(gdi_display
, data
->gl_drawable
, -w
, 0, w
, h
);
700 if (!(vis
= visual_from_fbconfig_id(data
->fbconfig_id
))) return;
703 pix
= XCreatePixmap(gdi_display
, root_window
, w
, h
, vis
->depth
);
706 ERR("Failed to create pixmap for offscreen rendering\n");
712 glxp
= create_glxpixmap(gdi_display
, vis
, pix
);
715 ERR("Failed to create drawable for offscreen rendering\n");
716 XFreePixmap(gdi_display
, pix
);
724 mark_drawable_dirty(data
->gl_drawable
, glxp
);
726 XFreePixmap(gdi_display
, data
->pixmap
);
727 destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
728 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp
, data
->gl_drawable
);
731 data
->gl_drawable
= glxp
;
733 XFlush( gdi_display
);
736 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
737 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
741 /***********************************************************************
744 * fill the window changes structure
746 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
750 if (old
->right
- old
->left
!= new->right
- new->left
)
752 if ((changes
->width
= new->right
- new->left
) <= 0) changes
->width
= 1;
753 else if (changes
->width
> 65535) changes
->width
= 65535;
756 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
758 if ((changes
->height
= new->bottom
- new->top
) <= 0) changes
->height
= 1;
759 else if (changes
->height
> 65535) changes
->height
= 65535;
762 if (old
->left
!= new->left
)
764 changes
->x
= new->left
;
767 if (old
->top
!= new->top
)
769 changes
->y
= new->top
;
776 /***********************************************************************
779 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
781 XSetWindowAttributes attr
;
783 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
784 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
785 attr
.bit_gravity
= NorthWestGravity
;
786 attr
.backing_store
= NotUseful
/*WhenMapped*/;
787 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
790 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
791 GetSystemMetrics( SM_CXICON
),
792 GetSystemMetrics( SM_CYICON
),
795 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
796 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
797 XFlush( display
); /* make sure the window exists before we start painting to it */
800 TRACE( "created %lx\n", data
->icon_window
);
801 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
802 return data
->icon_window
;
807 /***********************************************************************
808 * destroy_icon_window
810 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
812 if (!data
->icon_window
) return;
814 XDeleteContext( display
, data
->icon_window
, winContext
);
815 XDestroyWindow( display
, data
->icon_window
);
816 data
->icon_window
= 0;
818 RemovePropA( data
->hwnd
, icon_window_prop
);
822 /***********************************************************************
825 * Return the bitmap bits in ARGB format. Helper for setting icon hints.
827 static unsigned long *get_bitmap_argb( HDC hdc
, HBITMAP color
, HBITMAP mask
, unsigned int *size
)
831 unsigned int *ptr
, *bits
= NULL
;
832 unsigned char *mask_bits
= NULL
;
833 int i
, j
, has_alpha
= 0;
835 if (!GetObjectW( color
, sizeof(bm
), &bm
)) return NULL
;
836 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) return NULL
;
837 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
838 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
839 info
->bmiHeader
.biHeight
= -bm
.bmHeight
;
840 info
->bmiHeader
.biPlanes
= 1;
841 info
->bmiHeader
.biBitCount
= 32;
842 info
->bmiHeader
.biCompression
= BI_RGB
;
843 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* bm
.bmHeight
* 4;
844 info
->bmiHeader
.biXPelsPerMeter
= 0;
845 info
->bmiHeader
.biYPelsPerMeter
= 0;
846 info
->bmiHeader
.biClrUsed
= 0;
847 info
->bmiHeader
.biClrImportant
= 0;
848 *size
= bm
.bmWidth
* bm
.bmHeight
+ 2;
849 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, *size
* sizeof(long) ))) goto failed
;
850 if (!GetDIBits( hdc
, color
, 0, bm
.bmHeight
, bits
+ 2, info
, DIB_RGB_COLORS
)) goto failed
;
852 bits
[0] = bm
.bmWidth
;
853 bits
[1] = bm
.bmHeight
;
855 for (i
= 0; i
< bm
.bmWidth
* bm
.bmHeight
; i
++)
856 if ((has_alpha
= (bits
[i
+ 2] & 0xff000000) != 0)) break;
860 unsigned int width_bytes
= (bm
.bmWidth
+ 31) / 32 * 4;
861 /* generate alpha channel from the mask */
862 info
->bmiHeader
.biBitCount
= 1;
863 info
->bmiHeader
.biSizeImage
= width_bytes
* bm
.bmHeight
;
864 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto failed
;
865 if (!GetDIBits( hdc
, mask
, 0, bm
.bmHeight
, mask_bits
, info
, DIB_RGB_COLORS
)) goto failed
;
867 for (i
= 0; i
< bm
.bmHeight
; i
++)
868 for (j
= 0; j
< bm
.bmWidth
; j
++, ptr
++)
869 if (!((mask_bits
[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80)) *ptr
|= 0xff000000;
870 HeapFree( GetProcessHeap(), 0, mask_bits
);
872 HeapFree( GetProcessHeap(), 0, info
);
874 /* convert to array of longs */
875 if (bits
&& sizeof(long) > sizeof(int))
876 for (i
= *size
- 1; i
>= 0; i
--) ((unsigned long *)bits
)[i
] = bits
[i
];
878 return (unsigned long *)bits
;
881 HeapFree( GetProcessHeap(), 0, info
);
882 HeapFree( GetProcessHeap(), 0, bits
);
883 HeapFree( GetProcessHeap(), 0, mask_bits
);
888 /***********************************************************************
891 * Set the icon wm hints
893 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
,
894 HICON icon_big
, HICON icon_small
)
896 XWMHints
*hints
= data
->wm_hints
;
900 icon_big
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_BIG
, 0 );
901 if (!icon_big
) icon_big
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
);
905 icon_small
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
906 if (!icon_small
) icon_small
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICONSM
);
909 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
910 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
911 data
->hWMIconBitmap
= 0;
912 data
->hWMIconMask
= 0;
916 if (!data
->icon_window
) create_icon_window( display
, data
);
917 hints
->icon_window
= data
->icon_window
;
918 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
925 ICONINFO ii
, ii_small
;
930 if (!GetIconInfo(icon_big
, &ii
)) return;
932 GetObjectW(ii
.hbmMask
, sizeof(bm
), &bm
);
935 rcMask
.right
= bm
.bmWidth
;
936 rcMask
.bottom
= bm
.bmHeight
;
938 hDC
= CreateCompatibleDC(0);
939 bits
= get_bitmap_argb( hDC
, ii
.hbmColor
, ii
.hbmMask
, &size
);
940 if (bits
&& GetIconInfo( icon_small
, &ii_small
))
942 unsigned int size_small
;
943 unsigned long *bits_small
, *new;
945 if ((bits_small
= get_bitmap_argb( hDC
, ii_small
.hbmColor
, ii_small
.hbmMask
, &size_small
)) &&
946 (bits_small
[0] != bits
[0] || bits_small
[1] != bits
[1])) /* size must be different */
948 if ((new = HeapReAlloc( GetProcessHeap(), 0, bits
,
949 (size
+ size_small
) * sizeof(unsigned long) )))
952 memcpy( bits
+ size
, bits_small
, size_small
* sizeof(unsigned long) );
956 HeapFree( GetProcessHeap(), 0, bits_small
);
957 DeleteObject( ii_small
.hbmColor
);
958 DeleteObject( ii_small
.hbmMask
);
962 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_ICON
),
963 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)bits
, size
);
965 XDeleteProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_ICON
) );
967 HeapFree( GetProcessHeap(), 0, bits
);
969 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
970 InvertRect(hDC
, &rcMask
);
971 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
972 SelectObject(hDC
, hbmOrig
);
974 data
->hWMIconBitmap
= ii
.hbmColor
;
975 data
->hWMIconMask
= ii
.hbmMask
;
977 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
978 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
979 destroy_icon_window( display
, data
);
980 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
987 /***********************************************************************
990 * set the window size hints
992 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
994 XSizeHints
* size_hints
;
996 if (!(size_hints
= XAllocSizeHints())) return;
998 size_hints
->win_gravity
= StaticGravity
;
999 size_hints
->flags
|= PWinGravity
;
1001 /* don't update size hints if window is not in normal state */
1002 if (!(style
& (WS_MINIMIZE
| WS_MAXIMIZE
)))
1004 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
1006 size_hints
->x
= data
->whole_rect
.left
;
1007 size_hints
->y
= data
->whole_rect
.top
;
1008 size_hints
->flags
|= PPosition
;
1011 if (!is_window_resizable( data
, style
))
1013 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
1014 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
1015 if (size_hints
->max_width
<= 0 ||size_hints
->max_height
<= 0)
1016 size_hints
->max_width
= size_hints
->max_height
= 1;
1017 size_hints
->min_width
= size_hints
->max_width
;
1018 size_hints
->min_height
= size_hints
->max_height
;
1019 size_hints
->flags
|= PMinSize
| PMaxSize
;
1022 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
1023 XFree( size_hints
);
1027 /***********************************************************************
1030 * get the name of the current process for setting class hints
1032 static char *get_process_name(void)
1038 WCHAR module
[MAX_PATH
];
1039 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
1040 if (len
&& len
< MAX_PATH
)
1043 WCHAR
*p
, *appname
= module
;
1045 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
1046 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
1047 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
1048 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
1050 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
1059 /***********************************************************************
1060 * set_initial_wm_hints
1062 * Set the window manager hints that don't change over the lifetime of a window.
1064 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
1068 Atom dndVersion
= WINE_XDND_VERSION
;
1069 XClassHint
*class_hints
;
1070 char *process_name
= get_process_name();
1076 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
1077 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
1078 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
1079 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
1080 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
1083 if ((class_hints
= XAllocClassHint()))
1085 static char wine
[] = "Wine";
1087 class_hints
->res_name
= process_name
;
1088 class_hints
->res_class
= wine
;
1089 XSetClassHint( display
, data
->whole_window
, class_hints
);
1090 XFree( class_hints
);
1093 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
1094 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
1095 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
1097 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
1098 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
1100 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
1101 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
1103 data
->wm_hints
= XAllocWMHints();
1104 wine_tsx11_unlock();
1108 data
->wm_hints
->flags
= 0;
1109 set_icon_hints( display
, data
, 0, 0 );
1114 /***********************************************************************
1115 * get_owner_whole_window
1117 * Retrieve an owner's window, creating it if necessary.
1119 static Window
get_owner_whole_window( HWND owner
, BOOL force_managed
)
1121 struct x11drv_win_data
*data
;
1123 if (!owner
) return 0;
1125 if (!(data
= X11DRV_get_win_data( owner
)))
1127 if (GetWindowThreadProcessId( owner
, NULL
) != GetCurrentThreadId() ||
1128 !(data
= X11DRV_create_win_data( owner
)))
1129 return (Window
)GetPropA( owner
, whole_window_prop
);
1131 else if (!data
->managed
&& force_managed
) /* make it managed */
1133 SetWindowPos( owner
, 0, 0, 0, 0, 0,
1134 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOMOVE
|
1135 SWP_NOREDRAW
| SWP_DEFERERASE
| SWP_NOSENDCHANGING
| SWP_STATECHANGED
);
1137 return data
->whole_window
;
1141 /***********************************************************************
1144 * Set the window manager hints for a newly-created window
1146 static void set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
1148 Window group_leader
= data
->whole_window
;
1149 Window owner_win
= 0;
1152 DWORD style
, ex_style
;
1155 if (data
->hwnd
== GetDesktopWindow())
1157 /* force some styles for the desktop to get the correct decorations */
1158 style
= WS_POPUP
| WS_VISIBLE
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
1159 ex_style
= WS_EX_APPWINDOW
;
1164 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1165 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
1166 owner
= GetWindow( data
->hwnd
, GW_OWNER
);
1167 if ((owner_win
= get_owner_whole_window( owner
, data
->managed
))) group_leader
= owner_win
;
1172 if (owner_win
) XSetTransientForHint( display
, data
->whole_window
, owner_win
);
1175 set_size_hints( display
, data
, style
);
1177 /* set the WM_WINDOW_TYPE */
1178 if (style
& WS_THICKFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
1179 else if (ex_style
& WS_EX_APPWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
1180 else if (style
& WS_MINIMIZEBOX
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
1181 else if (style
& WS_DLGFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
1182 else if (ex_style
& WS_EX_DLGMODALFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
1183 else if ((style
& WS_POPUP
) && owner
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
1184 #if 0 /* many window managers don't handle utility windows very well */
1185 else if (ex_style
& WS_EX_TOOLWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY
);
1187 else window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
1189 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
1190 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
1192 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
1193 mwm_hints
.decorations
= get_mwm_decorations( data
, style
, ex_style
);
1194 mwm_hints
.functions
= MWM_FUNC_MOVE
;
1195 if (is_window_resizable( data
, style
)) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
1196 if (!(style
& WS_DISABLED
))
1198 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
1199 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
1200 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
1203 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
1204 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
1205 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
1210 data
->wm_hints
->flags
|= InputHint
| StateHint
| WindowGroupHint
;
1211 data
->wm_hints
->input
= !use_take_focus
&& !(style
& WS_DISABLED
);
1212 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
1213 data
->wm_hints
->window_group
= group_leader
;
1214 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
1217 wine_tsx11_unlock();
1221 /***********************************************************************
1222 * update_net_wm_states
1224 void update_net_wm_states( Display
*display
, struct x11drv_win_data
*data
)
1226 static const unsigned int state_atoms
[NB_NET_WM_STATES
] =
1228 XATOM__NET_WM_STATE_FULLSCREEN
,
1229 XATOM__NET_WM_STATE_ABOVE
,
1230 XATOM__NET_WM_STATE_MAXIMIZED_VERT
,
1231 XATOM__NET_WM_STATE_SKIP_PAGER
,
1232 XATOM__NET_WM_STATE_SKIP_TASKBAR
1235 DWORD i
, style
, ex_style
, new_state
= 0;
1237 if (!data
->managed
) return;
1238 if (data
->whole_window
== root_window
) return;
1240 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1241 if (data
->whole_rect
.left
<= 0 && data
->whole_rect
.right
>= screen_width
&&
1242 data
->whole_rect
.top
<= 0 && data
->whole_rect
.bottom
>= screen_height
)
1244 if ((style
& WS_MAXIMIZE
) && (style
& WS_CAPTION
) == WS_CAPTION
)
1245 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
1246 else if (!(style
& WS_MINIMIZE
))
1247 new_state
|= (1 << NET_WM_STATE_FULLSCREEN
);
1249 else if (style
& WS_MAXIMIZE
)
1250 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
1252 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
1253 if (ex_style
& WS_EX_TOPMOST
)
1254 new_state
|= (1 << NET_WM_STATE_ABOVE
);
1255 if (ex_style
& (WS_EX_TOOLWINDOW
| WS_EX_NOACTIVATE
))
1256 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
) | (1 << NET_WM_STATE_SKIP_PAGER
);
1257 if (!(ex_style
& WS_EX_APPWINDOW
) && GetWindow( data
->hwnd
, GW_OWNER
))
1258 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
);
1260 if (!data
->mapped
) /* set the _NET_WM_STATE atom directly */
1262 Atom atoms
[NB_NET_WM_STATES
+1];
1265 for (i
= count
= 0; i
< NB_NET_WM_STATES
; i
++)
1267 if (!(new_state
& (1 << i
))) continue;
1268 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
1269 i
, data
->hwnd
, data
->whole_window
);
1270 atoms
[count
++] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
1271 if (state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
)
1272 atoms
[count
++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
);
1275 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_STATE
), XA_ATOM
,
1276 32, PropModeReplace
, (unsigned char *)atoms
, count
);
1277 wine_tsx11_unlock();
1279 else /* ask the window manager to do it for us */
1283 xev
.xclient
.type
= ClientMessage
;
1284 xev
.xclient
.window
= data
->whole_window
;
1285 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
1286 xev
.xclient
.serial
= 0;
1287 xev
.xclient
.display
= display
;
1288 xev
.xclient
.send_event
= True
;
1289 xev
.xclient
.format
= 32;
1290 xev
.xclient
.data
.l
[3] = 1;
1292 for (i
= 0; i
< NB_NET_WM_STATES
; i
++)
1294 if (!((data
->net_wm_state
^ new_state
) & (1 << i
))) continue; /* unchanged */
1296 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1297 i
, data
->hwnd
, data
->whole_window
,
1298 (new_state
& (1 << i
)) != 0, (data
->net_wm_state
& (1 << i
)) != 0 );
1300 xev
.xclient
.data
.l
[0] = (new_state
& (1 << i
)) ? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
1301 xev
.xclient
.data
.l
[1] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
1302 xev
.xclient
.data
.l
[2] = ((state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
) ?
1303 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
) : 0);
1305 XSendEvent( display
, root_window
, False
,
1306 SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
1307 wine_tsx11_unlock();
1310 data
->net_wm_state
= new_state
;
1314 /***********************************************************************
1317 static void set_xembed_flags( Display
*display
, struct x11drv_win_data
*data
, unsigned long flags
)
1319 unsigned long info
[2];
1321 info
[0] = 0; /* protocol version */
1324 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_XEMBED_INFO
),
1325 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
, (unsigned char*)info
, 2 );
1326 wine_tsx11_unlock();
1330 /***********************************************************************
1333 static void map_window( Display
*display
, struct x11drv_win_data
*data
, DWORD new_style
)
1335 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1337 remove_startup_notification( display
, data
->whole_window
);
1339 wait_for_withdrawn_state( display
, data
, TRUE
);
1341 if (!data
->embedded
)
1343 update_net_wm_states( display
, data
);
1344 sync_window_style( display
, data
);
1346 XMapWindow( display
, data
->whole_window
);
1347 wine_tsx11_unlock();
1349 else set_xembed_flags( display
, data
, XEMBED_MAPPED
);
1351 data
->mapped
= TRUE
;
1352 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
1356 /***********************************************************************
1359 static void unmap_window( Display
*display
, struct x11drv_win_data
*data
)
1361 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1363 if (!data
->embedded
)
1365 wait_for_withdrawn_state( display
, data
, FALSE
);
1367 if (data
->managed
) XWithdrawWindow( display
, data
->whole_window
, DefaultScreen(display
) );
1368 else XUnmapWindow( display
, data
->whole_window
);
1369 wine_tsx11_unlock();
1371 else set_xembed_flags( display
, data
, 0 );
1373 data
->mapped
= FALSE
;
1374 data
->net_wm_state
= 0;
1378 /***********************************************************************
1379 * make_window_embedded
1381 void make_window_embedded( Display
*display
, struct x11drv_win_data
*data
)
1385 /* the window cannot be mapped before being embedded */
1386 unmap_window( display
, data
);
1387 data
->embedded
= TRUE
;
1388 map_window( display
, data
, 0 );
1392 data
->embedded
= TRUE
;
1393 set_xembed_flags( display
, data
, 0 );
1398 /***********************************************************************
1399 * X11DRV_window_to_X_rect
1401 * Convert a rect from client to X window coordinates
1403 static void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1407 if (!data
->managed
) return;
1408 if (IsRectEmpty( rect
)) return;
1410 get_x11_rect_offset( data
, &rc
);
1412 rect
->left
-= rc
.left
;
1413 rect
->right
-= rc
.right
;
1414 rect
->top
-= rc
.top
;
1415 rect
->bottom
-= rc
.bottom
;
1416 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1417 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1421 /***********************************************************************
1422 * X11DRV_X_to_window_rect
1424 * Opposite of X11DRV_window_to_X_rect
1426 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1430 if (!data
->managed
) return;
1431 if (IsRectEmpty( rect
)) return;
1433 get_x11_rect_offset( data
, &rc
);
1435 rect
->left
+= rc
.left
;
1436 rect
->right
+= rc
.right
;
1437 rect
->top
+= rc
.top
;
1438 rect
->bottom
+= rc
.bottom
;
1439 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1440 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1444 /***********************************************************************
1445 * sync_window_position
1447 * Synchronize the X window position with the Windows one
1449 static void sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
1450 UINT swp_flags
, const RECT
*old_window_rect
,
1451 const RECT
*old_whole_rect
, const RECT
*old_client_rect
)
1453 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1454 XWindowChanges changes
;
1455 unsigned int mask
= 0;
1457 if (data
->managed
&& data
->iconic
) return;
1459 /* resizing a managed maximized window is not allowed */
1460 if (!(style
& WS_MAXIMIZE
) || !data
->managed
)
1462 changes
.width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
1463 changes
.height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
1464 /* if window rect is empty force size to 1x1 */
1465 if (changes
.width
<= 0 || changes
.height
<= 0) changes
.width
= changes
.height
= 1;
1466 if (changes
.width
> 65535) changes
.width
= 65535;
1467 if (changes
.height
> 65535) changes
.height
= 65535;
1468 mask
|= CWWidth
| CWHeight
;
1471 /* only the size is allowed to change for the desktop window */
1472 if (data
->whole_window
!= root_window
)
1474 changes
.x
= data
->whole_rect
.left
- virtual_screen_rect
.left
;
1475 changes
.y
= data
->whole_rect
.top
- virtual_screen_rect
.top
;
1479 if (!(swp_flags
& SWP_NOZORDER
) || (swp_flags
& SWP_SHOWWINDOW
))
1481 /* find window that this one must be after */
1482 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
1483 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
1484 prev
= GetWindow( prev
, GW_HWNDPREV
);
1485 if (!prev
) /* top child */
1487 changes
.stack_mode
= Above
;
1488 mask
|= CWStackMode
;
1490 /* should use stack_mode Below but most window managers don't get it right */
1491 /* and Above with a sibling doesn't work so well either, so we ignore it */
1495 set_size_hints( display
, data
, style
);
1496 data
->configure_serial
= NextRequest( display
);
1497 XReconfigureWMWindow( display
, data
->whole_window
,
1498 DefaultScreen(display
), mask
, &changes
);
1499 #ifdef HAVE_LIBXSHAPE
1500 if (IsRectEmpty( old_window_rect
) != IsRectEmpty( &data
->window_rect
))
1501 sync_window_region( display
, data
, (HRGN
)1 );
1504 int old_x_offset
= old_window_rect
->left
- old_whole_rect
->left
;
1505 int old_y_offset
= old_window_rect
->top
- old_whole_rect
->top
;
1506 int new_x_offset
= data
->window_rect
.left
- data
->whole_rect
.left
;
1507 int new_y_offset
= data
->window_rect
.top
- data
->whole_rect
.top
;
1508 if (old_x_offset
!= new_x_offset
|| old_y_offset
!= new_y_offset
)
1509 XShapeOffsetShape( display
, data
->whole_window
, ShapeBounding
,
1510 new_x_offset
- old_x_offset
, new_y_offset
- old_y_offset
);
1513 wine_tsx11_unlock();
1515 TRACE( "win %p/%lx pos %d,%d,%dx%d after %lx changes=%x serial=%lu\n",
1516 data
->hwnd
, data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1517 data
->whole_rect
.right
- data
->whole_rect
.left
,
1518 data
->whole_rect
.bottom
- data
->whole_rect
.top
,
1519 changes
.sibling
, mask
, data
->configure_serial
);
1523 /***********************************************************************
1524 * sync_client_position
1526 * Synchronize the X client window position with the Windows one
1528 static void sync_client_position( Display
*display
, struct x11drv_win_data
*data
,
1529 UINT swp_flags
, const RECT
*old_client_rect
,
1530 const RECT
*old_whole_rect
)
1533 XWindowChanges changes
;
1534 RECT old
= *old_client_rect
;
1535 RECT
new = data
->client_rect
;
1537 OffsetRect( &old
, -old_whole_rect
->left
, -old_whole_rect
->top
);
1538 OffsetRect( &new, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
1539 if (!(mask
= get_window_changes( &changes
, &old
, &new ))) return;
1541 if (data
->client_window
)
1543 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1544 data
->client_window
, new.left
, new.top
,
1545 new.right
- new.left
, new.bottom
- new.top
, mask
);
1547 XConfigureWindow( display
, data
->client_window
, mask
, &changes
);
1548 wine_tsx11_unlock();
1551 if (data
->gl_drawable
&& (mask
& (CWWidth
|CWHeight
))) sync_gl_drawable( data
);
1555 /***********************************************************************
1558 * Move the window bits when a window is moved.
1560 static void move_window_bits( struct x11drv_win_data
*data
, const RECT
*old_rect
, const RECT
*new_rect
,
1561 const RECT
*old_client_rect
)
1563 RECT src_rect
= *old_rect
;
1564 RECT dst_rect
= *new_rect
;
1565 HDC hdc_src
, hdc_dst
;
1570 if (!data
->whole_window
)
1572 OffsetRect( &dst_rect
, -data
->window_rect
.left
, -data
->window_rect
.top
);
1573 parent
= GetAncestor( data
->hwnd
, GA_PARENT
);
1574 hdc_src
= GetDCEx( parent
, 0, DCX_CACHE
);
1575 hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
1579 OffsetRect( &dst_rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
1580 /* make src rect relative to the old position of the window */
1581 OffsetRect( &src_rect
, -old_client_rect
->left
, -old_client_rect
->top
);
1582 if (dst_rect
.left
== src_rect
.left
&& dst_rect
.top
== src_rect
.top
) return;
1583 hdc_src
= hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
);
1586 code
= X11DRV_START_EXPOSURES
;
1587 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
1589 TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n",
1590 data
->hwnd
, data
->whole_window
, data
->client_window
,
1591 wine_dbgstr_rect(&src_rect
), wine_dbgstr_rect(&dst_rect
) );
1592 BitBlt( hdc_dst
, dst_rect
.left
, dst_rect
.top
,
1593 dst_rect
.right
- dst_rect
.left
, dst_rect
.bottom
- dst_rect
.top
,
1594 hdc_src
, src_rect
.left
, src_rect
.top
, SRCCOPY
);
1596 code
= X11DRV_END_EXPOSURES
;
1597 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, sizeof(rgn
), (LPSTR
)&rgn
);
1599 ReleaseDC( data
->hwnd
, hdc_dst
);
1600 if (hdc_src
!= hdc_dst
) ReleaseDC( parent
, hdc_src
);
1604 if (!data
->whole_window
)
1606 /* map region to client rect since we are using DCX_WINDOW */
1607 OffsetRgn( rgn
, data
->window_rect
.left
- data
->client_rect
.left
,
1608 data
->window_rect
.top
- data
->client_rect
.top
);
1609 RedrawWindow( data
->hwnd
, NULL
, rgn
,
1610 RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
1612 else RedrawWindow( data
->hwnd
, NULL
, rgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1613 DeleteObject( rgn
);
1618 /**********************************************************************
1619 * create_whole_window
1621 * Create the whole X window for a given window
1623 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1626 XSetWindowAttributes attr
;
1630 DWORD layered_flags
;
1633 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1635 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1636 data
->managed
= TRUE
;
1637 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1640 if ((win_rgn
= CreateRectRgn( 0, 0, 0, 0 )) &&
1641 GetWindowRgn( data
->hwnd
, win_rgn
) == ERROR
)
1643 DeleteObject( win_rgn
);
1646 data
->shaped
= (win_rgn
!= 0);
1648 mask
= get_window_attributes( display
, data
, &attr
);
1650 data
->whole_rect
= data
->window_rect
;
1651 X11DRV_window_to_X_rect( data
, &data
->whole_rect
);
1652 if (!(cx
= data
->whole_rect
.right
- data
->whole_rect
.left
)) cx
= 1;
1653 else if (cx
> 65535) cx
= 65535;
1654 if (!(cy
= data
->whole_rect
.bottom
- data
->whole_rect
.top
)) cy
= 1;
1655 else if (cy
> 65535) cy
= 65535;
1658 data
->whole_window
= XCreateWindow( display
, root_window
,
1659 data
->whole_rect
.left
- virtual_screen_rect
.left
,
1660 data
->whole_rect
.top
- virtual_screen_rect
.top
,
1661 cx
, cy
, 0, screen_depth
, InputOutput
,
1662 visual
, mask
, &attr
);
1664 if (data
->whole_window
) XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1665 wine_tsx11_unlock();
1667 if (!data
->whole_window
) goto done
;
1669 if (!create_client_window( display
, data
, NULL
))
1672 XDeleteContext( display
, data
->whole_window
, winContext
);
1673 XDestroyWindow( display
, data
->whole_window
);
1674 data
->whole_window
= 0;
1675 wine_tsx11_unlock();
1679 set_initial_wm_hints( display
, data
);
1680 set_wm_hints( display
, data
);
1682 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1684 /* set the window text */
1685 if (!InternalGetWindowText( data
->hwnd
, text
, sizeof(text
)/sizeof(WCHAR
) )) text
[0] = 0;
1686 sync_window_text( display
, data
->whole_window
, text
);
1688 /* set the window region */
1689 if (win_rgn
|| IsRectEmpty( &data
->window_rect
)) sync_window_region( display
, data
, win_rgn
);
1691 /* set the window opacity */
1692 if (!GetLayeredWindowAttributes( data
->hwnd
, &key
, &alpha
, &layered_flags
)) layered_flags
= 0;
1693 sync_window_opacity( display
, data
->whole_window
, key
, alpha
, layered_flags
);
1696 XFlush( display
); /* make sure the window exists before we start painting to it */
1697 wine_tsx11_unlock();
1699 sync_window_cursor( data
);
1701 if (win_rgn
) DeleteObject( win_rgn
);
1702 return data
->whole_window
;
1706 /**********************************************************************
1707 * destroy_whole_window
1709 * Destroy the whole X window for a given window.
1711 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
, BOOL already_destroyed
)
1713 if (!data
->whole_window
) return;
1715 TRACE( "win %p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1717 XDeleteContext( display
, data
->whole_window
, winContext
);
1718 XDeleteContext( display
, data
->client_window
, winContext
);
1719 if (!already_destroyed
) XDestroyWindow( display
, data
->whole_window
);
1720 data
->whole_window
= data
->client_window
= 0;
1721 data
->wm_state
= WithdrawnState
;
1722 data
->net_wm_state
= 0;
1723 data
->mapped
= FALSE
;
1726 XUnsetICFocus( data
->xic
);
1727 XDestroyIC( data
->xic
);
1730 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1732 XFree( data
->wm_hints
);
1733 data
->wm_hints
= NULL
;
1734 wine_tsx11_unlock();
1735 RemovePropA( data
->hwnd
, whole_window_prop
);
1736 RemovePropA( data
->hwnd
, client_window_prop
);
1740 /*****************************************************************
1741 * SetWindowText (X11DRV.@)
1743 void CDECL
X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1747 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(gdi_display
))
1749 Display
*display
= thread_init_display();
1750 sync_window_text( display
, win
, text
);
1755 /***********************************************************************
1756 * SetWindowStyle (X11DRV.@)
1758 * Update the X state of a window to reflect a style change
1760 void CDECL
X11DRV_SetWindowStyle( HWND hwnd
, INT offset
, STYLESTRUCT
*style
)
1762 struct x11drv_win_data
*data
;
1765 if (hwnd
== GetDesktopWindow()) return;
1766 changed
= style
->styleNew
^ style
->styleOld
;
1768 if (offset
== GWL_STYLE
&& (changed
& WS_VISIBLE
) && (style
->styleNew
& WS_VISIBLE
))
1770 /* we don't unmap windows, that causes trouble with the window manager */
1771 if (!(data
= X11DRV_get_win_data( hwnd
)) &&
1772 !(data
= X11DRV_create_win_data( hwnd
))) return;
1774 if (data
->whole_window
&& is_window_rect_mapped( &data
->window_rect
))
1776 Display
*display
= thread_display();
1777 set_wm_hints( display
, data
);
1778 if (!data
->mapped
) map_window( display
, data
, style
->styleNew
);
1782 if (offset
== GWL_STYLE
&& (changed
& WS_DISABLED
))
1784 data
= X11DRV_get_win_data( hwnd
);
1785 if (data
&& data
->whole_window
)
1786 set_wm_hints( thread_display(), data
);
1789 if (offset
== GWL_EXSTYLE
&& (changed
& WS_EX_LAYERED
))
1791 /* changing WS_EX_LAYERED resets attributes */
1792 if ((data
= X11DRV_get_win_data( hwnd
)) && data
->whole_window
)
1793 sync_window_opacity( thread_display(), data
->whole_window
, 0, 0, 0 );
1798 /***********************************************************************
1799 * DestroyWindow (X11DRV.@)
1801 void CDECL
X11DRV_DestroyWindow( HWND hwnd
)
1803 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1804 struct x11drv_win_data
*data
;
1806 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1811 destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
1812 XFreePixmap(gdi_display
, data
->pixmap
);
1813 wine_tsx11_unlock();
1815 else if (data
->gl_drawable
)
1818 XDestroyWindow(gdi_display
, data
->gl_drawable
);
1819 wine_tsx11_unlock();
1822 destroy_whole_window( thread_data
->display
, data
, FALSE
);
1823 destroy_icon_window( thread_data
->display
, data
);
1828 XFreeColormap( thread_data
->display
, data
->colormap
);
1829 wine_tsx11_unlock();
1832 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1833 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1834 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1836 XDeleteContext( thread_data
->display
, (XID
)hwnd
, win_data_context
);
1837 wine_tsx11_unlock();
1838 HeapFree( GetProcessHeap(), 0, data
);
1842 /***********************************************************************
1843 * X11DRV_DestroyNotify
1845 void X11DRV_DestroyNotify( HWND hwnd
, XEvent
*event
)
1847 Display
*display
= event
->xdestroywindow
.display
;
1848 struct x11drv_win_data
*data
;
1850 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1852 FIXME( "window %p/%lx destroyed from the outside\n", hwnd
, data
->whole_window
);
1853 destroy_whole_window( display
, data
, TRUE
);
1857 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1859 struct x11drv_win_data
*data
;
1861 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
1865 if (!winContext
) winContext
= XUniqueContext();
1866 if (!win_data_context
) win_data_context
= XUniqueContext();
1867 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1868 wine_tsx11_unlock();
1874 /* initialize the desktop window id in the desktop manager process */
1875 static struct x11drv_win_data
*create_desktop_win_data( Display
*display
, HWND hwnd
)
1877 struct x11drv_win_data
*data
;
1879 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1880 data
->whole_window
= data
->client_window
= root_window
;
1881 data
->managed
= TRUE
;
1882 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1883 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1884 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)root_window
);
1885 set_initial_wm_hints( display
, data
);
1889 /**********************************************************************
1890 * CreateDesktopWindow (X11DRV.@)
1892 BOOL CDECL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1894 unsigned int width
, height
;
1896 /* retrieve the real size of the desktop */
1897 SERVER_START_REQ( get_window_rectangles
)
1899 req
->handle
= wine_server_user_handle( hwnd
);
1900 wine_server_call( req
);
1901 width
= reply
->window
.right
- reply
->window
.left
;
1902 height
= reply
->window
.bottom
- reply
->window
.top
;
1906 if (!width
&& !height
) /* not initialized yet */
1908 SERVER_START_REQ( set_window_pos
)
1910 req
->handle
= wine_server_user_handle( hwnd
);
1912 req
->flags
= SWP_NOZORDER
;
1913 req
->window
.left
= virtual_screen_rect
.left
;
1914 req
->window
.top
= virtual_screen_rect
.top
;
1915 req
->window
.right
= virtual_screen_rect
.right
;
1916 req
->window
.bottom
= virtual_screen_rect
.bottom
;
1917 req
->client
= req
->window
;
1918 wine_server_call( req
);
1924 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1925 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1931 /**********************************************************************
1932 * CreateWindow (X11DRV.@)
1934 BOOL CDECL
X11DRV_CreateWindow( HWND hwnd
)
1936 if (hwnd
== GetDesktopWindow() && root_window
!= DefaultRootWindow( gdi_display
))
1938 Display
*display
= thread_init_display();
1940 /* the desktop win data can't be created lazily */
1941 if (!create_desktop_win_data( display
, hwnd
)) return FALSE
;
1947 /***********************************************************************
1948 * X11DRV_get_win_data
1950 * Return the X11 data structure associated with a window.
1952 struct x11drv_win_data
*X11DRV_get_win_data( HWND hwnd
)
1954 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1957 if (!thread_data
) return NULL
;
1958 if (!hwnd
) return NULL
;
1959 if (XFindContext( thread_data
->display
, (XID
)hwnd
, win_data_context
, &data
)) data
= NULL
;
1960 return (struct x11drv_win_data
*)data
;
1964 /***********************************************************************
1965 * X11DRV_create_win_data
1967 * Create an X11 data window structure for an existing window.
1969 struct x11drv_win_data
*X11DRV_create_win_data( HWND hwnd
)
1972 struct x11drv_win_data
*data
;
1975 if (!(parent
= GetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop */
1977 /* don't create win data for HWND_MESSAGE windows */
1978 if (parent
!= GetDesktopWindow() && !GetAncestor( parent
, GA_PARENT
)) return NULL
;
1980 display
= thread_init_display();
1981 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1983 GetWindowRect( hwnd
, &data
->window_rect
);
1984 MapWindowPoints( 0, parent
, (POINT
*)&data
->window_rect
, 2 );
1985 data
->whole_rect
= data
->window_rect
;
1986 GetClientRect( hwnd
, &data
->client_rect
);
1987 MapWindowPoints( hwnd
, parent
, (POINT
*)&data
->client_rect
, 2 );
1989 if (parent
== GetDesktopWindow())
1991 if (!create_whole_window( display
, data
))
1993 HeapFree( GetProcessHeap(), 0, data
);
1996 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1997 hwnd
, data
->whole_window
, data
->client_window
, wine_dbgstr_rect( &data
->window_rect
),
1998 wine_dbgstr_rect( &data
->whole_rect
), wine_dbgstr_rect( &data
->client_rect
));
2004 /***********************************************************************
2005 * X11DRV_get_whole_window
2007 * Return the X window associated with the full area of a window
2009 Window
X11DRV_get_whole_window( HWND hwnd
)
2011 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2015 if (hwnd
== GetDesktopWindow()) return root_window
;
2016 return (Window
)GetPropA( hwnd
, whole_window_prop
);
2018 return data
->whole_window
;
2022 /***********************************************************************
2023 * X11DRV_get_client_window
2025 * Return the X window associated with the client area of a window
2027 static Window
X11DRV_get_client_window( HWND hwnd
)
2029 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2033 if (hwnd
== GetDesktopWindow()) return root_window
;
2034 return (Window
)GetPropA( hwnd
, client_window_prop
);
2036 return data
->client_window
;
2040 /***********************************************************************
2043 * Return the X input context associated with a window
2045 XIC
X11DRV_get_ic( HWND hwnd
)
2047 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2050 if (!data
) return 0;
2051 if (data
->xic
) return data
->xic
;
2052 if (!(xim
= x11drv_thread_data()->xim
)) return 0;
2053 return X11DRV_CreateIC( xim
, data
);
2057 /***********************************************************************
2058 * X11DRV_GetDC (X11DRV.@)
2060 void CDECL
X11DRV_GetDC( HDC hdc
, HWND hwnd
, HWND top
, const RECT
*win_rect
,
2061 const RECT
*top_rect
, DWORD flags
)
2063 struct x11drv_escape_set_drawable escape
;
2064 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2066 escape
.code
= X11DRV_SET_DRAWABLE
;
2067 escape
.mode
= IncludeInferiors
;
2068 escape
.fbconfig_id
= 0;
2069 escape
.gl_drawable
= 0;
2071 escape
.gl_copy
= FALSE
;
2075 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
2076 /* GL draws to the client area even for window DCs */
2077 escape
.gl_drawable
= data
? data
->client_window
: X11DRV_get_client_window( hwnd
);
2078 if (data
&& IsIconic( hwnd
) && data
->icon_window
)
2080 escape
.drawable
= data
->icon_window
;
2082 else if (flags
& DCX_WINDOW
)
2083 escape
.drawable
= data
? data
->whole_window
: X11DRV_get_whole_window( hwnd
);
2085 escape
.drawable
= escape
.gl_drawable
;
2089 escape
.drawable
= X11DRV_get_client_window( top
);
2090 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
2091 escape
.gl_drawable
= data
? data
->gl_drawable
: (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
2092 escape
.pixmap
= data
? data
->pixmap
: (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
2093 escape
.gl_copy
= (escape
.gl_drawable
!= 0);
2094 if (flags
& DCX_CLIPCHILDREN
) escape
.mode
= ClipByChildren
;
2097 escape
.dc_rect
.left
= win_rect
->left
- top_rect
->left
;
2098 escape
.dc_rect
.top
= win_rect
->top
- top_rect
->top
;
2099 escape
.dc_rect
.right
= win_rect
->right
- top_rect
->left
;
2100 escape
.dc_rect
.bottom
= win_rect
->bottom
- top_rect
->top
;
2101 escape
.drawable_rect
.left
= top_rect
->left
;
2102 escape
.drawable_rect
.top
= top_rect
->top
;
2103 escape
.drawable_rect
.right
= top_rect
->right
;
2104 escape
.drawable_rect
.bottom
= top_rect
->bottom
;
2106 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2110 /***********************************************************************
2111 * X11DRV_ReleaseDC (X11DRV.@)
2113 void CDECL
X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
2115 struct x11drv_escape_set_drawable escape
;
2117 escape
.code
= X11DRV_SET_DRAWABLE
;
2118 escape
.drawable
= root_window
;
2119 escape
.mode
= IncludeInferiors
;
2120 escape
.drawable_rect
= virtual_screen_rect
;
2121 SetRect( &escape
.dc_rect
, 0, 0, virtual_screen_rect
.right
- virtual_screen_rect
.left
,
2122 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
);
2123 OffsetRect( &escape
.dc_rect
, -escape
.drawable_rect
.left
, -escape
.drawable_rect
.top
);
2124 escape
.fbconfig_id
= 0;
2125 escape
.gl_drawable
= 0;
2127 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2131 /***********************************************************************
2132 * SetCapture (X11DRV.@)
2134 void CDECL
X11DRV_SetCapture( HWND hwnd
, UINT flags
)
2136 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2138 if (!thread_data
) return;
2139 if (!(flags
& (GUI_INMOVESIZE
| GUI_INMENUMODE
))) return;
2143 Window grab_win
= X11DRV_get_client_window( GetAncestor( hwnd
, GA_ROOT
) );
2145 if (!grab_win
) return;
2147 XFlush( gdi_display
);
2148 XGrabPointer( thread_data
->display
, grab_win
, False
,
2149 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
2150 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
);
2151 wine_tsx11_unlock();
2152 thread_data
->grab_window
= grab_win
;
2154 else /* release capture */
2157 XFlush( gdi_display
);
2158 XUngrabPointer( thread_data
->display
, CurrentTime
);
2159 XFlush( thread_data
->display
);
2160 wine_tsx11_unlock();
2161 thread_data
->grab_window
= None
;
2166 /*****************************************************************
2167 * SetParent (X11DRV.@)
2169 void CDECL
X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
2171 Display
*display
= thread_display();
2172 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2175 if (parent
== old_parent
) return;
2177 if (parent
!= GetDesktopWindow()) /* a child window */
2179 if (old_parent
== GetDesktopWindow())
2181 /* destroy the old X windows */
2182 destroy_whole_window( display
, data
, FALSE
);
2183 destroy_icon_window( display
, data
);
2186 data
->managed
= FALSE
;
2187 RemovePropA( data
->hwnd
, managed_prop
);
2191 else /* new top level window */
2193 /* FIXME: we ignore errors since we can't really recover anyway */
2194 create_whole_window( display
, data
);
2199 /*****************************************************************
2200 * SetFocus (X11DRV.@)
2204 void CDECL
X11DRV_SetFocus( HWND hwnd
)
2206 Display
*display
= thread_display();
2207 struct x11drv_win_data
*data
;
2208 XWindowChanges changes
;
2211 if (!(hwnd
= GetAncestor( hwnd
, GA_ROOT
))) return;
2212 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
2213 if (data
->managed
|| !data
->whole_window
) return;
2215 if (EVENT_x11_time_to_win32_time(0))
2216 /* ICCCM says don't use CurrentTime, so try to use last message time if possible */
2217 /* FIXME: this is not entirely correct */
2218 timestamp
= GetMessageTime() - EVENT_x11_time_to_win32_time(0);
2220 timestamp
= CurrentTime
;
2222 /* Set X focus and install colormap */
2224 changes
.stack_mode
= Above
;
2225 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
2226 XSetInputFocus( display
, data
->whole_window
, RevertToParent
, timestamp
);
2227 wine_tsx11_unlock();
2231 /***********************************************************************
2232 * WindowPosChanging (X11DRV.@)
2234 void CDECL
X11DRV_WindowPosChanging( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
2235 const RECT
*window_rect
, const RECT
*client_rect
, RECT
*visible_rect
)
2237 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2238 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2242 /* create the win data if the window is being made visible */
2243 if (!(style
& WS_VISIBLE
) && !(swp_flags
& SWP_SHOWWINDOW
)) return;
2244 if (!(data
= X11DRV_create_win_data( hwnd
))) return;
2247 /* check if we need to switch the window to managed */
2248 if (!data
->managed
&& data
->whole_window
&& is_window_managed( hwnd
, swp_flags
, window_rect
))
2250 TRACE( "making win %p/%lx managed\n", hwnd
, data
->whole_window
);
2251 if (data
->mapped
) unmap_window( thread_display(), data
);
2252 data
->managed
= TRUE
;
2253 SetPropA( hwnd
, managed_prop
, (HANDLE
)1 );
2256 *visible_rect
= *window_rect
;
2257 X11DRV_window_to_X_rect( data
, visible_rect
);
2261 /***********************************************************************
2262 * WindowPosChanged (X11DRV.@)
2264 void CDECL
X11DRV_WindowPosChanged( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
2265 const RECT
*rectWindow
, const RECT
*rectClient
,
2266 const RECT
*visible_rect
, const RECT
*valid_rects
)
2268 struct x11drv_thread_data
*thread_data
;
2270 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2271 DWORD new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2272 RECT old_window_rect
, old_whole_rect
, old_client_rect
;
2277 thread_data
= x11drv_thread_data();
2278 display
= thread_data
->display
;
2280 old_window_rect
= data
->window_rect
;
2281 old_whole_rect
= data
->whole_rect
;
2282 old_client_rect
= data
->client_rect
;
2283 data
->window_rect
= *rectWindow
;
2284 data
->whole_rect
= *visible_rect
;
2285 data
->client_rect
= *rectClient
;
2287 TRACE( "win %p window %s client %s style %08x flags %08x\n",
2288 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
, swp_flags
);
2290 if (!IsRectEmpty( &valid_rects
[0] ))
2292 int x_offset
= old_whole_rect
.left
- data
->whole_rect
.left
;
2293 int y_offset
= old_whole_rect
.top
- data
->whole_rect
.top
;
2295 /* if all that happened is that the whole window moved, copy everything */
2296 if (!(swp_flags
& SWP_FRAMECHANGED
) &&
2297 old_whole_rect
.right
- data
->whole_rect
.right
== x_offset
&&
2298 old_whole_rect
.bottom
- data
->whole_rect
.bottom
== y_offset
&&
2299 old_client_rect
.left
- data
->client_rect
.left
== x_offset
&&
2300 old_client_rect
.right
- data
->client_rect
.right
== x_offset
&&
2301 old_client_rect
.top
- data
->client_rect
.top
== y_offset
&&
2302 old_client_rect
.bottom
- data
->client_rect
.bottom
== y_offset
&&
2303 !memcmp( &valid_rects
[0], &data
->client_rect
, sizeof(RECT
) ))
2305 /* if we have an X window the bits will be moved by the X server */
2306 if (!data
->whole_window
)
2307 move_window_bits( data
, &old_whole_rect
, &data
->whole_rect
, &old_client_rect
);
2310 move_window_bits( data
, &valid_rects
[1], &valid_rects
[0], &old_client_rect
);
2314 XFlush( gdi_display
); /* make sure painting is done before we move the window */
2315 wine_tsx11_unlock();
2317 sync_client_position( display
, data
, swp_flags
, &old_client_rect
, &old_whole_rect
);
2319 if (!data
->whole_window
) return;
2321 /* check if we are currently processing an event relevant to this window */
2323 if (thread_data
->current_event
&& thread_data
->current_event
->xany
.window
== data
->whole_window
)
2324 event_type
= thread_data
->current_event
->type
;
2326 if (event_type
!= ConfigureNotify
&& event_type
!= PropertyNotify
)
2327 event_type
= 0; /* ignore other events */
2331 if (((swp_flags
& SWP_HIDEWINDOW
) && !(new_style
& WS_VISIBLE
)) ||
2332 (event_type
!= ConfigureNotify
&&
2333 !is_window_rect_mapped( rectWindow
) && is_window_rect_mapped( &old_window_rect
)))
2334 unmap_window( display
, data
);
2337 /* don't change position if we are about to minimize or maximize a managed window */
2339 !(data
->managed
&& (swp_flags
& SWP_STATECHANGED
) && (new_style
& (WS_MINIMIZE
|WS_MAXIMIZE
))))
2340 sync_window_position( display
, data
, swp_flags
,
2341 &old_window_rect
, &old_whole_rect
, &old_client_rect
);
2343 if ((new_style
& WS_VISIBLE
) &&
2344 ((new_style
& WS_MINIMIZE
) || is_window_rect_mapped( rectWindow
)))
2346 if (!data
->mapped
|| (swp_flags
& (SWP_FRAMECHANGED
|SWP_STATECHANGED
)))
2347 set_wm_hints( display
, data
);
2351 map_window( display
, data
, new_style
);
2353 else if ((swp_flags
& SWP_STATECHANGED
) && (!data
->iconic
!= !(new_style
& WS_MINIMIZE
)))
2355 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
2356 TRACE( "changing win %p iconic state to %u\n", data
->hwnd
, data
->iconic
);
2359 XIconifyWindow( display
, data
->whole_window
, DefaultScreen(display
) );
2360 else if (is_window_rect_mapped( rectWindow
))
2361 XMapWindow( display
, data
->whole_window
);
2362 wine_tsx11_unlock();
2363 update_net_wm_states( display
, data
);
2365 else if (!event_type
)
2367 update_net_wm_states( display
, data
);
2372 XFlush( display
); /* make sure changes are done before we start painting again */
2373 wine_tsx11_unlock();
2377 /***********************************************************************
2378 * ShowWindow (X11DRV.@)
2380 UINT CDECL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
, RECT
*rect
, UINT swp
)
2383 unsigned int width
, height
, border
, depth
;
2385 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2386 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2387 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2389 if (!data
|| !data
->whole_window
|| !data
->managed
|| !data
->mapped
|| data
->iconic
) return swp
;
2390 if (style
& WS_MINIMIZE
) return swp
;
2391 if (IsRectEmpty( rect
)) return swp
;
2393 /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */
2395 if (!thread_data
->current_event
|| thread_data
->current_event
->xany
.window
!= data
->whole_window
)
2398 if (thread_data
->current_event
->type
!= ConfigureNotify
&&
2399 thread_data
->current_event
->type
!= PropertyNotify
)
2402 TRACE( "win %p/%lx cmd %d at %s flags %08x\n",
2403 hwnd
, data
->whole_window
, cmd
, wine_dbgstr_rect(rect
), swp
);
2406 XGetGeometry( thread_data
->display
, data
->whole_window
,
2407 &root
, &x
, &y
, &width
, &height
, &border
, &depth
);
2408 XTranslateCoordinates( thread_data
->display
, data
->whole_window
, root
, 0, 0, &x
, &y
, &top
);
2409 wine_tsx11_unlock();
2412 rect
->right
= x
+ width
;
2413 rect
->bottom
= y
+ height
;
2414 OffsetRect( rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
2415 X11DRV_X_to_window_rect( data
, rect
);
2416 return swp
& ~(SWP_NOMOVE
| SWP_NOCLIENTMOVE
| SWP_NOSIZE
| SWP_NOCLIENTSIZE
);
2420 /**********************************************************************
2421 * SetWindowIcon (X11DRV.@)
2423 * hIcon or hIconSm has changed (or is being initialised for the
2424 * first time). Complete the X11 driver-specific initialisation
2425 * and set the window hints.
2427 * This is not entirely correct, may need to create
2428 * an icon window and set the pixmap as a background
2430 void CDECL
X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
2432 Display
*display
= thread_display();
2433 struct x11drv_win_data
*data
;
2436 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
2437 if (!data
->whole_window
) return;
2438 if (!data
->managed
) return;
2442 if (type
== ICON_BIG
) set_icon_hints( display
, data
, icon
, 0 );
2443 else set_icon_hints( display
, data
, 0, icon
);
2445 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
2446 wine_tsx11_unlock();
2451 /***********************************************************************
2452 * SetWindowRgn (X11DRV.@)
2454 * Assign specified region to window (for non-rectangular windows)
2456 int CDECL
X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
2458 struct x11drv_win_data
*data
;
2460 if ((data
= X11DRV_get_win_data( hwnd
)))
2462 sync_window_region( thread_display(), data
, hrgn
);
2464 else if (X11DRV_get_whole_window( hwnd
))
2466 SendMessageW( hwnd
, WM_X11DRV_SET_WIN_REGION
, 0, 0 );
2472 /***********************************************************************
2473 * SetLayeredWindowAttributes (X11DRV.@)
2475 * Set transparency attributes for a layered window.
2477 void CDECL
X11DRV_SetLayeredWindowAttributes( HWND hwnd
, COLORREF key
, BYTE alpha
, DWORD flags
)
2479 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2483 if (data
->whole_window
)
2484 sync_window_opacity( thread_display(), data
->whole_window
, key
, alpha
, flags
);
2488 Window win
= X11DRV_get_whole_window( hwnd
);
2489 if (win
) sync_window_opacity( gdi_display
, win
, key
, alpha
, flags
);
2494 /**********************************************************************
2495 * X11DRV_WindowMessage (X11DRV.@)
2497 LRESULT CDECL
X11DRV_WindowMessage( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2499 struct x11drv_win_data
*data
;
2503 case WM_X11DRV_ACQUIRE_SELECTION
:
2504 return X11DRV_AcquireClipboard( hwnd
);
2505 case WM_X11DRV_SET_WIN_FORMAT
:
2506 return set_win_format( hwnd
, (XID
)wp
);
2507 case WM_X11DRV_SET_WIN_REGION
:
2508 if ((data
= X11DRV_get_win_data( hwnd
))) sync_window_region( thread_display(), data
, (HRGN
)1 );
2510 case WM_X11DRV_RESIZE_DESKTOP
:
2511 X11DRV_resize_desktop( LOWORD(lp
), HIWORD(lp
) );
2513 case WM_X11DRV_SET_CURSOR
:
2514 set_window_cursor( hwnd
, (HCURSOR
)lp
);
2517 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg
, hwnd
, wp
, lp
);
2523 /***********************************************************************
2524 * is_netwm_supported
2526 static BOOL
is_netwm_supported( Display
*display
, Atom atom
)
2528 static Atom
*net_supported
;
2529 static int net_supported_count
= -1;
2533 if (net_supported_count
== -1)
2537 unsigned long count
, remaining
;
2539 if (!XGetWindowProperty( display
, DefaultRootWindow(display
), x11drv_atom(_NET_SUPPORTED
), 0,
2540 ~0UL, False
, XA_ATOM
, &type
, &format
, &count
,
2541 &remaining
, (unsigned char **)&net_supported
))
2542 net_supported_count
= get_property_size( format
, count
) / sizeof(Atom
);
2544 net_supported_count
= 0;
2546 wine_tsx11_unlock();
2548 for (i
= 0; i
< net_supported_count
; i
++)
2549 if (net_supported
[i
] == atom
) return TRUE
;
2554 /***********************************************************************
2555 * SysCommand (X11DRV.@)
2557 * Perform WM_SYSCOMMAND handling.
2559 LRESULT CDECL
X11DRV_SysCommand( HWND hwnd
, WPARAM wparam
, LPARAM lparam
)
2561 WPARAM hittest
= wparam
& 0x0f;
2565 Display
*display
= thread_display();
2566 struct x11drv_win_data
*data
;
2568 if (!(data
= X11DRV_get_win_data( hwnd
))) return -1;
2569 if (!data
->whole_window
|| !data
->managed
|| !data
->mapped
) return -1;
2571 switch (wparam
& 0xfff0)
2574 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
2575 else dir
= _NET_WM_MOVERESIZE_MOVE
;
2578 /* windows without WS_THICKFRAME are not resizable through the window manager */
2579 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_THICKFRAME
)) return -1;
2583 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
2584 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
2585 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
2586 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
2587 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
2588 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
2589 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
2590 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
2591 default: dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
; break;
2596 /* prevent a simple ALT press+release from activating the system menu,
2597 * as that can get confusing on managed windows */
2598 if ((WCHAR
)lparam
) return -1; /* got an explicit char */
2599 if (GetMenu( hwnd
)) return -1; /* window has a real menu */
2600 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_SYSMENU
)) return -1; /* no system menu */
2601 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam
, lparam
);
2608 if (IsZoomed(hwnd
)) return -1;
2610 if (!is_netwm_supported( display
, x11drv_atom(_NET_WM_MOVERESIZE
) ))
2612 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
2616 dwPoint
= GetMessagePos();
2617 x
= (short)LOWORD(dwPoint
);
2618 y
= (short)HIWORD(dwPoint
);
2620 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd
, x
, y
, dir
);
2622 xev
.xclient
.type
= ClientMessage
;
2623 xev
.xclient
.window
= X11DRV_get_whole_window(hwnd
);
2624 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_MOVERESIZE
);
2625 xev
.xclient
.serial
= 0;
2626 xev
.xclient
.display
= display
;
2627 xev
.xclient
.send_event
= True
;
2628 xev
.xclient
.format
= 32;
2629 xev
.xclient
.data
.l
[0] = x
- virtual_screen_rect
.left
; /* x coord */
2630 xev
.xclient
.data
.l
[1] = y
- virtual_screen_rect
.top
; /* y coord */
2631 xev
.xclient
.data
.l
[2] = dir
; /* direction */
2632 xev
.xclient
.data
.l
[3] = 1; /* button */
2633 xev
.xclient
.data
.l
[4] = 0; /* unused */
2635 /* need to ungrab the pointer that may have been automatically grabbed
2636 * with a ButtonPress event */
2638 XUngrabPointer( display
, CurrentTime
);
2639 XSendEvent(display
, root_window
, False
, SubstructureNotifyMask
, &xev
);
2640 wine_tsx11_unlock();