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>
40 #include "wine/unicode.h"
43 #include "xcomposite.h"
44 #include "wine/debug.h"
45 #include "wine/server.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
51 /* X context to associate a hwnd to an X window */
52 XContext winContext
= 0;
54 /* X context to associate a struct x11drv_win_data to an hwnd */
55 static XContext win_data_context
;
57 static const char whole_window_prop
[] = "__wine_x11_whole_window";
58 static const char icon_window_prop
[] = "__wine_x11_icon_window";
59 static const char fbconfig_id_prop
[] = "__wine_x11_fbconfig_id";
60 static const char gl_drawable_prop
[] = "__wine_x11_gl_drawable";
61 static const char pixmap_prop
[] = "__wine_x11_pixmap";
62 static const char managed_prop
[] = "__wine_x11_managed";
63 static const char visual_id_prop
[] = "__wine_x11_visual_id";
65 /* for XDG systray icons */
66 #define SYSTEM_TRAY_REQUEST_DOCK 0
68 extern int usexcomposite
;
70 /***********************************************************************
73 * Check if a given window should be managed
75 BOOL
is_window_managed( HWND hwnd
, UINT swp_flags
, const RECT
*window_rect
)
77 DWORD style
, ex_style
;
79 /* tray window is always managed */
80 ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
81 if (ex_style
& WS_EX_TRAYWINDOW
) return TRUE
;
82 /* child windows are not managed */
83 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
84 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) return FALSE
;
85 /* activated windows are managed */
86 if (!(swp_flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
))) return TRUE
;
87 if (hwnd
== GetActiveWindow()) return TRUE
;
88 /* windows with caption are managed */
89 if ((style
& WS_CAPTION
) == WS_CAPTION
) return TRUE
;
90 /* tool windows are not managed */
91 if (ex_style
& WS_EX_TOOLWINDOW
) return FALSE
;
92 /* windows with thick frame are managed */
93 if (style
& WS_THICKFRAME
) return TRUE
;
94 /* application windows are managed */
95 if (ex_style
& WS_EX_APPWINDOW
) return TRUE
;
98 /* popup with sysmenu == caption are managed */
99 if (style
& WS_SYSMENU
) return TRUE
;
100 /* full-screen popup windows are managed */
101 if ((window_rect
->right
- window_rect
->left
) == screen_width
&&
102 (window_rect
->bottom
- window_rect
->top
) == screen_height
)
105 /* default: not managed */
110 /***********************************************************************
111 * X11DRV_is_window_rect_mapped
113 * Check if the X whole window should be mapped based on its rectangle
115 BOOL
X11DRV_is_window_rect_mapped( const RECT
*rect
)
117 /* don't map if rect is empty */
118 if (IsRectEmpty( rect
)) return FALSE
;
120 /* don't map if rect is off-screen */
121 if (rect
->left
>= virtual_screen_rect
.right
||
122 rect
->top
>= virtual_screen_rect
.bottom
||
123 rect
->right
<= virtual_screen_rect
.left
||
124 rect
->bottom
<= virtual_screen_rect
.top
)
131 /***********************************************************************
132 * get_mwm_decorations
134 static unsigned long get_mwm_decorations( DWORD style
, DWORD ex_style
)
136 unsigned long ret
= 0;
138 if (ex_style
& WS_EX_TOOLWINDOW
) return 0;
140 if ((style
& WS_CAPTION
) == WS_CAPTION
)
142 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
143 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
144 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
145 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
147 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
148 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
149 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
154 /***********************************************************************
155 * get_x11_rect_offset
157 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
159 static void get_x11_rect_offset( struct x11drv_win_data
*data
, RECT
*rect
)
161 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
164 rect
->top
= rect
->bottom
= rect
->left
= rect
->right
= 0;
166 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
167 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
168 decor
= get_mwm_decorations( style
, ex_style
);
170 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
171 if (decor
& MWM_DECOR_BORDER
)
173 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
174 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
177 AdjustWindowRectEx( rect
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
181 /***********************************************************************
182 * get_window_attributes
184 * Fill the window attributes structure for an X window.
186 static int get_window_attributes( Display
*display
, struct x11drv_win_data
*data
,
187 XSetWindowAttributes
*attr
)
189 attr
->override_redirect
= !data
->managed
;
190 attr
->colormap
= X11DRV_PALETTE_PaletteXColormap
;
191 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
192 attr
->cursor
= x11drv_thread_data()->cursor
;
193 attr
->bit_gravity
= NorthWestGravity
;
194 attr
->backing_store
= NotUseful
;
195 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
196 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
197 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
| KeymapStateMask
);
198 if (data
->managed
) attr
->event_mask
|= StructureNotifyMask
;
200 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
| CWCursor
|
201 CWEventMask
| CWBitGravity
| CWBackingStore
);
205 /***********************************************************************
206 * X11DRV_sync_window_style
208 * Change the X window attributes when the window style has changed.
210 void X11DRV_sync_window_style( Display
*display
, struct x11drv_win_data
*data
)
212 if (data
->whole_window
!= root_window
)
214 XSetWindowAttributes attr
;
215 int mask
= get_window_attributes( display
, data
, &attr
);
218 XChangeWindowAttributes( display
, data
->whole_window
, mask
, &attr
);
224 /***********************************************************************
225 * X11DRV_set_win_format
227 BOOL
X11DRV_set_win_format( HWND hwnd
, XID fbconfig_id
)
229 Display
*display
= thread_display();
230 struct x11drv_win_data
*data
;
236 if (!(data
= X11DRV_get_win_data(hwnd
))) return FALSE
;
240 vis
= visual_from_fbconfig_id(fbconfig_id
);
247 if(data
->whole_window
&& vis
->visualid
== XVisualIDFromVisual(visual
))
249 TRACE("Whole window available and visual match, rendering onscreen\n");
255 parent
= data
->whole_window
;
259 next_hwnd
= GetAncestor(next_hwnd
, GA_PARENT
);
262 ERR("Could not find parent HWND with a drawable!\n");
265 parent
= X11DRV_get_whole_window(next_hwnd
);
268 w
= data
->client_rect
.right
- data
->client_rect
.left
;
269 h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
275 #ifdef SONAME_LIBXCOMPOSITE
278 XSetWindowAttributes attrib
;
280 attrib
.override_redirect
= True
;
281 attrib
.colormap
= XCreateColormap(display
, parent
, vis
->visual
,
282 (vis
->class == PseudoColor
||
283 vis
->class == GrayScale
||
284 vis
->class == DirectColor
) ?
285 AllocAll
: AllocNone
);
286 XInstallColormap(gdi_display
, attrib
.colormap
);
288 data
->gl_drawable
= XCreateWindow(display
, parent
, -w
, 0, w
, h
, 0,
289 vis
->depth
, InputOutput
, vis
->visual
,
290 CWColormap
| CWOverrideRedirect
,
292 if(data
->gl_drawable
)
294 pXCompositeRedirectWindow(display
, data
->gl_drawable
,
295 CompositeRedirectManual
);
296 XMapWindow(display
, data
->gl_drawable
);
302 WARN("XComposite is not available, using GLXPixmap hack\n");
304 data
->pixmap
= XCreatePixmap(display
, parent
, w
, h
, vis
->depth
);
307 ERR("Failed to create pixmap for offscreen rendering\n");
313 data
->gl_drawable
= create_glxpixmap(display
, vis
, data
->pixmap
);
314 if(!data
->gl_drawable
)
316 XFreePixmap(display
, data
->pixmap
);
321 if(!data
->gl_drawable
)
323 ERR("Failed to create drawable for offscreen rendering\n");
335 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
336 data
->gl_drawable
, fbconfig_id
);
338 data
->fbconfig_id
= fbconfig_id
;
339 SetPropA(hwnd
, fbconfig_id_prop
, (HANDLE
)data
->fbconfig_id
);
340 SetPropA(hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
341 SetPropA(hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
342 invalidate_dce( hwnd
, &data
->window_rect
);
346 static void update_gl_drawable(Display
*display
, struct x11drv_win_data
*data
, const RECT
*old_client_rect
)
348 int w
= data
->client_rect
.right
- data
->client_rect
.left
;
349 int h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
356 if((w
== old_client_rect
->right
- old_client_rect
->left
&&
357 h
== old_client_rect
->bottom
- old_client_rect
->top
) ||
360 TRACE("No resize needed\n");
364 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
365 #ifdef SONAME_LIBXCOMPOSITE
369 XMoveResizeWindow(display
, data
->gl_drawable
, -w
, 0, w
, h
);
375 parent
= data
->whole_window
;
376 next_hwnd
= data
->hwnd
;
379 next_hwnd
= GetAncestor(next_hwnd
, GA_PARENT
);
382 ERR("Could not find parent HWND with a drawable!\n");
385 parent
= X11DRV_get_whole_window(next_hwnd
);
390 vis
= visual_from_fbconfig_id(data
->fbconfig_id
);
397 pix
= XCreatePixmap(display
, parent
, w
, h
, vis
->depth
);
400 ERR("Failed to create pixmap for offscreen rendering\n");
406 glxp
= create_glxpixmap(display
, vis
, pix
);
409 ERR("Failed to create drawable for offscreen rendering\n");
410 XFreePixmap(display
, pix
);
418 mark_drawable_dirty(data
->gl_drawable
, glxp
);
420 XFreePixmap(display
, data
->pixmap
);
421 destroy_glxpixmap(display
, data
->gl_drawable
);
424 data
->gl_drawable
= glxp
;
429 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
430 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
431 invalidate_dce( data
->hwnd
, &data
->window_rect
);
435 /***********************************************************************
438 * fill the window changes structure
440 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
444 if (old
->right
- old
->left
!= new->right
- new->left
)
446 if (!(changes
->width
= new->right
- new->left
)) changes
->width
= 1;
449 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
451 if (!(changes
->height
= new->bottom
- new->top
)) changes
->height
= 1;
454 if (old
->left
!= new->left
)
456 changes
->x
= new->left
;
459 if (old
->top
!= new->top
)
461 changes
->y
= new->top
;
468 /***********************************************************************
471 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
473 XSetWindowAttributes attr
;
475 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
476 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
477 attr
.bit_gravity
= NorthWestGravity
;
478 attr
.backing_store
= NotUseful
/*WhenMapped*/;
479 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
482 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
483 GetSystemMetrics( SM_CXICON
),
484 GetSystemMetrics( SM_CYICON
),
487 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
488 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
491 TRACE( "created %lx\n", data
->icon_window
);
492 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
493 return data
->icon_window
;
498 /***********************************************************************
499 * destroy_icon_window
501 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
503 if (!data
->icon_window
) return;
504 if (x11drv_thread_data()->cursor_window
== data
->icon_window
)
505 x11drv_thread_data()->cursor_window
= None
;
507 XDeleteContext( display
, data
->icon_window
, winContext
);
508 XDestroyWindow( display
, data
->icon_window
);
509 data
->icon_window
= 0;
511 RemovePropA( data
->hwnd
, icon_window_prop
);
515 /***********************************************************************
518 * Set the icon wm hints
520 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
, HICON hIcon
)
522 XWMHints
*hints
= data
->wm_hints
;
524 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
525 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
526 data
->hWMIconBitmap
= 0;
527 data
->hWMIconMask
= 0;
531 destroy_icon_window( display
, data
);
532 hints
->flags
&= ~(IconPixmapHint
| IconMaskHint
| IconWindowHint
);
536 if (!data
->icon_window
) create_icon_window( display
, data
);
537 hints
->icon_window
= data
->icon_window
;
538 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
548 GetIconInfo(hIcon
, &ii
);
550 GetObjectA(ii
.hbmMask
, sizeof(bmMask
), &bmMask
);
553 rcMask
.right
= bmMask
.bmWidth
;
554 rcMask
.bottom
= bmMask
.bmHeight
;
556 hDC
= CreateCompatibleDC(0);
557 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
558 InvertRect(hDC
, &rcMask
);
559 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
560 SelectObject(hDC
, hbmOrig
);
563 data
->hWMIconBitmap
= ii
.hbmColor
;
564 data
->hWMIconMask
= ii
.hbmMask
;
566 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
567 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
568 destroy_icon_window( display
, data
);
569 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
573 /***********************************************************************
574 * systray_dock_window
576 * Docks the given X window with the NETWM system tray.
578 static void systray_dock_window( Display
*display
, struct x11drv_win_data
*data
)
580 static Atom systray_atom
;
581 Window systray_window
;
586 if (DefaultScreen( display
) == 0)
587 systray_atom
= x11drv_atom(_NET_SYSTEM_TRAY_S0
);
590 char systray_buffer
[29]; /* strlen(_NET_SYSTEM_TRAY_S4294967295)+1 */
591 sprintf( systray_buffer
, "_NET_SYSTEM_TRAY_S%u", DefaultScreen( display
) );
592 systray_atom
= XInternAtom( display
, systray_buffer
, False
);
595 systray_window
= XGetSelectionOwner( display
, systray_atom
);
598 TRACE("Docking tray icon %p\n", data
->hwnd
);
600 if (systray_window
!= None
)
603 unsigned long info
[2];
605 /* Put the window offscreen so it isn't mapped. The window _cannot_ be
606 * mapped if we intend to dock with an XEMBED tray. If the window is
607 * mapped when we dock, it may become visible as a child of the root
608 * window after it docks, which isn't the proper behavior.
610 * For more information on this problem, see
611 * http://standards.freedesktop.org/xembed-spec/latest/ar01s04.html */
613 SetWindowPos( data
->hwnd
, NULL
, virtual_screen_rect
.right
+ 1, virtual_screen_rect
.bottom
+ 1,
614 0, 0, SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
616 /* set XEMBED protocol data on the window */
617 info
[0] = 0; /* protocol version */
618 info
[1] = 1; /* mapped = true */
621 XChangeProperty( display
, data
->whole_window
,
622 x11drv_atom(_XEMBED_INFO
),
623 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
,
624 (unsigned char*)info
, 2 );
627 /* send the docking request message */
628 ZeroMemory( &ev
, sizeof(ev
) );
629 ev
.xclient
.type
= ClientMessage
;
630 ev
.xclient
.window
= systray_window
;
631 ev
.xclient
.message_type
= x11drv_atom( _NET_SYSTEM_TRAY_OPCODE
);
632 ev
.xclient
.format
= 32;
633 ev
.xclient
.data
.l
[0] = CurrentTime
;
634 ev
.xclient
.data
.l
[1] = SYSTEM_TRAY_REQUEST_DOCK
;
635 ev
.xclient
.data
.l
[2] = data
->whole_window
;
636 ev
.xclient
.data
.l
[3] = 0;
637 ev
.xclient
.data
.l
[4] = 0;
640 XSendEvent( display
, systray_window
, False
, NoEventMask
, &ev
);
648 /* fall back to he KDE hints if the WM doesn't support XEMBED'ed
652 XChangeProperty( display
, data
->whole_window
,
653 x11drv_atom(KWM_DOCKWINDOW
),
654 x11drv_atom(KWM_DOCKWINDOW
), 32, PropModeReplace
,
655 (unsigned char*)&val
, 1 );
656 XChangeProperty( display
, data
->whole_window
,
657 x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR
),
658 XA_WINDOW
, 32, PropModeReplace
,
659 (unsigned char*)&data
->whole_window
, 1 );
665 /***********************************************************************
668 * set the window size hints
670 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
672 XSizeHints
* size_hints
;
674 if ((size_hints
= XAllocSizeHints()))
676 size_hints
->flags
= 0;
678 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
680 size_hints
->win_gravity
= StaticGravity
;
681 size_hints
->x
= data
->whole_rect
.left
;
682 size_hints
->y
= data
->whole_rect
.top
;
683 size_hints
->flags
|= PWinGravity
| PPosition
;
686 if ( !(style
& WS_THICKFRAME
) )
688 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
689 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
690 size_hints
->min_width
= size_hints
->max_width
;
691 size_hints
->min_height
= size_hints
->max_height
;
692 size_hints
->flags
|= PMinSize
| PMaxSize
;
694 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
700 /***********************************************************************
703 * get the name of the current process for setting class hints
705 static char *get_process_name(void)
711 WCHAR module
[MAX_PATH
];
712 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
713 if (len
&& len
< MAX_PATH
)
716 WCHAR
*p
, *appname
= module
;
718 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
719 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
720 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
721 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
723 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
732 /***********************************************************************
733 * set_initial_wm_hints
735 * Set the window manager hints that don't change over the lifetime of a window.
737 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
742 XClassHint
*class_hints
;
743 char *process_name
= get_process_name();
749 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
750 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
751 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
752 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
753 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
756 if ((class_hints
= XAllocClassHint()))
758 static char wine
[] = "Wine";
760 class_hints
->res_name
= process_name
;
761 class_hints
->res_class
= wine
;
762 XSetClassHint( display
, data
->whole_window
, class_hints
);
763 XFree( class_hints
);
766 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
767 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
768 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
770 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
771 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
773 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
774 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
780 /***********************************************************************
781 * X11DRV_set_wm_hints
783 * Set the window manager hints for a newly-created window
785 void X11DRV_set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
790 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
791 DWORD ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
792 HWND owner
= GetWindow( data
->hwnd
, GW_OWNER
);
794 if (data
->hwnd
== GetDesktopWindow())
796 if (data
->whole_window
== DefaultRootWindow(display
)) return;
797 /* force some styles for the desktop to get the correct decorations */
798 style
|= WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
802 /* transient for hint */
805 Window owner_win
= X11DRV_get_whole_window( owner
);
807 XSetTransientForHint( display
, data
->whole_window
, owner_win
);
809 group_leader
= owner_win
;
811 else group_leader
= data
->whole_window
;
816 set_size_hints( display
, data
, style
);
818 /* set the WM_WINDOW_TYPE */
819 window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
820 if (ex_style
& WS_EX_TOOLWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY
);
821 else if (style
& WS_THICKFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
822 else if (style
& WS_DLGFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
823 else if (ex_style
& WS_EX_DLGMODALFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
825 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
826 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
828 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
829 mwm_hints
.decorations
= get_mwm_decorations( style
, ex_style
);
830 mwm_hints
.functions
= MWM_FUNC_MOVE
;
831 if (style
& WS_THICKFRAME
) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
832 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
833 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
834 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
836 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
837 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
838 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
845 data
->wm_hints
->flags
= InputHint
| StateHint
| WindowGroupHint
;
846 data
->wm_hints
->input
= !(style
& WS_DISABLED
);
847 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
848 data
->wm_hints
->window_group
= group_leader
;
849 set_icon_hints( display
, data
, (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
) );
852 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
858 /***********************************************************************
859 * X11DRV_set_iconic_state
861 * Set the X11 iconic state according to the window style.
863 void X11DRV_set_iconic_state( HWND hwnd
)
865 Display
*display
= thread_display();
866 struct x11drv_win_data
*data
;
868 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
869 BOOL iconic
= (style
& WS_MINIMIZE
) != 0;
871 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
872 if (!data
->whole_window
|| data
->whole_window
== DefaultRootWindow(display
)) return;
874 GetWindowRect( hwnd
, &rect
);
880 data
->wm_hints
->flags
|= StateHint
| IconPositionHint
;
881 data
->wm_hints
->initial_state
= iconic
? IconicState
: NormalState
;
882 data
->wm_hints
->icon_x
= rect
.left
- virtual_screen_rect
.left
;
883 data
->wm_hints
->icon_y
= rect
.top
- virtual_screen_rect
.top
;
884 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
887 if (style
& WS_VISIBLE
)
890 XIconifyWindow( display
, data
->whole_window
, DefaultScreen(display
) );
892 if (X11DRV_is_window_rect_mapped( &rect
))
893 XMapWindow( display
, data
->whole_window
);
900 /***********************************************************************
901 * X11DRV_window_to_X_rect
903 * Convert a rect from client to X window coordinates
905 void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
909 if (!data
->managed
) return;
910 if (IsRectEmpty( rect
)) return;
912 get_x11_rect_offset( data
, &rc
);
914 rect
->left
-= rc
.left
;
915 rect
->right
-= rc
.right
;
917 rect
->bottom
-= rc
.bottom
;
918 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
919 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
923 /***********************************************************************
924 * X11DRV_X_to_window_rect
926 * Opposite of X11DRV_window_to_X_rect
928 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
932 if (!data
->managed
) return;
933 if (IsRectEmpty( rect
)) return;
935 get_x11_rect_offset( data
, &rc
);
937 rect
->left
+= rc
.left
;
938 rect
->right
+= rc
.right
;
940 rect
->bottom
+= rc
.bottom
;
941 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
942 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
946 /***********************************************************************
947 * X11DRV_sync_window_position
949 * Synchronize the X window position with the Windows one
951 void X11DRV_sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
952 UINT swp_flags
, const RECT
*new_client_rect
,
953 const RECT
*new_whole_rect
)
955 XWindowChanges changes
;
958 RECT old_client_rect
;
960 old_whole_rect
= data
->whole_rect
;
961 data
->whole_rect
= *new_whole_rect
;
963 old_client_rect
= data
->client_rect
;
964 data
->client_rect
= *new_client_rect
;
965 OffsetRect( &data
->client_rect
, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
967 if (data
->gl_drawable
)
968 update_gl_drawable(display
, data
, &old_client_rect
);
970 if (!data
->whole_window
|| data
->lock_changes
) return;
972 mask
= get_window_changes( &changes
, &old_whole_rect
, &data
->whole_rect
);
974 if (!(swp_flags
& SWP_NOZORDER
))
976 /* find window that this one must be after */
977 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
978 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
979 prev
= GetWindow( prev
, GW_HWNDPREV
);
980 if (!prev
) /* top child */
982 changes
.stack_mode
= Above
;
987 /* should use stack_mode Below but most window managers don't get it right */
988 /* so move it above the next one in Z order */
989 HWND next
= GetWindow( data
->hwnd
, GW_HWNDNEXT
);
990 while (next
&& !(GetWindowLongW( next
, GWL_STYLE
) & WS_VISIBLE
))
991 next
= GetWindow( next
, GW_HWNDNEXT
);
994 changes
.stack_mode
= Above
;
995 changes
.sibling
= X11DRV_get_whole_window(next
);
996 mask
|= CWStackMode
| CWSibling
;
1003 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1005 TRACE( "setting win %lx pos %d,%d,%dx%d after %lx changes=%x\n",
1006 data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1007 data
->whole_rect
.right
- data
->whole_rect
.left
,
1008 data
->whole_rect
.bottom
- data
->whole_rect
.top
, changes
.sibling
, mask
);
1011 if (mask
& (CWWidth
|CWHeight
)) set_size_hints( display
, data
, style
);
1012 if (mask
& CWX
) changes
.x
-= virtual_screen_rect
.left
;
1013 if (mask
& CWY
) changes
.y
-= virtual_screen_rect
.top
;
1014 XReconfigureWMWindow( display
, data
->whole_window
,
1015 DefaultScreen(display
), mask
, &changes
);
1016 wine_tsx11_unlock();
1021 /**********************************************************************
1022 * create_whole_window
1024 * Create the whole X window for a given window
1026 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
1029 XSetWindowAttributes attr
;
1032 if (!(cx
= data
->window_rect
.right
- data
->window_rect
.left
)) cx
= 1;
1033 if (!(cy
= data
->window_rect
.bottom
- data
->window_rect
.top
)) cy
= 1;
1035 mask
= get_window_attributes( display
, data
, &attr
);
1039 data
->whole_rect
= data
->window_rect
;
1040 data
->whole_window
= XCreateWindow( display
, root_window
,
1041 data
->window_rect
.left
- virtual_screen_rect
.left
,
1042 data
->window_rect
.top
- virtual_screen_rect
.top
,
1043 cx
, cy
, 0, screen_depth
, InputOutput
,
1044 visual
, mask
, &attr
);
1046 if (!data
->whole_window
)
1048 wine_tsx11_unlock();
1051 XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1053 /* non-maximized child must be at bottom of Z order */
1054 if ((style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
1056 XWindowChanges changes
;
1057 changes
.stack_mode
= Below
;
1058 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
1060 wine_tsx11_unlock();
1062 xim
= x11drv_thread_data()->xim
;
1063 if (xim
) data
->xic
= X11DRV_CreateIC( xim
, display
, data
->whole_window
);
1065 set_initial_wm_hints( display
, data
);
1066 X11DRV_set_wm_hints( display
, data
);
1068 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1069 return data
->whole_window
;
1073 /**********************************************************************
1074 * destroy_whole_window
1076 * Destroy the whole X window for a given window.
1078 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1080 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1082 if (!data
->whole_window
) return;
1084 TRACE( "win %p xwin %lx\n", data
->hwnd
, data
->whole_window
);
1085 if (thread_data
->cursor_window
== data
->whole_window
) thread_data
->cursor_window
= None
;
1087 XDeleteContext( display
, data
->whole_window
, winContext
);
1088 if (data
->whole_window
!= DefaultRootWindow(display
))
1089 XDestroyWindow( display
, data
->whole_window
);
1090 data
->whole_window
= 0;
1093 XUnsetICFocus( data
->xic
);
1094 XDestroyIC( data
->xic
);
1096 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1098 wine_tsx11_unlock();
1099 RemovePropA( data
->hwnd
, whole_window_prop
);
1103 /*****************************************************************
1104 * SetWindowText (X11DRV.@)
1106 void X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1108 Display
*display
= thread_display();
1115 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(display
))
1117 /* allocate new buffer for window text */
1118 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
1119 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
1121 ERR("Not enough memory for window text\n");
1124 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
1126 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
1127 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
1129 ERR("Not enough memory for window text in UTF-8\n");
1130 HeapFree( GetProcessHeap(), 0, buffer
);
1133 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
1136 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
1138 XSetWMName( display
, win
, &prop
);
1139 XSetWMIconName( display
, win
, &prop
);
1140 XFree( prop
.value
);
1143 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
1144 according to the standard
1145 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
1147 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
1148 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
1149 wine_tsx11_unlock();
1151 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
1152 HeapFree( GetProcessHeap(), 0, buffer
);
1157 /***********************************************************************
1158 * DestroyWindow (X11DRV.@)
1160 void X11DRV_DestroyWindow( HWND hwnd
)
1162 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1163 Display
*display
= thread_data
->display
;
1164 struct x11drv_win_data
*data
;
1166 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1170 destroy_glxpixmap(display
, data
->gl_drawable
);
1172 XFreePixmap(display
, data
->pixmap
);
1173 wine_tsx11_unlock();
1175 else if (data
->gl_drawable
)
1178 XDestroyWindow(display
, data
->gl_drawable
);
1179 wine_tsx11_unlock();
1182 free_window_dce( data
);
1183 destroy_whole_window( display
, data
);
1184 destroy_icon_window( display
, data
);
1186 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1187 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1188 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1190 XDeleteContext( display
, (XID
)hwnd
, win_data_context
);
1191 XFree( data
->wm_hints
);
1192 wine_tsx11_unlock();
1193 HeapFree( GetProcessHeap(), 0, data
);
1197 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1199 struct x11drv_win_data
*data
;
1201 if ((data
= HeapAlloc(GetProcessHeap(), 0, sizeof(*data
))))
1204 data
->whole_window
= 0;
1205 data
->icon_window
= 0;
1206 data
->fbconfig_id
= 0;
1207 data
->gl_drawable
= 0;
1210 data
->managed
= FALSE
;
1213 data
->lock_changes
= 0;
1214 data
->hWMIconBitmap
= 0;
1215 data
->hWMIconMask
= 0;
1218 if (!winContext
) winContext
= XUniqueContext();
1219 if (!win_data_context
) win_data_context
= XUniqueContext();
1220 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1221 data
->wm_hints
= XAllocWMHints();
1222 wine_tsx11_unlock();
1228 /* fill in the desktop X window id in the x11drv_win_data structure */
1229 static void get_desktop_xwin( Display
*display
, struct x11drv_win_data
*data
)
1231 Window win
= (Window
)GetPropA( data
->hwnd
, whole_window_prop
);
1235 unsigned int width
, height
;
1237 /* retrieve the real size of the desktop */
1238 SERVER_START_REQ( get_window_rectangles
)
1240 req
->handle
= data
->hwnd
;
1241 wine_server_call( req
);
1242 width
= reply
->window
.right
- reply
->window
.left
;
1243 height
= reply
->window
.bottom
- reply
->window
.top
;
1246 data
->whole_window
= win
;
1247 if (win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1254 visualid
= XVisualIDFromVisual(visual
);
1255 wine_tsx11_unlock();
1256 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1257 SetPropA( data
->hwnd
, visual_id_prop
, (HANDLE
)visualid
);
1258 data
->whole_window
= root_window
;
1259 X11DRV_SetWindowPos( data
->hwnd
, 0, &virtual_screen_rect
, &virtual_screen_rect
,
1260 SWP_NOZORDER
| SWP_NOACTIVATE
, NULL
);
1261 if (root_window
!= DefaultRootWindow( display
))
1263 data
->managed
= TRUE
;
1264 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1265 set_initial_wm_hints( display
, data
);
1270 /**********************************************************************
1271 * CreateDesktopWindow (X11DRV.@)
1273 BOOL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1275 Display
*display
= thread_display();
1276 struct x11drv_win_data
*data
;
1278 if (!(data
= alloc_win_data( display
, hwnd
))) return FALSE
;
1280 get_desktop_xwin( display
, data
);
1286 /**********************************************************************
1287 * CreateWindow (X11DRV.@)
1289 BOOL
X11DRV_CreateWindow( HWND hwnd
, CREATESTRUCTA
*cs
, BOOL unicode
)
1291 Display
*display
= thread_display();
1293 struct x11drv_win_data
*data
;
1297 CBT_CREATEWNDA cbtc
;
1301 if (!(data
= alloc_win_data( display
, hwnd
))) return FALSE
;
1305 ERR( "invalid window width %d\n", cs
->cx
);
1310 ERR( "invalid window height %d\n", cs
->cy
);
1315 ERR( "invalid window width %d\n", cs
->cx
);
1320 ERR( "invalid window height %d\n", cs
->cy
);
1324 /* initialize the dimensions before sending WM_GETMINMAXINFO */
1325 SetRect( &rect
, cs
->x
, cs
->y
, cs
->x
+ cs
->cx
, cs
->y
+ cs
->cy
);
1326 X11DRV_SetWindowPos( hwnd
, 0, &rect
, &rect
, SWP_NOZORDER
| SWP_NOACTIVATE
, NULL
);
1328 /* create an X window if it's a top level window */
1329 if (GetAncestor( hwnd
, GA_PARENT
) == GetDesktopWindow())
1331 if (!create_whole_window( display
, data
, cs
->style
)) goto failed
;
1333 else if (hwnd
== GetDesktopWindow())
1335 get_desktop_xwin( display
, data
);
1338 /* get class or window DC if needed */
1339 alloc_window_dce( data
);
1341 /* Call the WH_CBT hook */
1343 /* the window style passed to the hook must be the real window style,
1344 * rather than just the window style that the caller to CreateWindowEx
1345 * passed in, so we have to copy the original CREATESTRUCT and get the
1346 * the real style. */
1348 cbcs
.style
= GetWindowLongW(hwnd
, GWL_STYLE
);
1351 cbtc
.hwndInsertAfter
= HWND_TOP
;
1352 if (HOOK_CallHooks( WH_CBT
, HCBT_CREATEWND
, (WPARAM
)hwnd
, (LPARAM
)&cbtc
, unicode
))
1354 TRACE("CBT-hook returned !0\n");
1358 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
1359 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
1361 POINT maxSize
, maxPos
, minTrack
, maxTrack
;
1363 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, &maxPos
, &minTrack
, &maxTrack
);
1364 if (maxTrack
.x
< cs
->cx
) cs
->cx
= maxTrack
.x
;
1365 if (maxTrack
.y
< cs
->cy
) cs
->cy
= maxTrack
.y
;
1366 if (cs
->cx
< 0) cs
->cx
= 0;
1367 if (cs
->cy
< 0) cs
->cy
= 0;
1369 SetRect( &rect
, cs
->x
, cs
->y
, cs
->x
+ cs
->cx
, cs
->y
+ cs
->cy
);
1370 if (!X11DRV_SetWindowPos( hwnd
, 0, &rect
, &rect
, SWP_NOZORDER
| SWP_NOACTIVATE
, NULL
))
1374 /* send WM_NCCREATE */
1375 TRACE( "hwnd %p cs %d,%d %dx%d\n", hwnd
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1377 ret
= SendMessageW( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1379 ret
= SendMessageA( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1382 WARN("aborted by WM_xxCREATE!\n");
1386 /* make sure the window is still valid */
1387 if (!(data
= X11DRV_get_win_data( hwnd
))) return FALSE
;
1388 if (data
->whole_window
) X11DRV_sync_window_style( display
, data
);
1390 /* send WM_NCCALCSIZE */
1391 rect
= data
->window_rect
;
1392 SendMessageW( hwnd
, WM_NCCALCSIZE
, FALSE
, (LPARAM
)&rect
);
1394 if (!(wndPtr
= WIN_GetPtr(hwnd
))) return FALSE
;
1396 /* yes, even if the CBT hook was called with HWND_TOP */
1397 insert_after
= (wndPtr
->dwStyle
& WS_CHILD
) ? HWND_BOTTOM
: HWND_TOP
;
1399 X11DRV_SetWindowPos( hwnd
, insert_after
, &wndPtr
->rectWindow
, &rect
, SWP_NOACTIVATE
, NULL
);
1401 TRACE( "win %p window %d,%d,%d,%d client %d,%d,%d,%d whole %d,%d,%d,%d X client %d,%d,%d,%d xwin %x\n",
1402 hwnd
, wndPtr
->rectWindow
.left
, wndPtr
->rectWindow
.top
,
1403 wndPtr
->rectWindow
.right
, wndPtr
->rectWindow
.bottom
,
1404 wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
,
1405 wndPtr
->rectClient
.right
, wndPtr
->rectClient
.bottom
,
1406 data
->whole_rect
.left
, data
->whole_rect
.top
,
1407 data
->whole_rect
.right
, data
->whole_rect
.bottom
,
1408 data
->client_rect
.left
, data
->client_rect
.top
,
1409 data
->client_rect
.right
, data
->client_rect
.bottom
,
1410 (unsigned int)data
->whole_window
);
1412 WIN_ReleasePtr( wndPtr
);
1415 ret
= (SendMessageW( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
) != -1);
1417 ret
= (SendMessageA( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
) != -1);
1419 if (!ret
) return FALSE
;
1421 NotifyWinEvent(EVENT_OBJECT_CREATE
, hwnd
, OBJID_WINDOW
, 0);
1423 /* Send the size messages */
1425 if (!(wndPtr
= WIN_GetPtr(hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return FALSE
;
1426 if (!(wndPtr
->flags
& WIN_NEED_SIZE
))
1428 RECT rect
= wndPtr
->rectClient
;
1429 WIN_ReleasePtr( wndPtr
);
1430 /* send it anyway */
1431 if (((rect
.right
-rect
.left
) <0) ||((rect
.bottom
-rect
.top
)<0))
1432 WARN("sending bogus WM_SIZE message 0x%08x\n",
1433 MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
));
1434 SendMessageW( hwnd
, WM_SIZE
, SIZE_RESTORED
,
1435 MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
));
1436 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( rect
.left
, rect
.top
) );
1438 else WIN_ReleasePtr( wndPtr
);
1440 /* Show the window, maximizing or minimizing if needed */
1442 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1443 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1445 extern UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
); /*FIXME*/
1448 UINT swFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
1449 WIN_SetStyle( hwnd
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
1450 swFlag
= WINPOS_MinMaximize( hwnd
, swFlag
, &newPos
);
1452 swFlag
|= SWP_FRAMECHANGED
; /* Frame always gets changed */
1453 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || GetActiveWindow()) swFlag
|= SWP_NOACTIVATE
;
1455 SetWindowPos( hwnd
, 0, newPos
.left
, newPos
.top
,
1456 newPos
.right
, newPos
.bottom
, swFlag
);
1459 /* Dock system tray windows. */
1460 /* Dock after the window is created so we don't have problems calling
1462 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_TRAYWINDOW
)
1463 systray_dock_window( display
, data
);
1468 X11DRV_DestroyWindow( hwnd
);
1473 /***********************************************************************
1474 * X11DRV_get_win_data
1476 * Return the X11 data structure associated with a window.
1478 struct x11drv_win_data
*X11DRV_get_win_data( HWND hwnd
)
1482 if (!hwnd
|| XFindContext( thread_display(), (XID
)hwnd
, win_data_context
, &data
)) data
= NULL
;
1483 return (struct x11drv_win_data
*)data
;
1487 /***********************************************************************
1488 * X11DRV_get_whole_window
1490 * Return the X window associated with the full area of a window
1492 Window
X11DRV_get_whole_window( HWND hwnd
)
1494 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1496 if (!data
) return (Window
)GetPropA( hwnd
, whole_window_prop
);
1497 return data
->whole_window
;
1501 /***********************************************************************
1502 * X11DRV_get_fbconfig_id
1504 * Return the GLXFBConfig ID of the drawable used by the window for
1505 * OpenGL rendering. This is 0 for windows without a pixel format set.
1507 XID
X11DRV_get_fbconfig_id( HWND hwnd
)
1509 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1511 if (!data
) return (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1512 return data
->fbconfig_id
;
1515 /***********************************************************************
1516 * X11DRV_get_gl_drawable
1518 * Return the GL drawable for this window.
1520 Drawable
X11DRV_get_gl_drawable( HWND hwnd
)
1522 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1524 if (!data
) return (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
1525 return data
->gl_drawable
;
1528 /***********************************************************************
1529 * X11DRV_get_gl_pixmap
1531 * Return the Pixmap associated with the GL drawable (if any) for this window.
1533 Pixmap
X11DRV_get_gl_pixmap( HWND hwnd
)
1535 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1537 if (!data
) return (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
1538 return data
->pixmap
;
1542 /***********************************************************************
1545 * Return the X input context associated with a window
1547 XIC
X11DRV_get_ic( HWND hwnd
)
1549 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1551 if (!data
) return 0;
1556 /*****************************************************************
1557 * SetParent (X11DRV.@)
1559 void X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
1561 Display
*display
= thread_display();
1562 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1565 if (parent
== old_parent
) return;
1567 if (parent
!= GetDesktopWindow()) /* a child window */
1569 if (old_parent
== GetDesktopWindow())
1571 /* destroy the old X windows */
1572 destroy_whole_window( display
, data
);
1573 destroy_icon_window( display
, data
);
1576 data
->managed
= FALSE
;
1577 RemovePropA( data
->hwnd
, managed_prop
);
1581 else /* new top level window */
1583 /* FIXME: we ignore errors since we can't really recover anyway */
1584 create_whole_window( display
, data
, GetWindowLongW( hwnd
, GWL_STYLE
) );
1589 /*****************************************************************
1590 * SetFocus (X11DRV.@)
1593 * Explicit colormap management seems to work only with OLVWM.
1595 void X11DRV_SetFocus( HWND hwnd
)
1597 Display
*display
= thread_display();
1598 struct x11drv_win_data
*data
;
1599 XWindowAttributes win_attr
;
1601 /* Only mess with the X focus if there's */
1602 /* no desktop window and if the window is not managed by the WM. */
1603 if (root_window
!= DefaultRootWindow(display
)) return;
1605 if (!hwnd
) /* If setting the focus to 0, uninstall the colormap */
1608 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1609 XUninstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1610 wine_tsx11_unlock();
1614 hwnd
= GetAncestor( hwnd
, GA_ROOT
);
1616 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1617 if (data
->managed
|| !data
->whole_window
) return;
1619 /* Set X focus and install colormap */
1621 if (XGetWindowAttributes( display
, data
->whole_window
, &win_attr
) &&
1622 (win_attr
.map_state
== IsViewable
))
1624 /* If window is not viewable, don't change anything */
1626 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1627 /* FIXME: this is not entirely correct */
1628 XSetInputFocus( display
, data
->whole_window
, RevertToParent
,
1630 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1631 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1632 XInstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1634 wine_tsx11_unlock();
1638 /**********************************************************************
1639 * SetWindowIcon (X11DRV.@)
1641 * hIcon or hIconSm has changed (or is being initialised for the
1642 * first time). Complete the X11 driver-specific initialisation
1643 * and set the window hints.
1645 * This is not entirely correct, may need to create
1646 * an icon window and set the pixmap as a background
1648 void X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
1650 Display
*display
= thread_display();
1651 struct x11drv_win_data
*data
;
1653 if (type
!= ICON_BIG
) return; /* nothing to do here */
1655 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1656 if (!data
->whole_window
) return;
1657 if (!data
->managed
) return;
1661 set_icon_hints( display
, data
, icon
);
1663 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
1664 wine_tsx11_unlock();