blob: 5aa01d9874c24ee539f6c96c1fd7531a07909e70 [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"
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000049#include "win.h"
Ove Kaaven77e7fd72002-01-21 18:41:27 +000050#include "mwm.h"
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000051
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000052WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000053
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000054/* X context to associate a hwnd to an X window */
55XContext winContext = 0;
56
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +000057/* X context to associate a struct x11drv_win_data to an hwnd */
58static XContext win_data_context;
59
Alexandre Julliardaf50ad62005-07-07 17:30:57 +000060static const char whole_window_prop[] = "__wine_x11_whole_window";
61static const char icon_window_prop[] = "__wine_x11_icon_window";
Chris Robinsond9571c92007-09-15 13:02:32 -070062static const char fbconfig_id_prop[] = "__wine_x11_fbconfig_id";
Chris Robinsona8124f92007-09-25 10:20:58 -070063static const char gl_drawable_prop[] = "__wine_x11_gl_drawable";
Chris Robinson37d835b2007-09-26 08:17:13 -070064static const char pixmap_prop[] = "__wine_x11_pixmap";
Alexandre Julliardaf50ad62005-07-07 17:30:57 +000065static const char managed_prop[] = "__wine_x11_managed";
66static const char visual_id_prop[] = "__wine_x11_visual_id";
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000067
James Liggett60a97502006-08-22 17:14:11 -070068/* for XDG systray icons */
69#define SYSTEM_TRAY_REQUEST_DOCK 0
70
Chris Robinson00633e32007-09-25 22:43:38 -070071extern int usexcomposite;
72
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000073/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +000074 * is_window_managed
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000075 *
Alexandre Julliarddc4fe772001-06-04 21:55:17 +000076 * Check if a given window should be managed
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000077 */
Alexandre Julliardeffdfa72007-08-27 12:37:14 +020078BOOL is_window_managed( HWND hwnd, UINT swp_flags, const RECT *window_rect )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000079{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000080 DWORD style, ex_style;
81
Alexandre Julliard89131822008-01-24 10:21:07 +010082 if (!managed_mode) return FALSE;
83
Alexandre Julliarddc4fe772001-06-04 21:55:17 +000084 /* child windows are not managed */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000085 style = GetWindowLongW( hwnd, GWL_STYLE );
Peter Dons Tychsend0b21ab2007-07-25 04:09:50 +020086 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD) return FALSE;
Alexandre Julliardeffdfa72007-08-27 12:37:14 +020087 /* activated windows are managed */
88 if (!(swp_flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) return TRUE;
89 if (hwnd == GetActiveWindow()) return TRUE;
Mike Hearn27d972f2003-12-04 21:54:13 +000090 /* windows with caption are managed */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000091 if ((style & WS_CAPTION) == WS_CAPTION) return TRUE;
Mike Hearn27d972f2003-12-04 21:54:13 +000092 /* tool windows are not managed */
Alexandre Julliardcbdf1292008-01-23 21:40:45 +010093 ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE );
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000094 if (ex_style & WS_EX_TOOLWINDOW) return FALSE;
Mike Hearn27d972f2003-12-04 21:54:13 +000095 /* windows with thick frame are managed */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000096 if (style & WS_THICKFRAME) return TRUE;
Jerry Jenkins4e6fab52003-12-13 00:05:53 +000097 /* application windows are managed */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000098 if (ex_style & WS_EX_APPWINDOW) return TRUE;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000099 if (style & WS_POPUP)
Alex Pasadynd18c8ca2004-02-06 05:17:55 +0000100 {
Vitaliy Margolenabcbcc32007-02-10 10:40:50 -0700101 /* popup with sysmenu == caption are managed */
102 if (style & WS_SYSMENU) return TRUE;
103 /* full-screen popup windows are managed */
Alexandre Julliardac98e0c2007-08-20 22:06:33 +0200104 if ((window_rect->right - window_rect->left) == screen_width &&
105 (window_rect->bottom - window_rect->top) == screen_height)
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000106 return TRUE;
Alex Pasadynd18c8ca2004-02-06 05:17:55 +0000107 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000108 /* default: not managed */
109 return FALSE;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000110}
111
112
113/***********************************************************************
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000114 * X11DRV_is_window_rect_mapped
115 *
116 * Check if the X whole window should be mapped based on its rectangle
117 */
118BOOL X11DRV_is_window_rect_mapped( const RECT *rect )
119{
120 /* don't map if rect is empty */
121 if (IsRectEmpty( rect )) return FALSE;
122
123 /* don't map if rect is off-screen */
Alexandre Julliard3c305f92006-10-23 14:37:17 +0200124 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)
128 return FALSE;
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000129
130 return TRUE;
131}
132
133
134/***********************************************************************
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200135 * get_mwm_decorations
136 */
137static unsigned long get_mwm_decorations( DWORD style, DWORD ex_style )
138{
139 unsigned long ret = 0;
140
141 if (ex_style & WS_EX_TOOLWINDOW) return 0;
142
143 if ((style & WS_CAPTION) == WS_CAPTION)
144 {
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;
149 }
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;
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200153 return ret;
154}
155
156
157/***********************************************************************
158 * get_x11_rect_offset
159 *
160 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
161 */
162static void get_x11_rect_offset( struct x11drv_win_data *data, RECT *rect )
163{
164 DWORD style, ex_style, style_mask = 0, ex_style_mask = 0;
165 unsigned long decor;
166
167 rect->top = rect->bottom = rect->left = rect->right = 0;
168
169 style = GetWindowLongW( data->hwnd, GWL_STYLE );
170 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
171 decor = get_mwm_decorations( style, ex_style );
172
173 if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION;
174 if (decor & MWM_DECOR_BORDER)
175 {
176 style_mask |= WS_DLGFRAME | WS_THICKFRAME;
177 ex_style_mask |= WS_EX_DLGMODALFRAME;
178 }
179
180 AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask );
181}
182
183
184/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000185 * get_window_attributes
186 *
Alexandre Julliard883cff42001-06-12 04:02:10 +0000187 * Fill the window attributes structure for an X window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000188 */
Alexandre Julliard6bb18e22006-03-27 15:33:43 +0200189static int get_window_attributes( Display *display, struct x11drv_win_data *data,
190 XSetWindowAttributes *attr )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000191{
Alexandre Julliardd7726c32005-02-01 18:53:59 +0000192 attr->override_redirect = !data->managed;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000193 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000194 attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0);
Alexandre Julliard9428f062002-06-14 00:08:40 +0000195 attr->cursor = x11drv_thread_data()->cursor;
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200196 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;
202
203 return (CWOverrideRedirect | CWSaveUnder | CWColormap | CWCursor |
204 CWEventMask | CWBitGravity | CWBackingStore);
Alexandre Julliard883cff42001-06-12 04:02:10 +0000205}
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000206
Alexandre Julliard883cff42001-06-12 04:02:10 +0000207
208/***********************************************************************
Alexandre Julliard911a1772002-08-20 00:36:45 +0000209 * X11DRV_sync_window_style
Alexandre Julliard883cff42001-06-12 04:02:10 +0000210 *
211 * Change the X window attributes when the window style has changed.
212 */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000213void X11DRV_sync_window_style( Display *display, struct x11drv_win_data *data )
Alexandre Julliard883cff42001-06-12 04:02:10 +0000214{
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200215 if (data->whole_window != root_window)
216 {
217 XSetWindowAttributes attr;
218 int mask = get_window_attributes( display, data, &attr );
Alexandre Julliard883cff42001-06-12 04:02:10 +0000219
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200220 wine_tsx11_lock();
Alexandre Julliard6d5f5442006-03-06 21:02:59 +0100221 XChangeWindowAttributes( display, data->whole_window, mask, &attr );
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200222 wine_tsx11_unlock();
223 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000224}
225
226
227/***********************************************************************
Alexandre Julliard395928d2008-01-23 16:30:18 +0100228 * sync_window_region
229 *
230 * Update the X11 window region.
231 */
232static void sync_window_region( Display *display, struct x11drv_win_data *data, HRGN hrgn )
233{
234#ifdef HAVE_LIBXSHAPE
235 if (!data->whole_window) return;
236
237 if (!hrgn)
238 {
239 wine_tsx11_lock();
240 XShapeCombineMask( display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet );
241 wine_tsx11_unlock();
242 }
243 else
244 {
245 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
246 if (pRegionData)
247 {
248 wine_tsx11_lock();
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 );
254 wine_tsx11_unlock();
255 HeapFree(GetProcessHeap(), 0, pRegionData);
256 }
257 }
258#endif /* HAVE_LIBXSHAPE */
259}
260
261
262/***********************************************************************
Alexandre Julliard3ba20252008-01-23 16:32:55 +0100263 * sync_window_text
264 */
265static void sync_window_text( Display *display, Window win, const WCHAR *text )
266{
267 UINT count;
268 char *buffer, *utf8_buffer;
269 XTextProperty prop;
270
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);
275
276 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
277 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
278 {
279 HeapFree( GetProcessHeap(), 0, buffer );
280 return;
281 }
282 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
283
284 wine_tsx11_lock();
285 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
286 {
287 XSetWMName( display, win, &prop );
288 XSetWMIconName( display, win, &prop );
289 XFree( prop.value );
290 }
291 /*
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 ).
295 */
296 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
297 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
298 wine_tsx11_unlock();
299
300 HeapFree( GetProcessHeap(), 0, utf8_buffer );
301 HeapFree( GetProcessHeap(), 0, buffer );
302}
303
304
305/***********************************************************************
Chris Robinsond9571c92007-09-15 13:02:32 -0700306 * X11DRV_set_win_format
307 */
308BOOL X11DRV_set_win_format( HWND hwnd, XID fbconfig_id )
309{
Chris Robinson00633e32007-09-25 22:43:38 -0700310 Display *display = thread_display();
Chris Robinsond9571c92007-09-15 13:02:32 -0700311 struct x11drv_win_data *data;
Chris Robinson00633e32007-09-25 22:43:38 -0700312 XVisualInfo *vis;
313 Drawable parent;
314 HWND next_hwnd;
315 int w, h;
Chris Robinsond9571c92007-09-15 13:02:32 -0700316
Alexandre Julliard026974f2008-01-24 10:20:51 +0100317 if (!(data = X11DRV_get_win_data(hwnd)) &&
318 !(data = X11DRV_create_win_data(hwnd))) return FALSE;
Chris Robinsond9571c92007-09-15 13:02:32 -0700319
Chris Robinson00633e32007-09-25 22:43:38 -0700320 wine_tsx11_lock();
321
322 vis = visual_from_fbconfig_id(fbconfig_id);
Michael Stefaniuc4e2eef22007-10-21 01:15:53 +0200323 if(!vis)
324 {
325 wine_tsx11_unlock();
326 return FALSE;
327 }
Chris Robinson00633e32007-09-25 22:43:38 -0700328
329 if(data->whole_window && vis->visualid == XVisualIDFromVisual(visual))
330 {
331 TRACE("Whole window available and visual match, rendering onscreen\n");
332 goto done;
333 }
334
335 wine_tsx11_unlock();
336
337 parent = data->whole_window;
338 next_hwnd = hwnd;
339 while(!parent)
340 {
341 next_hwnd = GetAncestor(next_hwnd, GA_PARENT);
342 if(!next_hwnd)
343 {
344 ERR("Could not find parent HWND with a drawable!\n");
345 return FALSE;
346 }
347 parent = X11DRV_get_whole_window(next_hwnd);
348 }
349
350 w = data->client_rect.right - data->client_rect.left;
351 h = data->client_rect.bottom - data->client_rect.top;
352
353 if(w <= 0) w = 1;
354 if(h <= 0) h = 1;
355
356 wine_tsx11_lock();
357#ifdef SONAME_LIBXCOMPOSITE
358 if(usexcomposite)
359 {
360 XSetWindowAttributes attrib;
361
362 attrib.override_redirect = True;
363 attrib.colormap = XCreateColormap(display, parent, vis->visual,
364 (vis->class == PseudoColor ||
365 vis->class == GrayScale ||
366 vis->class == DirectColor) ?
367 AllocAll : AllocNone);
368 XInstallColormap(gdi_display, attrib.colormap);
369
370 data->gl_drawable = XCreateWindow(display, parent, -w, 0, w, h, 0,
371 vis->depth, InputOutput, vis->visual,
372 CWColormap | CWOverrideRedirect,
373 &attrib);
374 if(data->gl_drawable)
375 {
376 pXCompositeRedirectWindow(display, data->gl_drawable,
377 CompositeRedirectManual);
378 XMapWindow(display, data->gl_drawable);
379 }
380 }
Chris Robinson37d835b2007-09-26 08:17:13 -0700381 else
Chris Robinson00633e32007-09-25 22:43:38 -0700382#endif
Chris Robinson37d835b2007-09-26 08:17:13 -0700383 {
384 WARN("XComposite is not available, using GLXPixmap hack\n");
385
386 data->pixmap = XCreatePixmap(display, parent, w, h, vis->depth);
387 if(!data->pixmap)
388 {
389 ERR("Failed to create pixmap for offscreen rendering\n");
390 XFree(vis);
391 wine_tsx11_unlock();
392 return FALSE;
393 }
394
395 data->gl_drawable = create_glxpixmap(display, vis, data->pixmap);
396 if(!data->gl_drawable)
397 {
398 XFreePixmap(display, data->pixmap);
399 data->pixmap = 0;
400 }
401 }
Chris Robinson00633e32007-09-25 22:43:38 -0700402
403 if(!data->gl_drawable)
404 {
405 ERR("Failed to create drawable for offscreen rendering\n");
406 XFree(vis);
407 wine_tsx11_unlock();
408 return FALSE;
409 }
410
411done:
412 XFree(vis);
413
414 XFlush(display);
415 wine_tsx11_unlock();
416
417 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
418 data->gl_drawable, fbconfig_id);
419
Chris Robinsond9571c92007-09-15 13:02:32 -0700420 data->fbconfig_id = fbconfig_id;
421 SetPropA(hwnd, fbconfig_id_prop, (HANDLE)data->fbconfig_id);
Chris Robinson00633e32007-09-25 22:43:38 -0700422 SetPropA(hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
Chris Robinson37d835b2007-09-26 08:17:13 -0700423 SetPropA(hwnd, pixmap_prop, (HANDLE)data->pixmap);
Alexandre Julliard12b49302007-09-17 16:57:09 +0200424 invalidate_dce( hwnd, &data->window_rect );
Chris Robinsond9571c92007-09-15 13:02:32 -0700425 return TRUE;
426}
427
Alexandre Julliardbbfbe242008-01-23 12:28:01 +0100428/***********************************************************************
429 * X11DRV_sync_gl_drawable
430 */
431void X11DRV_sync_gl_drawable(Display *display, struct x11drv_win_data *data)
Chris Robinson00633e32007-09-25 22:43:38 -0700432{
433 int w = data->client_rect.right - data->client_rect.left;
434 int h = data->client_rect.bottom - data->client_rect.top;
Chris Robinson37d835b2007-09-26 08:17:13 -0700435 XVisualInfo *vis;
436 Drawable parent;
437 HWND next_hwnd;
438 Drawable glxp;
439 Pixmap pix;
Chris Robinson00633e32007-09-25 22:43:38 -0700440
Chris Robinson00633e32007-09-25 22:43:38 -0700441 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data->gl_drawable, w, h);
442#ifdef SONAME_LIBXCOMPOSITE
443 if(usexcomposite)
444 {
445 wine_tsx11_lock();
446 XMoveResizeWindow(display, data->gl_drawable, -w, 0, w, h);
447 wine_tsx11_unlock();
448 return;
449 }
450#endif
Chris Robinson37d835b2007-09-26 08:17:13 -0700451
452 parent = data->whole_window;
453 next_hwnd = data->hwnd;
454 while(!parent)
455 {
456 next_hwnd = GetAncestor(next_hwnd, GA_PARENT);
457 if(!next_hwnd)
458 {
459 ERR("Could not find parent HWND with a drawable!\n");
460 return;
461 }
462 parent = X11DRV_get_whole_window(next_hwnd);
463 }
464
465 wine_tsx11_lock();
466
467 vis = visual_from_fbconfig_id(data->fbconfig_id);
Michael Stefaniuc4e2eef22007-10-21 01:15:53 +0200468 if(!vis)
469 {
470 wine_tsx11_unlock();
471 return;
472 }
Chris Robinson37d835b2007-09-26 08:17:13 -0700473
474 pix = XCreatePixmap(display, parent, w, h, vis->depth);
475 if(!pix)
476 {
477 ERR("Failed to create pixmap for offscreen rendering\n");
478 XFree(vis);
479 wine_tsx11_unlock();
480 return;
481 }
482
483 glxp = create_glxpixmap(display, vis, pix);
484 if(!glxp)
485 {
486 ERR("Failed to create drawable for offscreen rendering\n");
487 XFreePixmap(display, pix);
488 XFree(vis);
489 wine_tsx11_unlock();
490 return;
491 }
492
493 XFree(vis);
494
495 mark_drawable_dirty(data->gl_drawable, glxp);
496
497 XFreePixmap(display, data->pixmap);
498 destroy_glxpixmap(display, data->gl_drawable);
499
500 data->pixmap = pix;
501 data->gl_drawable = glxp;
502
503 XFlush(display);
504 wine_tsx11_unlock();
505
506 SetPropA(data->hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
507 SetPropA(data->hwnd, pixmap_prop, (HANDLE)data->pixmap);
508 invalidate_dce( data->hwnd, &data->window_rect );
Chris Robinson00633e32007-09-25 22:43:38 -0700509}
510
Chris Robinsond9571c92007-09-15 13:02:32 -0700511
512/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000513 * get_window_changes
514 *
515 * fill the window changes structure
516 */
517static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
518{
519 int mask = 0;
520
521 if (old->right - old->left != new->right - new->left )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000522 {
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000523 if (!(changes->width = new->right - new->left)) changes->width = 1;
524 mask |= CWWidth;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000525 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000526 if (old->bottom - old->top != new->bottom - new->top)
527 {
528 if (!(changes->height = new->bottom - new->top)) changes->height = 1;
529 mask |= CWHeight;
530 }
531 if (old->left != new->left)
532 {
533 changes->x = new->left;
534 mask |= CWX;
535 }
536 if (old->top != new->top)
537 {
538 changes->y = new->top;
539 mask |= CWY;
540 }
541 return mask;
542}
543
544
545/***********************************************************************
546 * create_icon_window
547 */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000548static Window create_icon_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000549{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000550 XSetWindowAttributes attr;
551
552 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
Alexandre Julliard9428f062002-06-14 00:08:40 +0000553 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000554 attr.bit_gravity = NorthWestGravity;
555 attr.backing_store = NotUseful/*WhenMapped*/;
Lionel Ulmer1fc39be2001-07-12 22:27:56 +0000556 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000557
Alexandre Julliard649637f2001-06-26 21:10:11 +0000558 wine_tsx11_lock();
559 data->icon_window = XCreateWindow( display, root_window, 0, 0,
560 GetSystemMetrics( SM_CXICON ),
561 GetSystemMetrics( SM_CYICON ),
562 0, screen_depth,
563 InputOutput, visual,
Lionel Ulmer1fc39be2001-07-12 22:27:56 +0000564 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000565 XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd );
Alexandre Julliard649637f2001-06-26 21:10:11 +0000566 wine_tsx11_unlock();
567
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000568 TRACE( "created %lx\n", data->icon_window );
Alexandre Julliardaf50ad62005-07-07 17:30:57 +0000569 SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000570 return data->icon_window;
571}
572
573
574
575/***********************************************************************
576 * destroy_icon_window
577 */
Alexandre Julliardf777d702005-01-31 16:34:07 +0000578static void destroy_icon_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000579{
580 if (!data->icon_window) return;
Alexandre Julliard9428f062002-06-14 00:08:40 +0000581 if (x11drv_thread_data()->cursor_window == data->icon_window)
582 x11drv_thread_data()->cursor_window = None;
Alexandre Julliard704d0352001-07-12 02:49:31 +0000583 wine_tsx11_lock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000584 XDeleteContext( display, data->icon_window, winContext );
585 XDestroyWindow( display, data->icon_window );
586 data->icon_window = 0;
Alexandre Julliard704d0352001-07-12 02:49:31 +0000587 wine_tsx11_unlock();
Alexandre Julliardaf50ad62005-07-07 17:30:57 +0000588 RemovePropA( data->hwnd, icon_window_prop );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000589}
590
591
592/***********************************************************************
593 * set_icon_hints
594 *
595 * Set the icon wm hints
596 */
Alexandre Julliardbde89572007-08-16 23:27:37 +0200597static void set_icon_hints( Display *display, struct x11drv_win_data *data, HICON hIcon )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000598{
Alexandre Julliardbde89572007-08-16 23:27:37 +0200599 XWMHints *hints = data->wm_hints;
600
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000601 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
602 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
Alexandre Julliard883cff42001-06-12 04:02:10 +0000603 data->hWMIconBitmap = 0;
604 data->hWMIconMask = 0;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000605
Alexandre Julliard12d1d402008-01-23 16:40:19 +0100606 if (!hIcon)
Alexandre Julliard883cff42001-06-12 04:02:10 +0000607 {
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000608 if (!data->icon_window) create_icon_window( display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000609 hints->icon_window = data->icon_window;
610 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000611 }
612 else
613 {
614 HBITMAP hbmOrig;
615 RECT rcMask;
616 BITMAP bmMask;
617 ICONINFO ii;
618 HDC hDC;
619
620 GetIconInfo(hIcon, &ii);
621
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000622 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
623 rcMask.top = 0;
624 rcMask.left = 0;
625 rcMask.right = bmMask.bmWidth;
626 rcMask.bottom = bmMask.bmHeight;
627
628 hDC = CreateCompatibleDC(0);
629 hbmOrig = SelectObject(hDC, ii.hbmMask);
630 InvertRect(hDC, &rcMask);
Alexandre Julliardd8a92442002-05-31 18:43:22 +0000631 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000632 SelectObject(hDC, hbmOrig);
633 DeleteDC(hDC);
634
635 data->hWMIconBitmap = ii.hbmColor;
636 data->hWMIconMask = ii.hbmMask;
637
Alexandre Julliard5fd13262005-03-27 18:30:51 +0000638 hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap);
639 hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask);
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000640 destroy_icon_window( display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000641 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000642 }
643}
644
James Liggett60a97502006-08-22 17:14:11 -0700645/***********************************************************************
Alexandre Julliardcbdf1292008-01-23 21:40:45 +0100646 * wine_make_systray_window (X11DRV.@)
James Liggett60a97502006-08-22 17:14:11 -0700647 *
648 * Docks the given X window with the NETWM system tray.
649 */
Alexandre Julliardcbdf1292008-01-23 21:40:45 +0100650void X11DRV_make_systray_window( HWND hwnd )
James Liggett60a97502006-08-22 17:14:11 -0700651{
652 static Atom systray_atom;
Alexandre Julliardcbdf1292008-01-23 21:40:45 +0100653 Display *display = thread_display();
654 struct x11drv_win_data *data;
James Liggett60a97502006-08-22 17:14:11 -0700655 Window systray_window;
656
Alexandre Julliard026974f2008-01-24 10:20:51 +0100657 if (!(data = X11DRV_get_win_data( hwnd )) &&
658 !(data = X11DRV_create_win_data( hwnd ))) return;
Alexandre Julliardcbdf1292008-01-23 21:40:45 +0100659
James Liggett60a97502006-08-22 17:14:11 -0700660 wine_tsx11_lock();
661 if (!systray_atom)
662 {
663 if (DefaultScreen( display ) == 0)
664 systray_atom = x11drv_atom(_NET_SYSTEM_TRAY_S0);
665 else
666 {
667 char systray_buffer[29]; /* strlen(_NET_SYSTEM_TRAY_S4294967295)+1 */
668 sprintf( systray_buffer, "_NET_SYSTEM_TRAY_S%u", DefaultScreen( display ) );
669 systray_atom = XInternAtom( display, systray_buffer, False );
670 }
671 }
672 systray_window = XGetSelectionOwner( display, systray_atom );
673 wine_tsx11_unlock();
674
675 TRACE("Docking tray icon %p\n", data->hwnd);
676
677 if (systray_window != None)
678 {
679 XEvent ev;
680 unsigned long info[2];
681
682 /* Put the window offscreen so it isn't mapped. The window _cannot_ be
683 * mapped if we intend to dock with an XEMBED tray. If the window is
684 * mapped when we dock, it may become visible as a child of the root
685 * window after it docks, which isn't the proper behavior.
686 *
687 * For more information on this problem, see
688 * http://standards.freedesktop.org/xembed-spec/latest/ar01s04.html */
689
Alexandre Julliard3c305f92006-10-23 14:37:17 +0200690 SetWindowPos( data->hwnd, NULL, virtual_screen_rect.right + 1, virtual_screen_rect.bottom + 1,
Rob Shearmanfba87b12007-08-23 15:44:24 +0100691 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE );
James Liggett60a97502006-08-22 17:14:11 -0700692
693 /* set XEMBED protocol data on the window */
694 info[0] = 0; /* protocol version */
695 info[1] = 1; /* mapped = true */
696
697 wine_tsx11_lock();
698 XChangeProperty( display, data->whole_window,
699 x11drv_atom(_XEMBED_INFO),
700 x11drv_atom(_XEMBED_INFO), 32, PropModeReplace,
701 (unsigned char*)info, 2 );
702 wine_tsx11_unlock();
703
704 /* send the docking request message */
705 ZeroMemory( &ev, sizeof(ev) );
706 ev.xclient.type = ClientMessage;
707 ev.xclient.window = systray_window;
708 ev.xclient.message_type = x11drv_atom( _NET_SYSTEM_TRAY_OPCODE );
709 ev.xclient.format = 32;
710 ev.xclient.data.l[0] = CurrentTime;
711 ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
712 ev.xclient.data.l[2] = data->whole_window;
713 ev.xclient.data.l[3] = 0;
714 ev.xclient.data.l[4] = 0;
715
716 wine_tsx11_lock();
717 XSendEvent( display, systray_window, False, NoEventMask, &ev );
718 wine_tsx11_unlock();
719
720 }
721 else
722 {
723 int val = 1;
724
725 /* fall back to he KDE hints if the WM doesn't support XEMBED'ed
726 * systrays */
727
728 wine_tsx11_lock();
729 XChangeProperty( display, data->whole_window,
730 x11drv_atom(KWM_DOCKWINDOW),
731 x11drv_atom(KWM_DOCKWINDOW), 32, PropModeReplace,
732 (unsigned char*)&val, 1 );
733 XChangeProperty( display, data->whole_window,
734 x11drv_atom(_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR),
735 XA_WINDOW, 32, PropModeReplace,
736 (unsigned char*)&data->whole_window, 1 );
737 wine_tsx11_unlock();
738 }
739}
740
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000741
742/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000743 * set_size_hints
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000744 *
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000745 * set the window size hints
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000746 */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000747static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000748{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000749 XSizeHints* size_hints;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000750
751 if ((size_hints = XAllocSizeHints()))
752 {
Alexandre Julliardba1517f2006-03-27 22:16:04 +0200753 size_hints->flags = 0;
754
755 if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */
756 {
757 size_hints->win_gravity = StaticGravity;
758 size_hints->x = data->whole_rect.left;
759 size_hints->y = data->whole_rect.top;
760 size_hints->flags |= PWinGravity | PPosition;
761 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000762
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000763 if ( !(style & WS_THICKFRAME) )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000764 {
765 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
766 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
767 size_hints->min_width = size_hints->max_width;
768 size_hints->min_height = size_hints->max_height;
769 size_hints->flags |= PMinSize | PMaxSize;
770 }
771 XSetWMNormalHints( display, data->whole_window, size_hints );
772 XFree( size_hints );
773 }
774}
775
776
777/***********************************************************************
Alexandre Julliardc7dbffc2005-07-01 16:16:00 +0000778 * get_process_name
779 *
780 * get the name of the current process for setting class hints
781 */
782static char *get_process_name(void)
783{
784 static char *name;
785
786 if (!name)
787 {
788 WCHAR module[MAX_PATH];
789 DWORD len = GetModuleFileNameW( 0, module, MAX_PATH );
790 if (len && len < MAX_PATH)
791 {
792 char *ptr;
793 WCHAR *p, *appname = module;
794
795 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
796 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
797 len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL );
798 if ((ptr = HeapAlloc( GetProcessHeap(), 0, len )))
799 {
800 WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL );
801 name = ptr;
802 }
803 }
804 }
805 return name;
806}
807
808
809/***********************************************************************
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200810 * set_initial_wm_hints
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000811 *
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200812 * Set the window manager hints that don't change over the lifetime of a window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000813 */
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200814static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000815{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000816 int i;
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200817 Atom protocols[3];
818 Atom dndVersion = 4;
819 XClassHint *class_hints;
Alexandre Julliardc7dbffc2005-07-01 16:16:00 +0000820 char *process_name = get_process_name();
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000821
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000822 wine_tsx11_lock();
823
824 /* wm protocols */
825 i = 0;
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000826 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
827 protocols[i++] = x11drv_atom(_NET_WM_PING);
828 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
829 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
Hans Leidekkerac147fe2005-03-22 21:17:34 +0000830 XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000831
832 /* class hints */
833 if ((class_hints = XAllocClassHint()))
834 {
Andrew Talbot55e20a72006-06-26 20:56:16 +0100835 static char wine[] = "Wine";
836
Alexandre Julliardc7dbffc2005-07-01 16:16:00 +0000837 class_hints->res_name = process_name;
Andrew Talbot55e20a72006-06-26 20:56:16 +0100838 class_hints->res_class = wine;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000839 XSetClassHint( display, data->whole_window, class_hints );
840 XFree( class_hints );
841 }
842
Mike Hearn34dd4552003-05-04 02:27:20 +0000843 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
844 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
845 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
846 i = getpid();
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000847 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
Hans Leidekkerac147fe2005-03-22 21:17:34 +0000848 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
Ove Kaaven77e7fd72002-01-21 18:41:27 +0000849
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200850 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
851 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
852
Alexandre Julliarddc07b6f2008-01-22 10:17:52 +0100853 data->wm_hints = XAllocWMHints();
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200854 wine_tsx11_unlock();
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100855
856 if (data->wm_hints)
857 {
Alexandre Julliarde929e3b2008-01-23 16:40:54 +0100858 HICON icon = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 );
859 if (!icon) icon = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON );
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100860 data->wm_hints->flags = 0;
Alexandre Julliarde929e3b2008-01-23 16:40:54 +0100861 set_icon_hints( display, data, icon );
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100862 }
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200863}
864
865
866/***********************************************************************
867 * X11DRV_set_wm_hints
868 *
869 * Set the window manager hints for a newly-created window
870 */
871void X11DRV_set_wm_hints( Display *display, struct x11drv_win_data *data )
872{
873 Window group_leader;
874 Atom window_type;
875 MwmHints mwm_hints;
876 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
877 DWORD ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
878 HWND owner = GetWindow( data->hwnd, GW_OWNER );
879
880 if (data->hwnd == GetDesktopWindow())
881 {
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200882 /* force some styles for the desktop to get the correct decorations */
883 style |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
884 owner = 0;
885 }
886
887 /* transient for hint */
888 if (owner)
889 {
890 Window owner_win = X11DRV_get_whole_window( owner );
891 wine_tsx11_lock();
892 XSetTransientForHint( display, data->whole_window, owner_win );
893 wine_tsx11_unlock();
894 group_leader = owner_win;
895 }
896 else group_leader = data->whole_window;
897
898 wine_tsx11_lock();
899
900 /* size hints */
901 set_size_hints( display, data, style );
902
Nickolay V. Shmyrev1a1b9022006-10-11 19:32:22 +0400903 /* set the WM_WINDOW_TYPE */
904 window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
905 if (ex_style & WS_EX_TOOLWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
906 else if (style & WS_THICKFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
907 else if (style & WS_DLGFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
908 else if (ex_style & WS_EX_DLGMODALFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
909
910 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
911 XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1);
Mike Hearn27d972f2003-12-04 21:54:13 +0000912
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000913 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200914 mwm_hints.decorations = get_mwm_decorations( style, ex_style );
Dmitry Timoshkovac387bb2006-10-05 23:16:36 +0900915 mwm_hints.functions = MWM_FUNC_MOVE;
Alexandre Julliard74cd76c2007-08-29 12:02:57 +0200916 if (style & WS_THICKFRAME) mwm_hints.functions |= MWM_FUNC_RESIZE;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000917 if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
918 if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
Alexandre Julliard74cd76c2007-08-29 12:02:57 +0200919 if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000920
921 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
922 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
Hans Leidekkerac147fe2005-03-22 21:17:34 +0000923 (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000924
Alexandre Julliard704d0352001-07-12 02:49:31 +0000925 /* wm hints */
Alexandre Julliardbde89572007-08-16 23:27:37 +0200926 if (data->wm_hints)
Alexandre Julliard704d0352001-07-12 02:49:31 +0000927 {
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100928 data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint;
Alexandre Julliardbde89572007-08-16 23:27:37 +0200929 data->wm_hints->input = !(style & WS_DISABLED);
930 data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
931 data->wm_hints->window_group = group_leader;
Alexandre Julliardbde89572007-08-16 23:27:37 +0200932 XSetWMHints( display, data->whole_window, data->wm_hints );
Alexandre Julliard704d0352001-07-12 02:49:31 +0000933 }
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100934
935 wine_tsx11_unlock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000936}
937
938
939/***********************************************************************
940 * X11DRV_set_iconic_state
941 *
942 * Set the X11 iconic state according to the window style.
943 */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000944void X11DRV_set_iconic_state( HWND hwnd )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000945{
946 Display *display = thread_display();
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000947 struct x11drv_win_data *data;
948 RECT rect;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000949 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
950 BOOL iconic = (style & WS_MINIMIZE) != 0;
951
952 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +0100953 if (!data->whole_window) return;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000954
955 GetWindowRect( hwnd, &rect );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000956
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000957 wine_tsx11_lock();
958
Alexandre Julliardbde89572007-08-16 23:27:37 +0200959 if (data->wm_hints)
960 {
961 data->wm_hints->flags |= StateHint | IconPositionHint;
962 data->wm_hints->initial_state = iconic ? IconicState : NormalState;
963 data->wm_hints->icon_x = rect.left - virtual_screen_rect.left;
964 data->wm_hints->icon_y = rect.top - virtual_screen_rect.top;
965 XSetWMHints( display, data->whole_window, data->wm_hints );
966 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000967
Alexandre Julliard9fc4e5f2008-01-23 12:28:32 +0100968 if (data->mapped)
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000969 {
970 if (iconic)
971 XIconifyWindow( display, data->whole_window, DefaultScreen(display) );
972 else
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000973 if (X11DRV_is_window_rect_mapped( &rect ))
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000974 XMapWindow( display, data->whole_window );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000975 }
976
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000977 wine_tsx11_unlock();
978}
979
980
981/***********************************************************************
982 * X11DRV_window_to_X_rect
983 *
984 * Convert a rect from client to X window coordinates
985 */
Alexandre Julliardd7726c32005-02-01 18:53:59 +0000986void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000987{
Alexandre Julliard8cd1f712001-07-20 18:37:37 +0000988 RECT rc;
989
Alexandre Julliardd7726c32005-02-01 18:53:59 +0000990 if (!data->managed) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000991 if (IsRectEmpty( rect )) return;
992
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200993 get_x11_rect_offset( data, &rc );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000994
Alexandre Julliard8cd1f712001-07-20 18:37:37 +0000995 rect->left -= rc.left;
996 rect->right -= rc.right;
997 rect->top -= rc.top;
998 rect->bottom -= rc.bottom;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000999 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1000 if (rect->left >= rect->right) rect->right = rect->left + 1;
1001}
1002
1003
1004/***********************************************************************
1005 * X11DRV_X_to_window_rect
1006 *
1007 * Opposite of X11DRV_window_to_X_rect
1008 */
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001009void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001010{
Alexandre Julliardc4e20e72007-10-11 12:24:27 +02001011 RECT rc;
Alexandre Julliard74cd76c2007-08-29 12:02:57 +02001012
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001013 if (!data->managed) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001014 if (IsRectEmpty( rect )) return;
1015
Alexandre Julliardc4e20e72007-10-11 12:24:27 +02001016 get_x11_rect_offset( data, &rc );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001017
Alexandre Julliardc4e20e72007-10-11 12:24:27 +02001018 rect->left += rc.left;
1019 rect->right += rc.right;
1020 rect->top += rc.top;
1021 rect->bottom += rc.bottom;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001022 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1023 if (rect->left >= rect->right) rect->right = rect->left + 1;
1024}
1025
1026
1027/***********************************************************************
Alexandre Julliardf777d702005-01-31 16:34:07 +00001028 * X11DRV_sync_window_position
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001029 *
Alexandre Julliardf777d702005-01-31 16:34:07 +00001030 * Synchronize the X window position with the Windows one
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001031 */
Alexandre Julliardf777d702005-01-31 16:34:07 +00001032void X11DRV_sync_window_position( Display *display, struct x11drv_win_data *data,
Alexandre Julliardbbfbe242008-01-23 12:28:01 +01001033 UINT swp_flags, const RECT *old_client_rect,
1034 const RECT *old_whole_rect )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001035{
1036 XWindowChanges changes;
Alexandre Julliardc5675562008-01-23 12:28:12 +01001037 int mask = get_window_changes( &changes, old_whole_rect, &data->whole_rect );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001038
1039 if (!(swp_flags & SWP_NOZORDER))
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001040 {
Alexandre Julliardf777d702005-01-31 16:34:07 +00001041 /* find window that this one must be after */
1042 HWND prev = GetWindow( data->hwnd, GW_HWNDPREV );
1043 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
1044 prev = GetWindow( prev, GW_HWNDPREV );
1045 if (!prev) /* top child */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001046 {
Alexandre Julliardf777d702005-01-31 16:34:07 +00001047 changes.stack_mode = Above;
1048 mask |= CWStackMode;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001049 }
1050 else
1051 {
Alexandre Julliardf777d702005-01-31 16:34:07 +00001052 /* should use stack_mode Below but most window managers don't get it right */
1053 /* so move it above the next one in Z order */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001054 HWND next = GetWindow( data->hwnd, GW_HWNDNEXT );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001055 while (next && !(GetWindowLongW( next, GWL_STYLE ) & WS_VISIBLE))
1056 next = GetWindow( next, GW_HWNDNEXT );
1057 if (next)
Alexandre Julliard08eac702003-05-19 19:08:57 +00001058 {
1059 changes.stack_mode = Above;
1060 changes.sibling = X11DRV_get_whole_window(next);
1061 mask |= CWStackMode | CWSibling;
1062 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001063 }
1064 }
1065
Alexandre Julliardc19af912008-01-17 19:53:59 +01001066 /* only the size is allowed to change for the desktop window */
1067 if (data->whole_window == root_window) mask &= CWWidth | CWHeight;
1068
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001069 if (mask)
1070 {
Alexandre Julliardf777d702005-01-31 16:34:07 +00001071 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
1072
Vitaliy Margolen6069d0d2006-10-07 17:34:01 -06001073 TRACE( "setting win %lx pos %d,%d,%dx%d after %lx changes=%x\n",
Alexandre Julliardf777d702005-01-31 16:34:07 +00001074 data->whole_window, data->whole_rect.left, data->whole_rect.top,
1075 data->whole_rect.right - data->whole_rect.left,
1076 data->whole_rect.bottom - data->whole_rect.top, changes.sibling, mask );
1077
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001078 wine_tsx11_lock();
Alexandre Julliardf777d702005-01-31 16:34:07 +00001079 if (mask & (CWWidth|CWHeight)) set_size_hints( display, data, style );
Alexandre Julliarda06aeab2006-10-26 12:53:59 +02001080 if (mask & CWX) changes.x -= virtual_screen_rect.left;
1081 if (mask & CWY) changes.y -= virtual_screen_rect.top;
Alexandre Julliardf777d702005-01-31 16:34:07 +00001082 XReconfigureWMWindow( display, data->whole_window,
1083 DefaultScreen(display), mask, &changes );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001084 wine_tsx11_unlock();
1085 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001086}
1087
1088
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001089/**********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001090 * create_whole_window
1091 *
1092 * Create the whole X window for a given window
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001093 */
Alexandre Julliardd147e022008-01-23 21:39:32 +01001094static Window create_whole_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001095{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001096 int cx, cy, mask;
1097 XSetWindowAttributes attr;
Alexandre Julliardf777d702005-01-31 16:34:07 +00001098 XIM xim;
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001099 WCHAR text[1024];
Alexandre Julliard395928d2008-01-23 16:30:18 +01001100 HRGN hrgn;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001101
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001102 if (!(cx = data->window_rect.right - data->window_rect.left)) cx = 1;
1103 if (!(cy = data->window_rect.bottom - data->window_rect.top)) cy = 1;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001104
Alexandre Julliard6bb18e22006-03-27 15:33:43 +02001105 mask = get_window_attributes( display, data, &attr );
Alexandre Julliard883cff42001-06-12 04:02:10 +00001106
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001107 wine_tsx11_lock();
1108
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001109 data->whole_rect = data->window_rect;
Alexandre Julliarda06aeab2006-10-26 12:53:59 +02001110 data->whole_window = XCreateWindow( display, root_window,
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001111 data->window_rect.left - virtual_screen_rect.left,
1112 data->window_rect.top - virtual_screen_rect.top,
Alexandre Julliarda06aeab2006-10-26 12:53:59 +02001113 cx, cy, 0, screen_depth, InputOutput,
1114 visual, mask, &attr );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001115
Alexandre Julliard704d0352001-07-12 02:49:31 +00001116 if (!data->whole_window)
1117 {
1118 wine_tsx11_unlock();
1119 return 0;
1120 }
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001121 XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
Alexandre Julliard704d0352001-07-12 02:49:31 +00001122 wine_tsx11_unlock();
1123
Alexandre Julliardf777d702005-01-31 16:34:07 +00001124 xim = x11drv_thread_data()->xim;
1125 if (xim) data->xic = X11DRV_CreateIC( xim, display, data->whole_window );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001126
Alexandre Julliard7d9739e2007-08-20 14:04:36 +02001127 set_initial_wm_hints( display, data );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001128 X11DRV_set_wm_hints( display, data );
1129
Alexandre Julliardaf50ad62005-07-07 17:30:57 +00001130 SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
Alexandre Julliard395928d2008-01-23 16:30:18 +01001131
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001132 /* set the window text */
1133 if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
1134 sync_window_text( display, data->whole_window, text );
1135
Alexandre Julliard395928d2008-01-23 16:30:18 +01001136 /* set the window region */
1137 if ((hrgn = CreateRectRgn( 0, 0, 0, 0 )))
1138 {
1139 if (GetWindowRgn( data->hwnd, hrgn ) != ERROR) sync_window_region( display, data, hrgn );
1140 DeleteObject( hrgn );
1141 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001142 return data->whole_window;
1143}
1144
1145
1146/**********************************************************************
Alexandre Julliardf777d702005-01-31 16:34:07 +00001147 * destroy_whole_window
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001148 *
Alexandre Julliardf777d702005-01-31 16:34:07 +00001149 * Destroy the whole X window for a given window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001150 */
Alexandre Julliardf777d702005-01-31 16:34:07 +00001151static void destroy_whole_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001152{
Alexandre Julliardf777d702005-01-31 16:34:07 +00001153 struct x11drv_thread_data *thread_data = x11drv_thread_data();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001154
Alexandre Julliardf777d702005-01-31 16:34:07 +00001155 if (!data->whole_window) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001156
Alexandre Julliardf777d702005-01-31 16:34:07 +00001157 TRACE( "win %p xwin %lx\n", data->hwnd, data->whole_window );
1158 if (thread_data->cursor_window == data->whole_window) thread_data->cursor_window = None;
Alexandre Julliard883cff42001-06-12 04:02:10 +00001159 wine_tsx11_lock();
Alexandre Julliardf777d702005-01-31 16:34:07 +00001160 XDeleteContext( display, data->whole_window, winContext );
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001161 XDestroyWindow( display, data->whole_window );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001162 data->whole_window = 0;
1163 if (data->xic)
1164 {
1165 XUnsetICFocus( data->xic );
1166 XDestroyIC( data->xic );
1167 }
Alexandre Julliard975f1b22006-05-09 17:32:40 +02001168 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1169 XFlush( display );
Alexandre Julliarddc07b6f2008-01-22 10:17:52 +01001170 XFree( data->wm_hints );
1171 data->wm_hints = NULL;
Alexandre Julliard883cff42001-06-12 04:02:10 +00001172 wine_tsx11_unlock();
Alexandre Julliardaf50ad62005-07-07 17:30:57 +00001173 RemovePropA( data->hwnd, whole_window_prop );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001174}
1175
1176
1177/*****************************************************************
1178 * SetWindowText (X11DRV.@)
1179 */
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001180void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001181{
Alexandre Julliard43230042001-05-16 19:52:29 +00001182 Display *display = thread_display();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001183 Window win;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001184
Alexandre Julliardc44410d2006-03-28 12:21:37 +02001185 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display))
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001186 sync_window_text( display, win, text );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001187}
1188
1189
1190/***********************************************************************
1191 * DestroyWindow (X11DRV.@)
1192 */
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001193void X11DRV_DestroyWindow( HWND hwnd )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001194{
Alexandre Julliard9428f062002-06-14 00:08:40 +00001195 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1196 Display *display = thread_data->display;
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001197 struct x11drv_win_data *data;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001198
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001199 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001200
Chris Robinson37d835b2007-09-26 08:17:13 -07001201 if (data->pixmap)
1202 {
1203 destroy_glxpixmap(display, data->gl_drawable);
1204 wine_tsx11_lock();
1205 XFreePixmap(display, data->pixmap);
1206 wine_tsx11_unlock();
1207 }
1208 else if (data->gl_drawable)
Chris Robinson00633e32007-09-25 22:43:38 -07001209 {
1210 wine_tsx11_lock();
1211 XDestroyWindow(display, data->gl_drawable);
1212 wine_tsx11_unlock();
1213 }
1214
Alexandre Julliard2fb7c872005-03-25 16:47:04 +00001215 free_window_dce( data );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001216 destroy_whole_window( display, data );
1217 destroy_icon_window( display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001218
Alexandre Julliardf777d702005-01-31 16:34:07 +00001219 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001220 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
1221 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001222 wine_tsx11_lock();
Alexandre Julliarde5515552005-02-09 14:01:40 +00001223 XDeleteContext( display, (XID)hwnd, win_data_context );
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001224 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001225 HeapFree( GetProcessHeap(), 0, data );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001226}
1227
1228
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001229static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
1230{
1231 struct x11drv_win_data *data;
1232
Alexandre Julliard30d84fc2008-01-22 10:15:38 +01001233 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001234 {
Alexandre Julliard30d84fc2008-01-22 10:15:38 +01001235 data->hwnd = hwnd;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001236 wine_tsx11_lock();
1237 if (!winContext) winContext = XUniqueContext();
1238 if (!win_data_context) win_data_context = XUniqueContext();
1239 XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
1240 wine_tsx11_unlock();
1241 }
1242 return data;
1243}
1244
1245
Alexandre Julliardc19af912008-01-17 19:53:59 +01001246/* initialize the desktop window id in the desktop manager process */
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001247static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd )
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001248{
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001249 struct x11drv_win_data *data;
1250 VisualID visualid;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001251
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001252 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1253 wine_tsx11_lock();
1254 visualid = XVisualIDFromVisual(visual);
1255 wine_tsx11_unlock();
1256 data->whole_window = root_window;
1257 data->managed = TRUE;
1258 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1259 SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
1260 SetPropA( data->hwnd, visual_id_prop, (HANDLE)visualid );
1261 set_initial_wm_hints( display, data );
1262 return data;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001263}
1264
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001265/**********************************************************************
1266 * CreateDesktopWindow (X11DRV.@)
1267 */
1268BOOL X11DRV_CreateDesktopWindow( HWND hwnd )
1269{
Alexandre Julliardc19af912008-01-17 19:53:59 +01001270 unsigned int width, height;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001271
Alexandre Julliardc19af912008-01-17 19:53:59 +01001272 /* retrieve the real size of the desktop */
1273 SERVER_START_REQ( get_window_rectangles )
1274 {
1275 req->handle = hwnd;
1276 wine_server_call( req );
1277 width = reply->window.right - reply->window.left;
1278 height = reply->window.bottom - reply->window.top;
1279 }
1280 SERVER_END_REQ;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001281
Alexandre Julliardc19af912008-01-17 19:53:59 +01001282 if (!width && !height) /* not initialized yet */
1283 {
1284 SERVER_START_REQ( set_window_pos )
1285 {
1286 req->handle = hwnd;
1287 req->previous = 0;
1288 req->flags = SWP_NOZORDER;
1289 req->window.left = virtual_screen_rect.left;
1290 req->window.top = virtual_screen_rect.top;
1291 req->window.right = virtual_screen_rect.right;
1292 req->window.bottom = virtual_screen_rect.bottom;
1293 req->client = req->window;
1294 wine_server_call( req );
1295 }
1296 SERVER_END_REQ;
1297 }
1298 else
1299 {
1300 Window win = (Window)GetPropA( hwnd, whole_window_prop );
1301 if (win && win != root_window) X11DRV_init_desktop( win, width, height );
1302 }
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001303 return TRUE;
1304}
1305
1306
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001307/**********************************************************************
1308 * CreateWindow (X11DRV.@)
1309 */
Alexandre Julliardd6f67452008-01-24 11:23:09 +01001310BOOL X11DRV_CreateWindow( HWND hwnd )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001311{
1312 Display *display = thread_display();
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001313 DWORD style;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001314
Alexandre Julliard026974f2008-01-24 10:20:51 +01001315 if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( display ))
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001316 {
Alexandre Julliard026974f2008-01-24 10:20:51 +01001317 /* the desktop win data can't be created lazily */
1318 if (!create_desktop_win_data( display, hwnd )) return FALSE;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001319 }
Alexandre Julliard649637f2001-06-26 21:10:11 +00001320
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001321 /* Show the window, maximizing or minimizing if needed */
1322
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001323 style = GetWindowLongW( hwnd, GWL_STYLE );
1324 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001325 {
1326 extern UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect ); /*FIXME*/
1327
1328 RECT newPos;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001329 UINT swFlag = (style & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE;
Alexandre Julliardf9364282005-01-21 10:32:13 +00001330 WIN_SetStyle( hwnd, 0, WS_MAXIMIZE | WS_MINIMIZE );
Juris Smotrovs00982462006-12-19 19:35:42 +08001331 swFlag = WINPOS_MinMaximize( hwnd, swFlag, &newPos );
Vitaliy Margolenaae76322005-11-30 12:32:22 +01001332
Juris Smotrovs00982462006-12-19 19:35:42 +08001333 swFlag |= SWP_FRAMECHANGED; /* Frame always gets changed */
Vitaliy Margolenaae76322005-11-30 12:32:22 +01001334 if (!(style & WS_VISIBLE) || (style & WS_CHILD) || GetActiveWindow()) swFlag |= SWP_NOACTIVATE;
1335
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001336 SetWindowPos( hwnd, 0, newPos.left, newPos.top,
1337 newPos.right, newPos.bottom, swFlag );
1338 }
1339
1340 return TRUE;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001341}
1342
1343
1344/***********************************************************************
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001345 * X11DRV_get_win_data
1346 *
1347 * Return the X11 data structure associated with a window.
1348 */
1349struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1350{
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001351 char *data;
Alexandre Julliarde5515552005-02-09 14:01:40 +00001352
1353 if (!hwnd || XFindContext( thread_display(), (XID)hwnd, win_data_context, &data )) data = NULL;
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001354 return (struct x11drv_win_data *)data;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001355}
1356
1357
1358/***********************************************************************
Alexandre Julliard026974f2008-01-24 10:20:51 +01001359 * X11DRV_create_win_data
1360 *
1361 * Create an X11 data window structure for an existing window.
1362 */
1363struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd )
1364{
1365 Display *display = thread_display();
1366 struct x11drv_win_data *data;
1367 HWND parent;
1368
1369 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
1370 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1371
1372 GetWindowRect( hwnd, &data->window_rect );
1373 MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 );
1374 data->whole_rect = data->window_rect;
1375 GetClientRect( hwnd, &data->client_rect );
1376 MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 );
1377
1378 if (parent == GetDesktopWindow())
1379 {
1380 if (!create_whole_window( display, data ))
1381 {
1382 HeapFree( GetProcessHeap(), 0, data );
1383 return NULL;
1384 }
1385 TRACE( "win %p/%lx window %s whole %s client %s\n",
1386 hwnd, data->whole_window, wine_dbgstr_rect( &data->window_rect ),
1387 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
1388 }
1389
1390 /* get class or window DC if needed */
1391 alloc_window_dce( data );
1392 return data;
1393}
1394
1395
1396/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001397 * X11DRV_get_whole_window
1398 *
1399 * Return the X window associated with the full area of a window
1400 */
1401Window X11DRV_get_whole_window( HWND hwnd )
1402{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001403 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001404
Alexandre Julliardc19af912008-01-17 19:53:59 +01001405 if (!data)
1406 {
1407 if (hwnd == GetDesktopWindow()) return root_window;
1408 return (Window)GetPropA( hwnd, whole_window_prop );
1409 }
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001410 return data->whole_window;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001411}
1412
1413
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001414/***********************************************************************
Chris Robinsond9571c92007-09-15 13:02:32 -07001415 * X11DRV_get_fbconfig_id
1416 *
1417 * Return the GLXFBConfig ID of the drawable used by the window for
1418 * OpenGL rendering. This is 0 for windows without a pixel format set.
1419 */
1420XID X11DRV_get_fbconfig_id( HWND hwnd )
1421{
1422 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1423
1424 if (!data) return (XID)GetPropA( hwnd, fbconfig_id_prop );
1425 return data->fbconfig_id;
1426}
1427
Chris Robinsona8124f92007-09-25 10:20:58 -07001428/***********************************************************************
1429 * X11DRV_get_gl_drawable
1430 *
1431 * Return the GL drawable for this window.
1432 */
1433Drawable X11DRV_get_gl_drawable( HWND hwnd )
1434{
1435 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1436
1437 if (!data) return (Drawable)GetPropA( hwnd, gl_drawable_prop );
1438 return data->gl_drawable;
1439}
1440
Chris Robinson37d835b2007-09-26 08:17:13 -07001441/***********************************************************************
1442 * X11DRV_get_gl_pixmap
1443 *
1444 * Return the Pixmap associated with the GL drawable (if any) for this window.
1445 */
1446Pixmap X11DRV_get_gl_pixmap( HWND hwnd )
1447{
1448 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1449
1450 if (!data) return (Pixmap)GetPropA( hwnd, pixmap_prop );
1451 return data->pixmap;
1452}
1453
Chris Robinsond9571c92007-09-15 13:02:32 -07001454
1455/***********************************************************************
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001456 * X11DRV_get_ic
1457 *
1458 * Return the X input context associated with a window
1459 */
1460XIC X11DRV_get_ic( HWND hwnd )
1461{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001462 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001463
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001464 if (!data) return 0;
1465 return data->xic;
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001466}
1467
1468
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001469/*****************************************************************
1470 * SetParent (X11DRV.@)
1471 */
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001472void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001473{
Alexandre Julliard43230042001-05-16 19:52:29 +00001474 Display *display = thread_display();
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001475 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001476
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001477 if (!data) return;
1478 if (parent == old_parent) return;
Alexandre Julliardfb0ff052001-10-16 21:58:58 +00001479
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001480 if (parent != GetDesktopWindow()) /* a child window */
Alexandre Julliard4d32a472005-03-25 10:38:56 +00001481 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001482 if (old_parent == GetDesktopWindow())
Alexandre Julliard4d32a472005-03-25 10:38:56 +00001483 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001484 /* destroy the old X windows */
1485 destroy_whole_window( display, data );
1486 destroy_icon_window( display, data );
1487 if (data->managed)
Alexandre Julliardf777d702005-01-31 16:34:07 +00001488 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001489 data->managed = FALSE;
1490 RemovePropA( data->hwnd, managed_prop );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001491 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001492 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001493 }
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001494 else /* new top level window */
1495 {
1496 /* FIXME: we ignore errors since we can't really recover anyway */
Alexandre Julliardd147e022008-01-23 21:39:32 +01001497 create_whole_window( display, data );
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001498 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001499}
1500
1501
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001502/*****************************************************************
1503 * SetFocus (X11DRV.@)
1504 *
1505 * Set the X focus.
1506 * Explicit colormap management seems to work only with OLVWM.
1507 */
1508void X11DRV_SetFocus( HWND hwnd )
1509{
Alexandre Julliard43230042001-05-16 19:52:29 +00001510 Display *display = thread_display();
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001511 struct x11drv_win_data *data;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001512 XWindowAttributes win_attr;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001513
1514 /* Only mess with the X focus if there's */
1515 /* no desktop window and if the window is not managed by the WM. */
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001516 if (root_window != DefaultRootWindow(display)) return;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001517
1518 if (!hwnd) /* If setting the focus to 0, uninstall the colormap */
1519 {
Alexandre Julliard2496c082003-11-21 00:17:33 +00001520 wine_tsx11_lock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001521 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
Alexandre Julliard2496c082003-11-21 00:17:33 +00001522 XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1523 wine_tsx11_unlock();
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001524 return;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001525 }
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001526
1527 hwnd = GetAncestor( hwnd, GA_ROOT );
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001528
1529 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Todd Mokros88ac4b92005-08-22 09:14:21 +00001530 if (data->managed || !data->whole_window) return;
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001531
1532 /* Set X focus and install colormap */
1533 wine_tsx11_lock();
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001534 if (XGetWindowAttributes( display, data->whole_window, &win_attr ) &&
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001535 (win_attr.map_state == IsViewable))
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001536 {
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001537 /* If window is not viewable, don't change anything */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001538
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001539 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1540 /* FIXME: this is not entirely correct */
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001541 XSetInputFocus( display, data->whole_window, RevertToParent,
Jeremy White77502e72005-01-14 17:06:40 +00001542 /* CurrentTime */
1543 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001544 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1545 XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001546 }
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001547 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001548}
1549
1550
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001551/**********************************************************************
Patrik Stridvall01d5e5b2001-07-02 19:59:40 +00001552 * SetWindowIcon (X11DRV.@)
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001553 *
1554 * hIcon or hIconSm has changed (or is being initialised for the
1555 * first time). Complete the X11 driver-specific initialisation
1556 * and set the window hints.
1557 *
1558 * This is not entirely correct, may need to create
1559 * an icon window and set the pixmap as a background
1560 */
Alexandre Julliard446d8322003-12-31 23:51:52 +00001561void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001562{
Alexandre Julliard43230042001-05-16 19:52:29 +00001563 Display *display = thread_display();
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001564 struct x11drv_win_data *data;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001565
Alexandre Julliard446d8322003-12-31 23:51:52 +00001566 if (type != ICON_BIG) return; /* nothing to do here */
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001567
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001568 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Alexandre Julliardf777d702005-01-31 16:34:07 +00001569 if (!data->whole_window) return;
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001570 if (!data->managed) return;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001571
Alexandre Julliardbde89572007-08-16 23:27:37 +02001572 if (data->wm_hints)
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001573 {
Alexandre Julliardbde89572007-08-16 23:27:37 +02001574 set_icon_hints( display, data, icon );
Alexandre Julliarde9119c12002-09-24 18:36:51 +00001575 wine_tsx11_lock();
Alexandre Julliardbde89572007-08-16 23:27:37 +02001576 XSetWMHints( display, data->whole_window, data->wm_hints );
Alexandre Julliarde9119c12002-09-24 18:36:51 +00001577 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001578 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001579}
Alexandre Julliard395928d2008-01-23 16:30:18 +01001580
1581
1582/***********************************************************************
1583 * SetWindowRgn (X11DRV.@)
1584 *
1585 * Assign specified region to window (for non-rectangular windows)
1586 */
1587int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1588{
1589 struct x11drv_win_data *data;
1590
1591 if ((data = X11DRV_get_win_data( hwnd )))
1592 {
1593 sync_window_region( thread_display(), data, hrgn );
1594 invalidate_dce( hwnd, &data->window_rect );
1595 }
1596 else if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
1597 {
1598 FIXME( "not supported on other thread window %p\n", hwnd );
1599 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1600 return FALSE;
1601 }
1602
1603 return TRUE;
1604}