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 (ex_style
& WS_EX_TOOLWINDOW
) return 0;
153 if ((style
& WS_CAPTION
) == WS_CAPTION
)
155 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
156 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
157 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
158 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
160 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
161 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
162 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
167 /***********************************************************************
168 * get_x11_rect_offset
170 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
172 static void get_x11_rect_offset( struct x11drv_win_data
*data
, RECT
*rect
)
174 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
177 rect
->top
= rect
->bottom
= rect
->left
= rect
->right
= 0;
179 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
180 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
181 decor
= get_mwm_decorations( style
, ex_style
);
183 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
184 if (decor
& MWM_DECOR_BORDER
)
186 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
187 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
190 AdjustWindowRectEx( rect
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
194 /***********************************************************************
195 * get_window_attributes
197 * Fill the window attributes structure for an X window.
199 static int get_window_attributes( Display
*display
, struct x11drv_win_data
*data
,
200 XSetWindowAttributes
*attr
)
202 attr
->override_redirect
= !data
->managed
;
203 attr
->colormap
= X11DRV_PALETTE_PaletteXColormap
;
204 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
205 attr
->cursor
= x11drv_thread_data()->cursor
;
206 attr
->bit_gravity
= NorthWestGravity
;
207 attr
->backing_store
= NotUseful
;
208 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
209 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
210 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
| KeymapStateMask
);
211 if (data
->managed
) attr
->event_mask
|= StructureNotifyMask
| PropertyChangeMask
;
213 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
| CWCursor
|
214 CWEventMask
| CWBitGravity
| CWBackingStore
);
218 /***********************************************************************
219 * create_client_window
221 static Window
create_client_window( Display
*display
, struct x11drv_win_data
*data
, XVisualInfo
*vis
)
224 XSetWindowAttributes attr
;
227 attr
.bit_gravity
= NorthWestGravity
;
228 attr
.win_gravity
= NorthWestGravity
;
229 attr
.backing_store
= NotUseful
;
230 attr
.event_mask
= (ExposureMask
| PointerMotionMask
|
231 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
232 mask
= CWEventMask
| CWBitGravity
| CWWinGravity
| CWBackingStore
;
234 if ((cx
= data
->client_rect
.right
- data
->client_rect
.left
) <= 0) cx
= 1;
235 if ((cy
= data
->client_rect
.bottom
- data
->client_rect
.top
) <= 0) cy
= 1;
241 attr
.colormap
= XCreateColormap( display
, root_window
, vis
->visual
,
242 (vis
->class == PseudoColor
|| vis
->class == GrayScale
||
243 vis
->class == DirectColor
) ? AllocAll
: AllocNone
);
247 client
= XCreateWindow( display
, data
->whole_window
,
248 data
->client_rect
.left
- data
->whole_rect
.left
,
249 data
->client_rect
.top
- data
->whole_rect
.top
,
250 cx
, cy
, 0, screen_depth
, InputOutput
,
251 vis
? vis
->visual
: visual
, mask
, &attr
);
258 if (data
->client_window
)
260 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
261 if (thread_data
->cursor_window
== data
->client_window
) thread_data
->cursor_window
= None
;
262 XDeleteContext( display
, data
->client_window
, winContext
);
263 XDestroyWindow( display
, data
->client_window
);
265 data
->client_window
= client
;
267 if (data
->colormap
) XFreeColormap( display
, data
->colormap
);
268 data
->colormap
= vis
? attr
.colormap
: 0;
270 XMapWindow( display
, data
->client_window
);
271 XSaveContext( display
, data
->client_window
, winContext
, (char *)data
->hwnd
);
274 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)data
->client_window
);
275 return data
->client_window
;
279 /***********************************************************************
280 * X11DRV_sync_window_style
282 * Change the X window attributes when the window style has changed.
284 void X11DRV_sync_window_style( Display
*display
, struct x11drv_win_data
*data
)
286 if (data
->whole_window
!= root_window
)
288 XSetWindowAttributes attr
;
289 int mask
= get_window_attributes( display
, data
, &attr
);
292 XChangeWindowAttributes( display
, data
->whole_window
, mask
, &attr
);
298 /***********************************************************************
301 * Update the X11 window region.
303 static void sync_window_region( Display
*display
, struct x11drv_win_data
*data
, HRGN hrgn
)
305 #ifdef HAVE_LIBXSHAPE
306 if (!data
->whole_window
) return;
311 XShapeCombineMask( display
, data
->whole_window
, ShapeBounding
, 0, 0, None
, ShapeSet
);
316 RGNDATA
*pRegionData
= X11DRV_GetRegionData( hrgn
, 0 );
320 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
321 data
->window_rect
.left
- data
->whole_rect
.left
,
322 data
->window_rect
.top
- data
->whole_rect
.top
,
323 (XRectangle
*)pRegionData
->Buffer
,
324 pRegionData
->rdh
.nCount
, ShapeSet
, YXBanded
);
326 HeapFree(GetProcessHeap(), 0, pRegionData
);
329 #endif /* HAVE_LIBXSHAPE */
333 /***********************************************************************
336 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
339 char *buffer
, *utf8_buffer
;
342 /* allocate new buffer for window text */
343 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
344 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
345 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
347 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
348 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
350 HeapFree( GetProcessHeap(), 0, buffer
);
353 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
356 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
358 XSetWMName( display
, win
, &prop
);
359 XSetWMIconName( display
, win
, &prop
);
363 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
364 according to the standard
365 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
367 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
368 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
371 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
372 HeapFree( GetProcessHeap(), 0, buffer
);
376 /***********************************************************************
377 * X11DRV_set_win_format
379 BOOL
X11DRV_set_win_format( HWND hwnd
, XID fbconfig_id
)
381 Display
*display
= thread_display();
382 struct x11drv_win_data
*data
;
386 if (!(data
= X11DRV_get_win_data(hwnd
)) &&
387 !(data
= X11DRV_create_win_data(hwnd
))) return FALSE
;
389 if (data
->fbconfig_id
) return FALSE
; /* can't change it twice */
392 vis
= visual_from_fbconfig_id(fbconfig_id
);
394 if (!vis
) return FALSE
;
396 if (data
->whole_window
)
398 Window client
= data
->client_window
;
400 if (vis
->visualid
!= XVisualIDFromVisual(visual
))
402 client
= create_client_window( display
, data
, vis
);
403 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client
, data
->hwnd
, fbconfig_id
);
408 if (client
) goto done
;
412 w
= data
->client_rect
.right
- data
->client_rect
.left
;
413 h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
418 #ifdef SONAME_LIBXCOMPOSITE
421 XSetWindowAttributes attrib
;
422 Window parent
= X11DRV_get_whole_window( GetAncestor( hwnd
, GA_ROOT
));
424 if (!parent
) parent
= root_window
;
426 data
->colormap
= XCreateColormap(display
, parent
, vis
->visual
,
427 (vis
->class == PseudoColor
||
428 vis
->class == GrayScale
||
429 vis
->class == DirectColor
) ?
430 AllocAll
: AllocNone
);
431 attrib
.override_redirect
= True
;
432 attrib
.colormap
= data
->colormap
;
433 XInstallColormap(gdi_display
, attrib
.colormap
);
435 data
->gl_drawable
= XCreateWindow(display
, parent
, -w
, 0, w
, h
, 0,
436 vis
->depth
, InputOutput
, vis
->visual
,
437 CWColormap
| CWOverrideRedirect
,
439 if(data
->gl_drawable
)
441 pXCompositeRedirectWindow(display
, data
->gl_drawable
,
442 CompositeRedirectManual
);
443 XMapWindow(display
, data
->gl_drawable
);
451 WARN("XComposite is not available, using GLXPixmap hack\n");
454 data
->pixmap
= XCreatePixmap(display
, root_window
, w
, h
, vis
->depth
);
462 data
->gl_drawable
= create_glxpixmap(display
, vis
, data
->pixmap
);
463 if(!data
->gl_drawable
)
465 XFreePixmap(display
, data
->pixmap
);
470 if (data
->pixmap
) SetPropA(hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
473 if (!data
->gl_drawable
) return FALSE
;
475 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
476 data
->gl_drawable
, fbconfig_id
);
477 SetPropA(hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
480 data
->fbconfig_id
= fbconfig_id
;
481 SetPropA(hwnd
, fbconfig_id_prop
, (HANDLE
)data
->fbconfig_id
);
485 WIN_invalidate_dce( hwnd
, NULL
);
489 /***********************************************************************
492 static void sync_gl_drawable(Display
*display
, struct x11drv_win_data
*data
)
494 int w
= data
->client_rect
.right
- data
->client_rect
.left
;
495 int h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
503 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
504 #ifdef SONAME_LIBXCOMPOSITE
508 XMoveResizeWindow(display
, data
->gl_drawable
, -w
, 0, w
, h
);
516 vis
= visual_from_fbconfig_id(data
->fbconfig_id
);
523 pix
= XCreatePixmap(display
, root_window
, w
, h
, vis
->depth
);
526 ERR("Failed to create pixmap for offscreen rendering\n");
532 glxp
= create_glxpixmap(display
, vis
, pix
);
535 ERR("Failed to create drawable for offscreen rendering\n");
536 XFreePixmap(display
, pix
);
544 mark_drawable_dirty(data
->gl_drawable
, glxp
);
546 XFreePixmap(display
, data
->pixmap
);
547 destroy_glxpixmap(display
, data
->gl_drawable
);
550 data
->gl_drawable
= glxp
;
555 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
556 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
560 /***********************************************************************
563 * fill the window changes structure
565 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
569 if (old
->right
- old
->left
!= new->right
- new->left
)
571 if ((changes
->width
= new->right
- new->left
) <= 0) changes
->width
= 1;
574 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
576 if ((changes
->height
= new->bottom
- new->top
) <= 0) changes
->height
= 1;
579 if (old
->left
!= new->left
)
581 changes
->x
= new->left
;
584 if (old
->top
!= new->top
)
586 changes
->y
= new->top
;
593 /***********************************************************************
596 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
598 XSetWindowAttributes attr
;
600 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
601 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
602 attr
.bit_gravity
= NorthWestGravity
;
603 attr
.backing_store
= NotUseful
/*WhenMapped*/;
604 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
607 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
608 GetSystemMetrics( SM_CXICON
),
609 GetSystemMetrics( SM_CYICON
),
612 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
613 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
614 XFlush( display
); /* make sure the window exists before we start painting to it */
617 TRACE( "created %lx\n", data
->icon_window
);
618 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
619 return data
->icon_window
;
624 /***********************************************************************
625 * destroy_icon_window
627 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
629 if (!data
->icon_window
) return;
630 if (x11drv_thread_data()->cursor_window
== data
->icon_window
)
631 x11drv_thread_data()->cursor_window
= None
;
633 XDeleteContext( display
, data
->icon_window
, winContext
);
634 XDestroyWindow( display
, data
->icon_window
);
635 data
->icon_window
= 0;
637 RemovePropA( data
->hwnd
, icon_window_prop
);
641 /***********************************************************************
644 * Set the icon wm hints
646 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
, HICON hIcon
)
648 XWMHints
*hints
= data
->wm_hints
;
650 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
651 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
652 data
->hWMIconBitmap
= 0;
653 data
->hWMIconMask
= 0;
657 if (!data
->icon_window
) create_icon_window( display
, data
);
658 hints
->icon_window
= data
->icon_window
;
659 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
669 GetIconInfo(hIcon
, &ii
);
671 GetObjectA(ii
.hbmMask
, sizeof(bmMask
), &bmMask
);
674 rcMask
.right
= bmMask
.bmWidth
;
675 rcMask
.bottom
= bmMask
.bmHeight
;
677 hDC
= CreateCompatibleDC(0);
678 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
679 InvertRect(hDC
, &rcMask
);
680 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
681 SelectObject(hDC
, hbmOrig
);
684 data
->hWMIconBitmap
= ii
.hbmColor
;
685 data
->hWMIconMask
= ii
.hbmMask
;
687 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
688 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
689 destroy_icon_window( display
, data
);
690 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
695 /***********************************************************************
698 * set the window size hints
700 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
702 XSizeHints
* size_hints
;
704 if (!(size_hints
= XAllocSizeHints())) return;
706 /* don't update size hints if window is not in normal state */
707 if (!(style
& (WS_MINIMIZE
| WS_MAXIMIZE
)))
709 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
711 size_hints
->win_gravity
= StaticGravity
;
712 size_hints
->x
= data
->whole_rect
.left
;
713 size_hints
->y
= data
->whole_rect
.top
;
714 size_hints
->flags
|= PWinGravity
| PPosition
;
717 if (!is_window_resizable( data
, style
))
719 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
720 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
721 size_hints
->min_width
= size_hints
->max_width
;
722 size_hints
->min_height
= size_hints
->max_height
;
723 size_hints
->flags
|= PMinSize
| PMaxSize
;
726 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
731 /***********************************************************************
734 * get the name of the current process for setting class hints
736 static char *get_process_name(void)
742 WCHAR module
[MAX_PATH
];
743 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
744 if (len
&& len
< MAX_PATH
)
747 WCHAR
*p
, *appname
= module
;
749 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
750 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
751 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
752 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
754 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
763 /***********************************************************************
764 * set_initial_wm_hints
766 * Set the window manager hints that don't change over the lifetime of a window.
768 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
773 XClassHint
*class_hints
;
774 char *process_name
= get_process_name();
780 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
781 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
782 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
783 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
784 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
787 if ((class_hints
= XAllocClassHint()))
789 static char wine
[] = "Wine";
791 class_hints
->res_name
= process_name
;
792 class_hints
->res_class
= wine
;
793 XSetClassHint( display
, data
->whole_window
, class_hints
);
794 XFree( class_hints
);
797 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
798 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
799 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
801 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
802 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
804 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
805 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
807 data
->wm_hints
= XAllocWMHints();
812 HICON icon
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_BIG
, 0 );
813 if (!icon
) icon
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
);
814 data
->wm_hints
->flags
= 0;
815 set_icon_hints( display
, data
, icon
);
820 /***********************************************************************
821 * X11DRV_set_wm_hints
823 * Set the window manager hints for a newly-created window
825 void X11DRV_set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
830 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
831 DWORD ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
832 HWND owner
= GetWindow( data
->hwnd
, GW_OWNER
);
834 if (data
->hwnd
== GetDesktopWindow())
836 /* force some styles for the desktop to get the correct decorations */
837 style
|= WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
841 /* transient for hint */
844 Window owner_win
= X11DRV_get_whole_window( owner
);
846 XSetTransientForHint( display
, data
->whole_window
, owner_win
);
848 group_leader
= owner_win
;
850 else group_leader
= data
->whole_window
;
855 set_size_hints( display
, data
, style
);
857 /* set the WM_WINDOW_TYPE */
858 window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
859 if (style
& WS_THICKFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
860 else if (style
& WS_DLGFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
861 else if (ex_style
& WS_EX_DLGMODALFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
862 #if 0 /* many window managers don't handle utility windows very well */
863 else if (ex_style
& WS_EX_TOOLWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY
);
866 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
867 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
869 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
870 mwm_hints
.decorations
= get_mwm_decorations( style
, ex_style
);
871 mwm_hints
.functions
= MWM_FUNC_MOVE
;
872 if (is_window_resizable( data
, style
)) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
873 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
874 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
875 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
877 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
878 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
879 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
884 data
->wm_hints
->flags
|= InputHint
| StateHint
| WindowGroupHint
;
885 data
->wm_hints
->input
= !(style
& WS_DISABLED
);
886 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
887 data
->wm_hints
->window_group
= group_leader
;
888 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
895 /***********************************************************************
896 * X11DRV_window_to_X_rect
898 * Convert a rect from client to X window coordinates
900 void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
904 if (!data
->managed
) return;
905 if (IsRectEmpty( rect
)) return;
907 get_x11_rect_offset( data
, &rc
);
909 rect
->left
-= rc
.left
;
910 rect
->right
-= rc
.right
;
912 rect
->bottom
-= rc
.bottom
;
913 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
914 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
918 /***********************************************************************
919 * X11DRV_X_to_window_rect
921 * Opposite of X11DRV_window_to_X_rect
923 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
927 if (!data
->managed
) return;
928 if (IsRectEmpty( rect
)) return;
930 get_x11_rect_offset( data
, &rc
);
932 rect
->left
+= rc
.left
;
933 rect
->right
+= rc
.right
;
935 rect
->bottom
+= rc
.bottom
;
936 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
937 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
941 /***********************************************************************
942 * X11DRV_sync_window_position
944 * Synchronize the X window position with the Windows one
946 void X11DRV_sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
947 UINT swp_flags
, const RECT
*old_client_rect
,
948 const RECT
*old_whole_rect
)
950 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
951 XWindowChanges changes
;
952 int mask
= CWWidth
| CWHeight
;
954 if (data
->managed
&& data
->iconic
) return;
956 if ((changes
.width
= data
->whole_rect
.right
- data
->whole_rect
.left
) <= 0) changes
.width
= 1;
957 if ((changes
.height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
) <= 0) changes
.height
= 1;
959 /* only the size is allowed to change for the desktop window */
960 if (data
->whole_window
!= root_window
)
962 changes
.x
= data
->whole_rect
.left
- virtual_screen_rect
.left
;
963 changes
.y
= data
->whole_rect
.top
- virtual_screen_rect
.top
;
967 if (!(swp_flags
& SWP_NOZORDER
))
969 /* find window that this one must be after */
970 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
971 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
972 prev
= GetWindow( prev
, GW_HWNDPREV
);
973 if (!prev
) /* top child */
975 changes
.stack_mode
= Above
;
978 /* should use stack_mode Below but most window managers don't get it right */
979 /* and Above with a sibling doesn't work so well either, so we ignore it */
982 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
983 data
->hwnd
, data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
984 data
->whole_rect
.right
- data
->whole_rect
.left
,
985 data
->whole_rect
.bottom
- data
->whole_rect
.top
, changes
.sibling
, mask
);
988 set_size_hints( display
, data
, style
);
989 XReconfigureWMWindow( display
, data
->whole_window
,
990 DefaultScreen(display
), mask
, &changes
);
995 /***********************************************************************
996 * X11DRV_sync_client_position
998 * Synchronize the X client window position with the Windows one
1000 void X11DRV_sync_client_position( Display
*display
, struct x11drv_win_data
*data
,
1001 UINT swp_flags
, const RECT
*old_client_rect
,
1002 const RECT
*old_whole_rect
)
1005 XWindowChanges changes
;
1006 RECT old
= *old_client_rect
;
1007 RECT
new = data
->client_rect
;
1009 OffsetRect( &old
, -old_whole_rect
->left
, -old_whole_rect
->top
);
1010 OffsetRect( &new, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
1011 if (!(mask
= get_window_changes( &changes
, &old
, &new ))) return;
1013 if (data
->client_window
)
1015 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1016 data
->client_window
, new.left
, new.top
,
1017 new.right
- new.left
, new.bottom
- new.top
, mask
);
1019 XConfigureWindow( display
, data
->client_window
, mask
, &changes
);
1020 wine_tsx11_unlock();
1023 if (data
->gl_drawable
&& (mask
& (CWWidth
|CWHeight
))) sync_gl_drawable( display
, data
);
1027 /**********************************************************************
1028 * create_whole_window
1030 * Create the whole X window for a given window
1032 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1035 XSetWindowAttributes attr
;
1039 if (!(cx
= data
->window_rect
.right
- data
->window_rect
.left
)) cx
= 1;
1040 if (!(cy
= data
->window_rect
.bottom
- data
->window_rect
.top
)) cy
= 1;
1042 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1044 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1045 data
->managed
= TRUE
;
1046 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1049 mask
= get_window_attributes( display
, data
, &attr
);
1053 data
->whole_rect
= data
->window_rect
;
1054 data
->whole_window
= XCreateWindow( display
, root_window
,
1055 data
->window_rect
.left
- virtual_screen_rect
.left
,
1056 data
->window_rect
.top
- virtual_screen_rect
.top
,
1057 cx
, cy
, 0, screen_depth
, InputOutput
,
1058 visual
, mask
, &attr
);
1060 if (data
->whole_window
) XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1061 wine_tsx11_unlock();
1063 if (!data
->whole_window
) return 0;
1065 if (!create_client_window( display
, data
, NULL
))
1068 XDeleteContext( display
, data
->whole_window
, winContext
);
1069 XDestroyWindow( display
, data
->whole_window
);
1070 data
->whole_window
= 0;
1071 wine_tsx11_unlock();
1075 set_initial_wm_hints( display
, data
);
1076 X11DRV_set_wm_hints( display
, data
);
1078 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1080 /* set the window text */
1081 if (!InternalGetWindowText( data
->hwnd
, text
, sizeof(text
)/sizeof(WCHAR
) )) text
[0] = 0;
1082 sync_window_text( display
, data
->whole_window
, text
);
1084 /* set the window region */
1085 if ((hrgn
= CreateRectRgn( 0, 0, 0, 0 )))
1087 if (GetWindowRgn( data
->hwnd
, hrgn
) != ERROR
) sync_window_region( display
, data
, hrgn
);
1088 DeleteObject( hrgn
);
1091 XFlush( display
); /* make sure the window exists before we start painting to it */
1092 wine_tsx11_unlock();
1093 return data
->whole_window
;
1097 /**********************************************************************
1098 * destroy_whole_window
1100 * Destroy the whole X window for a given window.
1102 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
, BOOL already_destroyed
)
1104 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1106 if (!data
->whole_window
) return;
1108 TRACE( "win %p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1109 if (thread_data
->cursor_window
== data
->whole_window
||
1110 thread_data
->cursor_window
== data
->client_window
)
1111 thread_data
->cursor_window
= None
;
1113 XDeleteContext( display
, data
->whole_window
, winContext
);
1114 XDeleteContext( display
, data
->client_window
, winContext
);
1115 if (!already_destroyed
) XDestroyWindow( display
, data
->whole_window
);
1116 data
->whole_window
= data
->client_window
= 0;
1117 data
->wm_state
= WithdrawnState
;
1118 data
->net_wm_state
= 0;
1119 data
->mapped
= FALSE
;
1122 XUnsetICFocus( data
->xic
);
1123 XDestroyIC( data
->xic
);
1126 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1128 XFree( data
->wm_hints
);
1129 data
->wm_hints
= NULL
;
1130 wine_tsx11_unlock();
1131 RemovePropA( data
->hwnd
, whole_window_prop
);
1132 RemovePropA( data
->hwnd
, client_window_prop
);
1136 /*****************************************************************
1137 * SetWindowText (X11DRV.@)
1139 void X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1141 Display
*display
= thread_display();
1144 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(display
))
1145 sync_window_text( display
, win
, text
);
1149 /***********************************************************************
1150 * DestroyWindow (X11DRV.@)
1152 void X11DRV_DestroyWindow( HWND hwnd
)
1154 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1155 Display
*display
= thread_data
->display
;
1156 struct x11drv_win_data
*data
;
1158 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1162 destroy_glxpixmap(display
, data
->gl_drawable
);
1164 XFreePixmap(display
, data
->pixmap
);
1165 wine_tsx11_unlock();
1167 else if (data
->gl_drawable
)
1170 XDestroyWindow(display
, data
->gl_drawable
);
1171 wine_tsx11_unlock();
1174 destroy_whole_window( display
, data
, FALSE
);
1175 destroy_icon_window( display
, data
);
1180 XFreeColormap( display
, data
->colormap
);
1181 wine_tsx11_unlock();
1184 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1185 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1186 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1188 XDeleteContext( display
, (XID
)hwnd
, win_data_context
);
1189 wine_tsx11_unlock();
1190 HeapFree( GetProcessHeap(), 0, data
);
1194 /***********************************************************************
1195 * X11DRV_DestroyNotify
1197 void X11DRV_DestroyNotify( HWND hwnd
, XEvent
*event
)
1199 Display
*display
= event
->xdestroywindow
.display
;
1200 struct x11drv_win_data
*data
;
1202 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1204 FIXME( "window %p/%lx destroyed from the outside\n", hwnd
, data
->whole_window
);
1205 destroy_whole_window( display
, data
, TRUE
);
1209 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1211 struct x11drv_win_data
*data
;
1213 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
1217 if (!winContext
) winContext
= XUniqueContext();
1218 if (!win_data_context
) win_data_context
= XUniqueContext();
1219 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1220 wine_tsx11_unlock();
1226 /* initialize the desktop window id in the desktop manager process */
1227 static struct x11drv_win_data
*create_desktop_win_data( Display
*display
, HWND hwnd
)
1229 struct x11drv_win_data
*data
;
1232 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1234 visualid
= XVisualIDFromVisual(visual
);
1235 wine_tsx11_unlock();
1236 data
->whole_window
= data
->client_window
= root_window
;
1237 data
->managed
= TRUE
;
1238 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1239 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1240 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)root_window
);
1241 set_initial_wm_hints( display
, data
);
1245 /**********************************************************************
1246 * CreateDesktopWindow (X11DRV.@)
1248 BOOL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1250 unsigned int width
, height
;
1252 /* retrieve the real size of the desktop */
1253 SERVER_START_REQ( get_window_rectangles
)
1256 wine_server_call( req
);
1257 width
= reply
->window
.right
- reply
->window
.left
;
1258 height
= reply
->window
.bottom
- reply
->window
.top
;
1262 if (!width
&& !height
) /* not initialized yet */
1264 SERVER_START_REQ( set_window_pos
)
1268 req
->flags
= SWP_NOZORDER
;
1269 req
->window
.left
= virtual_screen_rect
.left
;
1270 req
->window
.top
= virtual_screen_rect
.top
;
1271 req
->window
.right
= virtual_screen_rect
.right
;
1272 req
->window
.bottom
= virtual_screen_rect
.bottom
;
1273 req
->client
= req
->window
;
1274 wine_server_call( req
);
1280 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1281 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1287 /**********************************************************************
1288 * CreateWindow (X11DRV.@)
1290 BOOL
X11DRV_CreateWindow( HWND hwnd
)
1292 Display
*display
= thread_display();
1294 if (hwnd
== GetDesktopWindow() && root_window
!= DefaultRootWindow( display
))
1296 /* the desktop win data can't be created lazily */
1297 if (!create_desktop_win_data( display
, hwnd
)) return FALSE
;
1303 /***********************************************************************
1304 * X11DRV_get_win_data
1306 * Return the X11 data structure associated with a window.
1308 struct x11drv_win_data
*X11DRV_get_win_data( HWND hwnd
)
1312 if (!hwnd
|| XFindContext( thread_display(), (XID
)hwnd
, win_data_context
, &data
)) data
= NULL
;
1313 return (struct x11drv_win_data
*)data
;
1317 /***********************************************************************
1318 * X11DRV_create_win_data
1320 * Create an X11 data window structure for an existing window.
1322 struct x11drv_win_data
*X11DRV_create_win_data( HWND hwnd
)
1324 Display
*display
= thread_display();
1325 struct x11drv_win_data
*data
;
1328 if (!(parent
= GetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop */
1329 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1331 GetWindowRect( hwnd
, &data
->window_rect
);
1332 MapWindowPoints( 0, parent
, (POINT
*)&data
->window_rect
, 2 );
1333 data
->whole_rect
= data
->window_rect
;
1334 GetClientRect( hwnd
, &data
->client_rect
);
1335 MapWindowPoints( hwnd
, parent
, (POINT
*)&data
->client_rect
, 2 );
1337 if (parent
== GetDesktopWindow())
1339 if (!create_whole_window( display
, data
))
1341 HeapFree( GetProcessHeap(), 0, data
);
1344 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1345 hwnd
, data
->whole_window
, data
->client_window
, wine_dbgstr_rect( &data
->window_rect
),
1346 wine_dbgstr_rect( &data
->whole_rect
), wine_dbgstr_rect( &data
->client_rect
));
1352 /***********************************************************************
1353 * X11DRV_get_whole_window
1355 * Return the X window associated with the full area of a window
1357 Window
X11DRV_get_whole_window( HWND hwnd
)
1359 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1363 if (hwnd
== GetDesktopWindow()) return root_window
;
1364 return (Window
)GetPropA( hwnd
, whole_window_prop
);
1366 return data
->whole_window
;
1370 /***********************************************************************
1371 * X11DRV_get_client_window
1373 * Return the X window associated with the client area of a window
1375 Window
X11DRV_get_client_window( HWND hwnd
)
1377 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1381 if (hwnd
== GetDesktopWindow()) return root_window
;
1382 return (Window
)GetPropA( hwnd
, client_window_prop
);
1384 return data
->client_window
;
1388 /***********************************************************************
1391 * Return the X input context associated with a window
1393 XIC
X11DRV_get_ic( HWND hwnd
)
1395 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1398 if (!data
) return 0;
1399 if (data
->xic
) return data
->xic
;
1400 if (!(xim
= x11drv_thread_data()->xim
)) return 0;
1401 return X11DRV_CreateIC( xim
, data
);
1405 /***********************************************************************
1406 * X11DRV_GetDC (X11DRV.@)
1408 void X11DRV_GetDC( HDC hdc
, HWND hwnd
, HWND top
, const RECT
*win_rect
,
1409 const RECT
*top_rect
, DWORD flags
)
1411 struct x11drv_escape_set_drawable escape
;
1412 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1414 escape
.code
= X11DRV_SET_DRAWABLE
;
1415 escape
.mode
= IncludeInferiors
;
1416 escape
.fbconfig_id
= 0;
1417 escape
.gl_drawable
= 0;
1420 if (top
== hwnd
&& data
&& IsIconic( hwnd
) && data
->icon_window
)
1422 escape
.drawable
= data
->icon_window
;
1424 else if (top
== hwnd
&& (flags
& DCX_WINDOW
))
1426 escape
.drawable
= data
? data
->whole_window
: X11DRV_get_whole_window( hwnd
);
1430 escape
.drawable
= X11DRV_get_client_window( top
);
1431 escape
.fbconfig_id
= data
? data
->fbconfig_id
: (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1432 escape
.gl_drawable
= data
? data
->gl_drawable
: (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
1433 escape
.pixmap
= data
? data
->pixmap
: (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
1434 if (flags
& DCX_CLIPCHILDREN
) escape
.mode
= ClipByChildren
;
1437 escape
.dc_rect
.left
= win_rect
->left
- top_rect
->left
;
1438 escape
.dc_rect
.top
= win_rect
->top
- top_rect
->top
;
1439 escape
.dc_rect
.right
= win_rect
->right
- top_rect
->left
;
1440 escape
.dc_rect
.bottom
= win_rect
->bottom
- top_rect
->top
;
1441 escape
.drawable_rect
.left
= top_rect
->left
;
1442 escape
.drawable_rect
.top
= top_rect
->top
;
1443 escape
.drawable_rect
.right
= top_rect
->right
;
1444 escape
.drawable_rect
.bottom
= top_rect
->bottom
;
1446 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1450 /***********************************************************************
1451 * X11DRV_ReleaseDC (X11DRV.@)
1453 void X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
1455 struct x11drv_escape_set_drawable escape
;
1457 escape
.code
= X11DRV_SET_DRAWABLE
;
1458 escape
.drawable
= root_window
;
1459 escape
.mode
= IncludeInferiors
;
1460 escape
.drawable_rect
= virtual_screen_rect
;
1461 SetRect( &escape
.dc_rect
, 0, 0, virtual_screen_rect
.right
- virtual_screen_rect
.left
,
1462 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
);
1463 escape
.fbconfig_id
= 0;
1464 escape
.gl_drawable
= 0;
1466 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
1470 /***********************************************************************
1471 * SetCapture (X11DRV.@)
1473 void X11DRV_SetCapture( HWND hwnd
, UINT flags
)
1475 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1477 if (!(flags
& (GUI_INMOVESIZE
| GUI_INMENUMODE
))) return;
1481 Window grab_win
= X11DRV_get_client_window( GetAncestor( hwnd
, GA_ROOT
) );
1483 if (!grab_win
) return;
1485 XFlush( gdi_display
);
1486 XGrabPointer( thread_data
->display
, grab_win
, False
,
1487 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1488 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
);
1489 wine_tsx11_unlock();
1490 thread_data
->grab_window
= grab_win
;
1492 else /* release capture */
1495 XFlush( gdi_display
);
1496 XUngrabPointer( thread_data
->display
, CurrentTime
);
1497 wine_tsx11_unlock();
1498 thread_data
->grab_window
= None
;
1503 /*****************************************************************
1504 * SetParent (X11DRV.@)
1506 void X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
1508 Display
*display
= thread_display();
1509 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1512 if (parent
== old_parent
) return;
1514 if (parent
!= GetDesktopWindow()) /* a child window */
1516 if (old_parent
== GetDesktopWindow())
1518 /* destroy the old X windows */
1519 destroy_whole_window( display
, data
, FALSE
);
1520 destroy_icon_window( display
, data
);
1523 data
->managed
= FALSE
;
1524 RemovePropA( data
->hwnd
, managed_prop
);
1528 else /* new top level window */
1530 /* FIXME: we ignore errors since we can't really recover anyway */
1531 create_whole_window( display
, data
);
1536 /*****************************************************************
1537 * SetFocus (X11DRV.@)
1540 * Explicit colormap management seems to work only with OLVWM.
1542 void X11DRV_SetFocus( HWND hwnd
)
1544 Display
*display
= thread_display();
1545 struct x11drv_win_data
*data
;
1546 XWindowChanges changes
;
1548 /* If setting the focus to 0, uninstall the colormap */
1549 if (!hwnd
&& root_window
== DefaultRootWindow(display
))
1552 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1553 XUninstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1554 wine_tsx11_unlock();
1558 hwnd
= GetAncestor( hwnd
, GA_ROOT
);
1560 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1561 if (data
->managed
|| !data
->whole_window
) return;
1563 /* Set X focus and install colormap */
1565 changes
.stack_mode
= Above
;
1566 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
1567 if (root_window
== DefaultRootWindow(display
))
1569 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1570 /* FIXME: this is not entirely correct */
1571 XSetInputFocus( display
, data
->whole_window
, RevertToParent
,
1573 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1574 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1575 XInstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1577 wine_tsx11_unlock();
1581 /**********************************************************************
1582 * SetWindowIcon (X11DRV.@)
1584 * hIcon or hIconSm has changed (or is being initialised for the
1585 * first time). Complete the X11 driver-specific initialisation
1586 * and set the window hints.
1588 * This is not entirely correct, may need to create
1589 * an icon window and set the pixmap as a background
1591 void X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
1593 Display
*display
= thread_display();
1594 struct x11drv_win_data
*data
;
1596 if (type
!= ICON_BIG
) return; /* nothing to do here */
1598 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1599 if (!data
->whole_window
) return;
1600 if (!data
->managed
) return;
1604 set_icon_hints( display
, data
, icon
);
1606 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
1607 wine_tsx11_unlock();
1612 /***********************************************************************
1613 * SetWindowRgn (X11DRV.@)
1615 * Assign specified region to window (for non-rectangular windows)
1617 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
1619 struct x11drv_win_data
*data
;
1621 if ((data
= X11DRV_get_win_data( hwnd
)))
1623 sync_window_region( thread_display(), data
, hrgn
);
1625 else if (GetWindowThreadProcessId( hwnd
, NULL
) != GetCurrentThreadId())
1627 FIXME( "not supported on other thread window %p\n", hwnd
);
1628 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);