2 * Window related functions
4 * Copyright 1993, 1994, 1995, 1996, 2001 Alexandre Julliard
5 * Copyright 1993 David Metcalfe
6 * Copyright 1995, 1996 Alex Korobka
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include <X11/Xresource.h>
34 #include <X11/Xutil.h>
36 #include <X11/extensions/shape.h>
37 #endif /* HAVE_LIBXSHAPE */
43 #include "wine/unicode.h"
46 #include "xcomposite.h"
47 #include "wine/debug.h"
48 #include "wine/server.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
54 /* X context to associate a hwnd to an X window */
55 XContext winContext
= 0;
57 /* X context to associate a struct x11drv_win_data to an hwnd */
58 static XContext win_data_context
;
60 static const char whole_window_prop
[] = "__wine_x11_whole_window";
61 static const char icon_window_prop
[] = "__wine_x11_icon_window";
62 static const char fbconfig_id_prop
[] = "__wine_x11_fbconfig_id";
63 static const char gl_drawable_prop
[] = "__wine_x11_gl_drawable";
64 static const char pixmap_prop
[] = "__wine_x11_pixmap";
65 static const char managed_prop
[] = "__wine_x11_managed";
66 static const char visual_id_prop
[] = "__wine_x11_visual_id";
68 /* for XDG systray icons */
69 #define SYSTEM_TRAY_REQUEST_DOCK 0
71 extern int usexcomposite
;
73 /***********************************************************************
76 * Check if a given window should be managed
78 BOOL
is_window_managed( HWND hwnd
, UINT swp_flags
, const RECT
*window_rect
)
80 DWORD style
, ex_style
;
82 /* tray window is always managed */
83 ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
84 if (ex_style
& WS_EX_TRAYWINDOW
) return TRUE
;
85 /* child windows are not managed */
86 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
87 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
) return FALSE
;
88 /* activated windows are managed */
89 if (!(swp_flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
))) return TRUE
;
90 if (hwnd
== GetActiveWindow()) return TRUE
;
91 /* windows with caption are managed */
92 if ((style
& WS_CAPTION
) == WS_CAPTION
) return TRUE
;
93 /* tool windows are not managed */
94 if (ex_style
& WS_EX_TOOLWINDOW
) return FALSE
;
95 /* windows with thick frame are managed */
96 if (style
& WS_THICKFRAME
) return TRUE
;
97 /* application windows are managed */
98 if (ex_style
& WS_EX_APPWINDOW
) return TRUE
;
101 /* popup with sysmenu == caption are managed */
102 if (style
& WS_SYSMENU
) return TRUE
;
103 /* full-screen popup windows are managed */
104 if ((window_rect
->right
- window_rect
->left
) == screen_width
&&
105 (window_rect
->bottom
- window_rect
->top
) == screen_height
)
108 /* default: not managed */
113 /***********************************************************************
114 * X11DRV_is_window_rect_mapped
116 * Check if the X whole window should be mapped based on its rectangle
118 BOOL
X11DRV_is_window_rect_mapped( const RECT
*rect
)
120 /* don't map if rect is empty */
121 if (IsRectEmpty( rect
)) return FALSE
;
123 /* don't map if rect is off-screen */
124 if (rect
->left
>= virtual_screen_rect
.right
||
125 rect
->top
>= virtual_screen_rect
.bottom
||
126 rect
->right
<= virtual_screen_rect
.left
||
127 rect
->bottom
<= virtual_screen_rect
.top
)
134 /***********************************************************************
135 * get_mwm_decorations
137 static unsigned long get_mwm_decorations( DWORD style
, DWORD ex_style
)
139 unsigned long ret
= 0;
141 if (ex_style
& WS_EX_TOOLWINDOW
) return 0;
143 if ((style
& WS_CAPTION
) == WS_CAPTION
)
145 ret
|= MWM_DECOR_TITLE
| MWM_DECOR_BORDER
;
146 if (style
& WS_SYSMENU
) ret
|= MWM_DECOR_MENU
;
147 if (style
& WS_MINIMIZEBOX
) ret
|= MWM_DECOR_MINIMIZE
;
148 if (style
& WS_MAXIMIZEBOX
) ret
|= MWM_DECOR_MAXIMIZE
;
150 if (ex_style
& WS_EX_DLGMODALFRAME
) ret
|= MWM_DECOR_BORDER
;
151 else if (style
& WS_THICKFRAME
) ret
|= MWM_DECOR_BORDER
| MWM_DECOR_RESIZEH
;
152 else if ((style
& (WS_DLGFRAME
|WS_BORDER
)) == WS_DLGFRAME
) ret
|= MWM_DECOR_BORDER
;
157 /***********************************************************************
158 * get_x11_rect_offset
160 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
162 static void get_x11_rect_offset( struct x11drv_win_data
*data
, RECT
*rect
)
164 DWORD style
, ex_style
, style_mask
= 0, ex_style_mask
= 0;
167 rect
->top
= rect
->bottom
= rect
->left
= rect
->right
= 0;
169 style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
170 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
171 decor
= get_mwm_decorations( style
, ex_style
);
173 if (decor
& MWM_DECOR_TITLE
) style_mask
|= WS_CAPTION
;
174 if (decor
& MWM_DECOR_BORDER
)
176 style_mask
|= WS_DLGFRAME
| WS_THICKFRAME
;
177 ex_style_mask
|= WS_EX_DLGMODALFRAME
;
180 AdjustWindowRectEx( rect
, style
& style_mask
, FALSE
, ex_style
& ex_style_mask
);
184 /***********************************************************************
185 * get_window_attributes
187 * Fill the window attributes structure for an X window.
189 static int get_window_attributes( Display
*display
, struct x11drv_win_data
*data
,
190 XSetWindowAttributes
*attr
)
192 attr
->override_redirect
= !data
->managed
;
193 attr
->colormap
= X11DRV_PALETTE_PaletteXColormap
;
194 attr
->save_under
= ((GetClassLongW( data
->hwnd
, GCL_STYLE
) & CS_SAVEBITS
) != 0);
195 attr
->cursor
= x11drv_thread_data()->cursor
;
196 attr
->bit_gravity
= NorthWestGravity
;
197 attr
->backing_store
= NotUseful
;
198 attr
->event_mask
= (ExposureMask
| PointerMotionMask
|
199 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
|
200 KeyPressMask
| KeyReleaseMask
| FocusChangeMask
| KeymapStateMask
);
201 if (data
->managed
) attr
->event_mask
|= StructureNotifyMask
;
203 return (CWOverrideRedirect
| CWSaveUnder
| CWColormap
| CWCursor
|
204 CWEventMask
| CWBitGravity
| CWBackingStore
);
208 /***********************************************************************
209 * X11DRV_sync_window_style
211 * Change the X window attributes when the window style has changed.
213 void X11DRV_sync_window_style( Display
*display
, struct x11drv_win_data
*data
)
215 if (data
->whole_window
!= root_window
)
217 XSetWindowAttributes attr
;
218 int mask
= get_window_attributes( display
, data
, &attr
);
221 XChangeWindowAttributes( display
, data
->whole_window
, mask
, &attr
);
227 /***********************************************************************
230 * Update the X11 window region.
232 static void sync_window_region( Display
*display
, struct x11drv_win_data
*data
, HRGN hrgn
)
234 #ifdef HAVE_LIBXSHAPE
235 if (!data
->whole_window
) return;
240 XShapeCombineMask( display
, data
->whole_window
, ShapeBounding
, 0, 0, None
, ShapeSet
);
245 RGNDATA
*pRegionData
= X11DRV_GetRegionData( hrgn
, 0 );
249 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
250 data
->window_rect
.left
- data
->whole_rect
.left
,
251 data
->window_rect
.top
- data
->whole_rect
.top
,
252 (XRectangle
*)pRegionData
->Buffer
,
253 pRegionData
->rdh
.nCount
, ShapeSet
, YXBanded
);
255 HeapFree(GetProcessHeap(), 0, pRegionData
);
258 #endif /* HAVE_LIBXSHAPE */
262 /***********************************************************************
265 static void sync_window_text( Display
*display
, Window win
, const WCHAR
*text
)
268 char *buffer
, *utf8_buffer
;
271 /* allocate new buffer for window text */
272 count
= WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, NULL
, 0, NULL
, NULL
);
273 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, count
))) return;
274 WideCharToMultiByte(CP_UNIXCP
, 0, text
, -1, buffer
, count
, NULL
, NULL
);
276 count
= WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), NULL
, 0, NULL
, NULL
);
277 if (!(utf8_buffer
= HeapAlloc( GetProcessHeap(), 0, count
)))
279 HeapFree( GetProcessHeap(), 0, buffer
);
282 WideCharToMultiByte(CP_UTF8
, 0, text
, strlenW(text
), utf8_buffer
, count
, NULL
, NULL
);
285 if (XmbTextListToTextProperty( display
, &buffer
, 1, XStdICCTextStyle
, &prop
) == Success
)
287 XSetWMName( display
, win
, &prop
);
288 XSetWMIconName( display
, win
, &prop
);
292 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
293 according to the standard
294 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
296 XChangeProperty( display
, win
, x11drv_atom(_NET_WM_NAME
), x11drv_atom(UTF8_STRING
),
297 8, PropModeReplace
, (unsigned char *) utf8_buffer
, count
);
300 HeapFree( GetProcessHeap(), 0, utf8_buffer
);
301 HeapFree( GetProcessHeap(), 0, buffer
);
305 /***********************************************************************
306 * X11DRV_set_win_format
308 BOOL
X11DRV_set_win_format( HWND hwnd
, XID fbconfig_id
)
310 Display
*display
= thread_display();
311 struct x11drv_win_data
*data
;
317 if (!(data
= X11DRV_get_win_data(hwnd
))) return FALSE
;
321 vis
= visual_from_fbconfig_id(fbconfig_id
);
328 if(data
->whole_window
&& vis
->visualid
== XVisualIDFromVisual(visual
))
330 TRACE("Whole window available and visual match, rendering onscreen\n");
336 parent
= data
->whole_window
;
340 next_hwnd
= GetAncestor(next_hwnd
, GA_PARENT
);
343 ERR("Could not find parent HWND with a drawable!\n");
346 parent
= X11DRV_get_whole_window(next_hwnd
);
349 w
= data
->client_rect
.right
- data
->client_rect
.left
;
350 h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
356 #ifdef SONAME_LIBXCOMPOSITE
359 XSetWindowAttributes attrib
;
361 attrib
.override_redirect
= True
;
362 attrib
.colormap
= XCreateColormap(display
, parent
, vis
->visual
,
363 (vis
->class == PseudoColor
||
364 vis
->class == GrayScale
||
365 vis
->class == DirectColor
) ?
366 AllocAll
: AllocNone
);
367 XInstallColormap(gdi_display
, attrib
.colormap
);
369 data
->gl_drawable
= XCreateWindow(display
, parent
, -w
, 0, w
, h
, 0,
370 vis
->depth
, InputOutput
, vis
->visual
,
371 CWColormap
| CWOverrideRedirect
,
373 if(data
->gl_drawable
)
375 pXCompositeRedirectWindow(display
, data
->gl_drawable
,
376 CompositeRedirectManual
);
377 XMapWindow(display
, data
->gl_drawable
);
383 WARN("XComposite is not available, using GLXPixmap hack\n");
385 data
->pixmap
= XCreatePixmap(display
, parent
, w
, h
, vis
->depth
);
388 ERR("Failed to create pixmap for offscreen rendering\n");
394 data
->gl_drawable
= create_glxpixmap(display
, vis
, data
->pixmap
);
395 if(!data
->gl_drawable
)
397 XFreePixmap(display
, data
->pixmap
);
402 if(!data
->gl_drawable
)
404 ERR("Failed to create drawable for offscreen rendering\n");
416 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
417 data
->gl_drawable
, fbconfig_id
);
419 data
->fbconfig_id
= fbconfig_id
;
420 SetPropA(hwnd
, fbconfig_id_prop
, (HANDLE
)data
->fbconfig_id
);
421 SetPropA(hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
422 SetPropA(hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
423 invalidate_dce( hwnd
, &data
->window_rect
);
427 /***********************************************************************
428 * X11DRV_sync_gl_drawable
430 void X11DRV_sync_gl_drawable(Display
*display
, struct x11drv_win_data
*data
)
432 int w
= data
->client_rect
.right
- data
->client_rect
.left
;
433 int h
= data
->client_rect
.bottom
- data
->client_rect
.top
;
440 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data
->gl_drawable
, w
, h
);
441 #ifdef SONAME_LIBXCOMPOSITE
445 XMoveResizeWindow(display
, data
->gl_drawable
, -w
, 0, w
, h
);
451 parent
= data
->whole_window
;
452 next_hwnd
= data
->hwnd
;
455 next_hwnd
= GetAncestor(next_hwnd
, GA_PARENT
);
458 ERR("Could not find parent HWND with a drawable!\n");
461 parent
= X11DRV_get_whole_window(next_hwnd
);
466 vis
= visual_from_fbconfig_id(data
->fbconfig_id
);
473 pix
= XCreatePixmap(display
, parent
, w
, h
, vis
->depth
);
476 ERR("Failed to create pixmap for offscreen rendering\n");
482 glxp
= create_glxpixmap(display
, vis
, pix
);
485 ERR("Failed to create drawable for offscreen rendering\n");
486 XFreePixmap(display
, pix
);
494 mark_drawable_dirty(data
->gl_drawable
, glxp
);
496 XFreePixmap(display
, data
->pixmap
);
497 destroy_glxpixmap(display
, data
->gl_drawable
);
500 data
->gl_drawable
= glxp
;
505 SetPropA(data
->hwnd
, gl_drawable_prop
, (HANDLE
)data
->gl_drawable
);
506 SetPropA(data
->hwnd
, pixmap_prop
, (HANDLE
)data
->pixmap
);
507 invalidate_dce( data
->hwnd
, &data
->window_rect
);
511 /***********************************************************************
514 * fill the window changes structure
516 static int get_window_changes( XWindowChanges
*changes
, const RECT
*old
, const RECT
*new )
520 if (old
->right
- old
->left
!= new->right
- new->left
)
522 if (!(changes
->width
= new->right
- new->left
)) changes
->width
= 1;
525 if (old
->bottom
- old
->top
!= new->bottom
- new->top
)
527 if (!(changes
->height
= new->bottom
- new->top
)) changes
->height
= 1;
530 if (old
->left
!= new->left
)
532 changes
->x
= new->left
;
535 if (old
->top
!= new->top
)
537 changes
->y
= new->top
;
544 /***********************************************************************
547 static Window
create_icon_window( Display
*display
, struct x11drv_win_data
*data
)
549 XSetWindowAttributes attr
;
551 attr
.event_mask
= (ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
|
552 ButtonPressMask
| ButtonReleaseMask
| EnterWindowMask
);
553 attr
.bit_gravity
= NorthWestGravity
;
554 attr
.backing_store
= NotUseful
/*WhenMapped*/;
555 attr
.colormap
= X11DRV_PALETTE_PaletteXColormap
; /* Needed due to our visual */
558 data
->icon_window
= XCreateWindow( display
, root_window
, 0, 0,
559 GetSystemMetrics( SM_CXICON
),
560 GetSystemMetrics( SM_CYICON
),
563 CWEventMask
| CWBitGravity
| CWBackingStore
| CWColormap
, &attr
);
564 XSaveContext( display
, data
->icon_window
, winContext
, (char *)data
->hwnd
);
567 TRACE( "created %lx\n", data
->icon_window
);
568 SetPropA( data
->hwnd
, icon_window_prop
, (HANDLE
)data
->icon_window
);
569 return data
->icon_window
;
574 /***********************************************************************
575 * destroy_icon_window
577 static void destroy_icon_window( Display
*display
, struct x11drv_win_data
*data
)
579 if (!data
->icon_window
) return;
580 if (x11drv_thread_data()->cursor_window
== data
->icon_window
)
581 x11drv_thread_data()->cursor_window
= None
;
583 XDeleteContext( display
, data
->icon_window
, winContext
);
584 XDestroyWindow( display
, data
->icon_window
);
585 data
->icon_window
= 0;
587 RemovePropA( data
->hwnd
, icon_window_prop
);
591 /***********************************************************************
594 * Set the icon wm hints
596 static void set_icon_hints( Display
*display
, struct x11drv_win_data
*data
, HICON hIcon
)
598 XWMHints
*hints
= data
->wm_hints
;
600 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
601 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
602 data
->hWMIconBitmap
= 0;
603 data
->hWMIconMask
= 0;
607 if (!data
->icon_window
) create_icon_window( display
, data
);
608 hints
->icon_window
= data
->icon_window
;
609 hints
->flags
= (hints
->flags
& ~(IconPixmapHint
| IconMaskHint
)) | IconWindowHint
;
619 GetIconInfo(hIcon
, &ii
);
621 GetObjectA(ii
.hbmMask
, sizeof(bmMask
), &bmMask
);
624 rcMask
.right
= bmMask
.bmWidth
;
625 rcMask
.bottom
= bmMask
.bmHeight
;
627 hDC
= CreateCompatibleDC(0);
628 hbmOrig
= SelectObject(hDC
, ii
.hbmMask
);
629 InvertRect(hDC
, &rcMask
);
630 SelectObject(hDC
, ii
.hbmColor
); /* force the color bitmap to x11drv mode too */
631 SelectObject(hDC
, hbmOrig
);
634 data
->hWMIconBitmap
= ii
.hbmColor
;
635 data
->hWMIconMask
= ii
.hbmMask
;
637 hints
->icon_pixmap
= X11DRV_get_pixmap(data
->hWMIconBitmap
);
638 hints
->icon_mask
= X11DRV_get_pixmap(data
->hWMIconMask
);
639 destroy_icon_window( display
, data
);
640 hints
->flags
= (hints
->flags
& ~IconWindowHint
) | IconPixmapHint
| IconMaskHint
;
644 /***********************************************************************
645 * systray_dock_window
647 * Docks the given X window with the NETWM system tray.
649 static void systray_dock_window( Display
*display
, struct x11drv_win_data
*data
)
651 static Atom systray_atom
;
652 Window systray_window
;
657 if (DefaultScreen( display
) == 0)
658 systray_atom
= x11drv_atom(_NET_SYSTEM_TRAY_S0
);
661 char systray_buffer
[29]; /* strlen(_NET_SYSTEM_TRAY_S4294967295)+1 */
662 sprintf( systray_buffer
, "_NET_SYSTEM_TRAY_S%u", DefaultScreen( display
) );
663 systray_atom
= XInternAtom( display
, systray_buffer
, False
);
666 systray_window
= XGetSelectionOwner( display
, systray_atom
);
669 TRACE("Docking tray icon %p\n", data
->hwnd
);
671 if (systray_window
!= None
)
674 unsigned long info
[2];
676 /* Put the window offscreen so it isn't mapped. The window _cannot_ be
677 * mapped if we intend to dock with an XEMBED tray. If the window is
678 * mapped when we dock, it may become visible as a child of the root
679 * window after it docks, which isn't the proper behavior.
681 * For more information on this problem, see
682 * http://standards.freedesktop.org/xembed-spec/latest/ar01s04.html */
684 SetWindowPos( data
->hwnd
, NULL
, virtual_screen_rect
.right
+ 1, virtual_screen_rect
.bottom
+ 1,
685 0, 0, SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
687 /* set XEMBED protocol data on the window */
688 info
[0] = 0; /* protocol version */
689 info
[1] = 1; /* mapped = true */
692 XChangeProperty( display
, data
->whole_window
,
693 x11drv_atom(_XEMBED_INFO
),
694 x11drv_atom(_XEMBED_INFO
), 32, PropModeReplace
,
695 (unsigned char*)info
, 2 );
698 /* send the docking request message */
699 ZeroMemory( &ev
, sizeof(ev
) );
700 ev
.xclient
.type
= ClientMessage
;
701 ev
.xclient
.window
= systray_window
;
702 ev
.xclient
.message_type
= x11drv_atom( _NET_SYSTEM_TRAY_OPCODE
);
703 ev
.xclient
.format
= 32;
704 ev
.xclient
.data
.l
[0] = CurrentTime
;
705 ev
.xclient
.data
.l
[1] = SYSTEM_TRAY_REQUEST_DOCK
;
706 ev
.xclient
.data
.l
[2] = data
->whole_window
;
707 ev
.xclient
.data
.l
[3] = 0;
708 ev
.xclient
.data
.l
[4] = 0;
711 XSendEvent( display
, systray_window
, False
, NoEventMask
, &ev
);
719 /* fall back to he KDE hints if the WM doesn't support XEMBED'ed
723 XChangeProperty( display
, data
->whole_window
,
724 x11drv_atom(KWM_DOCKWINDOW
),
725 x11drv_atom(KWM_DOCKWINDOW
), 32, PropModeReplace
,
726 (unsigned char*)&val
, 1 );
727 XChangeProperty( display
, data
->whole_window
,
728 x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR
),
729 XA_WINDOW
, 32, PropModeReplace
,
730 (unsigned char*)&data
->whole_window
, 1 );
736 /***********************************************************************
739 * set the window size hints
741 static void set_size_hints( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
743 XSizeHints
* size_hints
;
745 if ((size_hints
= XAllocSizeHints()))
747 size_hints
->flags
= 0;
749 if (data
->hwnd
!= GetDesktopWindow()) /* don't force position of desktop */
751 size_hints
->win_gravity
= StaticGravity
;
752 size_hints
->x
= data
->whole_rect
.left
;
753 size_hints
->y
= data
->whole_rect
.top
;
754 size_hints
->flags
|= PWinGravity
| PPosition
;
757 if ( !(style
& WS_THICKFRAME
) )
759 size_hints
->max_width
= data
->whole_rect
.right
- data
->whole_rect
.left
;
760 size_hints
->max_height
= data
->whole_rect
.bottom
- data
->whole_rect
.top
;
761 size_hints
->min_width
= size_hints
->max_width
;
762 size_hints
->min_height
= size_hints
->max_height
;
763 size_hints
->flags
|= PMinSize
| PMaxSize
;
765 XSetWMNormalHints( display
, data
->whole_window
, size_hints
);
771 /***********************************************************************
774 * get the name of the current process for setting class hints
776 static char *get_process_name(void)
782 WCHAR module
[MAX_PATH
];
783 DWORD len
= GetModuleFileNameW( 0, module
, MAX_PATH
);
784 if (len
&& len
< MAX_PATH
)
787 WCHAR
*p
, *appname
= module
;
789 if ((p
= strrchrW( appname
, '/' ))) appname
= p
+ 1;
790 if ((p
= strrchrW( appname
, '\\' ))) appname
= p
+ 1;
791 len
= WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, NULL
, 0, NULL
, NULL
);
792 if ((ptr
= HeapAlloc( GetProcessHeap(), 0, len
)))
794 WideCharToMultiByte( CP_UNIXCP
, 0, appname
, -1, ptr
, len
, NULL
, NULL
);
803 /***********************************************************************
804 * set_initial_wm_hints
806 * Set the window manager hints that don't change over the lifetime of a window.
808 static void set_initial_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
813 XClassHint
*class_hints
;
814 char *process_name
= get_process_name();
820 protocols
[i
++] = x11drv_atom(WM_DELETE_WINDOW
);
821 protocols
[i
++] = x11drv_atom(_NET_WM_PING
);
822 if (use_take_focus
) protocols
[i
++] = x11drv_atom(WM_TAKE_FOCUS
);
823 XChangeProperty( display
, data
->whole_window
, x11drv_atom(WM_PROTOCOLS
),
824 XA_ATOM
, 32, PropModeReplace
, (unsigned char *)protocols
, i
);
827 if ((class_hints
= XAllocClassHint()))
829 static char wine
[] = "Wine";
831 class_hints
->res_name
= process_name
;
832 class_hints
->res_class
= wine
;
833 XSetClassHint( display
, data
->whole_window
, class_hints
);
834 XFree( class_hints
);
837 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
838 XSetWMProperties(display
, data
->whole_window
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, NULL
);
839 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
841 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_PID
),
842 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *)&i
, 1);
844 XChangeProperty( display
, data
->whole_window
, x11drv_atom(XdndAware
),
845 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&dndVersion
, 1 );
847 data
->wm_hints
= XAllocWMHints();
852 HICON icon
= (HICON
)SendMessageW( data
->hwnd
, WM_GETICON
, ICON_BIG
, 0 );
853 if (!icon
) icon
= (HICON
)GetClassLongPtrW( data
->hwnd
, GCLP_HICON
);
854 data
->wm_hints
->flags
= 0;
855 set_icon_hints( display
, data
, icon
);
860 /***********************************************************************
861 * X11DRV_set_wm_hints
863 * Set the window manager hints for a newly-created window
865 void X11DRV_set_wm_hints( Display
*display
, struct x11drv_win_data
*data
)
870 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
871 DWORD ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
872 HWND owner
= GetWindow( data
->hwnd
, GW_OWNER
);
874 if (data
->hwnd
== GetDesktopWindow())
876 if (data
->whole_window
== DefaultRootWindow(display
)) return;
877 /* force some styles for the desktop to get the correct decorations */
878 style
|= WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
882 /* transient for hint */
885 Window owner_win
= X11DRV_get_whole_window( owner
);
887 XSetTransientForHint( display
, data
->whole_window
, owner_win
);
889 group_leader
= owner_win
;
891 else group_leader
= data
->whole_window
;
896 set_size_hints( display
, data
, style
);
898 /* set the WM_WINDOW_TYPE */
899 window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
900 if (ex_style
& WS_EX_TOOLWINDOW
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY
);
901 else if (style
& WS_THICKFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL
);
902 else if (style
& WS_DLGFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
903 else if (ex_style
& WS_EX_DLGMODALFRAME
) window_type
= x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG
);
905 XChangeProperty(display
, data
->whole_window
, x11drv_atom(_NET_WM_WINDOW_TYPE
),
906 XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&window_type
, 1);
908 mwm_hints
.flags
= MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
909 mwm_hints
.decorations
= get_mwm_decorations( style
, ex_style
);
910 mwm_hints
.functions
= MWM_FUNC_MOVE
;
911 if (style
& WS_THICKFRAME
) mwm_hints
.functions
|= MWM_FUNC_RESIZE
;
912 if (style
& WS_MINIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MINIMIZE
;
913 if (style
& WS_MAXIMIZEBOX
) mwm_hints
.functions
|= MWM_FUNC_MAXIMIZE
;
914 if (style
& WS_SYSMENU
) mwm_hints
.functions
|= MWM_FUNC_CLOSE
;
916 XChangeProperty( display
, data
->whole_window
, x11drv_atom(_MOTIF_WM_HINTS
),
917 x11drv_atom(_MOTIF_WM_HINTS
), 32, PropModeReplace
,
918 (unsigned char*)&mwm_hints
, sizeof(mwm_hints
)/sizeof(long) );
923 data
->wm_hints
->flags
|= InputHint
| StateHint
| WindowGroupHint
;
924 data
->wm_hints
->input
= !(style
& WS_DISABLED
);
925 data
->wm_hints
->initial_state
= (style
& WS_MINIMIZE
) ? IconicState
: NormalState
;
926 data
->wm_hints
->window_group
= group_leader
;
927 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
934 /***********************************************************************
935 * X11DRV_set_iconic_state
937 * Set the X11 iconic state according to the window style.
939 void X11DRV_set_iconic_state( HWND hwnd
)
941 Display
*display
= thread_display();
942 struct x11drv_win_data
*data
;
944 DWORD style
= GetWindowLongW( hwnd
, GWL_STYLE
);
945 BOOL iconic
= (style
& WS_MINIMIZE
) != 0;
947 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
948 if (!data
->whole_window
|| data
->whole_window
== DefaultRootWindow(display
)) return;
950 GetWindowRect( hwnd
, &rect
);
956 data
->wm_hints
->flags
|= StateHint
| IconPositionHint
;
957 data
->wm_hints
->initial_state
= iconic
? IconicState
: NormalState
;
958 data
->wm_hints
->icon_x
= rect
.left
- virtual_screen_rect
.left
;
959 data
->wm_hints
->icon_y
= rect
.top
- virtual_screen_rect
.top
;
960 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
966 XIconifyWindow( display
, data
->whole_window
, DefaultScreen(display
) );
968 if (X11DRV_is_window_rect_mapped( &rect
))
969 XMapWindow( display
, data
->whole_window
);
976 /***********************************************************************
977 * X11DRV_window_to_X_rect
979 * Convert a rect from client to X window coordinates
981 void X11DRV_window_to_X_rect( struct x11drv_win_data
*data
, RECT
*rect
)
985 if (!data
->managed
) return;
986 if (IsRectEmpty( rect
)) return;
988 get_x11_rect_offset( data
, &rc
);
990 rect
->left
-= rc
.left
;
991 rect
->right
-= rc
.right
;
993 rect
->bottom
-= rc
.bottom
;
994 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
995 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
999 /***********************************************************************
1000 * X11DRV_X_to_window_rect
1002 * Opposite of X11DRV_window_to_X_rect
1004 void X11DRV_X_to_window_rect( struct x11drv_win_data
*data
, RECT
*rect
)
1008 if (!data
->managed
) return;
1009 if (IsRectEmpty( rect
)) return;
1011 get_x11_rect_offset( data
, &rc
);
1013 rect
->left
+= rc
.left
;
1014 rect
->right
+= rc
.right
;
1015 rect
->top
+= rc
.top
;
1016 rect
->bottom
+= rc
.bottom
;
1017 if (rect
->top
>= rect
->bottom
) rect
->bottom
= rect
->top
+ 1;
1018 if (rect
->left
>= rect
->right
) rect
->right
= rect
->left
+ 1;
1022 /***********************************************************************
1023 * X11DRV_sync_window_position
1025 * Synchronize the X window position with the Windows one
1027 void X11DRV_sync_window_position( Display
*display
, struct x11drv_win_data
*data
,
1028 UINT swp_flags
, const RECT
*old_client_rect
,
1029 const RECT
*old_whole_rect
)
1031 XWindowChanges changes
;
1032 int mask
= get_window_changes( &changes
, old_whole_rect
, &data
->whole_rect
);
1034 if (!(swp_flags
& SWP_NOZORDER
))
1036 /* find window that this one must be after */
1037 HWND prev
= GetWindow( data
->hwnd
, GW_HWNDPREV
);
1038 while (prev
&& !(GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
))
1039 prev
= GetWindow( prev
, GW_HWNDPREV
);
1040 if (!prev
) /* top child */
1042 changes
.stack_mode
= Above
;
1043 mask
|= CWStackMode
;
1047 /* should use stack_mode Below but most window managers don't get it right */
1048 /* so move it above the next one in Z order */
1049 HWND next
= GetWindow( data
->hwnd
, GW_HWNDNEXT
);
1050 while (next
&& !(GetWindowLongW( next
, GWL_STYLE
) & WS_VISIBLE
))
1051 next
= GetWindow( next
, GW_HWNDNEXT
);
1054 changes
.stack_mode
= Above
;
1055 changes
.sibling
= X11DRV_get_whole_window(next
);
1056 mask
|= CWStackMode
| CWSibling
;
1061 /* only the size is allowed to change for the desktop window */
1062 if (data
->whole_window
== root_window
) mask
&= CWWidth
| CWHeight
;
1066 DWORD style
= GetWindowLongW( data
->hwnd
, GWL_STYLE
);
1068 TRACE( "setting win %lx pos %d,%d,%dx%d after %lx changes=%x\n",
1069 data
->whole_window
, data
->whole_rect
.left
, data
->whole_rect
.top
,
1070 data
->whole_rect
.right
- data
->whole_rect
.left
,
1071 data
->whole_rect
.bottom
- data
->whole_rect
.top
, changes
.sibling
, mask
);
1074 if (mask
& (CWWidth
|CWHeight
)) set_size_hints( display
, data
, style
);
1075 if (mask
& CWX
) changes
.x
-= virtual_screen_rect
.left
;
1076 if (mask
& CWY
) changes
.y
-= virtual_screen_rect
.top
;
1077 XReconfigureWMWindow( display
, data
->whole_window
,
1078 DefaultScreen(display
), mask
, &changes
);
1079 wine_tsx11_unlock();
1084 /**********************************************************************
1085 * create_whole_window
1087 * Create the whole X window for a given window
1089 static Window
create_whole_window( Display
*display
, struct x11drv_win_data
*data
, DWORD style
)
1092 XSetWindowAttributes attr
;
1097 if (!(cx
= data
->window_rect
.right
- data
->window_rect
.left
)) cx
= 1;
1098 if (!(cy
= data
->window_rect
.bottom
- data
->window_rect
.top
)) cy
= 1;
1100 mask
= get_window_attributes( display
, data
, &attr
);
1104 data
->whole_rect
= data
->window_rect
;
1105 data
->whole_window
= XCreateWindow( display
, root_window
,
1106 data
->window_rect
.left
- virtual_screen_rect
.left
,
1107 data
->window_rect
.top
- virtual_screen_rect
.top
,
1108 cx
, cy
, 0, screen_depth
, InputOutput
,
1109 visual
, mask
, &attr
);
1111 if (!data
->whole_window
)
1113 wine_tsx11_unlock();
1116 XSaveContext( display
, data
->whole_window
, winContext
, (char *)data
->hwnd
);
1118 /* non-maximized child must be at bottom of Z order */
1119 if ((style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
1121 XWindowChanges changes
;
1122 changes
.stack_mode
= Below
;
1123 XConfigureWindow( display
, data
->whole_window
, CWStackMode
, &changes
);
1125 wine_tsx11_unlock();
1127 xim
= x11drv_thread_data()->xim
;
1128 if (xim
) data
->xic
= X11DRV_CreateIC( xim
, display
, data
->whole_window
);
1130 set_initial_wm_hints( display
, data
);
1131 X11DRV_set_wm_hints( display
, data
);
1133 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)data
->whole_window
);
1135 /* set the window text */
1136 if (!InternalGetWindowText( data
->hwnd
, text
, sizeof(text
)/sizeof(WCHAR
) )) text
[0] = 0;
1137 sync_window_text( display
, data
->whole_window
, text
);
1139 /* set the window region */
1140 if ((hrgn
= CreateRectRgn( 0, 0, 0, 0 )))
1142 if (GetWindowRgn( data
->hwnd
, hrgn
) != ERROR
) sync_window_region( display
, data
, hrgn
);
1143 DeleteObject( hrgn
);
1145 return data
->whole_window
;
1149 /**********************************************************************
1150 * destroy_whole_window
1152 * Destroy the whole X window for a given window.
1154 static void destroy_whole_window( Display
*display
, struct x11drv_win_data
*data
)
1156 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1158 if (!data
->whole_window
) return;
1160 TRACE( "win %p xwin %lx\n", data
->hwnd
, data
->whole_window
);
1161 if (thread_data
->cursor_window
== data
->whole_window
) thread_data
->cursor_window
= None
;
1163 XDeleteContext( display
, data
->whole_window
, winContext
);
1164 if (data
->whole_window
!= DefaultRootWindow(display
))
1165 XDestroyWindow( display
, data
->whole_window
);
1166 data
->whole_window
= 0;
1169 XUnsetICFocus( data
->xic
);
1170 XDestroyIC( data
->xic
);
1172 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1174 XFree( data
->wm_hints
);
1175 data
->wm_hints
= NULL
;
1176 wine_tsx11_unlock();
1177 RemovePropA( data
->hwnd
, whole_window_prop
);
1181 /*****************************************************************
1182 * SetWindowText (X11DRV.@)
1184 void X11DRV_SetWindowText( HWND hwnd
, LPCWSTR text
)
1186 Display
*display
= thread_display();
1189 if ((win
= X11DRV_get_whole_window( hwnd
)) && win
!= DefaultRootWindow(display
))
1190 sync_window_text( display
, win
, text
);
1194 /***********************************************************************
1195 * DestroyWindow (X11DRV.@)
1197 void X11DRV_DestroyWindow( HWND hwnd
)
1199 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1200 Display
*display
= thread_data
->display
;
1201 struct x11drv_win_data
*data
;
1203 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1207 destroy_glxpixmap(display
, data
->gl_drawable
);
1209 XFreePixmap(display
, data
->pixmap
);
1210 wine_tsx11_unlock();
1212 else if (data
->gl_drawable
)
1215 XDestroyWindow(display
, data
->gl_drawable
);
1216 wine_tsx11_unlock();
1219 free_window_dce( data
);
1220 destroy_whole_window( display
, data
);
1221 destroy_icon_window( display
, data
);
1223 if (thread_data
->last_focus
== hwnd
) thread_data
->last_focus
= 0;
1224 if (data
->hWMIconBitmap
) DeleteObject( data
->hWMIconBitmap
);
1225 if (data
->hWMIconMask
) DeleteObject( data
->hWMIconMask
);
1227 XDeleteContext( display
, (XID
)hwnd
, win_data_context
);
1228 wine_tsx11_unlock();
1229 HeapFree( GetProcessHeap(), 0, data
);
1233 static struct x11drv_win_data
*alloc_win_data( Display
*display
, HWND hwnd
)
1235 struct x11drv_win_data
*data
;
1237 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
1241 if (!winContext
) winContext
= XUniqueContext();
1242 if (!win_data_context
) win_data_context
= XUniqueContext();
1243 XSaveContext( display
, (XID
)hwnd
, win_data_context
, (char *)data
);
1244 wine_tsx11_unlock();
1250 /* initialize the desktop window id in the desktop manager process */
1251 static void get_desktop_xwin( Display
*display
, struct x11drv_win_data
*data
)
1253 data
->whole_window
= root_window
;
1254 if (root_window
!= DefaultRootWindow( display
))
1259 visualid
= XVisualIDFromVisual(visual
);
1260 wine_tsx11_unlock();
1261 data
->managed
= TRUE
;
1262 SetPropA( data
->hwnd
, managed_prop
, (HANDLE
)1 );
1263 SetPropA( data
->hwnd
, whole_window_prop
, (HANDLE
)root_window
);
1264 SetPropA( data
->hwnd
, visual_id_prop
, (HANDLE
)visualid
);
1265 set_initial_wm_hints( display
, data
);
1269 /**********************************************************************
1270 * CreateDesktopWindow (X11DRV.@)
1272 BOOL
X11DRV_CreateDesktopWindow( HWND hwnd
)
1274 unsigned int width
, height
;
1276 /* retrieve the real size of the desktop */
1277 SERVER_START_REQ( get_window_rectangles
)
1280 wine_server_call( req
);
1281 width
= reply
->window
.right
- reply
->window
.left
;
1282 height
= reply
->window
.bottom
- reply
->window
.top
;
1286 if (!width
&& !height
) /* not initialized yet */
1288 SERVER_START_REQ( set_window_pos
)
1292 req
->flags
= SWP_NOZORDER
;
1293 req
->window
.left
= virtual_screen_rect
.left
;
1294 req
->window
.top
= virtual_screen_rect
.top
;
1295 req
->window
.right
= virtual_screen_rect
.right
;
1296 req
->window
.bottom
= virtual_screen_rect
.bottom
;
1297 req
->client
= req
->window
;
1298 wine_server_call( req
);
1304 Window win
= (Window
)GetPropA( hwnd
, whole_window_prop
);
1305 if (win
&& win
!= root_window
) X11DRV_init_desktop( win
, width
, height
);
1311 /**********************************************************************
1312 * CreateWindow (X11DRV.@)
1314 BOOL
X11DRV_CreateWindow( HWND hwnd
, CREATESTRUCTA
*cs
, BOOL unicode
)
1316 Display
*display
= thread_display();
1318 struct x11drv_win_data
*data
;
1322 CBT_CREATEWNDA cbtc
;
1325 INT cx
= cs
->cx
, cy
= cs
->cy
;
1327 if (!(data
= alloc_win_data( display
, hwnd
))) return FALSE
;
1329 if (hwnd
== GetDesktopWindow()) get_desktop_xwin( display
, data
);
1332 /* create an X window if it's a top level window */
1333 if (GetAncestor( hwnd
, GA_PARENT
) == GetDesktopWindow())
1335 if (!create_whole_window( display
, data
, cs
->style
)) goto failed
;
1339 /* get class or window DC if needed */
1340 alloc_window_dce( data
);
1342 /* Call the WH_CBT hook */
1344 /* the window style passed to the hook must be the real window style,
1345 * rather than just the window style that the caller to CreateWindowEx
1346 * passed in, so we have to copy the original CREATESTRUCT and get the
1347 * the real style. */
1349 cbcs
.style
= GetWindowLongW(hwnd
, GWL_STYLE
);
1352 cbtc
.hwndInsertAfter
= HWND_TOP
;
1353 if (HOOK_CallHooks( WH_CBT
, HCBT_CREATEWND
, (WPARAM
)hwnd
, (LPARAM
)&cbtc
, unicode
))
1355 TRACE("CBT-hook returned !0\n");
1359 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
1360 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
1362 POINT maxSize
, maxPos
, minTrack
, maxTrack
;
1364 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, &maxPos
, &minTrack
, &maxTrack
);
1365 if (maxTrack
.x
< cx
) cx
= maxTrack
.x
;
1366 if (maxTrack
.y
< cy
) cy
= maxTrack
.y
;
1371 SetRect( &rect
, cs
->x
, cs
->y
, cs
->x
+ cx
, cs
->y
+ cy
);
1372 if (!X11DRV_SetWindowPos( hwnd
, 0, &rect
, &rect
, SWP_NOZORDER
| SWP_NOACTIVATE
, NULL
))
1375 /* send WM_NCCREATE */
1376 TRACE( "hwnd %p cs %d,%d %dx%d\n", hwnd
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1378 ret
= SendMessageW( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1380 ret
= SendMessageA( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1383 WARN("aborted by WM_xxCREATE!\n");
1387 /* make sure the window is still valid */
1388 if (!(data
= X11DRV_get_win_data( hwnd
))) return FALSE
;
1389 if (data
->whole_window
) X11DRV_sync_window_style( display
, data
);
1391 /* send WM_NCCALCSIZE */
1392 rect
= data
->window_rect
;
1393 SendMessageW( hwnd
, WM_NCCALCSIZE
, FALSE
, (LPARAM
)&rect
);
1395 if (!(wndPtr
= WIN_GetPtr(hwnd
))) return FALSE
;
1397 /* yes, even if the CBT hook was called with HWND_TOP */
1398 insert_after
= (wndPtr
->dwStyle
& WS_CHILD
) ? HWND_BOTTOM
: HWND_TOP
;
1400 X11DRV_SetWindowPos( hwnd
, insert_after
, &wndPtr
->rectWindow
, &rect
, SWP_NOACTIVATE
, NULL
);
1402 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",
1403 hwnd
, wndPtr
->rectWindow
.left
, wndPtr
->rectWindow
.top
,
1404 wndPtr
->rectWindow
.right
, wndPtr
->rectWindow
.bottom
,
1405 wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
,
1406 wndPtr
->rectClient
.right
, wndPtr
->rectClient
.bottom
,
1407 data
->whole_rect
.left
, data
->whole_rect
.top
,
1408 data
->whole_rect
.right
, data
->whole_rect
.bottom
,
1409 data
->client_rect
.left
, data
->client_rect
.top
,
1410 data
->client_rect
.right
, data
->client_rect
.bottom
,
1411 (unsigned int)data
->whole_window
);
1413 WIN_ReleasePtr( wndPtr
);
1416 ret
= (SendMessageW( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
) != -1);
1418 ret
= (SendMessageA( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
) != -1);
1420 if (!ret
) return FALSE
;
1422 NotifyWinEvent(EVENT_OBJECT_CREATE
, hwnd
, OBJID_WINDOW
, 0);
1424 /* Send the size messages */
1426 if (!(wndPtr
= WIN_GetPtr(hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return FALSE
;
1427 if (!(wndPtr
->flags
& WIN_NEED_SIZE
))
1429 RECT rect
= wndPtr
->rectClient
;
1430 WIN_ReleasePtr( wndPtr
);
1431 /* send it anyway */
1432 if (((rect
.right
-rect
.left
) <0) ||((rect
.bottom
-rect
.top
)<0))
1433 WARN("sending bogus WM_SIZE message 0x%08x\n",
1434 MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
));
1435 SendMessageW( hwnd
, WM_SIZE
, SIZE_RESTORED
,
1436 MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
));
1437 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( rect
.left
, rect
.top
) );
1439 else WIN_ReleasePtr( wndPtr
);
1441 /* Show the window, maximizing or minimizing if needed */
1443 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1444 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1446 extern UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
); /*FIXME*/
1449 UINT swFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
1450 WIN_SetStyle( hwnd
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
1451 swFlag
= WINPOS_MinMaximize( hwnd
, swFlag
, &newPos
);
1453 swFlag
|= SWP_FRAMECHANGED
; /* Frame always gets changed */
1454 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || GetActiveWindow()) swFlag
|= SWP_NOACTIVATE
;
1456 SetWindowPos( hwnd
, 0, newPos
.left
, newPos
.top
,
1457 newPos
.right
, newPos
.bottom
, swFlag
);
1460 /* Dock system tray windows. */
1461 /* Dock after the window is created so we don't have problems calling
1463 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_TRAYWINDOW
)
1464 systray_dock_window( display
, data
);
1469 X11DRV_DestroyWindow( hwnd
);
1474 /***********************************************************************
1475 * X11DRV_get_win_data
1477 * Return the X11 data structure associated with a window.
1479 struct x11drv_win_data
*X11DRV_get_win_data( HWND hwnd
)
1483 if (!hwnd
|| XFindContext( thread_display(), (XID
)hwnd
, win_data_context
, &data
)) data
= NULL
;
1484 return (struct x11drv_win_data
*)data
;
1488 /***********************************************************************
1489 * X11DRV_get_whole_window
1491 * Return the X window associated with the full area of a window
1493 Window
X11DRV_get_whole_window( HWND hwnd
)
1495 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1499 if (hwnd
== GetDesktopWindow()) return root_window
;
1500 return (Window
)GetPropA( hwnd
, whole_window_prop
);
1502 return data
->whole_window
;
1506 /***********************************************************************
1507 * X11DRV_get_fbconfig_id
1509 * Return the GLXFBConfig ID of the drawable used by the window for
1510 * OpenGL rendering. This is 0 for windows without a pixel format set.
1512 XID
X11DRV_get_fbconfig_id( HWND hwnd
)
1514 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1516 if (!data
) return (XID
)GetPropA( hwnd
, fbconfig_id_prop
);
1517 return data
->fbconfig_id
;
1520 /***********************************************************************
1521 * X11DRV_get_gl_drawable
1523 * Return the GL drawable for this window.
1525 Drawable
X11DRV_get_gl_drawable( HWND hwnd
)
1527 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1529 if (!data
) return (Drawable
)GetPropA( hwnd
, gl_drawable_prop
);
1530 return data
->gl_drawable
;
1533 /***********************************************************************
1534 * X11DRV_get_gl_pixmap
1536 * Return the Pixmap associated with the GL drawable (if any) for this window.
1538 Pixmap
X11DRV_get_gl_pixmap( HWND hwnd
)
1540 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1542 if (!data
) return (Pixmap
)GetPropA( hwnd
, pixmap_prop
);
1543 return data
->pixmap
;
1547 /***********************************************************************
1550 * Return the X input context associated with a window
1552 XIC
X11DRV_get_ic( HWND hwnd
)
1554 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1556 if (!data
) return 0;
1561 /*****************************************************************
1562 * SetParent (X11DRV.@)
1564 void X11DRV_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
1566 Display
*display
= thread_display();
1567 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
1570 if (parent
== old_parent
) return;
1572 if (parent
!= GetDesktopWindow()) /* a child window */
1574 if (old_parent
== GetDesktopWindow())
1576 /* destroy the old X windows */
1577 destroy_whole_window( display
, data
);
1578 destroy_icon_window( display
, data
);
1581 data
->managed
= FALSE
;
1582 RemovePropA( data
->hwnd
, managed_prop
);
1586 else /* new top level window */
1588 /* FIXME: we ignore errors since we can't really recover anyway */
1589 create_whole_window( display
, data
, GetWindowLongW( hwnd
, GWL_STYLE
) );
1594 /*****************************************************************
1595 * SetFocus (X11DRV.@)
1598 * Explicit colormap management seems to work only with OLVWM.
1600 void X11DRV_SetFocus( HWND hwnd
)
1602 Display
*display
= thread_display();
1603 struct x11drv_win_data
*data
;
1604 XWindowAttributes win_attr
;
1606 /* Only mess with the X focus if there's */
1607 /* no desktop window and if the window is not managed by the WM. */
1608 if (root_window
!= DefaultRootWindow(display
)) return;
1610 if (!hwnd
) /* If setting the focus to 0, uninstall the colormap */
1613 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1614 XUninstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1615 wine_tsx11_unlock();
1619 hwnd
= GetAncestor( hwnd
, GA_ROOT
);
1621 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1622 if (data
->managed
|| !data
->whole_window
) return;
1624 /* Set X focus and install colormap */
1626 if (XGetWindowAttributes( display
, data
->whole_window
, &win_attr
) &&
1627 (win_attr
.map_state
== IsViewable
))
1629 /* If window is not viewable, don't change anything */
1631 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1632 /* FIXME: this is not entirely correct */
1633 XSetInputFocus( display
, data
->whole_window
, RevertToParent
,
1635 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
1636 if (X11DRV_PALETTE_PaletteFlags
& X11DRV_PALETTE_PRIVATE
)
1637 XInstallColormap( display
, X11DRV_PALETTE_PaletteXColormap
);
1639 wine_tsx11_unlock();
1643 /**********************************************************************
1644 * SetWindowIcon (X11DRV.@)
1646 * hIcon or hIconSm has changed (or is being initialised for the
1647 * first time). Complete the X11 driver-specific initialisation
1648 * and set the window hints.
1650 * This is not entirely correct, may need to create
1651 * an icon window and set the pixmap as a background
1653 void X11DRV_SetWindowIcon( HWND hwnd
, UINT type
, HICON icon
)
1655 Display
*display
= thread_display();
1656 struct x11drv_win_data
*data
;
1658 if (type
!= ICON_BIG
) return; /* nothing to do here */
1660 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1661 if (!data
->whole_window
) return;
1662 if (!data
->managed
) return;
1666 set_icon_hints( display
, data
, icon
);
1668 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
1669 wine_tsx11_unlock();
1674 /***********************************************************************
1675 * SetWindowRgn (X11DRV.@)
1677 * Assign specified region to window (for non-rectangular windows)
1679 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
1681 struct x11drv_win_data
*data
;
1683 if ((data
= X11DRV_get_win_data( hwnd
)))
1685 sync_window_region( thread_display(), data
, hrgn
);
1686 invalidate_dce( hwnd
, &data
->window_rect
);
1688 else if (GetWindowThreadProcessId( hwnd
, NULL
) != GetCurrentThreadId())
1690 FIXME( "not supported on other thread window %p\n", hwnd
);
1691 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);