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_window_attributes
134 * Fill the window attributes structure for an X window.
136 static int get_window_attributes( Display
*display
, struct x11drv_win_data
*data
,
137 XSetWindowAttributes
*attr
)
139 attr
->override_redirect
= !data
->managed
;
140 attr
->colormap
= X11DRV_PALETTE_PaletteXColormap
;
141 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
142 attr
->cursor
= x11drv_thread_data()->cursor
;
143 attr
->bit_gravity
= NorthWestGravity
;
144 attr
->backing_store
= NotUseful
;
145 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
146 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
147 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
| KeymapStateMask
);
148 if (data
->managed
) attr
->event_mask
|= StructureNotifyMask
;
150 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
| CWCursor
|
151 CWEventMask
| CWBitGravity
| CWBackingStore
);
155 /***********************************************************************
156 * X11DRV_sync_window_style
158 * Change the X window attributes when the window style has changed.
160 void X11DRV_sync_window_style( Display
*display
, struct x11drv_win_data
*data
)
162 if (data
->whole_window
!= root_window
)
164 XSetWindowAttributes attr
;
165 int mask
= get_window_attributes( display
, data
, &attr
);
168 XChangeWindowAttributes( display
, data
->whole_window
, mask
, &attr
);
174 /***********************************************************************
175 * X11DRV_set_win_format
177 BOOL
X11DRV_set_win_format( HWND hwnd
, XID fbconfig_id
)
179 Display
*display
= thread_display();
180 struct x11drv_win_data
*data
;
186 if (!(data
= X11DRV_get_win_data(hwnd
))) return FALSE
;
190 vis
= visual_from_fbconfig_id(fbconfig_id
);
191 if(!vis
) return FALSE
;
193 if(data
->whole_window
&& vis
->visualid
== XVisualIDFromVisual(visual
))
195 TRACE("Whole window available and visual match, rendering onscreen\n");
201 parent
= data
->whole_window
;
205 next_hwnd
= GetAncestor(next_hwnd
, GA_PARENT
);
208 ERR("Could not find parent HWND with a drawable!\n");
211 parent
= X11DRV_get_whole_window(next_hwnd
);
214 w
= data
->client_rect
.right
- data
->client_rect
.left
;
215 h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
221 #ifdef SONAME_LIBXCOMPOSITE
224 XSetWindowAttributes attrib
;
226 attrib
.override_redirect
= True
;
227 attrib
.colormap
= XCreateColormap(display
, parent
, vis
->visual
,
228 (vis
->class == PseudoColor
||
229 vis
->class == GrayScale
||
230 vis
->class == DirectColor
) ?
231 AllocAll
: AllocNone
);
232 XInstallColormap(gdi_display
, attrib
.colormap
);
234 data
->gl_drawable
= XCreateWindow(display
, parent
, -w
, 0, w
, h
, 0,
235 vis
->depth
, InputOutput
, vis
->visual
,
236 CWColormap
| CWOverrideRedirect
,
238 if(data
->gl_drawable
)
240 pXCompositeRedirectWindow(display
, data
->gl_drawable
,
241 CompositeRedirectManual
);
242 XMapWindow(display
, data
->gl_drawable
);
248 WARN("XComposite is not available, using GLXPixmap hack\n");
250 data
->pixmap
= XCreatePixmap(display
, parent
, w
, h
, vis
->depth
);
253 ERR("Failed to create pixmap for offscreen rendering\n");
259 data
->gl_drawable
= create_glxpixmap(display
, vis
, data
->pixmap
);
260 if(!data
->gl_drawable
)
262 XFreePixmap(display
, data
->pixmap
);
267 if(!data
->gl_drawable
)
269 ERR("Failed to create drawable for offscreen rendering\n");
281 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
282 data
->gl_drawable
, fbconfig_id
);
284 data
->fbconfig_id
= fbconfig_id
;
285 SetPropA(hwnd
, fbconfig_id_prop
, (HANDLE
)data
->fbconfig_id
);
286 SetPropA(hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
287 SetPropA(hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
288 invalidate_dce( hwnd
, &data
->window_rect
);
292 static void update_gl_drawable(Display
*display
, struct x11drv_win_data
*data
, const RECT
*old_client_rect
)
294 int w
= data
->client_rect
.right
- data
->client_rect
.left
;
295 int h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
302 if((w
== old_client_rect
->right
- old_client_rect
->left
&&
303 h
== old_client_rect
->bottom
- old_client_rect
->top
) ||
306 TRACE("No resize needed\n");
310 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
311 #ifdef SONAME_LIBXCOMPOSITE
315 XMoveResizeWindow(display
, data
->gl_drawable
, -w
, 0, w
, h
);
321 parent
= data
->whole_window
;
322 next_hwnd
= data
->hwnd
;
325 next_hwnd
= GetAncestor(next_hwnd
, GA_PARENT
);
328 ERR("Could not find parent HWND with a drawable!\n");
331 parent
= X11DRV_get_whole_window(next_hwnd
);
336 vis
= visual_from_fbconfig_id(data
->fbconfig_id
);
339 pix
= XCreatePixmap(display
, parent
, w
, h
, vis
->depth
);
342 ERR("Failed to create pixmap for offscreen rendering\n");
348 glxp
= create_glxpixmap(display
, vis
, pix
);
351 ERR("Failed to create drawable for offscreen rendering\n");
352 XFreePixmap(display
, pix
);
360 mark_drawable_dirty(data
->gl_drawable
, glxp
);
362 XFreePixmap(display
, data
->pixmap
);
363 destroy_glxpixmap(display
, data
->gl_drawable
);
366 data
->gl_drawable
= glxp
;
371 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
372 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
373 invalidate_dce( data
->hwnd
, &data
->window_rect
);
377 /***********************************************************************
380 * fill the window changes structure
382 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
386 if (old
->right
- old
->left
!= new->right
- new->left
)
388 if (!(changes
->width
= new->right
- new->left
)) changes
->width
= 1;
391 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
393 if (!(changes
->height
= new->bottom
- new->top
)) changes
->height
= 1;
396 if (old
->left
!= new->left
)
398 changes
->x
= new->left
;
401 if (old
->top
!= new->top
)
403 changes
->y
= new->top
;
410 /***********************************************************************
413 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
415 XSetWindowAttributes attr
;
417 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
418 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
419 attr
.bit_gravity
= NorthWestGravity
;
420 attr
.backing_store
= NotUseful
/*WhenMapped*/;
421 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
424 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
425 GetSystemMetrics( SM_CXICON
),
426 GetSystemMetrics( SM_CYICON
),
429 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
430 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
433 TRACE( "created %lx\n", data
->icon_window
);
434 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
435 return data
->icon_window
;
440 /***********************************************************************
441 * destroy_icon_window
443 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
445 if (!data
->icon_window
) return;
446 if (x11drv_thread_data()->cursor_window
== data
->icon_window
)
447 x11drv_thread_data()->cursor_window
= None
;
449 XDeleteContext( display
, data
->icon_window
, winContext
);
450 XDestroyWindow( display
, data
->icon_window
);
451 data
->icon_window
= 0;
453 RemovePropA( data
->hwnd
, icon_window_prop
);
457 /***********************************************************************
460 * Set the icon wm hints
462 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
, HICON hIcon
)
464 XWMHints
*hints
= data
->wm_hints
;
466 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
467 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
468 data
->hWMIconBitmap
= 0;
469 data
->hWMIconMask
= 0;
473 destroy_icon_window( display
, data
);
474 hints
->flags
&= ~(IconPixmapHint
| IconMaskHint
| IconWindowHint
);
478 if (!data
->icon_window
) create_icon_window( display
, data
);
479 hints
->icon_window
= data
->icon_window
;
480 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
490 GetIconInfo(hIcon
, &ii
);
492 GetObjectA(ii
.hbmMask
, sizeof(bmMask
), &bmMask
);
495 rcMask
.right
= bmMask
.bmWidth
;
496 rcMask
.bottom
= bmMask
.bmHeight
;
498 hDC
= CreateCompatibleDC(0);
499 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
500 InvertRect(hDC
, &rcMask
);
501 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
502 SelectObject(hDC
, hbmOrig
);
505 data
->hWMIconBitmap
= ii
.hbmColor
;
506 data
->hWMIconMask
= ii
.hbmMask
;
508 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
509 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
510 destroy_icon_window( display
, data
);
511 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
515 /***********************************************************************
516 * systray_dock_window
518 * Docks the given X window with the NETWM system tray.
520 static void systray_dock_window( Display
*display
, struct x11drv_win_data
*data
)
522 static Atom systray_atom
;
523 Window systray_window
;
528 if (DefaultScreen( display
) == 0)
529 systray_atom
= x11drv_atom(_NET_SYSTEM_TRAY_S0
);
532 char systray_buffer
[29]; /* strlen(_NET_SYSTEM_TRAY_S4294967295)+1 */
533 sprintf( systray_buffer
, "_NET_SYSTEM_TRAY_S%u", DefaultScreen( display
) );
534 systray_atom
= XInternAtom( display
, systray_buffer
, False
);
537 systray_window
= XGetSelectionOwner( display
, systray_atom
);
540 TRACE("Docking tray icon %p\n", data
->hwnd
);
542 if (systray_window
!= None
)
545 unsigned long info
[2];
547 /* Put the window offscreen so it isn't mapped. The window _cannot_ be
548 * mapped if we intend to dock with an XEMBED tray. If the window is
549 * mapped when we dock, it may become visible as a child of the root
550 * window after it docks, which isn't the proper behavior.
552 * For more information on this problem, see
553 * http://standards.freedesktop.org/xembed-spec/latest/ar01s04.html */
555 SetWindowPos( data
->hwnd
, NULL
, virtual_screen_rect
.right
+ 1, virtual_screen_rect
.bottom
+ 1,
556 0, 0, SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
558 /* set XEMBED protocol data on the window */
559 info
[0] = 0; /* protocol version */
560 info
[1] = 1; /* mapped = true */
563 XChangeProperty( display
, data
->whole_window
,
564 x11drv_atom(_XEMBED_INFO
),
565 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
,
566 (unsigned char*)info
, 2 );
569 /* send the docking request message */
570 ZeroMemory( &ev
, sizeof(ev
) );
571 ev
.xclient
.type
= ClientMessage
;
572 ev
.xclient
.window
= systray_window
;
573 ev
.xclient
.message_type
= x11drv_atom( _NET_SYSTEM_TRAY_OPCODE
);
574 ev
.xclient
.format
= 32;
575 ev
.xclient
.data
.l
[0] = CurrentTime
;
576 ev
.xclient
.data
.l
[1] = SYSTEM_TRAY_REQUEST_DOCK
;
577 ev
.xclient
.data
.l
[2] = data
->whole_window
;
578 ev
.xclient
.data
.l
[3] = 0;
579 ev
.xclient
.data
.l
[4] = 0;
582 XSendEvent( display
, systray_window
, False
, NoEventMask
, &ev
);
590 /* fall back to he KDE hints if the WM doesn't support XEMBED'ed
594 XChangeProperty( display
, data
->whole_window
,
595 x11drv_atom(KWM_DOCKWINDOW
),
596 x11drv_atom(KWM_DOCKWINDOW
), 32, PropModeReplace
,
597 (unsigned char*)&val
, 1 );
598 XChangeProperty( display
, data
->whole_window
,
599 x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR
),
600 XA_WINDOW
, 32, PropModeReplace
,
601 (unsigned char*)&data
->whole_window
, 1 );
607 /***********************************************************************
610 * set the window size hints
612 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
614 XSizeHints
* size_hints
;
616 if ((size_hints
= XAllocSizeHints()))
618 size_hints
->flags
= 0;
620 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
622 size_hints
->win_gravity
= StaticGravity
;
623 size_hints
->x
= data
->whole_rect
.left
;
624 size_hints
->y
= data
->whole_rect
.top
;
625 size_hints
->flags
|= PWinGravity
| PPosition
;
628 if ( !(style
& WS_THICKFRAME
) )
630 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
631 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
632 size_hints
->min_width
= size_hints
->max_width
;
633 size_hints
->min_height
= size_hints
->max_height
;
634 size_hints
->flags
|= PMinSize
| PMaxSize
;
636 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
642 /***********************************************************************
645 * get the name of the current process for setting class hints
647 static char *get_process_name(void)
653 WCHAR module
[MAX_PATH
];
654 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
655 if (len
&& len
< MAX_PATH
)
658 WCHAR
*p
, *appname
= module
;
660 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
661 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
662 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
663 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
665 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
674 /***********************************************************************
675 * set_initial_wm_hints
677 * Set the window manager hints that don't change over the lifetime of a window.
679 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
684 XClassHint
*class_hints
;
685 char *process_name
= get_process_name();
691 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
692 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
693 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
694 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
695 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
698 if ((class_hints
= XAllocClassHint()))
700 static char wine
[] = "Wine";
702 class_hints
->res_name
= process_name
;
703 class_hints
->res_class
= wine
;
704 XSetClassHint( display
, data
->whole_window
, class_hints
);
705 XFree( class_hints
);
708 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
709 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
710 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
712 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
713 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
715 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
716 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
722 /***********************************************************************
723 * X11DRV_set_wm_hints
725 * Set the window manager hints for a newly-created window
727 void X11DRV_set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
732 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
733 DWORD ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
734 HWND owner
= GetWindow( data
->hwnd
, GW_OWNER
);
736 if (data
->hwnd
== GetDesktopWindow())
738 if (data
->whole_window
== DefaultRootWindow(display
)) return;
739 /* force some styles for the desktop to get the correct decorations */
740 style
|= WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
744 /* transient for hint */
747 Window owner_win
= X11DRV_get_whole_window( owner
);
749 XSetTransientForHint( display
, data
->whole_window
, owner_win
);
751 group_leader
= owner_win
;
753 else group_leader
= data
->whole_window
;
758 set_size_hints( display
, data
, style
);
760 /* set the WM_WINDOW_TYPE */
761 window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
762 if (ex_style
& WS_EX_TOOLWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY
);
763 else if (style
& WS_THICKFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
764 else if (style
& WS_DLGFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
765 else if (ex_style
& WS_EX_DLGMODALFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
767 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
768 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
770 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
771 mwm_hints
.functions
= MWM_FUNC_MOVE
;
772 if (style
& WS_THICKFRAME
) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
773 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
774 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
775 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
776 mwm_hints
.decorations
= 0;
777 if (!(ex_style
& WS_EX_TOOLWINDOW
))
779 if ((style
& WS_CAPTION
) == WS_CAPTION
)
781 mwm_hints
.decorations
|= MWM_DECOR_TITLE
;
782 if (style
& WS_SYSMENU
) mwm_hints
.decorations
|= MWM_DECOR_MENU
;
783 if (style
& WS_MINIMIZEBOX
) mwm_hints
.decorations
|= MWM_DECOR_MINIMIZE
;
784 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.decorations
|= MWM_DECOR_MAXIMIZE
;
786 if (ex_style
& WS_EX_DLGMODALFRAME
) mwm_hints
.decorations
|= MWM_DECOR_BORDER
;
787 else if (style
& WS_THICKFRAME
) mwm_hints
.decorations
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
788 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) mwm_hints
.decorations
|= MWM_DECOR_BORDER
;
789 else if (style
& WS_BORDER
) mwm_hints
.decorations
|= MWM_DECOR_BORDER
;
790 else if (!(style
& (WS_CHILD
|WS_POPUP
))) mwm_hints
.decorations
|= MWM_DECOR_BORDER
;
793 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
794 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
795 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
802 data
->wm_hints
->flags
= InputHint
| StateHint
| WindowGroupHint
;
803 data
->wm_hints
->input
= !(style
& WS_DISABLED
);
804 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
805 data
->wm_hints
->window_group
= group_leader
;
806 set_icon_hints( display
, data
, (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
) );
809 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
815 /***********************************************************************
816 * X11DRV_set_iconic_state
818 * Set the X11 iconic state according to the window style.
820 void X11DRV_set_iconic_state( HWND hwnd
)
822 Display
*display
= thread_display();
823 struct x11drv_win_data
*data
;
825 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
826 BOOL iconic
= (style
& WS_MINIMIZE
) != 0;
828 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
829 if (!data
->whole_window
|| data
->whole_window
== DefaultRootWindow(display
)) return;
831 GetWindowRect( hwnd
, &rect
);
837 data
->wm_hints
->flags
|= StateHint
| IconPositionHint
;
838 data
->wm_hints
->initial_state
= iconic
? IconicState
: NormalState
;
839 data
->wm_hints
->icon_x
= rect
.left
- virtual_screen_rect
.left
;
840 data
->wm_hints
->icon_y
= rect
.top
- virtual_screen_rect
.top
;
841 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
844 if (style
& WS_VISIBLE
)
847 XIconifyWindow( display
, data
->whole_window
, DefaultScreen(display
) );
849 if (X11DRV_is_window_rect_mapped( &rect
))
850 XMapWindow( display
, data
->whole_window
);
857 /***********************************************************************
858 * X11DRV_window_to_X_rect
860 * Convert a rect from client to X window coordinates
862 void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
867 if (!data
->managed
) return;
868 if (IsRectEmpty( rect
)) return;
869 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
870 if (ex_style
& WS_EX_TOOLWINDOW
) return;
872 rc
.top
= rc
.bottom
= rc
.left
= rc
.right
= 0;
874 AdjustWindowRectEx( &rc
, GetWindowLongW( data
->hwnd
, GWL_STYLE
) & ~(WS_HSCROLL
|WS_VSCROLL
),
877 rect
->left
-= rc
.left
;
878 rect
->right
-= rc
.right
;
880 rect
->bottom
-= rc
.bottom
;
881 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
882 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
886 /***********************************************************************
887 * X11DRV_X_to_window_rect
889 * Opposite of X11DRV_window_to_X_rect
891 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
895 if (!data
->managed
) return;
896 if (IsRectEmpty( rect
)) return;
897 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
898 if (ex_style
& WS_EX_TOOLWINDOW
) return;
900 AdjustWindowRectEx( rect
, GetWindowLongW( data
->hwnd
, GWL_STYLE
) & ~(WS_HSCROLL
|WS_VSCROLL
),
903 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
904 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
908 /***********************************************************************
909 * X11DRV_sync_window_position
911 * Synchronize the X window position with the Windows one
913 void X11DRV_sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
914 UINT swp_flags
, const RECT
*new_client_rect
,
915 const RECT
*new_whole_rect
)
917 XWindowChanges changes
;
920 RECT old_client_rect
;
922 old_whole_rect
= data
->whole_rect
;
923 data
->whole_rect
= *new_whole_rect
;
925 old_client_rect
= data
->client_rect
;
926 data
->client_rect
= *new_client_rect
;
927 OffsetRect( &data
->client_rect
, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
929 if (data
->gl_drawable
)
930 update_gl_drawable(display
, data
, &old_client_rect
);
932 if (!data
->whole_window
|| data
->lock_changes
) return;
934 mask
= get_window_changes( &changes
, &old_whole_rect
, &data
->whole_rect
);
936 if (!(swp_flags
& SWP_NOZORDER
))
938 /* find window that this one must be after */
939 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
940 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
941 prev
= GetWindow( prev
, GW_HWNDPREV
);
942 if (!prev
) /* top child */
944 changes
.stack_mode
= Above
;
949 /* should use stack_mode Below but most window managers don't get it right */
950 /* so move it above the next one in Z order */
951 HWND next
= GetWindow( data
->hwnd
, GW_HWNDNEXT
);
952 while (next
&& !(GetWindowLongW( next
, GWL_STYLE
) & WS_VISIBLE
))
953 next
= GetWindow( next
, GW_HWNDNEXT
);
956 changes
.stack_mode
= Above
;
957 changes
.sibling
= X11DRV_get_whole_window(next
);
958 mask
|= CWStackMode
| CWSibling
;
965 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
967 TRACE( "setting win %lx pos %d,%d,%dx%d after %lx changes=%x\n",
968 data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
969 data
->whole_rect
.right
- data
->whole_rect
.left
,
970 data
->whole_rect
.bottom
- data
->whole_rect
.top
, changes
.sibling
, mask
);
973 if (mask
& (CWWidth
|CWHeight
)) set_size_hints( display
, data
, style
);
974 if (mask
& CWX
) changes
.x
-= virtual_screen_rect
.left
;
975 if (mask
& CWY
) changes
.y
-= virtual_screen_rect
.top
;
976 XReconfigureWMWindow( display
, data
->whole_window
,
977 DefaultScreen(display
), mask
, &changes
);
983 /**********************************************************************
984 * create_whole_window
986 * Create the whole X window for a given window
988 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
991 XSetWindowAttributes attr
;
994 if (!(cx
= data
->window_rect
.right
- data
->window_rect
.left
)) cx
= 1;
995 if (!(cy
= data
->window_rect
.bottom
- data
->window_rect
.top
)) cy
= 1;
997 mask
= get_window_attributes( display
, data
, &attr
);
1001 data
->whole_rect
= data
->window_rect
;
1002 data
->whole_window
= XCreateWindow( display
, root_window
,
1003 data
->window_rect
.left
- virtual_screen_rect
.left
,
1004 data
->window_rect
.top
- virtual_screen_rect
.top
,
1005 cx
, cy
, 0, screen_depth
, InputOutput
,
1006 visual
, mask
, &attr
);
1008 if (!data
->whole_window
)
1010 wine_tsx11_unlock();
1013 XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1015 /* non-maximized child must be at bottom of Z order */
1016 if ((style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
1018 XWindowChanges changes
;
1019 changes
.stack_mode
= Below
;
1020 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
1022 wine_tsx11_unlock();
1024 xim
= x11drv_thread_data()->xim
;
1025 if (xim
) data
->xic
= X11DRV_CreateIC( xim
, display
, data
->whole_window
);
1027 set_initial_wm_hints( display
, data
);
1028 X11DRV_set_wm_hints( display
, data
);
1030 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1031 return data
->whole_window
;
1035 /**********************************************************************
1036 * destroy_whole_window
1038 * Destroy the whole X window for a given window.
1040 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1042 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1044 if (!data
->whole_window
) return;
1046 TRACE( "win %p xwin %lx\n", data
->hwnd
, data
->whole_window
);
1047 if (thread_data
->cursor_window
== data
->whole_window
) thread_data
->cursor_window
= None
;
1049 XDeleteContext( display
, data
->whole_window
, winContext
);
1050 if (data
->whole_window
!= DefaultRootWindow(display
))
1051 XDestroyWindow( display
, data
->whole_window
);
1052 data
->whole_window
= 0;
1055 XUnsetICFocus( data
->xic
);
1056 XDestroyIC( data
->xic
);
1058 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1060 wine_tsx11_unlock();
1061 RemovePropA( data
->hwnd
, whole_window_prop
);
1065 /*****************************************************************
1066 * SetWindowText (X11DRV.@)
1068 void X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1070 Display
*display
= thread_display();
1077 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(display
))
1079 /* allocate new buffer for window text */
1080 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
1081 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
1083 ERR("Not enough memory for window text\n");
1086 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
1088 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
1089 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
1091 ERR("Not enough memory for window text in UTF-8\n");
1092 HeapFree( GetProcessHeap(), 0, buffer
);
1095 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
1098 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
1100 XSetWMName( display
, win
, &prop
);
1101 XSetWMIconName( display
, win
, &prop
);
1102 XFree( prop
.value
);
1105 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
1106 according to the standard
1107 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
1109 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
1110 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
1111 wine_tsx11_unlock();
1113 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
1114 HeapFree( GetProcessHeap(), 0, buffer
);
1119 /***********************************************************************
1120 * DestroyWindow (X11DRV.@)
1122 void X11DRV_DestroyWindow( HWND hwnd
)
1124 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1125 Display
*display
= thread_data
->display
;
1126 struct x11drv_win_data
*data
;
1128 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1132 destroy_glxpixmap(display
, data
->gl_drawable
);
1134 XFreePixmap(display
, data
->pixmap
);
1135 wine_tsx11_unlock();
1137 else if (data
->gl_drawable
)
1140 XDestroyWindow(display
, data
->gl_drawable
);
1141 wine_tsx11_unlock();
1144 free_window_dce( data
);
1145 destroy_whole_window( display
, data
);
1146 destroy_icon_window( display
, data
);
1148 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1149 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1150 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1152 XDeleteContext( display
, (XID
)hwnd
, win_data_context
);
1153 XFree( data
->wm_hints
);
1154 wine_tsx11_unlock();
1155 HeapFree( GetProcessHeap(), 0, data
);
1159 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1161 struct x11drv_win_data
*data
;
1163 if ((data
= HeapAlloc(GetProcessHeap(), 0, sizeof(*data
))))
1166 data
->whole_window
= 0;
1167 data
->icon_window
= 0;
1168 data
->fbconfig_id
= 0;
1169 data
->gl_drawable
= 0;
1172 data
->managed
= FALSE
;
1174 data
->lock_changes
= 0;
1175 data
->hWMIconBitmap
= 0;
1176 data
->hWMIconMask
= 0;
1179 if (!winContext
) winContext
= XUniqueContext();
1180 if (!win_data_context
) win_data_context
= XUniqueContext();
1181 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1182 data
->wm_hints
= XAllocWMHints();
1183 wine_tsx11_unlock();
1189 /* fill in the desktop X window id in the x11drv_win_data structure */
1190 static void get_desktop_xwin( Display
*display
, struct x11drv_win_data
*data
)
1192 Window win
= (Window
)GetPropA( data
->hwnd
, whole_window_prop
);
1196 unsigned int width
, height
;
1198 /* retrieve the real size of the desktop */
1199 SERVER_START_REQ( get_window_rectangles
)
1201 req
->handle
= data
->hwnd
;
1202 wine_server_call( req
);
1203 width
= reply
->window
.right
- reply
->window
.left
;
1204 height
= reply
->window
.bottom
- reply
->window
.top
;
1207 data
->whole_window
= win
;
1208 if (win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1215 visualid
= XVisualIDFromVisual(visual
);
1216 wine_tsx11_unlock();
1217 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1218 SetPropA( data
->hwnd
, visual_id_prop
, (HANDLE
)visualid
);
1219 data
->whole_window
= root_window
;
1220 X11DRV_SetWindowPos( data
->hwnd
, 0, &virtual_screen_rect
, &virtual_screen_rect
,
1221 SWP_NOZORDER
| SWP_NOACTIVATE
, NULL
);
1222 if (root_window
!= DefaultRootWindow( display
))
1224 data
->managed
= TRUE
;
1225 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1226 set_initial_wm_hints( display
, data
);
1231 /**********************************************************************
1232 * CreateDesktopWindow (X11DRV.@)
1234 BOOL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1236 Display
*display
= thread_display();
1237 struct x11drv_win_data
*data
;
1239 if (!(data
= alloc_win_data( display
, hwnd
))) return FALSE
;
1241 get_desktop_xwin( display
, data
);
1247 /**********************************************************************
1248 * CreateWindow (X11DRV.@)
1250 BOOL
X11DRV_CreateWindow( HWND hwnd
, CREATESTRUCTA
*cs
, BOOL unicode
)
1252 Display
*display
= thread_display();
1254 struct x11drv_win_data
*data
;
1258 CBT_CREATEWNDA cbtc
;
1262 if (!(data
= alloc_win_data( display
, hwnd
))) return FALSE
;
1266 ERR( "invalid window width %d\n", cs
->cx
);
1271 ERR( "invalid window height %d\n", cs
->cy
);
1276 ERR( "invalid window width %d\n", cs
->cx
);
1281 ERR( "invalid window height %d\n", cs
->cy
);
1285 /* initialize the dimensions before sending WM_GETMINMAXINFO */
1286 SetRect( &rect
, cs
->x
, cs
->y
, cs
->x
+ cs
->cx
, cs
->y
+ cs
->cy
);
1287 X11DRV_SetWindowPos( hwnd
, 0, &rect
, &rect
, SWP_NOZORDER
| SWP_NOACTIVATE
, NULL
);
1289 /* create an X window if it's a top level window */
1290 if (GetAncestor( hwnd
, GA_PARENT
) == GetDesktopWindow())
1292 if (!create_whole_window( display
, data
, cs
->style
)) goto failed
;
1294 else if (hwnd
== GetDesktopWindow())
1296 get_desktop_xwin( display
, data
);
1299 /* get class or window DC if needed */
1300 alloc_window_dce( data
);
1302 /* Call the WH_CBT hook */
1304 /* the window style passed to the hook must be the real window style,
1305 * rather than just the window style that the caller to CreateWindowEx
1306 * passed in, so we have to copy the original CREATESTRUCT and get the
1307 * the real style. */
1309 cbcs
.style
= GetWindowLongW(hwnd
, GWL_STYLE
);
1312 cbtc
.hwndInsertAfter
= HWND_TOP
;
1313 if (HOOK_CallHooks( WH_CBT
, HCBT_CREATEWND
, (WPARAM
)hwnd
, (LPARAM
)&cbtc
, unicode
))
1315 TRACE("CBT-hook returned !0\n");
1319 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
1320 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
1322 POINT maxSize
, maxPos
, minTrack
, maxTrack
;
1324 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, &maxPos
, &minTrack
, &maxTrack
);
1325 if (maxTrack
.x
< cs
->cx
) cs
->cx
= maxTrack
.x
;
1326 if (maxTrack
.y
< cs
->cy
) cs
->cy
= maxTrack
.y
;
1327 if (cs
->cx
< 0) cs
->cx
= 0;
1328 if (cs
->cy
< 0) cs
->cy
= 0;
1330 SetRect( &rect
, cs
->x
, cs
->y
, cs
->x
+ cs
->cx
, cs
->y
+ cs
->cy
);
1331 if (!X11DRV_SetWindowPos( hwnd
, 0, &rect
, &rect
, SWP_NOZORDER
| SWP_NOACTIVATE
, NULL
))
1335 /* send WM_NCCREATE */
1336 TRACE( "hwnd %p cs %d,%d %dx%d\n", hwnd
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1338 ret
= SendMessageW( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1340 ret
= SendMessageA( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1343 WARN("aborted by WM_xxCREATE!\n");
1347 /* make sure the window is still valid */
1348 if (!(data
= X11DRV_get_win_data( hwnd
))) return FALSE
;
1349 if (data
->whole_window
) X11DRV_sync_window_style( display
, data
);
1351 /* send WM_NCCALCSIZE */
1352 rect
= data
->window_rect
;
1353 SendMessageW( hwnd
, WM_NCCALCSIZE
, FALSE
, (LPARAM
)&rect
);
1355 if (!(wndPtr
= WIN_GetPtr(hwnd
))) return FALSE
;
1357 /* yes, even if the CBT hook was called with HWND_TOP */
1358 insert_after
= (wndPtr
->dwStyle
& WS_CHILD
) ? HWND_BOTTOM
: HWND_TOP
;
1360 X11DRV_SetWindowPos( hwnd
, insert_after
, &wndPtr
->rectWindow
, &rect
, SWP_NOACTIVATE
, NULL
);
1362 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",
1363 hwnd
, wndPtr
->rectWindow
.left
, wndPtr
->rectWindow
.top
,
1364 wndPtr
->rectWindow
.right
, wndPtr
->rectWindow
.bottom
,
1365 wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
,
1366 wndPtr
->rectClient
.right
, wndPtr
->rectClient
.bottom
,
1367 data
->whole_rect
.left
, data
->whole_rect
.top
,
1368 data
->whole_rect
.right
, data
->whole_rect
.bottom
,
1369 data
->client_rect
.left
, data
->client_rect
.top
,
1370 data
->client_rect
.right
, data
->client_rect
.bottom
,
1371 (unsigned int)data
->whole_window
);
1373 WIN_ReleasePtr( wndPtr
);
1376 ret
= (SendMessageW( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
) != -1);
1378 ret
= (SendMessageA( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
) != -1);
1380 if (!ret
) return FALSE
;
1382 NotifyWinEvent(EVENT_OBJECT_CREATE
, hwnd
, OBJID_WINDOW
, 0);
1384 /* Send the size messages */
1386 if (!(wndPtr
= WIN_GetPtr(hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return FALSE
;
1387 if (!(wndPtr
->flags
& WIN_NEED_SIZE
))
1389 RECT rect
= wndPtr
->rectClient
;
1390 WIN_ReleasePtr( wndPtr
);
1391 /* send it anyway */
1392 if (((rect
.right
-rect
.left
) <0) ||((rect
.bottom
-rect
.top
)<0))
1393 WARN("sending bogus WM_SIZE message 0x%08x\n",
1394 MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
));
1395 SendMessageW( hwnd
, WM_SIZE
, SIZE_RESTORED
,
1396 MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
));
1397 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( rect
.left
, rect
.top
) );
1399 else WIN_ReleasePtr( wndPtr
);
1401 /* Show the window, maximizing or minimizing if needed */
1403 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1404 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1406 extern UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
); /*FIXME*/
1409 UINT swFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
1410 WIN_SetStyle( hwnd
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
1411 swFlag
= WINPOS_MinMaximize( hwnd
, swFlag
, &newPos
);
1413 swFlag
|= SWP_FRAMECHANGED
; /* Frame always gets changed */
1414 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || GetActiveWindow()) swFlag
|= SWP_NOACTIVATE
;
1416 SetWindowPos( hwnd
, 0, newPos
.left
, newPos
.top
,
1417 newPos
.right
, newPos
.bottom
, swFlag
);
1420 /* Dock system tray windows. */
1421 /* Dock after the window is created so we don't have problems calling
1423 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_TRAYWINDOW
)
1424 systray_dock_window( display
, data
);
1429 X11DRV_DestroyWindow( hwnd
);
1434 /***********************************************************************
1435 * X11DRV_get_win_data
1437 * Return the X11 data structure associated with a window.
1439 struct x11drv_win_data
*X11DRV_get_win_data( HWND hwnd
)
1443 if (!hwnd
|| XFindContext( thread_display(), (XID
)hwnd
, win_data_context
, &data
)) data
= NULL
;
1444 return (struct x11drv_win_data
*)data
;
1448 /***********************************************************************
1449 * X11DRV_get_whole_window
1451 * Return the X window associated with the full area of a window
1453 Window
X11DRV_get_whole_window( HWND hwnd
)
1455 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1457 if (!data
) return (Window
)GetPropA( hwnd
, whole_window_prop
);
1458 return data
->whole_window
;
1462 /***********************************************************************
1463 * X11DRV_get_fbconfig_id
1465 * Return the GLXFBConfig ID of the drawable used by the window for
1466 * OpenGL rendering. This is 0 for windows without a pixel format set.
1468 XID
X11DRV_get_fbconfig_id( HWND hwnd
)
1470 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1472 if (!data
) return (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1473 return data
->fbconfig_id
;
1476 /***********************************************************************
1477 * X11DRV_get_gl_drawable
1479 * Return the GL drawable for this window.
1481 Drawable
X11DRV_get_gl_drawable( HWND hwnd
)
1483 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1485 if (!data
) return (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
1486 return data
->gl_drawable
;
1489 /***********************************************************************
1490 * X11DRV_get_gl_pixmap
1492 * Return the Pixmap associated with the GL drawable (if any) for this window.
1494 Pixmap
X11DRV_get_gl_pixmap( HWND hwnd
)
1496 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1498 if (!data
) return (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
1499 return data
->pixmap
;
1503 /***********************************************************************
1506 * Return the X input context associated with a window
1508 XIC
X11DRV_get_ic( HWND hwnd
)
1510 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1512 if (!data
) return 0;
1517 /*****************************************************************
1518 * SetParent (X11DRV.@)
1520 void X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
1522 Display
*display
= thread_display();
1523 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1526 if (parent
== old_parent
) return;
1528 if (parent
!= GetDesktopWindow()) /* a child window */
1530 if (old_parent
== GetDesktopWindow())
1532 /* destroy the old X windows */
1533 destroy_whole_window( display
, data
);
1534 destroy_icon_window( display
, data
);
1537 data
->managed
= FALSE
;
1538 RemovePropA( data
->hwnd
, managed_prop
);
1542 else /* new top level window */
1544 /* FIXME: we ignore errors since we can't really recover anyway */
1545 create_whole_window( display
, data
, GetWindowLongW( hwnd
, GWL_STYLE
) );
1550 /*****************************************************************
1551 * SetFocus (X11DRV.@)
1554 * Explicit colormap management seems to work only with OLVWM.
1556 void X11DRV_SetFocus( HWND hwnd
)
1558 Display
*display
= thread_display();
1559 struct x11drv_win_data
*data
;
1560 XWindowAttributes win_attr
;
1562 /* Only mess with the X focus if there's */
1563 /* no desktop window and if the window is not managed by the WM. */
1564 if (root_window
!= DefaultRootWindow(display
)) return;
1566 if (!hwnd
) /* If setting the focus to 0, uninstall the colormap */
1569 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1570 XUninstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1571 wine_tsx11_unlock();
1575 hwnd
= GetAncestor( hwnd
, GA_ROOT
);
1577 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1578 if (data
->managed
|| !data
->whole_window
) return;
1580 /* Set X focus and install colormap */
1582 if (XGetWindowAttributes( display
, data
->whole_window
, &win_attr
) &&
1583 (win_attr
.map_state
== IsViewable
))
1585 /* If window is not viewable, don't change anything */
1587 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1588 /* FIXME: this is not entirely correct */
1589 XSetInputFocus( display
, data
->whole_window
, RevertToParent
,
1591 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1592 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1593 XInstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1595 wine_tsx11_unlock();
1599 /**********************************************************************
1600 * SetWindowIcon (X11DRV.@)
1602 * hIcon or hIconSm has changed (or is being initialised for the
1603 * first time). Complete the X11 driver-specific initialisation
1604 * and set the window hints.
1606 * This is not entirely correct, may need to create
1607 * an icon window and set the pixmap as a background
1609 void X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
1611 Display
*display
= thread_display();
1612 struct x11drv_win_data
*data
;
1614 if (type
!= ICON_BIG
) return; /* nothing to do here */
1616 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1617 if (!data
->whole_window
) return;
1618 if (!data
->managed
) return;
1622 set_icon_hints( display
, data
, icon
);
1624 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
1625 wine_tsx11_unlock();