blob: 81aa989e9bca1fefeef9cfa5816a6b973bfd6e3e [file] [log] [blame]
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001/*
2 * Window related functions
3 *
4 * Copyright 1993, 1994, 1995, 1996, 2001 Alexandre Julliard
5 * Copyright 1993 David Metcalfe
6 * Copyright 1995, 1996 Alex Korobka
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00007 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
Jonathan Ernst360a3f92006-05-18 14:49:52 +020020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000021 */
22
23#include "config.h"
24
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000025#include <stdarg.h>
Dmitry Timoshkovde70d2b2001-06-19 03:32:44 +000026#include <stdlib.h>
James Liggett60a97502006-08-22 17:14:11 -070027#include <stdio.h>
Patrik Stridvallba78aac2003-08-08 21:07:23 +000028#ifdef HAVE_UNISTD_H
29# include <unistd.h>
30#endif
Dmitry Timoshkovde70d2b2001-06-19 03:32:44 +000031
Alexandre Julliard64c0e2a2003-11-21 21:48:36 +000032#include <X11/Xlib.h>
Alexandre Julliarde9119c12002-09-24 18:36:51 +000033#include <X11/Xresource.h>
34#include <X11/Xutil.h>
Alexandre Julliard395928d2008-01-23 16:30:18 +010035#ifdef HAVE_LIBXSHAPE
36#include <X11/extensions/shape.h>
37#endif /* HAVE_LIBXSHAPE */
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000038
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000039#include "windef.h"
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000040#include "winbase.h"
41#include "wingdi.h"
42#include "winuser.h"
Ilya Konstantinov560ca322001-10-02 18:44:56 +000043#include "wine/unicode.h"
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000044
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000045#include "x11drv.h"
Chris Robinson00633e32007-09-25 22:43:38 -070046#include "xcomposite.h"
Alexandre Julliard4d32a472005-03-25 10:38:56 +000047#include "wine/debug.h"
48#include "wine/server.h"
Ove Kaaven77e7fd72002-01-21 18:41:27 +000049#include "mwm.h"
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000050
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000051WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000052
Alexandre Julliard24dbaa02008-04-17 16:13:34 +020053#define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
54#define _NET_WM_MOVERESIZE_SIZE_TOP 1
55#define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
56#define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
57#define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
58#define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
59#define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
60#define _NET_WM_MOVERESIZE_SIZE_LEFT 7
61#define _NET_WM_MOVERESIZE_MOVE 8
62#define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9
63#define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10
64
Alexandre Julliard855308f2008-04-23 15:32:58 +020065#define _NET_WM_STATE_REMOVE 0
66#define _NET_WM_STATE_ADD 1
67#define _NET_WM_STATE_TOGGLE 2
68
69#define SWP_AGG_NOPOSCHANGE (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
70
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000071/* X context to associate a hwnd to an X window */
72XContext winContext = 0;
73
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +000074/* X context to associate a struct x11drv_win_data to an hwnd */
75static XContext win_data_context;
76
Alexandre Julliardaf50ad62005-07-07 17:30:57 +000077static const char whole_window_prop[] = "__wine_x11_whole_window";
Alexandre Julliard8ee07d42008-02-21 12:29:36 +010078static const char client_window_prop[]= "__wine_x11_client_window";
Alexandre Julliardaf50ad62005-07-07 17:30:57 +000079static const char icon_window_prop[] = "__wine_x11_icon_window";
Chris Robinsond9571c92007-09-15 13:02:32 -070080static const char fbconfig_id_prop[] = "__wine_x11_fbconfig_id";
Chris Robinsona8124f92007-09-25 10:20:58 -070081static const char gl_drawable_prop[] = "__wine_x11_gl_drawable";
Chris Robinson37d835b2007-09-26 08:17:13 -070082static const char pixmap_prop[] = "__wine_x11_pixmap";
Alexandre Julliardaf50ad62005-07-07 17:30:57 +000083static const char managed_prop[] = "__wine_x11_managed";
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000084
85/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +000086 * is_window_managed
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000087 *
Alexandre Julliarddc4fe772001-06-04 21:55:17 +000088 * Check if a given window should be managed
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000089 */
Alexandre Julliard855308f2008-04-23 15:32:58 +020090static BOOL is_window_managed( HWND hwnd, UINT swp_flags, const RECT *window_rect )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000091{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000092 DWORD style, ex_style;
93
Alexandre Julliard89131822008-01-24 10:21:07 +010094 if (!managed_mode) return FALSE;
95
Alexandre Julliarddc4fe772001-06-04 21:55:17 +000096 /* child windows are not managed */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000097 style = GetWindowLongW( hwnd, GWL_STYLE );
Peter Dons Tychsend0b21ab2007-07-25 04:09:50 +020098 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD) return FALSE;
Alexandre Julliardeffdfa72007-08-27 12:37:14 +020099 /* activated windows are managed */
100 if (!(swp_flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) return TRUE;
101 if (hwnd == GetActiveWindow()) return TRUE;
Mike Hearn27d972f2003-12-04 21:54:13 +0000102 /* windows with caption are managed */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000103 if ((style & WS_CAPTION) == WS_CAPTION) return TRUE;
Mike Hearn27d972f2003-12-04 21:54:13 +0000104 /* windows with thick frame are managed */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000105 if (style & WS_THICKFRAME) return TRUE;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000106 if (style & WS_POPUP)
Alex Pasadynd18c8ca2004-02-06 05:17:55 +0000107 {
Vitaliy Margolenabcbcc32007-02-10 10:40:50 -0700108 /* popup with sysmenu == caption are managed */
109 if (style & WS_SYSMENU) return TRUE;
110 /* full-screen popup windows are managed */
Alexandre Julliarddba8ad52008-02-25 19:48:07 +0100111 if (window_rect->left <= 0 && window_rect->right >= screen_width &&
112 window_rect->top <= 0 && window_rect->bottom >= screen_height)
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000113 return TRUE;
Alex Pasadynd18c8ca2004-02-06 05:17:55 +0000114 }
Alexandre Julliard1f99d802008-04-25 14:26:52 +0200115 /* application windows are managed */
116 ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE );
117 if (ex_style & WS_EX_APPWINDOW) return TRUE;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000118 /* default: not managed */
119 return FALSE;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000120}
121
122
123/***********************************************************************
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000124 * X11DRV_is_window_rect_mapped
125 *
126 * Check if the X whole window should be mapped based on its rectangle
127 */
Alexandre Julliard855308f2008-04-23 15:32:58 +0200128static BOOL is_window_rect_mapped( const RECT *rect )
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000129{
Alexandre Julliard8a5f5782008-05-01 17:44:56 +0200130 /* don't map if rect is empty */
131 if (IsRectEmpty( rect )) return FALSE;
132
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000133 /* don't map if rect is off-screen */
Alexandre Julliard3c305f92006-10-23 14:37:17 +0200134 if (rect->left >= virtual_screen_rect.right ||
135 rect->top >= virtual_screen_rect.bottom ||
136 rect->right <= virtual_screen_rect.left ||
137 rect->bottom <= virtual_screen_rect.top)
138 return FALSE;
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000139
140 return TRUE;
141}
142
143
144/***********************************************************************
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200145 * is_window_resizable
146 *
147 * Check if window should be made resizable by the window manager
148 */
149static inline BOOL is_window_resizable( struct x11drv_win_data *data, DWORD style )
150{
151 if (style & WS_THICKFRAME) return TRUE;
152 /* Metacity needs the window to be resizable to make it fullscreen */
153 return (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width &&
154 data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height);
155}
156
157
158/***********************************************************************
Alexandre Julliard8a5f5782008-05-01 17:44:56 +0200159 * get_window_owner
160 */
161static HWND get_window_owner( HWND hwnd )
162{
163 RECT rect;
164 HWND owner = GetWindow( hwnd, GW_OWNER );
165 /* ignore the zero-size owners used by Delphi apps */
166 if (owner && GetWindowRect( owner, &rect ) && IsRectEmpty( &rect )) owner = 0;
167 return owner;
168}
169
170
171/***********************************************************************
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200172 * get_mwm_decorations
173 */
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900174static unsigned long get_mwm_decorations( struct x11drv_win_data *data,
175 DWORD style, DWORD ex_style )
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200176{
177 unsigned long ret = 0;
178
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900179 if (!decorated_mode) return 0;
180
181 if (IsRectEmpty( &data->window_rect )) return 0;
Alexandre Julliard2bbf00e2008-04-29 12:46:16 +0200182 if (data->shaped) return 0;
Matthew D'Asaro4217fcb2008-04-10 12:53:45 -0700183
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200184 if (ex_style & WS_EX_TOOLWINDOW) return 0;
185
186 if ((style & WS_CAPTION) == WS_CAPTION)
187 {
188 ret |= MWM_DECOR_TITLE | MWM_DECOR_BORDER;
189 if (style & WS_SYSMENU) ret |= MWM_DECOR_MENU;
190 if (style & WS_MINIMIZEBOX) ret |= MWM_DECOR_MINIMIZE;
191 if (style & WS_MAXIMIZEBOX) ret |= MWM_DECOR_MAXIMIZE;
192 }
193 if (ex_style & WS_EX_DLGMODALFRAME) ret |= MWM_DECOR_BORDER;
194 else if (style & WS_THICKFRAME) ret |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
195 else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) ret |= MWM_DECOR_BORDER;
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200196 return ret;
197}
198
199
200/***********************************************************************
201 * get_x11_rect_offset
202 *
203 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
204 */
205static void get_x11_rect_offset( struct x11drv_win_data *data, RECT *rect )
206{
207 DWORD style, ex_style, style_mask = 0, ex_style_mask = 0;
208 unsigned long decor;
209
210 rect->top = rect->bottom = rect->left = rect->right = 0;
211
212 style = GetWindowLongW( data->hwnd, GWL_STYLE );
213 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900214 decor = get_mwm_decorations( data, style, ex_style );
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200215
216 if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION;
217 if (decor & MWM_DECOR_BORDER)
218 {
219 style_mask |= WS_DLGFRAME | WS_THICKFRAME;
220 ex_style_mask |= WS_EX_DLGMODALFRAME;
221 }
222
223 AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask );
224}
225
226
227/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000228 * get_window_attributes
229 *
Alexandre Julliard883cff42001-06-12 04:02:10 +0000230 * Fill the window attributes structure for an X window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000231 */
Alexandre Julliard6bb18e22006-03-27 15:33:43 +0200232static int get_window_attributes( Display *display, struct x11drv_win_data *data,
233 XSetWindowAttributes *attr )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000234{
Alexandre Julliardd7726c32005-02-01 18:53:59 +0000235 attr->override_redirect = !data->managed;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000236 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000237 attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0);
Alexandre Julliard9428f062002-06-14 00:08:40 +0000238 attr->cursor = x11drv_thread_data()->cursor;
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200239 attr->bit_gravity = NorthWestGravity;
Alexandre Julliard6ba06fa2008-04-23 15:33:29 +0200240 attr->win_gravity = StaticGravity;
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200241 attr->backing_store = NotUseful;
242 attr->event_mask = (ExposureMask | PointerMotionMask |
243 ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
244 KeyPressMask | KeyReleaseMask | FocusChangeMask | KeymapStateMask);
Alexandre Julliard5a5344b2008-02-27 19:11:43 +0100245 if (data->managed) attr->event_mask |= StructureNotifyMask | PropertyChangeMask;
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200246
247 return (CWOverrideRedirect | CWSaveUnder | CWColormap | CWCursor |
248 CWEventMask | CWBitGravity | CWBackingStore);
Alexandre Julliard883cff42001-06-12 04:02:10 +0000249}
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000250
Alexandre Julliard883cff42001-06-12 04:02:10 +0000251
252/***********************************************************************
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100253 * create_client_window
254 */
255static Window create_client_window( Display *display, struct x11drv_win_data *data, XVisualInfo *vis )
256{
257 int cx, cy, mask;
258 XSetWindowAttributes attr;
259 Window client;
260
261 attr.bit_gravity = NorthWestGravity;
262 attr.win_gravity = NorthWestGravity;
263 attr.backing_store = NotUseful;
264 attr.event_mask = (ExposureMask | PointerMotionMask |
265 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
266 mask = CWEventMask | CWBitGravity | CWWinGravity | CWBackingStore;
267
268 if ((cx = data->client_rect.right - data->client_rect.left) <= 0) cx = 1;
269 if ((cy = data->client_rect.bottom - data->client_rect.top) <= 0) cy = 1;
270
271 wine_tsx11_lock();
272
273 if (vis)
274 {
275 attr.colormap = XCreateColormap( display, root_window, vis->visual,
276 (vis->class == PseudoColor || vis->class == GrayScale ||
277 vis->class == DirectColor) ? AllocAll : AllocNone );
278 mask |= CWColormap;
279 }
280
281 client = XCreateWindow( display, data->whole_window,
282 data->client_rect.left - data->whole_rect.left,
283 data->client_rect.top - data->whole_rect.top,
284 cx, cy, 0, screen_depth, InputOutput,
285 vis ? vis->visual : visual, mask, &attr );
286 if (!client)
287 {
288 wine_tsx11_unlock();
289 return 0;
290 }
291
292 if (data->client_window)
293 {
Alexandre Julliard51d3d622008-03-05 20:52:14 +0100294 struct x11drv_thread_data *thread_data = x11drv_thread_data();
295 if (thread_data->cursor_window == data->client_window) thread_data->cursor_window = None;
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100296 XDeleteContext( display, data->client_window, winContext );
297 XDestroyWindow( display, data->client_window );
298 }
299 data->client_window = client;
300
301 if (data->colormap) XFreeColormap( display, data->colormap );
302 data->colormap = vis ? attr.colormap : 0;
303
304 XMapWindow( display, data->client_window );
305 XSaveContext( display, data->client_window, winContext, (char *)data->hwnd );
306 wine_tsx11_unlock();
307
308 SetPropA( data->hwnd, client_window_prop, (HANDLE)data->client_window );
309 return data->client_window;
310}
311
312
313/***********************************************************************
Alexandre Julliard855308f2008-04-23 15:32:58 +0200314 * sync_window_style
Alexandre Julliard883cff42001-06-12 04:02:10 +0000315 *
316 * Change the X window attributes when the window style has changed.
317 */
Alexandre Julliard855308f2008-04-23 15:32:58 +0200318static void sync_window_style( Display *display, struct x11drv_win_data *data )
Alexandre Julliard883cff42001-06-12 04:02:10 +0000319{
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200320 if (data->whole_window != root_window)
321 {
322 XSetWindowAttributes attr;
323 int mask = get_window_attributes( display, data, &attr );
Alexandre Julliard883cff42001-06-12 04:02:10 +0000324
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200325 wine_tsx11_lock();
Alexandre Julliard6d5f5442006-03-06 21:02:59 +0100326 XChangeWindowAttributes( display, data->whole_window, mask, &attr );
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200327 wine_tsx11_unlock();
328 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000329}
330
331
332/***********************************************************************
Alexandre Julliard395928d2008-01-23 16:30:18 +0100333 * sync_window_region
334 *
335 * Update the X11 window region.
336 */
337static void sync_window_region( Display *display, struct x11drv_win_data *data, HRGN hrgn )
338{
339#ifdef HAVE_LIBXSHAPE
340 if (!data->whole_window) return;
Alexandre Julliard2bbf00e2008-04-29 12:46:16 +0200341 data->shaped = FALSE;
Alexandre Julliard395928d2008-01-23 16:30:18 +0100342
343 if (!hrgn)
344 {
345 wine_tsx11_lock();
346 XShapeCombineMask( display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet );
347 wine_tsx11_unlock();
348 }
349 else
350 {
351 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
352 if (pRegionData)
353 {
354 wine_tsx11_lock();
355 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
356 data->window_rect.left - data->whole_rect.left,
357 data->window_rect.top - data->whole_rect.top,
358 (XRectangle *)pRegionData->Buffer,
359 pRegionData->rdh.nCount, ShapeSet, YXBanded );
360 wine_tsx11_unlock();
361 HeapFree(GetProcessHeap(), 0, pRegionData);
Alexandre Julliard2bbf00e2008-04-29 12:46:16 +0200362 data->shaped = TRUE;
Alexandre Julliard395928d2008-01-23 16:30:18 +0100363 }
364 }
365#endif /* HAVE_LIBXSHAPE */
366}
367
368
369/***********************************************************************
Alexandre Julliard3ba20252008-01-23 16:32:55 +0100370 * sync_window_text
371 */
372static void sync_window_text( Display *display, Window win, const WCHAR *text )
373{
374 UINT count;
375 char *buffer, *utf8_buffer;
376 XTextProperty prop;
377
378 /* allocate new buffer for window text */
379 count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
380 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) return;
381 WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
382
383 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
384 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
385 {
386 HeapFree( GetProcessHeap(), 0, buffer );
387 return;
388 }
389 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
390
391 wine_tsx11_lock();
392 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
393 {
394 XSetWMName( display, win, &prop );
395 XSetWMIconName( display, win, &prop );
396 XFree( prop.value );
397 }
398 /*
399 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
400 according to the standard
401 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
402 */
403 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
404 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
405 wine_tsx11_unlock();
406
407 HeapFree( GetProcessHeap(), 0, utf8_buffer );
408 HeapFree( GetProcessHeap(), 0, buffer );
409}
410
411
412/***********************************************************************
Chris Robinsond9571c92007-09-15 13:02:32 -0700413 * X11DRV_set_win_format
414 */
415BOOL X11DRV_set_win_format( HWND hwnd, XID fbconfig_id )
416{
Chris Robinson00633e32007-09-25 22:43:38 -0700417 Display *display = thread_display();
Chris Robinsond9571c92007-09-15 13:02:32 -0700418 struct x11drv_win_data *data;
Chris Robinson00633e32007-09-25 22:43:38 -0700419 XVisualInfo *vis;
Chris Robinson00633e32007-09-25 22:43:38 -0700420 int w, h;
Chris Robinsond9571c92007-09-15 13:02:32 -0700421
Alexandre Julliard026974f2008-01-24 10:20:51 +0100422 if (!(data = X11DRV_get_win_data(hwnd)) &&
423 !(data = X11DRV_create_win_data(hwnd))) return FALSE;
Chris Robinsond9571c92007-09-15 13:02:32 -0700424
Chris Robinson00633e32007-09-25 22:43:38 -0700425 wine_tsx11_lock();
Chris Robinson00633e32007-09-25 22:43:38 -0700426 vis = visual_from_fbconfig_id(fbconfig_id);
Chris Robinson00633e32007-09-25 22:43:38 -0700427 wine_tsx11_unlock();
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100428 if (!vis) return FALSE;
Chris Robinson00633e32007-09-25 22:43:38 -0700429
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100430 if (data->whole_window)
Chris Robinson00633e32007-09-25 22:43:38 -0700431 {
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100432 Window client = data->client_window;
433
434 if (vis->visualid != XVisualIDFromVisual(visual))
Chris Robinson00633e32007-09-25 22:43:38 -0700435 {
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100436 client = create_client_window( display, data, vis );
437 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client, data->hwnd, fbconfig_id );
Chris Robinson00633e32007-09-25 22:43:38 -0700438 }
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100439 wine_tsx11_lock();
440 XFree(vis);
441 wine_tsx11_unlock();
442 if (client) goto done;
443 return FALSE;
Chris Robinson00633e32007-09-25 22:43:38 -0700444 }
445
446 w = data->client_rect.right - data->client_rect.left;
447 h = data->client_rect.bottom - data->client_rect.top;
448
449 if(w <= 0) w = 1;
450 if(h <= 0) h = 1;
451
Chris Robinson00633e32007-09-25 22:43:38 -0700452#ifdef SONAME_LIBXCOMPOSITE
453 if(usexcomposite)
454 {
455 XSetWindowAttributes attrib;
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100456 Window parent = X11DRV_get_whole_window( GetAncestor( hwnd, GA_ROOT ));
Chris Robinson00633e32007-09-25 22:43:38 -0700457
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100458 if (!parent) parent = root_window;
459 wine_tsx11_lock();
Alexandre Julliarde9307d02008-02-21 20:23:32 +0100460 data->colormap = XCreateColormap(display, parent, vis->visual,
461 (vis->class == PseudoColor ||
462 vis->class == GrayScale ||
463 vis->class == DirectColor) ?
464 AllocAll : AllocNone);
Chris Robinson00633e32007-09-25 22:43:38 -0700465 attrib.override_redirect = True;
Alexandre Julliarde9307d02008-02-21 20:23:32 +0100466 attrib.colormap = data->colormap;
Chris Robinson00633e32007-09-25 22:43:38 -0700467 XInstallColormap(gdi_display, attrib.colormap);
468
Roderick Colenbranderf0307d92008-04-22 22:15:15 +0000469 if(data->gl_drawable) XDestroyWindow(gdi_display, data->gl_drawable);
Chris Robinson00633e32007-09-25 22:43:38 -0700470 data->gl_drawable = XCreateWindow(display, parent, -w, 0, w, h, 0,
471 vis->depth, InputOutput, vis->visual,
472 CWColormap | CWOverrideRedirect,
473 &attrib);
474 if(data->gl_drawable)
475 {
476 pXCompositeRedirectWindow(display, data->gl_drawable,
477 CompositeRedirectManual);
478 XMapWindow(display, data->gl_drawable);
479 }
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100480 XFree(vis);
481 wine_tsx11_unlock();
Chris Robinson00633e32007-09-25 22:43:38 -0700482 }
Chris Robinson37d835b2007-09-26 08:17:13 -0700483 else
Chris Robinson00633e32007-09-25 22:43:38 -0700484#endif
Chris Robinson37d835b2007-09-26 08:17:13 -0700485 {
486 WARN("XComposite is not available, using GLXPixmap hack\n");
487
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100488 wine_tsx11_lock();
Roderick Colenbranderf0307d92008-04-22 22:15:15 +0000489
490 if(data->pixmap) XFreePixmap(display, data->pixmap);
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100491 data->pixmap = XCreatePixmap(display, root_window, w, h, vis->depth);
Chris Robinson37d835b2007-09-26 08:17:13 -0700492 if(!data->pixmap)
493 {
Chris Robinson37d835b2007-09-26 08:17:13 -0700494 XFree(vis);
495 wine_tsx11_unlock();
496 return FALSE;
497 }
498
Roderick Colenbranderf0307d92008-04-22 22:15:15 +0000499 if(data->gl_drawable) destroy_glxpixmap(display, data->gl_drawable);
Chris Robinson37d835b2007-09-26 08:17:13 -0700500 data->gl_drawable = create_glxpixmap(display, vis, data->pixmap);
501 if(!data->gl_drawable)
502 {
503 XFreePixmap(display, data->pixmap);
504 data->pixmap = 0;
505 }
Chris Robinson00633e32007-09-25 22:43:38 -0700506 XFree(vis);
507 wine_tsx11_unlock();
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100508 if (data->pixmap) SetPropA(hwnd, pixmap_prop, (HANDLE)data->pixmap);
Chris Robinson00633e32007-09-25 22:43:38 -0700509 }
510
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100511 if (!data->gl_drawable) return FALSE;
Chris Robinson00633e32007-09-25 22:43:38 -0700512
513 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
514 data->gl_drawable, fbconfig_id);
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100515 SetPropA(hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
Chris Robinson00633e32007-09-25 22:43:38 -0700516
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100517done:
Chris Robinsond9571c92007-09-15 13:02:32 -0700518 data->fbconfig_id = fbconfig_id;
519 SetPropA(hwnd, fbconfig_id_prop, (HANDLE)data->fbconfig_id);
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100520 wine_tsx11_lock();
521 XFlush( display );
522 wine_tsx11_unlock();
Alexandre Julliard9727aa82008-04-21 20:32:22 +0200523 /* force DCE invalidation */
524 SetWindowPos( hwnd, 0, 0, 0, 0, 0,
525 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE |
526 SWP_NOREDRAW | SWP_NOSENDCHANGING | SWP_STATECHANGED);
Chris Robinsond9571c92007-09-15 13:02:32 -0700527 return TRUE;
528}
529
Alexandre Julliardbbfbe242008-01-23 12:28:01 +0100530/***********************************************************************
Alexandre Julliard8ee07d42008-02-21 12:29:36 +0100531 * sync_gl_drawable
Alexandre Julliardbbfbe242008-01-23 12:28:01 +0100532 */
Alexandre Julliard8ee07d42008-02-21 12:29:36 +0100533static void sync_gl_drawable(Display *display, struct x11drv_win_data *data)
Chris Robinson00633e32007-09-25 22:43:38 -0700534{
535 int w = data->client_rect.right - data->client_rect.left;
536 int h = data->client_rect.bottom - data->client_rect.top;
Chris Robinson37d835b2007-09-26 08:17:13 -0700537 XVisualInfo *vis;
Chris Robinson37d835b2007-09-26 08:17:13 -0700538 Drawable glxp;
539 Pixmap pix;
Chris Robinson00633e32007-09-25 22:43:38 -0700540
Alexandre Julliardf13ef6b2008-02-22 16:30:10 +0100541 if (w <= 0) w = 1;
542 if (h <= 0) h = 1;
543
Chris Robinson00633e32007-09-25 22:43:38 -0700544 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data->gl_drawable, w, h);
545#ifdef SONAME_LIBXCOMPOSITE
546 if(usexcomposite)
547 {
548 wine_tsx11_lock();
549 XMoveResizeWindow(display, data->gl_drawable, -w, 0, w, h);
550 wine_tsx11_unlock();
551 return;
552 }
553#endif
Chris Robinson37d835b2007-09-26 08:17:13 -0700554
Chris Robinson37d835b2007-09-26 08:17:13 -0700555 wine_tsx11_lock();
556
557 vis = visual_from_fbconfig_id(data->fbconfig_id);
Michael Stefaniuc4e2eef22007-10-21 01:15:53 +0200558 if(!vis)
559 {
560 wine_tsx11_unlock();
561 return;
562 }
Chris Robinson37d835b2007-09-26 08:17:13 -0700563
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100564 pix = XCreatePixmap(display, root_window, w, h, vis->depth);
Chris Robinson37d835b2007-09-26 08:17:13 -0700565 if(!pix)
566 {
567 ERR("Failed to create pixmap for offscreen rendering\n");
568 XFree(vis);
569 wine_tsx11_unlock();
570 return;
571 }
572
573 glxp = create_glxpixmap(display, vis, pix);
574 if(!glxp)
575 {
576 ERR("Failed to create drawable for offscreen rendering\n");
577 XFreePixmap(display, pix);
578 XFree(vis);
579 wine_tsx11_unlock();
580 return;
581 }
582
583 XFree(vis);
584
585 mark_drawable_dirty(data->gl_drawable, glxp);
586
587 XFreePixmap(display, data->pixmap);
588 destroy_glxpixmap(display, data->gl_drawable);
Alexandre Julliard9727aa82008-04-21 20:32:22 +0200589 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp, data->gl_drawable );
Chris Robinson37d835b2007-09-26 08:17:13 -0700590
591 data->pixmap = pix;
592 data->gl_drawable = glxp;
593
Alexandre Julliard70ef99e2008-04-10 14:47:19 +0200594 XFlush( display );
Chris Robinson37d835b2007-09-26 08:17:13 -0700595 wine_tsx11_unlock();
596
597 SetPropA(data->hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
598 SetPropA(data->hwnd, pixmap_prop, (HANDLE)data->pixmap);
Chris Robinson00633e32007-09-25 22:43:38 -0700599}
600
Chris Robinsond9571c92007-09-15 13:02:32 -0700601
602/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000603 * get_window_changes
604 *
605 * fill the window changes structure
606 */
607static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
608{
609 int mask = 0;
610
611 if (old->right - old->left != new->right - new->left )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000612 {
Alexandre Julliard8ee07d42008-02-21 12:29:36 +0100613 if ((changes->width = new->right - new->left) <= 0) changes->width = 1;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000614 mask |= CWWidth;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000615 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000616 if (old->bottom - old->top != new->bottom - new->top)
617 {
Alexandre Julliard8ee07d42008-02-21 12:29:36 +0100618 if ((changes->height = new->bottom - new->top) <= 0) changes->height = 1;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000619 mask |= CWHeight;
620 }
621 if (old->left != new->left)
622 {
623 changes->x = new->left;
624 mask |= CWX;
625 }
626 if (old->top != new->top)
627 {
628 changes->y = new->top;
629 mask |= CWY;
630 }
631 return mask;
632}
633
634
635/***********************************************************************
636 * create_icon_window
637 */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000638static Window create_icon_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000639{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000640 XSetWindowAttributes attr;
641
642 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
Alexandre Julliard9428f062002-06-14 00:08:40 +0000643 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000644 attr.bit_gravity = NorthWestGravity;
645 attr.backing_store = NotUseful/*WhenMapped*/;
Lionel Ulmer1fc39be2001-07-12 22:27:56 +0000646 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000647
Alexandre Julliard649637f2001-06-26 21:10:11 +0000648 wine_tsx11_lock();
649 data->icon_window = XCreateWindow( display, root_window, 0, 0,
650 GetSystemMetrics( SM_CXICON ),
651 GetSystemMetrics( SM_CYICON ),
652 0, screen_depth,
653 InputOutput, visual,
Lionel Ulmer1fc39be2001-07-12 22:27:56 +0000654 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000655 XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd );
Alexandre Julliard731d77f2008-04-09 20:24:27 +0200656 XFlush( display ); /* make sure the window exists before we start painting to it */
Alexandre Julliard649637f2001-06-26 21:10:11 +0000657 wine_tsx11_unlock();
658
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000659 TRACE( "created %lx\n", data->icon_window );
Alexandre Julliardaf50ad62005-07-07 17:30:57 +0000660 SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000661 return data->icon_window;
662}
663
664
665
666/***********************************************************************
667 * destroy_icon_window
668 */
Alexandre Julliardf777d702005-01-31 16:34:07 +0000669static void destroy_icon_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000670{
671 if (!data->icon_window) return;
Alexandre Julliard9428f062002-06-14 00:08:40 +0000672 if (x11drv_thread_data()->cursor_window == data->icon_window)
673 x11drv_thread_data()->cursor_window = None;
Alexandre Julliard704d0352001-07-12 02:49:31 +0000674 wine_tsx11_lock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000675 XDeleteContext( display, data->icon_window, winContext );
676 XDestroyWindow( display, data->icon_window );
677 data->icon_window = 0;
Alexandre Julliard704d0352001-07-12 02:49:31 +0000678 wine_tsx11_unlock();
Alexandre Julliardaf50ad62005-07-07 17:30:57 +0000679 RemovePropA( data->hwnd, icon_window_prop );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000680}
681
682
683/***********************************************************************
684 * set_icon_hints
685 *
686 * Set the icon wm hints
687 */
Alexandre Julliardbde89572007-08-16 23:27:37 +0200688static void set_icon_hints( Display *display, struct x11drv_win_data *data, HICON hIcon )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000689{
Alexandre Julliardbde89572007-08-16 23:27:37 +0200690 XWMHints *hints = data->wm_hints;
691
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000692 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
693 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
Alexandre Julliard883cff42001-06-12 04:02:10 +0000694 data->hWMIconBitmap = 0;
695 data->hWMIconMask = 0;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000696
Alexandre Julliard12d1d402008-01-23 16:40:19 +0100697 if (!hIcon)
Alexandre Julliard883cff42001-06-12 04:02:10 +0000698 {
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000699 if (!data->icon_window) create_icon_window( display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000700 hints->icon_window = data->icon_window;
701 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000702 }
703 else
704 {
705 HBITMAP hbmOrig;
706 RECT rcMask;
707 BITMAP bmMask;
708 ICONINFO ii;
709 HDC hDC;
710
711 GetIconInfo(hIcon, &ii);
712
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000713 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
714 rcMask.top = 0;
715 rcMask.left = 0;
716 rcMask.right = bmMask.bmWidth;
717 rcMask.bottom = bmMask.bmHeight;
718
719 hDC = CreateCompatibleDC(0);
720 hbmOrig = SelectObject(hDC, ii.hbmMask);
721 InvertRect(hDC, &rcMask);
Alexandre Julliardd8a92442002-05-31 18:43:22 +0000722 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000723 SelectObject(hDC, hbmOrig);
724 DeleteDC(hDC);
725
726 data->hWMIconBitmap = ii.hbmColor;
727 data->hWMIconMask = ii.hbmMask;
728
Alexandre Julliard5fd13262005-03-27 18:30:51 +0000729 hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap);
730 hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask);
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000731 destroy_icon_window( display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000732 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000733 }
734}
735
736
737/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000738 * set_size_hints
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000739 *
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000740 * set the window size hints
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000741 */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000742static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000743{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000744 XSizeHints* size_hints;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000745
Alexandre Julliardcf9d3e32008-04-04 11:28:30 +0200746 if (!(size_hints = XAllocSizeHints())) return;
Alexandre Julliardba1517f2006-03-27 22:16:04 +0200747
Alexandre Julliard6ba06fa2008-04-23 15:33:29 +0200748 size_hints->win_gravity = StaticGravity;
749 size_hints->flags |= PWinGravity;
750
Alexandre Julliardcf9d3e32008-04-04 11:28:30 +0200751 /* don't update size hints if window is not in normal state */
752 if (!(style & (WS_MINIMIZE | WS_MAXIMIZE)))
753 {
Alexandre Julliardba1517f2006-03-27 22:16:04 +0200754 if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */
755 {
Alexandre Julliardba1517f2006-03-27 22:16:04 +0200756 size_hints->x = data->whole_rect.left;
757 size_hints->y = data->whole_rect.top;
Alexandre Julliard6ba06fa2008-04-23 15:33:29 +0200758 size_hints->flags |= PPosition;
Alexandre Julliardba1517f2006-03-27 22:16:04 +0200759 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000760
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200761 if (!is_window_resizable( data, style ))
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000762 {
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200763 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
764 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
765 size_hints->min_width = size_hints->max_width;
766 size_hints->min_height = size_hints->max_height;
767 size_hints->flags |= PMinSize | PMaxSize;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000768 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000769 }
Alexandre Julliardcf9d3e32008-04-04 11:28:30 +0200770 XSetWMNormalHints( display, data->whole_window, size_hints );
771 XFree( size_hints );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000772}
773
774
775/***********************************************************************
Alexandre Julliardc7dbffc2005-07-01 16:16:00 +0000776 * get_process_name
777 *
778 * get the name of the current process for setting class hints
779 */
780static char *get_process_name(void)
781{
782 static char *name;
783
784 if (!name)
785 {
786 WCHAR module[MAX_PATH];
787 DWORD len = GetModuleFileNameW( 0, module, MAX_PATH );
788 if (len && len < MAX_PATH)
789 {
790 char *ptr;
791 WCHAR *p, *appname = module;
792
793 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
794 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
795 len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL );
796 if ((ptr = HeapAlloc( GetProcessHeap(), 0, len )))
797 {
798 WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL );
799 name = ptr;
800 }
801 }
802 }
803 return name;
804}
805
806
807/***********************************************************************
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200808 * set_initial_wm_hints
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000809 *
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200810 * Set the window manager hints that don't change over the lifetime of a window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000811 */
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200812static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000813{
Alexandre Julliard3bfa90e2008-04-07 11:41:54 +0200814 long i;
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200815 Atom protocols[3];
816 Atom dndVersion = 4;
817 XClassHint *class_hints;
Alexandre Julliardc7dbffc2005-07-01 16:16:00 +0000818 char *process_name = get_process_name();
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000819
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000820 wine_tsx11_lock();
821
822 /* wm protocols */
823 i = 0;
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000824 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
825 protocols[i++] = x11drv_atom(_NET_WM_PING);
826 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
827 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
Hans Leidekkerac147fe2005-03-22 21:17:34 +0000828 XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000829
830 /* class hints */
831 if ((class_hints = XAllocClassHint()))
832 {
Andrew Talbot55e20a72006-06-26 20:56:16 +0100833 static char wine[] = "Wine";
834
Alexandre Julliardc7dbffc2005-07-01 16:16:00 +0000835 class_hints->res_name = process_name;
Andrew Talbot55e20a72006-06-26 20:56:16 +0100836 class_hints->res_class = wine;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000837 XSetClassHint( display, data->whole_window, class_hints );
838 XFree( class_hints );
839 }
840
Mike Hearn34dd4552003-05-04 02:27:20 +0000841 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
842 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
843 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
844 i = getpid();
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000845 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
Hans Leidekkerac147fe2005-03-22 21:17:34 +0000846 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
Ove Kaaven77e7fd72002-01-21 18:41:27 +0000847
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200848 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
849 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
850
Alexandre Julliarddc07b6f2008-01-22 10:17:52 +0100851 data->wm_hints = XAllocWMHints();
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200852 wine_tsx11_unlock();
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100853
854 if (data->wm_hints)
855 {
Alexandre Julliarde929e3b2008-01-23 16:40:54 +0100856 HICON icon = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 );
857 if (!icon) icon = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON );
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100858 data->wm_hints->flags = 0;
Alexandre Julliarde929e3b2008-01-23 16:40:54 +0100859 set_icon_hints( display, data, icon );
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100860 }
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200861}
862
863
864/***********************************************************************
Alexandre Julliard855308f2008-04-23 15:32:58 +0200865 * set_wm_hints
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200866 *
867 * Set the window manager hints for a newly-created window
868 */
Alexandre Julliard855308f2008-04-23 15:32:58 +0200869static void set_wm_hints( Display *display, struct x11drv_win_data *data )
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200870{
871 Window group_leader;
872 Atom window_type;
873 MwmHints mwm_hints;
Alexandre Julliard18f4fb92008-04-14 13:27:38 +0200874 DWORD style, ex_style;
875 HWND owner;
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200876
877 if (data->hwnd == GetDesktopWindow())
878 {
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200879 /* force some styles for the desktop to get the correct decorations */
Alexandre Julliard18f4fb92008-04-14 13:27:38 +0200880 style = WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
881 ex_style = WS_EX_APPWINDOW;
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200882 owner = 0;
883 }
Alexandre Julliard18f4fb92008-04-14 13:27:38 +0200884 else
885 {
886 style = GetWindowLongW( data->hwnd, GWL_STYLE );
887 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
Alexandre Julliard8a5f5782008-05-01 17:44:56 +0200888 owner = get_window_owner( data->hwnd );
Alexandre Julliard18f4fb92008-04-14 13:27:38 +0200889 }
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200890
891 /* transient for hint */
892 if (owner)
893 {
894 Window owner_win = X11DRV_get_whole_window( owner );
895 wine_tsx11_lock();
896 XSetTransientForHint( display, data->whole_window, owner_win );
897 wine_tsx11_unlock();
898 group_leader = owner_win;
899 }
900 else group_leader = data->whole_window;
901
902 wine_tsx11_lock();
903
904 /* size hints */
905 set_size_hints( display, data, style );
906
Nickolay V. Shmyrev1a1b9022006-10-11 19:32:22 +0400907 /* set the WM_WINDOW_TYPE */
Dmitry Timoshkov751a71a2008-04-07 13:37:44 +0900908 if (style & WS_THICKFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
Alexandre Julliard9bf9c0b2008-04-14 13:27:19 +0200909 else if (ex_style & WS_EX_APPWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
Nickolay V. Shmyrev1a1b9022006-10-11 19:32:22 +0400910 else if (style & WS_DLGFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
911 else if (ex_style & WS_EX_DLGMODALFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
Alexandre Julliard0bbadeb2008-04-21 20:33:18 +0200912 else if ((style & WS_POPUP) && owner) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
Dmitry Timoshkov1bf824e2008-04-07 22:17:47 +0900913#if 0 /* many window managers don't handle utility windows very well */
Dmitry Timoshkov751a71a2008-04-07 13:37:44 +0900914 else if (ex_style & WS_EX_TOOLWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
Dmitry Timoshkov1bf824e2008-04-07 22:17:47 +0900915#endif
Alexandre Julliard9bf9c0b2008-04-14 13:27:19 +0200916 else window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
Nickolay V. Shmyrev1a1b9022006-10-11 19:32:22 +0400917
918 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
919 XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1);
Mike Hearn27d972f2003-12-04 21:54:13 +0000920
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000921 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900922 mwm_hints.decorations = get_mwm_decorations( data, style, ex_style );
Dmitry Timoshkovac387bb2006-10-05 23:16:36 +0900923 mwm_hints.functions = MWM_FUNC_MOVE;
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200924 if (is_window_resizable( data, style )) mwm_hints.functions |= MWM_FUNC_RESIZE;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000925 if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
926 if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
Alexandre Julliard74cd76c2007-08-29 12:02:57 +0200927 if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000928
929 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
930 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
Hans Leidekkerac147fe2005-03-22 21:17:34 +0000931 (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000932
Alexandre Julliard704d0352001-07-12 02:49:31 +0000933 /* wm hints */
Alexandre Julliardbde89572007-08-16 23:27:37 +0200934 if (data->wm_hints)
Alexandre Julliard704d0352001-07-12 02:49:31 +0000935 {
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100936 data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint;
Alexandre Julliardbde89572007-08-16 23:27:37 +0200937 data->wm_hints->input = !(style & WS_DISABLED);
938 data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
939 data->wm_hints->window_group = group_leader;
Alexandre Julliardbde89572007-08-16 23:27:37 +0200940 XSetWMHints( display, data->whole_window, data->wm_hints );
Alexandre Julliard704d0352001-07-12 02:49:31 +0000941 }
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100942
943 wine_tsx11_unlock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000944}
945
946
947/***********************************************************************
Alexandre Julliard855308f2008-04-23 15:32:58 +0200948 * update_net_wm_states
949 */
950void update_net_wm_states( Display *display, struct x11drv_win_data *data )
951{
952 static const unsigned int state_atoms[NB_NET_WM_STATES] =
953 {
954 XATOM__NET_WM_STATE_FULLSCREEN,
955 XATOM__NET_WM_STATE_ABOVE,
956 XATOM__NET_WM_STATE_MAXIMIZED_VERT,
957 XATOM__NET_WM_STATE_SKIP_PAGER,
958 XATOM__NET_WM_STATE_SKIP_TASKBAR
959 };
960
961 DWORD i, style, ex_style, new_state = 0;
962
963 if (!data->managed) return;
964 if (data->whole_window == root_window) return;
965
966 style = GetWindowLongW( data->hwnd, GWL_STYLE );
967 if (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width &&
968 data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height)
969 {
970 if ((style & WS_MAXIMIZE) && (style & WS_CAPTION) == WS_CAPTION)
971 new_state |= (1 << NET_WM_STATE_MAXIMIZED);
972 else if (!(style & WS_MINIMIZE))
973 new_state |= (1 << NET_WM_STATE_FULLSCREEN);
974 }
975 else if (style & WS_MAXIMIZE)
976 new_state |= (1 << NET_WM_STATE_MAXIMIZED);
977
978 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
979 if (ex_style & WS_EX_TOPMOST)
980 new_state |= (1 << NET_WM_STATE_ABOVE);
981 if (ex_style & WS_EX_TOOLWINDOW)
982 new_state |= (1 << NET_WM_STATE_SKIP_TASKBAR) | (1 << NET_WM_STATE_SKIP_PAGER);
Alexandre Julliard8a5f5782008-05-01 17:44:56 +0200983 if (!(ex_style & WS_EX_APPWINDOW) && get_window_owner( data->hwnd ))
Alexandre Julliard855308f2008-04-23 15:32:58 +0200984 new_state |= (1 << NET_WM_STATE_SKIP_TASKBAR);
985
986 if (!data->mapped) /* set the _NET_WM_STATE atom directly */
987 {
988 Atom atoms[NB_NET_WM_STATES+1];
989 DWORD count;
990
991 for (i = count = 0; i < NB_NET_WM_STATES; i++)
992 {
993 if (!(new_state & (1 << i))) continue;
994 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
995 i, data->hwnd, data->whole_window );
996 atoms[count++] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM];
997 if (state_atoms[i] == XATOM__NET_WM_STATE_MAXIMIZED_VERT)
998 atoms[count++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ);
999 }
1000 wine_tsx11_lock();
1001 XChangeProperty( display, data->whole_window, x11drv_atom(_NET_WM_STATE), XA_ATOM,
1002 32, PropModeReplace, (unsigned char *)atoms, count );
1003 wine_tsx11_unlock();
1004 }
1005 else /* ask the window manager to do it for us */
1006 {
1007 XEvent xev;
1008
1009 xev.xclient.type = ClientMessage;
1010 xev.xclient.window = data->whole_window;
1011 xev.xclient.message_type = x11drv_atom(_NET_WM_STATE);
1012 xev.xclient.serial = 0;
1013 xev.xclient.display = display;
1014 xev.xclient.send_event = True;
1015 xev.xclient.format = 32;
1016 xev.xclient.data.l[3] = 1;
1017
1018 for (i = 0; i < NB_NET_WM_STATES; i++)
1019 {
1020 if (!((data->net_wm_state ^ new_state) & (1 << i))) continue; /* unchanged */
1021
1022 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1023 i, data->hwnd, data->whole_window,
1024 (new_state & (1 << i)) != 0, (data->net_wm_state & (1 << i)) != 0 );
1025
1026 xev.xclient.data.l[0] = (new_state & (1 << i)) ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1027 xev.xclient.data.l[1] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM];
1028 xev.xclient.data.l[2] = ((state_atoms[i] == XATOM__NET_WM_STATE_MAXIMIZED_VERT) ?
1029 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ) : 0);
1030 wine_tsx11_lock();
1031 XSendEvent( display, root_window, False,
1032 SubstructureRedirectMask | SubstructureNotifyMask, &xev );
1033 wine_tsx11_unlock();
1034 }
1035 }
1036 data->net_wm_state = new_state;
1037}
1038
1039
1040/***********************************************************************
1041 * set_xembed_flags
1042 */
1043static void set_xembed_flags( Display *display, struct x11drv_win_data *data, unsigned long flags )
1044{
1045 unsigned long info[2];
1046
1047 info[0] = 0; /* protocol version */
1048 info[1] = flags;
1049 wine_tsx11_lock();
1050 XChangeProperty( display, data->whole_window, x11drv_atom(_XEMBED_INFO),
1051 x11drv_atom(_XEMBED_INFO), 32, PropModeReplace, (unsigned char*)info, 2 );
1052 wine_tsx11_unlock();
1053}
1054
1055
1056/***********************************************************************
1057 * map_window
1058 */
1059static void map_window( Display *display, struct x11drv_win_data *data, DWORD new_style )
1060{
1061 TRACE( "win %p/%lx\n", data->hwnd, data->whole_window );
1062
1063 wait_for_withdrawn_state( display, data, TRUE );
1064
1065 if (!data->embedded)
1066 {
1067 update_net_wm_states( display, data );
1068 sync_window_style( display, data );
1069 wine_tsx11_lock();
1070 XMapWindow( display, data->whole_window );
1071 wine_tsx11_unlock();
1072 }
1073 else set_xembed_flags( display, data, XEMBED_MAPPED );
1074
1075 data->mapped = TRUE;
1076 data->iconic = (new_style & WS_MINIMIZE) != 0;
1077}
1078
1079
1080/***********************************************************************
1081 * unmap_window
1082 */
1083static void unmap_window( Display *display, struct x11drv_win_data *data )
1084{
1085 TRACE( "win %p/%lx\n", data->hwnd, data->whole_window );
1086
1087 if (!data->embedded)
1088 {
1089 wait_for_withdrawn_state( display, data, FALSE );
1090 wine_tsx11_lock();
1091 if (data->managed) XWithdrawWindow( display, data->whole_window, DefaultScreen(display) );
1092 else XUnmapWindow( display, data->whole_window );
1093 wine_tsx11_unlock();
1094 }
1095 else set_xembed_flags( display, data, 0 );
1096
1097 data->mapped = FALSE;
1098 data->net_wm_state = 0;
1099}
1100
1101
1102/***********************************************************************
1103 * make_window_embedded
1104 */
1105void make_window_embedded( Display *display, struct x11drv_win_data *data )
1106{
1107 if (data->mapped)
1108 {
1109 /* the window cannot be mapped before being embedded */
1110 unmap_window( display, data );
1111 data->embedded = TRUE;
1112 map_window( display, data, 0 );
1113 }
1114 else
1115 {
1116 data->embedded = TRUE;
1117 set_xembed_flags( display, data, 0 );
1118 }
1119}
1120
1121
1122/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001123 * X11DRV_window_to_X_rect
1124 *
1125 * Convert a rect from client to X window coordinates
1126 */
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001127void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001128{
Alexandre Julliard8cd1f712001-07-20 18:37:37 +00001129 RECT rc;
1130
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001131 if (!data->managed) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001132 if (IsRectEmpty( rect )) return;
1133
Alexandre Julliardc4e20e72007-10-11 12:24:27 +02001134 get_x11_rect_offset( data, &rc );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001135
Alexandre Julliard8cd1f712001-07-20 18:37:37 +00001136 rect->left -= rc.left;
1137 rect->right -= rc.right;
1138 rect->top -= rc.top;
1139 rect->bottom -= rc.bottom;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001140 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1141 if (rect->left >= rect->right) rect->right = rect->left + 1;
1142}
1143
1144
1145/***********************************************************************
1146 * X11DRV_X_to_window_rect
1147 *
1148 * Opposite of X11DRV_window_to_X_rect
1149 */
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001150void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001151{
Alexandre Julliardc4e20e72007-10-11 12:24:27 +02001152 RECT rc;
Alexandre Julliard74cd76c2007-08-29 12:02:57 +02001153
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001154 if (!data->managed) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001155 if (IsRectEmpty( rect )) return;
1156
Alexandre Julliardc4e20e72007-10-11 12:24:27 +02001157 get_x11_rect_offset( data, &rc );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001158
Alexandre Julliardc4e20e72007-10-11 12:24:27 +02001159 rect->left += rc.left;
1160 rect->right += rc.right;
1161 rect->top += rc.top;
1162 rect->bottom += rc.bottom;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001163 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1164 if (rect->left >= rect->right) rect->right = rect->left + 1;
1165}
1166
1167
1168/***********************************************************************
Alexandre Julliard855308f2008-04-23 15:32:58 +02001169 * sync_window_position
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001170 *
Alexandre Julliardf777d702005-01-31 16:34:07 +00001171 * Synchronize the X window position with the Windows one
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001172 */
Alexandre Julliard855308f2008-04-23 15:32:58 +02001173static void sync_window_position( Display *display, struct x11drv_win_data *data,
Alexandre Julliardbbfbe242008-01-23 12:28:01 +01001174 UINT swp_flags, const RECT *old_client_rect,
1175 const RECT *old_whole_rect )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001176{
Alexandre Julliardcef3bc62008-04-04 11:20:45 +02001177 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001178 XWindowChanges changes;
Alexandre Julliardbbd32aa2008-04-23 15:34:07 +02001179 unsigned int mask = 0;
Alexandre Julliardcef3bc62008-04-04 11:20:45 +02001180
1181 if (data->managed && data->iconic) return;
1182
Alexandre Julliardbbd32aa2008-04-23 15:34:07 +02001183 /* resizing a managed maximized window is not allowed */
1184 if (!(style & WS_MAXIMIZE) || !data->managed)
1185 {
1186 if ((changes.width = data->whole_rect.right - data->whole_rect.left) <= 0) changes.width = 1;
1187 if ((changes.height = data->whole_rect.bottom - data->whole_rect.top) <= 0) changes.height = 1;
1188 mask |= CWWidth | CWHeight;
1189 }
Alexandre Julliardcef3bc62008-04-04 11:20:45 +02001190
1191 /* only the size is allowed to change for the desktop window */
1192 if (data->whole_window != root_window)
1193 {
1194 changes.x = data->whole_rect.left - virtual_screen_rect.left;
1195 changes.y = data->whole_rect.top - virtual_screen_rect.top;
1196 mask |= CWX | CWY;
1197 }
Alexandre Julliardf777d702005-01-31 16:34:07 +00001198
1199 if (!(swp_flags & SWP_NOZORDER))
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001200 {
Alexandre Julliardf777d702005-01-31 16:34:07 +00001201 /* find window that this one must be after */
1202 HWND prev = GetWindow( data->hwnd, GW_HWNDPREV );
1203 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
1204 prev = GetWindow( prev, GW_HWNDPREV );
1205 if (!prev) /* top child */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001206 {
Alexandre Julliardf777d702005-01-31 16:34:07 +00001207 changes.stack_mode = Above;
1208 mask |= CWStackMode;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001209 }
Alexandre Julliard5787c122008-03-24 15:47:28 +01001210 /* should use stack_mode Below but most window managers don't get it right */
1211 /* and Above with a sibling doesn't work so well either, so we ignore it */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001212 }
1213
Alexandre Julliardcef3bc62008-04-04 11:20:45 +02001214 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
1215 data->hwnd, data->whole_window, data->whole_rect.left, data->whole_rect.top,
1216 data->whole_rect.right - data->whole_rect.left,
1217 data->whole_rect.bottom - data->whole_rect.top, changes.sibling, mask );
Alexandre Julliardc19af912008-01-17 19:53:59 +01001218
Alexandre Julliardcef3bc62008-04-04 11:20:45 +02001219 wine_tsx11_lock();
1220 set_size_hints( display, data, style );
1221 XReconfigureWMWindow( display, data->whole_window,
1222 DefaultScreen(display), mask, &changes );
1223 wine_tsx11_unlock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001224}
1225
1226
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001227/***********************************************************************
Alexandre Julliard855308f2008-04-23 15:32:58 +02001228 * sync_client_position
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001229 *
1230 * Synchronize the X client window position with the Windows one
1231 */
Alexandre Julliard855308f2008-04-23 15:32:58 +02001232static void sync_client_position( Display *display, struct x11drv_win_data *data,
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001233 UINT swp_flags, const RECT *old_client_rect,
1234 const RECT *old_whole_rect )
1235{
1236 int mask;
1237 XWindowChanges changes;
1238 RECT old = *old_client_rect;
1239 RECT new = data->client_rect;
1240
1241 OffsetRect( &old, -old_whole_rect->left, -old_whole_rect->top );
1242 OffsetRect( &new, -data->whole_rect.left, -data->whole_rect.top );
1243 if (!(mask = get_window_changes( &changes, &old, &new ))) return;
1244
1245 if (data->client_window)
1246 {
1247 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1248 data->client_window, new.left, new.top,
1249 new.right - new.left, new.bottom - new.top, mask );
1250 wine_tsx11_lock();
1251 XConfigureWindow( display, data->client_window, mask, &changes );
1252 wine_tsx11_unlock();
1253 }
1254
1255 if (data->gl_drawable && (mask & (CWWidth|CWHeight))) sync_gl_drawable( display, data );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001256}
1257
1258
Alexandre Julliard855308f2008-04-23 15:32:58 +02001259/***********************************************************************
1260 * move_window_bits
1261 *
1262 * Move the window bits when a window is moved.
1263 */
1264static void move_window_bits( struct x11drv_win_data *data, const RECT *old_rect, const RECT *new_rect,
1265 const RECT *old_client_rect )
1266{
1267 RECT src_rect = *old_rect;
1268 RECT dst_rect = *new_rect;
1269 HDC hdc_src, hdc_dst;
1270 INT code;
1271 HRGN rgn = 0;
1272 HWND parent = 0;
1273
1274 if (!data->whole_window)
1275 {
1276 OffsetRect( &dst_rect, -data->window_rect.left, -data->window_rect.top );
1277 parent = GetAncestor( data->hwnd, GA_PARENT );
1278 hdc_src = GetDCEx( parent, 0, DCX_CACHE );
1279 hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE | DCX_WINDOW );
1280 }
1281 else
1282 {
1283 OffsetRect( &dst_rect, -data->client_rect.left, -data->client_rect.top );
1284 /* make src rect relative to the old position of the window */
1285 OffsetRect( &src_rect, -old_client_rect->left, -old_client_rect->top );
1286 if (dst_rect.left == src_rect.left && dst_rect.top == src_rect.top) return;
1287 hdc_src = hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE );
1288 }
1289
1290 code = X11DRV_START_EXPOSURES;
1291 ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1292
1293 TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n",
1294 data->hwnd, data->whole_window, data->client_window,
1295 wine_dbgstr_rect(&src_rect), wine_dbgstr_rect(&dst_rect) );
1296 BitBlt( hdc_dst, dst_rect.left, dst_rect.top,
1297 dst_rect.right - dst_rect.left, dst_rect.bottom - dst_rect.top,
1298 hdc_src, src_rect.left, src_rect.top, SRCCOPY );
1299
1300 code = X11DRV_END_EXPOSURES;
1301 ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, sizeof(rgn), (LPSTR)&rgn );
1302
1303 ReleaseDC( data->hwnd, hdc_dst );
1304 if (hdc_src != hdc_dst) ReleaseDC( parent, hdc_src );
1305
1306 if (rgn)
1307 {
1308 if (!data->whole_window)
1309 {
1310 /* map region to client rect since we are using DCX_WINDOW */
1311 OffsetRgn( rgn, data->window_rect.left - data->client_rect.left,
1312 data->window_rect.top - data->client_rect.top );
1313 RedrawWindow( data->hwnd, NULL, rgn,
1314 RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ALLCHILDREN );
1315 }
1316 else RedrawWindow( data->hwnd, NULL, rgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
1317 DeleteObject( rgn );
1318 }
1319}
1320
1321
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001322/**********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001323 * create_whole_window
1324 *
1325 * Create the whole X window for a given window
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001326 */
Alexandre Julliardd147e022008-01-23 21:39:32 +01001327static Window create_whole_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001328{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001329 int cx, cy, mask;
1330 XSetWindowAttributes attr;
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001331 WCHAR text[1024];
Alexandre Julliard395928d2008-01-23 16:30:18 +01001332 HRGN hrgn;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001333
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001334 if (!(cx = data->window_rect.right - data->window_rect.left)) cx = 1;
1335 if (!(cy = data->window_rect.bottom - data->window_rect.top)) cy = 1;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001336
Alexandre Julliarde6dfbcb2008-01-25 12:07:11 +01001337 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1338 {
1339 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1340 data->managed = TRUE;
1341 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1342 }
1343
Alexandre Julliard6bb18e22006-03-27 15:33:43 +02001344 mask = get_window_attributes( display, data, &attr );
Alexandre Julliard883cff42001-06-12 04:02:10 +00001345
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001346 wine_tsx11_lock();
1347
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001348 data->whole_rect = data->window_rect;
Alexandre Julliarda06aeab2006-10-26 12:53:59 +02001349 data->whole_window = XCreateWindow( display, root_window,
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001350 data->window_rect.left - virtual_screen_rect.left,
1351 data->window_rect.top - virtual_screen_rect.top,
Alexandre Julliarda06aeab2006-10-26 12:53:59 +02001352 cx, cy, 0, screen_depth, InputOutput,
1353 visual, mask, &attr );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001354
Alexandre Julliard42ad3452008-02-22 10:40:22 +01001355 if (data->whole_window) XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
1356 wine_tsx11_unlock();
1357
1358 if (!data->whole_window) return 0;
1359
1360 if (!create_client_window( display, data, NULL ))
Alexandre Julliard704d0352001-07-12 02:49:31 +00001361 {
Alexandre Julliard42ad3452008-02-22 10:40:22 +01001362 wine_tsx11_lock();
1363 XDeleteContext( display, data->whole_window, winContext );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001364 XDestroyWindow( display, data->whole_window );
1365 data->whole_window = 0;
1366 wine_tsx11_unlock();
1367 return 0;
1368 }
1369
Alexandre Julliard7d9739e2007-08-20 14:04:36 +02001370 set_initial_wm_hints( display, data );
Alexandre Julliard855308f2008-04-23 15:32:58 +02001371 set_wm_hints( display, data );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001372
Alexandre Julliardaf50ad62005-07-07 17:30:57 +00001373 SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
Alexandre Julliard395928d2008-01-23 16:30:18 +01001374
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001375 /* set the window text */
1376 if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
1377 sync_window_text( display, data->whole_window, text );
1378
Alexandre Julliard395928d2008-01-23 16:30:18 +01001379 /* set the window region */
1380 if ((hrgn = CreateRectRgn( 0, 0, 0, 0 )))
1381 {
1382 if (GetWindowRgn( data->hwnd, hrgn ) != ERROR) sync_window_region( display, data, hrgn );
1383 DeleteObject( hrgn );
1384 }
Alexandre Julliard731d77f2008-04-09 20:24:27 +02001385 wine_tsx11_lock();
1386 XFlush( display ); /* make sure the window exists before we start painting to it */
1387 wine_tsx11_unlock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001388 return data->whole_window;
1389}
1390
1391
1392/**********************************************************************
Alexandre Julliardf777d702005-01-31 16:34:07 +00001393 * destroy_whole_window
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001394 *
Alexandre Julliardf777d702005-01-31 16:34:07 +00001395 * Destroy the whole X window for a given window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001396 */
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001397static void destroy_whole_window( Display *display, struct x11drv_win_data *data, BOOL already_destroyed )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001398{
Alexandre Julliardf777d702005-01-31 16:34:07 +00001399 struct x11drv_thread_data *thread_data = x11drv_thread_data();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001400
Alexandre Julliardf777d702005-01-31 16:34:07 +00001401 if (!data->whole_window) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001402
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001403 TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1404 if (thread_data->cursor_window == data->whole_window ||
1405 thread_data->cursor_window == data->client_window)
1406 thread_data->cursor_window = None;
Alexandre Julliard883cff42001-06-12 04:02:10 +00001407 wine_tsx11_lock();
Alexandre Julliardf777d702005-01-31 16:34:07 +00001408 XDeleteContext( display, data->whole_window, winContext );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001409 XDeleteContext( display, data->client_window, winContext );
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001410 if (!already_destroyed) XDestroyWindow( display, data->whole_window );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001411 data->whole_window = data->client_window = 0;
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001412 data->wm_state = WithdrawnState;
1413 data->net_wm_state = 0;
1414 data->mapped = FALSE;
Alexandre Julliardf777d702005-01-31 16:34:07 +00001415 if (data->xic)
1416 {
1417 XUnsetICFocus( data->xic );
1418 XDestroyIC( data->xic );
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001419 data->xic = 0;
Alexandre Julliardf777d702005-01-31 16:34:07 +00001420 }
Alexandre Julliard975f1b22006-05-09 17:32:40 +02001421 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1422 XFlush( display );
Alexandre Julliarddc07b6f2008-01-22 10:17:52 +01001423 XFree( data->wm_hints );
1424 data->wm_hints = NULL;
Alexandre Julliard883cff42001-06-12 04:02:10 +00001425 wine_tsx11_unlock();
Alexandre Julliardaf50ad62005-07-07 17:30:57 +00001426 RemovePropA( data->hwnd, whole_window_prop );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001427 RemovePropA( data->hwnd, client_window_prop );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001428}
1429
1430
1431/*****************************************************************
1432 * SetWindowText (X11DRV.@)
1433 */
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001434void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001435{
Alexandre Julliard43230042001-05-16 19:52:29 +00001436 Display *display = thread_display();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001437 Window win;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001438
Alexandre Julliardc44410d2006-03-28 12:21:37 +02001439 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display))
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001440 sync_window_text( display, win, text );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001441}
1442
1443
1444/***********************************************************************
Alexandre Julliard855308f2008-04-23 15:32:58 +02001445 * SetWindowStyle (X11DRV.@)
1446 *
1447 * Update the X state of a window to reflect a style change
1448 */
1449void X11DRV_SetWindowStyle( HWND hwnd, DWORD old_style )
1450{
1451 Display *display = thread_display();
1452 struct x11drv_win_data *data;
1453 DWORD new_style, changed;
1454
1455 if (hwnd == GetDesktopWindow()) return;
1456 new_style = GetWindowLongW( hwnd, GWL_STYLE );
1457 changed = new_style ^ old_style;
1458
1459 if ((changed & WS_VISIBLE) && (new_style & WS_VISIBLE))
1460 {
1461 /* we don't unmap windows, that causes trouble with the window manager */
1462 if (!(data = X11DRV_get_win_data( hwnd )) &&
1463 !(data = X11DRV_create_win_data( hwnd ))) return;
1464
1465 if (data->whole_window && is_window_rect_mapped( &data->window_rect ))
1466 {
1467 set_wm_hints( display, data );
1468 if (!data->mapped) map_window( display, data, new_style );
1469 }
1470 }
1471
1472 if (changed & WS_DISABLED)
1473 {
1474 data = X11DRV_get_win_data( hwnd );
1475 if (data && data->wm_hints)
1476 {
1477 wine_tsx11_lock();
1478 data->wm_hints->input = !(new_style & WS_DISABLED);
1479 XSetWMHints( display, data->whole_window, data->wm_hints );
1480 wine_tsx11_unlock();
1481 }
1482 }
1483}
1484
1485
1486/***********************************************************************
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001487 * DestroyWindow (X11DRV.@)
1488 */
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001489void X11DRV_DestroyWindow( HWND hwnd )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001490{
Alexandre Julliard9428f062002-06-14 00:08:40 +00001491 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1492 Display *display = thread_data->display;
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001493 struct x11drv_win_data *data;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001494
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001495 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001496
Chris Robinson37d835b2007-09-26 08:17:13 -07001497 if (data->pixmap)
1498 {
1499 destroy_glxpixmap(display, data->gl_drawable);
1500 wine_tsx11_lock();
1501 XFreePixmap(display, data->pixmap);
1502 wine_tsx11_unlock();
1503 }
1504 else if (data->gl_drawable)
Chris Robinson00633e32007-09-25 22:43:38 -07001505 {
1506 wine_tsx11_lock();
1507 XDestroyWindow(display, data->gl_drawable);
1508 wine_tsx11_unlock();
1509 }
1510
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001511 destroy_whole_window( display, data, FALSE );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001512 destroy_icon_window( display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001513
Alexandre Julliarde9307d02008-02-21 20:23:32 +01001514 if (data->colormap)
1515 {
1516 wine_tsx11_lock();
1517 XFreeColormap( display, data->colormap );
1518 wine_tsx11_unlock();
1519 }
1520
Alexandre Julliardf777d702005-01-31 16:34:07 +00001521 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001522 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
1523 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001524 wine_tsx11_lock();
Alexandre Julliarde5515552005-02-09 14:01:40 +00001525 XDeleteContext( display, (XID)hwnd, win_data_context );
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001526 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001527 HeapFree( GetProcessHeap(), 0, data );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001528}
1529
1530
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001531/***********************************************************************
1532 * X11DRV_DestroyNotify
1533 */
1534void X11DRV_DestroyNotify( HWND hwnd, XEvent *event )
1535{
1536 Display *display = event->xdestroywindow.display;
1537 struct x11drv_win_data *data;
1538
1539 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1540
1541 FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window );
1542 destroy_whole_window( display, data, TRUE );
1543}
1544
1545
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001546static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
1547{
1548 struct x11drv_win_data *data;
1549
Alexandre Julliard30d84fc2008-01-22 10:15:38 +01001550 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001551 {
Alexandre Julliard30d84fc2008-01-22 10:15:38 +01001552 data->hwnd = hwnd;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001553 wine_tsx11_lock();
1554 if (!winContext) winContext = XUniqueContext();
1555 if (!win_data_context) win_data_context = XUniqueContext();
1556 XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
1557 wine_tsx11_unlock();
1558 }
1559 return data;
1560}
1561
1562
Alexandre Julliardc19af912008-01-17 19:53:59 +01001563/* initialize the desktop window id in the desktop manager process */
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001564static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd )
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001565{
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001566 struct x11drv_win_data *data;
1567 VisualID visualid;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001568
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001569 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1570 wine_tsx11_lock();
1571 visualid = XVisualIDFromVisual(visual);
1572 wine_tsx11_unlock();
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001573 data->whole_window = data->client_window = root_window;
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001574 data->managed = TRUE;
1575 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1576 SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001577 SetPropA( data->hwnd, client_window_prop, (HANDLE)root_window );
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001578 set_initial_wm_hints( display, data );
1579 return data;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001580}
1581
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001582/**********************************************************************
1583 * CreateDesktopWindow (X11DRV.@)
1584 */
1585BOOL X11DRV_CreateDesktopWindow( HWND hwnd )
1586{
Alexandre Julliardc19af912008-01-17 19:53:59 +01001587 unsigned int width, height;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001588
Alexandre Julliardc19af912008-01-17 19:53:59 +01001589 /* retrieve the real size of the desktop */
1590 SERVER_START_REQ( get_window_rectangles )
1591 {
1592 req->handle = hwnd;
1593 wine_server_call( req );
1594 width = reply->window.right - reply->window.left;
1595 height = reply->window.bottom - reply->window.top;
1596 }
1597 SERVER_END_REQ;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001598
Alexandre Julliardc19af912008-01-17 19:53:59 +01001599 if (!width && !height) /* not initialized yet */
1600 {
1601 SERVER_START_REQ( set_window_pos )
1602 {
1603 req->handle = hwnd;
1604 req->previous = 0;
1605 req->flags = SWP_NOZORDER;
1606 req->window.left = virtual_screen_rect.left;
1607 req->window.top = virtual_screen_rect.top;
1608 req->window.right = virtual_screen_rect.right;
1609 req->window.bottom = virtual_screen_rect.bottom;
1610 req->client = req->window;
1611 wine_server_call( req );
1612 }
1613 SERVER_END_REQ;
1614 }
1615 else
1616 {
1617 Window win = (Window)GetPropA( hwnd, whole_window_prop );
1618 if (win && win != root_window) X11DRV_init_desktop( win, width, height );
1619 }
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001620 return TRUE;
1621}
1622
1623
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001624/**********************************************************************
1625 * CreateWindow (X11DRV.@)
1626 */
Alexandre Julliardd6f67452008-01-24 11:23:09 +01001627BOOL X11DRV_CreateWindow( HWND hwnd )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001628{
1629 Display *display = thread_display();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001630
Alexandre Julliard026974f2008-01-24 10:20:51 +01001631 if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( display ))
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001632 {
Alexandre Julliard026974f2008-01-24 10:20:51 +01001633 /* the desktop win data can't be created lazily */
1634 if (!create_desktop_win_data( display, hwnd )) return FALSE;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001635 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001636 return TRUE;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001637}
1638
1639
1640/***********************************************************************
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001641 * X11DRV_get_win_data
1642 *
1643 * Return the X11 data structure associated with a window.
1644 */
1645struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1646{
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001647 char *data;
Alexandre Julliarde5515552005-02-09 14:01:40 +00001648
1649 if (!hwnd || XFindContext( thread_display(), (XID)hwnd, win_data_context, &data )) data = NULL;
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001650 return (struct x11drv_win_data *)data;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001651}
1652
1653
1654/***********************************************************************
Alexandre Julliard026974f2008-01-24 10:20:51 +01001655 * X11DRV_create_win_data
1656 *
1657 * Create an X11 data window structure for an existing window.
1658 */
1659struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd )
1660{
1661 Display *display = thread_display();
1662 struct x11drv_win_data *data;
1663 HWND parent;
1664
1665 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
1666 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1667
1668 GetWindowRect( hwnd, &data->window_rect );
1669 MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 );
1670 data->whole_rect = data->window_rect;
1671 GetClientRect( hwnd, &data->client_rect );
1672 MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 );
1673
1674 if (parent == GetDesktopWindow())
1675 {
1676 if (!create_whole_window( display, data ))
1677 {
1678 HeapFree( GetProcessHeap(), 0, data );
1679 return NULL;
1680 }
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001681 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1682 hwnd, data->whole_window, data->client_window, wine_dbgstr_rect( &data->window_rect ),
Alexandre Julliard026974f2008-01-24 10:20:51 +01001683 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
1684 }
Alexandre Julliard026974f2008-01-24 10:20:51 +01001685 return data;
1686}
1687
1688
1689/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001690 * X11DRV_get_whole_window
1691 *
1692 * Return the X window associated with the full area of a window
1693 */
1694Window X11DRV_get_whole_window( HWND hwnd )
1695{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001696 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001697
Alexandre Julliardc19af912008-01-17 19:53:59 +01001698 if (!data)
1699 {
1700 if (hwnd == GetDesktopWindow()) return root_window;
1701 return (Window)GetPropA( hwnd, whole_window_prop );
1702 }
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001703 return data->whole_window;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001704}
1705
1706
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001707/***********************************************************************
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001708 * X11DRV_get_client_window
1709 *
1710 * Return the X window associated with the client area of a window
1711 */
1712Window X11DRV_get_client_window( HWND hwnd )
1713{
1714 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1715
1716 if (!data)
1717 {
1718 if (hwnd == GetDesktopWindow()) return root_window;
1719 return (Window)GetPropA( hwnd, client_window_prop );
1720 }
1721 return data->client_window;
1722}
1723
1724
1725/***********************************************************************
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001726 * X11DRV_get_ic
1727 *
1728 * Return the X input context associated with a window
1729 */
1730XIC X11DRV_get_ic( HWND hwnd )
1731{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001732 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Kusanagi Kouichi185157c2008-04-04 20:44:36 +09001733 XIM xim;
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001734
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001735 if (!data) return 0;
Kusanagi Kouichi185157c2008-04-04 20:44:36 +09001736 if (data->xic) return data->xic;
1737 if (!(xim = x11drv_thread_data()->xim)) return 0;
1738 return X11DRV_CreateIC( xim, data );
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001739}
1740
1741
Alexandre Julliard1642fbc2008-02-25 15:59:19 +01001742/***********************************************************************
1743 * X11DRV_GetDC (X11DRV.@)
1744 */
1745void X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect,
1746 const RECT *top_rect, DWORD flags )
1747{
1748 struct x11drv_escape_set_drawable escape;
1749 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1750
1751 escape.code = X11DRV_SET_DRAWABLE;
1752 escape.mode = IncludeInferiors;
1753 escape.fbconfig_id = 0;
1754 escape.gl_drawable = 0;
1755 escape.pixmap = 0;
1756
1757 if (top == hwnd && data && IsIconic( hwnd ) && data->icon_window)
1758 {
1759 escape.drawable = data->icon_window;
1760 }
1761 else if (top == hwnd && (flags & DCX_WINDOW))
1762 {
1763 escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd );
1764 }
1765 else
1766 {
1767 escape.drawable = X11DRV_get_client_window( top );
1768 escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop );
1769 escape.gl_drawable = data ? data->gl_drawable : (Drawable)GetPropA( hwnd, gl_drawable_prop );
1770 escape.pixmap = data ? data->pixmap : (Pixmap)GetPropA( hwnd, pixmap_prop );
Alexandre Julliardaf369102008-03-18 12:42:25 +01001771 if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren;
Alexandre Julliard1642fbc2008-02-25 15:59:19 +01001772 }
1773
1774 escape.dc_rect.left = win_rect->left - top_rect->left;
1775 escape.dc_rect.top = win_rect->top - top_rect->top;
1776 escape.dc_rect.right = win_rect->right - top_rect->left;
1777 escape.dc_rect.bottom = win_rect->bottom - top_rect->top;
1778 escape.drawable_rect.left = top_rect->left;
1779 escape.drawable_rect.top = top_rect->top;
1780 escape.drawable_rect.right = top_rect->right;
1781 escape.drawable_rect.bottom = top_rect->bottom;
1782
1783 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1784}
1785
1786
1787/***********************************************************************
1788 * X11DRV_ReleaseDC (X11DRV.@)
1789 */
1790void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
1791{
1792 struct x11drv_escape_set_drawable escape;
1793
1794 escape.code = X11DRV_SET_DRAWABLE;
1795 escape.drawable = root_window;
1796 escape.mode = IncludeInferiors;
1797 escape.drawable_rect = virtual_screen_rect;
1798 SetRect( &escape.dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left,
1799 virtual_screen_rect.bottom - virtual_screen_rect.top );
1800 escape.fbconfig_id = 0;
1801 escape.gl_drawable = 0;
1802 escape.pixmap = 0;
1803 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1804}
1805
1806
Alexandre Julliarddc26f272008-03-12 15:01:24 +01001807/***********************************************************************
1808 * SetCapture (X11DRV.@)
1809 */
1810void X11DRV_SetCapture( HWND hwnd, UINT flags )
1811{
1812 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1813
Alexandre Julliard78de7e32008-03-24 17:59:40 +01001814 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
Alexandre Julliarddc26f272008-03-12 15:01:24 +01001815
1816 if (hwnd)
1817 {
1818 Window grab_win = X11DRV_get_client_window( GetAncestor( hwnd, GA_ROOT ) );
1819
1820 if (!grab_win) return;
1821 wine_tsx11_lock();
1822 XFlush( gdi_display );
1823 XGrabPointer( thread_data->display, grab_win, False,
1824 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
Alexandre Julliard78de7e32008-03-24 17:59:40 +01001825 GrabModeAsync, GrabModeAsync, None, None, CurrentTime );
Alexandre Julliarddc26f272008-03-12 15:01:24 +01001826 wine_tsx11_unlock();
1827 thread_data->grab_window = grab_win;
1828 }
1829 else /* release capture */
1830 {
1831 wine_tsx11_lock();
1832 XFlush( gdi_display );
1833 XUngrabPointer( thread_data->display, CurrentTime );
1834 wine_tsx11_unlock();
1835 thread_data->grab_window = None;
1836 }
1837}
1838
1839
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001840/*****************************************************************
1841 * SetParent (X11DRV.@)
1842 */
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001843void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001844{
Alexandre Julliard43230042001-05-16 19:52:29 +00001845 Display *display = thread_display();
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001846 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001847
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001848 if (!data) return;
1849 if (parent == old_parent) return;
Alexandre Julliardfb0ff052001-10-16 21:58:58 +00001850
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001851 if (parent != GetDesktopWindow()) /* a child window */
Alexandre Julliard4d32a472005-03-25 10:38:56 +00001852 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001853 if (old_parent == GetDesktopWindow())
Alexandre Julliard4d32a472005-03-25 10:38:56 +00001854 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001855 /* destroy the old X windows */
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001856 destroy_whole_window( display, data, FALSE );
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001857 destroy_icon_window( display, data );
1858 if (data->managed)
Alexandre Julliardf777d702005-01-31 16:34:07 +00001859 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001860 data->managed = FALSE;
1861 RemovePropA( data->hwnd, managed_prop );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001862 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001863 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001864 }
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001865 else /* new top level window */
1866 {
1867 /* FIXME: we ignore errors since we can't really recover anyway */
Alexandre Julliardd147e022008-01-23 21:39:32 +01001868 create_whole_window( display, data );
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001869 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001870}
1871
1872
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001873/*****************************************************************
1874 * SetFocus (X11DRV.@)
1875 *
1876 * Set the X focus.
1877 * Explicit colormap management seems to work only with OLVWM.
1878 */
1879void X11DRV_SetFocus( HWND hwnd )
1880{
Alexandre Julliard43230042001-05-16 19:52:29 +00001881 Display *display = thread_display();
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001882 struct x11drv_win_data *data;
Alexandre Julliard125793d2008-02-18 17:22:51 +01001883 XWindowChanges changes;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001884
Alexandre Julliard125793d2008-02-18 17:22:51 +01001885 /* If setting the focus to 0, uninstall the colormap */
1886 if (!hwnd && root_window == DefaultRootWindow(display))
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001887 {
Alexandre Julliard2496c082003-11-21 00:17:33 +00001888 wine_tsx11_lock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001889 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
Alexandre Julliard2496c082003-11-21 00:17:33 +00001890 XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1891 wine_tsx11_unlock();
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001892 return;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001893 }
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001894
1895 hwnd = GetAncestor( hwnd, GA_ROOT );
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001896
1897 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Todd Mokros88ac4b92005-08-22 09:14:21 +00001898 if (data->managed || !data->whole_window) return;
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001899
1900 /* Set X focus and install colormap */
1901 wine_tsx11_lock();
Alexandre Julliard125793d2008-02-18 17:22:51 +01001902 changes.stack_mode = Above;
1903 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
1904 if (root_window == DefaultRootWindow(display))
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001905 {
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001906 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1907 /* FIXME: this is not entirely correct */
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001908 XSetInputFocus( display, data->whole_window, RevertToParent,
Jeremy White77502e72005-01-14 17:06:40 +00001909 /* CurrentTime */
1910 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001911 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1912 XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001913 }
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001914 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001915}
1916
1917
Alexandre Julliard855308f2008-04-23 15:32:58 +02001918/***********************************************************************
1919 * SetWindowPos (X11DRV.@)
1920 */
1921void X11DRV_SetWindowPos( HWND hwnd, HWND insert_after, UINT swp_flags,
1922 const RECT *rectWindow, const RECT *rectClient,
1923 const RECT *visible_rect, const RECT *valid_rects )
1924{
1925 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1926 Display *display = thread_data->display;
1927 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1928 DWORD new_style = GetWindowLongW( hwnd, GWL_STYLE );
1929 RECT old_window_rect, old_whole_rect, old_client_rect;
1930 int event_type;
1931
1932 if (!data)
1933 {
1934 /* create the win data if the window is being made visible */
1935 if (!(new_style & WS_VISIBLE)) return;
1936 if (!(data = X11DRV_create_win_data( hwnd ))) return;
1937 }
1938
1939 /* check if we need to switch the window to managed */
1940 if (!data->managed && data->whole_window && is_window_managed( hwnd, swp_flags, rectWindow ))
1941 {
1942 TRACE( "making win %p/%lx managed\n", hwnd, data->whole_window );
1943 if (data->mapped) unmap_window( display, data );
1944 data->managed = TRUE;
1945 SetPropA( hwnd, managed_prop, (HANDLE)1 );
1946 }
1947
1948 old_window_rect = data->window_rect;
1949 old_whole_rect = data->whole_rect;
1950 old_client_rect = data->client_rect;
1951 data->window_rect = *rectWindow;
1952 data->whole_rect = *rectWindow;
1953 data->client_rect = *rectClient;
1954 X11DRV_window_to_X_rect( data, &data->whole_rect );
1955 if (memcmp( visible_rect, &data->whole_rect, sizeof(RECT) ))
1956 {
1957 TRACE( "%p: need to update visible rect %s -> %s\n", hwnd,
1958 wine_dbgstr_rect(visible_rect), wine_dbgstr_rect(&data->whole_rect) );
1959 SERVER_START_REQ( set_window_visible_rect )
1960 {
1961 req->handle = hwnd;
1962 req->flags = swp_flags;
1963 req->visible.left = data->whole_rect.left;
1964 req->visible.top = data->whole_rect.top;
1965 req->visible.right = data->whole_rect.right;
1966 req->visible.bottom = data->whole_rect.bottom;
1967 wine_server_call( req );
1968 }
1969 SERVER_END_REQ;
1970 }
1971
1972 TRACE( "win %p window %s client %s style %08x flags %08x\n",
1973 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style, swp_flags );
1974
1975 if (!IsRectEmpty( &valid_rects[0] ))
1976 {
1977 int x_offset = old_whole_rect.left - data->whole_rect.left;
1978 int y_offset = old_whole_rect.top - data->whole_rect.top;
1979
1980 /* if all that happened is that the whole window moved, copy everything */
1981 if (!(swp_flags & SWP_FRAMECHANGED) &&
1982 old_whole_rect.right - data->whole_rect.right == x_offset &&
1983 old_whole_rect.bottom - data->whole_rect.bottom == y_offset &&
1984 old_client_rect.left - data->client_rect.left == x_offset &&
1985 old_client_rect.right - data->client_rect.right == x_offset &&
1986 old_client_rect.top - data->client_rect.top == y_offset &&
1987 old_client_rect.bottom - data->client_rect.bottom == y_offset &&
1988 !memcmp( &valid_rects[0], &data->client_rect, sizeof(RECT) ))
1989 {
1990 /* if we have an X window the bits will be moved by the X server */
1991 if (!data->whole_window)
1992 move_window_bits( data, &old_whole_rect, &data->whole_rect, &old_client_rect );
1993 }
1994 else
1995 move_window_bits( data, &valid_rects[1], &valid_rects[0], &old_client_rect );
1996 }
1997
1998 wine_tsx11_lock();
1999 XFlush( gdi_display ); /* make sure painting is done before we move the window */
2000 wine_tsx11_unlock();
2001
2002 sync_client_position( display, data, swp_flags, &old_client_rect, &old_whole_rect );
2003
2004 if (!data->whole_window) return;
2005
2006 /* check if we are currently processing an event relevant to this window */
2007 event_type = 0;
2008 if (thread_data->current_event && thread_data->current_event->xany.window == data->whole_window)
2009 event_type = thread_data->current_event->type;
2010
2011 if (event_type != ConfigureNotify && event_type != PropertyNotify)
2012 event_type = 0; /* ignore other events */
2013
2014 if (data->mapped && (!(new_style & WS_VISIBLE) ||
2015 (!event_type && !is_window_rect_mapped( rectWindow ))))
2016 unmap_window( display, data );
2017
2018 /* don't change position if we are about to minimize or maximize a managed window */
2019 if (!event_type &&
2020 !(data->managed && (swp_flags & SWP_STATECHANGED) && (new_style & (WS_MINIMIZE|WS_MAXIMIZE))))
2021 sync_window_position( display, data, swp_flags, &old_client_rect, &old_whole_rect );
2022
2023 if ((new_style & WS_VISIBLE) &&
2024 ((new_style & WS_MINIMIZE) || is_window_rect_mapped( rectWindow )))
2025 {
2026 if (!data->mapped || (swp_flags & (SWP_FRAMECHANGED|SWP_STATECHANGED)))
2027 set_wm_hints( display, data );
2028
2029 if (!data->mapped)
2030 {
2031 map_window( display, data, new_style );
2032 }
2033 else if ((swp_flags & SWP_STATECHANGED) && (!data->iconic != !(new_style & WS_MINIMIZE)))
2034 {
2035 data->iconic = (new_style & WS_MINIMIZE) != 0;
2036 TRACE( "changing win %p iconic state to %u\n", data->hwnd, data->iconic );
2037 wine_tsx11_lock();
2038 if (data->iconic)
2039 XIconifyWindow( display, data->whole_window, DefaultScreen(display) );
2040 else if (is_window_rect_mapped( rectWindow ))
2041 XMapWindow( display, data->whole_window );
2042 wine_tsx11_unlock();
2043 update_net_wm_states( display, data );
2044 }
2045 else if (!event_type)
2046 {
2047 update_net_wm_states( display, data );
2048 }
2049 }
2050
2051 wine_tsx11_lock();
2052 XFlush( display ); /* make sure changes are done before we start painting again */
2053 wine_tsx11_unlock();
2054}
2055
2056
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002057/**********************************************************************
Patrik Stridvall01d5e5b2001-07-02 19:59:40 +00002058 * SetWindowIcon (X11DRV.@)
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002059 *
2060 * hIcon or hIconSm has changed (or is being initialised for the
2061 * first time). Complete the X11 driver-specific initialisation
2062 * and set the window hints.
2063 *
2064 * This is not entirely correct, may need to create
2065 * an icon window and set the pixmap as a background
2066 */
Alexandre Julliard446d8322003-12-31 23:51:52 +00002067void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002068{
Alexandre Julliard43230042001-05-16 19:52:29 +00002069 Display *display = thread_display();
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00002070 struct x11drv_win_data *data;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002071
Alexandre Julliard446d8322003-12-31 23:51:52 +00002072 if (type != ICON_BIG) return; /* nothing to do here */
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002073
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00002074 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Alexandre Julliardf777d702005-01-31 16:34:07 +00002075 if (!data->whole_window) return;
Alexandre Julliardd7726c32005-02-01 18:53:59 +00002076 if (!data->managed) return;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00002077
Alexandre Julliardbde89572007-08-16 23:27:37 +02002078 if (data->wm_hints)
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002079 {
Alexandre Julliardbde89572007-08-16 23:27:37 +02002080 set_icon_hints( display, data, icon );
Alexandre Julliarde9119c12002-09-24 18:36:51 +00002081 wine_tsx11_lock();
Alexandre Julliardbde89572007-08-16 23:27:37 +02002082 XSetWMHints( display, data->whole_window, data->wm_hints );
Alexandre Julliarde9119c12002-09-24 18:36:51 +00002083 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002084 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002085}
Alexandre Julliard395928d2008-01-23 16:30:18 +01002086
2087
2088/***********************************************************************
2089 * SetWindowRgn (X11DRV.@)
2090 *
2091 * Assign specified region to window (for non-rectangular windows)
2092 */
2093int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
2094{
2095 struct x11drv_win_data *data;
2096
2097 if ((data = X11DRV_get_win_data( hwnd )))
2098 {
2099 sync_window_region( thread_display(), data, hrgn );
Alexandre Julliard395928d2008-01-23 16:30:18 +01002100 }
2101 else if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
2102 {
2103 FIXME( "not supported on other thread window %p\n", hwnd );
2104 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2105 return FALSE;
2106 }
2107
2108 return TRUE;
2109}
Alexandre Julliard24dbaa02008-04-17 16:13:34 +02002110
2111
2112/***********************************************************************
2113 * is_netwm_supported
2114 */
2115static BOOL is_netwm_supported( Display *display, Atom atom )
2116{
2117 static Atom *net_supported;
2118 static int net_supported_count = -1;
2119 int i;
2120
2121 wine_tsx11_lock();
2122 if (net_supported_count == -1)
2123 {
2124 Atom type;
2125 int format;
2126 unsigned long count, remaining;
2127
2128 if (!XGetWindowProperty( display, DefaultRootWindow(display), x11drv_atom(_NET_SUPPORTED), 0,
2129 ~0UL, False, XA_ATOM, &type, &format, &count,
2130 &remaining, (unsigned char **)&net_supported ))
2131 net_supported_count = get_property_size( format, count ) / sizeof(Atom);
2132 else
2133 net_supported_count = 0;
2134 }
2135 wine_tsx11_unlock();
2136
2137 for (i = 0; i < net_supported_count; i++)
2138 if (net_supported[i] == atom) return TRUE;
2139 return FALSE;
2140}
2141
2142
2143/***********************************************************************
2144 * SysCommand (X11DRV.@)
2145 *
2146 * Perform WM_SYSCOMMAND handling.
2147 */
2148LRESULT X11DRV_SysCommand( HWND hwnd, WPARAM wparam, LPARAM lparam )
2149{
2150 WPARAM hittest = wparam & 0x0f;
2151 DWORD dwPoint;
2152 int x, y, dir;
2153 XEvent xev;
2154 Display *display = thread_display();
2155 struct x11drv_win_data *data;
2156
2157 if (!(data = X11DRV_get_win_data( hwnd ))) return -1;
2158 if (!data->whole_window || !data->managed || !data->mapped) return -1;
2159
2160 switch (wparam & 0xfff0)
2161 {
2162 case SC_MOVE:
2163 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
2164 else dir = _NET_WM_MOVERESIZE_MOVE;
2165 break;
2166 case SC_SIZE:
2167 /* windows without WS_THICKFRAME are not resizable through the window manager */
2168 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) return -1;
2169
2170 switch (hittest)
2171 {
2172 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
2173 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
2174 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
2175 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
2176 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
2177 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
2178 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
2179 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
2180 default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break;
2181 }
2182 break;
2183
2184 case SC_KEYMENU:
2185 /* prevent a simple ALT press+release from activating the system menu,
2186 * as that can get confusing on managed windows */
2187 if ((WCHAR)lparam) return -1; /* got an explicit char */
2188 if (GetMenu( hwnd )) return -1; /* window has a real menu */
2189 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_SYSMENU)) return -1; /* no system menu */
2190 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam, lparam );
2191 return 0;
2192
2193 default:
2194 return -1;
2195 }
2196
2197 if (IsZoomed(hwnd)) return -1;
2198
2199 if (!is_netwm_supported( display, x11drv_atom(_NET_WM_MOVERESIZE) ))
2200 {
2201 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
2202 return -1;
2203 }
2204
2205 dwPoint = GetMessagePos();
2206 x = (short)LOWORD(dwPoint);
2207 y = (short)HIWORD(dwPoint);
2208
2209 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd, x, y, dir);
2210
2211 xev.xclient.type = ClientMessage;
2212 xev.xclient.window = X11DRV_get_whole_window(hwnd);
2213 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
2214 xev.xclient.serial = 0;
2215 xev.xclient.display = display;
2216 xev.xclient.send_event = True;
2217 xev.xclient.format = 32;
2218 xev.xclient.data.l[0] = x; /* x coord */
2219 xev.xclient.data.l[1] = y; /* y coord */
2220 xev.xclient.data.l[2] = dir; /* direction */
2221 xev.xclient.data.l[3] = 1; /* button */
2222 xev.xclient.data.l[4] = 0; /* unused */
2223
2224 /* need to ungrab the pointer that may have been automatically grabbed
2225 * with a ButtonPress event */
2226 wine_tsx11_lock();
2227 XUngrabPointer( display, CurrentTime );
2228 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
2229 wine_tsx11_unlock();
2230 return 0;
2231}