blob: 5ead13319fea4f0a63e1de5baedec4735194e0d4 [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 Julliarde6dfbcb2008-01-25 12:07:11 +01001105 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1106 {
1107 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1108 data->managed = TRUE;
1109 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1110 }
1111
Alexandre Julliard6bb18e22006-03-27 15:33:43 +02001112 mask = get_window_attributes( display, data, &attr );
Alexandre Julliard883cff42001-06-12 04:02:10 +00001113
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001114 wine_tsx11_lock();
1115
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001116 data->whole_rect = data->window_rect;
Alexandre Julliarda06aeab2006-10-26 12:53:59 +02001117 data->whole_window = XCreateWindow( display, root_window,
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001118 data->window_rect.left - virtual_screen_rect.left,
1119 data->window_rect.top - virtual_screen_rect.top,
Alexandre Julliarda06aeab2006-10-26 12:53:59 +02001120 cx, cy, 0, screen_depth, InputOutput,
1121 visual, mask, &attr );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001122
Alexandre Julliard704d0352001-07-12 02:49:31 +00001123 if (!data->whole_window)
1124 {
1125 wine_tsx11_unlock();
1126 return 0;
1127 }
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001128 XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
Alexandre Julliard704d0352001-07-12 02:49:31 +00001129 wine_tsx11_unlock();
1130
Alexandre Julliardf777d702005-01-31 16:34:07 +00001131 xim = x11drv_thread_data()->xim;
1132 if (xim) data->xic = X11DRV_CreateIC( xim, display, data->whole_window );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001133
Alexandre Julliard7d9739e2007-08-20 14:04:36 +02001134 set_initial_wm_hints( display, data );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001135 X11DRV_set_wm_hints( display, data );
1136
Alexandre Julliardaf50ad62005-07-07 17:30:57 +00001137 SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
Alexandre Julliard395928d2008-01-23 16:30:18 +01001138
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001139 /* set the window text */
1140 if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
1141 sync_window_text( display, data->whole_window, text );
1142
Alexandre Julliard395928d2008-01-23 16:30:18 +01001143 /* set the window region */
1144 if ((hrgn = CreateRectRgn( 0, 0, 0, 0 )))
1145 {
1146 if (GetWindowRgn( data->hwnd, hrgn ) != ERROR) sync_window_region( display, data, hrgn );
1147 DeleteObject( hrgn );
1148 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001149 return data->whole_window;
1150}
1151
1152
1153/**********************************************************************
Alexandre Julliardf777d702005-01-31 16:34:07 +00001154 * destroy_whole_window
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001155 *
Alexandre Julliardf777d702005-01-31 16:34:07 +00001156 * Destroy the whole X window for a given window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001157 */
Alexandre Julliardf777d702005-01-31 16:34:07 +00001158static void destroy_whole_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001159{
Alexandre Julliardf777d702005-01-31 16:34:07 +00001160 struct x11drv_thread_data *thread_data = x11drv_thread_data();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001161
Alexandre Julliardf777d702005-01-31 16:34:07 +00001162 if (!data->whole_window) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001163
Alexandre Julliardf777d702005-01-31 16:34:07 +00001164 TRACE( "win %p xwin %lx\n", data->hwnd, data->whole_window );
1165 if (thread_data->cursor_window == data->whole_window) thread_data->cursor_window = None;
Alexandre Julliard883cff42001-06-12 04:02:10 +00001166 wine_tsx11_lock();
Alexandre Julliardf777d702005-01-31 16:34:07 +00001167 XDeleteContext( display, data->whole_window, winContext );
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001168 XDestroyWindow( display, data->whole_window );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001169 data->whole_window = 0;
1170 if (data->xic)
1171 {
1172 XUnsetICFocus( data->xic );
1173 XDestroyIC( data->xic );
1174 }
Alexandre Julliard975f1b22006-05-09 17:32:40 +02001175 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1176 XFlush( display );
Alexandre Julliarddc07b6f2008-01-22 10:17:52 +01001177 XFree( data->wm_hints );
1178 data->wm_hints = NULL;
Alexandre Julliard883cff42001-06-12 04:02:10 +00001179 wine_tsx11_unlock();
Alexandre Julliardaf50ad62005-07-07 17:30:57 +00001180 RemovePropA( data->hwnd, whole_window_prop );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001181}
1182
1183
1184/*****************************************************************
1185 * SetWindowText (X11DRV.@)
1186 */
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001187void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001188{
Alexandre Julliard43230042001-05-16 19:52:29 +00001189 Display *display = thread_display();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001190 Window win;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001191
Alexandre Julliardc44410d2006-03-28 12:21:37 +02001192 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display))
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001193 sync_window_text( display, win, text );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001194}
1195
1196
1197/***********************************************************************
1198 * DestroyWindow (X11DRV.@)
1199 */
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001200void X11DRV_DestroyWindow( HWND hwnd )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001201{
Alexandre Julliard9428f062002-06-14 00:08:40 +00001202 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1203 Display *display = thread_data->display;
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001204 struct x11drv_win_data *data;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001205
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001206 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001207
Chris Robinson37d835b2007-09-26 08:17:13 -07001208 if (data->pixmap)
1209 {
1210 destroy_glxpixmap(display, data->gl_drawable);
1211 wine_tsx11_lock();
1212 XFreePixmap(display, data->pixmap);
1213 wine_tsx11_unlock();
1214 }
1215 else if (data->gl_drawable)
Chris Robinson00633e32007-09-25 22:43:38 -07001216 {
1217 wine_tsx11_lock();
1218 XDestroyWindow(display, data->gl_drawable);
1219 wine_tsx11_unlock();
1220 }
1221
Alexandre Julliard2fb7c872005-03-25 16:47:04 +00001222 free_window_dce( data );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001223 destroy_whole_window( display, data );
1224 destroy_icon_window( display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001225
Alexandre Julliardf777d702005-01-31 16:34:07 +00001226 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001227 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
1228 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001229 wine_tsx11_lock();
Alexandre Julliarde5515552005-02-09 14:01:40 +00001230 XDeleteContext( display, (XID)hwnd, win_data_context );
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001231 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001232 HeapFree( GetProcessHeap(), 0, data );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001233}
1234
1235
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001236static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
1237{
1238 struct x11drv_win_data *data;
1239
Alexandre Julliard30d84fc2008-01-22 10:15:38 +01001240 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001241 {
Alexandre Julliard30d84fc2008-01-22 10:15:38 +01001242 data->hwnd = hwnd;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001243 wine_tsx11_lock();
1244 if (!winContext) winContext = XUniqueContext();
1245 if (!win_data_context) win_data_context = XUniqueContext();
1246 XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
1247 wine_tsx11_unlock();
1248 }
1249 return data;
1250}
1251
1252
Alexandre Julliardc19af912008-01-17 19:53:59 +01001253/* initialize the desktop window id in the desktop manager process */
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001254static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd )
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001255{
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001256 struct x11drv_win_data *data;
1257 VisualID visualid;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001258
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001259 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1260 wine_tsx11_lock();
1261 visualid = XVisualIDFromVisual(visual);
1262 wine_tsx11_unlock();
1263 data->whole_window = root_window;
1264 data->managed = TRUE;
1265 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1266 SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
1267 SetPropA( data->hwnd, visual_id_prop, (HANDLE)visualid );
1268 set_initial_wm_hints( display, data );
1269 return data;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001270}
1271
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001272/**********************************************************************
1273 * CreateDesktopWindow (X11DRV.@)
1274 */
1275BOOL X11DRV_CreateDesktopWindow( HWND hwnd )
1276{
Alexandre Julliardc19af912008-01-17 19:53:59 +01001277 unsigned int width, height;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001278
Alexandre Julliardc19af912008-01-17 19:53:59 +01001279 /* retrieve the real size of the desktop */
1280 SERVER_START_REQ( get_window_rectangles )
1281 {
1282 req->handle = hwnd;
1283 wine_server_call( req );
1284 width = reply->window.right - reply->window.left;
1285 height = reply->window.bottom - reply->window.top;
1286 }
1287 SERVER_END_REQ;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001288
Alexandre Julliardc19af912008-01-17 19:53:59 +01001289 if (!width && !height) /* not initialized yet */
1290 {
1291 SERVER_START_REQ( set_window_pos )
1292 {
1293 req->handle = hwnd;
1294 req->previous = 0;
1295 req->flags = SWP_NOZORDER;
1296 req->window.left = virtual_screen_rect.left;
1297 req->window.top = virtual_screen_rect.top;
1298 req->window.right = virtual_screen_rect.right;
1299 req->window.bottom = virtual_screen_rect.bottom;
1300 req->client = req->window;
1301 wine_server_call( req );
1302 }
1303 SERVER_END_REQ;
1304 }
1305 else
1306 {
1307 Window win = (Window)GetPropA( hwnd, whole_window_prop );
1308 if (win && win != root_window) X11DRV_init_desktop( win, width, height );
1309 }
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001310 return TRUE;
1311}
1312
1313
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001314/**********************************************************************
1315 * CreateWindow (X11DRV.@)
1316 */
Alexandre Julliardd6f67452008-01-24 11:23:09 +01001317BOOL X11DRV_CreateWindow( HWND hwnd )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001318{
1319 Display *display = thread_display();
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001320 DWORD style;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001321
Alexandre Julliard026974f2008-01-24 10:20:51 +01001322 if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( display ))
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001323 {
Alexandre Julliard026974f2008-01-24 10:20:51 +01001324 /* the desktop win data can't be created lazily */
1325 if (!create_desktop_win_data( display, hwnd )) return FALSE;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001326 }
Alexandre Julliard649637f2001-06-26 21:10:11 +00001327
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001328 /* Show the window, maximizing or minimizing if needed */
1329
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001330 style = GetWindowLongW( hwnd, GWL_STYLE );
1331 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001332 {
1333 extern UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect ); /*FIXME*/
1334
1335 RECT newPos;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001336 UINT swFlag = (style & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE;
Alexandre Julliardf9364282005-01-21 10:32:13 +00001337 WIN_SetStyle( hwnd, 0, WS_MAXIMIZE | WS_MINIMIZE );
Juris Smotrovs00982462006-12-19 19:35:42 +08001338 swFlag = WINPOS_MinMaximize( hwnd, swFlag, &newPos );
Vitaliy Margolenaae76322005-11-30 12:32:22 +01001339
Juris Smotrovs00982462006-12-19 19:35:42 +08001340 swFlag |= SWP_FRAMECHANGED; /* Frame always gets changed */
Vitaliy Margolenaae76322005-11-30 12:32:22 +01001341 if (!(style & WS_VISIBLE) || (style & WS_CHILD) || GetActiveWindow()) swFlag |= SWP_NOACTIVATE;
1342
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001343 SetWindowPos( hwnd, 0, newPos.left, newPos.top,
1344 newPos.right, newPos.bottom, swFlag );
1345 }
1346
1347 return TRUE;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001348}
1349
1350
1351/***********************************************************************
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001352 * X11DRV_get_win_data
1353 *
1354 * Return the X11 data structure associated with a window.
1355 */
1356struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1357{
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001358 char *data;
Alexandre Julliarde5515552005-02-09 14:01:40 +00001359
1360 if (!hwnd || XFindContext( thread_display(), (XID)hwnd, win_data_context, &data )) data = NULL;
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001361 return (struct x11drv_win_data *)data;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001362}
1363
1364
1365/***********************************************************************
Alexandre Julliard026974f2008-01-24 10:20:51 +01001366 * X11DRV_create_win_data
1367 *
1368 * Create an X11 data window structure for an existing window.
1369 */
1370struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd )
1371{
1372 Display *display = thread_display();
1373 struct x11drv_win_data *data;
1374 HWND parent;
1375
1376 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
1377 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1378
1379 GetWindowRect( hwnd, &data->window_rect );
1380 MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 );
1381 data->whole_rect = data->window_rect;
1382 GetClientRect( hwnd, &data->client_rect );
1383 MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 );
1384
1385 if (parent == GetDesktopWindow())
1386 {
1387 if (!create_whole_window( display, data ))
1388 {
1389 HeapFree( GetProcessHeap(), 0, data );
1390 return NULL;
1391 }
1392 TRACE( "win %p/%lx window %s whole %s client %s\n",
1393 hwnd, data->whole_window, wine_dbgstr_rect( &data->window_rect ),
1394 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
1395 }
1396
1397 /* get class or window DC if needed */
1398 alloc_window_dce( data );
1399 return data;
1400}
1401
1402
1403/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001404 * X11DRV_get_whole_window
1405 *
1406 * Return the X window associated with the full area of a window
1407 */
1408Window X11DRV_get_whole_window( HWND hwnd )
1409{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001410 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001411
Alexandre Julliardc19af912008-01-17 19:53:59 +01001412 if (!data)
1413 {
1414 if (hwnd == GetDesktopWindow()) return root_window;
1415 return (Window)GetPropA( hwnd, whole_window_prop );
1416 }
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001417 return data->whole_window;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001418}
1419
1420
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001421/***********************************************************************
Chris Robinsond9571c92007-09-15 13:02:32 -07001422 * X11DRV_get_fbconfig_id
1423 *
1424 * Return the GLXFBConfig ID of the drawable used by the window for
1425 * OpenGL rendering. This is 0 for windows without a pixel format set.
1426 */
1427XID X11DRV_get_fbconfig_id( HWND hwnd )
1428{
1429 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1430
1431 if (!data) return (XID)GetPropA( hwnd, fbconfig_id_prop );
1432 return data->fbconfig_id;
1433}
1434
Chris Robinsona8124f92007-09-25 10:20:58 -07001435/***********************************************************************
1436 * X11DRV_get_gl_drawable
1437 *
1438 * Return the GL drawable for this window.
1439 */
1440Drawable X11DRV_get_gl_drawable( HWND hwnd )
1441{
1442 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1443
1444 if (!data) return (Drawable)GetPropA( hwnd, gl_drawable_prop );
1445 return data->gl_drawable;
1446}
1447
Chris Robinson37d835b2007-09-26 08:17:13 -07001448/***********************************************************************
1449 * X11DRV_get_gl_pixmap
1450 *
1451 * Return the Pixmap associated with the GL drawable (if any) for this window.
1452 */
1453Pixmap X11DRV_get_gl_pixmap( HWND hwnd )
1454{
1455 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1456
1457 if (!data) return (Pixmap)GetPropA( hwnd, pixmap_prop );
1458 return data->pixmap;
1459}
1460
Chris Robinsond9571c92007-09-15 13:02:32 -07001461
1462/***********************************************************************
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001463 * X11DRV_get_ic
1464 *
1465 * Return the X input context associated with a window
1466 */
1467XIC X11DRV_get_ic( HWND hwnd )
1468{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001469 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001470
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001471 if (!data) return 0;
1472 return data->xic;
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001473}
1474
1475
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001476/*****************************************************************
1477 * SetParent (X11DRV.@)
1478 */
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001479void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001480{
Alexandre Julliard43230042001-05-16 19:52:29 +00001481 Display *display = thread_display();
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001482 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001483
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001484 if (!data) return;
1485 if (parent == old_parent) return;
Alexandre Julliardfb0ff052001-10-16 21:58:58 +00001486
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001487 if (parent != GetDesktopWindow()) /* a child window */
Alexandre Julliard4d32a472005-03-25 10:38:56 +00001488 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001489 if (old_parent == GetDesktopWindow())
Alexandre Julliard4d32a472005-03-25 10:38:56 +00001490 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001491 /* destroy the old X windows */
1492 destroy_whole_window( display, data );
1493 destroy_icon_window( display, data );
1494 if (data->managed)
Alexandre Julliardf777d702005-01-31 16:34:07 +00001495 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001496 data->managed = FALSE;
1497 RemovePropA( data->hwnd, managed_prop );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001498 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001499 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001500 }
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001501 else /* new top level window */
1502 {
1503 /* FIXME: we ignore errors since we can't really recover anyway */
Alexandre Julliardd147e022008-01-23 21:39:32 +01001504 create_whole_window( display, data );
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001505 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001506}
1507
1508
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001509/*****************************************************************
1510 * SetFocus (X11DRV.@)
1511 *
1512 * Set the X focus.
1513 * Explicit colormap management seems to work only with OLVWM.
1514 */
1515void X11DRV_SetFocus( HWND hwnd )
1516{
Alexandre Julliard43230042001-05-16 19:52:29 +00001517 Display *display = thread_display();
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001518 struct x11drv_win_data *data;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001519 XWindowAttributes win_attr;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001520
1521 /* Only mess with the X focus if there's */
1522 /* no desktop window and if the window is not managed by the WM. */
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001523 if (root_window != DefaultRootWindow(display)) return;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001524
1525 if (!hwnd) /* If setting the focus to 0, uninstall the colormap */
1526 {
Alexandre Julliard2496c082003-11-21 00:17:33 +00001527 wine_tsx11_lock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001528 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
Alexandre Julliard2496c082003-11-21 00:17:33 +00001529 XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1530 wine_tsx11_unlock();
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001531 return;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001532 }
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001533
1534 hwnd = GetAncestor( hwnd, GA_ROOT );
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001535
1536 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Todd Mokros88ac4b92005-08-22 09:14:21 +00001537 if (data->managed || !data->whole_window) return;
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001538
1539 /* Set X focus and install colormap */
1540 wine_tsx11_lock();
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001541 if (XGetWindowAttributes( display, data->whole_window, &win_attr ) &&
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001542 (win_attr.map_state == IsViewable))
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001543 {
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001544 /* If window is not viewable, don't change anything */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001545
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001546 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1547 /* FIXME: this is not entirely correct */
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001548 XSetInputFocus( display, data->whole_window, RevertToParent,
Jeremy White77502e72005-01-14 17:06:40 +00001549 /* CurrentTime */
1550 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001551 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1552 XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001553 }
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001554 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001555}
1556
1557
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001558/**********************************************************************
Patrik Stridvall01d5e5b2001-07-02 19:59:40 +00001559 * SetWindowIcon (X11DRV.@)
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001560 *
1561 * hIcon or hIconSm has changed (or is being initialised for the
1562 * first time). Complete the X11 driver-specific initialisation
1563 * and set the window hints.
1564 *
1565 * This is not entirely correct, may need to create
1566 * an icon window and set the pixmap as a background
1567 */
Alexandre Julliard446d8322003-12-31 23:51:52 +00001568void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001569{
Alexandre Julliard43230042001-05-16 19:52:29 +00001570 Display *display = thread_display();
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001571 struct x11drv_win_data *data;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001572
Alexandre Julliard446d8322003-12-31 23:51:52 +00001573 if (type != ICON_BIG) return; /* nothing to do here */
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001574
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001575 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Alexandre Julliardf777d702005-01-31 16:34:07 +00001576 if (!data->whole_window) return;
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001577 if (!data->managed) return;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001578
Alexandre Julliardbde89572007-08-16 23:27:37 +02001579 if (data->wm_hints)
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001580 {
Alexandre Julliardbde89572007-08-16 23:27:37 +02001581 set_icon_hints( display, data, icon );
Alexandre Julliarde9119c12002-09-24 18:36:51 +00001582 wine_tsx11_lock();
Alexandre Julliardbde89572007-08-16 23:27:37 +02001583 XSetWMHints( display, data->whole_window, data->wm_hints );
Alexandre Julliarde9119c12002-09-24 18:36:51 +00001584 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001585 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001586}
Alexandre Julliard395928d2008-01-23 16:30:18 +01001587
1588
1589/***********************************************************************
1590 * SetWindowRgn (X11DRV.@)
1591 *
1592 * Assign specified region to window (for non-rectangular windows)
1593 */
1594int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1595{
1596 struct x11drv_win_data *data;
1597
1598 if ((data = X11DRV_get_win_data( hwnd )))
1599 {
1600 sync_window_region( thread_display(), data, hrgn );
1601 invalidate_dce( hwnd, &data->window_rect );
1602 }
1603 else if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
1604 {
1605 FIXME( "not supported on other thread window %p\n", hwnd );
1606 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1607 return FALSE;
1608 }
1609
1610 return TRUE;
1611}