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
;
492 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
493 #ifdef SONAME_LIBXCOMPOSITE
497 XMoveResizeWindow(display
, data
->gl_drawable
, -w
, 0, w
, h
);
505 vis
= visual_from_fbconfig_id(data
->fbconfig_id
);
512 pix
= XCreatePixmap(display
, root_window
, w
, h
, vis
->depth
);
515 ERR("Failed to create pixmap for offscreen rendering\n");
521 glxp
= create_glxpixmap(display
, vis
, pix
);
524 ERR("Failed to create drawable for offscreen rendering\n");
525 XFreePixmap(display
, pix
);
533 mark_drawable_dirty(data
->gl_drawable
, glxp
);
535 XFreePixmap(display
, data
->pixmap
);
536 destroy_glxpixmap(display
, data
->gl_drawable
);
539 data
->gl_drawable
= glxp
;
543 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
544 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
545 invalidate_dce( data
->hwnd
, &data
->window_rect
);
549 /***********************************************************************
552 * fill the window changes structure
554 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
558 if (old
->right
- old
->left
!= new->right
- new->left
)
560 if ((changes
->width
= new->right
- new->left
) <= 0) changes
->width
= 1;
563 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
565 if ((changes
->height
= new->bottom
- new->top
) <= 0) changes
->height
= 1;
568 if (old
->left
!= new->left
)
570 changes
->x
= new->left
;
573 if (old
->top
!= new->top
)
575 changes
->y
= new->top
;
582 /***********************************************************************
585 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
587 XSetWindowAttributes attr
;
589 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
590 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
591 attr
.bit_gravity
= NorthWestGravity
;
592 attr
.backing_store
= NotUseful
/*WhenMapped*/;
593 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
596 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
597 GetSystemMetrics( SM_CXICON
),
598 GetSystemMetrics( SM_CYICON
),
601 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
602 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
605 TRACE( "created %lx\n", data
->icon_window
);
606 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
607 return data
->icon_window
;
612 /***********************************************************************
613 * destroy_icon_window
615 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
617 if (!data
->icon_window
) return;
618 if (x11drv_thread_data()->cursor_window
== data
->icon_window
)
619 x11drv_thread_data()->cursor_window
= None
;
621 XDeleteContext( display
, data
->icon_window
, winContext
);
622 XDestroyWindow( display
, data
->icon_window
);
623 data
->icon_window
= 0;
625 RemovePropA( data
->hwnd
, icon_window_prop
);
629 /***********************************************************************
632 * Set the icon wm hints
634 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
, HICON hIcon
)
636 XWMHints
*hints
= data
->wm_hints
;
638 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
639 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
640 data
->hWMIconBitmap
= 0;
641 data
->hWMIconMask
= 0;
645 if (!data
->icon_window
) create_icon_window( display
, data
);
646 hints
->icon_window
= data
->icon_window
;
647 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
657 GetIconInfo(hIcon
, &ii
);
659 GetObjectA(ii
.hbmMask
, sizeof(bmMask
), &bmMask
);
662 rcMask
.right
= bmMask
.bmWidth
;
663 rcMask
.bottom
= bmMask
.bmHeight
;
665 hDC
= CreateCompatibleDC(0);
666 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
667 InvertRect(hDC
, &rcMask
);
668 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
669 SelectObject(hDC
, hbmOrig
);
672 data
->hWMIconBitmap
= ii
.hbmColor
;
673 data
->hWMIconMask
= ii
.hbmMask
;
675 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
676 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
677 destroy_icon_window( display
, data
);
678 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
682 /***********************************************************************
683 * wine_make_systray_window (X11DRV.@)
685 * Docks the given X window with the NETWM system tray.
687 void X11DRV_make_systray_window( HWND hwnd
)
689 static Atom systray_atom
;
690 Display
*display
= thread_display();
691 struct x11drv_win_data
*data
;
692 Window systray_window
;
694 if (!(data
= X11DRV_get_win_data( hwnd
)) &&
695 !(data
= X11DRV_create_win_data( hwnd
))) return;
700 if (DefaultScreen( display
) == 0)
701 systray_atom
= x11drv_atom(_NET_SYSTEM_TRAY_S0
);
704 char systray_buffer
[29]; /* strlen(_NET_SYSTEM_TRAY_S4294967295)+1 */
705 sprintf( systray_buffer
, "_NET_SYSTEM_TRAY_S%u", DefaultScreen( display
) );
706 systray_atom
= XInternAtom( display
, systray_buffer
, False
);
709 systray_window
= XGetSelectionOwner( display
, systray_atom
);
712 TRACE("Docking tray icon %p\n", data
->hwnd
);
714 if (systray_window
!= None
)
717 unsigned long info
[2];
719 /* Put the window offscreen so it isn't mapped. The window _cannot_ be
720 * mapped if we intend to dock with an XEMBED tray. If the window is
721 * mapped when we dock, it may become visible as a child of the root
722 * window after it docks, which isn't the proper behavior.
724 * For more information on this problem, see
725 * http://standards.freedesktop.org/xembed-spec/latest/ar01s04.html */
727 SetWindowPos( data
->hwnd
, NULL
, virtual_screen_rect
.right
+ 1, virtual_screen_rect
.bottom
+ 1,
728 0, 0, SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
730 /* set XEMBED protocol data on the window */
731 info
[0] = 0; /* protocol version */
732 info
[1] = 1; /* mapped = true */
735 XChangeProperty( display
, data
->whole_window
,
736 x11drv_atom(_XEMBED_INFO
),
737 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
,
738 (unsigned char*)info
, 2 );
741 /* send the docking request message */
742 ZeroMemory( &ev
, sizeof(ev
) );
743 ev
.xclient
.type
= ClientMessage
;
744 ev
.xclient
.window
= systray_window
;
745 ev
.xclient
.message_type
= x11drv_atom( _NET_SYSTEM_TRAY_OPCODE
);
746 ev
.xclient
.format
= 32;
747 ev
.xclient
.data
.l
[0] = CurrentTime
;
748 ev
.xclient
.data
.l
[1] = SYSTEM_TRAY_REQUEST_DOCK
;
749 ev
.xclient
.data
.l
[2] = data
->whole_window
;
750 ev
.xclient
.data
.l
[3] = 0;
751 ev
.xclient
.data
.l
[4] = 0;
754 XSendEvent( display
, systray_window
, False
, NoEventMask
, &ev
);
762 /* fall back to he KDE hints if the WM doesn't support XEMBED'ed
766 XChangeProperty( display
, data
->whole_window
,
767 x11drv_atom(KWM_DOCKWINDOW
),
768 x11drv_atom(KWM_DOCKWINDOW
), 32, PropModeReplace
,
769 (unsigned char*)&val
, 1 );
770 XChangeProperty( display
, data
->whole_window
,
771 x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR
),
772 XA_WINDOW
, 32, PropModeReplace
,
773 (unsigned char*)&data
->whole_window
, 1 );
779 /***********************************************************************
782 * set the window size hints
784 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
786 XSizeHints
* size_hints
;
788 if ((size_hints
= XAllocSizeHints()))
790 size_hints
->flags
= 0;
792 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
794 size_hints
->win_gravity
= StaticGravity
;
795 size_hints
->x
= data
->whole_rect
.left
;
796 size_hints
->y
= data
->whole_rect
.top
;
797 size_hints
->flags
|= PWinGravity
| PPosition
;
800 if ( !(style
& WS_THICKFRAME
) )
802 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
803 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
804 size_hints
->min_width
= size_hints
->max_width
;
805 size_hints
->min_height
= size_hints
->max_height
;
806 size_hints
->flags
|= PMinSize
| PMaxSize
;
808 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
814 /***********************************************************************
817 * get the name of the current process for setting class hints
819 static char *get_process_name(void)
825 WCHAR module
[MAX_PATH
];
826 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
827 if (len
&& len
< MAX_PATH
)
830 WCHAR
*p
, *appname
= module
;
832 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
833 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
834 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
835 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
837 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
846 /***********************************************************************
847 * set_initial_wm_hints
849 * Set the window manager hints that don't change over the lifetime of a window.
851 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
856 XClassHint
*class_hints
;
857 char *process_name
= get_process_name();
863 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
864 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
865 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
866 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
867 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
870 if ((class_hints
= XAllocClassHint()))
872 static char wine
[] = "Wine";
874 class_hints
->res_name
= process_name
;
875 class_hints
->res_class
= wine
;
876 XSetClassHint( display
, data
->whole_window
, class_hints
);
877 XFree( class_hints
);
880 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
881 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
882 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
884 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
885 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
887 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
888 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
890 data
->wm_hints
= XAllocWMHints();
895 HICON icon
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_BIG
, 0 );
896 if (!icon
) icon
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
);
897 data
->wm_hints
->flags
= 0;
898 set_icon_hints( display
, data
, icon
);
903 /***********************************************************************
904 * X11DRV_set_wm_hints
906 * Set the window manager hints for a newly-created window
908 void X11DRV_set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
913 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
914 DWORD ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
915 HWND owner
= GetWindow( data
->hwnd
, GW_OWNER
);
917 if (data
->hwnd
== GetDesktopWindow())
919 /* force some styles for the desktop to get the correct decorations */
920 style
|= WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
924 /* transient for hint */
927 Window owner_win
= X11DRV_get_whole_window( owner
);
929 XSetTransientForHint( display
, data
->whole_window
, owner_win
);
931 group_leader
= owner_win
;
933 else group_leader
= data
->whole_window
;
938 set_size_hints( display
, data
, style
);
940 /* set the WM_WINDOW_TYPE */
941 window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
942 if (ex_style
& WS_EX_TOOLWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY
);
943 else if (style
& WS_THICKFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
944 else if (style
& WS_DLGFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
945 else if (ex_style
& WS_EX_DLGMODALFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
947 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
948 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
950 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
951 mwm_hints
.decorations
= get_mwm_decorations( style
, ex_style
);
952 mwm_hints
.functions
= MWM_FUNC_MOVE
;
953 if (style
& WS_THICKFRAME
) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
954 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
955 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
956 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
958 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
959 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
960 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
965 data
->wm_hints
->flags
|= InputHint
| StateHint
| WindowGroupHint
;
966 data
->wm_hints
->input
= !(style
& WS_DISABLED
);
967 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
968 data
->wm_hints
->window_group
= group_leader
;
969 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
976 /***********************************************************************
977 * X11DRV_set_iconic_state
979 * Set the X11 iconic state according to the window style.
981 void X11DRV_set_iconic_state( HWND hwnd
)
983 Display
*display
= thread_display();
984 struct x11drv_win_data
*data
;
986 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
987 BOOL iconic
= (style
& WS_MINIMIZE
) != 0;
989 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
990 if (!data
->whole_window
) return;
992 GetWindowRect( hwnd
, &rect
);
998 data
->wm_hints
->flags
|= StateHint
| IconPositionHint
;
999 data
->wm_hints
->initial_state
= iconic
? IconicState
: NormalState
;
1000 data
->wm_hints
->icon_x
= rect
.left
- virtual_screen_rect
.left
;
1001 data
->wm_hints
->icon_y
= rect
.top
- virtual_screen_rect
.top
;
1002 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
1008 XIconifyWindow( display
, data
->whole_window
, DefaultScreen(display
) );
1010 if (X11DRV_is_window_rect_mapped( &rect
))
1011 XMapWindow( display
, data
->whole_window
);
1014 wine_tsx11_unlock();
1018 /***********************************************************************
1019 * X11DRV_window_to_X_rect
1021 * Convert a rect from client to X window coordinates
1023 void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1027 if (!data
->managed
) return;
1028 if (IsRectEmpty( rect
)) return;
1030 get_x11_rect_offset( data
, &rc
);
1032 rect
->left
-= rc
.left
;
1033 rect
->right
-= rc
.right
;
1034 rect
->top
-= rc
.top
;
1035 rect
->bottom
-= rc
.bottom
;
1036 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1037 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1041 /***********************************************************************
1042 * X11DRV_X_to_window_rect
1044 * Opposite of X11DRV_window_to_X_rect
1046 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1050 if (!data
->managed
) return;
1051 if (IsRectEmpty( rect
)) return;
1053 get_x11_rect_offset( data
, &rc
);
1055 rect
->left
+= rc
.left
;
1056 rect
->right
+= rc
.right
;
1057 rect
->top
+= rc
.top
;
1058 rect
->bottom
+= rc
.bottom
;
1059 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1060 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1064 /***********************************************************************
1065 * X11DRV_sync_window_position
1067 * Synchronize the X window position with the Windows one
1069 void X11DRV_sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
1070 UINT swp_flags
, const RECT
*old_client_rect
,
1071 const RECT
*old_whole_rect
)
1073 XWindowChanges changes
;
1074 int mask
= get_window_changes( &changes
, old_whole_rect
, &data
->whole_rect
);
1076 if (!(swp_flags
& SWP_NOZORDER
))
1078 /* find window that this one must be after */
1079 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
1080 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
1081 prev
= GetWindow( prev
, GW_HWNDPREV
);
1082 if (!prev
) /* top child */
1084 changes
.stack_mode
= Above
;
1085 mask
|= CWStackMode
;
1089 /* should use stack_mode Below but most window managers don't get it right */
1090 /* so move it above the next one in Z order */
1091 HWND next
= GetWindow( data
->hwnd
, GW_HWNDNEXT
);
1092 while (next
&& !(GetWindowLongW( next
, GWL_STYLE
) & WS_VISIBLE
))
1093 next
= GetWindow( next
, GW_HWNDNEXT
);
1096 changes
.stack_mode
= Above
;
1097 changes
.sibling
= X11DRV_get_whole_window(next
);
1098 mask
|= CWStackMode
| CWSibling
;
1103 /* only the size is allowed to change for the desktop window */
1104 if (data
->whole_window
== root_window
) mask
&= CWWidth
| CWHeight
;
1108 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1110 TRACE( "setting win %lx pos %d,%d,%dx%d after %lx changes=%x\n",
1111 data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1112 data
->whole_rect
.right
- data
->whole_rect
.left
,
1113 data
->whole_rect
.bottom
- data
->whole_rect
.top
, changes
.sibling
, mask
);
1116 if (mask
& (CWWidth
|CWHeight
)) set_size_hints( display
, data
, style
);
1117 if (mask
& CWX
) changes
.x
-= virtual_screen_rect
.left
;
1118 if (mask
& CWY
) changes
.y
-= virtual_screen_rect
.top
;
1119 XReconfigureWMWindow( display
, data
->whole_window
,
1120 DefaultScreen(display
), mask
, &changes
);
1121 wine_tsx11_unlock();
1126 /***********************************************************************
1127 * X11DRV_sync_client_position
1129 * Synchronize the X client window position with the Windows one
1131 void X11DRV_sync_client_position( Display
*display
, struct x11drv_win_data
*data
,
1132 UINT swp_flags
, const RECT
*old_client_rect
,
1133 const RECT
*old_whole_rect
)
1136 XWindowChanges changes
;
1137 RECT old
= *old_client_rect
;
1138 RECT
new = data
->client_rect
;
1140 OffsetRect( &old
, -old_whole_rect
->left
, -old_whole_rect
->top
);
1141 OffsetRect( &new, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
1142 if (!(mask
= get_window_changes( &changes
, &old
, &new ))) return;
1144 if (data
->client_window
)
1146 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1147 data
->client_window
, new.left
, new.top
,
1148 new.right
- new.left
, new.bottom
- new.top
, mask
);
1150 XConfigureWindow( display
, data
->client_window
, mask
, &changes
);
1151 wine_tsx11_unlock();
1154 if (data
->gl_drawable
&& (mask
& (CWWidth
|CWHeight
))) sync_gl_drawable( display
, data
);
1156 /* make sure the changes get to the server before we start painting */
1157 if (data
->client_window
|| data
->gl_drawable
)
1161 wine_tsx11_unlock();
1166 /**********************************************************************
1167 * create_whole_window
1169 * Create the whole X window for a given window
1171 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1174 XSetWindowAttributes attr
;
1179 if (!(cx
= data
->window_rect
.right
- data
->window_rect
.left
)) cx
= 1;
1180 if (!(cy
= data
->window_rect
.bottom
- data
->window_rect
.top
)) cy
= 1;
1182 if (!data
->managed
&& is_window_managed( data
->hwnd
, SWP_NOACTIVATE
, &data
->window_rect
))
1184 TRACE( "making win %p/%lx managed\n", data
->hwnd
, data
->whole_window
);
1185 data
->managed
= TRUE
;
1186 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1189 mask
= get_window_attributes( display
, data
, &attr
);
1193 data
->whole_rect
= data
->window_rect
;
1194 data
->whole_window
= XCreateWindow( display
, root_window
,
1195 data
->window_rect
.left
- virtual_screen_rect
.left
,
1196 data
->window_rect
.top
- virtual_screen_rect
.top
,
1197 cx
, cy
, 0, screen_depth
, InputOutput
,
1198 visual
, mask
, &attr
);
1200 if (data
->whole_window
) XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1201 wine_tsx11_unlock();
1203 if (!data
->whole_window
) return 0;
1205 if (!create_client_window( display
, data
, NULL
))
1208 XDeleteContext( display
, data
->whole_window
, winContext
);
1209 XDestroyWindow( display
, data
->whole_window
);
1210 data
->whole_window
= 0;
1211 wine_tsx11_unlock();
1215 xim
= x11drv_thread_data()->xim
;
1216 if (xim
) data
->xic
= X11DRV_CreateIC( xim
, display
, data
->whole_window
);
1218 set_initial_wm_hints( display
, data
);
1219 X11DRV_set_wm_hints( display
, data
);
1221 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1223 /* set the window text */
1224 if (!InternalGetWindowText( data
->hwnd
, text
, sizeof(text
)/sizeof(WCHAR
) )) text
[0] = 0;
1225 sync_window_text( display
, data
->whole_window
, text
);
1227 /* set the window region */
1228 if ((hrgn
= CreateRectRgn( 0, 0, 0, 0 )))
1230 if (GetWindowRgn( data
->hwnd
, hrgn
) != ERROR
) sync_window_region( display
, data
, hrgn
);
1231 DeleteObject( hrgn
);
1233 return data
->whole_window
;
1237 /**********************************************************************
1238 * destroy_whole_window
1240 * Destroy the whole X window for a given window.
1242 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1244 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1246 if (!data
->whole_window
) return;
1248 TRACE( "win %p xwin %lx/%lx\n", data
->hwnd
, data
->whole_window
, data
->client_window
);
1249 if (thread_data
->cursor_window
== data
->whole_window
||
1250 thread_data
->cursor_window
== data
->client_window
)
1251 thread_data
->cursor_window
= None
;
1253 XDeleteContext( display
, data
->whole_window
, winContext
);
1254 XDeleteContext( display
, data
->client_window
, winContext
);
1255 XDestroyWindow( display
, data
->whole_window
);
1256 data
->whole_window
= data
->client_window
= 0;
1259 XUnsetICFocus( data
->xic
);
1260 XDestroyIC( data
->xic
);
1262 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1264 XFree( data
->wm_hints
);
1265 data
->wm_hints
= NULL
;
1266 wine_tsx11_unlock();
1267 RemovePropA( data
->hwnd
, whole_window_prop
);
1268 RemovePropA( data
->hwnd
, client_window_prop
);
1272 /*****************************************************************
1273 * SetWindowText (X11DRV.@)
1275 void X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1277 Display
*display
= thread_display();
1280 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(display
))
1281 sync_window_text( display
, win
, text
);
1285 /***********************************************************************
1286 * DestroyWindow (X11DRV.@)
1288 void X11DRV_DestroyWindow( HWND hwnd
)
1290 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1291 Display
*display
= thread_data
->display
;
1292 struct x11drv_win_data
*data
;
1294 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1298 destroy_glxpixmap(display
, data
->gl_drawable
);
1300 XFreePixmap(display
, data
->pixmap
);
1301 wine_tsx11_unlock();
1303 else if (data
->gl_drawable
)
1306 XDestroyWindow(display
, data
->gl_drawable
);
1307 wine_tsx11_unlock();
1310 free_window_dce( data
);
1311 destroy_whole_window( display
, data
);
1312 destroy_icon_window( display
, data
);
1317 XFreeColormap( display
, data
->colormap
);
1318 wine_tsx11_unlock();
1321 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1322 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1323 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1325 XDeleteContext( display
, (XID
)hwnd
, win_data_context
);
1326 wine_tsx11_unlock();
1327 HeapFree( GetProcessHeap(), 0, data
);
1331 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1333 struct x11drv_win_data
*data
;
1335 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
1339 if (!winContext
) winContext
= XUniqueContext();
1340 if (!win_data_context
) win_data_context
= XUniqueContext();
1341 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1342 wine_tsx11_unlock();
1348 /* initialize the desktop window id in the desktop manager process */
1349 static struct x11drv_win_data
*create_desktop_win_data( Display
*display
, HWND hwnd
)
1351 struct x11drv_win_data
*data
;
1354 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1356 visualid
= XVisualIDFromVisual(visual
);
1357 wine_tsx11_unlock();
1358 data
->whole_window
= data
->client_window
= root_window
;
1359 data
->managed
= TRUE
;
1360 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1361 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1362 SetPropA( data
->hwnd
, client_window_prop
, (HANDLE
)root_window
);
1363 SetPropA( data
->hwnd
, visual_id_prop
, (HANDLE
)visualid
);
1364 set_initial_wm_hints( display
, data
);
1368 /**********************************************************************
1369 * CreateDesktopWindow (X11DRV.@)
1371 BOOL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1373 unsigned int width
, height
;
1375 /* retrieve the real size of the desktop */
1376 SERVER_START_REQ( get_window_rectangles
)
1379 wine_server_call( req
);
1380 width
= reply
->window
.right
- reply
->window
.left
;
1381 height
= reply
->window
.bottom
- reply
->window
.top
;
1385 if (!width
&& !height
) /* not initialized yet */
1387 SERVER_START_REQ( set_window_pos
)
1391 req
->flags
= SWP_NOZORDER
;
1392 req
->window
.left
= virtual_screen_rect
.left
;
1393 req
->window
.top
= virtual_screen_rect
.top
;
1394 req
->window
.right
= virtual_screen_rect
.right
;
1395 req
->window
.bottom
= virtual_screen_rect
.bottom
;
1396 req
->client
= req
->window
;
1397 wine_server_call( req
);
1403 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1404 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1410 /**********************************************************************
1411 * CreateWindow (X11DRV.@)
1413 BOOL
X11DRV_CreateWindow( HWND hwnd
)
1415 Display
*display
= thread_display();
1418 if (hwnd
== GetDesktopWindow() && root_window
!= DefaultRootWindow( display
))
1420 /* the desktop win data can't be created lazily */
1421 if (!create_desktop_win_data( display
, hwnd
)) return FALSE
;
1424 /* Show the window, maximizing or minimizing if needed */
1426 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1427 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1429 extern UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
); /*FIXME*/
1432 UINT swFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
1433 WIN_SetStyle( hwnd
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
1434 swFlag
= WINPOS_MinMaximize( hwnd
, swFlag
, &newPos
);
1436 swFlag
|= SWP_FRAMECHANGED
; /* Frame always gets changed */
1437 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || GetActiveWindow()) swFlag
|= SWP_NOACTIVATE
;
1439 SetWindowPos( hwnd
, 0, newPos
.left
, newPos
.top
,
1440 newPos
.right
, newPos
.bottom
, swFlag
);
1447 /***********************************************************************
1448 * X11DRV_get_win_data
1450 * Return the X11 data structure associated with a window.
1452 struct x11drv_win_data
*X11DRV_get_win_data( HWND hwnd
)
1456 if (!hwnd
|| XFindContext( thread_display(), (XID
)hwnd
, win_data_context
, &data
)) data
= NULL
;
1457 return (struct x11drv_win_data
*)data
;
1461 /***********************************************************************
1462 * X11DRV_create_win_data
1464 * Create an X11 data window structure for an existing window.
1466 struct x11drv_win_data
*X11DRV_create_win_data( HWND hwnd
)
1468 Display
*display
= thread_display();
1469 struct x11drv_win_data
*data
;
1472 if (!(parent
= GetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop */
1473 if (!(data
= alloc_win_data( display
, hwnd
))) return NULL
;
1475 GetWindowRect( hwnd
, &data
->window_rect
);
1476 MapWindowPoints( 0, parent
, (POINT
*)&data
->window_rect
, 2 );
1477 data
->whole_rect
= data
->window_rect
;
1478 GetClientRect( hwnd
, &data
->client_rect
);
1479 MapWindowPoints( hwnd
, parent
, (POINT
*)&data
->client_rect
, 2 );
1481 if (parent
== GetDesktopWindow())
1483 if (!create_whole_window( display
, data
))
1485 HeapFree( GetProcessHeap(), 0, data
);
1488 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1489 hwnd
, data
->whole_window
, data
->client_window
, wine_dbgstr_rect( &data
->window_rect
),
1490 wine_dbgstr_rect( &data
->whole_rect
), wine_dbgstr_rect( &data
->client_rect
));
1493 /* get class or window DC if needed */
1494 alloc_window_dce( data
);
1499 /***********************************************************************
1500 * X11DRV_get_whole_window
1502 * Return the X window associated with the full area of a window
1504 Window
X11DRV_get_whole_window( HWND hwnd
)
1506 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1510 if (hwnd
== GetDesktopWindow()) return root_window
;
1511 return (Window
)GetPropA( hwnd
, whole_window_prop
);
1513 return data
->whole_window
;
1517 /***********************************************************************
1518 * X11DRV_get_client_window
1520 * Return the X window associated with the client area of a window
1522 Window
X11DRV_get_client_window( HWND hwnd
)
1524 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1528 if (hwnd
== GetDesktopWindow()) return root_window
;
1529 return (Window
)GetPropA( hwnd
, client_window_prop
);
1531 return data
->client_window
;
1535 /***********************************************************************
1536 * X11DRV_get_fbconfig_id
1538 * Return the GLXFBConfig ID of the drawable used by the window for
1539 * OpenGL rendering. This is 0 for windows without a pixel format set.
1541 XID
X11DRV_get_fbconfig_id( HWND hwnd
)
1543 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1545 if (!data
) return (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1546 return data
->fbconfig_id
;
1549 /***********************************************************************
1550 * X11DRV_get_gl_drawable
1552 * Return the GL drawable for this window.
1554 Drawable
X11DRV_get_gl_drawable( HWND hwnd
)
1556 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1558 if (!data
) return (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
1559 return data
->gl_drawable
;
1562 /***********************************************************************
1563 * X11DRV_get_gl_pixmap
1565 * Return the Pixmap associated with the GL drawable (if any) for this window.
1567 Pixmap
X11DRV_get_gl_pixmap( HWND hwnd
)
1569 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1571 if (!data
) return (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
1572 return data
->pixmap
;
1576 /***********************************************************************
1579 * Return the X input context associated with a window
1581 XIC
X11DRV_get_ic( HWND hwnd
)
1583 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1585 if (!data
) return 0;
1590 /*****************************************************************
1591 * SetParent (X11DRV.@)
1593 void X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
1595 Display
*display
= thread_display();
1596 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1599 if (parent
== old_parent
) return;
1601 if (parent
!= GetDesktopWindow()) /* a child window */
1603 if (old_parent
== GetDesktopWindow())
1605 /* destroy the old X windows */
1606 destroy_whole_window( display
, data
);
1607 destroy_icon_window( display
, data
);
1610 data
->managed
= FALSE
;
1611 RemovePropA( data
->hwnd
, managed_prop
);
1615 else /* new top level window */
1617 /* FIXME: we ignore errors since we can't really recover anyway */
1618 create_whole_window( display
, data
);
1623 /*****************************************************************
1624 * SetFocus (X11DRV.@)
1627 * Explicit colormap management seems to work only with OLVWM.
1629 void X11DRV_SetFocus( HWND hwnd
)
1631 Display
*display
= thread_display();
1632 struct x11drv_win_data
*data
;
1633 XWindowChanges changes
;
1635 /* If setting the focus to 0, uninstall the colormap */
1636 if (!hwnd
&& root_window
== DefaultRootWindow(display
))
1639 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1640 XUninstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1641 wine_tsx11_unlock();
1645 hwnd
= GetAncestor( hwnd
, GA_ROOT
);
1647 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1648 if (data
->managed
|| !data
->whole_window
) return;
1650 /* Set X focus and install colormap */
1652 changes
.stack_mode
= Above
;
1653 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
1654 if (root_window
== DefaultRootWindow(display
))
1656 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1657 /* FIXME: this is not entirely correct */
1658 XSetInputFocus( display
, data
->whole_window
, RevertToParent
,
1660 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1661 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1662 XInstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1664 wine_tsx11_unlock();
1668 /**********************************************************************
1669 * SetWindowIcon (X11DRV.@)
1671 * hIcon or hIconSm has changed (or is being initialised for the
1672 * first time). Complete the X11 driver-specific initialisation
1673 * and set the window hints.
1675 * This is not entirely correct, may need to create
1676 * an icon window and set the pixmap as a background
1678 void X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
1680 Display
*display
= thread_display();
1681 struct x11drv_win_data
*data
;
1683 if (type
!= ICON_BIG
) return; /* nothing to do here */
1685 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1686 if (!data
->whole_window
) return;
1687 if (!data
->managed
) return;
1691 set_icon_hints( display
, data
, icon
);
1693 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
1694 wine_tsx11_unlock();
1699 /***********************************************************************
1700 * SetWindowRgn (X11DRV.@)
1702 * Assign specified region to window (for non-rectangular windows)
1704 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
1706 struct x11drv_win_data
*data
;
1708 if ((data
= X11DRV_get_win_data( hwnd
)))
1710 sync_window_region( thread_display(), data
, hrgn
);
1711 invalidate_dce( hwnd
, &data
->window_rect
);
1713 else if (GetWindowThreadProcessId( hwnd
, NULL
) != GetCurrentThreadId())
1715 FIXME( "not supported on other thread window %p\n", hwnd
);
1716 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);