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 /* is cursor clipping active? */
72 int clipping_cursor
= 0;
74 /* X context to associate a hwnd to an X window */
75 XContext winContext
= 0;
77 /* X context to associate a struct x11drv_win_data to an hwnd */
78 static XContext win_data_context
;
80 /* time of last user event and window where it's stored */
81 static Time last_user_time
;
82 static Window user_time_window
;
84 static const char foreign_window_prop
[] = "__wine_x11_foreign_window";
85 static const char whole_window_prop
[] = "__wine_x11_whole_window";
86 static const char client_window_prop
[]= "__wine_x11_client_window";
87 static const char icon_window_prop
[] = "__wine_x11_icon_window";
88 static const char clip_window_prop
[] = "__wine_x11_clip_window";
89 static const char fbconfig_id_prop
[] = "__wine_x11_fbconfig_id";
90 static const char gl_drawable_prop
[] = "__wine_x11_gl_drawable";
91 static const char pixmap_prop
[] = "__wine_x11_pixmap";
92 static const char managed_prop
[] = "__wine_x11_managed";
95 /***********************************************************************
96 * http://standards.freedesktop.org/startup-notification-spec
98 static void remove_startup_notification(Display
*display
, Window window
)
100 static LONG startup_notification_removed
= 0;
109 if (InterlockedCompareExchange(&startup_notification_removed
, 1, 0) != 0)
112 if (GetEnvironmentVariableA("DESKTOP_STARTUP_ID", id
, sizeof(id
)) == 0)
114 SetEnvironmentVariableA("DESKTOP_STARTUP_ID", NULL
);
116 if ((src
= strstr( id
, "_TIME" ))) update_user_time( atol( src
+ 5 ));
118 pos
= snprintf(message
, sizeof(message
), "remove: ID=");
119 message
[pos
++] = '"';
120 for (i
= 0; id
[i
] && pos
< sizeof(message
) - 2; i
++)
122 if (id
[i
] == '"' || id
[i
] == '\\')
123 message
[pos
++] = '\\';
124 message
[pos
++] = id
[i
];
126 message
[pos
++] = '"';
127 message
[pos
++] = '\0';
129 xevent
.xclient
.type
= ClientMessage
;
130 xevent
.xclient
.message_type
= x11drv_atom(_NET_STARTUP_INFO_BEGIN
);
131 xevent
.xclient
.display
= display
;
132 xevent
.xclient
.window
= window
;
133 xevent
.xclient
.format
= 8;
136 srclen
= strlen(src
) + 1;
144 memset(&xevent
.xclient
.data
.b
[0], 0, 20);
145 memcpy(&xevent
.xclient
.data
.b
[0], src
, msglen
);
149 XSendEvent( display
, DefaultRootWindow( display
), False
, PropertyChangeMask
, &xevent
);
150 xevent
.xclient
.message_type
= x11drv_atom(_NET_STARTUP_INFO
);
156 struct has_popup_result
162 static BOOL CALLBACK
has_managed_popup( HWND hwnd
, LPARAM lparam
)
164 struct has_popup_result
*result
= (struct has_popup_result
*)lparam
;
165 struct x11drv_win_data
*data
;
167 if (hwnd
== result
->hwnd
) return FALSE
; /* popups are always above owner */
168 if (!(data
= X11DRV_get_win_data( hwnd
))) return TRUE
;
169 if (GetWindow( hwnd
, GW_OWNER
) != result
->hwnd
) return TRUE
;
170 result
->found
= data
->managed
;
171 return !result
->found
;
174 static BOOL
has_owned_popups( HWND hwnd
)
176 struct has_popup_result result
;
179 result
.found
= FALSE
;
180 EnumWindows( has_managed_popup
, (LPARAM
)&result
);
184 /***********************************************************************
187 * Check if a given window should be managed
189 static BOOL
is_window_managed( HWND hwnd
, UINT swp_flags
, const RECT
*window_rect
)
191 DWORD style
, ex_style
;
193 if (!managed_mode
) return FALSE
;
195 /* child windows are not managed */
196 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
197 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) return FALSE
;
198 /* activated windows are managed */
199 if (!(swp_flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
))) return TRUE
;
200 if (hwnd
== GetActiveWindow()) return TRUE
;
201 /* windows with caption are managed */
202 if ((style
& WS_CAPTION
) == WS_CAPTION
) return TRUE
;
203 /* windows with thick frame are managed */
204 if (style
& WS_THICKFRAME
) return TRUE
;
205 if (style
& WS_POPUP
)
210 /* popup with sysmenu == caption are managed */
211 if (style
& WS_SYSMENU
) return TRUE
;
212 /* full-screen popup windows are managed */
213 hmon
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
);
214 mi
.cbSize
= sizeof( mi
);
215 GetMonitorInfoW( hmon
, &mi
);
216 if (window_rect
->left
<= mi
.rcWork
.left
&& window_rect
->right
>= mi
.rcWork
.right
&&
217 window_rect
->top
<= mi
.rcWork
.top
&& window_rect
->bottom
>= mi
.rcWork
.bottom
)
220 /* application windows are managed */
221 ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
222 if (ex_style
& WS_EX_APPWINDOW
) return TRUE
;
223 /* windows that own popups are managed */
224 if (has_owned_popups( hwnd
)) return TRUE
;
225 /* default: not managed */
230 /***********************************************************************
231 * is_window_resizable
233 * Check if window should be made resizable by the window manager
235 static inline BOOL
is_window_resizable( struct x11drv_win_data
*data
, DWORD style
)
237 if (style
& WS_THICKFRAME
) return TRUE
;
238 /* Metacity needs the window to be resizable to make it fullscreen */
239 return is_window_rect_fullscreen( &data
->whole_rect
);
243 /***********************************************************************
244 * get_mwm_decorations
246 static unsigned long get_mwm_decorations( struct x11drv_win_data
*data
,
247 DWORD style
, DWORD ex_style
)
249 unsigned long ret
= 0;
251 if (!decorated_mode
) return 0;
253 if (IsRectEmpty( &data
->window_rect
)) return 0;
254 if (data
->shaped
) return 0;
256 if (ex_style
& WS_EX_TOOLWINDOW
) return 0;
258 if ((style
& WS_CAPTION
) == WS_CAPTION
)
260 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
261 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
262 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
263 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
265 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
266 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
267 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
272 /***********************************************************************
273 * get_x11_rect_offset
275 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
277 static void get_x11_rect_offset( struct x11drv_win_data
*data
, RECT
*rect
)
279 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
282 rect
->top
= rect
->bottom
= rect
->left
= rect
->right
= 0;
284 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
285 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
286 decor
= get_mwm_decorations( data
, style
, ex_style
);
288 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
289 if (decor
& MWM_DECOR_BORDER
)
291 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
292 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
295 AdjustWindowRectEx( rect
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
299 /***********************************************************************
300 * get_window_attributes
302 * Fill the window attributes structure for an X window.
304 static int get_window_attributes( Display
*display
, struct x11drv_win_data
*data
,
305 XSetWindowAttributes
*attr
)
307 attr
->override_redirect
= !data
->managed
;
308 attr
->colormap
= X11DRV_PALETTE_PaletteXColormap
;
309 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
310 attr
->bit_gravity
= NorthWestGravity
;
311 attr
->win_gravity
= StaticGravity
;
312 attr
->backing_store
= NotUseful
;
313 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
314 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
315 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
|
316 KeymapStateMask
| StructureNotifyMask
);
317 if (data
->managed
) attr
->event_mask
|= PropertyChangeMask
;
319 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
|
320 CWEventMask
| CWBitGravity
| CWBackingStore
);
324 /***********************************************************************
325 * create_client_window
327 static Window
create_client_window( Display
*display
, struct x11drv_win_data
*data
, XVisualInfo
*vis
)
330 XSetWindowAttributes attr
;
332 Visual
*client_visual
= vis
? vis
->visual
: visual
;
334 attr
.bit_gravity
= NorthWestGravity
;
335 attr
.win_gravity
= NorthWestGravity
;
336 attr
.backing_store
= NotUseful
;
337 attr
.event_mask
= (ExposureMask
| PointerMotionMask
|
338 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
339 mask
= CWEventMask
| CWBitGravity
| CWWinGravity
| CWBackingStore
;
341 if ((cx
= data
->client_rect
.right
- data
->client_rect
.left
) <= 0) cx
= 1;
342 else if (cx
> 65535) cx
= 65535;
343 if ((cy
= data
->client_rect
.bottom
- data
->client_rect
.top
) <= 0) cy
= 1;
344 else if (cy
> 65535) cy
= 65535;
350 attr
.colormap
= XCreateColormap( display
, root_window
, vis
->visual
,
351 (vis
->class == PseudoColor
|| vis
->class == GrayScale
||
352 vis
->class == DirectColor
) ? AllocAll
: AllocNone
);
356 client
= XCreateWindow( display
, data
->whole_window
,
357 data
->client_rect
.left
- data
->whole_rect
.left
,
358 data
->client_rect
.top
- data
->whole_rect
.top
,
359 cx
, cy
, 0, screen_depth
, InputOutput
,
360 client_visual
, mask
, &attr
);
367 if (data
->client_window
)
369 XDeleteContext( display
, data
->client_window
, winContext
);
370 XDestroyWindow( display
, data
->client_window
);
372 data
->client_window
= client
;
373 data
->visualid
= XVisualIDFromVisual( client_visual
);
375 if (data
->colormap
) XFreeColormap( display
, data
->colormap
);
376 data
->colormap
= vis
? attr
.colormap
: 0;
378 XMapWindow( display
, data
->client_window
);
379 XSaveContext( display
, data
->client_window
, winContext
, (char *)data
->hwnd
);
382 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)data
->client_window
);
383 return data
->client_window
;
387 /***********************************************************************
390 * Change the X window attributes when the window style has changed.
392 static void sync_window_style( Display
*display
, struct x11drv_win_data
*data
)
394 if (data
->whole_window
!= root_window
)
396 XSetWindowAttributes attr
;
397 int mask
= get_window_attributes( display
, data
, &attr
);
400 XChangeWindowAttributes( display
, data
->whole_window
, mask
, &attr
);
406 /***********************************************************************
409 * Update the X11 window region.
411 static void sync_window_region( Display
*display
, struct x11drv_win_data
*data
, HRGN win_region
)
413 #ifdef HAVE_LIBXSHAPE
414 HRGN hrgn
= win_region
;
416 if (!data
->whole_window
) return;
417 data
->shaped
= FALSE
;
419 if (IsRectEmpty( &data
->window_rect
)) /* set an empty shape */
421 static XRectangle empty_rect
;
423 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
, 0, 0,
424 &empty_rect
, 1, ShapeSet
, YXBanded
);
429 if (hrgn
== (HRGN
)1) /* hack: win_region == 1 means retrieve region from server */
431 if (!(hrgn
= CreateRectRgn( 0, 0, 0, 0 ))) return;
432 if (GetWindowRgn( data
->hwnd
, hrgn
) == ERROR
)
434 DeleteObject( hrgn
);
442 XShapeCombineMask( display
, data
->whole_window
, ShapeBounding
, 0, 0, None
, ShapeSet
);
447 RGNDATA
*pRegionData
;
449 if (GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) MirrorRgn( data
->hwnd
, hrgn
);
450 if ((pRegionData
= X11DRV_GetRegionData( hrgn
, 0 )))
453 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
454 data
->window_rect
.left
- data
->whole_rect
.left
,
455 data
->window_rect
.top
- data
->whole_rect
.top
,
456 (XRectangle
*)pRegionData
->Buffer
,
457 pRegionData
->rdh
.nCount
, ShapeSet
, YXBanded
);
459 HeapFree(GetProcessHeap(), 0, pRegionData
);
463 if (hrgn
&& hrgn
!= win_region
) DeleteObject( hrgn
);
464 #endif /* HAVE_LIBXSHAPE */
468 /***********************************************************************
469 * sync_window_opacity
471 static void sync_window_opacity( Display
*display
, Window win
,
472 COLORREF key
, BYTE alpha
, DWORD flags
)
474 unsigned long opacity
= 0xffffffff;
476 if (flags
& LWA_ALPHA
) opacity
= (0xffffffff / 0xff) * alpha
;
478 if (flags
& LWA_COLORKEY
) FIXME("LWA_COLORKEY not supported\n");
481 if (opacity
== 0xffffffff)
482 XDeleteProperty( display
, win
, x11drv_atom(_NET_WM_WINDOW_OPACITY
) );
484 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_WINDOW_OPACITY
),
485 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&opacity
, 1 );
490 /***********************************************************************
493 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
496 char *buffer
, *utf8_buffer
;
499 /* allocate new buffer for window text */
500 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
501 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
502 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
504 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
505 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
507 HeapFree( GetProcessHeap(), 0, buffer
);
510 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
513 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
515 XSetWMName( display
, win
, &prop
);
516 XSetWMIconName( display
, win
, &prop
);
520 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
521 according to the standard
522 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
524 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
525 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
528 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
529 HeapFree( GetProcessHeap(), 0, buffer
);
533 /***********************************************************************
536 static BOOL
set_win_format( HWND hwnd
, XID fbconfig_id
)
538 struct x11drv_win_data
*data
;
542 if (!(data
= X11DRV_get_win_data(hwnd
)) &&
543 !(data
= X11DRV_create_win_data(hwnd
))) return FALSE
;
545 if (!(vis
= visual_from_fbconfig_id(fbconfig_id
))) return FALSE
;
547 if (data
->whole_window
)
549 Display
*display
= thread_display();
550 Window client
= data
->client_window
;
552 if (vis
->visualid
!= data
->visualid
)
554 client
= create_client_window( display
, data
, vis
);
555 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client
, data
->hwnd
, fbconfig_id
);
561 if (client
) goto done
;
565 w
= data
->client_rect
.right
- data
->client_rect
.left
;
566 h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
571 #ifdef SONAME_LIBXCOMPOSITE
574 XSetWindowAttributes attrib
;
575 static Window dummy_parent
;
578 attrib
.override_redirect
= True
;
581 dummy_parent
= XCreateWindow( gdi_display
, root_window
, -1, -1, 1, 1, 0, screen_depth
,
582 InputOutput
, visual
, CWOverrideRedirect
, &attrib
);
583 XMapWindow( gdi_display
, dummy_parent
);
585 data
->colormap
= XCreateColormap(gdi_display
, dummy_parent
, vis
->visual
,
586 (vis
->class == PseudoColor
||
587 vis
->class == GrayScale
||
588 vis
->class == DirectColor
) ?
589 AllocAll
: AllocNone
);
590 attrib
.colormap
= data
->colormap
;
591 XInstallColormap(gdi_display
, attrib
.colormap
);
593 if(data
->gl_drawable
) XDestroyWindow(gdi_display
, data
->gl_drawable
);
594 data
->gl_drawable
= XCreateWindow(gdi_display
, dummy_parent
, -w
, 0, w
, h
, 0,
595 vis
->depth
, InputOutput
, vis
->visual
,
596 CWColormap
| CWOverrideRedirect
,
598 if(data
->gl_drawable
)
600 pXCompositeRedirectWindow(gdi_display
, data
->gl_drawable
,
601 CompositeRedirectManual
);
602 XMapWindow(gdi_display
, data
->gl_drawable
);
605 XFlush( gdi_display
);
611 WARN("XComposite is not available, using GLXPixmap hack\n");
615 if(data
->pixmap
) XFreePixmap(gdi_display
, data
->pixmap
);
616 data
->pixmap
= XCreatePixmap(gdi_display
, root_window
, w
, h
, vis
->depth
);
624 if(data
->gl_drawable
) destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
625 data
->gl_drawable
= create_glxpixmap(gdi_display
, vis
, data
->pixmap
);
626 if(!data
->gl_drawable
)
628 XFreePixmap(gdi_display
, data
->pixmap
);
632 XFlush( gdi_display
);
634 if (data
->pixmap
) SetPropA(hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
637 if (!data
->gl_drawable
) return FALSE
;
639 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
640 data
->gl_drawable
, fbconfig_id
);
641 SetPropA(hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
644 data
->fbconfig_id
= fbconfig_id
;
645 SetPropA(hwnd
, fbconfig_id_prop
, (HANDLE
)data
->fbconfig_id
);
646 /* force DCE invalidation */
647 SetWindowPos( hwnd
, 0, 0, 0, 0, 0,
648 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOMOVE
|
649 SWP_NOREDRAW
| SWP_DEFERERASE
| SWP_NOSENDCHANGING
| SWP_STATECHANGED
);
653 /***********************************************************************
656 static void sync_gl_drawable(struct x11drv_win_data
*data
)
658 int w
= data
->client_rect
.right
- data
->client_rect
.left
;
659 int h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
667 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
668 #ifdef SONAME_LIBXCOMPOSITE
672 XMoveResizeWindow(gdi_display
, data
->gl_drawable
, -w
, 0, w
, h
);
678 if (!(vis
= visual_from_fbconfig_id(data
->fbconfig_id
))) return;
681 pix
= XCreatePixmap(gdi_display
, root_window
, w
, h
, vis
->depth
);
684 ERR("Failed to create pixmap for offscreen rendering\n");
690 glxp
= create_glxpixmap(gdi_display
, vis
, pix
);
693 ERR("Failed to create drawable for offscreen rendering\n");
694 XFreePixmap(gdi_display
, pix
);
702 mark_drawable_dirty(data
->gl_drawable
, glxp
);
704 XFreePixmap(gdi_display
, data
->pixmap
);
705 destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
706 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp
, data
->gl_drawable
);
709 data
->gl_drawable
= glxp
;
711 XFlush( gdi_display
);
714 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
715 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
719 /***********************************************************************
722 * fill the window changes structure
724 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
728 if (old
->right
- old
->left
!= new->right
- new->left
)
730 if ((changes
->width
= new->right
- new->left
) <= 0) changes
->width
= 1;
731 else if (changes
->width
> 65535) changes
->width
= 65535;
734 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
736 if ((changes
->height
= new->bottom
- new->top
) <= 0) changes
->height
= 1;
737 else if (changes
->height
> 65535) changes
->height
= 65535;
740 if (old
->left
!= new->left
)
742 changes
->x
= new->left
;
745 if (old
->top
!= new->top
)
747 changes
->y
= new->top
;
754 /***********************************************************************
757 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
759 XSetWindowAttributes attr
;
761 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
762 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
763 attr
.bit_gravity
= NorthWestGravity
;
764 attr
.backing_store
= NotUseful
/*WhenMapped*/;
765 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
768 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
769 GetSystemMetrics( SM_CXICON
),
770 GetSystemMetrics( SM_CYICON
),
773 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
774 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
775 XFlush( display
); /* make sure the window exists before we start painting to it */
778 TRACE( "created %lx\n", data
->icon_window
);
779 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
780 return data
->icon_window
;
785 /***********************************************************************
786 * destroy_icon_window
788 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
790 if (!data
->icon_window
) return;
792 XDeleteContext( display
, data
->icon_window
, winContext
);
793 XDestroyWindow( display
, data
->icon_window
);
794 data
->icon_window
= 0;
796 RemovePropA( data
->hwnd
, icon_window_prop
);
800 /***********************************************************************
803 * Return the bitmap bits in ARGB format. Helper for setting icon hints.
805 static unsigned long *get_bitmap_argb( HDC hdc
, HBITMAP color
, HBITMAP mask
, unsigned int *size
)
809 unsigned int *ptr
, *bits
= NULL
;
810 unsigned char *mask_bits
= NULL
;
811 int i
, j
, has_alpha
= 0;
813 if (!GetObjectW( color
, sizeof(bm
), &bm
)) return NULL
;
814 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) return NULL
;
815 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
816 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
817 info
->bmiHeader
.biHeight
= -bm
.bmHeight
;
818 info
->bmiHeader
.biPlanes
= 1;
819 info
->bmiHeader
.biBitCount
= 32;
820 info
->bmiHeader
.biCompression
= BI_RGB
;
821 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* bm
.bmHeight
* 4;
822 info
->bmiHeader
.biXPelsPerMeter
= 0;
823 info
->bmiHeader
.biYPelsPerMeter
= 0;
824 info
->bmiHeader
.biClrUsed
= 0;
825 info
->bmiHeader
.biClrImportant
= 0;
826 *size
= bm
.bmWidth
* bm
.bmHeight
+ 2;
827 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, *size
* sizeof(long) ))) goto failed
;
828 if (!GetDIBits( hdc
, color
, 0, bm
.bmHeight
, bits
+ 2, info
, DIB_RGB_COLORS
)) goto failed
;
830 bits
[0] = bm
.bmWidth
;
831 bits
[1] = bm
.bmHeight
;
833 for (i
= 0; i
< bm
.bmWidth
* bm
.bmHeight
; i
++)
834 if ((has_alpha
= (bits
[i
+ 2] & 0xff000000) != 0)) break;
838 unsigned int width_bytes
= (bm
.bmWidth
+ 31) / 32 * 4;
839 /* generate alpha channel from the mask */
840 info
->bmiHeader
.biBitCount
= 1;
841 info
->bmiHeader
.biSizeImage
= width_bytes
* bm
.bmHeight
;
842 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto failed
;
843 if (!GetDIBits( hdc
, mask
, 0, bm
.bmHeight
, mask_bits
, info
, DIB_RGB_COLORS
)) goto failed
;
845 for (i
= 0; i
< bm
.bmHeight
; i
++)
846 for (j
= 0; j
< bm
.bmWidth
; j
++, ptr
++)
847 if (!((mask_bits
[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80)) *ptr
|= 0xff000000;
848 HeapFree( GetProcessHeap(), 0, mask_bits
);
850 HeapFree( GetProcessHeap(), 0, info
);
852 /* convert to array of longs */
853 if (bits
&& sizeof(long) > sizeof(int))
854 for (i
= *size
- 1; i
>= 0; i
--) ((unsigned long *)bits
)[i
] = bits
[i
];
856 return (unsigned long *)bits
;
859 HeapFree( GetProcessHeap(), 0, info
);
860 HeapFree( GetProcessHeap(), 0, bits
);
861 HeapFree( GetProcessHeap(), 0, mask_bits
);
866 /***********************************************************************
869 * Set the icon wm hints
871 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
,
872 HICON icon_big
, HICON icon_small
)
874 XWMHints
*hints
= data
->wm_hints
;
878 icon_big
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_BIG
, 0 );
879 if (!icon_big
) icon_big
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
);
883 icon_small
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
884 if (!icon_small
) icon_small
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICONSM
);
887 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
888 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
889 data
->hWMIconBitmap
= 0;
890 data
->hWMIconMask
= 0;
894 if (!data
->icon_window
) create_icon_window( display
, data
);
895 hints
->icon_window
= data
->icon_window
;
896 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
903 ICONINFO ii
, ii_small
;
908 if (!GetIconInfo(icon_big
, &ii
)) return;
910 GetObjectW(ii
.hbmMask
, sizeof(bm
), &bm
);
913 rcMask
.right
= bm
.bmWidth
;
914 rcMask
.bottom
= bm
.bmHeight
;
916 hDC
= CreateCompatibleDC(0);
917 bits
= get_bitmap_argb( hDC
, ii
.hbmColor
, ii
.hbmMask
, &size
);
918 if (bits
&& GetIconInfo( icon_small
, &ii_small
))
920 unsigned int size_small
;
921 unsigned long *bits_small
, *new;
923 if ((bits_small
= get_bitmap_argb( hDC
, ii_small
.hbmColor
, ii_small
.hbmMask
, &size_small
)) &&
924 (bits_small
[0] != bits
[0] || bits_small
[1] != bits
[1])) /* size must be different */
926 if ((new = HeapReAlloc( GetProcessHeap(), 0, bits
,
927 (size
+ size_small
) * sizeof(unsigned long) )))
930 memcpy( bits
+ size
, bits_small
, size_small
* sizeof(unsigned long) );
934 HeapFree( GetProcessHeap(), 0, bits_small
);
935 DeleteObject( ii_small
.hbmColor
);
936 DeleteObject( ii_small
.hbmMask
);
940 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_ICON
),
941 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)bits
, size
);
943 XDeleteProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_ICON
) );
945 HeapFree( GetProcessHeap(), 0, bits
);
947 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
948 InvertRect(hDC
, &rcMask
);
949 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
950 SelectObject(hDC
, hbmOrig
);
952 data
->hWMIconBitmap
= ii
.hbmColor
;
953 data
->hWMIconMask
= ii
.hbmMask
;
955 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
956 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
957 destroy_icon_window( display
, data
);
958 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
965 /***********************************************************************
968 * set the window size hints
970 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
972 XSizeHints
* size_hints
;
974 if (!(size_hints
= XAllocSizeHints())) return;
976 size_hints
->win_gravity
= StaticGravity
;
977 size_hints
->flags
|= PWinGravity
;
979 /* don't update size hints if window is not in normal state */
980 if (!(style
& (WS_MINIMIZE
| WS_MAXIMIZE
)))
982 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
984 size_hints
->x
= data
->whole_rect
.left
;
985 size_hints
->y
= data
->whole_rect
.top
;
986 size_hints
->flags
|= PPosition
;
988 else size_hints
->win_gravity
= NorthWestGravity
;
990 if (!is_window_resizable( data
, style
))
992 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
993 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
994 if (size_hints
->max_width
<= 0 ||size_hints
->max_height
<= 0)
995 size_hints
->max_width
= size_hints
->max_height
= 1;
996 size_hints
->min_width
= size_hints
->max_width
;
997 size_hints
->min_height
= size_hints
->max_height
;
998 size_hints
->flags
|= PMinSize
| PMaxSize
;
1001 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
1002 XFree( size_hints
);
1006 /***********************************************************************
1009 static void set_mwm_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
, DWORD ex_style
)
1013 if (data
->hwnd
== GetDesktopWindow())
1015 mwm_hints
.decorations
= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
| MWM_DECOR_MENU
| MWM_DECOR_MINIMIZE
;
1016 mwm_hints
.functions
= MWM_FUNC_MOVE
| MWM_FUNC_MINIMIZE
| MWM_FUNC_CLOSE
;
1020 mwm_hints
.decorations
= get_mwm_decorations( data
, style
, ex_style
);
1021 mwm_hints
.functions
= MWM_FUNC_MOVE
;
1022 if (is_window_resizable( data
, style
)) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
1023 if (!(style
& WS_DISABLED
))
1025 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
1026 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
1027 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
1031 TRACE( "%p setting mwm hints to %lx,%lx (style %x exstyle %x)\n",
1032 data
->hwnd
, mwm_hints
.decorations
, mwm_hints
.functions
, style
, ex_style
);
1034 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
1035 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
1036 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
1037 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
1041 /***********************************************************************
1044 * get the name of the current process for setting class hints
1046 static char *get_process_name(void)
1052 WCHAR module
[MAX_PATH
];
1053 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
1054 if (len
&& len
< MAX_PATH
)
1057 WCHAR
*p
, *appname
= module
;
1059 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
1060 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
1061 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
1062 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
1064 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
1073 /***********************************************************************
1074 * set_initial_wm_hints
1076 * Set the window manager hints that don't change over the lifetime of a window.
1078 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
1082 Atom dndVersion
= WINE_XDND_VERSION
;
1083 XClassHint
*class_hints
;
1084 char *process_name
= get_process_name();
1090 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
1091 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
1092 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
1093 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
1094 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
1097 if ((class_hints
= XAllocClassHint()))
1099 static char wine
[] = "Wine";
1101 class_hints
->res_name
= process_name
;
1102 class_hints
->res_class
= wine
;
1103 XSetClassHint( display
, data
->whole_window
, class_hints
);
1104 XFree( class_hints
);
1107 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
1108 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
1109 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
1111 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
1112 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
1114 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
1115 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
1117 update_user_time( 0 ); /* make sure that the user time window exists */
1118 if (user_time_window
)
1119 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_USER_TIME_WINDOW
),
1120 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&user_time_window
, 1 );
1122 data
->wm_hints
= XAllocWMHints();
1123 wine_tsx11_unlock();
1127 data
->wm_hints
->flags
= 0;
1128 set_icon_hints( display
, data
, 0, 0 );
1133 /***********************************************************************
1134 * get_owner_whole_window
1136 * Retrieve an owner's window, creating it if necessary.
1138 static Window
get_owner_whole_window( HWND owner
, BOOL force_managed
)
1140 struct x11drv_win_data
*data
;
1142 if (!owner
) return 0;
1144 if (!(data
= X11DRV_get_win_data( owner
)))
1146 if (GetWindowThreadProcessId( owner
, NULL
) != GetCurrentThreadId() ||
1147 !(data
= X11DRV_create_win_data( owner
)))
1148 return (Window
)GetPropA( owner
, whole_window_prop
);
1150 else if (!data
->managed
&& force_managed
) /* make it managed */
1152 SetWindowPos( owner
, 0, 0, 0, 0, 0,
1153 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOMOVE
|
1154 SWP_NOREDRAW
| SWP_DEFERERASE
| SWP_NOSENDCHANGING
| SWP_STATECHANGED
);
1156 return data
->whole_window
;
1160 /***********************************************************************
1163 * Set the window manager hints for a newly-created window
1165 static void set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
1167 Window group_leader
= data
->whole_window
;
1168 Window owner_win
= 0;
1170 DWORD style
, ex_style
;
1173 if (data
->hwnd
== GetDesktopWindow())
1175 /* force some styles for the desktop to get the correct decorations */
1176 style
= WS_POPUP
| WS_VISIBLE
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
1177 ex_style
= WS_EX_APPWINDOW
;
1182 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1183 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
1184 owner
= GetWindow( data
->hwnd
, GW_OWNER
);
1185 if ((owner_win
= get_owner_whole_window( owner
, data
->managed
))) group_leader
= owner_win
;
1190 if (owner_win
) XSetTransientForHint( display
, data
->whole_window
, owner_win
);
1193 set_size_hints( display
, data
, style
);
1194 set_mwm_hints( display
, data
, style
, ex_style
);
1196 /* Only use dialog type for owned popups. Metacity allows making fullscreen
1197 * only normal windows, and doesn't handle correctly TRANSIENT_FOR hint for
1198 * dialogs owned by fullscreen windows.
1200 if ((style
& WS_POPUP
) && owner
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
1201 else window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
1203 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
1204 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
1209 data
->wm_hints
->flags
|= InputHint
| StateHint
| WindowGroupHint
;
1210 data
->wm_hints
->input
= !use_take_focus
&& !(style
& WS_DISABLED
);
1211 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
1212 data
->wm_hints
->window_group
= group_leader
;
1213 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
1216 wine_tsx11_unlock();
1220 /***********************************************************************
1223 Window
init_clip_window(void)
1225 struct x11drv_thread_data
*data
= x11drv_init_thread_data();
1227 if (!data
->clip_window
&&
1228 (data
->clip_window
= (Window
)GetPropA( GetDesktopWindow(), clip_window_prop
)))
1231 XSelectInput( data
->display
, data
->clip_window
, StructureNotifyMask
);
1232 wine_tsx11_unlock();
1234 return data
->clip_window
;
1238 /***********************************************************************
1241 void update_user_time( Time time
)
1244 if (!user_time_window
)
1246 user_time_window
= XCreateWindow( gdi_display
, root_window
, -1, -1, 1, 1, 0, 0, InputOnly
,
1247 DefaultVisual(gdi_display
,DefaultScreen(gdi_display
)), 0, NULL
);
1248 TRACE( "user time window %lx\n", user_time_window
);
1250 if (time
&& (!last_user_time
|| (long)(time
- last_user_time
) > 0))
1252 last_user_time
= time
;
1253 XChangeProperty( gdi_display
, user_time_window
, x11drv_atom(_NET_WM_USER_TIME
),
1254 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&time
, 1 );
1256 wine_tsx11_unlock();
1259 /***********************************************************************
1260 * update_net_wm_states
1262 void update_net_wm_states( Display
*display
, struct x11drv_win_data
*data
)
1264 static const unsigned int state_atoms
[NB_NET_WM_STATES
] =
1266 XATOM__NET_WM_STATE_FULLSCREEN
,
1267 XATOM__NET_WM_STATE_ABOVE
,
1268 XATOM__NET_WM_STATE_MAXIMIZED_VERT
,
1269 XATOM__NET_WM_STATE_SKIP_PAGER
,
1270 XATOM__NET_WM_STATE_SKIP_TASKBAR
1273 DWORD i
, style
, ex_style
, new_state
= 0;
1275 if (!data
->managed
) return;
1276 if (data
->whole_window
== root_window
) return;
1278 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1279 if (is_window_rect_fullscreen( &data
->whole_rect
))
1281 if ((style
& WS_MAXIMIZE
) && (style
& WS_CAPTION
) == WS_CAPTION
)
1282 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
1283 else if (!(style
& WS_MINIMIZE
))
1284 new_state
|= (1 << NET_WM_STATE_FULLSCREEN
);
1286 else if (style
& WS_MAXIMIZE
)
1287 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
1289 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
1290 if (ex_style
& WS_EX_TOPMOST
)
1291 new_state
|= (1 << NET_WM_STATE_ABOVE
);
1292 if (ex_style
& (WS_EX_TOOLWINDOW
| WS_EX_NOACTIVATE
))
1293 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
) | (1 << NET_WM_STATE_SKIP_PAGER
);
1294 if (!(ex_style
& WS_EX_APPWINDOW
) && GetWindow( data
->hwnd
, GW_OWNER
))
1295 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
);
1297 if (!data
->mapped
) /* set the _NET_WM_STATE atom directly */
1299 Atom atoms
[NB_NET_WM_STATES
+1];
1302 for (i
= count
= 0; i
< NB_NET_WM_STATES
; i
++)
1304 if (!(new_state
& (1 << i
))) continue;
1305 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
1306 i
, data
->hwnd
, data
->whole_window
);
1307 atoms
[count
++] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
1308 if (state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
)
1309 atoms
[count
++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
);
1312 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_STATE
), XA_ATOM
,
1313 32, PropModeReplace
, (unsigned char *)atoms
, count
);
1314 wine_tsx11_unlock();
1316 else /* ask the window manager to do it for us */
1320 xev
.xclient
.type
= ClientMessage
;
1321 xev
.xclient
.window
= data
->whole_window
;
1322 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
1323 xev
.xclient
.serial
= 0;
1324 xev
.xclient
.display
= display
;
1325 xev
.xclient
.send_event
= True
;
1326 xev
.xclient
.format
= 32;
1327 xev
.xclient
.data
.l
[3] = 1;
1329 for (i
= 0; i
< NB_NET_WM_STATES
; i
++)
1331 if (!((data
->net_wm_state
^ new_state
) & (1 << i
))) continue; /* unchanged */
1333 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1334 i
, data
->hwnd
, data
->whole_window
,
1335 (new_state
& (1 << i
)) != 0, (data
->net_wm_state
& (1 << i
)) != 0 );
1337 xev
.xclient
.data
.l
[0] = (new_state
& (1 << i
)) ? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
1338 xev
.xclient
.data
.l
[1] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
1339 xev
.xclient
.data
.l
[2] = ((state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
) ?
1340 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
) : 0);
1342 XSendEvent( display
, root_window
, False
,
1343 SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
1344 wine_tsx11_unlock();
1347 data
->net_wm_state
= new_state
;
1351 /***********************************************************************
1354 static void set_xembed_flags( Display
*display
, struct x11drv_win_data
*data
, unsigned long flags
)
1356 unsigned long info
[2];
1358 if (!data
->whole_window
) return;
1360 info
[0] = 0; /* protocol version */
1363 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_XEMBED_INFO
),
1364 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
, (unsigned char*)info
, 2 );
1365 wine_tsx11_unlock();
1369 /***********************************************************************
1372 static void map_window( Display
*display
, struct x11drv_win_data
*data
, DWORD new_style
)
1374 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1376 remove_startup_notification( display
, data
->whole_window
);
1378 wait_for_withdrawn_state( display
, data
, TRUE
);
1380 if (!data
->embedded
)
1382 update_net_wm_states( display
, data
);
1383 sync_window_style( display
, data
);
1385 XMapWindow( display
, data
->whole_window
);
1386 wine_tsx11_unlock();
1388 else set_xembed_flags( display
, data
, XEMBED_MAPPED
);
1390 data
->mapped
= TRUE
;
1391 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
1395 /***********************************************************************
1398 static void unmap_window( Display
*display
, struct x11drv_win_data
*data
)
1400 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1402 if (!data
->embedded
)
1404 wait_for_withdrawn_state( display
, data
, FALSE
);
1406 if (data
->managed
) XWithdrawWindow( display
, data
->whole_window
, DefaultScreen(display
) );
1407 else XUnmapWindow( display
, data
->whole_window
);
1408 wine_tsx11_unlock();
1410 else set_xembed_flags( display
, data
, 0 );
1412 data
->mapped
= FALSE
;
1413 data
->net_wm_state
= 0;
1417 /***********************************************************************
1418 * make_window_embedded
1420 void make_window_embedded( Display
*display
, struct x11drv_win_data
*data
)
1422 BOOL was_mapped
= data
->mapped
;
1423 /* the window cannot be mapped before being embedded */
1424 if (data
->mapped
) unmap_window( display
, data
);
1426 data
->embedded
= TRUE
;
1427 data
->managed
= TRUE
;
1428 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1429 sync_window_style( display
, data
);
1432 map_window( display
, data
, 0 );
1434 set_xembed_flags( display
, data
, 0 );
1438 /***********************************************************************
1439 * X11DRV_window_to_X_rect
1441 * Convert a rect from client to X window coordinates
1443 static void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1447 if (!data
->managed
) return;
1448 if (IsRectEmpty( rect
)) return;
1450 get_x11_rect_offset( data
, &rc
);
1452 rect
->left
-= rc
.left
;
1453 rect
->right
-= rc
.right
;
1454 rect
->top
-= rc
.top
;
1455 rect
->bottom
-= rc
.bottom
;
1456 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1457 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1461 /***********************************************************************
1462 * X11DRV_X_to_window_rect
1464 * Opposite of X11DRV_window_to_X_rect
1466 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1470 if (!data
->managed
) return;
1471 if (IsRectEmpty( rect
)) return;
1473 get_x11_rect_offset( data
, &rc
);
1475 rect
->left
+= rc
.left
;
1476 rect
->right
+= rc
.right
;
1477 rect
->top
+= rc
.top
;
1478 rect
->bottom
+= rc
.bottom
;
1479 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1480 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1484 /***********************************************************************
1485 * sync_window_position
1487 * Synchronize the X window position with the Windows one
1489 static void sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
1490 UINT swp_flags
, const RECT
*old_window_rect
,
1491 const RECT
*old_whole_rect
, const RECT
*old_client_rect
)
1493 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1494 DWORD ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
1495 XWindowChanges changes
;
1496 unsigned int mask
= 0;
1498 if (data
->managed
&& data
->iconic
) return;
1500 /* resizing a managed maximized window is not allowed */
1501 if (!(style
& WS_MAXIMIZE
) || !data
->managed
)
1503 changes
.width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
1504 changes
.height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
1505 /* if window rect is empty force size to 1x1 */
1506 if (changes
.width
<= 0 || changes
.height
<= 0) changes
.width
= changes
.height
= 1;
1507 if (changes
.width
> 65535) changes
.width
= 65535;
1508 if (changes
.height
> 65535) changes
.height
= 65535;
1509 mask
|= CWWidth
| CWHeight
;
1512 /* only the size is allowed to change for the desktop window */
1513 if (data
->whole_window
!= root_window
)
1515 changes
.x
= data
->whole_rect
.left
- virtual_screen_rect
.left
;
1516 changes
.y
= data
->whole_rect
.top
- virtual_screen_rect
.top
;
1520 if (!(swp_flags
& SWP_NOZORDER
) || (swp_flags
& SWP_SHOWWINDOW
))
1522 /* find window that this one must be after */
1523 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
1524 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
1525 prev
= GetWindow( prev
, GW_HWNDPREV
);
1526 if (!prev
) /* top child */
1528 changes
.stack_mode
= Above
;
1529 mask
|= CWStackMode
;
1531 /* should use stack_mode Below but most window managers don't get it right */
1532 /* and Above with a sibling doesn't work so well either, so we ignore it */
1536 set_size_hints( display
, data
, style
);
1537 set_mwm_hints( display
, data
, style
, ex_style
);
1538 data
->configure_serial
= NextRequest( display
);
1539 XReconfigureWMWindow( display
, data
->whole_window
,
1540 DefaultScreen(display
), mask
, &changes
);
1541 wine_tsx11_unlock();
1542 #ifdef HAVE_LIBXSHAPE
1543 if (IsRectEmpty( old_window_rect
) != IsRectEmpty( &data
->window_rect
))
1544 sync_window_region( display
, data
, (HRGN
)1 );
1547 int old_x_offset
= old_window_rect
->left
- old_whole_rect
->left
;
1548 int old_y_offset
= old_window_rect
->top
- old_whole_rect
->top
;
1549 int new_x_offset
= data
->window_rect
.left
- data
->whole_rect
.left
;
1550 int new_y_offset
= data
->window_rect
.top
- data
->whole_rect
.top
;
1551 if (old_x_offset
!= new_x_offset
|| old_y_offset
!= new_y_offset
)
1554 XShapeOffsetShape( display
, data
->whole_window
, ShapeBounding
,
1555 new_x_offset
- old_x_offset
, new_y_offset
- old_y_offset
);
1556 wine_tsx11_unlock();
1561 TRACE( "win %p/%lx pos %d,%d,%dx%d after %lx changes=%x serial=%lu\n",
1562 data
->hwnd
, data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1563 data
->whole_rect
.right
- data
->whole_rect
.left
,
1564 data
->whole_rect
.bottom
- data
->whole_rect
.top
,
1565 changes
.sibling
, mask
, data
->configure_serial
);
1569 /***********************************************************************
1570 * sync_client_position
1572 * Synchronize the X client window position with the Windows one
1574 static void sync_client_position( Display
*display
, struct x11drv_win_data
*data
,
1575 UINT swp_flags
, const RECT
*old_client_rect
,
1576 const RECT
*old_whole_rect
)
1579 XWindowChanges changes
;
1580 RECT old
= *old_client_rect
;
1581 RECT
new = data
->client_rect
;
1583 OffsetRect( &old
, -old_whole_rect
->left
, -old_whole_rect
->top
);
1584 OffsetRect( &new, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
1585 if (!(mask
= get_window_changes( &changes
, &old
, &new ))) return;
1587 if (data
->client_window
)
1589 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1590 data
->client_window
, new.left
, new.top
,
1591 new.right
- new.left
, new.bottom
- new.top
, mask
);
1593 XConfigureWindow( display
, data
->client_window
, mask
, &changes
);
1594 wine_tsx11_unlock();
1597 if (data
->gl_drawable
&& (mask
& (CWWidth
|CWHeight
))) sync_gl_drawable( data
);
1601 /***********************************************************************
1604 * Move the window bits when a window is moved.
1606 static void move_window_bits( struct x11drv_win_data
*data
, const RECT
*old_rect
, const RECT
*new_rect
,
1607 const RECT
*old_client_rect
)
1609 RECT src_rect
= *old_rect
;
1610 RECT dst_rect
= *new_rect
;
1611 HDC hdc_src
, hdc_dst
;
1616 if (!data
->whole_window
)
1618 OffsetRect( &dst_rect
, -data
->window_rect
.left
, -data
->window_rect
.top
);
1619 parent
= GetAncestor( data
->hwnd
, GA_PARENT
);
1620 hdc_src
= GetDCEx( parent
, 0, DCX_CACHE
);
1621 hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
1625 OffsetRect( &dst_rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
1626 /* make src rect relative to the old position of the window */
1627 OffsetRect( &src_rect
, -old_client_rect
->left
, -old_client_rect
->top
);
1628 if (dst_rect
.left
== src_rect
.left
&& dst_rect
.top
== src_rect
.top
) return;
1629 hdc_src
= hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
);
1632 rgn
= CreateRectRgnIndirect( &dst_rect
);
1633 SelectClipRgn( hdc_dst
, rgn
);
1634 DeleteObject( rgn
);
1635 ExcludeUpdateRgn( hdc_dst
, data
->hwnd
);
1637 code
= X11DRV_START_EXPOSURES
;
1638 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
1640 TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n",
1641 data
->hwnd
, data
->whole_window
, data
->client_window
,
1642 wine_dbgstr_rect(&src_rect
), wine_dbgstr_rect(&dst_rect
) );
1643 BitBlt( hdc_dst
, dst_rect
.left
, dst_rect
.top
,
1644 dst_rect
.right
- dst_rect
.left
, dst_rect
.bottom
- dst_rect
.top
,
1645 hdc_src
, src_rect
.left
, src_rect
.top
, SRCCOPY
);
1648 code
= X11DRV_END_EXPOSURES
;
1649 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, sizeof(rgn
), (LPSTR
)&rgn
);
1651 ReleaseDC( data
->hwnd
, hdc_dst
);
1652 if (hdc_src
!= hdc_dst
) ReleaseDC( parent
, hdc_src
);
1656 if (!data
->whole_window
)
1658 /* map region to client rect since we are using DCX_WINDOW */
1659 OffsetRgn( rgn
, data
->window_rect
.left
- data
->client_rect
.left
,
1660 data
->window_rect
.top
- data
->client_rect
.top
);
1661 RedrawWindow( data
->hwnd
, NULL
, rgn
,
1662 RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
1664 else RedrawWindow( data
->hwnd
, NULL
, rgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1665 DeleteObject( rgn
);
1670 /**********************************************************************
1671 * create_whole_window
1673 * Create the whole X window for a given window
1675 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1678 XSetWindowAttributes attr
;
1682 DWORD layered_flags
;
1685 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1687 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1688 data
->managed
= TRUE
;
1689 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1692 if ((win_rgn
= CreateRectRgn( 0, 0, 0, 0 )) &&
1693 GetWindowRgn( data
->hwnd
, win_rgn
) == ERROR
)
1695 DeleteObject( win_rgn
);
1698 data
->shaped
= (win_rgn
!= 0);
1700 mask
= get_window_attributes( display
, data
, &attr
);
1702 data
->whole_rect
= data
->window_rect
;
1703 X11DRV_window_to_X_rect( data
, &data
->whole_rect
);
1704 if (!(cx
= data
->whole_rect
.right
- data
->whole_rect
.left
)) cx
= 1;
1705 else if (cx
> 65535) cx
= 65535;
1706 if (!(cy
= data
->whole_rect
.bottom
- data
->whole_rect
.top
)) cy
= 1;
1707 else if (cy
> 65535) cy
= 65535;
1710 data
->whole_window
= XCreateWindow( display
, root_window
,
1711 data
->whole_rect
.left
- virtual_screen_rect
.left
,
1712 data
->whole_rect
.top
- virtual_screen_rect
.top
,
1713 cx
, cy
, 0, screen_depth
, InputOutput
,
1714 visual
, mask
, &attr
);
1716 if (data
->whole_window
) XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1717 wine_tsx11_unlock();
1719 if (!data
->whole_window
) goto done
;
1721 if (!create_client_window( display
, data
, NULL
))
1724 XDeleteContext( display
, data
->whole_window
, winContext
);
1725 XDestroyWindow( display
, data
->whole_window
);
1726 data
->whole_window
= 0;
1727 wine_tsx11_unlock();
1731 set_initial_wm_hints( display
, data
);
1732 set_wm_hints( display
, data
);
1734 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1736 /* set the window text */
1737 if (!InternalGetWindowText( data
->hwnd
, text
, sizeof(text
)/sizeof(WCHAR
) )) text
[0] = 0;
1738 sync_window_text( display
, data
->whole_window
, text
);
1740 /* set the window region */
1741 if (win_rgn
|| IsRectEmpty( &data
->window_rect
)) sync_window_region( display
, data
, win_rgn
);
1743 /* set the window opacity */
1744 if (!GetLayeredWindowAttributes( data
->hwnd
, &key
, &alpha
, &layered_flags
)) layered_flags
= 0;
1745 sync_window_opacity( display
, data
->whole_window
, key
, alpha
, layered_flags
);
1747 init_clip_window(); /* make sure the clip window is initialized in this thread */
1750 XFlush( display
); /* make sure the window exists before we start painting to it */
1751 wine_tsx11_unlock();
1753 sync_window_cursor( data
->whole_window
);
1756 if (win_rgn
) DeleteObject( win_rgn
);
1757 return data
->whole_window
;
1761 /**********************************************************************
1762 * destroy_whole_window
1764 * Destroy the whole X window for a given window.
1766 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
, BOOL already_destroyed
)
1768 if (!data
->whole_window
)
1772 Window xwin
= (Window
)GetPropA( data
->hwnd
, foreign_window_prop
);
1776 if (!already_destroyed
) XSelectInput( display
, xwin
, 0 );
1777 XDeleteContext( display
, xwin
, winContext
);
1778 wine_tsx11_unlock();
1779 RemovePropA( data
->hwnd
, foreign_window_prop
);
1786 TRACE( "win %p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1788 XDeleteContext( display
, data
->whole_window
, winContext
);
1789 XDeleteContext( display
, data
->client_window
, winContext
);
1790 if (!already_destroyed
) XDestroyWindow( display
, data
->whole_window
);
1791 data
->whole_window
= data
->client_window
= 0;
1792 data
->wm_state
= WithdrawnState
;
1793 data
->net_wm_state
= 0;
1794 data
->mapped
= FALSE
;
1797 XUnsetICFocus( data
->xic
);
1798 XDestroyIC( data
->xic
);
1801 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1803 XFree( data
->wm_hints
);
1804 data
->wm_hints
= NULL
;
1805 wine_tsx11_unlock();
1806 RemovePropA( data
->hwnd
, whole_window_prop
);
1807 RemovePropA( data
->hwnd
, client_window_prop
);
1811 /*****************************************************************
1812 * SetWindowText (X11DRV.@)
1814 void CDECL
X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1818 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(gdi_display
))
1820 Display
*display
= thread_init_display();
1821 sync_window_text( display
, win
, text
);
1826 /***********************************************************************
1827 * SetWindowStyle (X11DRV.@)
1829 * Update the X state of a window to reflect a style change
1831 void CDECL
X11DRV_SetWindowStyle( HWND hwnd
, INT offset
, STYLESTRUCT
*style
)
1833 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1836 if (hwnd
== GetDesktopWindow()) return;
1837 changed
= style
->styleNew
^ style
->styleOld
;
1839 /* if WS_VISIBLE was set through WM_SETREDRAW, map the window if it's the first time */
1840 if (offset
== GWL_STYLE
&& (changed
& WS_VISIBLE
) && (style
->styleNew
& WS_VISIBLE
) && !data
)
1842 if (!(data
= X11DRV_create_win_data( hwnd
))) return;
1844 if (data
->whole_window
&& is_window_rect_mapped( &data
->window_rect
))
1846 Display
*display
= thread_display();
1847 set_wm_hints( display
, data
);
1848 if (!data
->mapped
) map_window( display
, data
, style
->styleNew
);
1851 if (!data
|| !data
->whole_window
) return;
1853 if (offset
== GWL_STYLE
&& (changed
& WS_DISABLED
))
1854 set_wm_hints( thread_display(), data
);
1856 if (offset
== GWL_EXSTYLE
&& (changed
& WS_EX_LAYERED
)) /* changing WS_EX_LAYERED resets attributes */
1857 sync_window_opacity( thread_display(), data
->whole_window
, 0, 0, 0 );
1861 /***********************************************************************
1862 * DestroyWindow (X11DRV.@)
1864 void CDECL
X11DRV_DestroyWindow( HWND hwnd
)
1866 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1867 struct x11drv_win_data
*data
;
1869 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1874 destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
1875 XFreePixmap(gdi_display
, data
->pixmap
);
1876 wine_tsx11_unlock();
1878 else if (data
->gl_drawable
)
1881 XDestroyWindow(gdi_display
, data
->gl_drawable
);
1882 wine_tsx11_unlock();
1885 destroy_whole_window( thread_data
->display
, data
, FALSE
);
1886 destroy_icon_window( thread_data
->display
, data
);
1891 XFreeColormap( thread_data
->display
, data
->colormap
);
1892 wine_tsx11_unlock();
1895 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1896 if (thread_data
->last_xic_hwnd
== hwnd
) thread_data
->last_xic_hwnd
= 0;
1897 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1898 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1900 XDeleteContext( thread_data
->display
, (XID
)hwnd
, win_data_context
);
1901 wine_tsx11_unlock();
1902 HeapFree( GetProcessHeap(), 0, data
);
1906 /***********************************************************************
1907 * X11DRV_DestroyNotify
1909 void X11DRV_DestroyNotify( HWND hwnd
, XEvent
*event
)
1911 Display
*display
= event
->xdestroywindow
.display
;
1912 struct x11drv_win_data
*data
;
1914 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1915 if (!data
->embedded
) FIXME( "window %p/%lx destroyed from the outside\n", hwnd
, data
->whole_window
);
1917 destroy_whole_window( display
, data
, TRUE
);
1918 if (data
->embedded
) SendMessageW( hwnd
, WM_CLOSE
, 0, 0 );
1922 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1924 struct x11drv_win_data
*data
;
1926 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
1930 if (!winContext
) winContext
= XUniqueContext();
1931 if (!win_data_context
) win_data_context
= XUniqueContext();
1932 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1933 wine_tsx11_unlock();
1939 /* initialize the desktop window id in the desktop manager process */
1940 static struct x11drv_win_data
*create_desktop_win_data( Display
*display
, HWND hwnd
)
1942 struct x11drv_win_data
*data
;
1944 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1945 data
->whole_window
= data
->client_window
= root_window
;
1946 data
->managed
= TRUE
;
1947 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1948 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1949 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)root_window
);
1950 set_initial_wm_hints( display
, data
);
1954 /**********************************************************************
1955 * CreateDesktopWindow (X11DRV.@)
1957 BOOL CDECL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1959 unsigned int width
, height
;
1961 /* retrieve the real size of the desktop */
1962 SERVER_START_REQ( get_window_rectangles
)
1964 req
->handle
= wine_server_user_handle( hwnd
);
1965 req
->relative
= COORDS_CLIENT
;
1966 wine_server_call( req
);
1967 width
= reply
->window
.right
;
1968 height
= reply
->window
.bottom
;
1972 if (!width
&& !height
) /* not initialized yet */
1974 SERVER_START_REQ( set_window_pos
)
1976 req
->handle
= wine_server_user_handle( hwnd
);
1978 req
->flags
= SWP_NOZORDER
;
1979 req
->window
.left
= virtual_screen_rect
.left
;
1980 req
->window
.top
= virtual_screen_rect
.top
;
1981 req
->window
.right
= virtual_screen_rect
.right
;
1982 req
->window
.bottom
= virtual_screen_rect
.bottom
;
1983 req
->client
= req
->window
;
1984 wine_server_call( req
);
1990 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1991 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1997 /**********************************************************************
1998 * CreateWindow (X11DRV.@)
2000 BOOL CDECL
X11DRV_CreateWindow( HWND hwnd
)
2002 if (hwnd
== GetDesktopWindow())
2004 struct x11drv_thread_data
*data
= x11drv_init_thread_data();
2005 XSetWindowAttributes attr
;
2007 if (root_window
!= DefaultRootWindow( gdi_display
))
2009 /* the desktop win data can't be created lazily */
2010 if (!create_desktop_win_data( data
->display
, hwnd
)) return FALSE
;
2013 /* create the cursor clipping window */
2014 attr
.override_redirect
= TRUE
;
2015 attr
.event_mask
= StructureNotifyMask
| FocusChangeMask
;
2017 data
->clip_window
= XCreateWindow( data
->display
, root_window
, 0, 0, 1, 1, 0, 0,
2018 InputOnly
, visual
, CWOverrideRedirect
| CWEventMask
, &attr
);
2019 wine_tsx11_unlock();
2020 SetPropA( hwnd
, clip_window_prop
, (HANDLE
)data
->clip_window
);
2026 /***********************************************************************
2027 * X11DRV_get_win_data
2029 * Return the X11 data structure associated with a window.
2031 struct x11drv_win_data
*X11DRV_get_win_data( HWND hwnd
)
2033 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2036 if (!thread_data
) return NULL
;
2037 if (!hwnd
) return NULL
;
2038 if (XFindContext( thread_data
->display
, (XID
)hwnd
, win_data_context
, &data
)) data
= NULL
;
2039 return (struct x11drv_win_data
*)data
;
2043 /***********************************************************************
2044 * X11DRV_create_win_data
2046 * Create an X11 data window structure for an existing window.
2048 struct x11drv_win_data
*X11DRV_create_win_data( HWND hwnd
)
2051 struct x11drv_win_data
*data
;
2054 if (!(parent
= GetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop */
2056 /* don't create win data for HWND_MESSAGE windows */
2057 if (parent
!= GetDesktopWindow() && !GetAncestor( parent
, GA_PARENT
)) return NULL
;
2059 display
= thread_init_display();
2060 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
2062 GetWindowRect( hwnd
, &data
->window_rect
);
2063 MapWindowPoints( 0, parent
, (POINT
*)&data
->window_rect
, 2 );
2064 data
->whole_rect
= data
->window_rect
;
2065 GetClientRect( hwnd
, &data
->client_rect
);
2066 MapWindowPoints( hwnd
, parent
, (POINT
*)&data
->client_rect
, 2 );
2068 if (parent
== GetDesktopWindow())
2070 if (!create_whole_window( display
, data
))
2072 HeapFree( GetProcessHeap(), 0, data
);
2075 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
2076 hwnd
, data
->whole_window
, data
->client_window
, wine_dbgstr_rect( &data
->window_rect
),
2077 wine_dbgstr_rect( &data
->whole_rect
), wine_dbgstr_rect( &data
->client_rect
));
2083 /* window procedure for foreign windows */
2084 static LRESULT WINAPI
foreign_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2088 case WM_WINDOWPOSCHANGED
:
2089 update_systray_balloon_position();
2091 case WM_PARENTNOTIFY
:
2092 if (LOWORD(wparam
) == WM_DESTROY
)
2094 TRACE( "%p: got parent notify destroy for win %lx\n", hwnd
, lparam
);
2095 PostMessageW( hwnd
, WM_CLOSE
, 0, 0 ); /* so that we come back here once the child is gone */
2099 if (GetWindow( hwnd
, GW_CHILD
)) return 0; /* refuse to die if we still have children */
2102 return DefWindowProcW( hwnd
, msg
, wparam
, lparam
);
2106 /***********************************************************************
2107 * create_foreign_window
2109 * Create a foreign window for the specified X window and its ancestors
2111 HWND
create_foreign_window( Display
*display
, Window xwin
)
2113 static const WCHAR classW
[] = {'_','_','w','i','n','e','_','x','1','1','_','f','o','r','e','i','g','n','_','w','i','n','d','o','w',0};
2114 static BOOL class_registered
;
2115 struct x11drv_win_data
*data
;
2117 Window xparent
, xroot
;
2119 unsigned int nchildren
;
2120 XWindowAttributes attr
;
2121 DWORD style
= WS_CLIPCHILDREN
;
2123 if (!class_registered
)
2127 memset( &class, 0, sizeof(class) );
2128 class.cbSize
= sizeof(class);
2129 class.lpfnWndProc
= foreign_window_proc
;
2130 class.lpszClassName
= classW
;
2131 if (!RegisterClassExW( &class ) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS
)
2133 ERR( "Could not register foreign window class\n" );
2136 class_registered
= TRUE
;
2140 if (XFindContext( display
, xwin
, winContext
, (char **)&hwnd
)) hwnd
= 0;
2141 if (hwnd
) /* already created */
2143 wine_tsx11_unlock();
2147 XSelectInput( display
, xwin
, StructureNotifyMask
);
2148 if (!XGetWindowAttributes( display
, xwin
, &attr
) ||
2149 !XQueryTree( display
, xwin
, &xroot
, &xparent
, &xchildren
, &nchildren
))
2151 XSelectInput( display
, xwin
, 0 );
2152 wine_tsx11_unlock();
2156 wine_tsx11_unlock();
2158 if (xparent
== xroot
)
2160 parent
= GetDesktopWindow();
2162 attr
.x
+= virtual_screen_rect
.left
;
2163 attr
.y
+= virtual_screen_rect
.top
;
2167 parent
= create_foreign_window( display
, xparent
);
2171 hwnd
= CreateWindowW( classW
, NULL
, style
, attr
.x
, attr
.y
, attr
.width
, attr
.height
,
2172 parent
, 0, 0, NULL
);
2174 if (!(data
= alloc_win_data( display
, hwnd
)))
2176 DestroyWindow( hwnd
);
2179 SetRect( &data
->window_rect
, attr
.x
, attr
.y
, attr
.x
+ attr
.width
, attr
.y
+ attr
.height
);
2180 data
->whole_rect
= data
->client_rect
= data
->window_rect
;
2181 data
->whole_window
= data
->client_window
= 0;
2182 data
->embedded
= TRUE
;
2183 data
->mapped
= TRUE
;
2185 SetPropA( hwnd
, foreign_window_prop
, (HANDLE
)xwin
);
2187 XSaveContext( display
, xwin
, winContext
, (char *)data
->hwnd
);
2188 wine_tsx11_unlock();
2190 ShowWindow( hwnd
, SW_SHOW
);
2192 TRACE( "win %lx parent %p style %08x %s -> hwnd %p\n",
2193 xwin
, parent
, style
, wine_dbgstr_rect(&data
->window_rect
), hwnd
);
2199 /***********************************************************************
2200 * X11DRV_get_whole_window
2202 * Return the X window associated with the full area of a window
2204 Window
X11DRV_get_whole_window( HWND hwnd
)
2206 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2210 if (hwnd
== GetDesktopWindow()) return root_window
;
2211 return (Window
)GetPropA( hwnd
, whole_window_prop
);
2213 return data
->whole_window
;
2217 /***********************************************************************
2218 * X11DRV_get_client_window
2220 * Return the X window associated with the client area of a window
2222 static Window
X11DRV_get_client_window( HWND hwnd
)
2224 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2228 if (hwnd
== GetDesktopWindow()) return root_window
;
2229 return (Window
)GetPropA( hwnd
, client_window_prop
);
2231 return data
->client_window
;
2235 /***********************************************************************
2238 * Return the X input context associated with a window
2240 XIC
X11DRV_get_ic( HWND hwnd
)
2242 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2245 if (!data
) return 0;
2247 x11drv_thread_data()->last_xic_hwnd
= hwnd
;
2248 if (data
->xic
) return data
->xic
;
2249 if (!(xim
= x11drv_thread_data()->xim
)) return 0;
2250 return X11DRV_CreateIC( xim
, data
);
2254 /***********************************************************************
2255 * X11DRV_GetDC (X11DRV.@)
2257 void CDECL
X11DRV_GetDC( HDC hdc
, HWND hwnd
, HWND top
, const RECT
*win_rect
,
2258 const RECT
*top_rect
, DWORD flags
)
2260 struct x11drv_escape_set_drawable escape
;
2261 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2264 escape
.code
= X11DRV_SET_DRAWABLE
;
2265 escape
.mode
= IncludeInferiors
;
2266 escape
.fbconfig_id
= 0;
2267 escape
.gl_drawable
= 0;
2269 escape
.gl_copy
= FALSE
;
2271 escape
.dc_rect
.left
= win_rect
->left
- top_rect
->left
;
2272 escape
.dc_rect
.top
= win_rect
->top
- top_rect
->top
;
2273 escape
.dc_rect
.right
= win_rect
->right
- top_rect
->left
;
2274 escape
.dc_rect
.bottom
= win_rect
->bottom
- top_rect
->top
;
2275 escape
.drawable_rect
.left
= top_rect
->left
;
2276 escape
.drawable_rect
.top
= top_rect
->top
;
2277 escape
.drawable_rect
.right
= top_rect
->right
;
2278 escape
.drawable_rect
.bottom
= top_rect
->bottom
;
2282 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
2283 /* GL draws to the client area even for window DCs */
2284 escape
.gl_drawable
= data
? data
->client_window
: X11DRV_get_client_window( hwnd
);
2285 if (data
&& IsIconic( hwnd
) && data
->icon_window
)
2287 escape
.drawable
= data
->icon_window
;
2289 else if (flags
& DCX_WINDOW
)
2290 escape
.drawable
= data
? data
->whole_window
: X11DRV_get_whole_window( hwnd
);
2292 escape
.drawable
= escape
.gl_drawable
;
2294 /* special case: when repainting the root window, clip out top-level windows */
2295 if (data
&& data
->whole_window
== root_window
) escape
.mode
= ClipByChildren
;
2299 /* find the first ancestor that has a drawable */
2300 for (parent
= hwnd
; parent
&& parent
!= top
; parent
= GetAncestor( parent
, GA_PARENT
))
2301 if ((escape
.drawable
= X11DRV_get_client_window( parent
))) break;
2303 if (escape
.drawable
)
2305 POINT pt
= { 0, 0 };
2306 MapWindowPoints( top
, parent
, &pt
, 1 );
2307 OffsetRect( &escape
.dc_rect
, pt
.x
, pt
.y
);
2308 OffsetRect( &escape
.drawable_rect
, -pt
.x
, -pt
.y
);
2310 else escape
.drawable
= X11DRV_get_client_window( top
);
2312 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
2313 escape
.gl_drawable
= data
? data
->gl_drawable
: (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
2314 escape
.pixmap
= data
? data
->pixmap
: (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
2315 escape
.gl_copy
= (escape
.gl_drawable
!= 0);
2316 if (flags
& DCX_CLIPCHILDREN
) escape
.mode
= ClipByChildren
;
2319 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2323 /***********************************************************************
2324 * X11DRV_ReleaseDC (X11DRV.@)
2326 void CDECL
X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
2328 struct x11drv_escape_set_drawable escape
;
2330 escape
.code
= X11DRV_SET_DRAWABLE
;
2331 escape
.drawable
= root_window
;
2332 escape
.mode
= IncludeInferiors
;
2333 escape
.drawable_rect
= virtual_screen_rect
;
2334 SetRect( &escape
.dc_rect
, 0, 0, virtual_screen_rect
.right
- virtual_screen_rect
.left
,
2335 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
);
2336 OffsetRect( &escape
.dc_rect
, -escape
.drawable_rect
.left
, -escape
.drawable_rect
.top
);
2337 escape
.fbconfig_id
= 0;
2338 escape
.gl_drawable
= 0;
2340 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2344 /***********************************************************************
2345 * SetCapture (X11DRV.@)
2347 void CDECL
X11DRV_SetCapture( HWND hwnd
, UINT flags
)
2349 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2351 if (!thread_data
) return;
2352 if (!(flags
& (GUI_INMOVESIZE
| GUI_INMENUMODE
))) return;
2356 Window grab_win
= X11DRV_get_client_window( GetAncestor( hwnd
, GA_ROOT
) );
2358 if (!grab_win
) return;
2360 XFlush( gdi_display
);
2361 XGrabPointer( thread_data
->display
, grab_win
, False
,
2362 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
2363 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
);
2364 wine_tsx11_unlock();
2365 thread_data
->grab_window
= grab_win
;
2367 else /* release capture */
2370 XFlush( gdi_display
);
2371 XUngrabPointer( thread_data
->display
, CurrentTime
);
2372 XFlush( thread_data
->display
);
2373 wine_tsx11_unlock();
2374 thread_data
->grab_window
= None
;
2379 /*****************************************************************
2380 * SetParent (X11DRV.@)
2382 void CDECL
X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
2384 Display
*display
= thread_display();
2385 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2388 if (parent
== old_parent
) return;
2389 if (data
->embedded
) return;
2391 if (parent
!= GetDesktopWindow()) /* a child window */
2393 if (old_parent
== GetDesktopWindow())
2395 /* destroy the old X windows */
2396 destroy_whole_window( display
, data
, FALSE
);
2397 destroy_icon_window( display
, data
);
2400 data
->managed
= FALSE
;
2401 RemovePropA( data
->hwnd
, managed_prop
);
2405 else /* new top level window */
2407 /* FIXME: we ignore errors since we can't really recover anyway */
2408 create_whole_window( display
, data
);
2413 /*****************************************************************
2414 * SetFocus (X11DRV.@)
2418 void CDECL
X11DRV_SetFocus( HWND hwnd
)
2420 Display
*display
= thread_display();
2421 struct x11drv_win_data
*data
;
2422 XWindowChanges changes
;
2425 if (!(hwnd
= GetAncestor( hwnd
, GA_ROOT
))) return;
2426 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
2427 if (data
->managed
|| !data
->whole_window
) return;
2429 if (EVENT_x11_time_to_win32_time(0))
2430 /* ICCCM says don't use CurrentTime, so try to use last message time if possible */
2431 /* FIXME: this is not entirely correct */
2432 timestamp
= GetMessageTime() - EVENT_x11_time_to_win32_time(0);
2434 timestamp
= CurrentTime
;
2436 /* Set X focus and install colormap */
2438 changes
.stack_mode
= Above
;
2439 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
2440 XSetInputFocus( display
, data
->whole_window
, RevertToParent
, timestamp
);
2441 wine_tsx11_unlock();
2445 /***********************************************************************
2446 * WindowPosChanging (X11DRV.@)
2448 void CDECL
X11DRV_WindowPosChanging( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
2449 const RECT
*window_rect
, const RECT
*client_rect
, RECT
*visible_rect
)
2451 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2452 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2456 /* create the win data if the window is being made visible */
2457 if (!(style
& WS_VISIBLE
) && !(swp_flags
& SWP_SHOWWINDOW
)) return;
2458 if (!(data
= X11DRV_create_win_data( hwnd
))) return;
2461 /* check if we need to switch the window to managed */
2462 if (!data
->managed
&& data
->whole_window
&& is_window_managed( hwnd
, swp_flags
, window_rect
))
2464 TRACE( "making win %p/%lx managed\n", hwnd
, data
->whole_window
);
2465 if (data
->mapped
) unmap_window( thread_display(), data
);
2466 data
->managed
= TRUE
;
2467 SetPropA( hwnd
, managed_prop
, (HANDLE
)1 );
2470 *visible_rect
= *window_rect
;
2471 X11DRV_window_to_X_rect( data
, visible_rect
);
2475 /***********************************************************************
2476 * WindowPosChanged (X11DRV.@)
2478 void CDECL
X11DRV_WindowPosChanged( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
2479 const RECT
*rectWindow
, const RECT
*rectClient
,
2480 const RECT
*visible_rect
, const RECT
*valid_rects
)
2482 struct x11drv_thread_data
*thread_data
;
2484 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2485 DWORD new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2486 RECT old_window_rect
, old_whole_rect
, old_client_rect
;
2491 thread_data
= x11drv_thread_data();
2492 display
= thread_data
->display
;
2494 old_window_rect
= data
->window_rect
;
2495 old_whole_rect
= data
->whole_rect
;
2496 old_client_rect
= data
->client_rect
;
2497 data
->window_rect
= *rectWindow
;
2498 data
->whole_rect
= *visible_rect
;
2499 data
->client_rect
= *rectClient
;
2501 TRACE( "win %p window %s client %s style %08x flags %08x\n",
2502 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
, swp_flags
);
2504 if (!IsRectEmpty( &valid_rects
[0] ))
2506 int x_offset
= old_whole_rect
.left
- data
->whole_rect
.left
;
2507 int y_offset
= old_whole_rect
.top
- data
->whole_rect
.top
;
2509 /* if all that happened is that the whole window moved, copy everything */
2510 if (!(swp_flags
& SWP_FRAMECHANGED
) &&
2511 old_whole_rect
.right
- data
->whole_rect
.right
== x_offset
&&
2512 old_whole_rect
.bottom
- data
->whole_rect
.bottom
== y_offset
&&
2513 old_client_rect
.left
- data
->client_rect
.left
== x_offset
&&
2514 old_client_rect
.right
- data
->client_rect
.right
== x_offset
&&
2515 old_client_rect
.top
- data
->client_rect
.top
== y_offset
&&
2516 old_client_rect
.bottom
- data
->client_rect
.bottom
== y_offset
&&
2517 !memcmp( &valid_rects
[0], &data
->client_rect
, sizeof(RECT
) ))
2519 /* if we have an X window the bits will be moved by the X server */
2520 if (!data
->whole_window
&& (x_offset
!= 0 || y_offset
!= 0))
2521 move_window_bits( data
, &old_whole_rect
, &data
->whole_rect
, &old_client_rect
);
2524 move_window_bits( data
, &valid_rects
[1], &valid_rects
[0], &old_client_rect
);
2528 XFlush( gdi_display
); /* make sure painting is done before we move the window */
2529 wine_tsx11_unlock();
2531 sync_client_position( display
, data
, swp_flags
, &old_client_rect
, &old_whole_rect
);
2533 if (!data
->whole_window
) return;
2535 /* check if we are currently processing an event relevant to this window */
2537 if (thread_data
->current_event
&& thread_data
->current_event
->xany
.window
== data
->whole_window
)
2538 event_type
= thread_data
->current_event
->type
;
2540 if (event_type
!= ConfigureNotify
&& event_type
!= PropertyNotify
&&
2541 event_type
!= GravityNotify
&& event_type
!= ReparentNotify
)
2542 event_type
= 0; /* ignore other events */
2544 if (data
->mapped
&& event_type
!= ReparentNotify
)
2546 if (((swp_flags
& SWP_HIDEWINDOW
) && !(new_style
& WS_VISIBLE
)) ||
2548 !is_window_rect_mapped( rectWindow
) && is_window_rect_mapped( &old_window_rect
)))
2549 unmap_window( display
, data
);
2552 /* don't change position if we are about to minimize or maximize a managed window */
2554 !(data
->managed
&& (swp_flags
& SWP_STATECHANGED
) && (new_style
& (WS_MINIMIZE
|WS_MAXIMIZE
))))
2555 sync_window_position( display
, data
, swp_flags
,
2556 &old_window_rect
, &old_whole_rect
, &old_client_rect
);
2558 if ((new_style
& WS_VISIBLE
) &&
2559 ((new_style
& WS_MINIMIZE
) || is_window_rect_mapped( rectWindow
)))
2561 if (!data
->mapped
|| (swp_flags
& (SWP_FRAMECHANGED
|SWP_STATECHANGED
)))
2562 set_wm_hints( display
, data
);
2566 map_window( display
, data
, new_style
);
2568 else if ((swp_flags
& SWP_STATECHANGED
) && (!data
->iconic
!= !(new_style
& WS_MINIMIZE
)))
2570 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
2571 TRACE( "changing win %p iconic state to %u\n", data
->hwnd
, data
->iconic
);
2574 XIconifyWindow( display
, data
->whole_window
, DefaultScreen(display
) );
2575 else if (is_window_rect_mapped( rectWindow
))
2576 XMapWindow( display
, data
->whole_window
);
2577 wine_tsx11_unlock();
2578 update_net_wm_states( display
, data
);
2580 else if (!event_type
)
2582 update_net_wm_states( display
, data
);
2587 XFlush( display
); /* make sure changes are done before we start painting again */
2588 wine_tsx11_unlock();
2592 /***********************************************************************
2593 * ShowWindow (X11DRV.@)
2595 UINT CDECL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
, RECT
*rect
, UINT swp
)
2598 unsigned int width
, height
, border
, depth
;
2600 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2601 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2602 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2604 if (!data
|| !data
->whole_window
|| !data
->managed
|| !data
->mapped
|| data
->iconic
) return swp
;
2605 if (style
& WS_MINIMIZE
) return swp
;
2606 if (IsRectEmpty( rect
)) return swp
;
2608 /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */
2610 if (!thread_data
->current_event
|| thread_data
->current_event
->xany
.window
!= data
->whole_window
)
2613 if (thread_data
->current_event
->type
!= ConfigureNotify
&&
2614 thread_data
->current_event
->type
!= PropertyNotify
)
2617 TRACE( "win %p/%lx cmd %d at %s flags %08x\n",
2618 hwnd
, data
->whole_window
, cmd
, wine_dbgstr_rect(rect
), swp
);
2621 XGetGeometry( thread_data
->display
, data
->whole_window
,
2622 &root
, &x
, &y
, &width
, &height
, &border
, &depth
);
2623 XTranslateCoordinates( thread_data
->display
, data
->whole_window
, root
, 0, 0, &x
, &y
, &top
);
2624 wine_tsx11_unlock();
2627 rect
->right
= x
+ width
;
2628 rect
->bottom
= y
+ height
;
2629 OffsetRect( rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
2630 X11DRV_X_to_window_rect( data
, rect
);
2631 return swp
& ~(SWP_NOMOVE
| SWP_NOCLIENTMOVE
| SWP_NOSIZE
| SWP_NOCLIENTSIZE
);
2635 /**********************************************************************
2636 * SetWindowIcon (X11DRV.@)
2638 * hIcon or hIconSm has changed (or is being initialised for the
2639 * first time). Complete the X11 driver-specific initialisation
2640 * and set the window hints.
2642 * This is not entirely correct, may need to create
2643 * an icon window and set the pixmap as a background
2645 void CDECL
X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
2647 Display
*display
= thread_display();
2648 struct x11drv_win_data
*data
;
2651 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
2652 if (!data
->whole_window
) return;
2653 if (!data
->managed
) return;
2657 if (type
== ICON_BIG
) set_icon_hints( display
, data
, icon
, 0 );
2658 else set_icon_hints( display
, data
, 0, icon
);
2660 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
2661 wine_tsx11_unlock();
2666 /***********************************************************************
2667 * SetWindowRgn (X11DRV.@)
2669 * Assign specified region to window (for non-rectangular windows)
2671 int CDECL
X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
2673 struct x11drv_win_data
*data
;
2675 if ((data
= X11DRV_get_win_data( hwnd
)))
2677 sync_window_region( thread_display(), data
, hrgn
);
2679 else if (X11DRV_get_whole_window( hwnd
))
2681 SendMessageW( hwnd
, WM_X11DRV_SET_WIN_REGION
, 0, 0 );
2687 /***********************************************************************
2688 * SetLayeredWindowAttributes (X11DRV.@)
2690 * Set transparency attributes for a layered window.
2692 void CDECL
X11DRV_SetLayeredWindowAttributes( HWND hwnd
, COLORREF key
, BYTE alpha
, DWORD flags
)
2694 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2698 if (data
->whole_window
)
2699 sync_window_opacity( thread_display(), data
->whole_window
, key
, alpha
, flags
);
2703 Window win
= X11DRV_get_whole_window( hwnd
);
2704 if (win
) sync_window_opacity( gdi_display
, win
, key
, alpha
, flags
);
2709 /**********************************************************************
2710 * X11DRV_WindowMessage (X11DRV.@)
2712 LRESULT CDECL
X11DRV_WindowMessage( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2714 struct x11drv_win_data
*data
;
2718 case WM_X11DRV_ACQUIRE_SELECTION
:
2719 return X11DRV_AcquireClipboard( hwnd
);
2720 case WM_X11DRV_SET_WIN_FORMAT
:
2721 return set_win_format( hwnd
, (XID
)wp
);
2722 case WM_X11DRV_SET_WIN_REGION
:
2723 if ((data
= X11DRV_get_win_data( hwnd
))) sync_window_region( thread_display(), data
, (HRGN
)1 );
2725 case WM_X11DRV_RESIZE_DESKTOP
:
2726 X11DRV_resize_desktop( LOWORD(lp
), HIWORD(lp
) );
2728 case WM_X11DRV_SET_CURSOR
:
2729 if ((data
= X11DRV_get_win_data( hwnd
)) && data
->whole_window
)
2730 set_window_cursor( data
->whole_window
, (HCURSOR
)lp
);
2731 else if (hwnd
== x11drv_thread_data()->clip_hwnd
)
2732 set_window_cursor( x11drv_thread_data()->clip_window
, (HCURSOR
)lp
);
2734 case WM_X11DRV_CLIP_CURSOR
:
2735 return clip_cursor_notify( hwnd
, (HWND
)lp
);
2737 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg
, hwnd
, wp
, lp
);
2743 /***********************************************************************
2744 * is_netwm_supported
2746 static BOOL
is_netwm_supported( Display
*display
, Atom atom
)
2748 static Atom
*net_supported
;
2749 static int net_supported_count
= -1;
2753 if (net_supported_count
== -1)
2757 unsigned long count
, remaining
;
2759 if (!XGetWindowProperty( display
, DefaultRootWindow(display
), x11drv_atom(_NET_SUPPORTED
), 0,
2760 ~0UL, False
, XA_ATOM
, &type
, &format
, &count
,
2761 &remaining
, (unsigned char **)&net_supported
))
2762 net_supported_count
= get_property_size( format
, count
) / sizeof(Atom
);
2764 net_supported_count
= 0;
2766 wine_tsx11_unlock();
2768 for (i
= 0; i
< net_supported_count
; i
++)
2769 if (net_supported
[i
] == atom
) return TRUE
;
2774 /***********************************************************************
2775 * SysCommand (X11DRV.@)
2777 * Perform WM_SYSCOMMAND handling.
2779 LRESULT CDECL
X11DRV_SysCommand( HWND hwnd
, WPARAM wparam
, LPARAM lparam
)
2781 WPARAM hittest
= wparam
& 0x0f;
2785 Display
*display
= thread_display();
2786 struct x11drv_win_data
*data
;
2788 if (!(data
= X11DRV_get_win_data( hwnd
))) return -1;
2789 if (!data
->whole_window
|| !data
->managed
|| !data
->mapped
) return -1;
2791 switch (wparam
& 0xfff0)
2794 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
2795 else dir
= _NET_WM_MOVERESIZE_MOVE
;
2798 /* windows without WS_THICKFRAME are not resizable through the window manager */
2799 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_THICKFRAME
)) return -1;
2803 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
2804 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
2805 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
2806 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
2807 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
2808 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
2809 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
2810 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
2811 default: dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
; break;
2816 /* prevent a simple ALT press+release from activating the system menu,
2817 * as that can get confusing on managed windows */
2818 if ((WCHAR
)lparam
) return -1; /* got an explicit char */
2819 if (GetMenu( hwnd
)) return -1; /* window has a real menu */
2820 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_SYSMENU
)) return -1; /* no system menu */
2821 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam
, lparam
);
2828 if (IsZoomed(hwnd
)) return -1;
2830 if (!is_netwm_supported( display
, x11drv_atom(_NET_WM_MOVERESIZE
) ))
2832 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
2836 dwPoint
= GetMessagePos();
2837 x
= (short)LOWORD(dwPoint
);
2838 y
= (short)HIWORD(dwPoint
);
2840 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd
, x
, y
, dir
);
2842 xev
.xclient
.type
= ClientMessage
;
2843 xev
.xclient
.window
= X11DRV_get_whole_window(hwnd
);
2844 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_MOVERESIZE
);
2845 xev
.xclient
.serial
= 0;
2846 xev
.xclient
.display
= display
;
2847 xev
.xclient
.send_event
= True
;
2848 xev
.xclient
.format
= 32;
2849 xev
.xclient
.data
.l
[0] = x
- virtual_screen_rect
.left
; /* x coord */
2850 xev
.xclient
.data
.l
[1] = y
- virtual_screen_rect
.top
; /* y coord */
2851 xev
.xclient
.data
.l
[2] = dir
; /* direction */
2852 xev
.xclient
.data
.l
[3] = 1; /* button */
2853 xev
.xclient
.data
.l
[4] = 0; /* unused */
2855 /* need to ungrab the pointer that may have been automatically grabbed
2856 * with a ButtonPress event */
2858 XUngrabPointer( display
, CurrentTime
);
2859 XSendEvent(display
, root_window
, False
, SubstructureNotifyMask
| SubstructureRedirectMask
, &xev
);
2860 wine_tsx11_unlock();