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"
52 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
54 /* X context to associate a hwnd to an X window */
55 XContext winContext
= 0;
57 /* X context to associate a struct x11drv_win_data to an hwnd */
58 static XContext win_data_context
;
60 static const char whole_window_prop
[] = "__wine_x11_whole_window";
61 static const char client_window_prop
[]= "__wine_x11_client_window";
62 static const char icon_window_prop
[] = "__wine_x11_icon_window";
63 static const char fbconfig_id_prop
[] = "__wine_x11_fbconfig_id";
64 static const char gl_drawable_prop
[] = "__wine_x11_gl_drawable";
65 static const char pixmap_prop
[] = "__wine_x11_pixmap";
66 static const char managed_prop
[] = "__wine_x11_managed";
67 static const char visual_id_prop
[] = "__wine_x11_visual_id";
69 /* for XDG systray icons */
70 #define SYSTEM_TRAY_REQUEST_DOCK 0
72 extern int usexcomposite
;
74 /***********************************************************************
77 * Check if a given window should be managed
79 BOOL
is_window_managed( HWND hwnd
, UINT swp_flags
, const RECT
*window_rect
)
81 DWORD style
, ex_style
;
83 if (!managed_mode
) return FALSE
;
85 /* child windows are not managed */
86 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
87 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) return FALSE
;
88 /* activated windows are managed */
89 if (!(swp_flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
))) return TRUE
;
90 if (hwnd
== GetActiveWindow()) return TRUE
;
91 /* windows with caption are managed */
92 if ((style
& WS_CAPTION
) == WS_CAPTION
) return TRUE
;
93 /* tool windows are not managed */
94 ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
95 if (ex_style
& WS_EX_TOOLWINDOW
) return FALSE
;
96 /* windows with thick frame are managed */
97 if (style
& WS_THICKFRAME
) return TRUE
;
98 /* application windows are managed */
99 if (ex_style
& WS_EX_APPWINDOW
) return TRUE
;
100 if (style
& WS_POPUP
)
102 /* popup with sysmenu == caption are managed */
103 if (style
& WS_SYSMENU
) return TRUE
;
104 /* full-screen popup windows are managed */
105 if ((window_rect
->right
- window_rect
->left
) == screen_width
&&
106 (window_rect
->bottom
- window_rect
->top
) == screen_height
)
109 /* default: not managed */
114 /***********************************************************************
115 * X11DRV_is_window_rect_mapped
117 * Check if the X whole window should be mapped based on its rectangle
119 BOOL
X11DRV_is_window_rect_mapped( const RECT
*rect
)
121 /* don't map if rect is empty */
122 if (IsRectEmpty( rect
)) return FALSE
;
124 /* don't map if rect is off-screen */
125 if (rect
->left
>= virtual_screen_rect
.right
||
126 rect
->top
>= virtual_screen_rect
.bottom
||
127 rect
->right
<= virtual_screen_rect
.left
||
128 rect
->bottom
<= virtual_screen_rect
.top
)
135 /***********************************************************************
136 * get_mwm_decorations
138 static unsigned long get_mwm_decorations( DWORD style
, DWORD ex_style
)
140 unsigned long ret
= 0;
142 if (ex_style
& WS_EX_TOOLWINDOW
) return 0;
144 if ((style
& WS_CAPTION
) == WS_CAPTION
)
146 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
147 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
148 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
149 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
151 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
152 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
153 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
158 /***********************************************************************
159 * get_x11_rect_offset
161 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
163 static void get_x11_rect_offset( struct x11drv_win_data
*data
, RECT
*rect
)
165 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
168 rect
->top
= rect
->bottom
= rect
->left
= rect
->right
= 0;
170 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
171 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
172 decor
= get_mwm_decorations( style
, ex_style
);
174 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
175 if (decor
& MWM_DECOR_BORDER
)
177 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
178 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
181 AdjustWindowRectEx( rect
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
185 /***********************************************************************
186 * get_window_attributes
188 * Fill the window attributes structure for an X window.
190 static int get_window_attributes( Display
*display
, struct x11drv_win_data
*data
,
191 XSetWindowAttributes
*attr
)
193 attr
->override_redirect
= !data
->managed
;
194 attr
->colormap
= X11DRV_PALETTE_PaletteXColormap
;
195 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
196 attr
->cursor
= x11drv_thread_data()->cursor
;
197 attr
->bit_gravity
= NorthWestGravity
;
198 attr
->backing_store
= NotUseful
;
199 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
200 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
201 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
| KeymapStateMask
);
202 if (data
->managed
) attr
->event_mask
|= StructureNotifyMask
;
204 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
| CWCursor
|
205 CWEventMask
| CWBitGravity
| CWBackingStore
);
209 /***********************************************************************
210 * create_client_window
212 static Window
create_client_window( Display
*display
, struct x11drv_win_data
*data
, XVisualInfo
*vis
)
215 XSetWindowAttributes attr
;
218 attr
.bit_gravity
= NorthWestGravity
;
219 attr
.win_gravity
= NorthWestGravity
;
220 attr
.backing_store
= NotUseful
;
221 attr
.event_mask
= (ExposureMask
| PointerMotionMask
|
222 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
223 mask
= CWEventMask
| CWBitGravity
| CWWinGravity
| CWBackingStore
;
225 if ((cx
= data
->client_rect
.right
- data
->client_rect
.left
) <= 0) cx
= 1;
226 if ((cy
= data
->client_rect
.bottom
- data
->client_rect
.top
) <= 0) cy
= 1;
232 attr
.colormap
= XCreateColormap( display
, root_window
, vis
->visual
,
233 (vis
->class == PseudoColor
|| vis
->class == GrayScale
||
234 vis
->class == DirectColor
) ? AllocAll
: AllocNone
);
238 client
= XCreateWindow( display
, data
->whole_window
,
239 data
->client_rect
.left
- data
->whole_rect
.left
,
240 data
->client_rect
.top
- data
->whole_rect
.top
,
241 cx
, cy
, 0, screen_depth
, InputOutput
,
242 vis
? vis
->visual
: visual
, mask
, &attr
);
249 if (data
->client_window
)
251 XDeleteContext( display
, data
->client_window
, winContext
);
252 XDestroyWindow( display
, data
->client_window
);
254 data
->client_window
= client
;
256 if (data
->colormap
) XFreeColormap( display
, data
->colormap
);
257 data
->colormap
= vis
? attr
.colormap
: 0;
259 XMapWindow( display
, data
->client_window
);
260 XSaveContext( display
, data
->client_window
, winContext
, (char *)data
->hwnd
);
263 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)data
->client_window
);
264 return data
->client_window
;
268 /***********************************************************************
269 * X11DRV_sync_window_style
271 * Change the X window attributes when the window style has changed.
273 void X11DRV_sync_window_style( Display
*display
, struct x11drv_win_data
*data
)
275 if (data
->whole_window
!= root_window
)
277 XSetWindowAttributes attr
;
278 int mask
= get_window_attributes( display
, data
, &attr
);
281 XChangeWindowAttributes( display
, data
->whole_window
, mask
, &attr
);
287 /***********************************************************************
290 * Update the X11 window region.
292 static void sync_window_region( Display
*display
, struct x11drv_win_data
*data
, HRGN hrgn
)
294 #ifdef HAVE_LIBXSHAPE
295 if (!data
->whole_window
) return;
300 XShapeCombineMask( display
, data
->whole_window
, ShapeBounding
, 0, 0, None
, ShapeSet
);
305 RGNDATA
*pRegionData
= X11DRV_GetRegionData( hrgn
, 0 );
309 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
310 data
->window_rect
.left
- data
->whole_rect
.left
,
311 data
->window_rect
.top
- data
->whole_rect
.top
,
312 (XRectangle
*)pRegionData
->Buffer
,
313 pRegionData
->rdh
.nCount
, ShapeSet
, YXBanded
);
315 HeapFree(GetProcessHeap(), 0, pRegionData
);
318 #endif /* HAVE_LIBXSHAPE */
322 /***********************************************************************
325 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
328 char *buffer
, *utf8_buffer
;
331 /* allocate new buffer for window text */
332 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
333 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
334 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
336 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
337 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
339 HeapFree( GetProcessHeap(), 0, buffer
);
342 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
345 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
347 XSetWMName( display
, win
, &prop
);
348 XSetWMIconName( display
, win
, &prop
);
352 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
353 according to the standard
354 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
356 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
357 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
360 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
361 HeapFree( GetProcessHeap(), 0, buffer
);
365 /***********************************************************************
366 * X11DRV_set_win_format
368 BOOL
X11DRV_set_win_format( HWND hwnd
, XID fbconfig_id
)
370 Display
*display
= thread_display();
371 struct x11drv_win_data
*data
;
375 if (!(data
= X11DRV_get_win_data(hwnd
)) &&
376 !(data
= X11DRV_create_win_data(hwnd
))) return FALSE
;
378 if (data
->fbconfig_id
) return FALSE
; /* can't change it twice */
381 vis
= visual_from_fbconfig_id(fbconfig_id
);
383 if (!vis
) return FALSE
;
385 if (data
->whole_window
)
387 Window client
= data
->client_window
;
389 if (vis
->visualid
!= XVisualIDFromVisual(visual
))
391 client
= create_client_window( display
, data
, vis
);
392 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client
, data
->hwnd
, fbconfig_id
);
397 if (client
) goto done
;
401 w
= data
->client_rect
.right
- data
->client_rect
.left
;
402 h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
407 #ifdef SONAME_LIBXCOMPOSITE
410 XSetWindowAttributes attrib
;
411 Window parent
= X11DRV_get_whole_window( GetAncestor( hwnd
, GA_ROOT
));
413 if (!parent
) parent
= root_window
;
415 data
->colormap
= XCreateColormap(display
, parent
, vis
->visual
,
416 (vis
->class == PseudoColor
||
417 vis
->class == GrayScale
||
418 vis
->class == DirectColor
) ?
419 AllocAll
: AllocNone
);
420 attrib
.override_redirect
= True
;
421 attrib
.colormap
= data
->colormap
;
422 XInstallColormap(gdi_display
, attrib
.colormap
);
424 data
->gl_drawable
= XCreateWindow(display
, parent
, -w
, 0, w
, h
, 0,
425 vis
->depth
, InputOutput
, vis
->visual
,
426 CWColormap
| CWOverrideRedirect
,
428 if(data
->gl_drawable
)
430 pXCompositeRedirectWindow(display
, data
->gl_drawable
,
431 CompositeRedirectManual
);
432 XMapWindow(display
, data
->gl_drawable
);
440 WARN("XComposite is not available, using GLXPixmap hack\n");
443 data
->pixmap
= XCreatePixmap(display
, root_window
, w
, h
, vis
->depth
);
451 data
->gl_drawable
= create_glxpixmap(display
, vis
, data
->pixmap
);
452 if(!data
->gl_drawable
)
454 XFreePixmap(display
, data
->pixmap
);
459 if (data
->pixmap
) SetPropA(hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
462 if (!data
->gl_drawable
) return FALSE
;
464 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
465 data
->gl_drawable
, fbconfig_id
);
466 SetPropA(hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
469 data
->fbconfig_id
= fbconfig_id
;
470 SetPropA(hwnd
, fbconfig_id_prop
, (HANDLE
)data
->fbconfig_id
);
474 invalidate_dce( hwnd
, &data
->window_rect
);
478 /***********************************************************************
481 static void sync_gl_drawable(Display
*display
, struct x11drv_win_data
*data
)
483 int w
= data
->client_rect
.right
- data
->client_rect
.left
;
484 int h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
489 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
490 #ifdef SONAME_LIBXCOMPOSITE
494 XMoveResizeWindow(display
, data
->gl_drawable
, -w
, 0, w
, h
);
502 vis
= visual_from_fbconfig_id(data
->fbconfig_id
);
509 pix
= XCreatePixmap(display
, root_window
, w
, h
, vis
->depth
);
512 ERR("Failed to create pixmap for offscreen rendering\n");
518 glxp
= create_glxpixmap(display
, vis
, pix
);
521 ERR("Failed to create drawable for offscreen rendering\n");
522 XFreePixmap(display
, pix
);
530 mark_drawable_dirty(data
->gl_drawable
, glxp
);
532 XFreePixmap(display
, data
->pixmap
);
533 destroy_glxpixmap(display
, data
->gl_drawable
);
536 data
->gl_drawable
= glxp
;
540 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
541 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
542 invalidate_dce( data
->hwnd
, &data
->window_rect
);
546 /***********************************************************************
549 * fill the window changes structure
551 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
555 if (old
->right
- old
->left
!= new->right
- new->left
)
557 if ((changes
->width
= new->right
- new->left
) <= 0) changes
->width
= 1;
560 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
562 if ((changes
->height
= new->bottom
- new->top
) <= 0) changes
->height
= 1;
565 if (old
->left
!= new->left
)
567 changes
->x
= new->left
;
570 if (old
->top
!= new->top
)
572 changes
->y
= new->top
;
579 /***********************************************************************
582 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
584 XSetWindowAttributes attr
;
586 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
587 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
588 attr
.bit_gravity
= NorthWestGravity
;
589 attr
.backing_store
= NotUseful
/*WhenMapped*/;
590 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
593 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
594 GetSystemMetrics( SM_CXICON
),
595 GetSystemMetrics( SM_CYICON
),
598 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
599 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
602 TRACE( "created %lx\n", data
->icon_window
);
603 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
604 return data
->icon_window
;
609 /***********************************************************************
610 * destroy_icon_window
612 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
614 if (!data
->icon_window
) return;
615 if (x11drv_thread_data()->cursor_window
== data
->icon_window
)
616 x11drv_thread_data()->cursor_window
= None
;
618 XDeleteContext( display
, data
->icon_window
, winContext
);
619 XDestroyWindow( display
, data
->icon_window
);
620 data
->icon_window
= 0;
622 RemovePropA( data
->hwnd
, icon_window_prop
);
626 /***********************************************************************
629 * Set the icon wm hints
631 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
, HICON hIcon
)
633 XWMHints
*hints
= data
->wm_hints
;
635 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
636 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
637 data
->hWMIconBitmap
= 0;
638 data
->hWMIconMask
= 0;
642 if (!data
->icon_window
) create_icon_window( display
, data
);
643 hints
->icon_window
= data
->icon_window
;
644 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
654 GetIconInfo(hIcon
, &ii
);
656 GetObjectA(ii
.hbmMask
, sizeof(bmMask
), &bmMask
);
659 rcMask
.right
= bmMask
.bmWidth
;
660 rcMask
.bottom
= bmMask
.bmHeight
;
662 hDC
= CreateCompatibleDC(0);
663 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
664 InvertRect(hDC
, &rcMask
);
665 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
666 SelectObject(hDC
, hbmOrig
);
669 data
->hWMIconBitmap
= ii
.hbmColor
;
670 data
->hWMIconMask
= ii
.hbmMask
;
672 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
673 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
674 destroy_icon_window( display
, data
);
675 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
679 /***********************************************************************
680 * wine_make_systray_window (X11DRV.@)
682 * Docks the given X window with the NETWM system tray.
684 void X11DRV_make_systray_window( HWND hwnd
)
686 static Atom systray_atom
;
687 Display
*display
= thread_display();
688 struct x11drv_win_data
*data
;
689 Window systray_window
;
691 if (!(data
= X11DRV_get_win_data( hwnd
)) &&
692 !(data
= X11DRV_create_win_data( hwnd
))) return;
697 if (DefaultScreen( display
) == 0)
698 systray_atom
= x11drv_atom(_NET_SYSTEM_TRAY_S0
);
701 char systray_buffer
[29]; /* strlen(_NET_SYSTEM_TRAY_S4294967295)+1 */
702 sprintf( systray_buffer
, "_NET_SYSTEM_TRAY_S%u", DefaultScreen( display
) );
703 systray_atom
= XInternAtom( display
, systray_buffer
, False
);
706 systray_window
= XGetSelectionOwner( display
, systray_atom
);
709 TRACE("Docking tray icon %p\n", data
->hwnd
);
711 if (systray_window
!= None
)
714 unsigned long info
[2];
716 /* Put the window offscreen so it isn't mapped. The window _cannot_ be
717 * mapped if we intend to dock with an XEMBED tray. If the window is
718 * mapped when we dock, it may become visible as a child of the root
719 * window after it docks, which isn't the proper behavior.
721 * For more information on this problem, see
722 * http://standards.freedesktop.org/xembed-spec/latest/ar01s04.html */
724 SetWindowPos( data
->hwnd
, NULL
, virtual_screen_rect
.right
+ 1, virtual_screen_rect
.bottom
+ 1,
725 0, 0, SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
727 /* set XEMBED protocol data on the window */
728 info
[0] = 0; /* protocol version */
729 info
[1] = 1; /* mapped = true */
732 XChangeProperty( display
, data
->whole_window
,
733 x11drv_atom(_XEMBED_INFO
),
734 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
,
735 (unsigned char*)info
, 2 );
738 /* send the docking request message */
739 ZeroMemory( &ev
, sizeof(ev
) );
740 ev
.xclient
.type
= ClientMessage
;
741 ev
.xclient
.window
= systray_window
;
742 ev
.xclient
.message_type
= x11drv_atom( _NET_SYSTEM_TRAY_OPCODE
);
743 ev
.xclient
.format
= 32;
744 ev
.xclient
.data
.l
[0] = CurrentTime
;
745 ev
.xclient
.data
.l
[1] = SYSTEM_TRAY_REQUEST_DOCK
;
746 ev
.xclient
.data
.l
[2] = data
->whole_window
;
747 ev
.xclient
.data
.l
[3] = 0;
748 ev
.xclient
.data
.l
[4] = 0;
751 XSendEvent( display
, systray_window
, False
, NoEventMask
, &ev
);
759 /* fall back to he KDE hints if the WM doesn't support XEMBED'ed
763 XChangeProperty( display
, data
->whole_window
,
764 x11drv_atom(KWM_DOCKWINDOW
),
765 x11drv_atom(KWM_DOCKWINDOW
), 32, PropModeReplace
,
766 (unsigned char*)&val
, 1 );
767 XChangeProperty( display
, data
->whole_window
,
768 x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR
),
769 XA_WINDOW
, 32, PropModeReplace
,
770 (unsigned char*)&data
->whole_window
, 1 );
776 /***********************************************************************
779 * set the window size hints
781 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
783 XSizeHints
* size_hints
;
785 if ((size_hints
= XAllocSizeHints()))
787 size_hints
->flags
= 0;
789 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
791 size_hints
->win_gravity
= StaticGravity
;
792 size_hints
->x
= data
->whole_rect
.left
;
793 size_hints
->y
= data
->whole_rect
.top
;
794 size_hints
->flags
|= PWinGravity
| PPosition
;
797 if ( !(style
& WS_THICKFRAME
) )
799 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
800 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
801 size_hints
->min_width
= size_hints
->max_width
;
802 size_hints
->min_height
= size_hints
->max_height
;
803 size_hints
->flags
|= PMinSize
| PMaxSize
;
805 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
811 /***********************************************************************
814 * get the name of the current process for setting class hints
816 static char *get_process_name(void)
822 WCHAR module
[MAX_PATH
];
823 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
824 if (len
&& len
< MAX_PATH
)
827 WCHAR
*p
, *appname
= module
;
829 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
830 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
831 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
832 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
834 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
843 /***********************************************************************
844 * set_initial_wm_hints
846 * Set the window manager hints that don't change over the lifetime of a window.
848 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
853 XClassHint
*class_hints
;
854 char *process_name
= get_process_name();
860 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
861 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
862 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
863 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
864 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
867 if ((class_hints
= XAllocClassHint()))
869 static char wine
[] = "Wine";
871 class_hints
->res_name
= process_name
;
872 class_hints
->res_class
= wine
;
873 XSetClassHint( display
, data
->whole_window
, class_hints
);
874 XFree( class_hints
);
877 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
878 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
879 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
881 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
882 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
884 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
885 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
887 data
->wm_hints
= XAllocWMHints();
892 HICON icon
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_BIG
, 0 );
893 if (!icon
) icon
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
);
894 data
->wm_hints
->flags
= 0;
895 set_icon_hints( display
, data
, icon
);
900 /***********************************************************************
901 * X11DRV_set_wm_hints
903 * Set the window manager hints for a newly-created window
905 void X11DRV_set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
910 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
911 DWORD ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
912 HWND owner
= GetWindow( data
->hwnd
, GW_OWNER
);
914 if (data
->hwnd
== GetDesktopWindow())
916 /* force some styles for the desktop to get the correct decorations */
917 style
|= WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
921 /* transient for hint */
924 Window owner_win
= X11DRV_get_whole_window( owner
);
926 XSetTransientForHint( display
, data
->whole_window
, owner_win
);
928 group_leader
= owner_win
;
930 else group_leader
= data
->whole_window
;
935 set_size_hints( display
, data
, style
);
937 /* set the WM_WINDOW_TYPE */
938 window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
939 if (ex_style
& WS_EX_TOOLWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY
);
940 else if (style
& WS_THICKFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
941 else if (style
& WS_DLGFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
942 else if (ex_style
& WS_EX_DLGMODALFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
944 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
945 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
947 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
948 mwm_hints
.decorations
= get_mwm_decorations( style
, ex_style
);
949 mwm_hints
.functions
= MWM_FUNC_MOVE
;
950 if (style
& WS_THICKFRAME
) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
951 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
952 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
953 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
955 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
956 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
957 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
962 data
->wm_hints
->flags
|= InputHint
| StateHint
| WindowGroupHint
;
963 data
->wm_hints
->input
= !(style
& WS_DISABLED
);
964 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
965 data
->wm_hints
->window_group
= group_leader
;
966 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
973 /***********************************************************************
974 * X11DRV_set_iconic_state
976 * Set the X11 iconic state according to the window style.
978 void X11DRV_set_iconic_state( HWND hwnd
)
980 Display
*display
= thread_display();
981 struct x11drv_win_data
*data
;
983 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
984 BOOL iconic
= (style
& WS_MINIMIZE
) != 0;
986 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
987 if (!data
->whole_window
) return;
989 GetWindowRect( hwnd
, &rect
);
995 data
->wm_hints
->flags
|= StateHint
| IconPositionHint
;
996 data
->wm_hints
->initial_state
= iconic
? IconicState
: NormalState
;
997 data
->wm_hints
->icon_x
= rect
.left
- virtual_screen_rect
.left
;
998 data
->wm_hints
->icon_y
= rect
.top
- virtual_screen_rect
.top
;
999 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
1005 XIconifyWindow( display
, data
->whole_window
, DefaultScreen(display
) );
1007 if (X11DRV_is_window_rect_mapped( &rect
))
1008 XMapWindow( display
, data
->whole_window
);
1011 wine_tsx11_unlock();
1015 /***********************************************************************
1016 * X11DRV_window_to_X_rect
1018 * Convert a rect from client to X window coordinates
1020 void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1024 if (!data
->managed
) return;
1025 if (IsRectEmpty( rect
)) return;
1027 get_x11_rect_offset( data
, &rc
);
1029 rect
->left
-= rc
.left
;
1030 rect
->right
-= rc
.right
;
1031 rect
->top
-= rc
.top
;
1032 rect
->bottom
-= rc
.bottom
;
1033 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1034 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1038 /***********************************************************************
1039 * X11DRV_X_to_window_rect
1041 * Opposite of X11DRV_window_to_X_rect
1043 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1047 if (!data
->managed
) return;
1048 if (IsRectEmpty( rect
)) return;
1050 get_x11_rect_offset( data
, &rc
);
1052 rect
->left
+= rc
.left
;
1053 rect
->right
+= rc
.right
;
1054 rect
->top
+= rc
.top
;
1055 rect
->bottom
+= rc
.bottom
;
1056 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1057 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1061 /***********************************************************************
1062 * X11DRV_sync_window_position
1064 * Synchronize the X window position with the Windows one
1066 void X11DRV_sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
1067 UINT swp_flags
, const RECT
*old_client_rect
,
1068 const RECT
*old_whole_rect
)
1070 XWindowChanges changes
;
1071 int mask
= get_window_changes( &changes
, old_whole_rect
, &data
->whole_rect
);
1073 if (!(swp_flags
& SWP_NOZORDER
))
1075 /* find window that this one must be after */
1076 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
1077 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
1078 prev
= GetWindow( prev
, GW_HWNDPREV
);
1079 if (!prev
) /* top child */
1081 changes
.stack_mode
= Above
;
1082 mask
|= CWStackMode
;
1086 /* should use stack_mode Below but most window managers don't get it right */
1087 /* so move it above the next one in Z order */
1088 HWND next
= GetWindow( data
->hwnd
, GW_HWNDNEXT
);
1089 while (next
&& !(GetWindowLongW( next
, GWL_STYLE
) & WS_VISIBLE
))
1090 next
= GetWindow( next
, GW_HWNDNEXT
);
1093 changes
.stack_mode
= Above
;
1094 changes
.sibling
= X11DRV_get_whole_window(next
);
1095 mask
|= CWStackMode
| CWSibling
;
1100 /* only the size is allowed to change for the desktop window */
1101 if (data
->whole_window
== root_window
) mask
&= CWWidth
| CWHeight
;
1105 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1107 TRACE( "setting win %lx pos %d,%d,%dx%d after %lx changes=%x\n",
1108 data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1109 data
->whole_rect
.right
- data
->whole_rect
.left
,
1110 data
->whole_rect
.bottom
- data
->whole_rect
.top
, changes
.sibling
, mask
);
1113 if (mask
& (CWWidth
|CWHeight
)) set_size_hints( display
, data
, style
);
1114 if (mask
& CWX
) changes
.x
-= virtual_screen_rect
.left
;
1115 if (mask
& CWY
) changes
.y
-= virtual_screen_rect
.top
;
1116 XReconfigureWMWindow( display
, data
->whole_window
,
1117 DefaultScreen(display
), mask
, &changes
);
1118 wine_tsx11_unlock();
1123 /***********************************************************************
1124 * X11DRV_sync_client_position
1126 * Synchronize the X client window position with the Windows one
1128 void X11DRV_sync_client_position( Display
*display
, struct x11drv_win_data
*data
,
1129 UINT swp_flags
, const RECT
*old_client_rect
,
1130 const RECT
*old_whole_rect
)
1133 XWindowChanges changes
;
1134 RECT old
= *old_client_rect
;
1135 RECT
new = data
->client_rect
;
1137 OffsetRect( &old
, -old_whole_rect
->left
, -old_whole_rect
->top
);
1138 OffsetRect( &new, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
1139 if (!(mask
= get_window_changes( &changes
, &old
, &new ))) return;
1141 if (data
->client_window
)
1143 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1144 data
->client_window
, new.left
, new.top
,
1145 new.right
- new.left
, new.bottom
- new.top
, mask
);
1147 XConfigureWindow( display
, data
->client_window
, mask
, &changes
);
1148 wine_tsx11_unlock();
1151 if (data
->gl_drawable
&& (mask
& (CWWidth
|CWHeight
))) sync_gl_drawable( display
, data
);
1153 /* make sure the changes get to the server before we start painting */
1154 if (data
->client_window
|| data
->gl_drawable
)
1158 wine_tsx11_unlock();
1163 /**********************************************************************
1164 * create_whole_window
1166 * Create the whole X window for a given window
1168 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1171 XSetWindowAttributes attr
;
1176 if (!(cx
= data
->window_rect
.right
- data
->window_rect
.left
)) cx
= 1;
1177 if (!(cy
= data
->window_rect
.bottom
- data
->window_rect
.top
)) cy
= 1;
1179 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1181 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1182 data
->managed
= TRUE
;
1183 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1186 mask
= get_window_attributes( display
, data
, &attr
);
1190 data
->whole_rect
= data
->window_rect
;
1191 data
->whole_window
= XCreateWindow( display
, root_window
,
1192 data
->window_rect
.left
- virtual_screen_rect
.left
,
1193 data
->window_rect
.top
- virtual_screen_rect
.top
,
1194 cx
, cy
, 0, screen_depth
, InputOutput
,
1195 visual
, mask
, &attr
);
1197 if (data
->whole_window
) XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1198 wine_tsx11_unlock();
1200 if (!data
->whole_window
) return 0;
1202 if (!create_client_window( display
, data
, NULL
))
1205 XDeleteContext( display
, data
->whole_window
, winContext
);
1206 XDestroyWindow( display
, data
->whole_window
);
1207 data
->whole_window
= 0;
1208 wine_tsx11_unlock();
1212 xim
= x11drv_thread_data()->xim
;
1213 if (xim
) data
->xic
= X11DRV_CreateIC( xim
, display
, data
->whole_window
);
1215 set_initial_wm_hints( display
, data
);
1216 X11DRV_set_wm_hints( display
, data
);
1218 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1220 /* set the window text */
1221 if (!InternalGetWindowText( data
->hwnd
, text
, sizeof(text
)/sizeof(WCHAR
) )) text
[0] = 0;
1222 sync_window_text( display
, data
->whole_window
, text
);
1224 /* set the window region */
1225 if ((hrgn
= CreateRectRgn( 0, 0, 0, 0 )))
1227 if (GetWindowRgn( data
->hwnd
, hrgn
) != ERROR
) sync_window_region( display
, data
, hrgn
);
1228 DeleteObject( hrgn
);
1230 return data
->whole_window
;
1234 /**********************************************************************
1235 * destroy_whole_window
1237 * Destroy the whole X window for a given window.
1239 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1241 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1243 if (!data
->whole_window
) return;
1245 TRACE( "win %p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1246 if (thread_data
->cursor_window
== data
->whole_window
||
1247 thread_data
->cursor_window
== data
->client_window
)
1248 thread_data
->cursor_window
= None
;
1250 XDeleteContext( display
, data
->whole_window
, winContext
);
1251 XDeleteContext( display
, data
->client_window
, winContext
);
1252 XDestroyWindow( display
, data
->whole_window
);
1253 data
->whole_window
= data
->client_window
= 0;
1256 XUnsetICFocus( data
->xic
);
1257 XDestroyIC( data
->xic
);
1259 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1261 XFree( data
->wm_hints
);
1262 data
->wm_hints
= NULL
;
1263 wine_tsx11_unlock();
1264 RemovePropA( data
->hwnd
, whole_window_prop
);
1265 RemovePropA( data
->hwnd
, client_window_prop
);
1269 /*****************************************************************
1270 * SetWindowText (X11DRV.@)
1272 void X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1274 Display
*display
= thread_display();
1277 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(display
))
1278 sync_window_text( display
, win
, text
);
1282 /***********************************************************************
1283 * DestroyWindow (X11DRV.@)
1285 void X11DRV_DestroyWindow( HWND hwnd
)
1287 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1288 Display
*display
= thread_data
->display
;
1289 struct x11drv_win_data
*data
;
1291 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1295 destroy_glxpixmap(display
, data
->gl_drawable
);
1297 XFreePixmap(display
, data
->pixmap
);
1298 wine_tsx11_unlock();
1300 else if (data
->gl_drawable
)
1303 XDestroyWindow(display
, data
->gl_drawable
);
1304 wine_tsx11_unlock();
1307 free_window_dce( data
);
1308 destroy_whole_window( display
, data
);
1309 destroy_icon_window( display
, data
);
1314 XFreeColormap( display
, data
->colormap
);
1315 wine_tsx11_unlock();
1318 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1319 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1320 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1322 XDeleteContext( display
, (XID
)hwnd
, win_data_context
);
1323 wine_tsx11_unlock();
1324 HeapFree( GetProcessHeap(), 0, data
);
1328 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1330 struct x11drv_win_data
*data
;
1332 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
1336 if (!winContext
) winContext
= XUniqueContext();
1337 if (!win_data_context
) win_data_context
= XUniqueContext();
1338 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1339 wine_tsx11_unlock();
1345 /* initialize the desktop window id in the desktop manager process */
1346 static struct x11drv_win_data
*create_desktop_win_data( Display
*display
, HWND hwnd
)
1348 struct x11drv_win_data
*data
;
1351 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1353 visualid
= XVisualIDFromVisual(visual
);
1354 wine_tsx11_unlock();
1355 data
->whole_window
= data
->client_window
= root_window
;
1356 data
->managed
= TRUE
;
1357 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1358 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1359 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)root_window
);
1360 SetPropA( data
->hwnd
, visual_id_prop
, (HANDLE
)visualid
);
1361 set_initial_wm_hints( display
, data
);
1365 /**********************************************************************
1366 * CreateDesktopWindow (X11DRV.@)
1368 BOOL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1370 unsigned int width
, height
;
1372 /* retrieve the real size of the desktop */
1373 SERVER_START_REQ( get_window_rectangles
)
1376 wine_server_call( req
);
1377 width
= reply
->window
.right
- reply
->window
.left
;
1378 height
= reply
->window
.bottom
- reply
->window
.top
;
1382 if (!width
&& !height
) /* not initialized yet */
1384 SERVER_START_REQ( set_window_pos
)
1388 req
->flags
= SWP_NOZORDER
;
1389 req
->window
.left
= virtual_screen_rect
.left
;
1390 req
->window
.top
= virtual_screen_rect
.top
;
1391 req
->window
.right
= virtual_screen_rect
.right
;
1392 req
->window
.bottom
= virtual_screen_rect
.bottom
;
1393 req
->client
= req
->window
;
1394 wine_server_call( req
);
1400 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1401 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1407 /**********************************************************************
1408 * CreateWindow (X11DRV.@)
1410 BOOL
X11DRV_CreateWindow( HWND hwnd
)
1412 Display
*display
= thread_display();
1415 if (hwnd
== GetDesktopWindow() && root_window
!= DefaultRootWindow( display
))
1417 /* the desktop win data can't be created lazily */
1418 if (!create_desktop_win_data( display
, hwnd
)) return FALSE
;
1421 /* Show the window, maximizing or minimizing if needed */
1423 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1424 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1426 extern UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
); /*FIXME*/
1429 UINT swFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
1430 WIN_SetStyle( hwnd
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
1431 swFlag
= WINPOS_MinMaximize( hwnd
, swFlag
, &newPos
);
1433 swFlag
|= SWP_FRAMECHANGED
; /* Frame always gets changed */
1434 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || GetActiveWindow()) swFlag
|= SWP_NOACTIVATE
;
1436 SetWindowPos( hwnd
, 0, newPos
.left
, newPos
.top
,
1437 newPos
.right
, newPos
.bottom
, swFlag
);
1444 /***********************************************************************
1445 * X11DRV_get_win_data
1447 * Return the X11 data structure associated with a window.
1449 struct x11drv_win_data
*X11DRV_get_win_data( HWND hwnd
)
1453 if (!hwnd
|| XFindContext( thread_display(), (XID
)hwnd
, win_data_context
, &data
)) data
= NULL
;
1454 return (struct x11drv_win_data
*)data
;
1458 /***********************************************************************
1459 * X11DRV_create_win_data
1461 * Create an X11 data window structure for an existing window.
1463 struct x11drv_win_data
*X11DRV_create_win_data( HWND hwnd
)
1465 Display
*display
= thread_display();
1466 struct x11drv_win_data
*data
;
1469 if (!(parent
= GetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop */
1470 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1472 GetWindowRect( hwnd
, &data
->window_rect
);
1473 MapWindowPoints( 0, parent
, (POINT
*)&data
->window_rect
, 2 );
1474 data
->whole_rect
= data
->window_rect
;
1475 GetClientRect( hwnd
, &data
->client_rect
);
1476 MapWindowPoints( hwnd
, parent
, (POINT
*)&data
->client_rect
, 2 );
1478 if (parent
== GetDesktopWindow())
1480 if (!create_whole_window( display
, data
))
1482 HeapFree( GetProcessHeap(), 0, data
);
1485 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1486 hwnd
, data
->whole_window
, data
->client_window
, wine_dbgstr_rect( &data
->window_rect
),
1487 wine_dbgstr_rect( &data
->whole_rect
), wine_dbgstr_rect( &data
->client_rect
));
1490 /* get class or window DC if needed */
1491 alloc_window_dce( data
);
1496 /***********************************************************************
1497 * X11DRV_get_whole_window
1499 * Return the X window associated with the full area of a window
1501 Window
X11DRV_get_whole_window( HWND hwnd
)
1503 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1507 if (hwnd
== GetDesktopWindow()) return root_window
;
1508 return (Window
)GetPropA( hwnd
, whole_window_prop
);
1510 return data
->whole_window
;
1514 /***********************************************************************
1515 * X11DRV_get_client_window
1517 * Return the X window associated with the client area of a window
1519 Window
X11DRV_get_client_window( HWND hwnd
)
1521 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1525 if (hwnd
== GetDesktopWindow()) return root_window
;
1526 return (Window
)GetPropA( hwnd
, client_window_prop
);
1528 return data
->client_window
;
1532 /***********************************************************************
1533 * X11DRV_get_fbconfig_id
1535 * Return the GLXFBConfig ID of the drawable used by the window for
1536 * OpenGL rendering. This is 0 for windows without a pixel format set.
1538 XID
X11DRV_get_fbconfig_id( HWND hwnd
)
1540 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1542 if (!data
) return (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1543 return data
->fbconfig_id
;
1546 /***********************************************************************
1547 * X11DRV_get_gl_drawable
1549 * Return the GL drawable for this window.
1551 Drawable
X11DRV_get_gl_drawable( HWND hwnd
)
1553 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1555 if (!data
) return (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
1556 return data
->gl_drawable
;
1559 /***********************************************************************
1560 * X11DRV_get_gl_pixmap
1562 * Return the Pixmap associated with the GL drawable (if any) for this window.
1564 Pixmap
X11DRV_get_gl_pixmap( HWND hwnd
)
1566 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1568 if (!data
) return (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
1569 return data
->pixmap
;
1573 /***********************************************************************
1576 * Return the X input context associated with a window
1578 XIC
X11DRV_get_ic( HWND hwnd
)
1580 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1582 if (!data
) return 0;
1587 /*****************************************************************
1588 * SetParent (X11DRV.@)
1590 void X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
1592 Display
*display
= thread_display();
1593 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1596 if (parent
== old_parent
) return;
1598 if (parent
!= GetDesktopWindow()) /* a child window */
1600 if (old_parent
== GetDesktopWindow())
1602 /* destroy the old X windows */
1603 destroy_whole_window( display
, data
);
1604 destroy_icon_window( display
, data
);
1607 data
->managed
= FALSE
;
1608 RemovePropA( data
->hwnd
, managed_prop
);
1612 else /* new top level window */
1614 /* FIXME: we ignore errors since we can't really recover anyway */
1615 create_whole_window( display
, data
);
1620 /*****************************************************************
1621 * SetFocus (X11DRV.@)
1624 * Explicit colormap management seems to work only with OLVWM.
1626 void X11DRV_SetFocus( HWND hwnd
)
1628 Display
*display
= thread_display();
1629 struct x11drv_win_data
*data
;
1630 XWindowChanges changes
;
1632 /* If setting the focus to 0, uninstall the colormap */
1633 if (!hwnd
&& root_window
== DefaultRootWindow(display
))
1636 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1637 XUninstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1638 wine_tsx11_unlock();
1642 hwnd
= GetAncestor( hwnd
, GA_ROOT
);
1644 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1645 if (data
->managed
|| !data
->whole_window
) return;
1647 /* Set X focus and install colormap */
1649 changes
.stack_mode
= Above
;
1650 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
1651 if (root_window
== DefaultRootWindow(display
))
1653 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1654 /* FIXME: this is not entirely correct */
1655 XSetInputFocus( display
, data
->whole_window
, RevertToParent
,
1657 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1658 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1659 XInstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1661 wine_tsx11_unlock();
1665 /**********************************************************************
1666 * SetWindowIcon (X11DRV.@)
1668 * hIcon or hIconSm has changed (or is being initialised for the
1669 * first time). Complete the X11 driver-specific initialisation
1670 * and set the window hints.
1672 * This is not entirely correct, may need to create
1673 * an icon window and set the pixmap as a background
1675 void X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
1677 Display
*display
= thread_display();
1678 struct x11drv_win_data
*data
;
1680 if (type
!= ICON_BIG
) return; /* nothing to do here */
1682 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1683 if (!data
->whole_window
) return;
1684 if (!data
->managed
) return;
1688 set_icon_hints( display
, data
, icon
);
1690 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
1691 wine_tsx11_unlock();
1696 /***********************************************************************
1697 * SetWindowRgn (X11DRV.@)
1699 * Assign specified region to window (for non-rectangular windows)
1701 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
1703 struct x11drv_win_data
*data
;
1705 if ((data
= X11DRV_get_win_data( hwnd
)))
1707 sync_window_region( thread_display(), data
, hrgn
);
1708 invalidate_dce( hwnd
, &data
->window_rect
);
1710 else if (GetWindowThreadProcessId( hwnd
, NULL
) != GetCurrentThreadId())
1712 FIXME( "not supported on other thread window %p\n", hwnd
);
1713 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);