blob: e362e9cd32336f8ce1e7a8466ca4ea4592e57935 [file] [log] [blame]
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001/*
2 * Window related functions
3 *
4 * Copyright 1993, 1994, 1995, 1996, 2001 Alexandre Julliard
5 * Copyright 1993 David Metcalfe
6 * Copyright 1995, 1996 Alex Korobka
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00007 *
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.
12 *
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.
17 *
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
Jonathan Ernst360a3f92006-05-18 14:49:52 +020020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000021 */
22
23#include "config.h"
24
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000025#include <stdarg.h>
Dmitry Timoshkovde70d2b2001-06-19 03:32:44 +000026#include <stdlib.h>
James Liggett60a97502006-08-22 17:14:11 -070027#include <stdio.h>
Patrik Stridvallba78aac2003-08-08 21:07:23 +000028#ifdef HAVE_UNISTD_H
29# include <unistd.h>
30#endif
Dmitry Timoshkovde70d2b2001-06-19 03:32:44 +000031
Alexandre Julliard64c0e2a2003-11-21 21:48:36 +000032#include <X11/Xlib.h>
Alexandre Julliarde9119c12002-09-24 18:36:51 +000033#include <X11/Xresource.h>
34#include <X11/Xutil.h>
Alexandre Julliard395928d2008-01-23 16:30:18 +010035#ifdef HAVE_LIBXSHAPE
36#include <X11/extensions/shape.h>
37#endif /* HAVE_LIBXSHAPE */
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000038
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000039#include "windef.h"
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000040#include "winbase.h"
41#include "wingdi.h"
42#include "winuser.h"
Ilya Konstantinov560ca322001-10-02 18:44:56 +000043#include "wine/unicode.h"
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000044
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000045#include "x11drv.h"
Chris Robinson00633e32007-09-25 22:43:38 -070046#include "xcomposite.h"
Alexandre Julliard4d32a472005-03-25 10:38:56 +000047#include "wine/debug.h"
48#include "wine/server.h"
Ove Kaaven77e7fd72002-01-21 18:41:27 +000049#include "mwm.h"
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000050
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000051WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000052
Alexandre Julliard24dbaa02008-04-17 16:13:34 +020053#define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
54#define _NET_WM_MOVERESIZE_SIZE_TOP 1
55#define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
56#define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
57#define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
58#define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
59#define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
60#define _NET_WM_MOVERESIZE_SIZE_LEFT 7
61#define _NET_WM_MOVERESIZE_MOVE 8
62#define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9
63#define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10
64
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000065/* X context to associate a hwnd to an X window */
66XContext winContext = 0;
67
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +000068/* X context to associate a struct x11drv_win_data to an hwnd */
69static XContext win_data_context;
70
Alexandre Julliardaf50ad62005-07-07 17:30:57 +000071static const char whole_window_prop[] = "__wine_x11_whole_window";
Alexandre Julliard8ee07d42008-02-21 12:29:36 +010072static const char client_window_prop[]= "__wine_x11_client_window";
Alexandre Julliardaf50ad62005-07-07 17:30:57 +000073static const char icon_window_prop[] = "__wine_x11_icon_window";
Chris Robinsond9571c92007-09-15 13:02:32 -070074static const char fbconfig_id_prop[] = "__wine_x11_fbconfig_id";
Chris Robinsona8124f92007-09-25 10:20:58 -070075static const char gl_drawable_prop[] = "__wine_x11_gl_drawable";
Chris Robinson37d835b2007-09-26 08:17:13 -070076static const char pixmap_prop[] = "__wine_x11_pixmap";
Alexandre Julliardaf50ad62005-07-07 17:30:57 +000077static const char managed_prop[] = "__wine_x11_managed";
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000078
Chris Robinson00633e32007-09-25 22:43:38 -070079extern int usexcomposite;
80
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000081/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +000082 * is_window_managed
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000083 *
Alexandre Julliarddc4fe772001-06-04 21:55:17 +000084 * Check if a given window should be managed
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000085 */
Alexandre Julliardeffdfa72007-08-27 12:37:14 +020086BOOL is_window_managed( HWND hwnd, UINT swp_flags, const RECT *window_rect )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000087{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000088 DWORD style, ex_style;
89
Alexandre Julliard89131822008-01-24 10:21:07 +010090 if (!managed_mode) return FALSE;
91
Alexandre Julliarddc4fe772001-06-04 21:55:17 +000092 /* child windows are not managed */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000093 style = GetWindowLongW( hwnd, GWL_STYLE );
Peter Dons Tychsend0b21ab2007-07-25 04:09:50 +020094 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD) return FALSE;
Alexandre Julliardeffdfa72007-08-27 12:37:14 +020095 /* activated windows are managed */
96 if (!(swp_flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) return TRUE;
97 if (hwnd == GetActiveWindow()) return TRUE;
Mike Hearn27d972f2003-12-04 21:54:13 +000098 /* windows with caption are managed */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000099 if ((style & WS_CAPTION) == WS_CAPTION) return TRUE;
Mike Hearn27d972f2003-12-04 21:54:13 +0000100 /* tool windows are not managed */
Alexandre Julliardcbdf1292008-01-23 21:40:45 +0100101 ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE );
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000102 if (ex_style & WS_EX_TOOLWINDOW) return FALSE;
Mike Hearn27d972f2003-12-04 21:54:13 +0000103 /* windows with thick frame are managed */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000104 if (style & WS_THICKFRAME) return TRUE;
Jerry Jenkins4e6fab52003-12-13 00:05:53 +0000105 /* application windows are managed */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000106 if (ex_style & WS_EX_APPWINDOW) return TRUE;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000107 if (style & WS_POPUP)
Alex Pasadynd18c8ca2004-02-06 05:17:55 +0000108 {
Vitaliy Margolenabcbcc32007-02-10 10:40:50 -0700109 /* popup with sysmenu == caption are managed */
110 if (style & WS_SYSMENU) return TRUE;
111 /* full-screen popup windows are managed */
Alexandre Julliarddba8ad52008-02-25 19:48:07 +0100112 if (window_rect->left <= 0 && window_rect->right >= screen_width &&
113 window_rect->top <= 0 && window_rect->bottom >= screen_height)
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000114 return TRUE;
Alex Pasadynd18c8ca2004-02-06 05:17:55 +0000115 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000116 /* default: not managed */
117 return FALSE;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000118}
119
120
121/***********************************************************************
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000122 * X11DRV_is_window_rect_mapped
123 *
124 * Check if the X whole window should be mapped based on its rectangle
125 */
126BOOL X11DRV_is_window_rect_mapped( const RECT *rect )
127{
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000128 /* don't map if rect is off-screen */
Alexandre Julliard3c305f92006-10-23 14:37:17 +0200129 if (rect->left >= virtual_screen_rect.right ||
130 rect->top >= virtual_screen_rect.bottom ||
131 rect->right <= virtual_screen_rect.left ||
132 rect->bottom <= virtual_screen_rect.top)
133 return FALSE;
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000134
135 return TRUE;
136}
137
138
139/***********************************************************************
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200140 * is_window_resizable
141 *
142 * Check if window should be made resizable by the window manager
143 */
144static inline BOOL is_window_resizable( struct x11drv_win_data *data, DWORD style )
145{
146 if (style & WS_THICKFRAME) return TRUE;
147 /* Metacity needs the window to be resizable to make it fullscreen */
148 return (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width &&
149 data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height);
150}
151
152
153/***********************************************************************
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200154 * get_mwm_decorations
155 */
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900156static unsigned long get_mwm_decorations( struct x11drv_win_data *data,
157 DWORD style, DWORD ex_style )
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200158{
159 unsigned long ret = 0;
160
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900161 if (!decorated_mode) return 0;
162
163 if (IsRectEmpty( &data->window_rect )) return 0;
Matthew D'Asaro4217fcb2008-04-10 12:53:45 -0700164
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200165 if (ex_style & WS_EX_TOOLWINDOW) return 0;
166
167 if ((style & WS_CAPTION) == WS_CAPTION)
168 {
169 ret |= MWM_DECOR_TITLE | MWM_DECOR_BORDER;
170 if (style & WS_SYSMENU) ret |= MWM_DECOR_MENU;
171 if (style & WS_MINIMIZEBOX) ret |= MWM_DECOR_MINIMIZE;
172 if (style & WS_MAXIMIZEBOX) ret |= MWM_DECOR_MAXIMIZE;
173 }
174 if (ex_style & WS_EX_DLGMODALFRAME) ret |= MWM_DECOR_BORDER;
175 else if (style & WS_THICKFRAME) ret |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
176 else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) ret |= MWM_DECOR_BORDER;
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200177 return ret;
178}
179
180
181/***********************************************************************
182 * get_x11_rect_offset
183 *
184 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
185 */
186static void get_x11_rect_offset( struct x11drv_win_data *data, RECT *rect )
187{
188 DWORD style, ex_style, style_mask = 0, ex_style_mask = 0;
189 unsigned long decor;
190
191 rect->top = rect->bottom = rect->left = rect->right = 0;
192
193 style = GetWindowLongW( data->hwnd, GWL_STYLE );
194 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900195 decor = get_mwm_decorations( data, style, ex_style );
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200196
197 if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION;
198 if (decor & MWM_DECOR_BORDER)
199 {
200 style_mask |= WS_DLGFRAME | WS_THICKFRAME;
201 ex_style_mask |= WS_EX_DLGMODALFRAME;
202 }
203
204 AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask );
205}
206
207
208/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000209 * get_window_attributes
210 *
Alexandre Julliard883cff42001-06-12 04:02:10 +0000211 * Fill the window attributes structure for an X window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000212 */
Alexandre Julliard6bb18e22006-03-27 15:33:43 +0200213static int get_window_attributes( Display *display, struct x11drv_win_data *data,
214 XSetWindowAttributes *attr )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000215{
Alexandre Julliardd7726c32005-02-01 18:53:59 +0000216 attr->override_redirect = !data->managed;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000217 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000218 attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0);
Alexandre Julliard9428f062002-06-14 00:08:40 +0000219 attr->cursor = x11drv_thread_data()->cursor;
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200220 attr->bit_gravity = NorthWestGravity;
221 attr->backing_store = NotUseful;
222 attr->event_mask = (ExposureMask | PointerMotionMask |
223 ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
224 KeyPressMask | KeyReleaseMask | FocusChangeMask | KeymapStateMask);
Alexandre Julliard5a5344b2008-02-27 19:11:43 +0100225 if (data->managed) attr->event_mask |= StructureNotifyMask | PropertyChangeMask;
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200226
227 return (CWOverrideRedirect | CWSaveUnder | CWColormap | CWCursor |
228 CWEventMask | CWBitGravity | CWBackingStore);
Alexandre Julliard883cff42001-06-12 04:02:10 +0000229}
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000230
Alexandre Julliard883cff42001-06-12 04:02:10 +0000231
232/***********************************************************************
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100233 * create_client_window
234 */
235static Window create_client_window( Display *display, struct x11drv_win_data *data, XVisualInfo *vis )
236{
237 int cx, cy, mask;
238 XSetWindowAttributes attr;
239 Window client;
240
241 attr.bit_gravity = NorthWestGravity;
242 attr.win_gravity = NorthWestGravity;
243 attr.backing_store = NotUseful;
244 attr.event_mask = (ExposureMask | PointerMotionMask |
245 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
246 mask = CWEventMask | CWBitGravity | CWWinGravity | CWBackingStore;
247
248 if ((cx = data->client_rect.right - data->client_rect.left) <= 0) cx = 1;
249 if ((cy = data->client_rect.bottom - data->client_rect.top) <= 0) cy = 1;
250
251 wine_tsx11_lock();
252
253 if (vis)
254 {
255 attr.colormap = XCreateColormap( display, root_window, vis->visual,
256 (vis->class == PseudoColor || vis->class == GrayScale ||
257 vis->class == DirectColor) ? AllocAll : AllocNone );
258 mask |= CWColormap;
259 }
260
261 client = XCreateWindow( display, data->whole_window,
262 data->client_rect.left - data->whole_rect.left,
263 data->client_rect.top - data->whole_rect.top,
264 cx, cy, 0, screen_depth, InputOutput,
265 vis ? vis->visual : visual, mask, &attr );
266 if (!client)
267 {
268 wine_tsx11_unlock();
269 return 0;
270 }
271
272 if (data->client_window)
273 {
Alexandre Julliard51d3d622008-03-05 20:52:14 +0100274 struct x11drv_thread_data *thread_data = x11drv_thread_data();
275 if (thread_data->cursor_window == data->client_window) thread_data->cursor_window = None;
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100276 XDeleteContext( display, data->client_window, winContext );
277 XDestroyWindow( display, data->client_window );
278 }
279 data->client_window = client;
280
281 if (data->colormap) XFreeColormap( display, data->colormap );
282 data->colormap = vis ? attr.colormap : 0;
283
284 XMapWindow( display, data->client_window );
285 XSaveContext( display, data->client_window, winContext, (char *)data->hwnd );
286 wine_tsx11_unlock();
287
288 SetPropA( data->hwnd, client_window_prop, (HANDLE)data->client_window );
289 return data->client_window;
290}
291
292
293/***********************************************************************
Alexandre Julliard911a1772002-08-20 00:36:45 +0000294 * X11DRV_sync_window_style
Alexandre Julliard883cff42001-06-12 04:02:10 +0000295 *
296 * Change the X window attributes when the window style has changed.
297 */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000298void X11DRV_sync_window_style( Display *display, struct x11drv_win_data *data )
Alexandre Julliard883cff42001-06-12 04:02:10 +0000299{
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200300 if (data->whole_window != root_window)
301 {
302 XSetWindowAttributes attr;
303 int mask = get_window_attributes( display, data, &attr );
Alexandre Julliard883cff42001-06-12 04:02:10 +0000304
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200305 wine_tsx11_lock();
Alexandre Julliard6d5f5442006-03-06 21:02:59 +0100306 XChangeWindowAttributes( display, data->whole_window, mask, &attr );
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200307 wine_tsx11_unlock();
308 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000309}
310
311
312/***********************************************************************
Alexandre Julliard395928d2008-01-23 16:30:18 +0100313 * sync_window_region
314 *
315 * Update the X11 window region.
316 */
317static void sync_window_region( Display *display, struct x11drv_win_data *data, HRGN hrgn )
318{
319#ifdef HAVE_LIBXSHAPE
320 if (!data->whole_window) return;
321
322 if (!hrgn)
323 {
324 wine_tsx11_lock();
325 XShapeCombineMask( display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet );
326 wine_tsx11_unlock();
327 }
328 else
329 {
330 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
331 if (pRegionData)
332 {
333 wine_tsx11_lock();
334 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
335 data->window_rect.left - data->whole_rect.left,
336 data->window_rect.top - data->whole_rect.top,
337 (XRectangle *)pRegionData->Buffer,
338 pRegionData->rdh.nCount, ShapeSet, YXBanded );
339 wine_tsx11_unlock();
340 HeapFree(GetProcessHeap(), 0, pRegionData);
341 }
342 }
343#endif /* HAVE_LIBXSHAPE */
344}
345
346
347/***********************************************************************
Alexandre Julliard3ba20252008-01-23 16:32:55 +0100348 * sync_window_text
349 */
350static void sync_window_text( Display *display, Window win, const WCHAR *text )
351{
352 UINT count;
353 char *buffer, *utf8_buffer;
354 XTextProperty prop;
355
356 /* allocate new buffer for window text */
357 count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
358 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) return;
359 WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
360
361 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
362 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
363 {
364 HeapFree( GetProcessHeap(), 0, buffer );
365 return;
366 }
367 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
368
369 wine_tsx11_lock();
370 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
371 {
372 XSetWMName( display, win, &prop );
373 XSetWMIconName( display, win, &prop );
374 XFree( prop.value );
375 }
376 /*
377 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
378 according to the standard
379 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
380 */
381 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
382 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
383 wine_tsx11_unlock();
384
385 HeapFree( GetProcessHeap(), 0, utf8_buffer );
386 HeapFree( GetProcessHeap(), 0, buffer );
387}
388
389
390/***********************************************************************
Chris Robinsond9571c92007-09-15 13:02:32 -0700391 * X11DRV_set_win_format
392 */
393BOOL X11DRV_set_win_format( HWND hwnd, XID fbconfig_id )
394{
Chris Robinson00633e32007-09-25 22:43:38 -0700395 Display *display = thread_display();
Chris Robinsond9571c92007-09-15 13:02:32 -0700396 struct x11drv_win_data *data;
Chris Robinson00633e32007-09-25 22:43:38 -0700397 XVisualInfo *vis;
Chris Robinson00633e32007-09-25 22:43:38 -0700398 int w, h;
Chris Robinsond9571c92007-09-15 13:02:32 -0700399
Alexandre Julliard026974f2008-01-24 10:20:51 +0100400 if (!(data = X11DRV_get_win_data(hwnd)) &&
401 !(data = X11DRV_create_win_data(hwnd))) return FALSE;
Chris Robinsond9571c92007-09-15 13:02:32 -0700402
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100403 if (data->fbconfig_id) return FALSE; /* can't change it twice */
404
Chris Robinson00633e32007-09-25 22:43:38 -0700405 wine_tsx11_lock();
Chris Robinson00633e32007-09-25 22:43:38 -0700406 vis = visual_from_fbconfig_id(fbconfig_id);
Chris Robinson00633e32007-09-25 22:43:38 -0700407 wine_tsx11_unlock();
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100408 if (!vis) return FALSE;
Chris Robinson00633e32007-09-25 22:43:38 -0700409
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100410 if (data->whole_window)
Chris Robinson00633e32007-09-25 22:43:38 -0700411 {
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100412 Window client = data->client_window;
413
414 if (vis->visualid != XVisualIDFromVisual(visual))
Chris Robinson00633e32007-09-25 22:43:38 -0700415 {
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100416 client = create_client_window( display, data, vis );
417 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client, data->hwnd, fbconfig_id );
Chris Robinson00633e32007-09-25 22:43:38 -0700418 }
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100419 wine_tsx11_lock();
420 XFree(vis);
421 wine_tsx11_unlock();
422 if (client) goto done;
423 return FALSE;
Chris Robinson00633e32007-09-25 22:43:38 -0700424 }
425
426 w = data->client_rect.right - data->client_rect.left;
427 h = data->client_rect.bottom - data->client_rect.top;
428
429 if(w <= 0) w = 1;
430 if(h <= 0) h = 1;
431
Chris Robinson00633e32007-09-25 22:43:38 -0700432#ifdef SONAME_LIBXCOMPOSITE
433 if(usexcomposite)
434 {
435 XSetWindowAttributes attrib;
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100436 Window parent = X11DRV_get_whole_window( GetAncestor( hwnd, GA_ROOT ));
Chris Robinson00633e32007-09-25 22:43:38 -0700437
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100438 if (!parent) parent = root_window;
439 wine_tsx11_lock();
Alexandre Julliarde9307d02008-02-21 20:23:32 +0100440 data->colormap = XCreateColormap(display, parent, vis->visual,
441 (vis->class == PseudoColor ||
442 vis->class == GrayScale ||
443 vis->class == DirectColor) ?
444 AllocAll : AllocNone);
Chris Robinson00633e32007-09-25 22:43:38 -0700445 attrib.override_redirect = True;
Alexandre Julliarde9307d02008-02-21 20:23:32 +0100446 attrib.colormap = data->colormap;
Chris Robinson00633e32007-09-25 22:43:38 -0700447 XInstallColormap(gdi_display, attrib.colormap);
448
449 data->gl_drawable = XCreateWindow(display, parent, -w, 0, w, h, 0,
450 vis->depth, InputOutput, vis->visual,
451 CWColormap | CWOverrideRedirect,
452 &attrib);
453 if(data->gl_drawable)
454 {
455 pXCompositeRedirectWindow(display, data->gl_drawable,
456 CompositeRedirectManual);
457 XMapWindow(display, data->gl_drawable);
458 }
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100459 XFree(vis);
460 wine_tsx11_unlock();
Chris Robinson00633e32007-09-25 22:43:38 -0700461 }
Chris Robinson37d835b2007-09-26 08:17:13 -0700462 else
Chris Robinson00633e32007-09-25 22:43:38 -0700463#endif
Chris Robinson37d835b2007-09-26 08:17:13 -0700464 {
465 WARN("XComposite is not available, using GLXPixmap hack\n");
466
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100467 wine_tsx11_lock();
468 data->pixmap = XCreatePixmap(display, root_window, w, h, vis->depth);
Chris Robinson37d835b2007-09-26 08:17:13 -0700469 if(!data->pixmap)
470 {
Chris Robinson37d835b2007-09-26 08:17:13 -0700471 XFree(vis);
472 wine_tsx11_unlock();
473 return FALSE;
474 }
475
476 data->gl_drawable = create_glxpixmap(display, vis, data->pixmap);
477 if(!data->gl_drawable)
478 {
479 XFreePixmap(display, data->pixmap);
480 data->pixmap = 0;
481 }
Chris Robinson00633e32007-09-25 22:43:38 -0700482 XFree(vis);
483 wine_tsx11_unlock();
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100484 if (data->pixmap) SetPropA(hwnd, pixmap_prop, (HANDLE)data->pixmap);
Chris Robinson00633e32007-09-25 22:43:38 -0700485 }
486
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100487 if (!data->gl_drawable) return FALSE;
Chris Robinson00633e32007-09-25 22:43:38 -0700488
489 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
490 data->gl_drawable, fbconfig_id);
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100491 SetPropA(hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
Chris Robinson00633e32007-09-25 22:43:38 -0700492
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100493done:
Chris Robinsond9571c92007-09-15 13:02:32 -0700494 data->fbconfig_id = fbconfig_id;
495 SetPropA(hwnd, fbconfig_id_prop, (HANDLE)data->fbconfig_id);
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100496 wine_tsx11_lock();
497 XFlush( display );
498 wine_tsx11_unlock();
Alexandre Julliard9727aa82008-04-21 20:32:22 +0200499 /* force DCE invalidation */
500 SetWindowPos( hwnd, 0, 0, 0, 0, 0,
501 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE |
502 SWP_NOREDRAW | SWP_NOSENDCHANGING | SWP_STATECHANGED);
Chris Robinsond9571c92007-09-15 13:02:32 -0700503 return TRUE;
504}
505
Alexandre Julliardbbfbe242008-01-23 12:28:01 +0100506/***********************************************************************
Alexandre Julliard8ee07d42008-02-21 12:29:36 +0100507 * sync_gl_drawable
Alexandre Julliardbbfbe242008-01-23 12:28:01 +0100508 */
Alexandre Julliard8ee07d42008-02-21 12:29:36 +0100509static void sync_gl_drawable(Display *display, struct x11drv_win_data *data)
Chris Robinson00633e32007-09-25 22:43:38 -0700510{
511 int w = data->client_rect.right - data->client_rect.left;
512 int h = data->client_rect.bottom - data->client_rect.top;
Chris Robinson37d835b2007-09-26 08:17:13 -0700513 XVisualInfo *vis;
Chris Robinson37d835b2007-09-26 08:17:13 -0700514 Drawable glxp;
515 Pixmap pix;
Chris Robinson00633e32007-09-25 22:43:38 -0700516
Alexandre Julliardf13ef6b2008-02-22 16:30:10 +0100517 if (w <= 0) w = 1;
518 if (h <= 0) h = 1;
519
Chris Robinson00633e32007-09-25 22:43:38 -0700520 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data->gl_drawable, w, h);
521#ifdef SONAME_LIBXCOMPOSITE
522 if(usexcomposite)
523 {
524 wine_tsx11_lock();
525 XMoveResizeWindow(display, data->gl_drawable, -w, 0, w, h);
526 wine_tsx11_unlock();
527 return;
528 }
529#endif
Chris Robinson37d835b2007-09-26 08:17:13 -0700530
Chris Robinson37d835b2007-09-26 08:17:13 -0700531 wine_tsx11_lock();
532
533 vis = visual_from_fbconfig_id(data->fbconfig_id);
Michael Stefaniuc4e2eef22007-10-21 01:15:53 +0200534 if(!vis)
535 {
536 wine_tsx11_unlock();
537 return;
538 }
Chris Robinson37d835b2007-09-26 08:17:13 -0700539
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100540 pix = XCreatePixmap(display, root_window, w, h, vis->depth);
Chris Robinson37d835b2007-09-26 08:17:13 -0700541 if(!pix)
542 {
543 ERR("Failed to create pixmap for offscreen rendering\n");
544 XFree(vis);
545 wine_tsx11_unlock();
546 return;
547 }
548
549 glxp = create_glxpixmap(display, vis, pix);
550 if(!glxp)
551 {
552 ERR("Failed to create drawable for offscreen rendering\n");
553 XFreePixmap(display, pix);
554 XFree(vis);
555 wine_tsx11_unlock();
556 return;
557 }
558
559 XFree(vis);
560
561 mark_drawable_dirty(data->gl_drawable, glxp);
562
563 XFreePixmap(display, data->pixmap);
564 destroy_glxpixmap(display, data->gl_drawable);
Alexandre Julliard9727aa82008-04-21 20:32:22 +0200565 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp, data->gl_drawable );
Chris Robinson37d835b2007-09-26 08:17:13 -0700566
567 data->pixmap = pix;
568 data->gl_drawable = glxp;
569
Alexandre Julliard70ef99e2008-04-10 14:47:19 +0200570 XFlush( display );
Chris Robinson37d835b2007-09-26 08:17:13 -0700571 wine_tsx11_unlock();
572
573 SetPropA(data->hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
574 SetPropA(data->hwnd, pixmap_prop, (HANDLE)data->pixmap);
Chris Robinson00633e32007-09-25 22:43:38 -0700575}
576
Chris Robinsond9571c92007-09-15 13:02:32 -0700577
578/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000579 * get_window_changes
580 *
581 * fill the window changes structure
582 */
583static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
584{
585 int mask = 0;
586
587 if (old->right - old->left != new->right - new->left )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000588 {
Alexandre Julliard8ee07d42008-02-21 12:29:36 +0100589 if ((changes->width = new->right - new->left) <= 0) changes->width = 1;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000590 mask |= CWWidth;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000591 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000592 if (old->bottom - old->top != new->bottom - new->top)
593 {
Alexandre Julliard8ee07d42008-02-21 12:29:36 +0100594 if ((changes->height = new->bottom - new->top) <= 0) changes->height = 1;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000595 mask |= CWHeight;
596 }
597 if (old->left != new->left)
598 {
599 changes->x = new->left;
600 mask |= CWX;
601 }
602 if (old->top != new->top)
603 {
604 changes->y = new->top;
605 mask |= CWY;
606 }
607 return mask;
608}
609
610
611/***********************************************************************
612 * create_icon_window
613 */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000614static Window create_icon_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000615{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000616 XSetWindowAttributes attr;
617
618 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
Alexandre Julliard9428f062002-06-14 00:08:40 +0000619 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000620 attr.bit_gravity = NorthWestGravity;
621 attr.backing_store = NotUseful/*WhenMapped*/;
Lionel Ulmer1fc39be2001-07-12 22:27:56 +0000622 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000623
Alexandre Julliard649637f2001-06-26 21:10:11 +0000624 wine_tsx11_lock();
625 data->icon_window = XCreateWindow( display, root_window, 0, 0,
626 GetSystemMetrics( SM_CXICON ),
627 GetSystemMetrics( SM_CYICON ),
628 0, screen_depth,
629 InputOutput, visual,
Lionel Ulmer1fc39be2001-07-12 22:27:56 +0000630 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000631 XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd );
Alexandre Julliard731d77f2008-04-09 20:24:27 +0200632 XFlush( display ); /* make sure the window exists before we start painting to it */
Alexandre Julliard649637f2001-06-26 21:10:11 +0000633 wine_tsx11_unlock();
634
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000635 TRACE( "created %lx\n", data->icon_window );
Alexandre Julliardaf50ad62005-07-07 17:30:57 +0000636 SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000637 return data->icon_window;
638}
639
640
641
642/***********************************************************************
643 * destroy_icon_window
644 */
Alexandre Julliardf777d702005-01-31 16:34:07 +0000645static void destroy_icon_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000646{
647 if (!data->icon_window) return;
Alexandre Julliard9428f062002-06-14 00:08:40 +0000648 if (x11drv_thread_data()->cursor_window == data->icon_window)
649 x11drv_thread_data()->cursor_window = None;
Alexandre Julliard704d0352001-07-12 02:49:31 +0000650 wine_tsx11_lock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000651 XDeleteContext( display, data->icon_window, winContext );
652 XDestroyWindow( display, data->icon_window );
653 data->icon_window = 0;
Alexandre Julliard704d0352001-07-12 02:49:31 +0000654 wine_tsx11_unlock();
Alexandre Julliardaf50ad62005-07-07 17:30:57 +0000655 RemovePropA( data->hwnd, icon_window_prop );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000656}
657
658
659/***********************************************************************
660 * set_icon_hints
661 *
662 * Set the icon wm hints
663 */
Alexandre Julliardbde89572007-08-16 23:27:37 +0200664static void set_icon_hints( Display *display, struct x11drv_win_data *data, HICON hIcon )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000665{
Alexandre Julliardbde89572007-08-16 23:27:37 +0200666 XWMHints *hints = data->wm_hints;
667
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000668 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
669 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
Alexandre Julliard883cff42001-06-12 04:02:10 +0000670 data->hWMIconBitmap = 0;
671 data->hWMIconMask = 0;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000672
Alexandre Julliard12d1d402008-01-23 16:40:19 +0100673 if (!hIcon)
Alexandre Julliard883cff42001-06-12 04:02:10 +0000674 {
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000675 if (!data->icon_window) create_icon_window( display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000676 hints->icon_window = data->icon_window;
677 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000678 }
679 else
680 {
681 HBITMAP hbmOrig;
682 RECT rcMask;
683 BITMAP bmMask;
684 ICONINFO ii;
685 HDC hDC;
686
687 GetIconInfo(hIcon, &ii);
688
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000689 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
690 rcMask.top = 0;
691 rcMask.left = 0;
692 rcMask.right = bmMask.bmWidth;
693 rcMask.bottom = bmMask.bmHeight;
694
695 hDC = CreateCompatibleDC(0);
696 hbmOrig = SelectObject(hDC, ii.hbmMask);
697 InvertRect(hDC, &rcMask);
Alexandre Julliardd8a92442002-05-31 18:43:22 +0000698 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000699 SelectObject(hDC, hbmOrig);
700 DeleteDC(hDC);
701
702 data->hWMIconBitmap = ii.hbmColor;
703 data->hWMIconMask = ii.hbmMask;
704
Alexandre Julliard5fd13262005-03-27 18:30:51 +0000705 hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap);
706 hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask);
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000707 destroy_icon_window( display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000708 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000709 }
710}
711
712
713/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000714 * set_size_hints
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000715 *
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000716 * set the window size hints
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000717 */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000718static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000719{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000720 XSizeHints* size_hints;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000721
Alexandre Julliardcf9d3e32008-04-04 11:28:30 +0200722 if (!(size_hints = XAllocSizeHints())) return;
Alexandre Julliardba1517f2006-03-27 22:16:04 +0200723
Alexandre Julliardcf9d3e32008-04-04 11:28:30 +0200724 /* don't update size hints if window is not in normal state */
725 if (!(style & (WS_MINIMIZE | WS_MAXIMIZE)))
726 {
Alexandre Julliardba1517f2006-03-27 22:16:04 +0200727 if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */
728 {
729 size_hints->win_gravity = StaticGravity;
730 size_hints->x = data->whole_rect.left;
731 size_hints->y = data->whole_rect.top;
732 size_hints->flags |= PWinGravity | PPosition;
733 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000734
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200735 if (!is_window_resizable( data, style ))
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000736 {
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200737 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
738 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
739 size_hints->min_width = size_hints->max_width;
740 size_hints->min_height = size_hints->max_height;
741 size_hints->flags |= PMinSize | PMaxSize;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000742 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000743 }
Alexandre Julliardcf9d3e32008-04-04 11:28:30 +0200744 XSetWMNormalHints( display, data->whole_window, size_hints );
745 XFree( size_hints );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000746}
747
748
749/***********************************************************************
Alexandre Julliardc7dbffc2005-07-01 16:16:00 +0000750 * get_process_name
751 *
752 * get the name of the current process for setting class hints
753 */
754static char *get_process_name(void)
755{
756 static char *name;
757
758 if (!name)
759 {
760 WCHAR module[MAX_PATH];
761 DWORD len = GetModuleFileNameW( 0, module, MAX_PATH );
762 if (len && len < MAX_PATH)
763 {
764 char *ptr;
765 WCHAR *p, *appname = module;
766
767 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
768 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
769 len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL );
770 if ((ptr = HeapAlloc( GetProcessHeap(), 0, len )))
771 {
772 WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL );
773 name = ptr;
774 }
775 }
776 }
777 return name;
778}
779
780
781/***********************************************************************
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200782 * set_initial_wm_hints
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000783 *
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200784 * Set the window manager hints that don't change over the lifetime of a window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000785 */
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200786static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000787{
Alexandre Julliard3bfa90e2008-04-07 11:41:54 +0200788 long i;
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200789 Atom protocols[3];
790 Atom dndVersion = 4;
791 XClassHint *class_hints;
Alexandre Julliardc7dbffc2005-07-01 16:16:00 +0000792 char *process_name = get_process_name();
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000793
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000794 wine_tsx11_lock();
795
796 /* wm protocols */
797 i = 0;
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000798 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
799 protocols[i++] = x11drv_atom(_NET_WM_PING);
800 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
801 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
Hans Leidekkerac147fe2005-03-22 21:17:34 +0000802 XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000803
804 /* class hints */
805 if ((class_hints = XAllocClassHint()))
806 {
Andrew Talbot55e20a72006-06-26 20:56:16 +0100807 static char wine[] = "Wine";
808
Alexandre Julliardc7dbffc2005-07-01 16:16:00 +0000809 class_hints->res_name = process_name;
Andrew Talbot55e20a72006-06-26 20:56:16 +0100810 class_hints->res_class = wine;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000811 XSetClassHint( display, data->whole_window, class_hints );
812 XFree( class_hints );
813 }
814
Mike Hearn34dd4552003-05-04 02:27:20 +0000815 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
816 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
817 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
818 i = getpid();
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000819 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
Hans Leidekkerac147fe2005-03-22 21:17:34 +0000820 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
Ove Kaaven77e7fd72002-01-21 18:41:27 +0000821
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200822 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
823 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
824
Alexandre Julliarddc07b6f2008-01-22 10:17:52 +0100825 data->wm_hints = XAllocWMHints();
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200826 wine_tsx11_unlock();
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100827
828 if (data->wm_hints)
829 {
Alexandre Julliarde929e3b2008-01-23 16:40:54 +0100830 HICON icon = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 );
831 if (!icon) icon = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON );
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100832 data->wm_hints->flags = 0;
Alexandre Julliarde929e3b2008-01-23 16:40:54 +0100833 set_icon_hints( display, data, icon );
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100834 }
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200835}
836
837
838/***********************************************************************
839 * X11DRV_set_wm_hints
840 *
841 * Set the window manager hints for a newly-created window
842 */
843void X11DRV_set_wm_hints( Display *display, struct x11drv_win_data *data )
844{
845 Window group_leader;
846 Atom window_type;
847 MwmHints mwm_hints;
Alexandre Julliard18f4fb92008-04-14 13:27:38 +0200848 DWORD style, ex_style;
849 HWND owner;
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200850
851 if (data->hwnd == GetDesktopWindow())
852 {
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200853 /* force some styles for the desktop to get the correct decorations */
Alexandre Julliard18f4fb92008-04-14 13:27:38 +0200854 style = WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
855 ex_style = WS_EX_APPWINDOW;
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200856 owner = 0;
857 }
Alexandre Julliard18f4fb92008-04-14 13:27:38 +0200858 else
859 {
860 style = GetWindowLongW( data->hwnd, GWL_STYLE );
861 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
862 owner = GetWindow( data->hwnd, GW_OWNER );
863 }
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200864
865 /* transient for hint */
866 if (owner)
867 {
868 Window owner_win = X11DRV_get_whole_window( owner );
869 wine_tsx11_lock();
870 XSetTransientForHint( display, data->whole_window, owner_win );
871 wine_tsx11_unlock();
872 group_leader = owner_win;
873 }
874 else group_leader = data->whole_window;
875
876 wine_tsx11_lock();
877
878 /* size hints */
879 set_size_hints( display, data, style );
880
Nickolay V. Shmyrev1a1b9022006-10-11 19:32:22 +0400881 /* set the WM_WINDOW_TYPE */
Dmitry Timoshkov751a71a2008-04-07 13:37:44 +0900882 if (style & WS_THICKFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
Alexandre Julliard9bf9c0b2008-04-14 13:27:19 +0200883 else if (ex_style & WS_EX_APPWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
Nickolay V. Shmyrev1a1b9022006-10-11 19:32:22 +0400884 else if (style & WS_DLGFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
885 else if (ex_style & WS_EX_DLGMODALFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
Dmitry Timoshkov1bf824e2008-04-07 22:17:47 +0900886#if 0 /* many window managers don't handle utility windows very well */
Dmitry Timoshkov751a71a2008-04-07 13:37:44 +0900887 else if (ex_style & WS_EX_TOOLWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
Dmitry Timoshkov1bf824e2008-04-07 22:17:47 +0900888#endif
Alexandre Julliard9bf9c0b2008-04-14 13:27:19 +0200889 else window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
Nickolay V. Shmyrev1a1b9022006-10-11 19:32:22 +0400890
891 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
892 XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1);
Mike Hearn27d972f2003-12-04 21:54:13 +0000893
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000894 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900895 mwm_hints.decorations = get_mwm_decorations( data, style, ex_style );
Dmitry Timoshkovac387bb2006-10-05 23:16:36 +0900896 mwm_hints.functions = MWM_FUNC_MOVE;
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200897 if (is_window_resizable( data, style )) mwm_hints.functions |= MWM_FUNC_RESIZE;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000898 if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
899 if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
Alexandre Julliard74cd76c2007-08-29 12:02:57 +0200900 if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000901
902 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
903 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
Hans Leidekkerac147fe2005-03-22 21:17:34 +0000904 (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000905
Alexandre Julliard704d0352001-07-12 02:49:31 +0000906 /* wm hints */
Alexandre Julliardbde89572007-08-16 23:27:37 +0200907 if (data->wm_hints)
Alexandre Julliard704d0352001-07-12 02:49:31 +0000908 {
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100909 data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint;
Alexandre Julliardbde89572007-08-16 23:27:37 +0200910 data->wm_hints->input = !(style & WS_DISABLED);
911 data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
912 data->wm_hints->window_group = group_leader;
Alexandre Julliardbde89572007-08-16 23:27:37 +0200913 XSetWMHints( display, data->whole_window, data->wm_hints );
Alexandre Julliard704d0352001-07-12 02:49:31 +0000914 }
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100915
916 wine_tsx11_unlock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000917}
918
919
920/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000921 * X11DRV_window_to_X_rect
922 *
923 * Convert a rect from client to X window coordinates
924 */
Alexandre Julliardd7726c32005-02-01 18:53:59 +0000925void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000926{
Alexandre Julliard8cd1f712001-07-20 18:37:37 +0000927 RECT rc;
928
Alexandre Julliardd7726c32005-02-01 18:53:59 +0000929 if (!data->managed) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000930 if (IsRectEmpty( rect )) return;
931
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200932 get_x11_rect_offset( data, &rc );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000933
Alexandre Julliard8cd1f712001-07-20 18:37:37 +0000934 rect->left -= rc.left;
935 rect->right -= rc.right;
936 rect->top -= rc.top;
937 rect->bottom -= rc.bottom;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000938 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
939 if (rect->left >= rect->right) rect->right = rect->left + 1;
940}
941
942
943/***********************************************************************
944 * X11DRV_X_to_window_rect
945 *
946 * Opposite of X11DRV_window_to_X_rect
947 */
Alexandre Julliardd7726c32005-02-01 18:53:59 +0000948void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000949{
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200950 RECT rc;
Alexandre Julliard74cd76c2007-08-29 12:02:57 +0200951
Alexandre Julliardd7726c32005-02-01 18:53:59 +0000952 if (!data->managed) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000953 if (IsRectEmpty( rect )) return;
954
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200955 get_x11_rect_offset( data, &rc );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000956
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200957 rect->left += rc.left;
958 rect->right += rc.right;
959 rect->top += rc.top;
960 rect->bottom += rc.bottom;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000961 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
962 if (rect->left >= rect->right) rect->right = rect->left + 1;
963}
964
965
966/***********************************************************************
Alexandre Julliardf777d702005-01-31 16:34:07 +0000967 * X11DRV_sync_window_position
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000968 *
Alexandre Julliardf777d702005-01-31 16:34:07 +0000969 * Synchronize the X window position with the Windows one
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000970 */
Alexandre Julliardf777d702005-01-31 16:34:07 +0000971void X11DRV_sync_window_position( Display *display, struct x11drv_win_data *data,
Alexandre Julliardbbfbe242008-01-23 12:28:01 +0100972 UINT swp_flags, const RECT *old_client_rect,
973 const RECT *old_whole_rect )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000974{
Alexandre Julliardcef3bc62008-04-04 11:20:45 +0200975 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000976 XWindowChanges changes;
Alexandre Julliardcef3bc62008-04-04 11:20:45 +0200977 int mask = CWWidth | CWHeight;
978
979 if (data->managed && data->iconic) return;
980
981 if ((changes.width = data->whole_rect.right - data->whole_rect.left) <= 0) changes.width = 1;
982 if ((changes.height = data->whole_rect.bottom - data->whole_rect.top) <= 0) changes.height = 1;
983
984 /* only the size is allowed to change for the desktop window */
985 if (data->whole_window != root_window)
986 {
987 changes.x = data->whole_rect.left - virtual_screen_rect.left;
988 changes.y = data->whole_rect.top - virtual_screen_rect.top;
989 mask |= CWX | CWY;
990 }
Alexandre Julliardf777d702005-01-31 16:34:07 +0000991
992 if (!(swp_flags & SWP_NOZORDER))
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000993 {
Alexandre Julliardf777d702005-01-31 16:34:07 +0000994 /* find window that this one must be after */
995 HWND prev = GetWindow( data->hwnd, GW_HWNDPREV );
996 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
997 prev = GetWindow( prev, GW_HWNDPREV );
998 if (!prev) /* top child */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000999 {
Alexandre Julliardf777d702005-01-31 16:34:07 +00001000 changes.stack_mode = Above;
1001 mask |= CWStackMode;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001002 }
Alexandre Julliard5787c122008-03-24 15:47:28 +01001003 /* should use stack_mode Below but most window managers don't get it right */
1004 /* and Above with a sibling doesn't work so well either, so we ignore it */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001005 }
1006
Alexandre Julliardcef3bc62008-04-04 11:20:45 +02001007 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
1008 data->hwnd, data->whole_window, data->whole_rect.left, data->whole_rect.top,
1009 data->whole_rect.right - data->whole_rect.left,
1010 data->whole_rect.bottom - data->whole_rect.top, changes.sibling, mask );
Alexandre Julliardc19af912008-01-17 19:53:59 +01001011
Alexandre Julliardcef3bc62008-04-04 11:20:45 +02001012 wine_tsx11_lock();
1013 set_size_hints( display, data, style );
1014 XReconfigureWMWindow( display, data->whole_window,
1015 DefaultScreen(display), mask, &changes );
1016 wine_tsx11_unlock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001017}
1018
1019
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001020/***********************************************************************
1021 * X11DRV_sync_client_position
1022 *
1023 * Synchronize the X client window position with the Windows one
1024 */
1025void X11DRV_sync_client_position( Display *display, struct x11drv_win_data *data,
1026 UINT swp_flags, const RECT *old_client_rect,
1027 const RECT *old_whole_rect )
1028{
1029 int mask;
1030 XWindowChanges changes;
1031 RECT old = *old_client_rect;
1032 RECT new = data->client_rect;
1033
1034 OffsetRect( &old, -old_whole_rect->left, -old_whole_rect->top );
1035 OffsetRect( &new, -data->whole_rect.left, -data->whole_rect.top );
1036 if (!(mask = get_window_changes( &changes, &old, &new ))) return;
1037
1038 if (data->client_window)
1039 {
1040 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1041 data->client_window, new.left, new.top,
1042 new.right - new.left, new.bottom - new.top, mask );
1043 wine_tsx11_lock();
1044 XConfigureWindow( display, data->client_window, mask, &changes );
1045 wine_tsx11_unlock();
1046 }
1047
1048 if (data->gl_drawable && (mask & (CWWidth|CWHeight))) sync_gl_drawable( display, data );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001049}
1050
1051
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001052/**********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001053 * create_whole_window
1054 *
1055 * Create the whole X window for a given window
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001056 */
Alexandre Julliardd147e022008-01-23 21:39:32 +01001057static Window create_whole_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001058{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001059 int cx, cy, mask;
1060 XSetWindowAttributes attr;
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001061 WCHAR text[1024];
Alexandre Julliard395928d2008-01-23 16:30:18 +01001062 HRGN hrgn;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001063
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001064 if (!(cx = data->window_rect.right - data->window_rect.left)) cx = 1;
1065 if (!(cy = data->window_rect.bottom - data->window_rect.top)) cy = 1;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001066
Alexandre Julliarde6dfbcb2008-01-25 12:07:11 +01001067 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1068 {
1069 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1070 data->managed = TRUE;
1071 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1072 }
1073
Alexandre Julliard6bb18e22006-03-27 15:33:43 +02001074 mask = get_window_attributes( display, data, &attr );
Alexandre Julliard883cff42001-06-12 04:02:10 +00001075
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001076 wine_tsx11_lock();
1077
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001078 data->whole_rect = data->window_rect;
Alexandre Julliarda06aeab2006-10-26 12:53:59 +02001079 data->whole_window = XCreateWindow( display, root_window,
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001080 data->window_rect.left - virtual_screen_rect.left,
1081 data->window_rect.top - virtual_screen_rect.top,
Alexandre Julliarda06aeab2006-10-26 12:53:59 +02001082 cx, cy, 0, screen_depth, InputOutput,
1083 visual, mask, &attr );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001084
Alexandre Julliard42ad3452008-02-22 10:40:22 +01001085 if (data->whole_window) XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
1086 wine_tsx11_unlock();
1087
1088 if (!data->whole_window) return 0;
1089
1090 if (!create_client_window( display, data, NULL ))
Alexandre Julliard704d0352001-07-12 02:49:31 +00001091 {
Alexandre Julliard42ad3452008-02-22 10:40:22 +01001092 wine_tsx11_lock();
1093 XDeleteContext( display, data->whole_window, winContext );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001094 XDestroyWindow( display, data->whole_window );
1095 data->whole_window = 0;
1096 wine_tsx11_unlock();
1097 return 0;
1098 }
1099
Alexandre Julliard7d9739e2007-08-20 14:04:36 +02001100 set_initial_wm_hints( display, data );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001101 X11DRV_set_wm_hints( display, data );
1102
Alexandre Julliardaf50ad62005-07-07 17:30:57 +00001103 SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
Alexandre Julliard395928d2008-01-23 16:30:18 +01001104
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001105 /* set the window text */
1106 if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
1107 sync_window_text( display, data->whole_window, text );
1108
Alexandre Julliard395928d2008-01-23 16:30:18 +01001109 /* set the window region */
1110 if ((hrgn = CreateRectRgn( 0, 0, 0, 0 )))
1111 {
1112 if (GetWindowRgn( data->hwnd, hrgn ) != ERROR) sync_window_region( display, data, hrgn );
1113 DeleteObject( hrgn );
1114 }
Alexandre Julliard731d77f2008-04-09 20:24:27 +02001115 wine_tsx11_lock();
1116 XFlush( display ); /* make sure the window exists before we start painting to it */
1117 wine_tsx11_unlock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001118 return data->whole_window;
1119}
1120
1121
1122/**********************************************************************
Alexandre Julliardf777d702005-01-31 16:34:07 +00001123 * destroy_whole_window
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001124 *
Alexandre Julliardf777d702005-01-31 16:34:07 +00001125 * Destroy the whole X window for a given window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001126 */
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001127static void destroy_whole_window( Display *display, struct x11drv_win_data *data, BOOL already_destroyed )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001128{
Alexandre Julliardf777d702005-01-31 16:34:07 +00001129 struct x11drv_thread_data *thread_data = x11drv_thread_data();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001130
Alexandre Julliardf777d702005-01-31 16:34:07 +00001131 if (!data->whole_window) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001132
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001133 TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1134 if (thread_data->cursor_window == data->whole_window ||
1135 thread_data->cursor_window == data->client_window)
1136 thread_data->cursor_window = None;
Alexandre Julliard883cff42001-06-12 04:02:10 +00001137 wine_tsx11_lock();
Alexandre Julliardf777d702005-01-31 16:34:07 +00001138 XDeleteContext( display, data->whole_window, winContext );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001139 XDeleteContext( display, data->client_window, winContext );
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001140 if (!already_destroyed) XDestroyWindow( display, data->whole_window );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001141 data->whole_window = data->client_window = 0;
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001142 data->wm_state = WithdrawnState;
1143 data->net_wm_state = 0;
1144 data->mapped = FALSE;
Alexandre Julliardf777d702005-01-31 16:34:07 +00001145 if (data->xic)
1146 {
1147 XUnsetICFocus( data->xic );
1148 XDestroyIC( data->xic );
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001149 data->xic = 0;
Alexandre Julliardf777d702005-01-31 16:34:07 +00001150 }
Alexandre Julliard975f1b22006-05-09 17:32:40 +02001151 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1152 XFlush( display );
Alexandre Julliarddc07b6f2008-01-22 10:17:52 +01001153 XFree( data->wm_hints );
1154 data->wm_hints = NULL;
Alexandre Julliard883cff42001-06-12 04:02:10 +00001155 wine_tsx11_unlock();
Alexandre Julliardaf50ad62005-07-07 17:30:57 +00001156 RemovePropA( data->hwnd, whole_window_prop );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001157 RemovePropA( data->hwnd, client_window_prop );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001158}
1159
1160
1161/*****************************************************************
1162 * SetWindowText (X11DRV.@)
1163 */
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001164void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001165{
Alexandre Julliard43230042001-05-16 19:52:29 +00001166 Display *display = thread_display();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001167 Window win;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001168
Alexandre Julliardc44410d2006-03-28 12:21:37 +02001169 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display))
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001170 sync_window_text( display, win, text );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001171}
1172
1173
1174/***********************************************************************
1175 * DestroyWindow (X11DRV.@)
1176 */
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001177void X11DRV_DestroyWindow( HWND hwnd )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001178{
Alexandre Julliard9428f062002-06-14 00:08:40 +00001179 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1180 Display *display = thread_data->display;
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001181 struct x11drv_win_data *data;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001182
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001183 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001184
Chris Robinson37d835b2007-09-26 08:17:13 -07001185 if (data->pixmap)
1186 {
1187 destroy_glxpixmap(display, data->gl_drawable);
1188 wine_tsx11_lock();
1189 XFreePixmap(display, data->pixmap);
1190 wine_tsx11_unlock();
1191 }
1192 else if (data->gl_drawable)
Chris Robinson00633e32007-09-25 22:43:38 -07001193 {
1194 wine_tsx11_lock();
1195 XDestroyWindow(display, data->gl_drawable);
1196 wine_tsx11_unlock();
1197 }
1198
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001199 destroy_whole_window( display, data, FALSE );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001200 destroy_icon_window( display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001201
Alexandre Julliarde9307d02008-02-21 20:23:32 +01001202 if (data->colormap)
1203 {
1204 wine_tsx11_lock();
1205 XFreeColormap( display, data->colormap );
1206 wine_tsx11_unlock();
1207 }
1208
Alexandre Julliardf777d702005-01-31 16:34:07 +00001209 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001210 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
1211 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001212 wine_tsx11_lock();
Alexandre Julliarde5515552005-02-09 14:01:40 +00001213 XDeleteContext( display, (XID)hwnd, win_data_context );
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001214 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001215 HeapFree( GetProcessHeap(), 0, data );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001216}
1217
1218
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001219/***********************************************************************
1220 * X11DRV_DestroyNotify
1221 */
1222void X11DRV_DestroyNotify( HWND hwnd, XEvent *event )
1223{
1224 Display *display = event->xdestroywindow.display;
1225 struct x11drv_win_data *data;
1226
1227 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1228
1229 FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window );
1230 destroy_whole_window( display, data, TRUE );
1231}
1232
1233
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001234static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
1235{
1236 struct x11drv_win_data *data;
1237
Alexandre Julliard30d84fc2008-01-22 10:15:38 +01001238 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001239 {
Alexandre Julliard30d84fc2008-01-22 10:15:38 +01001240 data->hwnd = hwnd;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001241 wine_tsx11_lock();
1242 if (!winContext) winContext = XUniqueContext();
1243 if (!win_data_context) win_data_context = XUniqueContext();
1244 XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
1245 wine_tsx11_unlock();
1246 }
1247 return data;
1248}
1249
1250
Alexandre Julliardc19af912008-01-17 19:53:59 +01001251/* initialize the desktop window id in the desktop manager process */
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001252static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd )
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001253{
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001254 struct x11drv_win_data *data;
1255 VisualID visualid;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001256
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001257 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1258 wine_tsx11_lock();
1259 visualid = XVisualIDFromVisual(visual);
1260 wine_tsx11_unlock();
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001261 data->whole_window = data->client_window = root_window;
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001262 data->managed = TRUE;
1263 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1264 SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001265 SetPropA( data->hwnd, client_window_prop, (HANDLE)root_window );
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001266 set_initial_wm_hints( display, data );
1267 return data;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001268}
1269
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001270/**********************************************************************
1271 * CreateDesktopWindow (X11DRV.@)
1272 */
1273BOOL X11DRV_CreateDesktopWindow( HWND hwnd )
1274{
Alexandre Julliardc19af912008-01-17 19:53:59 +01001275 unsigned int width, height;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001276
Alexandre Julliardc19af912008-01-17 19:53:59 +01001277 /* retrieve the real size of the desktop */
1278 SERVER_START_REQ( get_window_rectangles )
1279 {
1280 req->handle = hwnd;
1281 wine_server_call( req );
1282 width = reply->window.right - reply->window.left;
1283 height = reply->window.bottom - reply->window.top;
1284 }
1285 SERVER_END_REQ;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001286
Alexandre Julliardc19af912008-01-17 19:53:59 +01001287 if (!width && !height) /* not initialized yet */
1288 {
1289 SERVER_START_REQ( set_window_pos )
1290 {
1291 req->handle = hwnd;
1292 req->previous = 0;
1293 req->flags = SWP_NOZORDER;
1294 req->window.left = virtual_screen_rect.left;
1295 req->window.top = virtual_screen_rect.top;
1296 req->window.right = virtual_screen_rect.right;
1297 req->window.bottom = virtual_screen_rect.bottom;
1298 req->client = req->window;
1299 wine_server_call( req );
1300 }
1301 SERVER_END_REQ;
1302 }
1303 else
1304 {
1305 Window win = (Window)GetPropA( hwnd, whole_window_prop );
1306 if (win && win != root_window) X11DRV_init_desktop( win, width, height );
1307 }
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001308 return TRUE;
1309}
1310
1311
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001312/**********************************************************************
1313 * CreateWindow (X11DRV.@)
1314 */
Alexandre Julliardd6f67452008-01-24 11:23:09 +01001315BOOL X11DRV_CreateWindow( HWND hwnd )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001316{
1317 Display *display = thread_display();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001318
Alexandre Julliard026974f2008-01-24 10:20:51 +01001319 if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( display ))
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001320 {
Alexandre Julliard026974f2008-01-24 10:20:51 +01001321 /* the desktop win data can't be created lazily */
1322 if (!create_desktop_win_data( display, hwnd )) return FALSE;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001323 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001324 return TRUE;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001325}
1326
1327
1328/***********************************************************************
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001329 * X11DRV_get_win_data
1330 *
1331 * Return the X11 data structure associated with a window.
1332 */
1333struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1334{
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001335 char *data;
Alexandre Julliarde5515552005-02-09 14:01:40 +00001336
1337 if (!hwnd || XFindContext( thread_display(), (XID)hwnd, win_data_context, &data )) data = NULL;
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001338 return (struct x11drv_win_data *)data;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001339}
1340
1341
1342/***********************************************************************
Alexandre Julliard026974f2008-01-24 10:20:51 +01001343 * X11DRV_create_win_data
1344 *
1345 * Create an X11 data window structure for an existing window.
1346 */
1347struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd )
1348{
1349 Display *display = thread_display();
1350 struct x11drv_win_data *data;
1351 HWND parent;
1352
1353 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
1354 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1355
1356 GetWindowRect( hwnd, &data->window_rect );
1357 MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 );
1358 data->whole_rect = data->window_rect;
1359 GetClientRect( hwnd, &data->client_rect );
1360 MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 );
1361
1362 if (parent == GetDesktopWindow())
1363 {
1364 if (!create_whole_window( display, data ))
1365 {
1366 HeapFree( GetProcessHeap(), 0, data );
1367 return NULL;
1368 }
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001369 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1370 hwnd, data->whole_window, data->client_window, wine_dbgstr_rect( &data->window_rect ),
Alexandre Julliard026974f2008-01-24 10:20:51 +01001371 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
1372 }
Alexandre Julliard026974f2008-01-24 10:20:51 +01001373 return data;
1374}
1375
1376
1377/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001378 * X11DRV_get_whole_window
1379 *
1380 * Return the X window associated with the full area of a window
1381 */
1382Window X11DRV_get_whole_window( HWND hwnd )
1383{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001384 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001385
Alexandre Julliardc19af912008-01-17 19:53:59 +01001386 if (!data)
1387 {
1388 if (hwnd == GetDesktopWindow()) return root_window;
1389 return (Window)GetPropA( hwnd, whole_window_prop );
1390 }
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001391 return data->whole_window;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001392}
1393
1394
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001395/***********************************************************************
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001396 * X11DRV_get_client_window
1397 *
1398 * Return the X window associated with the client area of a window
1399 */
1400Window X11DRV_get_client_window( HWND hwnd )
1401{
1402 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1403
1404 if (!data)
1405 {
1406 if (hwnd == GetDesktopWindow()) return root_window;
1407 return (Window)GetPropA( hwnd, client_window_prop );
1408 }
1409 return data->client_window;
1410}
1411
1412
1413/***********************************************************************
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001414 * X11DRV_get_ic
1415 *
1416 * Return the X input context associated with a window
1417 */
1418XIC X11DRV_get_ic( HWND hwnd )
1419{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001420 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Kusanagi Kouichi185157c2008-04-04 20:44:36 +09001421 XIM xim;
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001422
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001423 if (!data) return 0;
Kusanagi Kouichi185157c2008-04-04 20:44:36 +09001424 if (data->xic) return data->xic;
1425 if (!(xim = x11drv_thread_data()->xim)) return 0;
1426 return X11DRV_CreateIC( xim, data );
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001427}
1428
1429
Alexandre Julliard1642fbc2008-02-25 15:59:19 +01001430/***********************************************************************
1431 * X11DRV_GetDC (X11DRV.@)
1432 */
1433void X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect,
1434 const RECT *top_rect, DWORD flags )
1435{
1436 struct x11drv_escape_set_drawable escape;
1437 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1438
1439 escape.code = X11DRV_SET_DRAWABLE;
1440 escape.mode = IncludeInferiors;
1441 escape.fbconfig_id = 0;
1442 escape.gl_drawable = 0;
1443 escape.pixmap = 0;
1444
1445 if (top == hwnd && data && IsIconic( hwnd ) && data->icon_window)
1446 {
1447 escape.drawable = data->icon_window;
1448 }
1449 else if (top == hwnd && (flags & DCX_WINDOW))
1450 {
1451 escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd );
1452 }
1453 else
1454 {
1455 escape.drawable = X11DRV_get_client_window( top );
1456 escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop );
1457 escape.gl_drawable = data ? data->gl_drawable : (Drawable)GetPropA( hwnd, gl_drawable_prop );
1458 escape.pixmap = data ? data->pixmap : (Pixmap)GetPropA( hwnd, pixmap_prop );
Alexandre Julliardaf369102008-03-18 12:42:25 +01001459 if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren;
Alexandre Julliard1642fbc2008-02-25 15:59:19 +01001460 }
1461
1462 escape.dc_rect.left = win_rect->left - top_rect->left;
1463 escape.dc_rect.top = win_rect->top - top_rect->top;
1464 escape.dc_rect.right = win_rect->right - top_rect->left;
1465 escape.dc_rect.bottom = win_rect->bottom - top_rect->top;
1466 escape.drawable_rect.left = top_rect->left;
1467 escape.drawable_rect.top = top_rect->top;
1468 escape.drawable_rect.right = top_rect->right;
1469 escape.drawable_rect.bottom = top_rect->bottom;
1470
1471 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1472}
1473
1474
1475/***********************************************************************
1476 * X11DRV_ReleaseDC (X11DRV.@)
1477 */
1478void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
1479{
1480 struct x11drv_escape_set_drawable escape;
1481
1482 escape.code = X11DRV_SET_DRAWABLE;
1483 escape.drawable = root_window;
1484 escape.mode = IncludeInferiors;
1485 escape.drawable_rect = virtual_screen_rect;
1486 SetRect( &escape.dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left,
1487 virtual_screen_rect.bottom - virtual_screen_rect.top );
1488 escape.fbconfig_id = 0;
1489 escape.gl_drawable = 0;
1490 escape.pixmap = 0;
1491 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1492}
1493
1494
Alexandre Julliarddc26f272008-03-12 15:01:24 +01001495/***********************************************************************
1496 * SetCapture (X11DRV.@)
1497 */
1498void X11DRV_SetCapture( HWND hwnd, UINT flags )
1499{
1500 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1501
Alexandre Julliard78de7e32008-03-24 17:59:40 +01001502 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
Alexandre Julliarddc26f272008-03-12 15:01:24 +01001503
1504 if (hwnd)
1505 {
1506 Window grab_win = X11DRV_get_client_window( GetAncestor( hwnd, GA_ROOT ) );
1507
1508 if (!grab_win) return;
1509 wine_tsx11_lock();
1510 XFlush( gdi_display );
1511 XGrabPointer( thread_data->display, grab_win, False,
1512 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
Alexandre Julliard78de7e32008-03-24 17:59:40 +01001513 GrabModeAsync, GrabModeAsync, None, None, CurrentTime );
Alexandre Julliarddc26f272008-03-12 15:01:24 +01001514 wine_tsx11_unlock();
1515 thread_data->grab_window = grab_win;
1516 }
1517 else /* release capture */
1518 {
1519 wine_tsx11_lock();
1520 XFlush( gdi_display );
1521 XUngrabPointer( thread_data->display, CurrentTime );
1522 wine_tsx11_unlock();
1523 thread_data->grab_window = None;
1524 }
1525}
1526
1527
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001528/*****************************************************************
1529 * SetParent (X11DRV.@)
1530 */
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001531void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001532{
Alexandre Julliard43230042001-05-16 19:52:29 +00001533 Display *display = thread_display();
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001534 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001535
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001536 if (!data) return;
1537 if (parent == old_parent) return;
Alexandre Julliardfb0ff052001-10-16 21:58:58 +00001538
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001539 if (parent != GetDesktopWindow()) /* a child window */
Alexandre Julliard4d32a472005-03-25 10:38:56 +00001540 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001541 if (old_parent == GetDesktopWindow())
Alexandre Julliard4d32a472005-03-25 10:38:56 +00001542 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001543 /* destroy the old X windows */
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001544 destroy_whole_window( display, data, FALSE );
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001545 destroy_icon_window( display, data );
1546 if (data->managed)
Alexandre Julliardf777d702005-01-31 16:34:07 +00001547 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001548 data->managed = FALSE;
1549 RemovePropA( data->hwnd, managed_prop );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001550 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001551 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001552 }
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001553 else /* new top level window */
1554 {
1555 /* FIXME: we ignore errors since we can't really recover anyway */
Alexandre Julliardd147e022008-01-23 21:39:32 +01001556 create_whole_window( display, data );
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001557 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001558}
1559
1560
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001561/*****************************************************************
1562 * SetFocus (X11DRV.@)
1563 *
1564 * Set the X focus.
1565 * Explicit colormap management seems to work only with OLVWM.
1566 */
1567void X11DRV_SetFocus( HWND hwnd )
1568{
Alexandre Julliard43230042001-05-16 19:52:29 +00001569 Display *display = thread_display();
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001570 struct x11drv_win_data *data;
Alexandre Julliard125793d2008-02-18 17:22:51 +01001571 XWindowChanges changes;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001572
Alexandre Julliard125793d2008-02-18 17:22:51 +01001573 /* If setting the focus to 0, uninstall the colormap */
1574 if (!hwnd && root_window == DefaultRootWindow(display))
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001575 {
Alexandre Julliard2496c082003-11-21 00:17:33 +00001576 wine_tsx11_lock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001577 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
Alexandre Julliard2496c082003-11-21 00:17:33 +00001578 XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1579 wine_tsx11_unlock();
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001580 return;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001581 }
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001582
1583 hwnd = GetAncestor( hwnd, GA_ROOT );
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001584
1585 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Todd Mokros88ac4b92005-08-22 09:14:21 +00001586 if (data->managed || !data->whole_window) return;
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001587
1588 /* Set X focus and install colormap */
1589 wine_tsx11_lock();
Alexandre Julliard125793d2008-02-18 17:22:51 +01001590 changes.stack_mode = Above;
1591 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
1592 if (root_window == DefaultRootWindow(display))
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001593 {
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001594 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1595 /* FIXME: this is not entirely correct */
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001596 XSetInputFocus( display, data->whole_window, RevertToParent,
Jeremy White77502e72005-01-14 17:06:40 +00001597 /* CurrentTime */
1598 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001599 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1600 XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001601 }
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001602 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001603}
1604
1605
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001606/**********************************************************************
Patrik Stridvall01d5e5b2001-07-02 19:59:40 +00001607 * SetWindowIcon (X11DRV.@)
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001608 *
1609 * hIcon or hIconSm has changed (or is being initialised for the
1610 * first time). Complete the X11 driver-specific initialisation
1611 * and set the window hints.
1612 *
1613 * This is not entirely correct, may need to create
1614 * an icon window and set the pixmap as a background
1615 */
Alexandre Julliard446d8322003-12-31 23:51:52 +00001616void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001617{
Alexandre Julliard43230042001-05-16 19:52:29 +00001618 Display *display = thread_display();
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001619 struct x11drv_win_data *data;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001620
Alexandre Julliard446d8322003-12-31 23:51:52 +00001621 if (type != ICON_BIG) return; /* nothing to do here */
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001622
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001623 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Alexandre Julliardf777d702005-01-31 16:34:07 +00001624 if (!data->whole_window) return;
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001625 if (!data->managed) return;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001626
Alexandre Julliardbde89572007-08-16 23:27:37 +02001627 if (data->wm_hints)
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001628 {
Alexandre Julliardbde89572007-08-16 23:27:37 +02001629 set_icon_hints( display, data, icon );
Alexandre Julliarde9119c12002-09-24 18:36:51 +00001630 wine_tsx11_lock();
Alexandre Julliardbde89572007-08-16 23:27:37 +02001631 XSetWMHints( display, data->whole_window, data->wm_hints );
Alexandre Julliarde9119c12002-09-24 18:36:51 +00001632 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001633 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001634}
Alexandre Julliard395928d2008-01-23 16:30:18 +01001635
1636
1637/***********************************************************************
1638 * SetWindowRgn (X11DRV.@)
1639 *
1640 * Assign specified region to window (for non-rectangular windows)
1641 */
1642int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1643{
1644 struct x11drv_win_data *data;
1645
1646 if ((data = X11DRV_get_win_data( hwnd )))
1647 {
1648 sync_window_region( thread_display(), data, hrgn );
Alexandre Julliard395928d2008-01-23 16:30:18 +01001649 }
1650 else if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
1651 {
1652 FIXME( "not supported on other thread window %p\n", hwnd );
1653 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1654 return FALSE;
1655 }
1656
1657 return TRUE;
1658}
Alexandre Julliard24dbaa02008-04-17 16:13:34 +02001659
1660
1661/***********************************************************************
1662 * is_netwm_supported
1663 */
1664static BOOL is_netwm_supported( Display *display, Atom atom )
1665{
1666 static Atom *net_supported;
1667 static int net_supported_count = -1;
1668 int i;
1669
1670 wine_tsx11_lock();
1671 if (net_supported_count == -1)
1672 {
1673 Atom type;
1674 int format;
1675 unsigned long count, remaining;
1676
1677 if (!XGetWindowProperty( display, DefaultRootWindow(display), x11drv_atom(_NET_SUPPORTED), 0,
1678 ~0UL, False, XA_ATOM, &type, &format, &count,
1679 &remaining, (unsigned char **)&net_supported ))
1680 net_supported_count = get_property_size( format, count ) / sizeof(Atom);
1681 else
1682 net_supported_count = 0;
1683 }
1684 wine_tsx11_unlock();
1685
1686 for (i = 0; i < net_supported_count; i++)
1687 if (net_supported[i] == atom) return TRUE;
1688 return FALSE;
1689}
1690
1691
1692/***********************************************************************
1693 * SysCommand (X11DRV.@)
1694 *
1695 * Perform WM_SYSCOMMAND handling.
1696 */
1697LRESULT X11DRV_SysCommand( HWND hwnd, WPARAM wparam, LPARAM lparam )
1698{
1699 WPARAM hittest = wparam & 0x0f;
1700 DWORD dwPoint;
1701 int x, y, dir;
1702 XEvent xev;
1703 Display *display = thread_display();
1704 struct x11drv_win_data *data;
1705
1706 if (!(data = X11DRV_get_win_data( hwnd ))) return -1;
1707 if (!data->whole_window || !data->managed || !data->mapped) return -1;
1708
1709 switch (wparam & 0xfff0)
1710 {
1711 case SC_MOVE:
1712 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
1713 else dir = _NET_WM_MOVERESIZE_MOVE;
1714 break;
1715 case SC_SIZE:
1716 /* windows without WS_THICKFRAME are not resizable through the window manager */
1717 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) return -1;
1718
1719 switch (hittest)
1720 {
1721 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
1722 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
1723 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
1724 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
1725 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
1726 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
1727 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
1728 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
1729 default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break;
1730 }
1731 break;
1732
1733 case SC_KEYMENU:
1734 /* prevent a simple ALT press+release from activating the system menu,
1735 * as that can get confusing on managed windows */
1736 if ((WCHAR)lparam) return -1; /* got an explicit char */
1737 if (GetMenu( hwnd )) return -1; /* window has a real menu */
1738 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_SYSMENU)) return -1; /* no system menu */
1739 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam, lparam );
1740 return 0;
1741
1742 default:
1743 return -1;
1744 }
1745
1746 if (IsZoomed(hwnd)) return -1;
1747
1748 if (!is_netwm_supported( display, x11drv_atom(_NET_WM_MOVERESIZE) ))
1749 {
1750 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
1751 return -1;
1752 }
1753
1754 dwPoint = GetMessagePos();
1755 x = (short)LOWORD(dwPoint);
1756 y = (short)HIWORD(dwPoint);
1757
1758 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd, x, y, dir);
1759
1760 xev.xclient.type = ClientMessage;
1761 xev.xclient.window = X11DRV_get_whole_window(hwnd);
1762 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
1763 xev.xclient.serial = 0;
1764 xev.xclient.display = display;
1765 xev.xclient.send_event = True;
1766 xev.xclient.format = 32;
1767 xev.xclient.data.l[0] = x; /* x coord */
1768 xev.xclient.data.l[1] = y; /* y coord */
1769 xev.xclient.data.l[2] = dir; /* direction */
1770 xev.xclient.data.l[3] = 1; /* button */
1771 xev.xclient.data.l[4] = 0; /* unused */
1772
1773 /* need to ungrab the pointer that may have been automatically grabbed
1774 * with a ButtonPress event */
1775 wine_tsx11_lock();
1776 XUngrabPointer( display, CurrentTime );
1777 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
1778 wine_tsx11_unlock();
1779 return 0;
1780}