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_popup( HWND hwnd
, LPARAM lparam
)
164 struct has_popup_result
*result
= (struct has_popup_result
*)lparam
;
166 if (hwnd
== result
->hwnd
) return FALSE
; /* popups are always above owner */
167 result
->found
= (GetWindow( hwnd
, GW_OWNER
) == result
->hwnd
);
168 return !result
->found
;
171 static BOOL
has_owned_popups( HWND hwnd
)
173 struct has_popup_result result
;
176 result
.found
= FALSE
;
177 EnumWindows( has_popup
, (LPARAM
)&result
);
181 /***********************************************************************
184 * Check if a given window should be managed
186 static BOOL
is_window_managed( HWND hwnd
, UINT swp_flags
, const RECT
*window_rect
)
188 DWORD style
, ex_style
;
190 if (!managed_mode
) return FALSE
;
192 /* child windows are not managed */
193 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
194 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) return FALSE
;
195 /* activated windows are managed */
196 if (!(swp_flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
))) return TRUE
;
197 if (hwnd
== GetActiveWindow()) return TRUE
;
198 /* windows with caption are managed */
199 if ((style
& WS_CAPTION
) == WS_CAPTION
) return TRUE
;
200 /* windows with thick frame are managed */
201 if (style
& WS_THICKFRAME
) return TRUE
;
202 if (style
& WS_POPUP
)
207 /* popup with sysmenu == caption are managed */
208 if (style
& WS_SYSMENU
) return TRUE
;
209 /* full-screen popup windows are managed */
210 hmon
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
);
211 mi
.cbSize
= sizeof( mi
);
212 GetMonitorInfoW( hmon
, &mi
);
213 if (window_rect
->left
<= mi
.rcWork
.left
&& window_rect
->right
>= mi
.rcWork
.right
&&
214 window_rect
->top
<= mi
.rcWork
.top
&& window_rect
->bottom
>= mi
.rcWork
.bottom
)
217 /* application windows are managed */
218 ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
219 if (ex_style
& WS_EX_APPWINDOW
) return TRUE
;
220 /* windows that own popups are managed */
221 if (has_owned_popups( hwnd
)) return TRUE
;
222 /* default: not managed */
227 /***********************************************************************
228 * is_window_resizable
230 * Check if window should be made resizable by the window manager
232 static inline BOOL
is_window_resizable( struct x11drv_win_data
*data
, DWORD style
)
234 if (style
& WS_THICKFRAME
) return TRUE
;
235 /* Metacity needs the window to be resizable to make it fullscreen */
236 return is_window_rect_fullscreen( &data
->whole_rect
);
240 /***********************************************************************
241 * get_mwm_decorations
243 static unsigned long get_mwm_decorations( struct x11drv_win_data
*data
,
244 DWORD style
, DWORD ex_style
)
246 unsigned long ret
= 0;
248 if (!decorated_mode
) return 0;
250 if (IsRectEmpty( &data
->window_rect
)) return 0;
251 if (data
->shaped
) return 0;
253 if (ex_style
& WS_EX_TOOLWINDOW
) return 0;
255 if ((style
& WS_CAPTION
) == WS_CAPTION
)
257 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
258 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
259 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
260 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
262 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
263 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
264 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
269 /***********************************************************************
270 * get_x11_rect_offset
272 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
274 static void get_x11_rect_offset( struct x11drv_win_data
*data
, RECT
*rect
)
276 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
279 rect
->top
= rect
->bottom
= rect
->left
= rect
->right
= 0;
281 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
282 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
283 decor
= get_mwm_decorations( data
, style
, ex_style
);
285 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
286 if (decor
& MWM_DECOR_BORDER
)
288 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
289 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
292 AdjustWindowRectEx( rect
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
296 /***********************************************************************
297 * get_window_attributes
299 * Fill the window attributes structure for an X window.
301 static int get_window_attributes( Display
*display
, struct x11drv_win_data
*data
,
302 XSetWindowAttributes
*attr
)
304 attr
->override_redirect
= !data
->managed
;
305 attr
->colormap
= X11DRV_PALETTE_PaletteXColormap
;
306 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
307 attr
->bit_gravity
= NorthWestGravity
;
308 attr
->win_gravity
= StaticGravity
;
309 attr
->backing_store
= NotUseful
;
310 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
311 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
312 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
|
313 KeymapStateMask
| StructureNotifyMask
);
314 if (data
->managed
) attr
->event_mask
|= PropertyChangeMask
;
316 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
|
317 CWEventMask
| CWBitGravity
| CWBackingStore
);
321 /***********************************************************************
322 * create_client_window
324 static Window
create_client_window( Display
*display
, struct x11drv_win_data
*data
, XVisualInfo
*vis
)
327 XSetWindowAttributes attr
;
329 Visual
*client_visual
= vis
? vis
->visual
: visual
;
331 attr
.bit_gravity
= NorthWestGravity
;
332 attr
.win_gravity
= NorthWestGravity
;
333 attr
.backing_store
= NotUseful
;
334 attr
.event_mask
= (ExposureMask
| PointerMotionMask
|
335 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
336 mask
= CWEventMask
| CWBitGravity
| CWWinGravity
| CWBackingStore
;
338 if ((cx
= data
->client_rect
.right
- data
->client_rect
.left
) <= 0) cx
= 1;
339 else if (cx
> 65535) cx
= 65535;
340 if ((cy
= data
->client_rect
.bottom
- data
->client_rect
.top
) <= 0) cy
= 1;
341 else if (cy
> 65535) cy
= 65535;
347 attr
.colormap
= XCreateColormap( display
, root_window
, vis
->visual
,
348 (vis
->class == PseudoColor
|| vis
->class == GrayScale
||
349 vis
->class == DirectColor
) ? AllocAll
: AllocNone
);
353 client
= XCreateWindow( display
, data
->whole_window
,
354 data
->client_rect
.left
- data
->whole_rect
.left
,
355 data
->client_rect
.top
- data
->whole_rect
.top
,
356 cx
, cy
, 0, screen_depth
, InputOutput
,
357 client_visual
, mask
, &attr
);
364 if (data
->client_window
)
366 XDeleteContext( display
, data
->client_window
, winContext
);
367 XDestroyWindow( display
, data
->client_window
);
369 data
->client_window
= client
;
370 data
->visualid
= XVisualIDFromVisual( client_visual
);
372 if (data
->colormap
) XFreeColormap( display
, data
->colormap
);
373 data
->colormap
= vis
? attr
.colormap
: 0;
375 XMapWindow( display
, data
->client_window
);
376 XSaveContext( display
, data
->client_window
, winContext
, (char *)data
->hwnd
);
379 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)data
->client_window
);
380 return data
->client_window
;
384 /***********************************************************************
387 * Change the X window attributes when the window style has changed.
389 static void sync_window_style( Display
*display
, struct x11drv_win_data
*data
)
391 if (data
->whole_window
!= root_window
)
393 XSetWindowAttributes attr
;
394 int mask
= get_window_attributes( display
, data
, &attr
);
397 XChangeWindowAttributes( display
, data
->whole_window
, mask
, &attr
);
403 /***********************************************************************
406 * Update the X11 window region.
408 static void sync_window_region( Display
*display
, struct x11drv_win_data
*data
, HRGN win_region
)
410 #ifdef HAVE_LIBXSHAPE
411 HRGN hrgn
= win_region
;
413 if (!data
->whole_window
) return;
414 data
->shaped
= FALSE
;
416 if (IsRectEmpty( &data
->window_rect
)) /* set an empty shape */
418 static XRectangle empty_rect
;
420 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
, 0, 0,
421 &empty_rect
, 1, ShapeSet
, YXBanded
);
426 if (hrgn
== (HRGN
)1) /* hack: win_region == 1 means retrieve region from server */
428 if (!(hrgn
= CreateRectRgn( 0, 0, 0, 0 ))) return;
429 if (GetWindowRgn( data
->hwnd
, hrgn
) == ERROR
)
431 DeleteObject( hrgn
);
439 XShapeCombineMask( display
, data
->whole_window
, ShapeBounding
, 0, 0, None
, ShapeSet
);
444 RGNDATA
*pRegionData
;
446 if (GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
) MirrorRgn( data
->hwnd
, hrgn
);
447 if ((pRegionData
= X11DRV_GetRegionData( hrgn
, 0 )))
450 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
451 data
->window_rect
.left
- data
->whole_rect
.left
,
452 data
->window_rect
.top
- data
->whole_rect
.top
,
453 (XRectangle
*)pRegionData
->Buffer
,
454 pRegionData
->rdh
.nCount
, ShapeSet
, YXBanded
);
456 HeapFree(GetProcessHeap(), 0, pRegionData
);
460 if (hrgn
&& hrgn
!= win_region
) DeleteObject( hrgn
);
461 #endif /* HAVE_LIBXSHAPE */
465 /***********************************************************************
466 * sync_window_opacity
468 static void sync_window_opacity( Display
*display
, Window win
,
469 COLORREF key
, BYTE alpha
, DWORD flags
)
471 unsigned long opacity
= 0xffffffff;
473 if (flags
& LWA_ALPHA
) opacity
= (0xffffffff / 0xff) * alpha
;
475 if (flags
& LWA_COLORKEY
) FIXME("LWA_COLORKEY not supported\n");
478 if (opacity
== 0xffffffff)
479 XDeleteProperty( display
, win
, x11drv_atom(_NET_WM_WINDOW_OPACITY
) );
481 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_WINDOW_OPACITY
),
482 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&opacity
, 1 );
487 /***********************************************************************
490 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
493 char *buffer
, *utf8_buffer
;
496 /* allocate new buffer for window text */
497 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
498 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
499 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
501 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
502 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
504 HeapFree( GetProcessHeap(), 0, buffer
);
507 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
510 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
512 XSetWMName( display
, win
, &prop
);
513 XSetWMIconName( display
, win
, &prop
);
517 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
518 according to the standard
519 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
521 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
522 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
525 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
526 HeapFree( GetProcessHeap(), 0, buffer
);
530 /***********************************************************************
533 static BOOL
set_win_format( HWND hwnd
, XID fbconfig_id
)
535 struct x11drv_win_data
*data
;
539 if (!(data
= X11DRV_get_win_data(hwnd
)) &&
540 !(data
= X11DRV_create_win_data(hwnd
))) return FALSE
;
542 if (!(vis
= visual_from_fbconfig_id(fbconfig_id
))) return FALSE
;
544 if (data
->whole_window
)
546 Display
*display
= thread_display();
547 Window client
= data
->client_window
;
549 if (vis
->visualid
!= data
->visualid
)
551 client
= create_client_window( display
, data
, vis
);
552 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client
, data
->hwnd
, fbconfig_id
);
558 if (client
) goto done
;
562 w
= data
->client_rect
.right
- data
->client_rect
.left
;
563 h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
568 #ifdef SONAME_LIBXCOMPOSITE
571 XSetWindowAttributes attrib
;
572 static Window dummy_parent
;
575 attrib
.override_redirect
= True
;
578 dummy_parent
= XCreateWindow( gdi_display
, root_window
, -1, -1, 1, 1, 0, screen_depth
,
579 InputOutput
, visual
, CWOverrideRedirect
, &attrib
);
580 XMapWindow( gdi_display
, dummy_parent
);
582 data
->colormap
= XCreateColormap(gdi_display
, dummy_parent
, vis
->visual
,
583 (vis
->class == PseudoColor
||
584 vis
->class == GrayScale
||
585 vis
->class == DirectColor
) ?
586 AllocAll
: AllocNone
);
587 attrib
.colormap
= data
->colormap
;
588 XInstallColormap(gdi_display
, attrib
.colormap
);
590 if(data
->gl_drawable
) XDestroyWindow(gdi_display
, data
->gl_drawable
);
591 data
->gl_drawable
= XCreateWindow(gdi_display
, dummy_parent
, -w
, 0, w
, h
, 0,
592 vis
->depth
, InputOutput
, vis
->visual
,
593 CWColormap
| CWOverrideRedirect
,
595 if(data
->gl_drawable
)
597 pXCompositeRedirectWindow(gdi_display
, data
->gl_drawable
,
598 CompositeRedirectManual
);
599 XMapWindow(gdi_display
, data
->gl_drawable
);
602 XFlush( gdi_display
);
608 WARN("XComposite is not available, using GLXPixmap hack\n");
612 if(data
->pixmap
) XFreePixmap(gdi_display
, data
->pixmap
);
613 data
->pixmap
= XCreatePixmap(gdi_display
, root_window
, w
, h
, vis
->depth
);
621 if(data
->gl_drawable
) destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
622 data
->gl_drawable
= create_glxpixmap(gdi_display
, vis
, data
->pixmap
);
623 if(!data
->gl_drawable
)
625 XFreePixmap(gdi_display
, data
->pixmap
);
629 XFlush( gdi_display
);
631 if (data
->pixmap
) SetPropA(hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
634 if (!data
->gl_drawable
) return FALSE
;
636 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
637 data
->gl_drawable
, fbconfig_id
);
638 SetPropA(hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
641 data
->fbconfig_id
= fbconfig_id
;
642 SetPropA(hwnd
, fbconfig_id_prop
, (HANDLE
)data
->fbconfig_id
);
643 /* force DCE invalidation */
644 SetWindowPos( hwnd
, 0, 0, 0, 0, 0,
645 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOMOVE
|
646 SWP_NOREDRAW
| SWP_DEFERERASE
| SWP_NOSENDCHANGING
| SWP_STATECHANGED
);
650 /***********************************************************************
653 static void sync_gl_drawable(struct x11drv_win_data
*data
)
655 int w
= data
->client_rect
.right
- data
->client_rect
.left
;
656 int h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
664 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
665 #ifdef SONAME_LIBXCOMPOSITE
669 XMoveResizeWindow(gdi_display
, data
->gl_drawable
, -w
, 0, w
, h
);
675 if (!(vis
= visual_from_fbconfig_id(data
->fbconfig_id
))) return;
678 pix
= XCreatePixmap(gdi_display
, root_window
, w
, h
, vis
->depth
);
681 ERR("Failed to create pixmap for offscreen rendering\n");
687 glxp
= create_glxpixmap(gdi_display
, vis
, pix
);
690 ERR("Failed to create drawable for offscreen rendering\n");
691 XFreePixmap(gdi_display
, pix
);
699 mark_drawable_dirty(data
->gl_drawable
, glxp
);
701 XFreePixmap(gdi_display
, data
->pixmap
);
702 destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
703 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp
, data
->gl_drawable
);
706 data
->gl_drawable
= glxp
;
708 XFlush( gdi_display
);
711 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
712 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
716 /***********************************************************************
719 * fill the window changes structure
721 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
725 if (old
->right
- old
->left
!= new->right
- new->left
)
727 if ((changes
->width
= new->right
- new->left
) <= 0) changes
->width
= 1;
728 else if (changes
->width
> 65535) changes
->width
= 65535;
731 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
733 if ((changes
->height
= new->bottom
- new->top
) <= 0) changes
->height
= 1;
734 else if (changes
->height
> 65535) changes
->height
= 65535;
737 if (old
->left
!= new->left
)
739 changes
->x
= new->left
;
742 if (old
->top
!= new->top
)
744 changes
->y
= new->top
;
751 /***********************************************************************
754 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
756 XSetWindowAttributes attr
;
758 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
759 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
760 attr
.bit_gravity
= NorthWestGravity
;
761 attr
.backing_store
= NotUseful
/*WhenMapped*/;
762 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
765 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
766 GetSystemMetrics( SM_CXICON
),
767 GetSystemMetrics( SM_CYICON
),
770 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
771 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
772 XFlush( display
); /* make sure the window exists before we start painting to it */
775 TRACE( "created %lx\n", data
->icon_window
);
776 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
777 return data
->icon_window
;
782 /***********************************************************************
783 * destroy_icon_window
785 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
787 if (!data
->icon_window
) return;
789 XDeleteContext( display
, data
->icon_window
, winContext
);
790 XDestroyWindow( display
, data
->icon_window
);
791 data
->icon_window
= 0;
793 RemovePropA( data
->hwnd
, icon_window_prop
);
797 /***********************************************************************
800 * Return the bitmap bits in ARGB format. Helper for setting icon hints.
802 static unsigned long *get_bitmap_argb( HDC hdc
, HBITMAP color
, HBITMAP mask
, unsigned int *size
)
806 unsigned int *ptr
, *bits
= NULL
;
807 unsigned char *mask_bits
= NULL
;
808 int i
, j
, has_alpha
= 0;
810 if (!GetObjectW( color
, sizeof(bm
), &bm
)) return NULL
;
811 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) return NULL
;
812 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
813 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
814 info
->bmiHeader
.biHeight
= -bm
.bmHeight
;
815 info
->bmiHeader
.biPlanes
= 1;
816 info
->bmiHeader
.biBitCount
= 32;
817 info
->bmiHeader
.biCompression
= BI_RGB
;
818 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* bm
.bmHeight
* 4;
819 info
->bmiHeader
.biXPelsPerMeter
= 0;
820 info
->bmiHeader
.biYPelsPerMeter
= 0;
821 info
->bmiHeader
.biClrUsed
= 0;
822 info
->bmiHeader
.biClrImportant
= 0;
823 *size
= bm
.bmWidth
* bm
.bmHeight
+ 2;
824 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, *size
* sizeof(long) ))) goto failed
;
825 if (!GetDIBits( hdc
, color
, 0, bm
.bmHeight
, bits
+ 2, info
, DIB_RGB_COLORS
)) goto failed
;
827 bits
[0] = bm
.bmWidth
;
828 bits
[1] = bm
.bmHeight
;
830 for (i
= 0; i
< bm
.bmWidth
* bm
.bmHeight
; i
++)
831 if ((has_alpha
= (bits
[i
+ 2] & 0xff000000) != 0)) break;
835 unsigned int width_bytes
= (bm
.bmWidth
+ 31) / 32 * 4;
836 /* generate alpha channel from the mask */
837 info
->bmiHeader
.biBitCount
= 1;
838 info
->bmiHeader
.biSizeImage
= width_bytes
* bm
.bmHeight
;
839 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto failed
;
840 if (!GetDIBits( hdc
, mask
, 0, bm
.bmHeight
, mask_bits
, info
, DIB_RGB_COLORS
)) goto failed
;
842 for (i
= 0; i
< bm
.bmHeight
; i
++)
843 for (j
= 0; j
< bm
.bmWidth
; j
++, ptr
++)
844 if (!((mask_bits
[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80)) *ptr
|= 0xff000000;
845 HeapFree( GetProcessHeap(), 0, mask_bits
);
847 HeapFree( GetProcessHeap(), 0, info
);
849 /* convert to array of longs */
850 if (bits
&& sizeof(long) > sizeof(int))
851 for (i
= *size
- 1; i
>= 0; i
--) ((unsigned long *)bits
)[i
] = bits
[i
];
853 return (unsigned long *)bits
;
856 HeapFree( GetProcessHeap(), 0, info
);
857 HeapFree( GetProcessHeap(), 0, bits
);
858 HeapFree( GetProcessHeap(), 0, mask_bits
);
863 /***********************************************************************
866 * Set the icon wm hints
868 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
,
869 HICON icon_big
, HICON icon_small
)
871 XWMHints
*hints
= data
->wm_hints
;
875 icon_big
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_BIG
, 0 );
876 if (!icon_big
) icon_big
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
);
880 icon_small
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
881 if (!icon_small
) icon_small
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICONSM
);
884 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
885 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
886 data
->hWMIconBitmap
= 0;
887 data
->hWMIconMask
= 0;
891 if (!data
->icon_window
) create_icon_window( display
, data
);
892 hints
->icon_window
= data
->icon_window
;
893 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
900 ICONINFO ii
, ii_small
;
905 if (!GetIconInfo(icon_big
, &ii
)) return;
907 GetObjectW(ii
.hbmMask
, sizeof(bm
), &bm
);
910 rcMask
.right
= bm
.bmWidth
;
911 rcMask
.bottom
= bm
.bmHeight
;
913 hDC
= CreateCompatibleDC(0);
914 bits
= get_bitmap_argb( hDC
, ii
.hbmColor
, ii
.hbmMask
, &size
);
915 if (bits
&& GetIconInfo( icon_small
, &ii_small
))
917 unsigned int size_small
;
918 unsigned long *bits_small
, *new;
920 if ((bits_small
= get_bitmap_argb( hDC
, ii_small
.hbmColor
, ii_small
.hbmMask
, &size_small
)) &&
921 (bits_small
[0] != bits
[0] || bits_small
[1] != bits
[1])) /* size must be different */
923 if ((new = HeapReAlloc( GetProcessHeap(), 0, bits
,
924 (size
+ size_small
) * sizeof(unsigned long) )))
927 memcpy( bits
+ size
, bits_small
, size_small
* sizeof(unsigned long) );
931 HeapFree( GetProcessHeap(), 0, bits_small
);
932 DeleteObject( ii_small
.hbmColor
);
933 DeleteObject( ii_small
.hbmMask
);
937 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_ICON
),
938 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)bits
, size
);
940 XDeleteProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_ICON
) );
942 HeapFree( GetProcessHeap(), 0, bits
);
944 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
945 InvertRect(hDC
, &rcMask
);
946 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
947 SelectObject(hDC
, hbmOrig
);
949 data
->hWMIconBitmap
= ii
.hbmColor
;
950 data
->hWMIconMask
= ii
.hbmMask
;
952 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
953 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
954 destroy_icon_window( display
, data
);
955 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
962 /***********************************************************************
965 * set the window size hints
967 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
969 XSizeHints
* size_hints
;
971 if (!(size_hints
= XAllocSizeHints())) return;
973 size_hints
->win_gravity
= StaticGravity
;
974 size_hints
->flags
|= PWinGravity
;
976 /* don't update size hints if window is not in normal state */
977 if (!(style
& (WS_MINIMIZE
| WS_MAXIMIZE
)))
979 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
981 size_hints
->x
= data
->whole_rect
.left
;
982 size_hints
->y
= data
->whole_rect
.top
;
983 size_hints
->flags
|= PPosition
;
985 else size_hints
->win_gravity
= NorthWestGravity
;
987 if (!is_window_resizable( data
, style
))
989 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
990 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
991 if (size_hints
->max_width
<= 0 ||size_hints
->max_height
<= 0)
992 size_hints
->max_width
= size_hints
->max_height
= 1;
993 size_hints
->min_width
= size_hints
->max_width
;
994 size_hints
->min_height
= size_hints
->max_height
;
995 size_hints
->flags
|= PMinSize
| PMaxSize
;
998 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
1003 /***********************************************************************
1006 static void set_mwm_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
, DWORD ex_style
)
1010 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
1011 mwm_hints
.decorations
= get_mwm_decorations( data
, style
, ex_style
);
1012 mwm_hints
.functions
= MWM_FUNC_MOVE
;
1013 if (is_window_resizable( data
, style
)) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
1014 if (!(style
& WS_DISABLED
))
1016 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
1017 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
1018 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
1020 TRACE( "%p setting mwm hints to %lx,%lx (style %x exstyle %x)\n",
1021 data
->hwnd
, mwm_hints
.decorations
, mwm_hints
.functions
, style
, ex_style
);
1023 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
1024 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
1025 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
1029 /***********************************************************************
1032 * get the name of the current process for setting class hints
1034 static char *get_process_name(void)
1040 WCHAR module
[MAX_PATH
];
1041 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
1042 if (len
&& len
< MAX_PATH
)
1045 WCHAR
*p
, *appname
= module
;
1047 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
1048 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
1049 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
1050 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
1052 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
1061 /***********************************************************************
1062 * set_initial_wm_hints
1064 * Set the window manager hints that don't change over the lifetime of a window.
1066 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
1070 Atom dndVersion
= WINE_XDND_VERSION
;
1071 XClassHint
*class_hints
;
1072 char *process_name
= get_process_name();
1078 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
1079 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
1080 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
1081 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
1082 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
1085 if ((class_hints
= XAllocClassHint()))
1087 static char wine
[] = "Wine";
1089 class_hints
->res_name
= process_name
;
1090 class_hints
->res_class
= wine
;
1091 XSetClassHint( display
, data
->whole_window
, class_hints
);
1092 XFree( class_hints
);
1095 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
1096 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
1097 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
1099 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
1100 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
1102 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
1103 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
1105 update_user_time( 0 ); /* make sure that the user time window exists */
1106 if (user_time_window
)
1107 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_USER_TIME_WINDOW
),
1108 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&user_time_window
, 1 );
1110 data
->wm_hints
= XAllocWMHints();
1111 wine_tsx11_unlock();
1115 data
->wm_hints
->flags
= 0;
1116 set_icon_hints( display
, data
, 0, 0 );
1121 /***********************************************************************
1122 * get_owner_whole_window
1124 * Retrieve an owner's window, creating it if necessary.
1126 static Window
get_owner_whole_window( HWND owner
, BOOL force_managed
)
1128 struct x11drv_win_data
*data
;
1130 if (!owner
) return 0;
1132 if (!(data
= X11DRV_get_win_data( owner
)))
1134 if (GetWindowThreadProcessId( owner
, NULL
) != GetCurrentThreadId() ||
1135 !(data
= X11DRV_create_win_data( owner
)))
1136 return (Window
)GetPropA( owner
, whole_window_prop
);
1138 else if (!data
->managed
&& force_managed
) /* make it managed */
1140 SetWindowPos( owner
, 0, 0, 0, 0, 0,
1141 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOMOVE
|
1142 SWP_NOREDRAW
| SWP_DEFERERASE
| SWP_NOSENDCHANGING
| SWP_STATECHANGED
);
1144 return data
->whole_window
;
1148 /***********************************************************************
1151 * Set the window manager hints for a newly-created window
1153 static void set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
1155 Window group_leader
= data
->whole_window
;
1156 Window owner_win
= 0;
1158 DWORD style
, ex_style
;
1161 if (data
->hwnd
== GetDesktopWindow())
1163 /* force some styles for the desktop to get the correct decorations */
1164 style
= WS_POPUP
| WS_VISIBLE
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
1165 ex_style
= WS_EX_APPWINDOW
;
1170 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1171 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
1172 owner
= GetWindow( data
->hwnd
, GW_OWNER
);
1173 if ((owner_win
= get_owner_whole_window( owner
, data
->managed
))) group_leader
= owner_win
;
1178 if (owner_win
) XSetTransientForHint( display
, data
->whole_window
, owner_win
);
1181 set_size_hints( display
, data
, style
);
1182 set_mwm_hints( display
, data
, style
, ex_style
);
1184 /* Only use dialog type for owned popups. Metacity allows making fullscreen
1185 * only normal windows, and doesn't handle correctly TRANSIENT_FOR hint for
1186 * dialogs owned by fullscreen windows.
1188 if ((style
& WS_POPUP
) && owner
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
1189 else window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
1191 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
1192 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
1197 data
->wm_hints
->flags
|= InputHint
| StateHint
| WindowGroupHint
;
1198 data
->wm_hints
->input
= !use_take_focus
&& !(style
& WS_DISABLED
);
1199 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
1200 data
->wm_hints
->window_group
= group_leader
;
1201 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
1204 wine_tsx11_unlock();
1208 /***********************************************************************
1211 Window
init_clip_window(void)
1213 struct x11drv_thread_data
*data
= x11drv_init_thread_data();
1215 if (!data
->clip_window
&&
1216 (data
->clip_window
= (Window
)GetPropA( GetDesktopWindow(), clip_window_prop
)))
1219 XSelectInput( data
->display
, data
->clip_window
, StructureNotifyMask
);
1220 wine_tsx11_unlock();
1222 return data
->clip_window
;
1226 /***********************************************************************
1229 void update_user_time( Time time
)
1232 if (!user_time_window
)
1234 user_time_window
= XCreateWindow( gdi_display
, root_window
, -1, -1, 1, 1, 0, 0, InputOnly
,
1235 DefaultVisual(gdi_display
,DefaultScreen(gdi_display
)), 0, NULL
);
1236 TRACE( "user time window %lx\n", user_time_window
);
1238 if (time
&& (!last_user_time
|| (long)(time
- last_user_time
) > 0))
1240 last_user_time
= time
;
1241 XChangeProperty( gdi_display
, user_time_window
, x11drv_atom(_NET_WM_USER_TIME
),
1242 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&time
, 1 );
1244 wine_tsx11_unlock();
1247 /***********************************************************************
1248 * update_net_wm_states
1250 void update_net_wm_states( Display
*display
, struct x11drv_win_data
*data
)
1252 static const unsigned int state_atoms
[NB_NET_WM_STATES
] =
1254 XATOM__NET_WM_STATE_FULLSCREEN
,
1255 XATOM__NET_WM_STATE_ABOVE
,
1256 XATOM__NET_WM_STATE_MAXIMIZED_VERT
,
1257 XATOM__NET_WM_STATE_SKIP_PAGER
,
1258 XATOM__NET_WM_STATE_SKIP_TASKBAR
1261 DWORD i
, style
, ex_style
, new_state
= 0;
1263 if (!data
->managed
) return;
1264 if (data
->whole_window
== root_window
) return;
1266 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1267 if (is_window_rect_fullscreen( &data
->whole_rect
))
1269 if ((style
& WS_MAXIMIZE
) && (style
& WS_CAPTION
) == WS_CAPTION
)
1270 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
1271 else if (!(style
& WS_MINIMIZE
))
1272 new_state
|= (1 << NET_WM_STATE_FULLSCREEN
);
1274 else if (style
& WS_MAXIMIZE
)
1275 new_state
|= (1 << NET_WM_STATE_MAXIMIZED
);
1277 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
1278 if (ex_style
& WS_EX_TOPMOST
)
1279 new_state
|= (1 << NET_WM_STATE_ABOVE
);
1280 if (ex_style
& (WS_EX_TOOLWINDOW
| WS_EX_NOACTIVATE
))
1281 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
) | (1 << NET_WM_STATE_SKIP_PAGER
);
1282 if (!(ex_style
& WS_EX_APPWINDOW
) && GetWindow( data
->hwnd
, GW_OWNER
))
1283 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
);
1285 if (!data
->mapped
) /* set the _NET_WM_STATE atom directly */
1287 Atom atoms
[NB_NET_WM_STATES
+1];
1290 for (i
= count
= 0; i
< NB_NET_WM_STATES
; i
++)
1292 if (!(new_state
& (1 << i
))) continue;
1293 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
1294 i
, data
->hwnd
, data
->whole_window
);
1295 atoms
[count
++] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
1296 if (state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
)
1297 atoms
[count
++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
);
1300 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_NET_WM_STATE
), XA_ATOM
,
1301 32, PropModeReplace
, (unsigned char *)atoms
, count
);
1302 wine_tsx11_unlock();
1304 else /* ask the window manager to do it for us */
1308 xev
.xclient
.type
= ClientMessage
;
1309 xev
.xclient
.window
= data
->whole_window
;
1310 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
1311 xev
.xclient
.serial
= 0;
1312 xev
.xclient
.display
= display
;
1313 xev
.xclient
.send_event
= True
;
1314 xev
.xclient
.format
= 32;
1315 xev
.xclient
.data
.l
[3] = 1;
1317 for (i
= 0; i
< NB_NET_WM_STATES
; i
++)
1319 if (!((data
->net_wm_state
^ new_state
) & (1 << i
))) continue; /* unchanged */
1321 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1322 i
, data
->hwnd
, data
->whole_window
,
1323 (new_state
& (1 << i
)) != 0, (data
->net_wm_state
& (1 << i
)) != 0 );
1325 xev
.xclient
.data
.l
[0] = (new_state
& (1 << i
)) ? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
1326 xev
.xclient
.data
.l
[1] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
1327 xev
.xclient
.data
.l
[2] = ((state_atoms
[i
] == XATOM__NET_WM_STATE_MAXIMIZED_VERT
) ?
1328 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ
) : 0);
1330 XSendEvent( display
, root_window
, False
,
1331 SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
1332 wine_tsx11_unlock();
1335 data
->net_wm_state
= new_state
;
1339 /***********************************************************************
1342 static void set_xembed_flags( Display
*display
, struct x11drv_win_data
*data
, unsigned long flags
)
1344 unsigned long info
[2];
1346 if (!data
->whole_window
) return;
1348 info
[0] = 0; /* protocol version */
1351 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_XEMBED_INFO
),
1352 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
, (unsigned char*)info
, 2 );
1353 wine_tsx11_unlock();
1357 /***********************************************************************
1360 static void map_window( Display
*display
, struct x11drv_win_data
*data
, DWORD new_style
)
1362 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1364 remove_startup_notification( display
, data
->whole_window
);
1366 wait_for_withdrawn_state( display
, data
, TRUE
);
1368 if (!data
->embedded
)
1370 update_net_wm_states( display
, data
);
1371 sync_window_style( display
, data
);
1373 XMapWindow( display
, data
->whole_window
);
1374 wine_tsx11_unlock();
1376 else set_xembed_flags( display
, data
, XEMBED_MAPPED
);
1378 data
->mapped
= TRUE
;
1379 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
1383 /***********************************************************************
1386 static void unmap_window( Display
*display
, struct x11drv_win_data
*data
)
1388 TRACE( "win %p/%lx\n", data
->hwnd
, data
->whole_window
);
1390 if (!data
->embedded
)
1392 wait_for_withdrawn_state( display
, data
, FALSE
);
1394 if (data
->managed
) XWithdrawWindow( display
, data
->whole_window
, DefaultScreen(display
) );
1395 else XUnmapWindow( display
, data
->whole_window
);
1396 wine_tsx11_unlock();
1398 else set_xembed_flags( display
, data
, 0 );
1400 data
->mapped
= FALSE
;
1401 data
->net_wm_state
= 0;
1405 /***********************************************************************
1406 * make_window_embedded
1408 void make_window_embedded( Display
*display
, struct x11drv_win_data
*data
)
1410 BOOL was_mapped
= data
->mapped
;
1411 /* the window cannot be mapped before being embedded */
1412 if (data
->mapped
) unmap_window( display
, data
);
1414 data
->embedded
= TRUE
;
1415 data
->managed
= TRUE
;
1416 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1417 sync_window_style( display
, data
);
1420 map_window( display
, data
, 0 );
1422 set_xembed_flags( display
, data
, 0 );
1426 /***********************************************************************
1427 * X11DRV_window_to_X_rect
1429 * Convert a rect from client to X window coordinates
1431 static void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1435 if (!data
->managed
) return;
1436 if (IsRectEmpty( rect
)) return;
1438 get_x11_rect_offset( data
, &rc
);
1440 rect
->left
-= rc
.left
;
1441 rect
->right
-= rc
.right
;
1442 rect
->top
-= rc
.top
;
1443 rect
->bottom
-= rc
.bottom
;
1444 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1445 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1449 /***********************************************************************
1450 * X11DRV_X_to_window_rect
1452 * Opposite of X11DRV_window_to_X_rect
1454 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1458 if (!data
->managed
) return;
1459 if (IsRectEmpty( rect
)) return;
1461 get_x11_rect_offset( data
, &rc
);
1463 rect
->left
+= rc
.left
;
1464 rect
->right
+= rc
.right
;
1465 rect
->top
+= rc
.top
;
1466 rect
->bottom
+= rc
.bottom
;
1467 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1468 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1472 /***********************************************************************
1473 * sync_window_position
1475 * Synchronize the X window position with the Windows one
1477 static void sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
1478 UINT swp_flags
, const RECT
*old_window_rect
,
1479 const RECT
*old_whole_rect
, const RECT
*old_client_rect
)
1481 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1482 DWORD ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
1483 XWindowChanges changes
;
1484 unsigned int mask
= 0;
1486 if (data
->managed
&& data
->iconic
) return;
1488 /* resizing a managed maximized window is not allowed */
1489 if (!(style
& WS_MAXIMIZE
) || !data
->managed
)
1491 changes
.width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
1492 changes
.height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
1493 /* if window rect is empty force size to 1x1 */
1494 if (changes
.width
<= 0 || changes
.height
<= 0) changes
.width
= changes
.height
= 1;
1495 if (changes
.width
> 65535) changes
.width
= 65535;
1496 if (changes
.height
> 65535) changes
.height
= 65535;
1497 mask
|= CWWidth
| CWHeight
;
1500 /* only the size is allowed to change for the desktop window */
1501 if (data
->whole_window
!= root_window
)
1503 changes
.x
= data
->whole_rect
.left
- virtual_screen_rect
.left
;
1504 changes
.y
= data
->whole_rect
.top
- virtual_screen_rect
.top
;
1508 if (!(swp_flags
& SWP_NOZORDER
) || (swp_flags
& SWP_SHOWWINDOW
))
1510 /* find window that this one must be after */
1511 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
1512 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
1513 prev
= GetWindow( prev
, GW_HWNDPREV
);
1514 if (!prev
) /* top child */
1516 changes
.stack_mode
= Above
;
1517 mask
|= CWStackMode
;
1519 /* should use stack_mode Below but most window managers don't get it right */
1520 /* and Above with a sibling doesn't work so well either, so we ignore it */
1524 set_size_hints( display
, data
, style
);
1525 set_mwm_hints( display
, data
, style
, ex_style
);
1526 data
->configure_serial
= NextRequest( display
);
1527 XReconfigureWMWindow( display
, data
->whole_window
,
1528 DefaultScreen(display
), mask
, &changes
);
1529 wine_tsx11_unlock();
1530 #ifdef HAVE_LIBXSHAPE
1531 if (IsRectEmpty( old_window_rect
) != IsRectEmpty( &data
->window_rect
))
1532 sync_window_region( display
, data
, (HRGN
)1 );
1535 int old_x_offset
= old_window_rect
->left
- old_whole_rect
->left
;
1536 int old_y_offset
= old_window_rect
->top
- old_whole_rect
->top
;
1537 int new_x_offset
= data
->window_rect
.left
- data
->whole_rect
.left
;
1538 int new_y_offset
= data
->window_rect
.top
- data
->whole_rect
.top
;
1539 if (old_x_offset
!= new_x_offset
|| old_y_offset
!= new_y_offset
)
1542 XShapeOffsetShape( display
, data
->whole_window
, ShapeBounding
,
1543 new_x_offset
- old_x_offset
, new_y_offset
- old_y_offset
);
1544 wine_tsx11_unlock();
1549 TRACE( "win %p/%lx pos %d,%d,%dx%d after %lx changes=%x serial=%lu\n",
1550 data
->hwnd
, data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1551 data
->whole_rect
.right
- data
->whole_rect
.left
,
1552 data
->whole_rect
.bottom
- data
->whole_rect
.top
,
1553 changes
.sibling
, mask
, data
->configure_serial
);
1557 /***********************************************************************
1558 * sync_client_position
1560 * Synchronize the X client window position with the Windows one
1562 static void sync_client_position( Display
*display
, struct x11drv_win_data
*data
,
1563 UINT swp_flags
, const RECT
*old_client_rect
,
1564 const RECT
*old_whole_rect
)
1567 XWindowChanges changes
;
1568 RECT old
= *old_client_rect
;
1569 RECT
new = data
->client_rect
;
1571 OffsetRect( &old
, -old_whole_rect
->left
, -old_whole_rect
->top
);
1572 OffsetRect( &new, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
1573 if (!(mask
= get_window_changes( &changes
, &old
, &new ))) return;
1575 if (data
->client_window
)
1577 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1578 data
->client_window
, new.left
, new.top
,
1579 new.right
- new.left
, new.bottom
- new.top
, mask
);
1581 XConfigureWindow( display
, data
->client_window
, mask
, &changes
);
1582 wine_tsx11_unlock();
1585 if (data
->gl_drawable
&& (mask
& (CWWidth
|CWHeight
))) sync_gl_drawable( data
);
1589 /***********************************************************************
1592 * Move the window bits when a window is moved.
1594 static void move_window_bits( struct x11drv_win_data
*data
, const RECT
*old_rect
, const RECT
*new_rect
,
1595 const RECT
*old_client_rect
)
1597 RECT src_rect
= *old_rect
;
1598 RECT dst_rect
= *new_rect
;
1599 HDC hdc_src
, hdc_dst
;
1604 if (!data
->whole_window
)
1606 OffsetRect( &dst_rect
, -data
->window_rect
.left
, -data
->window_rect
.top
);
1607 parent
= GetAncestor( data
->hwnd
, GA_PARENT
);
1608 hdc_src
= GetDCEx( parent
, 0, DCX_CACHE
);
1609 hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
1613 OffsetRect( &dst_rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
1614 /* make src rect relative to the old position of the window */
1615 OffsetRect( &src_rect
, -old_client_rect
->left
, -old_client_rect
->top
);
1616 if (dst_rect
.left
== src_rect
.left
&& dst_rect
.top
== src_rect
.top
) return;
1617 hdc_src
= hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
);
1620 rgn
= CreateRectRgnIndirect( &dst_rect
);
1621 SelectClipRgn( hdc_dst
, rgn
);
1622 DeleteObject( rgn
);
1623 ExcludeUpdateRgn( hdc_dst
, data
->hwnd
);
1625 code
= X11DRV_START_EXPOSURES
;
1626 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
1628 TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n",
1629 data
->hwnd
, data
->whole_window
, data
->client_window
,
1630 wine_dbgstr_rect(&src_rect
), wine_dbgstr_rect(&dst_rect
) );
1631 BitBlt( hdc_dst
, dst_rect
.left
, dst_rect
.top
,
1632 dst_rect
.right
- dst_rect
.left
, dst_rect
.bottom
- dst_rect
.top
,
1633 hdc_src
, src_rect
.left
, src_rect
.top
, SRCCOPY
);
1636 code
= X11DRV_END_EXPOSURES
;
1637 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, sizeof(rgn
), (LPSTR
)&rgn
);
1639 ReleaseDC( data
->hwnd
, hdc_dst
);
1640 if (hdc_src
!= hdc_dst
) ReleaseDC( parent
, hdc_src
);
1644 if (!data
->whole_window
)
1646 /* map region to client rect since we are using DCX_WINDOW */
1647 OffsetRgn( rgn
, data
->window_rect
.left
- data
->client_rect
.left
,
1648 data
->window_rect
.top
- data
->client_rect
.top
);
1649 RedrawWindow( data
->hwnd
, NULL
, rgn
,
1650 RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
1652 else RedrawWindow( data
->hwnd
, NULL
, rgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1653 DeleteObject( rgn
);
1658 /**********************************************************************
1659 * create_whole_window
1661 * Create the whole X window for a given window
1663 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1666 XSetWindowAttributes attr
;
1670 DWORD layered_flags
;
1673 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1675 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1676 data
->managed
= TRUE
;
1677 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1680 if ((win_rgn
= CreateRectRgn( 0, 0, 0, 0 )) &&
1681 GetWindowRgn( data
->hwnd
, win_rgn
) == ERROR
)
1683 DeleteObject( win_rgn
);
1686 data
->shaped
= (win_rgn
!= 0);
1688 mask
= get_window_attributes( display
, data
, &attr
);
1690 data
->whole_rect
= data
->window_rect
;
1691 X11DRV_window_to_X_rect( data
, &data
->whole_rect
);
1692 if (!(cx
= data
->whole_rect
.right
- data
->whole_rect
.left
)) cx
= 1;
1693 else if (cx
> 65535) cx
= 65535;
1694 if (!(cy
= data
->whole_rect
.bottom
- data
->whole_rect
.top
)) cy
= 1;
1695 else if (cy
> 65535) cy
= 65535;
1698 data
->whole_window
= XCreateWindow( display
, root_window
,
1699 data
->whole_rect
.left
- virtual_screen_rect
.left
,
1700 data
->whole_rect
.top
- virtual_screen_rect
.top
,
1701 cx
, cy
, 0, screen_depth
, InputOutput
,
1702 visual
, mask
, &attr
);
1704 if (data
->whole_window
) XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1705 wine_tsx11_unlock();
1707 if (!data
->whole_window
) goto done
;
1709 if (!create_client_window( display
, data
, NULL
))
1712 XDeleteContext( display
, data
->whole_window
, winContext
);
1713 XDestroyWindow( display
, data
->whole_window
);
1714 data
->whole_window
= 0;
1715 wine_tsx11_unlock();
1719 set_initial_wm_hints( display
, data
);
1720 set_wm_hints( display
, data
);
1722 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1724 /* set the window text */
1725 if (!InternalGetWindowText( data
->hwnd
, text
, sizeof(text
)/sizeof(WCHAR
) )) text
[0] = 0;
1726 sync_window_text( display
, data
->whole_window
, text
);
1728 /* set the window region */
1729 if (win_rgn
|| IsRectEmpty( &data
->window_rect
)) sync_window_region( display
, data
, win_rgn
);
1731 /* set the window opacity */
1732 if (!GetLayeredWindowAttributes( data
->hwnd
, &key
, &alpha
, &layered_flags
)) layered_flags
= 0;
1733 sync_window_opacity( display
, data
->whole_window
, key
, alpha
, layered_flags
);
1735 init_clip_window(); /* make sure the clip window is initialized in this thread */
1738 XFlush( display
); /* make sure the window exists before we start painting to it */
1739 wine_tsx11_unlock();
1741 sync_window_cursor( data
->whole_window
);
1744 if (win_rgn
) DeleteObject( win_rgn
);
1745 return data
->whole_window
;
1749 /**********************************************************************
1750 * destroy_whole_window
1752 * Destroy the whole X window for a given window.
1754 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
, BOOL already_destroyed
)
1756 if (!data
->whole_window
)
1760 Window xwin
= (Window
)GetPropA( data
->hwnd
, foreign_window_prop
);
1764 if (!already_destroyed
) XSelectInput( display
, xwin
, 0 );
1765 XDeleteContext( display
, xwin
, winContext
);
1766 wine_tsx11_unlock();
1767 RemovePropA( data
->hwnd
, foreign_window_prop
);
1774 TRACE( "win %p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1776 XDeleteContext( display
, data
->whole_window
, winContext
);
1777 XDeleteContext( display
, data
->client_window
, winContext
);
1778 if (!already_destroyed
) XDestroyWindow( display
, data
->whole_window
);
1779 data
->whole_window
= data
->client_window
= 0;
1780 data
->wm_state
= WithdrawnState
;
1781 data
->net_wm_state
= 0;
1782 data
->mapped
= FALSE
;
1785 XUnsetICFocus( data
->xic
);
1786 XDestroyIC( data
->xic
);
1789 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1791 XFree( data
->wm_hints
);
1792 data
->wm_hints
= NULL
;
1793 wine_tsx11_unlock();
1794 RemovePropA( data
->hwnd
, whole_window_prop
);
1795 RemovePropA( data
->hwnd
, client_window_prop
);
1799 /*****************************************************************
1800 * SetWindowText (X11DRV.@)
1802 void CDECL
X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1806 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(gdi_display
))
1808 Display
*display
= thread_init_display();
1809 sync_window_text( display
, win
, text
);
1814 /***********************************************************************
1815 * SetWindowStyle (X11DRV.@)
1817 * Update the X state of a window to reflect a style change
1819 void CDECL
X11DRV_SetWindowStyle( HWND hwnd
, INT offset
, STYLESTRUCT
*style
)
1821 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1824 if (hwnd
== GetDesktopWindow()) return;
1825 changed
= style
->styleNew
^ style
->styleOld
;
1827 /* if WS_VISIBLE was set through WM_SETREDRAW, map the window if it's the first time */
1828 if (offset
== GWL_STYLE
&& (changed
& WS_VISIBLE
) && (style
->styleNew
& WS_VISIBLE
) && !data
)
1830 if (!(data
= X11DRV_create_win_data( hwnd
))) return;
1832 if (data
->whole_window
&& is_window_rect_mapped( &data
->window_rect
))
1834 Display
*display
= thread_display();
1835 set_wm_hints( display
, data
);
1836 if (!data
->mapped
) map_window( display
, data
, style
->styleNew
);
1839 if (!data
|| !data
->whole_window
) return;
1841 if (offset
== GWL_STYLE
&& (changed
& WS_DISABLED
))
1842 set_wm_hints( thread_display(), data
);
1844 if (offset
== GWL_EXSTYLE
&& (changed
& WS_EX_LAYERED
)) /* changing WS_EX_LAYERED resets attributes */
1845 sync_window_opacity( thread_display(), data
->whole_window
, 0, 0, 0 );
1849 /***********************************************************************
1850 * DestroyWindow (X11DRV.@)
1852 void CDECL
X11DRV_DestroyWindow( HWND hwnd
)
1854 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1855 struct x11drv_win_data
*data
;
1857 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1862 destroy_glxpixmap(gdi_display
, data
->gl_drawable
);
1863 XFreePixmap(gdi_display
, data
->pixmap
);
1864 wine_tsx11_unlock();
1866 else if (data
->gl_drawable
)
1869 XDestroyWindow(gdi_display
, data
->gl_drawable
);
1870 wine_tsx11_unlock();
1873 destroy_whole_window( thread_data
->display
, data
, FALSE
);
1874 destroy_icon_window( thread_data
->display
, data
);
1879 XFreeColormap( thread_data
->display
, data
->colormap
);
1880 wine_tsx11_unlock();
1883 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1884 if (thread_data
->last_xic_hwnd
== hwnd
) thread_data
->last_xic_hwnd
= 0;
1885 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1886 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1888 XDeleteContext( thread_data
->display
, (XID
)hwnd
, win_data_context
);
1889 wine_tsx11_unlock();
1890 HeapFree( GetProcessHeap(), 0, data
);
1894 /***********************************************************************
1895 * X11DRV_DestroyNotify
1897 void X11DRV_DestroyNotify( HWND hwnd
, XEvent
*event
)
1899 Display
*display
= event
->xdestroywindow
.display
;
1900 struct x11drv_win_data
*data
;
1902 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1903 if (!data
->embedded
) FIXME( "window %p/%lx destroyed from the outside\n", hwnd
, data
->whole_window
);
1905 destroy_whole_window( display
, data
, TRUE
);
1906 if (data
->embedded
) SendMessageW( hwnd
, WM_CLOSE
, 0, 0 );
1910 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1912 struct x11drv_win_data
*data
;
1914 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
1918 if (!winContext
) winContext
= XUniqueContext();
1919 if (!win_data_context
) win_data_context
= XUniqueContext();
1920 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1921 wine_tsx11_unlock();
1927 /* initialize the desktop window id in the desktop manager process */
1928 static struct x11drv_win_data
*create_desktop_win_data( Display
*display
, HWND hwnd
)
1930 struct x11drv_win_data
*data
;
1932 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1933 data
->whole_window
= data
->client_window
= root_window
;
1934 data
->managed
= TRUE
;
1935 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1936 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1937 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)root_window
);
1938 set_initial_wm_hints( display
, data
);
1942 /**********************************************************************
1943 * CreateDesktopWindow (X11DRV.@)
1945 BOOL CDECL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1947 unsigned int width
, height
;
1949 /* retrieve the real size of the desktop */
1950 SERVER_START_REQ( get_window_rectangles
)
1952 req
->handle
= wine_server_user_handle( hwnd
);
1953 req
->relative
= COORDS_CLIENT
;
1954 wine_server_call( req
);
1955 width
= reply
->window
.right
;
1956 height
= reply
->window
.bottom
;
1960 if (!width
&& !height
) /* not initialized yet */
1962 SERVER_START_REQ( set_window_pos
)
1964 req
->handle
= wine_server_user_handle( hwnd
);
1966 req
->flags
= SWP_NOZORDER
;
1967 req
->window
.left
= virtual_screen_rect
.left
;
1968 req
->window
.top
= virtual_screen_rect
.top
;
1969 req
->window
.right
= virtual_screen_rect
.right
;
1970 req
->window
.bottom
= virtual_screen_rect
.bottom
;
1971 req
->client
= req
->window
;
1972 wine_server_call( req
);
1978 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1979 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1985 /**********************************************************************
1986 * CreateWindow (X11DRV.@)
1988 BOOL CDECL
X11DRV_CreateWindow( HWND hwnd
)
1990 if (hwnd
== GetDesktopWindow())
1992 struct x11drv_thread_data
*data
= x11drv_init_thread_data();
1993 XSetWindowAttributes attr
;
1995 if (root_window
!= DefaultRootWindow( gdi_display
))
1997 /* the desktop win data can't be created lazily */
1998 if (!create_desktop_win_data( data
->display
, hwnd
)) return FALSE
;
2001 /* create the cursor clipping window */
2002 attr
.override_redirect
= TRUE
;
2003 attr
.event_mask
= StructureNotifyMask
| FocusChangeMask
;
2005 data
->clip_window
= XCreateWindow( data
->display
, root_window
, 0, 0, 1, 1, 0, 0,
2006 InputOnly
, visual
, CWOverrideRedirect
| CWEventMask
, &attr
);
2007 wine_tsx11_unlock();
2008 SetPropA( hwnd
, clip_window_prop
, (HANDLE
)data
->clip_window
);
2014 /***********************************************************************
2015 * X11DRV_get_win_data
2017 * Return the X11 data structure associated with a window.
2019 struct x11drv_win_data
*X11DRV_get_win_data( HWND hwnd
)
2021 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2024 if (!thread_data
) return NULL
;
2025 if (!hwnd
) return NULL
;
2026 if (XFindContext( thread_data
->display
, (XID
)hwnd
, win_data_context
, &data
)) data
= NULL
;
2027 return (struct x11drv_win_data
*)data
;
2031 /***********************************************************************
2032 * X11DRV_create_win_data
2034 * Create an X11 data window structure for an existing window.
2036 struct x11drv_win_data
*X11DRV_create_win_data( HWND hwnd
)
2039 struct x11drv_win_data
*data
;
2042 if (!(parent
= GetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop */
2044 /* don't create win data for HWND_MESSAGE windows */
2045 if (parent
!= GetDesktopWindow() && !GetAncestor( parent
, GA_PARENT
)) return NULL
;
2047 display
= thread_init_display();
2048 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
2050 GetWindowRect( hwnd
, &data
->window_rect
);
2051 MapWindowPoints( 0, parent
, (POINT
*)&data
->window_rect
, 2 );
2052 data
->whole_rect
= data
->window_rect
;
2053 GetClientRect( hwnd
, &data
->client_rect
);
2054 MapWindowPoints( hwnd
, parent
, (POINT
*)&data
->client_rect
, 2 );
2056 if (parent
== GetDesktopWindow())
2058 if (!create_whole_window( display
, data
))
2060 HeapFree( GetProcessHeap(), 0, data
);
2063 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
2064 hwnd
, data
->whole_window
, data
->client_window
, wine_dbgstr_rect( &data
->window_rect
),
2065 wine_dbgstr_rect( &data
->whole_rect
), wine_dbgstr_rect( &data
->client_rect
));
2071 /* window procedure for foreign windows */
2072 static LRESULT WINAPI
foreign_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2076 case WM_WINDOWPOSCHANGED
:
2077 update_systray_balloon_position();
2079 case WM_PARENTNOTIFY
:
2080 if (LOWORD(wparam
) == WM_DESTROY
)
2082 TRACE( "%p: got parent notify destroy for win %lx\n", hwnd
, lparam
);
2083 PostMessageW( hwnd
, WM_CLOSE
, 0, 0 ); /* so that we come back here once the child is gone */
2087 if (GetWindow( hwnd
, GW_CHILD
)) return 0; /* refuse to die if we still have children */
2090 return DefWindowProcW( hwnd
, msg
, wparam
, lparam
);
2094 /***********************************************************************
2095 * create_foreign_window
2097 * Create a foreign window for the specified X window and its ancestors
2099 HWND
create_foreign_window( Display
*display
, Window xwin
)
2101 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};
2102 static BOOL class_registered
;
2103 struct x11drv_win_data
*data
;
2105 Window xparent
, xroot
;
2107 unsigned int nchildren
;
2108 XWindowAttributes attr
;
2109 DWORD style
= WS_CLIPCHILDREN
;
2111 if (!class_registered
)
2115 memset( &class, 0, sizeof(class) );
2116 class.cbSize
= sizeof(class);
2117 class.lpfnWndProc
= foreign_window_proc
;
2118 class.lpszClassName
= classW
;
2119 if (!RegisterClassExW( &class ) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS
)
2121 ERR( "Could not register foreign window class\n" );
2124 class_registered
= TRUE
;
2128 if (XFindContext( display
, xwin
, winContext
, (char **)&hwnd
)) hwnd
= 0;
2129 if (hwnd
) /* already created */
2131 wine_tsx11_unlock();
2135 XSelectInput( display
, xwin
, StructureNotifyMask
);
2136 if (!XGetWindowAttributes( display
, xwin
, &attr
) ||
2137 !XQueryTree( display
, xwin
, &xroot
, &xparent
, &xchildren
, &nchildren
))
2139 XSelectInput( display
, xwin
, 0 );
2140 wine_tsx11_unlock();
2144 wine_tsx11_unlock();
2146 if (xparent
== xroot
)
2148 parent
= GetDesktopWindow();
2150 attr
.x
+= virtual_screen_rect
.left
;
2151 attr
.y
+= virtual_screen_rect
.top
;
2155 parent
= create_foreign_window( display
, xparent
);
2159 hwnd
= CreateWindowW( classW
, NULL
, style
, attr
.x
, attr
.y
, attr
.width
, attr
.height
,
2160 parent
, 0, 0, NULL
);
2162 if (!(data
= alloc_win_data( display
, hwnd
)))
2164 DestroyWindow( hwnd
);
2167 SetRect( &data
->window_rect
, attr
.x
, attr
.y
, attr
.x
+ attr
.width
, attr
.y
+ attr
.height
);
2168 data
->whole_rect
= data
->client_rect
= data
->window_rect
;
2169 data
->whole_window
= data
->client_window
= 0;
2170 data
->embedded
= TRUE
;
2171 data
->mapped
= TRUE
;
2173 SetPropA( hwnd
, foreign_window_prop
, (HANDLE
)xwin
);
2175 XSaveContext( display
, xwin
, winContext
, (char *)data
->hwnd
);
2176 wine_tsx11_unlock();
2178 ShowWindow( hwnd
, SW_SHOW
);
2180 TRACE( "win %lx parent %p style %08x %s -> hwnd %p\n",
2181 xwin
, parent
, style
, wine_dbgstr_rect(&data
->window_rect
), hwnd
);
2187 /***********************************************************************
2188 * X11DRV_get_whole_window
2190 * Return the X window associated with the full area of a window
2192 Window
X11DRV_get_whole_window( HWND hwnd
)
2194 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2198 if (hwnd
== GetDesktopWindow()) return root_window
;
2199 return (Window
)GetPropA( hwnd
, whole_window_prop
);
2201 return data
->whole_window
;
2205 /***********************************************************************
2206 * X11DRV_get_client_window
2208 * Return the X window associated with the client area of a window
2210 static Window
X11DRV_get_client_window( HWND hwnd
)
2212 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2216 if (hwnd
== GetDesktopWindow()) return root_window
;
2217 return (Window
)GetPropA( hwnd
, client_window_prop
);
2219 return data
->client_window
;
2223 /***********************************************************************
2226 * Return the X input context associated with a window
2228 XIC
X11DRV_get_ic( HWND hwnd
)
2230 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2233 if (!data
) return 0;
2235 x11drv_thread_data()->last_xic_hwnd
= hwnd
;
2236 if (data
->xic
) return data
->xic
;
2237 if (!(xim
= x11drv_thread_data()->xim
)) return 0;
2238 return X11DRV_CreateIC( xim
, data
);
2242 /***********************************************************************
2243 * X11DRV_GetDC (X11DRV.@)
2245 void CDECL
X11DRV_GetDC( HDC hdc
, HWND hwnd
, HWND top
, const RECT
*win_rect
,
2246 const RECT
*top_rect
, DWORD flags
)
2248 struct x11drv_escape_set_drawable escape
;
2249 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2252 escape
.code
= X11DRV_SET_DRAWABLE
;
2253 escape
.mode
= IncludeInferiors
;
2254 escape
.fbconfig_id
= 0;
2255 escape
.gl_drawable
= 0;
2257 escape
.gl_copy
= FALSE
;
2259 escape
.dc_rect
.left
= win_rect
->left
- top_rect
->left
;
2260 escape
.dc_rect
.top
= win_rect
->top
- top_rect
->top
;
2261 escape
.dc_rect
.right
= win_rect
->right
- top_rect
->left
;
2262 escape
.dc_rect
.bottom
= win_rect
->bottom
- top_rect
->top
;
2263 escape
.drawable_rect
.left
= top_rect
->left
;
2264 escape
.drawable_rect
.top
= top_rect
->top
;
2265 escape
.drawable_rect
.right
= top_rect
->right
;
2266 escape
.drawable_rect
.bottom
= top_rect
->bottom
;
2270 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
2271 /* GL draws to the client area even for window DCs */
2272 escape
.gl_drawable
= data
? data
->client_window
: X11DRV_get_client_window( hwnd
);
2273 if (data
&& IsIconic( hwnd
) && data
->icon_window
)
2275 escape
.drawable
= data
->icon_window
;
2277 else if (flags
& DCX_WINDOW
)
2278 escape
.drawable
= data
? data
->whole_window
: X11DRV_get_whole_window( hwnd
);
2280 escape
.drawable
= escape
.gl_drawable
;
2282 /* special case: when repainting the root window, clip out top-level windows */
2283 if (data
&& data
->whole_window
== root_window
) escape
.mode
= ClipByChildren
;
2287 /* find the first ancestor that has a drawable */
2288 for (parent
= hwnd
; parent
&& parent
!= top
; parent
= GetAncestor( parent
, GA_PARENT
))
2289 if ((escape
.drawable
= X11DRV_get_client_window( parent
))) break;
2291 if (escape
.drawable
)
2293 POINT pt
= { 0, 0 };
2294 MapWindowPoints( top
, parent
, &pt
, 1 );
2295 OffsetRect( &escape
.dc_rect
, pt
.x
, pt
.y
);
2296 OffsetRect( &escape
.drawable_rect
, -pt
.x
, -pt
.y
);
2298 else escape
.drawable
= X11DRV_get_client_window( top
);
2300 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
2301 escape
.gl_drawable
= data
? data
->gl_drawable
: (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
2302 escape
.pixmap
= data
? data
->pixmap
: (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
2303 escape
.gl_copy
= (escape
.gl_drawable
!= 0);
2304 if (flags
& DCX_CLIPCHILDREN
) escape
.mode
= ClipByChildren
;
2307 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2311 /***********************************************************************
2312 * X11DRV_ReleaseDC (X11DRV.@)
2314 void CDECL
X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
2316 struct x11drv_escape_set_drawable escape
;
2318 escape
.code
= X11DRV_SET_DRAWABLE
;
2319 escape
.drawable
= root_window
;
2320 escape
.mode
= IncludeInferiors
;
2321 escape
.drawable_rect
= virtual_screen_rect
;
2322 SetRect( &escape
.dc_rect
, 0, 0, virtual_screen_rect
.right
- virtual_screen_rect
.left
,
2323 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
);
2324 OffsetRect( &escape
.dc_rect
, -escape
.drawable_rect
.left
, -escape
.drawable_rect
.top
);
2325 escape
.fbconfig_id
= 0;
2326 escape
.gl_drawable
= 0;
2328 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
2332 /***********************************************************************
2333 * SetCapture (X11DRV.@)
2335 void CDECL
X11DRV_SetCapture( HWND hwnd
, UINT flags
)
2337 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2339 if (!thread_data
) return;
2340 if (!(flags
& (GUI_INMOVESIZE
| GUI_INMENUMODE
))) return;
2344 Window grab_win
= X11DRV_get_client_window( GetAncestor( hwnd
, GA_ROOT
) );
2346 if (!grab_win
) return;
2348 XFlush( gdi_display
);
2349 XGrabPointer( thread_data
->display
, grab_win
, False
,
2350 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
2351 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
);
2352 wine_tsx11_unlock();
2353 thread_data
->grab_window
= grab_win
;
2355 else /* release capture */
2358 XFlush( gdi_display
);
2359 XUngrabPointer( thread_data
->display
, CurrentTime
);
2360 XFlush( thread_data
->display
);
2361 wine_tsx11_unlock();
2362 thread_data
->grab_window
= None
;
2367 /*****************************************************************
2368 * SetParent (X11DRV.@)
2370 void CDECL
X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
2372 Display
*display
= thread_display();
2373 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2376 if (parent
== old_parent
) return;
2377 if (data
->embedded
) return;
2379 if (parent
!= GetDesktopWindow()) /* a child window */
2381 if (old_parent
== GetDesktopWindow())
2383 /* destroy the old X windows */
2384 destroy_whole_window( display
, data
, FALSE
);
2385 destroy_icon_window( display
, data
);
2388 data
->managed
= FALSE
;
2389 RemovePropA( data
->hwnd
, managed_prop
);
2393 else /* new top level window */
2395 /* FIXME: we ignore errors since we can't really recover anyway */
2396 create_whole_window( display
, data
);
2401 /*****************************************************************
2402 * SetFocus (X11DRV.@)
2406 void CDECL
X11DRV_SetFocus( HWND hwnd
)
2408 Display
*display
= thread_display();
2409 struct x11drv_win_data
*data
;
2410 XWindowChanges changes
;
2413 if (!(hwnd
= GetAncestor( hwnd
, GA_ROOT
))) return;
2414 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
2415 if (data
->managed
|| !data
->whole_window
) return;
2417 if (EVENT_x11_time_to_win32_time(0))
2418 /* ICCCM says don't use CurrentTime, so try to use last message time if possible */
2419 /* FIXME: this is not entirely correct */
2420 timestamp
= GetMessageTime() - EVENT_x11_time_to_win32_time(0);
2422 timestamp
= CurrentTime
;
2424 /* Set X focus and install colormap */
2426 changes
.stack_mode
= Above
;
2427 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
2428 XSetInputFocus( display
, data
->whole_window
, RevertToParent
, timestamp
);
2429 wine_tsx11_unlock();
2433 /***********************************************************************
2434 * WindowPosChanging (X11DRV.@)
2436 void CDECL
X11DRV_WindowPosChanging( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
2437 const RECT
*window_rect
, const RECT
*client_rect
, RECT
*visible_rect
)
2439 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2440 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2444 /* create the win data if the window is being made visible */
2445 if (!(style
& WS_VISIBLE
) && !(swp_flags
& SWP_SHOWWINDOW
)) return;
2446 if (!(data
= X11DRV_create_win_data( hwnd
))) return;
2449 /* check if we need to switch the window to managed */
2450 if (!data
->managed
&& data
->whole_window
&& is_window_managed( hwnd
, swp_flags
, window_rect
))
2452 TRACE( "making win %p/%lx managed\n", hwnd
, data
->whole_window
);
2453 if (data
->mapped
) unmap_window( thread_display(), data
);
2454 data
->managed
= TRUE
;
2455 SetPropA( hwnd
, managed_prop
, (HANDLE
)1 );
2458 *visible_rect
= *window_rect
;
2459 X11DRV_window_to_X_rect( data
, visible_rect
);
2463 /***********************************************************************
2464 * WindowPosChanged (X11DRV.@)
2466 void CDECL
X11DRV_WindowPosChanged( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
2467 const RECT
*rectWindow
, const RECT
*rectClient
,
2468 const RECT
*visible_rect
, const RECT
*valid_rects
)
2470 struct x11drv_thread_data
*thread_data
;
2472 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2473 DWORD new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2474 RECT old_window_rect
, old_whole_rect
, old_client_rect
;
2479 thread_data
= x11drv_thread_data();
2480 display
= thread_data
->display
;
2482 old_window_rect
= data
->window_rect
;
2483 old_whole_rect
= data
->whole_rect
;
2484 old_client_rect
= data
->client_rect
;
2485 data
->window_rect
= *rectWindow
;
2486 data
->whole_rect
= *visible_rect
;
2487 data
->client_rect
= *rectClient
;
2489 TRACE( "win %p window %s client %s style %08x flags %08x\n",
2490 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
, swp_flags
);
2492 if (!IsRectEmpty( &valid_rects
[0] ))
2494 int x_offset
= old_whole_rect
.left
- data
->whole_rect
.left
;
2495 int y_offset
= old_whole_rect
.top
- data
->whole_rect
.top
;
2497 /* if all that happened is that the whole window moved, copy everything */
2498 if (!(swp_flags
& SWP_FRAMECHANGED
) &&
2499 old_whole_rect
.right
- data
->whole_rect
.right
== x_offset
&&
2500 old_whole_rect
.bottom
- data
->whole_rect
.bottom
== y_offset
&&
2501 old_client_rect
.left
- data
->client_rect
.left
== x_offset
&&
2502 old_client_rect
.right
- data
->client_rect
.right
== x_offset
&&
2503 old_client_rect
.top
- data
->client_rect
.top
== y_offset
&&
2504 old_client_rect
.bottom
- data
->client_rect
.bottom
== y_offset
&&
2505 !memcmp( &valid_rects
[0], &data
->client_rect
, sizeof(RECT
) ))
2507 /* if we have an X window the bits will be moved by the X server */
2508 if (!data
->whole_window
&& (x_offset
!= 0 || y_offset
!= 0))
2509 move_window_bits( data
, &old_whole_rect
, &data
->whole_rect
, &old_client_rect
);
2512 move_window_bits( data
, &valid_rects
[1], &valid_rects
[0], &old_client_rect
);
2516 XFlush( gdi_display
); /* make sure painting is done before we move the window */
2517 wine_tsx11_unlock();
2519 sync_client_position( display
, data
, swp_flags
, &old_client_rect
, &old_whole_rect
);
2521 if (!data
->whole_window
) return;
2523 /* check if we are currently processing an event relevant to this window */
2525 if (thread_data
->current_event
&& thread_data
->current_event
->xany
.window
== data
->whole_window
)
2526 event_type
= thread_data
->current_event
->type
;
2528 if (event_type
!= ConfigureNotify
&& event_type
!= PropertyNotify
&&
2529 event_type
!= GravityNotify
&& event_type
!= ReparentNotify
)
2530 event_type
= 0; /* ignore other events */
2532 if (data
->mapped
&& event_type
!= ReparentNotify
)
2534 if (((swp_flags
& SWP_HIDEWINDOW
) && !(new_style
& WS_VISIBLE
)) ||
2536 !is_window_rect_mapped( rectWindow
) && is_window_rect_mapped( &old_window_rect
)))
2537 unmap_window( display
, data
);
2540 /* don't change position if we are about to minimize or maximize a managed window */
2542 !(data
->managed
&& (swp_flags
& SWP_STATECHANGED
) && (new_style
& (WS_MINIMIZE
|WS_MAXIMIZE
))))
2543 sync_window_position( display
, data
, swp_flags
,
2544 &old_window_rect
, &old_whole_rect
, &old_client_rect
);
2546 if ((new_style
& WS_VISIBLE
) &&
2547 ((new_style
& WS_MINIMIZE
) || is_window_rect_mapped( rectWindow
)))
2549 if (!data
->mapped
|| (swp_flags
& (SWP_FRAMECHANGED
|SWP_STATECHANGED
)))
2550 set_wm_hints( display
, data
);
2554 map_window( display
, data
, new_style
);
2556 else if ((swp_flags
& SWP_STATECHANGED
) && (!data
->iconic
!= !(new_style
& WS_MINIMIZE
)))
2558 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
2559 TRACE( "changing win %p iconic state to %u\n", data
->hwnd
, data
->iconic
);
2562 XIconifyWindow( display
, data
->whole_window
, DefaultScreen(display
) );
2563 else if (is_window_rect_mapped( rectWindow
))
2564 XMapWindow( display
, data
->whole_window
);
2565 wine_tsx11_unlock();
2566 update_net_wm_states( display
, data
);
2568 else if (!event_type
)
2570 update_net_wm_states( display
, data
);
2575 XFlush( display
); /* make sure changes are done before we start painting again */
2576 wine_tsx11_unlock();
2580 /***********************************************************************
2581 * ShowWindow (X11DRV.@)
2583 UINT CDECL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
, RECT
*rect
, UINT swp
)
2586 unsigned int width
, height
, border
, depth
;
2588 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2589 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
2590 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2592 if (!data
|| !data
->whole_window
|| !data
->managed
|| !data
->mapped
|| data
->iconic
) return swp
;
2593 if (style
& WS_MINIMIZE
) return swp
;
2594 if (IsRectEmpty( rect
)) return swp
;
2596 /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */
2598 if (!thread_data
->current_event
|| thread_data
->current_event
->xany
.window
!= data
->whole_window
)
2601 if (thread_data
->current_event
->type
!= ConfigureNotify
&&
2602 thread_data
->current_event
->type
!= PropertyNotify
)
2605 TRACE( "win %p/%lx cmd %d at %s flags %08x\n",
2606 hwnd
, data
->whole_window
, cmd
, wine_dbgstr_rect(rect
), swp
);
2609 XGetGeometry( thread_data
->display
, data
->whole_window
,
2610 &root
, &x
, &y
, &width
, &height
, &border
, &depth
);
2611 XTranslateCoordinates( thread_data
->display
, data
->whole_window
, root
, 0, 0, &x
, &y
, &top
);
2612 wine_tsx11_unlock();
2615 rect
->right
= x
+ width
;
2616 rect
->bottom
= y
+ height
;
2617 OffsetRect( rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
2618 X11DRV_X_to_window_rect( data
, rect
);
2619 return swp
& ~(SWP_NOMOVE
| SWP_NOCLIENTMOVE
| SWP_NOSIZE
| SWP_NOCLIENTSIZE
);
2623 /**********************************************************************
2624 * SetWindowIcon (X11DRV.@)
2626 * hIcon or hIconSm has changed (or is being initialised for the
2627 * first time). Complete the X11 driver-specific initialisation
2628 * and set the window hints.
2630 * This is not entirely correct, may need to create
2631 * an icon window and set the pixmap as a background
2633 void CDECL
X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
2635 Display
*display
= thread_display();
2636 struct x11drv_win_data
*data
;
2639 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
2640 if (!data
->whole_window
) return;
2641 if (!data
->managed
) return;
2645 if (type
== ICON_BIG
) set_icon_hints( display
, data
, icon
, 0 );
2646 else set_icon_hints( display
, data
, 0, icon
);
2648 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
2649 wine_tsx11_unlock();
2654 /***********************************************************************
2655 * SetWindowRgn (X11DRV.@)
2657 * Assign specified region to window (for non-rectangular windows)
2659 int CDECL
X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
2661 struct x11drv_win_data
*data
;
2663 if ((data
= X11DRV_get_win_data( hwnd
)))
2665 sync_window_region( thread_display(), data
, hrgn
);
2667 else if (X11DRV_get_whole_window( hwnd
))
2669 SendMessageW( hwnd
, WM_X11DRV_SET_WIN_REGION
, 0, 0 );
2675 /***********************************************************************
2676 * SetLayeredWindowAttributes (X11DRV.@)
2678 * Set transparency attributes for a layered window.
2680 void CDECL
X11DRV_SetLayeredWindowAttributes( HWND hwnd
, COLORREF key
, BYTE alpha
, DWORD flags
)
2682 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
2686 if (data
->whole_window
)
2687 sync_window_opacity( thread_display(), data
->whole_window
, key
, alpha
, flags
);
2691 Window win
= X11DRV_get_whole_window( hwnd
);
2692 if (win
) sync_window_opacity( gdi_display
, win
, key
, alpha
, flags
);
2697 /**********************************************************************
2698 * X11DRV_WindowMessage (X11DRV.@)
2700 LRESULT CDECL
X11DRV_WindowMessage( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2702 struct x11drv_win_data
*data
;
2706 case WM_X11DRV_ACQUIRE_SELECTION
:
2707 return X11DRV_AcquireClipboard( hwnd
);
2708 case WM_X11DRV_SET_WIN_FORMAT
:
2709 return set_win_format( hwnd
, (XID
)wp
);
2710 case WM_X11DRV_SET_WIN_REGION
:
2711 if ((data
= X11DRV_get_win_data( hwnd
))) sync_window_region( thread_display(), data
, (HRGN
)1 );
2713 case WM_X11DRV_RESIZE_DESKTOP
:
2714 X11DRV_resize_desktop( LOWORD(lp
), HIWORD(lp
) );
2716 case WM_X11DRV_SET_CURSOR
:
2717 if ((data
= X11DRV_get_win_data( hwnd
)) && data
->whole_window
)
2718 set_window_cursor( data
->whole_window
, (HCURSOR
)lp
);
2719 else if (hwnd
== x11drv_thread_data()->clip_hwnd
)
2720 set_window_cursor( x11drv_thread_data()->clip_window
, (HCURSOR
)lp
);
2722 case WM_X11DRV_CLIP_CURSOR
:
2723 return clip_cursor_notify( hwnd
, (HWND
)lp
);
2725 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg
, hwnd
, wp
, lp
);
2731 /***********************************************************************
2732 * is_netwm_supported
2734 static BOOL
is_netwm_supported( Display
*display
, Atom atom
)
2736 static Atom
*net_supported
;
2737 static int net_supported_count
= -1;
2741 if (net_supported_count
== -1)
2745 unsigned long count
, remaining
;
2747 if (!XGetWindowProperty( display
, DefaultRootWindow(display
), x11drv_atom(_NET_SUPPORTED
), 0,
2748 ~0UL, False
, XA_ATOM
, &type
, &format
, &count
,
2749 &remaining
, (unsigned char **)&net_supported
))
2750 net_supported_count
= get_property_size( format
, count
) / sizeof(Atom
);
2752 net_supported_count
= 0;
2754 wine_tsx11_unlock();
2756 for (i
= 0; i
< net_supported_count
; i
++)
2757 if (net_supported
[i
] == atom
) return TRUE
;
2762 /***********************************************************************
2763 * SysCommand (X11DRV.@)
2765 * Perform WM_SYSCOMMAND handling.
2767 LRESULT CDECL
X11DRV_SysCommand( HWND hwnd
, WPARAM wparam
, LPARAM lparam
)
2769 WPARAM hittest
= wparam
& 0x0f;
2773 Display
*display
= thread_display();
2774 struct x11drv_win_data
*data
;
2776 if (!(data
= X11DRV_get_win_data( hwnd
))) return -1;
2777 if (!data
->whole_window
|| !data
->managed
|| !data
->mapped
) return -1;
2779 switch (wparam
& 0xfff0)
2782 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
2783 else dir
= _NET_WM_MOVERESIZE_MOVE
;
2786 /* windows without WS_THICKFRAME are not resizable through the window manager */
2787 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_THICKFRAME
)) return -1;
2791 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
2792 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
2793 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
2794 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
2795 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
2796 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
2797 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
2798 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
2799 default: dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
; break;
2804 /* prevent a simple ALT press+release from activating the system menu,
2805 * as that can get confusing on managed windows */
2806 if ((WCHAR
)lparam
) return -1; /* got an explicit char */
2807 if (GetMenu( hwnd
)) return -1; /* window has a real menu */
2808 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_SYSMENU
)) return -1; /* no system menu */
2809 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam
, lparam
);
2816 if (IsZoomed(hwnd
)) return -1;
2818 if (!is_netwm_supported( display
, x11drv_atom(_NET_WM_MOVERESIZE
) ))
2820 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
2824 dwPoint
= GetMessagePos();
2825 x
= (short)LOWORD(dwPoint
);
2826 y
= (short)HIWORD(dwPoint
);
2828 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd
, x
, y
, dir
);
2830 xev
.xclient
.type
= ClientMessage
;
2831 xev
.xclient
.window
= X11DRV_get_whole_window(hwnd
);
2832 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_MOVERESIZE
);
2833 xev
.xclient
.serial
= 0;
2834 xev
.xclient
.display
= display
;
2835 xev
.xclient
.send_event
= True
;
2836 xev
.xclient
.format
= 32;
2837 xev
.xclient
.data
.l
[0] = x
- virtual_screen_rect
.left
; /* x coord */
2838 xev
.xclient
.data
.l
[1] = y
- virtual_screen_rect
.top
; /* y coord */
2839 xev
.xclient
.data
.l
[2] = dir
; /* direction */
2840 xev
.xclient
.data
.l
[3] = 1; /* button */
2841 xev
.xclient
.data
.l
[4] = 0; /* unused */
2843 /* need to ungrab the pointer that may have been automatically grabbed
2844 * with a ButtonPress event */
2846 XUngrabPointer( display
, CurrentTime
);
2847 XSendEvent(display
, root_window
, False
, SubstructureNotifyMask
| SubstructureRedirectMask
, &xev
);
2848 wine_tsx11_unlock();