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 /* X context to associate a hwnd to an X window */
54 XContext winContext
= 0;
56 /* X context to associate a struct x11drv_win_data to an hwnd */
57 static XContext win_data_context
;
59 static const char whole_window_prop
[] = "__wine_x11_whole_window";
60 static const char client_window_prop
[]= "__wine_x11_client_window";
61 static const char icon_window_prop
[] = "__wine_x11_icon_window";
62 static const char fbconfig_id_prop
[] = "__wine_x11_fbconfig_id";
63 static const char gl_drawable_prop
[] = "__wine_x11_gl_drawable";
64 static const char pixmap_prop
[] = "__wine_x11_pixmap";
65 static const char managed_prop
[] = "__wine_x11_managed";
67 extern int usexcomposite
;
69 /***********************************************************************
72 * Check if a given window should be managed
74 BOOL
is_window_managed( HWND hwnd
, UINT swp_flags
, const RECT
*window_rect
)
76 DWORD style
, ex_style
;
78 if (!managed_mode
) return FALSE
;
80 /* child windows are not managed */
81 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
82 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) return FALSE
;
83 /* activated windows are managed */
84 if (!(swp_flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
))) return TRUE
;
85 if (hwnd
== GetActiveWindow()) return TRUE
;
86 /* windows with caption are managed */
87 if ((style
& WS_CAPTION
) == WS_CAPTION
) return TRUE
;
88 /* tool windows are not managed */
89 ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
90 if (ex_style
& WS_EX_TOOLWINDOW
) return FALSE
;
91 /* windows with thick frame are managed */
92 if (style
& WS_THICKFRAME
) return TRUE
;
93 /* application windows are managed */
94 if (ex_style
& WS_EX_APPWINDOW
) return TRUE
;
97 /* popup with sysmenu == caption are managed */
98 if (style
& WS_SYSMENU
) return TRUE
;
99 /* full-screen popup windows are managed */
100 if (window_rect
->left
<= 0 && window_rect
->right
>= screen_width
&&
101 window_rect
->top
<= 0 && window_rect
->bottom
>= screen_height
)
104 /* default: not managed */
109 /***********************************************************************
110 * X11DRV_is_window_rect_mapped
112 * Check if the X whole window should be mapped based on its rectangle
114 BOOL
X11DRV_is_window_rect_mapped( const RECT
*rect
)
116 /* don't map if rect is empty */
117 if (IsRectEmpty( rect
)) return FALSE
;
119 /* don't map if rect is off-screen */
120 if (rect
->left
>= virtual_screen_rect
.right
||
121 rect
->top
>= virtual_screen_rect
.bottom
||
122 rect
->right
<= virtual_screen_rect
.left
||
123 rect
->bottom
<= virtual_screen_rect
.top
)
130 /***********************************************************************
131 * is_window_resizable
133 * Check if window should be made resizable by the window manager
135 static inline BOOL
is_window_resizable( struct x11drv_win_data
*data
, DWORD style
)
137 if (style
& WS_THICKFRAME
) return TRUE
;
138 /* Metacity needs the window to be resizable to make it fullscreen */
139 return (data
->whole_rect
.left
<= 0 && data
->whole_rect
.right
>= screen_width
&&
140 data
->whole_rect
.top
<= 0 && data
->whole_rect
.bottom
>= screen_height
);
144 /***********************************************************************
145 * get_mwm_decorations
147 static unsigned long get_mwm_decorations( DWORD style
, DWORD ex_style
)
149 unsigned long ret
= 0;
151 if (!decorated_mode
) return ret
;
153 if (ex_style
& WS_EX_TOOLWINDOW
) return 0;
155 if ((style
& WS_CAPTION
) == WS_CAPTION
)
157 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
158 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
159 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
160 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
162 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
163 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
164 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
169 /***********************************************************************
170 * get_x11_rect_offset
172 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
174 static void get_x11_rect_offset( struct x11drv_win_data
*data
, RECT
*rect
)
176 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
179 rect
->top
= rect
->bottom
= rect
->left
= rect
->right
= 0;
181 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
182 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
183 decor
= get_mwm_decorations( style
, ex_style
);
185 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
186 if (decor
& MWM_DECOR_BORDER
)
188 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
189 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
192 AdjustWindowRectEx( rect
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
196 /***********************************************************************
197 * get_window_attributes
199 * Fill the window attributes structure for an X window.
201 static int get_window_attributes( Display
*display
, struct x11drv_win_data
*data
,
202 XSetWindowAttributes
*attr
)
204 attr
->override_redirect
= !data
->managed
;
205 attr
->colormap
= X11DRV_PALETTE_PaletteXColormap
;
206 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
207 attr
->cursor
= x11drv_thread_data()->cursor
;
208 attr
->bit_gravity
= NorthWestGravity
;
209 attr
->backing_store
= NotUseful
;
210 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
211 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
212 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
| KeymapStateMask
);
213 if (data
->managed
) attr
->event_mask
|= StructureNotifyMask
| PropertyChangeMask
;
215 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
| CWCursor
|
216 CWEventMask
| CWBitGravity
| CWBackingStore
);
220 /***********************************************************************
221 * create_client_window
223 static Window
create_client_window( Display
*display
, struct x11drv_win_data
*data
, XVisualInfo
*vis
)
226 XSetWindowAttributes attr
;
229 attr
.bit_gravity
= NorthWestGravity
;
230 attr
.win_gravity
= NorthWestGravity
;
231 attr
.backing_store
= NotUseful
;
232 attr
.event_mask
= (ExposureMask
| PointerMotionMask
|
233 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
234 mask
= CWEventMask
| CWBitGravity
| CWWinGravity
| CWBackingStore
;
236 if ((cx
= data
->client_rect
.right
- data
->client_rect
.left
) <= 0) cx
= 1;
237 if ((cy
= data
->client_rect
.bottom
- data
->client_rect
.top
) <= 0) cy
= 1;
243 attr
.colormap
= XCreateColormap( display
, root_window
, vis
->visual
,
244 (vis
->class == PseudoColor
|| vis
->class == GrayScale
||
245 vis
->class == DirectColor
) ? AllocAll
: AllocNone
);
249 client
= XCreateWindow( display
, data
->whole_window
,
250 data
->client_rect
.left
- data
->whole_rect
.left
,
251 data
->client_rect
.top
- data
->whole_rect
.top
,
252 cx
, cy
, 0, screen_depth
, InputOutput
,
253 vis
? vis
->visual
: visual
, mask
, &attr
);
260 if (data
->client_window
)
262 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
263 if (thread_data
->cursor_window
== data
->client_window
) thread_data
->cursor_window
= None
;
264 XDeleteContext( display
, data
->client_window
, winContext
);
265 XDestroyWindow( display
, data
->client_window
);
267 data
->client_window
= client
;
269 if (data
->colormap
) XFreeColormap( display
, data
->colormap
);
270 data
->colormap
= vis
? attr
.colormap
: 0;
272 XMapWindow( display
, data
->client_window
);
273 XSaveContext( display
, data
->client_window
, winContext
, (char *)data
->hwnd
);
276 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)data
->client_window
);
277 return data
->client_window
;
281 /***********************************************************************
282 * X11DRV_sync_window_style
284 * Change the X window attributes when the window style has changed.
286 void X11DRV_sync_window_style( Display
*display
, struct x11drv_win_data
*data
)
288 if (data
->whole_window
!= root_window
)
290 XSetWindowAttributes attr
;
291 int mask
= get_window_attributes( display
, data
, &attr
);
294 XChangeWindowAttributes( display
, data
->whole_window
, mask
, &attr
);
300 /***********************************************************************
303 * Update the X11 window region.
305 static void sync_window_region( Display
*display
, struct x11drv_win_data
*data
, HRGN hrgn
)
307 #ifdef HAVE_LIBXSHAPE
308 if (!data
->whole_window
) return;
313 XShapeCombineMask( display
, data
->whole_window
, ShapeBounding
, 0, 0, None
, ShapeSet
);
318 RGNDATA
*pRegionData
= X11DRV_GetRegionData( hrgn
, 0 );
322 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
323 data
->window_rect
.left
- data
->whole_rect
.left
,
324 data
->window_rect
.top
- data
->whole_rect
.top
,
325 (XRectangle
*)pRegionData
->Buffer
,
326 pRegionData
->rdh
.nCount
, ShapeSet
, YXBanded
);
328 HeapFree(GetProcessHeap(), 0, pRegionData
);
331 #endif /* HAVE_LIBXSHAPE */
335 /***********************************************************************
338 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
341 char *buffer
, *utf8_buffer
;
344 /* allocate new buffer for window text */
345 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
346 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
347 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
349 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
350 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
352 HeapFree( GetProcessHeap(), 0, buffer
);
355 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
358 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
360 XSetWMName( display
, win
, &prop
);
361 XSetWMIconName( display
, win
, &prop
);
365 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
366 according to the standard
367 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
369 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
370 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
373 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
374 HeapFree( GetProcessHeap(), 0, buffer
);
378 /***********************************************************************
379 * X11DRV_set_win_format
381 BOOL
X11DRV_set_win_format( HWND hwnd
, XID fbconfig_id
)
383 Display
*display
= thread_display();
384 struct x11drv_win_data
*data
;
388 if (!(data
= X11DRV_get_win_data(hwnd
)) &&
389 !(data
= X11DRV_create_win_data(hwnd
))) return FALSE
;
391 if (data
->fbconfig_id
) return FALSE
; /* can't change it twice */
394 vis
= visual_from_fbconfig_id(fbconfig_id
);
396 if (!vis
) return FALSE
;
398 if (data
->whole_window
)
400 Window client
= data
->client_window
;
402 if (vis
->visualid
!= XVisualIDFromVisual(visual
))
404 client
= create_client_window( display
, data
, vis
);
405 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client
, data
->hwnd
, fbconfig_id
);
410 if (client
) goto done
;
414 w
= data
->client_rect
.right
- data
->client_rect
.left
;
415 h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
420 #ifdef SONAME_LIBXCOMPOSITE
423 XSetWindowAttributes attrib
;
424 Window parent
= X11DRV_get_whole_window( GetAncestor( hwnd
, GA_ROOT
));
426 if (!parent
) parent
= root_window
;
428 data
->colormap
= XCreateColormap(display
, parent
, vis
->visual
,
429 (vis
->class == PseudoColor
||
430 vis
->class == GrayScale
||
431 vis
->class == DirectColor
) ?
432 AllocAll
: AllocNone
);
433 attrib
.override_redirect
= True
;
434 attrib
.colormap
= data
->colormap
;
435 XInstallColormap(gdi_display
, attrib
.colormap
);
437 data
->gl_drawable
= XCreateWindow(display
, parent
, -w
, 0, w
, h
, 0,
438 vis
->depth
, InputOutput
, vis
->visual
,
439 CWColormap
| CWOverrideRedirect
,
441 if(data
->gl_drawable
)
443 pXCompositeRedirectWindow(display
, data
->gl_drawable
,
444 CompositeRedirectManual
);
445 XMapWindow(display
, data
->gl_drawable
);
453 WARN("XComposite is not available, using GLXPixmap hack\n");
456 data
->pixmap
= XCreatePixmap(display
, root_window
, w
, h
, vis
->depth
);
464 data
->gl_drawable
= create_glxpixmap(display
, vis
, data
->pixmap
);
465 if(!data
->gl_drawable
)
467 XFreePixmap(display
, data
->pixmap
);
472 if (data
->pixmap
) SetPropA(hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
475 if (!data
->gl_drawable
) return FALSE
;
477 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
478 data
->gl_drawable
, fbconfig_id
);
479 SetPropA(hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
482 data
->fbconfig_id
= fbconfig_id
;
483 SetPropA(hwnd
, fbconfig_id_prop
, (HANDLE
)data
->fbconfig_id
);
487 WIN_invalidate_dce( hwnd
, NULL
);
491 /***********************************************************************
494 static void sync_gl_drawable(Display
*display
, struct x11drv_win_data
*data
)
496 int w
= data
->client_rect
.right
- data
->client_rect
.left
;
497 int h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
505 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
506 #ifdef SONAME_LIBXCOMPOSITE
510 XMoveResizeWindow(display
, data
->gl_drawable
, -w
, 0, w
, h
);
518 vis
= visual_from_fbconfig_id(data
->fbconfig_id
);
525 pix
= XCreatePixmap(display
, root_window
, w
, h
, vis
->depth
);
528 ERR("Failed to create pixmap for offscreen rendering\n");
534 glxp
= create_glxpixmap(display
, vis
, pix
);
537 ERR("Failed to create drawable for offscreen rendering\n");
538 XFreePixmap(display
, pix
);
546 mark_drawable_dirty(data
->gl_drawable
, glxp
);
548 XFreePixmap(display
, data
->pixmap
);
549 destroy_glxpixmap(display
, data
->gl_drawable
);
552 data
->gl_drawable
= glxp
;
557 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
558 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
562 /***********************************************************************
565 * fill the window changes structure
567 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
571 if (old
->right
- old
->left
!= new->right
- new->left
)
573 if ((changes
->width
= new->right
- new->left
) <= 0) changes
->width
= 1;
576 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
578 if ((changes
->height
= new->bottom
- new->top
) <= 0) changes
->height
= 1;
581 if (old
->left
!= new->left
)
583 changes
->x
= new->left
;
586 if (old
->top
!= new->top
)
588 changes
->y
= new->top
;
595 /***********************************************************************
598 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
600 XSetWindowAttributes attr
;
602 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
603 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
604 attr
.bit_gravity
= NorthWestGravity
;
605 attr
.backing_store
= NotUseful
/*WhenMapped*/;
606 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
609 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
610 GetSystemMetrics( SM_CXICON
),
611 GetSystemMetrics( SM_CYICON
),
614 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
615 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
616 XFlush( display
); /* make sure the window exists before we start painting to it */
619 TRACE( "created %lx\n", data
->icon_window
);
620 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
621 return data
->icon_window
;
626 /***********************************************************************
627 * destroy_icon_window
629 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
631 if (!data
->icon_window
) return;
632 if (x11drv_thread_data()->cursor_window
== data
->icon_window
)
633 x11drv_thread_data()->cursor_window
= None
;
635 XDeleteContext( display
, data
->icon_window
, winContext
);
636 XDestroyWindow( display
, data
->icon_window
);
637 data
->icon_window
= 0;
639 RemovePropA( data
->hwnd
, icon_window_prop
);
643 /***********************************************************************
646 * Set the icon wm hints
648 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
, HICON hIcon
)
650 XWMHints
*hints
= data
->wm_hints
;
652 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
653 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
654 data
->hWMIconBitmap
= 0;
655 data
->hWMIconMask
= 0;
659 if (!data
->icon_window
) create_icon_window( display
, data
);
660 hints
->icon_window
= data
->icon_window
;
661 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
671 GetIconInfo(hIcon
, &ii
);
673 GetObjectA(ii
.hbmMask
, sizeof(bmMask
), &bmMask
);
676 rcMask
.right
= bmMask
.bmWidth
;
677 rcMask
.bottom
= bmMask
.bmHeight
;
679 hDC
= CreateCompatibleDC(0);
680 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
681 InvertRect(hDC
, &rcMask
);
682 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
683 SelectObject(hDC
, hbmOrig
);
686 data
->hWMIconBitmap
= ii
.hbmColor
;
687 data
->hWMIconMask
= ii
.hbmMask
;
689 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
690 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
691 destroy_icon_window( display
, data
);
692 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
697 /***********************************************************************
700 * set the window size hints
702 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
704 XSizeHints
* size_hints
;
706 if (!(size_hints
= XAllocSizeHints())) return;
708 /* don't update size hints if window is not in normal state */
709 if (!(style
& (WS_MINIMIZE
| WS_MAXIMIZE
)))
711 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
713 size_hints
->win_gravity
= StaticGravity
;
714 size_hints
->x
= data
->whole_rect
.left
;
715 size_hints
->y
= data
->whole_rect
.top
;
716 size_hints
->flags
|= PWinGravity
| PPosition
;
719 if (!is_window_resizable( data
, style
))
721 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
722 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
723 size_hints
->min_width
= size_hints
->max_width
;
724 size_hints
->min_height
= size_hints
->max_height
;
725 size_hints
->flags
|= PMinSize
| PMaxSize
;
728 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
733 /***********************************************************************
736 * get the name of the current process for setting class hints
738 static char *get_process_name(void)
744 WCHAR module
[MAX_PATH
];
745 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
746 if (len
&& len
< MAX_PATH
)
749 WCHAR
*p
, *appname
= module
;
751 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
752 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
753 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
754 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
756 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
765 /***********************************************************************
766 * set_initial_wm_hints
768 * Set the window manager hints that don't change over the lifetime of a window.
770 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
775 XClassHint
*class_hints
;
776 char *process_name
= get_process_name();
782 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
783 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
784 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
785 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
786 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
789 if ((class_hints
= XAllocClassHint()))
791 static char wine
[] = "Wine";
793 class_hints
->res_name
= process_name
;
794 class_hints
->res_class
= wine
;
795 XSetClassHint( display
, data
->whole_window
, class_hints
);
796 XFree( class_hints
);
799 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
800 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
801 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
803 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
804 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
806 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
807 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
809 data
->wm_hints
= XAllocWMHints();
814 HICON icon
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_BIG
, 0 );
815 if (!icon
) icon
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
);
816 data
->wm_hints
->flags
= 0;
817 set_icon_hints( display
, data
, icon
);
822 /***********************************************************************
823 * X11DRV_set_wm_hints
825 * Set the window manager hints for a newly-created window
827 void X11DRV_set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
832 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
833 DWORD ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
834 HWND owner
= GetWindow( data
->hwnd
, GW_OWNER
);
836 if (data
->hwnd
== GetDesktopWindow())
838 /* force some styles for the desktop to get the correct decorations */
839 style
|= WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
843 /* transient for hint */
846 Window owner_win
= X11DRV_get_whole_window( owner
);
848 XSetTransientForHint( display
, data
->whole_window
, owner_win
);
850 group_leader
= owner_win
;
852 else group_leader
= data
->whole_window
;
857 set_size_hints( display
, data
, style
);
859 /* set the WM_WINDOW_TYPE */
860 if (style
& WS_THICKFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
861 else if (ex_style
& WS_EX_APPWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
862 else if (style
& WS_DLGFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
863 else if (ex_style
& WS_EX_DLGMODALFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
864 #if 0 /* many window managers don't handle utility windows very well */
865 else if (ex_style
& WS_EX_TOOLWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY
);
867 else window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
869 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
870 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
872 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
873 mwm_hints
.decorations
= get_mwm_decorations( style
, ex_style
);
874 mwm_hints
.functions
= MWM_FUNC_MOVE
;
875 if (is_window_resizable( data
, style
)) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
876 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
877 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
878 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
880 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
881 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
882 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
887 data
->wm_hints
->flags
|= InputHint
| StateHint
| WindowGroupHint
;
888 data
->wm_hints
->input
= !(style
& WS_DISABLED
);
889 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
890 data
->wm_hints
->window_group
= group_leader
;
891 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
898 /***********************************************************************
899 * X11DRV_window_to_X_rect
901 * Convert a rect from client to X window coordinates
903 void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
907 if (!data
->managed
) return;
908 if (IsRectEmpty( rect
)) return;
910 get_x11_rect_offset( data
, &rc
);
912 rect
->left
-= rc
.left
;
913 rect
->right
-= rc
.right
;
915 rect
->bottom
-= rc
.bottom
;
916 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
917 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
921 /***********************************************************************
922 * X11DRV_X_to_window_rect
924 * Opposite of X11DRV_window_to_X_rect
926 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
930 if (!data
->managed
) return;
931 if (IsRectEmpty( rect
)) return;
933 get_x11_rect_offset( data
, &rc
);
935 rect
->left
+= rc
.left
;
936 rect
->right
+= rc
.right
;
938 rect
->bottom
+= rc
.bottom
;
939 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
940 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
944 /***********************************************************************
945 * X11DRV_sync_window_position
947 * Synchronize the X window position with the Windows one
949 void X11DRV_sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
950 UINT swp_flags
, const RECT
*old_client_rect
,
951 const RECT
*old_whole_rect
)
953 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
954 XWindowChanges changes
;
955 int mask
= CWWidth
| CWHeight
;
957 if (data
->managed
&& data
->iconic
) return;
959 if ((changes
.width
= data
->whole_rect
.right
- data
->whole_rect
.left
) <= 0) changes
.width
= 1;
960 if ((changes
.height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
) <= 0) changes
.height
= 1;
962 /* only the size is allowed to change for the desktop window */
963 if (data
->whole_window
!= root_window
)
965 changes
.x
= data
->whole_rect
.left
- virtual_screen_rect
.left
;
966 changes
.y
= data
->whole_rect
.top
- virtual_screen_rect
.top
;
970 if (!(swp_flags
& SWP_NOZORDER
))
972 /* find window that this one must be after */
973 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
974 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
975 prev
= GetWindow( prev
, GW_HWNDPREV
);
976 if (!prev
) /* top child */
978 changes
.stack_mode
= Above
;
981 /* should use stack_mode Below but most window managers don't get it right */
982 /* and Above with a sibling doesn't work so well either, so we ignore it */
985 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
986 data
->hwnd
, data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
987 data
->whole_rect
.right
- data
->whole_rect
.left
,
988 data
->whole_rect
.bottom
- data
->whole_rect
.top
, changes
.sibling
, mask
);
991 set_size_hints( display
, data
, style
);
992 XReconfigureWMWindow( display
, data
->whole_window
,
993 DefaultScreen(display
), mask
, &changes
);
998 /***********************************************************************
999 * X11DRV_sync_client_position
1001 * Synchronize the X client window position with the Windows one
1003 void X11DRV_sync_client_position( Display
*display
, struct x11drv_win_data
*data
,
1004 UINT swp_flags
, const RECT
*old_client_rect
,
1005 const RECT
*old_whole_rect
)
1008 XWindowChanges changes
;
1009 RECT old
= *old_client_rect
;
1010 RECT
new = data
->client_rect
;
1012 OffsetRect( &old
, -old_whole_rect
->left
, -old_whole_rect
->top
);
1013 OffsetRect( &new, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
1014 if (!(mask
= get_window_changes( &changes
, &old
, &new ))) return;
1016 if (data
->client_window
)
1018 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1019 data
->client_window
, new.left
, new.top
,
1020 new.right
- new.left
, new.bottom
- new.top
, mask
);
1022 XConfigureWindow( display
, data
->client_window
, mask
, &changes
);
1023 wine_tsx11_unlock();
1026 if (data
->gl_drawable
&& (mask
& (CWWidth
|CWHeight
))) sync_gl_drawable( display
, data
);
1030 /**********************************************************************
1031 * create_whole_window
1033 * Create the whole X window for a given window
1035 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1038 XSetWindowAttributes attr
;
1042 if (!(cx
= data
->window_rect
.right
- data
->window_rect
.left
)) cx
= 1;
1043 if (!(cy
= data
->window_rect
.bottom
- data
->window_rect
.top
)) cy
= 1;
1045 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1047 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1048 data
->managed
= TRUE
;
1049 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1052 mask
= get_window_attributes( display
, data
, &attr
);
1056 data
->whole_rect
= data
->window_rect
;
1057 data
->whole_window
= XCreateWindow( display
, root_window
,
1058 data
->window_rect
.left
- virtual_screen_rect
.left
,
1059 data
->window_rect
.top
- virtual_screen_rect
.top
,
1060 cx
, cy
, 0, screen_depth
, InputOutput
,
1061 visual
, mask
, &attr
);
1063 if (data
->whole_window
) XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1064 wine_tsx11_unlock();
1066 if (!data
->whole_window
) return 0;
1068 if (!create_client_window( display
, data
, NULL
))
1071 XDeleteContext( display
, data
->whole_window
, winContext
);
1072 XDestroyWindow( display
, data
->whole_window
);
1073 data
->whole_window
= 0;
1074 wine_tsx11_unlock();
1078 set_initial_wm_hints( display
, data
);
1079 X11DRV_set_wm_hints( display
, data
);
1081 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1083 /* set the window text */
1084 if (!InternalGetWindowText( data
->hwnd
, text
, sizeof(text
)/sizeof(WCHAR
) )) text
[0] = 0;
1085 sync_window_text( display
, data
->whole_window
, text
);
1087 /* set the window region */
1088 if ((hrgn
= CreateRectRgn( 0, 0, 0, 0 )))
1090 if (GetWindowRgn( data
->hwnd
, hrgn
) != ERROR
) sync_window_region( display
, data
, hrgn
);
1091 DeleteObject( hrgn
);
1094 XFlush( display
); /* make sure the window exists before we start painting to it */
1095 wine_tsx11_unlock();
1096 return data
->whole_window
;
1100 /**********************************************************************
1101 * destroy_whole_window
1103 * Destroy the whole X window for a given window.
1105 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
, BOOL already_destroyed
)
1107 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1109 if (!data
->whole_window
) return;
1111 TRACE( "win %p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1112 if (thread_data
->cursor_window
== data
->whole_window
||
1113 thread_data
->cursor_window
== data
->client_window
)
1114 thread_data
->cursor_window
= None
;
1116 XDeleteContext( display
, data
->whole_window
, winContext
);
1117 XDeleteContext( display
, data
->client_window
, winContext
);
1118 if (!already_destroyed
) XDestroyWindow( display
, data
->whole_window
);
1119 data
->whole_window
= data
->client_window
= 0;
1120 data
->wm_state
= WithdrawnState
;
1121 data
->net_wm_state
= 0;
1122 data
->mapped
= FALSE
;
1125 XUnsetICFocus( data
->xic
);
1126 XDestroyIC( data
->xic
);
1129 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1131 XFree( data
->wm_hints
);
1132 data
->wm_hints
= NULL
;
1133 wine_tsx11_unlock();
1134 RemovePropA( data
->hwnd
, whole_window_prop
);
1135 RemovePropA( data
->hwnd
, client_window_prop
);
1139 /*****************************************************************
1140 * SetWindowText (X11DRV.@)
1142 void X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1144 Display
*display
= thread_display();
1147 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(display
))
1148 sync_window_text( display
, win
, text
);
1152 /***********************************************************************
1153 * DestroyWindow (X11DRV.@)
1155 void X11DRV_DestroyWindow( HWND hwnd
)
1157 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1158 Display
*display
= thread_data
->display
;
1159 struct x11drv_win_data
*data
;
1161 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1165 destroy_glxpixmap(display
, data
->gl_drawable
);
1167 XFreePixmap(display
, data
->pixmap
);
1168 wine_tsx11_unlock();
1170 else if (data
->gl_drawable
)
1173 XDestroyWindow(display
, data
->gl_drawable
);
1174 wine_tsx11_unlock();
1177 destroy_whole_window( display
, data
, FALSE
);
1178 destroy_icon_window( display
, data
);
1183 XFreeColormap( display
, data
->colormap
);
1184 wine_tsx11_unlock();
1187 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1188 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1189 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1191 XDeleteContext( display
, (XID
)hwnd
, win_data_context
);
1192 wine_tsx11_unlock();
1193 HeapFree( GetProcessHeap(), 0, data
);
1197 /***********************************************************************
1198 * X11DRV_DestroyNotify
1200 void X11DRV_DestroyNotify( HWND hwnd
, XEvent
*event
)
1202 Display
*display
= event
->xdestroywindow
.display
;
1203 struct x11drv_win_data
*data
;
1205 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1207 FIXME( "window %p/%lx destroyed from the outside\n", hwnd
, data
->whole_window
);
1208 destroy_whole_window( display
, data
, TRUE
);
1212 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1214 struct x11drv_win_data
*data
;
1216 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
1220 if (!winContext
) winContext
= XUniqueContext();
1221 if (!win_data_context
) win_data_context
= XUniqueContext();
1222 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1223 wine_tsx11_unlock();
1229 /* initialize the desktop window id in the desktop manager process */
1230 static struct x11drv_win_data
*create_desktop_win_data( Display
*display
, HWND hwnd
)
1232 struct x11drv_win_data
*data
;
1235 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1237 visualid
= XVisualIDFromVisual(visual
);
1238 wine_tsx11_unlock();
1239 data
->whole_window
= data
->client_window
= root_window
;
1240 data
->managed
= TRUE
;
1241 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1242 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1243 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)root_window
);
1244 set_initial_wm_hints( display
, data
);
1248 /**********************************************************************
1249 * CreateDesktopWindow (X11DRV.@)
1251 BOOL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1253 unsigned int width
, height
;
1255 /* retrieve the real size of the desktop */
1256 SERVER_START_REQ( get_window_rectangles
)
1259 wine_server_call( req
);
1260 width
= reply
->window
.right
- reply
->window
.left
;
1261 height
= reply
->window
.bottom
- reply
->window
.top
;
1265 if (!width
&& !height
) /* not initialized yet */
1267 SERVER_START_REQ( set_window_pos
)
1271 req
->flags
= SWP_NOZORDER
;
1272 req
->window
.left
= virtual_screen_rect
.left
;
1273 req
->window
.top
= virtual_screen_rect
.top
;
1274 req
->window
.right
= virtual_screen_rect
.right
;
1275 req
->window
.bottom
= virtual_screen_rect
.bottom
;
1276 req
->client
= req
->window
;
1277 wine_server_call( req
);
1283 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1284 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1290 /**********************************************************************
1291 * CreateWindow (X11DRV.@)
1293 BOOL
X11DRV_CreateWindow( HWND hwnd
)
1295 Display
*display
= thread_display();
1297 if (hwnd
== GetDesktopWindow() && root_window
!= DefaultRootWindow( display
))
1299 /* the desktop win data can't be created lazily */
1300 if (!create_desktop_win_data( display
, hwnd
)) return FALSE
;
1306 /***********************************************************************
1307 * X11DRV_get_win_data
1309 * Return the X11 data structure associated with a window.
1311 struct x11drv_win_data
*X11DRV_get_win_data( HWND hwnd
)
1315 if (!hwnd
|| XFindContext( thread_display(), (XID
)hwnd
, win_data_context
, &data
)) data
= NULL
;
1316 return (struct x11drv_win_data
*)data
;
1320 /***********************************************************************
1321 * X11DRV_create_win_data
1323 * Create an X11 data window structure for an existing window.
1325 struct x11drv_win_data
*X11DRV_create_win_data( HWND hwnd
)
1327 Display
*display
= thread_display();
1328 struct x11drv_win_data
*data
;
1331 if (!(parent
= GetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop */
1332 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1334 GetWindowRect( hwnd
, &data
->window_rect
);
1335 MapWindowPoints( 0, parent
, (POINT
*)&data
->window_rect
, 2 );
1336 data
->whole_rect
= data
->window_rect
;
1337 GetClientRect( hwnd
, &data
->client_rect
);
1338 MapWindowPoints( hwnd
, parent
, (POINT
*)&data
->client_rect
, 2 );
1340 if (parent
== GetDesktopWindow())
1342 if (!create_whole_window( display
, data
))
1344 HeapFree( GetProcessHeap(), 0, data
);
1347 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1348 hwnd
, data
->whole_window
, data
->client_window
, wine_dbgstr_rect( &data
->window_rect
),
1349 wine_dbgstr_rect( &data
->whole_rect
), wine_dbgstr_rect( &data
->client_rect
));
1355 /***********************************************************************
1356 * X11DRV_get_whole_window
1358 * Return the X window associated with the full area of a window
1360 Window
X11DRV_get_whole_window( HWND hwnd
)
1362 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1366 if (hwnd
== GetDesktopWindow()) return root_window
;
1367 return (Window
)GetPropA( hwnd
, whole_window_prop
);
1369 return data
->whole_window
;
1373 /***********************************************************************
1374 * X11DRV_get_client_window
1376 * Return the X window associated with the client area of a window
1378 Window
X11DRV_get_client_window( HWND hwnd
)
1380 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1384 if (hwnd
== GetDesktopWindow()) return root_window
;
1385 return (Window
)GetPropA( hwnd
, client_window_prop
);
1387 return data
->client_window
;
1391 /***********************************************************************
1394 * Return the X input context associated with a window
1396 XIC
X11DRV_get_ic( HWND hwnd
)
1398 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1401 if (!data
) return 0;
1402 if (data
->xic
) return data
->xic
;
1403 if (!(xim
= x11drv_thread_data()->xim
)) return 0;
1404 return X11DRV_CreateIC( xim
, data
);
1408 /***********************************************************************
1409 * X11DRV_GetDC (X11DRV.@)
1411 void X11DRV_GetDC( HDC hdc
, HWND hwnd
, HWND top
, const RECT
*win_rect
,
1412 const RECT
*top_rect
, DWORD flags
)
1414 struct x11drv_escape_set_drawable escape
;
1415 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1417 escape
.code
= X11DRV_SET_DRAWABLE
;
1418 escape
.mode
= IncludeInferiors
;
1419 escape
.fbconfig_id
= 0;
1420 escape
.gl_drawable
= 0;
1423 if (top
== hwnd
&& data
&& IsIconic( hwnd
) && data
->icon_window
)
1425 escape
.drawable
= data
->icon_window
;
1427 else if (top
== hwnd
&& (flags
& DCX_WINDOW
))
1429 escape
.drawable
= data
? data
->whole_window
: X11DRV_get_whole_window( hwnd
);
1433 escape
.drawable
= X11DRV_get_client_window( top
);
1434 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1435 escape
.gl_drawable
= data
? data
->gl_drawable
: (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
1436 escape
.pixmap
= data
? data
->pixmap
: (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
1437 if (flags
& DCX_CLIPCHILDREN
) escape
.mode
= ClipByChildren
;
1440 escape
.dc_rect
.left
= win_rect
->left
- top_rect
->left
;
1441 escape
.dc_rect
.top
= win_rect
->top
- top_rect
->top
;
1442 escape
.dc_rect
.right
= win_rect
->right
- top_rect
->left
;
1443 escape
.dc_rect
.bottom
= win_rect
->bottom
- top_rect
->top
;
1444 escape
.drawable_rect
.left
= top_rect
->left
;
1445 escape
.drawable_rect
.top
= top_rect
->top
;
1446 escape
.drawable_rect
.right
= top_rect
->right
;
1447 escape
.drawable_rect
.bottom
= top_rect
->bottom
;
1449 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1453 /***********************************************************************
1454 * X11DRV_ReleaseDC (X11DRV.@)
1456 void X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
1458 struct x11drv_escape_set_drawable escape
;
1460 escape
.code
= X11DRV_SET_DRAWABLE
;
1461 escape
.drawable
= root_window
;
1462 escape
.mode
= IncludeInferiors
;
1463 escape
.drawable_rect
= virtual_screen_rect
;
1464 SetRect( &escape
.dc_rect
, 0, 0, virtual_screen_rect
.right
- virtual_screen_rect
.left
,
1465 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
);
1466 escape
.fbconfig_id
= 0;
1467 escape
.gl_drawable
= 0;
1469 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1473 /***********************************************************************
1474 * SetCapture (X11DRV.@)
1476 void X11DRV_SetCapture( HWND hwnd
, UINT flags
)
1478 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1480 if (!(flags
& (GUI_INMOVESIZE
| GUI_INMENUMODE
))) return;
1484 Window grab_win
= X11DRV_get_client_window( GetAncestor( hwnd
, GA_ROOT
) );
1486 if (!grab_win
) return;
1488 XFlush( gdi_display
);
1489 XGrabPointer( thread_data
->display
, grab_win
, False
,
1490 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1491 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
);
1492 wine_tsx11_unlock();
1493 thread_data
->grab_window
= grab_win
;
1495 else /* release capture */
1498 XFlush( gdi_display
);
1499 XUngrabPointer( thread_data
->display
, CurrentTime
);
1500 wine_tsx11_unlock();
1501 thread_data
->grab_window
= None
;
1506 /*****************************************************************
1507 * SetParent (X11DRV.@)
1509 void X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
1511 Display
*display
= thread_display();
1512 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1515 if (parent
== old_parent
) return;
1517 if (parent
!= GetDesktopWindow()) /* a child window */
1519 if (old_parent
== GetDesktopWindow())
1521 /* destroy the old X windows */
1522 destroy_whole_window( display
, data
, FALSE
);
1523 destroy_icon_window( display
, data
);
1526 data
->managed
= FALSE
;
1527 RemovePropA( data
->hwnd
, managed_prop
);
1531 else /* new top level window */
1533 /* FIXME: we ignore errors since we can't really recover anyway */
1534 create_whole_window( display
, data
);
1539 /*****************************************************************
1540 * SetFocus (X11DRV.@)
1543 * Explicit colormap management seems to work only with OLVWM.
1545 void X11DRV_SetFocus( HWND hwnd
)
1547 Display
*display
= thread_display();
1548 struct x11drv_win_data
*data
;
1549 XWindowChanges changes
;
1551 /* If setting the focus to 0, uninstall the colormap */
1552 if (!hwnd
&& root_window
== DefaultRootWindow(display
))
1555 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1556 XUninstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1557 wine_tsx11_unlock();
1561 hwnd
= GetAncestor( hwnd
, GA_ROOT
);
1563 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1564 if (data
->managed
|| !data
->whole_window
) return;
1566 /* Set X focus and install colormap */
1568 changes
.stack_mode
= Above
;
1569 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
1570 if (root_window
== DefaultRootWindow(display
))
1572 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1573 /* FIXME: this is not entirely correct */
1574 XSetInputFocus( display
, data
->whole_window
, RevertToParent
,
1576 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1577 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1578 XInstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1580 wine_tsx11_unlock();
1584 /**********************************************************************
1585 * SetWindowIcon (X11DRV.@)
1587 * hIcon or hIconSm has changed (or is being initialised for the
1588 * first time). Complete the X11 driver-specific initialisation
1589 * and set the window hints.
1591 * This is not entirely correct, may need to create
1592 * an icon window and set the pixmap as a background
1594 void X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
1596 Display
*display
= thread_display();
1597 struct x11drv_win_data
*data
;
1599 if (type
!= ICON_BIG
) return; /* nothing to do here */
1601 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1602 if (!data
->whole_window
) return;
1603 if (!data
->managed
) return;
1607 set_icon_hints( display
, data
, icon
);
1609 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
1610 wine_tsx11_unlock();
1615 /***********************************************************************
1616 * SetWindowRgn (X11DRV.@)
1618 * Assign specified region to window (for non-rectangular windows)
1620 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
1622 struct x11drv_win_data
*data
;
1624 if ((data
= X11DRV_get_win_data( hwnd
)))
1626 sync_window_region( thread_display(), data
, hrgn
);
1628 else if (GetWindowThreadProcessId( hwnd
, NULL
) != GetCurrentThreadId())
1630 FIXME( "not supported on other thread window %p\n", hwnd
);
1631 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);