blob: 0ca0836de0857645a857e43c8941650b57e1c2b1 [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 {
Dmitry Timoshkov15c82062008-10-07 12:14:52 +0900108 HMONITOR hmon;
109 MONITORINFO mi;
110
Vitaliy Margolenabcbcc32007-02-10 10:40:50 -0700111 /* popup with sysmenu == caption are managed */
112 if (style & WS_SYSMENU) return TRUE;
113 /* full-screen popup windows are managed */
Dmitry Timoshkov15c82062008-10-07 12:14:52 +0900114 hmon = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY );
115 mi.cbSize = sizeof( mi );
116 GetMonitorInfoW( hmon, &mi );
117 if (window_rect->left <= mi.rcWork.left && window_rect->right >= mi.rcWork.right &&
118 window_rect->top <= mi.rcWork.top && window_rect->bottom >= mi.rcWork.bottom)
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000119 return TRUE;
Alex Pasadynd18c8ca2004-02-06 05:17:55 +0000120 }
Alexandre Julliard1f99d802008-04-25 14:26:52 +0200121 /* application windows are managed */
122 ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE );
123 if (ex_style & WS_EX_APPWINDOW) return TRUE;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000124 /* default: not managed */
125 return FALSE;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000126}
127
128
129/***********************************************************************
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000130 * X11DRV_is_window_rect_mapped
131 *
132 * Check if the X whole window should be mapped based on its rectangle
133 */
Alexandre Julliard855308f2008-04-23 15:32:58 +0200134static BOOL is_window_rect_mapped( const RECT *rect )
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000135{
Alexandre Julliard8a5f5782008-05-01 17:44:56 +0200136 /* don't map if rect is empty */
137 if (IsRectEmpty( rect )) return FALSE;
138
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000139 /* don't map if rect is off-screen */
Alexandre Julliard3c305f92006-10-23 14:37:17 +0200140 if (rect->left >= virtual_screen_rect.right ||
141 rect->top >= virtual_screen_rect.bottom ||
142 rect->right <= virtual_screen_rect.left ||
143 rect->bottom <= virtual_screen_rect.top)
144 return FALSE;
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000145
146 return TRUE;
147}
148
149
150/***********************************************************************
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200151 * is_window_resizable
152 *
153 * Check if window should be made resizable by the window manager
154 */
155static inline BOOL is_window_resizable( struct x11drv_win_data *data, DWORD style )
156{
157 if (style & WS_THICKFRAME) return TRUE;
158 /* Metacity needs the window to be resizable to make it fullscreen */
159 return (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width &&
160 data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height);
161}
162
163
164/***********************************************************************
Alexandre Julliard8a5f5782008-05-01 17:44:56 +0200165 * get_window_owner
166 */
167static HWND get_window_owner( HWND hwnd )
168{
169 RECT rect;
170 HWND owner = GetWindow( hwnd, GW_OWNER );
171 /* ignore the zero-size owners used by Delphi apps */
172 if (owner && GetWindowRect( owner, &rect ) && IsRectEmpty( &rect )) owner = 0;
173 return owner;
174}
175
176
177/***********************************************************************
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200178 * get_mwm_decorations
179 */
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900180static unsigned long get_mwm_decorations( struct x11drv_win_data *data,
181 DWORD style, DWORD ex_style )
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200182{
183 unsigned long ret = 0;
184
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900185 if (!decorated_mode) return 0;
186
187 if (IsRectEmpty( &data->window_rect )) return 0;
Alexandre Julliard2bbf00e2008-04-29 12:46:16 +0200188 if (data->shaped) return 0;
Matthew D'Asaro4217fcb2008-04-10 12:53:45 -0700189
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200190 if (ex_style & WS_EX_TOOLWINDOW) return 0;
191
192 if ((style & WS_CAPTION) == WS_CAPTION)
193 {
194 ret |= MWM_DECOR_TITLE | MWM_DECOR_BORDER;
195 if (style & WS_SYSMENU) ret |= MWM_DECOR_MENU;
196 if (style & WS_MINIMIZEBOX) ret |= MWM_DECOR_MINIMIZE;
197 if (style & WS_MAXIMIZEBOX) ret |= MWM_DECOR_MAXIMIZE;
198 }
199 if (ex_style & WS_EX_DLGMODALFRAME) ret |= MWM_DECOR_BORDER;
200 else if (style & WS_THICKFRAME) ret |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
201 else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) ret |= MWM_DECOR_BORDER;
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200202 return ret;
203}
204
205
206/***********************************************************************
207 * get_x11_rect_offset
208 *
209 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
210 */
211static void get_x11_rect_offset( struct x11drv_win_data *data, RECT *rect )
212{
213 DWORD style, ex_style, style_mask = 0, ex_style_mask = 0;
214 unsigned long decor;
215
216 rect->top = rect->bottom = rect->left = rect->right = 0;
217
218 style = GetWindowLongW( data->hwnd, GWL_STYLE );
219 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900220 decor = get_mwm_decorations( data, style, ex_style );
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200221
222 if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION;
223 if (decor & MWM_DECOR_BORDER)
224 {
225 style_mask |= WS_DLGFRAME | WS_THICKFRAME;
226 ex_style_mask |= WS_EX_DLGMODALFRAME;
227 }
228
229 AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask );
230}
231
232
233/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000234 * get_window_attributes
235 *
Alexandre Julliard883cff42001-06-12 04:02:10 +0000236 * Fill the window attributes structure for an X window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000237 */
Alexandre Julliard6bb18e22006-03-27 15:33:43 +0200238static int get_window_attributes( Display *display, struct x11drv_win_data *data,
239 XSetWindowAttributes *attr )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000240{
Alexandre Julliardd7726c32005-02-01 18:53:59 +0000241 attr->override_redirect = !data->managed;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000242 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000243 attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0);
Alexandre Julliard9428f062002-06-14 00:08:40 +0000244 attr->cursor = x11drv_thread_data()->cursor;
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200245 attr->bit_gravity = NorthWestGravity;
Alexandre Julliard6ba06fa2008-04-23 15:33:29 +0200246 attr->win_gravity = StaticGravity;
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200247 attr->backing_store = NotUseful;
248 attr->event_mask = (ExposureMask | PointerMotionMask |
249 ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
250 KeyPressMask | KeyReleaseMask | FocusChangeMask | KeymapStateMask);
Alexandre Julliard5a5344b2008-02-27 19:11:43 +0100251 if (data->managed) attr->event_mask |= StructureNotifyMask | PropertyChangeMask;
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200252
253 return (CWOverrideRedirect | CWSaveUnder | CWColormap | CWCursor |
254 CWEventMask | CWBitGravity | CWBackingStore);
Alexandre Julliard883cff42001-06-12 04:02:10 +0000255}
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000256
Alexandre Julliard883cff42001-06-12 04:02:10 +0000257
258/***********************************************************************
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100259 * create_client_window
260 */
261static Window create_client_window( Display *display, struct x11drv_win_data *data, XVisualInfo *vis )
262{
263 int cx, cy, mask;
264 XSetWindowAttributes attr;
265 Window client;
Alexandre Julliard30a133f2008-05-13 10:43:48 +0200266 Visual *client_visual = vis ? vis->visual : visual;
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100267
268 attr.bit_gravity = NorthWestGravity;
269 attr.win_gravity = NorthWestGravity;
270 attr.backing_store = NotUseful;
271 attr.event_mask = (ExposureMask | PointerMotionMask |
272 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
273 mask = CWEventMask | CWBitGravity | CWWinGravity | CWBackingStore;
274
275 if ((cx = data->client_rect.right - data->client_rect.left) <= 0) cx = 1;
276 if ((cy = data->client_rect.bottom - data->client_rect.top) <= 0) cy = 1;
277
278 wine_tsx11_lock();
279
280 if (vis)
281 {
282 attr.colormap = XCreateColormap( display, root_window, vis->visual,
283 (vis->class == PseudoColor || vis->class == GrayScale ||
284 vis->class == DirectColor) ? AllocAll : AllocNone );
285 mask |= CWColormap;
286 }
287
288 client = XCreateWindow( display, data->whole_window,
289 data->client_rect.left - data->whole_rect.left,
290 data->client_rect.top - data->whole_rect.top,
291 cx, cy, 0, screen_depth, InputOutput,
Alexandre Julliard30a133f2008-05-13 10:43:48 +0200292 client_visual, mask, &attr );
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100293 if (!client)
294 {
295 wine_tsx11_unlock();
296 return 0;
297 }
298
299 if (data->client_window)
300 {
Alexandre Julliard51d3d622008-03-05 20:52:14 +0100301 struct x11drv_thread_data *thread_data = x11drv_thread_data();
302 if (thread_data->cursor_window == data->client_window) thread_data->cursor_window = None;
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100303 XDeleteContext( display, data->client_window, winContext );
304 XDestroyWindow( display, data->client_window );
305 }
306 data->client_window = client;
Alexandre Julliard30a133f2008-05-13 10:43:48 +0200307 data->visualid = XVisualIDFromVisual( client_visual );
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100308
309 if (data->colormap) XFreeColormap( display, data->colormap );
310 data->colormap = vis ? attr.colormap : 0;
311
312 XMapWindow( display, data->client_window );
313 XSaveContext( display, data->client_window, winContext, (char *)data->hwnd );
314 wine_tsx11_unlock();
315
316 SetPropA( data->hwnd, client_window_prop, (HANDLE)data->client_window );
317 return data->client_window;
318}
319
320
321/***********************************************************************
Alexandre Julliard855308f2008-04-23 15:32:58 +0200322 * sync_window_style
Alexandre Julliard883cff42001-06-12 04:02:10 +0000323 *
324 * Change the X window attributes when the window style has changed.
325 */
Alexandre Julliard855308f2008-04-23 15:32:58 +0200326static void sync_window_style( Display *display, struct x11drv_win_data *data )
Alexandre Julliard883cff42001-06-12 04:02:10 +0000327{
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200328 if (data->whole_window != root_window)
329 {
330 XSetWindowAttributes attr;
331 int mask = get_window_attributes( display, data, &attr );
Alexandre Julliard883cff42001-06-12 04:02:10 +0000332
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200333 wine_tsx11_lock();
Alexandre Julliard6d5f5442006-03-06 21:02:59 +0100334 XChangeWindowAttributes( display, data->whole_window, mask, &attr );
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200335 wine_tsx11_unlock();
336 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000337}
338
339
340/***********************************************************************
Alexandre Julliard395928d2008-01-23 16:30:18 +0100341 * sync_window_region
342 *
343 * Update the X11 window region.
344 */
Alexandre Julliard9d45cfd2008-09-08 15:51:08 +0200345static void sync_window_region( Display *display, struct x11drv_win_data *data, HRGN win_region )
Alexandre Julliard395928d2008-01-23 16:30:18 +0100346{
347#ifdef HAVE_LIBXSHAPE
Alexandre Julliard9d45cfd2008-09-08 15:51:08 +0200348 HRGN hrgn = win_region;
349
Alexandre Julliard395928d2008-01-23 16:30:18 +0100350 if (!data->whole_window) return;
Alexandre Julliard2bbf00e2008-04-29 12:46:16 +0200351 data->shaped = FALSE;
Alexandre Julliard395928d2008-01-23 16:30:18 +0100352
Alexandre Julliard9d45cfd2008-09-08 15:51:08 +0200353 if (hrgn == (HRGN)1) /* hack: win_region == 1 means retrieve region from server */
354 {
355 if (!(hrgn = CreateRectRgn( 0, 0, 0, 0 ))) return;
356 if (GetWindowRgn( data->hwnd, hrgn ) == ERROR)
357 {
358 DeleteObject( hrgn );
359 hrgn = 0;
360 }
361 }
362
Alexandre Julliard395928d2008-01-23 16:30:18 +0100363 if (!hrgn)
364 {
365 wine_tsx11_lock();
366 XShapeCombineMask( display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet );
367 wine_tsx11_unlock();
368 }
369 else
370 {
371 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
372 if (pRegionData)
373 {
374 wine_tsx11_lock();
375 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
376 data->window_rect.left - data->whole_rect.left,
377 data->window_rect.top - data->whole_rect.top,
378 (XRectangle *)pRegionData->Buffer,
379 pRegionData->rdh.nCount, ShapeSet, YXBanded );
380 wine_tsx11_unlock();
381 HeapFree(GetProcessHeap(), 0, pRegionData);
Alexandre Julliard2bbf00e2008-04-29 12:46:16 +0200382 data->shaped = TRUE;
Alexandre Julliard395928d2008-01-23 16:30:18 +0100383 }
384 }
Alexandre Julliard9d45cfd2008-09-08 15:51:08 +0200385 if (hrgn && hrgn != win_region) DeleteObject( hrgn );
Alexandre Julliard395928d2008-01-23 16:30:18 +0100386#endif /* HAVE_LIBXSHAPE */
387}
388
389
390/***********************************************************************
Alexandre Julliardbe3c3a52008-09-12 15:54:02 +0200391 * sync_window_opacity
392 */
393static void sync_window_opacity( Display *display, Window win,
394 COLORREF key, BYTE alpha, DWORD flags )
395{
396 unsigned long opacity = 0xffffffff;
397
398 if (flags & LWA_ALPHA) opacity = (0xffffffff / 0xff) * alpha;
399
400 if (flags & LWA_COLORKEY) FIXME("LWA_COLORKEY not supported\n");
401
402 wine_tsx11_lock();
403 if (opacity == 0xffffffff)
404 XDeleteProperty( display, win, x11drv_atom(_NET_WM_WINDOW_OPACITY) );
405 else
406 XChangeProperty( display, win, x11drv_atom(_NET_WM_WINDOW_OPACITY),
407 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&opacity, 1 );
408 wine_tsx11_unlock();
409}
410
411
412/***********************************************************************
Alexandre Julliard3ba20252008-01-23 16:32:55 +0100413 * sync_window_text
414 */
415static void sync_window_text( Display *display, Window win, const WCHAR *text )
416{
417 UINT count;
418 char *buffer, *utf8_buffer;
419 XTextProperty prop;
420
421 /* allocate new buffer for window text */
422 count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
423 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) return;
424 WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
425
426 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
427 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
428 {
429 HeapFree( GetProcessHeap(), 0, buffer );
430 return;
431 }
432 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
433
434 wine_tsx11_lock();
435 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
436 {
437 XSetWMName( display, win, &prop );
438 XSetWMIconName( display, win, &prop );
439 XFree( prop.value );
440 }
441 /*
442 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
443 according to the standard
444 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
445 */
446 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
447 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
448 wine_tsx11_unlock();
449
450 HeapFree( GetProcessHeap(), 0, utf8_buffer );
451 HeapFree( GetProcessHeap(), 0, buffer );
452}
453
454
455/***********************************************************************
Alexandre Julliard370368a2008-09-08 15:42:24 +0200456 * set_win_format
Chris Robinsond9571c92007-09-15 13:02:32 -0700457 */
Alexandre Julliard370368a2008-09-08 15:42:24 +0200458static BOOL set_win_format( HWND hwnd, XID fbconfig_id )
Chris Robinsond9571c92007-09-15 13:02:32 -0700459{
460 struct x11drv_win_data *data;
Chris Robinson00633e32007-09-25 22:43:38 -0700461 XVisualInfo *vis;
Chris Robinson00633e32007-09-25 22:43:38 -0700462 int w, h;
Chris Robinsond9571c92007-09-15 13:02:32 -0700463
Alexandre Julliard026974f2008-01-24 10:20:51 +0100464 if (!(data = X11DRV_get_win_data(hwnd)) &&
465 !(data = X11DRV_create_win_data(hwnd))) return FALSE;
Chris Robinsond9571c92007-09-15 13:02:32 -0700466
Alexandre Julliarded371742008-05-28 17:02:07 +0200467 if (!(vis = visual_from_fbconfig_id(fbconfig_id))) return FALSE;
Chris Robinson00633e32007-09-25 22:43:38 -0700468
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100469 if (data->whole_window)
Chris Robinson00633e32007-09-25 22:43:38 -0700470 {
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200471 Display *display = thread_display();
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100472 Window client = data->client_window;
473
Alexandre Julliard30a133f2008-05-13 10:43:48 +0200474 if (vis->visualid != data->visualid)
Chris Robinson00633e32007-09-25 22:43:38 -0700475 {
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100476 client = create_client_window( display, data, vis );
477 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client, data->hwnd, fbconfig_id );
Chris Robinson00633e32007-09-25 22:43:38 -0700478 }
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100479 wine_tsx11_lock();
480 XFree(vis);
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200481 XFlush( display );
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100482 wine_tsx11_unlock();
483 if (client) goto done;
484 return FALSE;
Chris Robinson00633e32007-09-25 22:43:38 -0700485 }
486
487 w = data->client_rect.right - data->client_rect.left;
488 h = data->client_rect.bottom - data->client_rect.top;
489
490 if(w <= 0) w = 1;
491 if(h <= 0) h = 1;
492
Chris Robinson00633e32007-09-25 22:43:38 -0700493#ifdef SONAME_LIBXCOMPOSITE
494 if(usexcomposite)
495 {
496 XSetWindowAttributes attrib;
Alexandre Julliardb6059802008-05-12 19:14:11 +0200497 static Window dummy_parent;
Chris Robinson00633e32007-09-25 22:43:38 -0700498
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100499 wine_tsx11_lock();
Alexandre Julliardb6059802008-05-12 19:14:11 +0200500 attrib.override_redirect = True;
501 if (!dummy_parent)
502 {
503 dummy_parent = XCreateWindow( gdi_display, root_window, -1, -1, 1, 1, 0, screen_depth,
504 InputOutput, visual, CWOverrideRedirect, &attrib );
505 XMapWindow( gdi_display, dummy_parent );
506 }
507 data->colormap = XCreateColormap(gdi_display, dummy_parent, vis->visual,
Alexandre Julliarde9307d02008-02-21 20:23:32 +0100508 (vis->class == PseudoColor ||
509 vis->class == GrayScale ||
510 vis->class == DirectColor) ?
511 AllocAll : AllocNone);
Alexandre Julliarde9307d02008-02-21 20:23:32 +0100512 attrib.colormap = data->colormap;
Chris Robinson00633e32007-09-25 22:43:38 -0700513 XInstallColormap(gdi_display, attrib.colormap);
514
Roderick Colenbranderf0307d92008-04-22 22:15:15 +0000515 if(data->gl_drawable) XDestroyWindow(gdi_display, data->gl_drawable);
Alexandre Julliardb6059802008-05-12 19:14:11 +0200516 data->gl_drawable = XCreateWindow(gdi_display, dummy_parent, -w, 0, w, h, 0,
Chris Robinson00633e32007-09-25 22:43:38 -0700517 vis->depth, InputOutput, vis->visual,
518 CWColormap | CWOverrideRedirect,
519 &attrib);
520 if(data->gl_drawable)
521 {
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200522 pXCompositeRedirectWindow(gdi_display, data->gl_drawable,
Chris Robinson00633e32007-09-25 22:43:38 -0700523 CompositeRedirectManual);
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200524 XMapWindow(gdi_display, data->gl_drawable);
Chris Robinson00633e32007-09-25 22:43:38 -0700525 }
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100526 XFree(vis);
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200527 XFlush( gdi_display );
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100528 wine_tsx11_unlock();
Chris Robinson00633e32007-09-25 22:43:38 -0700529 }
Chris Robinson37d835b2007-09-26 08:17:13 -0700530 else
Chris Robinson00633e32007-09-25 22:43:38 -0700531#endif
Chris Robinson37d835b2007-09-26 08:17:13 -0700532 {
533 WARN("XComposite is not available, using GLXPixmap hack\n");
534
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100535 wine_tsx11_lock();
Roderick Colenbranderf0307d92008-04-22 22:15:15 +0000536
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200537 if(data->pixmap) XFreePixmap(gdi_display, data->pixmap);
538 data->pixmap = XCreatePixmap(gdi_display, root_window, w, h, vis->depth);
Chris Robinson37d835b2007-09-26 08:17:13 -0700539 if(!data->pixmap)
540 {
Chris Robinson37d835b2007-09-26 08:17:13 -0700541 XFree(vis);
542 wine_tsx11_unlock();
543 return FALSE;
544 }
545
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200546 if(data->gl_drawable) destroy_glxpixmap(gdi_display, data->gl_drawable);
547 data->gl_drawable = create_glxpixmap(gdi_display, vis, data->pixmap);
Chris Robinson37d835b2007-09-26 08:17:13 -0700548 if(!data->gl_drawable)
549 {
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200550 XFreePixmap(gdi_display, data->pixmap);
Chris Robinson37d835b2007-09-26 08:17:13 -0700551 data->pixmap = 0;
552 }
Chris Robinson00633e32007-09-25 22:43:38 -0700553 XFree(vis);
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200554 XFlush( gdi_display );
Chris Robinson00633e32007-09-25 22:43:38 -0700555 wine_tsx11_unlock();
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100556 if (data->pixmap) SetPropA(hwnd, pixmap_prop, (HANDLE)data->pixmap);
Chris Robinson00633e32007-09-25 22:43:38 -0700557 }
558
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100559 if (!data->gl_drawable) return FALSE;
Chris Robinson00633e32007-09-25 22:43:38 -0700560
561 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
562 data->gl_drawable, fbconfig_id);
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100563 SetPropA(hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
Chris Robinson00633e32007-09-25 22:43:38 -0700564
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100565done:
Chris Robinsond9571c92007-09-15 13:02:32 -0700566 data->fbconfig_id = fbconfig_id;
567 SetPropA(hwnd, fbconfig_id_prop, (HANDLE)data->fbconfig_id);
Alexandre Julliard9727aa82008-04-21 20:32:22 +0200568 /* force DCE invalidation */
569 SetWindowPos( hwnd, 0, 0, 0, 0, 0,
570 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE |
Alexandre Julliardfc8c21c2008-06-18 20:10:56 +0200571 SWP_NOREDRAW | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_STATECHANGED);
Chris Robinsond9571c92007-09-15 13:02:32 -0700572 return TRUE;
573}
574
Alexandre Julliardbbfbe242008-01-23 12:28:01 +0100575/***********************************************************************
Alexandre Julliard8ee07d42008-02-21 12:29:36 +0100576 * sync_gl_drawable
Alexandre Julliardbbfbe242008-01-23 12:28:01 +0100577 */
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200578static void sync_gl_drawable(struct x11drv_win_data *data)
Chris Robinson00633e32007-09-25 22:43:38 -0700579{
580 int w = data->client_rect.right - data->client_rect.left;
581 int h = data->client_rect.bottom - data->client_rect.top;
Chris Robinson37d835b2007-09-26 08:17:13 -0700582 XVisualInfo *vis;
Chris Robinson37d835b2007-09-26 08:17:13 -0700583 Drawable glxp;
584 Pixmap pix;
Chris Robinson00633e32007-09-25 22:43:38 -0700585
Alexandre Julliardf13ef6b2008-02-22 16:30:10 +0100586 if (w <= 0) w = 1;
587 if (h <= 0) h = 1;
588
Chris Robinson00633e32007-09-25 22:43:38 -0700589 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data->gl_drawable, w, h);
590#ifdef SONAME_LIBXCOMPOSITE
591 if(usexcomposite)
592 {
593 wine_tsx11_lock();
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200594 XMoveResizeWindow(gdi_display, data->gl_drawable, -w, 0, w, h);
Chris Robinson00633e32007-09-25 22:43:38 -0700595 wine_tsx11_unlock();
596 return;
597 }
598#endif
Chris Robinson37d835b2007-09-26 08:17:13 -0700599
Alexandre Julliarded371742008-05-28 17:02:07 +0200600 if (!(vis = visual_from_fbconfig_id(data->fbconfig_id))) return;
601
Chris Robinson37d835b2007-09-26 08:17:13 -0700602 wine_tsx11_lock();
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200603 pix = XCreatePixmap(gdi_display, root_window, w, h, vis->depth);
Chris Robinson37d835b2007-09-26 08:17:13 -0700604 if(!pix)
605 {
606 ERR("Failed to create pixmap for offscreen rendering\n");
607 XFree(vis);
608 wine_tsx11_unlock();
609 return;
610 }
611
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200612 glxp = create_glxpixmap(gdi_display, vis, pix);
Chris Robinson37d835b2007-09-26 08:17:13 -0700613 if(!glxp)
614 {
615 ERR("Failed to create drawable for offscreen rendering\n");
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200616 XFreePixmap(gdi_display, pix);
Chris Robinson37d835b2007-09-26 08:17:13 -0700617 XFree(vis);
618 wine_tsx11_unlock();
619 return;
620 }
621
622 XFree(vis);
623
624 mark_drawable_dirty(data->gl_drawable, glxp);
625
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200626 XFreePixmap(gdi_display, data->pixmap);
627 destroy_glxpixmap(gdi_display, data->gl_drawable);
Alexandre Julliard9727aa82008-04-21 20:32:22 +0200628 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp, data->gl_drawable );
Chris Robinson37d835b2007-09-26 08:17:13 -0700629
630 data->pixmap = pix;
631 data->gl_drawable = glxp;
632
Alexandre Julliard6e9dea82008-05-12 19:37:54 +0200633 XFlush( gdi_display );
Chris Robinson37d835b2007-09-26 08:17:13 -0700634 wine_tsx11_unlock();
635
636 SetPropA(data->hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
637 SetPropA(data->hwnd, pixmap_prop, (HANDLE)data->pixmap);
Chris Robinson00633e32007-09-25 22:43:38 -0700638}
639
Chris Robinsond9571c92007-09-15 13:02:32 -0700640
641/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000642 * get_window_changes
643 *
644 * fill the window changes structure
645 */
646static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
647{
648 int mask = 0;
649
650 if (old->right - old->left != new->right - new->left )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000651 {
Alexandre Julliard8ee07d42008-02-21 12:29:36 +0100652 if ((changes->width = new->right - new->left) <= 0) changes->width = 1;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000653 mask |= CWWidth;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000654 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000655 if (old->bottom - old->top != new->bottom - new->top)
656 {
Alexandre Julliard8ee07d42008-02-21 12:29:36 +0100657 if ((changes->height = new->bottom - new->top) <= 0) changes->height = 1;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000658 mask |= CWHeight;
659 }
660 if (old->left != new->left)
661 {
662 changes->x = new->left;
663 mask |= CWX;
664 }
665 if (old->top != new->top)
666 {
667 changes->y = new->top;
668 mask |= CWY;
669 }
670 return mask;
671}
672
673
674/***********************************************************************
675 * create_icon_window
676 */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000677static Window create_icon_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000678{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000679 XSetWindowAttributes attr;
680
681 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
Alexandre Julliard9428f062002-06-14 00:08:40 +0000682 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000683 attr.bit_gravity = NorthWestGravity;
684 attr.backing_store = NotUseful/*WhenMapped*/;
Lionel Ulmer1fc39be2001-07-12 22:27:56 +0000685 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000686
Alexandre Julliard649637f2001-06-26 21:10:11 +0000687 wine_tsx11_lock();
688 data->icon_window = XCreateWindow( display, root_window, 0, 0,
689 GetSystemMetrics( SM_CXICON ),
690 GetSystemMetrics( SM_CYICON ),
691 0, screen_depth,
692 InputOutput, visual,
Lionel Ulmer1fc39be2001-07-12 22:27:56 +0000693 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000694 XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd );
Alexandre Julliard731d77f2008-04-09 20:24:27 +0200695 XFlush( display ); /* make sure the window exists before we start painting to it */
Alexandre Julliard649637f2001-06-26 21:10:11 +0000696 wine_tsx11_unlock();
697
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000698 TRACE( "created %lx\n", data->icon_window );
Alexandre Julliardaf50ad62005-07-07 17:30:57 +0000699 SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000700 return data->icon_window;
701}
702
703
704
705/***********************************************************************
706 * destroy_icon_window
707 */
Alexandre Julliardf777d702005-01-31 16:34:07 +0000708static void destroy_icon_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000709{
710 if (!data->icon_window) return;
Alexandre Julliard9428f062002-06-14 00:08:40 +0000711 if (x11drv_thread_data()->cursor_window == data->icon_window)
712 x11drv_thread_data()->cursor_window = None;
Alexandre Julliard704d0352001-07-12 02:49:31 +0000713 wine_tsx11_lock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000714 XDeleteContext( display, data->icon_window, winContext );
715 XDestroyWindow( display, data->icon_window );
716 data->icon_window = 0;
Alexandre Julliard704d0352001-07-12 02:49:31 +0000717 wine_tsx11_unlock();
Alexandre Julliardaf50ad62005-07-07 17:30:57 +0000718 RemovePropA( data->hwnd, icon_window_prop );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000719}
720
721
722/***********************************************************************
723 * set_icon_hints
724 *
725 * Set the icon wm hints
726 */
Alexandre Julliardbde89572007-08-16 23:27:37 +0200727static void set_icon_hints( Display *display, struct x11drv_win_data *data, HICON hIcon )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000728{
Alexandre Julliardbde89572007-08-16 23:27:37 +0200729 XWMHints *hints = data->wm_hints;
730
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000731 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
732 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
Alexandre Julliard883cff42001-06-12 04:02:10 +0000733 data->hWMIconBitmap = 0;
734 data->hWMIconMask = 0;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000735
Alexandre Julliard12d1d402008-01-23 16:40:19 +0100736 if (!hIcon)
Alexandre Julliard883cff42001-06-12 04:02:10 +0000737 {
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000738 if (!data->icon_window) create_icon_window( display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000739 hints->icon_window = data->icon_window;
740 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000741 }
742 else
743 {
744 HBITMAP hbmOrig;
745 RECT rcMask;
746 BITMAP bmMask;
747 ICONINFO ii;
748 HDC hDC;
749
750 GetIconInfo(hIcon, &ii);
751
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000752 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
753 rcMask.top = 0;
754 rcMask.left = 0;
755 rcMask.right = bmMask.bmWidth;
756 rcMask.bottom = bmMask.bmHeight;
757
758 hDC = CreateCompatibleDC(0);
759 hbmOrig = SelectObject(hDC, ii.hbmMask);
760 InvertRect(hDC, &rcMask);
Alexandre Julliardd8a92442002-05-31 18:43:22 +0000761 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000762 SelectObject(hDC, hbmOrig);
763 DeleteDC(hDC);
764
765 data->hWMIconBitmap = ii.hbmColor;
766 data->hWMIconMask = ii.hbmMask;
767
Alexandre Julliard5fd13262005-03-27 18:30:51 +0000768 hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap);
769 hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask);
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000770 destroy_icon_window( display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000771 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000772 }
773}
774
775
776/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000777 * set_size_hints
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000778 *
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000779 * set the window size hints
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000780 */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000781static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000782{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000783 XSizeHints* size_hints;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000784
Alexandre Julliardcf9d3e32008-04-04 11:28:30 +0200785 if (!(size_hints = XAllocSizeHints())) return;
Alexandre Julliardba1517f2006-03-27 22:16:04 +0200786
Alexandre Julliard6ba06fa2008-04-23 15:33:29 +0200787 size_hints->win_gravity = StaticGravity;
788 size_hints->flags |= PWinGravity;
789
Alexandre Julliardcf9d3e32008-04-04 11:28:30 +0200790 /* don't update size hints if window is not in normal state */
791 if (!(style & (WS_MINIMIZE | WS_MAXIMIZE)))
792 {
Alexandre Julliardba1517f2006-03-27 22:16:04 +0200793 if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */
794 {
Alexandre Julliardba1517f2006-03-27 22:16:04 +0200795 size_hints->x = data->whole_rect.left;
796 size_hints->y = data->whole_rect.top;
Alexandre Julliard6ba06fa2008-04-23 15:33:29 +0200797 size_hints->flags |= PPosition;
Alexandre Julliardba1517f2006-03-27 22:16:04 +0200798 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000799
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200800 if (!is_window_resizable( data, style ))
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000801 {
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200802 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
803 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
804 size_hints->min_width = size_hints->max_width;
805 size_hints->min_height = size_hints->max_height;
806 size_hints->flags |= PMinSize | PMaxSize;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000807 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000808 }
Alexandre Julliardcf9d3e32008-04-04 11:28:30 +0200809 XSetWMNormalHints( display, data->whole_window, size_hints );
810 XFree( size_hints );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000811}
812
813
814/***********************************************************************
Alexandre Julliardc7dbffc2005-07-01 16:16:00 +0000815 * get_process_name
816 *
817 * get the name of the current process for setting class hints
818 */
819static char *get_process_name(void)
820{
821 static char *name;
822
823 if (!name)
824 {
825 WCHAR module[MAX_PATH];
826 DWORD len = GetModuleFileNameW( 0, module, MAX_PATH );
827 if (len && len < MAX_PATH)
828 {
829 char *ptr;
830 WCHAR *p, *appname = module;
831
832 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
833 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
834 len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL );
835 if ((ptr = HeapAlloc( GetProcessHeap(), 0, len )))
836 {
837 WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL );
838 name = ptr;
839 }
840 }
841 }
842 return name;
843}
844
845
846/***********************************************************************
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200847 * set_initial_wm_hints
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000848 *
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200849 * Set the window manager hints that don't change over the lifetime of a window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000850 */
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200851static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000852{
Alexandre Julliard3bfa90e2008-04-07 11:41:54 +0200853 long i;
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200854 Atom protocols[3];
855 Atom dndVersion = 4;
856 XClassHint *class_hints;
Alexandre Julliardc7dbffc2005-07-01 16:16:00 +0000857 char *process_name = get_process_name();
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000858
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000859 wine_tsx11_lock();
860
861 /* wm protocols */
862 i = 0;
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000863 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
864 protocols[i++] = x11drv_atom(_NET_WM_PING);
865 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
866 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
Hans Leidekkerac147fe2005-03-22 21:17:34 +0000867 XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000868
869 /* class hints */
870 if ((class_hints = XAllocClassHint()))
871 {
Andrew Talbot55e20a72006-06-26 20:56:16 +0100872 static char wine[] = "Wine";
873
Alexandre Julliardc7dbffc2005-07-01 16:16:00 +0000874 class_hints->res_name = process_name;
Andrew Talbot55e20a72006-06-26 20:56:16 +0100875 class_hints->res_class = wine;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000876 XSetClassHint( display, data->whole_window, class_hints );
877 XFree( class_hints );
878 }
879
Mike Hearn34dd4552003-05-04 02:27:20 +0000880 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
881 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
882 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
883 i = getpid();
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000884 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
Hans Leidekkerac147fe2005-03-22 21:17:34 +0000885 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
Ove Kaaven77e7fd72002-01-21 18:41:27 +0000886
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200887 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
888 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
889
Alexandre Julliarddc07b6f2008-01-22 10:17:52 +0100890 data->wm_hints = XAllocWMHints();
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200891 wine_tsx11_unlock();
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100892
893 if (data->wm_hints)
894 {
Alexandre Julliarde929e3b2008-01-23 16:40:54 +0100895 HICON icon = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 );
896 if (!icon) icon = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON );
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100897 data->wm_hints->flags = 0;
Alexandre Julliarde929e3b2008-01-23 16:40:54 +0100898 set_icon_hints( display, data, icon );
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100899 }
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200900}
901
902
903/***********************************************************************
Alexandre Julliard855308f2008-04-23 15:32:58 +0200904 * set_wm_hints
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200905 *
906 * Set the window manager hints for a newly-created window
907 */
Alexandre Julliard855308f2008-04-23 15:32:58 +0200908static void set_wm_hints( Display *display, struct x11drv_win_data *data )
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200909{
910 Window group_leader;
911 Atom window_type;
912 MwmHints mwm_hints;
Alexandre Julliard18f4fb92008-04-14 13:27:38 +0200913 DWORD style, ex_style;
914 HWND owner;
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200915
916 if (data->hwnd == GetDesktopWindow())
917 {
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200918 /* force some styles for the desktop to get the correct decorations */
Alexandre Julliard18f4fb92008-04-14 13:27:38 +0200919 style = WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
920 ex_style = WS_EX_APPWINDOW;
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200921 owner = 0;
922 }
Alexandre Julliard18f4fb92008-04-14 13:27:38 +0200923 else
924 {
925 style = GetWindowLongW( data->hwnd, GWL_STYLE );
926 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
Alexandre Julliard8a5f5782008-05-01 17:44:56 +0200927 owner = get_window_owner( data->hwnd );
Alexandre Julliard18f4fb92008-04-14 13:27:38 +0200928 }
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200929
930 /* transient for hint */
931 if (owner)
932 {
933 Window owner_win = X11DRV_get_whole_window( owner );
934 wine_tsx11_lock();
935 XSetTransientForHint( display, data->whole_window, owner_win );
936 wine_tsx11_unlock();
937 group_leader = owner_win;
938 }
939 else group_leader = data->whole_window;
940
941 wine_tsx11_lock();
942
943 /* size hints */
944 set_size_hints( display, data, style );
945
Nickolay V. Shmyrev1a1b9022006-10-11 19:32:22 +0400946 /* set the WM_WINDOW_TYPE */
Dmitry Timoshkov751a71a2008-04-07 13:37:44 +0900947 if (style & WS_THICKFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
Alexandre Julliard9bf9c0b2008-04-14 13:27:19 +0200948 else if (ex_style & WS_EX_APPWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
Nickolay V. Shmyrev1a1b9022006-10-11 19:32:22 +0400949 else if (style & WS_DLGFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
950 else if (ex_style & WS_EX_DLGMODALFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
Alexandre Julliard0bbadeb2008-04-21 20:33:18 +0200951 else if ((style & WS_POPUP) && owner) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
Dmitry Timoshkov1bf824e2008-04-07 22:17:47 +0900952#if 0 /* many window managers don't handle utility windows very well */
Dmitry Timoshkov751a71a2008-04-07 13:37:44 +0900953 else if (ex_style & WS_EX_TOOLWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
Dmitry Timoshkov1bf824e2008-04-07 22:17:47 +0900954#endif
Alexandre Julliard9bf9c0b2008-04-14 13:27:19 +0200955 else window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
Nickolay V. Shmyrev1a1b9022006-10-11 19:32:22 +0400956
957 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
958 XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1);
Mike Hearn27d972f2003-12-04 21:54:13 +0000959
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000960 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900961 mwm_hints.decorations = get_mwm_decorations( data, style, ex_style );
Dmitry Timoshkovac387bb2006-10-05 23:16:36 +0900962 mwm_hints.functions = MWM_FUNC_MOVE;
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200963 if (is_window_resizable( data, style )) mwm_hints.functions |= MWM_FUNC_RESIZE;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000964 if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
965 if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
Alexandre Julliard74cd76c2007-08-29 12:02:57 +0200966 if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000967
968 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
969 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
Hans Leidekkerac147fe2005-03-22 21:17:34 +0000970 (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000971
Alexandre Julliard704d0352001-07-12 02:49:31 +0000972 /* wm hints */
Alexandre Julliardbde89572007-08-16 23:27:37 +0200973 if (data->wm_hints)
Alexandre Julliard704d0352001-07-12 02:49:31 +0000974 {
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100975 data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint;
Alexandre Julliardbde89572007-08-16 23:27:37 +0200976 data->wm_hints->input = !(style & WS_DISABLED);
977 data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
978 data->wm_hints->window_group = group_leader;
Alexandre Julliardbde89572007-08-16 23:27:37 +0200979 XSetWMHints( display, data->whole_window, data->wm_hints );
Alexandre Julliard704d0352001-07-12 02:49:31 +0000980 }
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100981
982 wine_tsx11_unlock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000983}
984
985
986/***********************************************************************
Alexandre Julliard855308f2008-04-23 15:32:58 +0200987 * update_net_wm_states
988 */
989void update_net_wm_states( Display *display, struct x11drv_win_data *data )
990{
991 static const unsigned int state_atoms[NB_NET_WM_STATES] =
992 {
993 XATOM__NET_WM_STATE_FULLSCREEN,
994 XATOM__NET_WM_STATE_ABOVE,
995 XATOM__NET_WM_STATE_MAXIMIZED_VERT,
996 XATOM__NET_WM_STATE_SKIP_PAGER,
997 XATOM__NET_WM_STATE_SKIP_TASKBAR
998 };
999
1000 DWORD i, style, ex_style, new_state = 0;
1001
1002 if (!data->managed) return;
1003 if (data->whole_window == root_window) return;
1004
1005 style = GetWindowLongW( data->hwnd, GWL_STYLE );
1006 if (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width &&
1007 data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height)
1008 {
1009 if ((style & WS_MAXIMIZE) && (style & WS_CAPTION) == WS_CAPTION)
1010 new_state |= (1 << NET_WM_STATE_MAXIMIZED);
1011 else if (!(style & WS_MINIMIZE))
1012 new_state |= (1 << NET_WM_STATE_FULLSCREEN);
1013 }
1014 else if (style & WS_MAXIMIZE)
1015 new_state |= (1 << NET_WM_STATE_MAXIMIZED);
1016
1017 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
1018 if (ex_style & WS_EX_TOPMOST)
1019 new_state |= (1 << NET_WM_STATE_ABOVE);
1020 if (ex_style & WS_EX_TOOLWINDOW)
1021 new_state |= (1 << NET_WM_STATE_SKIP_TASKBAR) | (1 << NET_WM_STATE_SKIP_PAGER);
Alexandre Julliard8a5f5782008-05-01 17:44:56 +02001022 if (!(ex_style & WS_EX_APPWINDOW) && get_window_owner( data->hwnd ))
Alexandre Julliard855308f2008-04-23 15:32:58 +02001023 new_state |= (1 << NET_WM_STATE_SKIP_TASKBAR);
1024
1025 if (!data->mapped) /* set the _NET_WM_STATE atom directly */
1026 {
1027 Atom atoms[NB_NET_WM_STATES+1];
1028 DWORD count;
1029
1030 for (i = count = 0; i < NB_NET_WM_STATES; i++)
1031 {
1032 if (!(new_state & (1 << i))) continue;
1033 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
1034 i, data->hwnd, data->whole_window );
1035 atoms[count++] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM];
1036 if (state_atoms[i] == XATOM__NET_WM_STATE_MAXIMIZED_VERT)
1037 atoms[count++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ);
1038 }
1039 wine_tsx11_lock();
1040 XChangeProperty( display, data->whole_window, x11drv_atom(_NET_WM_STATE), XA_ATOM,
1041 32, PropModeReplace, (unsigned char *)atoms, count );
1042 wine_tsx11_unlock();
1043 }
1044 else /* ask the window manager to do it for us */
1045 {
1046 XEvent xev;
1047
1048 xev.xclient.type = ClientMessage;
1049 xev.xclient.window = data->whole_window;
1050 xev.xclient.message_type = x11drv_atom(_NET_WM_STATE);
1051 xev.xclient.serial = 0;
1052 xev.xclient.display = display;
1053 xev.xclient.send_event = True;
1054 xev.xclient.format = 32;
1055 xev.xclient.data.l[3] = 1;
1056
1057 for (i = 0; i < NB_NET_WM_STATES; i++)
1058 {
1059 if (!((data->net_wm_state ^ new_state) & (1 << i))) continue; /* unchanged */
1060
1061 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1062 i, data->hwnd, data->whole_window,
1063 (new_state & (1 << i)) != 0, (data->net_wm_state & (1 << i)) != 0 );
1064
1065 xev.xclient.data.l[0] = (new_state & (1 << i)) ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1066 xev.xclient.data.l[1] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM];
1067 xev.xclient.data.l[2] = ((state_atoms[i] == XATOM__NET_WM_STATE_MAXIMIZED_VERT) ?
1068 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ) : 0);
1069 wine_tsx11_lock();
1070 XSendEvent( display, root_window, False,
1071 SubstructureRedirectMask | SubstructureNotifyMask, &xev );
1072 wine_tsx11_unlock();
1073 }
1074 }
1075 data->net_wm_state = new_state;
1076}
1077
1078
1079/***********************************************************************
1080 * set_xembed_flags
1081 */
1082static void set_xembed_flags( Display *display, struct x11drv_win_data *data, unsigned long flags )
1083{
1084 unsigned long info[2];
1085
1086 info[0] = 0; /* protocol version */
1087 info[1] = flags;
1088 wine_tsx11_lock();
1089 XChangeProperty( display, data->whole_window, x11drv_atom(_XEMBED_INFO),
1090 x11drv_atom(_XEMBED_INFO), 32, PropModeReplace, (unsigned char*)info, 2 );
1091 wine_tsx11_unlock();
1092}
1093
1094
1095/***********************************************************************
1096 * map_window
1097 */
1098static void map_window( Display *display, struct x11drv_win_data *data, DWORD new_style )
1099{
1100 TRACE( "win %p/%lx\n", data->hwnd, data->whole_window );
1101
1102 wait_for_withdrawn_state( display, data, TRUE );
1103
1104 if (!data->embedded)
1105 {
1106 update_net_wm_states( display, data );
1107 sync_window_style( display, data );
1108 wine_tsx11_lock();
1109 XMapWindow( display, data->whole_window );
1110 wine_tsx11_unlock();
1111 }
1112 else set_xembed_flags( display, data, XEMBED_MAPPED );
1113
1114 data->mapped = TRUE;
1115 data->iconic = (new_style & WS_MINIMIZE) != 0;
1116}
1117
1118
1119/***********************************************************************
1120 * unmap_window
1121 */
1122static void unmap_window( Display *display, struct x11drv_win_data *data )
1123{
1124 TRACE( "win %p/%lx\n", data->hwnd, data->whole_window );
1125
1126 if (!data->embedded)
1127 {
1128 wait_for_withdrawn_state( display, data, FALSE );
1129 wine_tsx11_lock();
1130 if (data->managed) XWithdrawWindow( display, data->whole_window, DefaultScreen(display) );
1131 else XUnmapWindow( display, data->whole_window );
1132 wine_tsx11_unlock();
1133 }
1134 else set_xembed_flags( display, data, 0 );
1135
1136 data->mapped = FALSE;
1137 data->net_wm_state = 0;
1138}
1139
1140
1141/***********************************************************************
1142 * make_window_embedded
1143 */
1144void make_window_embedded( Display *display, struct x11drv_win_data *data )
1145{
1146 if (data->mapped)
1147 {
1148 /* the window cannot be mapped before being embedded */
1149 unmap_window( display, data );
1150 data->embedded = TRUE;
1151 map_window( display, data, 0 );
1152 }
1153 else
1154 {
1155 data->embedded = TRUE;
1156 set_xembed_flags( display, data, 0 );
1157 }
1158}
1159
1160
1161/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001162 * X11DRV_window_to_X_rect
1163 *
1164 * Convert a rect from client to X window coordinates
1165 */
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001166void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001167{
Alexandre Julliard8cd1f712001-07-20 18:37:37 +00001168 RECT rc;
1169
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001170 if (!data->managed) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001171 if (IsRectEmpty( rect )) return;
1172
Alexandre Julliardc4e20e72007-10-11 12:24:27 +02001173 get_x11_rect_offset( data, &rc );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001174
Alexandre Julliard8cd1f712001-07-20 18:37:37 +00001175 rect->left -= rc.left;
1176 rect->right -= rc.right;
1177 rect->top -= rc.top;
1178 rect->bottom -= rc.bottom;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001179 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1180 if (rect->left >= rect->right) rect->right = rect->left + 1;
1181}
1182
1183
1184/***********************************************************************
1185 * X11DRV_X_to_window_rect
1186 *
1187 * Opposite of X11DRV_window_to_X_rect
1188 */
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001189void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001190{
Alexandre Julliardc4e20e72007-10-11 12:24:27 +02001191 RECT rc;
Alexandre Julliard74cd76c2007-08-29 12:02:57 +02001192
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001193 if (!data->managed) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001194 if (IsRectEmpty( rect )) return;
1195
Alexandre Julliardc4e20e72007-10-11 12:24:27 +02001196 get_x11_rect_offset( data, &rc );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001197
Alexandre Julliardc4e20e72007-10-11 12:24:27 +02001198 rect->left += rc.left;
1199 rect->right += rc.right;
1200 rect->top += rc.top;
1201 rect->bottom += rc.bottom;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001202 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1203 if (rect->left >= rect->right) rect->right = rect->left + 1;
1204}
1205
1206
1207/***********************************************************************
Alexandre Julliard855308f2008-04-23 15:32:58 +02001208 * sync_window_position
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001209 *
Alexandre Julliardf777d702005-01-31 16:34:07 +00001210 * Synchronize the X window position with the Windows one
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001211 */
Alexandre Julliard855308f2008-04-23 15:32:58 +02001212static void sync_window_position( Display *display, struct x11drv_win_data *data,
Alexandre Julliardbbfbe242008-01-23 12:28:01 +01001213 UINT swp_flags, const RECT *old_client_rect,
1214 const RECT *old_whole_rect )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001215{
Alexandre Julliardcef3bc62008-04-04 11:20:45 +02001216 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001217 XWindowChanges changes;
Alexandre Julliardbbd32aa2008-04-23 15:34:07 +02001218 unsigned int mask = 0;
Alexandre Julliardcef3bc62008-04-04 11:20:45 +02001219
1220 if (data->managed && data->iconic) return;
1221
Alexandre Julliardbbd32aa2008-04-23 15:34:07 +02001222 /* resizing a managed maximized window is not allowed */
1223 if (!(style & WS_MAXIMIZE) || !data->managed)
1224 {
Alexandre Julliard308476e2008-09-17 21:11:47 +02001225 changes.width = data->whole_rect.right - data->whole_rect.left;
1226 changes.height = data->whole_rect.bottom - data->whole_rect.top;
1227 /* if window rect is empty force size to 1x1 */
1228 if (changes.width <= 0 || changes.height <= 0) changes.width = changes.height = 1;
Alexandre Julliardbbd32aa2008-04-23 15:34:07 +02001229 mask |= CWWidth | CWHeight;
1230 }
Alexandre Julliardcef3bc62008-04-04 11:20:45 +02001231
1232 /* only the size is allowed to change for the desktop window */
1233 if (data->whole_window != root_window)
1234 {
1235 changes.x = data->whole_rect.left - virtual_screen_rect.left;
1236 changes.y = data->whole_rect.top - virtual_screen_rect.top;
1237 mask |= CWX | CWY;
1238 }
Alexandre Julliardf777d702005-01-31 16:34:07 +00001239
Alexandre Julliardac40efa2008-08-29 13:34:55 +02001240 if (!(swp_flags & SWP_NOZORDER) || (swp_flags & SWP_SHOWWINDOW))
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001241 {
Alexandre Julliardf777d702005-01-31 16:34:07 +00001242 /* find window that this one must be after */
1243 HWND prev = GetWindow( data->hwnd, GW_HWNDPREV );
1244 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
1245 prev = GetWindow( prev, GW_HWNDPREV );
1246 if (!prev) /* top child */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001247 {
Alexandre Julliardf777d702005-01-31 16:34:07 +00001248 changes.stack_mode = Above;
1249 mask |= CWStackMode;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001250 }
Alexandre Julliard5787c122008-03-24 15:47:28 +01001251 /* should use stack_mode Below but most window managers don't get it right */
1252 /* and Above with a sibling doesn't work so well either, so we ignore it */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001253 }
1254
Alexandre Julliardcef3bc62008-04-04 11:20:45 +02001255 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
1256 data->hwnd, data->whole_window, data->whole_rect.left, data->whole_rect.top,
1257 data->whole_rect.right - data->whole_rect.left,
1258 data->whole_rect.bottom - data->whole_rect.top, changes.sibling, mask );
Alexandre Julliardc19af912008-01-17 19:53:59 +01001259
Alexandre Julliardcef3bc62008-04-04 11:20:45 +02001260 wine_tsx11_lock();
1261 set_size_hints( display, data, style );
1262 XReconfigureWMWindow( display, data->whole_window,
1263 DefaultScreen(display), mask, &changes );
1264 wine_tsx11_unlock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001265}
1266
1267
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001268/***********************************************************************
Alexandre Julliard855308f2008-04-23 15:32:58 +02001269 * sync_client_position
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001270 *
1271 * Synchronize the X client window position with the Windows one
1272 */
Alexandre Julliard855308f2008-04-23 15:32:58 +02001273static void sync_client_position( Display *display, struct x11drv_win_data *data,
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001274 UINT swp_flags, const RECT *old_client_rect,
1275 const RECT *old_whole_rect )
1276{
1277 int mask;
1278 XWindowChanges changes;
1279 RECT old = *old_client_rect;
1280 RECT new = data->client_rect;
1281
1282 OffsetRect( &old, -old_whole_rect->left, -old_whole_rect->top );
1283 OffsetRect( &new, -data->whole_rect.left, -data->whole_rect.top );
1284 if (!(mask = get_window_changes( &changes, &old, &new ))) return;
1285
1286 if (data->client_window)
1287 {
1288 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1289 data->client_window, new.left, new.top,
1290 new.right - new.left, new.bottom - new.top, mask );
1291 wine_tsx11_lock();
1292 XConfigureWindow( display, data->client_window, mask, &changes );
1293 wine_tsx11_unlock();
1294 }
1295
Alexandre Julliard6e9dea82008-05-12 19:37:54 +02001296 if (data->gl_drawable && (mask & (CWWidth|CWHeight))) sync_gl_drawable( data );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001297}
1298
1299
Alexandre Julliard855308f2008-04-23 15:32:58 +02001300/***********************************************************************
1301 * move_window_bits
1302 *
1303 * Move the window bits when a window is moved.
1304 */
1305static void move_window_bits( struct x11drv_win_data *data, const RECT *old_rect, const RECT *new_rect,
1306 const RECT *old_client_rect )
1307{
1308 RECT src_rect = *old_rect;
1309 RECT dst_rect = *new_rect;
1310 HDC hdc_src, hdc_dst;
1311 INT code;
1312 HRGN rgn = 0;
1313 HWND parent = 0;
1314
1315 if (!data->whole_window)
1316 {
1317 OffsetRect( &dst_rect, -data->window_rect.left, -data->window_rect.top );
1318 parent = GetAncestor( data->hwnd, GA_PARENT );
1319 hdc_src = GetDCEx( parent, 0, DCX_CACHE );
1320 hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE | DCX_WINDOW );
1321 }
1322 else
1323 {
1324 OffsetRect( &dst_rect, -data->client_rect.left, -data->client_rect.top );
1325 /* make src rect relative to the old position of the window */
1326 OffsetRect( &src_rect, -old_client_rect->left, -old_client_rect->top );
1327 if (dst_rect.left == src_rect.left && dst_rect.top == src_rect.top) return;
1328 hdc_src = hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE );
1329 }
1330
1331 code = X11DRV_START_EXPOSURES;
1332 ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1333
1334 TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n",
1335 data->hwnd, data->whole_window, data->client_window,
1336 wine_dbgstr_rect(&src_rect), wine_dbgstr_rect(&dst_rect) );
1337 BitBlt( hdc_dst, dst_rect.left, dst_rect.top,
1338 dst_rect.right - dst_rect.left, dst_rect.bottom - dst_rect.top,
1339 hdc_src, src_rect.left, src_rect.top, SRCCOPY );
1340
1341 code = X11DRV_END_EXPOSURES;
1342 ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, sizeof(rgn), (LPSTR)&rgn );
1343
1344 ReleaseDC( data->hwnd, hdc_dst );
1345 if (hdc_src != hdc_dst) ReleaseDC( parent, hdc_src );
1346
1347 if (rgn)
1348 {
1349 if (!data->whole_window)
1350 {
1351 /* map region to client rect since we are using DCX_WINDOW */
1352 OffsetRgn( rgn, data->window_rect.left - data->client_rect.left,
1353 data->window_rect.top - data->client_rect.top );
1354 RedrawWindow( data->hwnd, NULL, rgn,
1355 RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ALLCHILDREN );
1356 }
1357 else RedrawWindow( data->hwnd, NULL, rgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
1358 DeleteObject( rgn );
1359 }
1360}
1361
1362
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001363/**********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001364 * create_whole_window
1365 *
1366 * Create the whole X window for a given window
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001367 */
Alexandre Julliardd147e022008-01-23 21:39:32 +01001368static Window create_whole_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001369{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001370 int cx, cy, mask;
1371 XSetWindowAttributes attr;
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001372 WCHAR text[1024];
Alexandre Julliardbe3c3a52008-09-12 15:54:02 +02001373 COLORREF key;
1374 BYTE alpha;
1375 DWORD layered_flags;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001376
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001377 if (!(cx = data->window_rect.right - data->window_rect.left)) cx = 1;
1378 if (!(cy = data->window_rect.bottom - data->window_rect.top)) cy = 1;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001379
Alexandre Julliarde6dfbcb2008-01-25 12:07:11 +01001380 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1381 {
1382 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1383 data->managed = TRUE;
1384 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1385 }
1386
Alexandre Julliard6bb18e22006-03-27 15:33:43 +02001387 mask = get_window_attributes( display, data, &attr );
Alexandre Julliard883cff42001-06-12 04:02:10 +00001388
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001389 wine_tsx11_lock();
1390
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001391 data->whole_rect = data->window_rect;
Alexandre Julliarda06aeab2006-10-26 12:53:59 +02001392 data->whole_window = XCreateWindow( display, root_window,
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001393 data->window_rect.left - virtual_screen_rect.left,
1394 data->window_rect.top - virtual_screen_rect.top,
Alexandre Julliarda06aeab2006-10-26 12:53:59 +02001395 cx, cy, 0, screen_depth, InputOutput,
1396 visual, mask, &attr );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001397
Alexandre Julliard42ad3452008-02-22 10:40:22 +01001398 if (data->whole_window) XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
1399 wine_tsx11_unlock();
1400
1401 if (!data->whole_window) return 0;
1402
1403 if (!create_client_window( display, data, NULL ))
Alexandre Julliard704d0352001-07-12 02:49:31 +00001404 {
Alexandre Julliard42ad3452008-02-22 10:40:22 +01001405 wine_tsx11_lock();
1406 XDeleteContext( display, data->whole_window, winContext );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001407 XDestroyWindow( display, data->whole_window );
1408 data->whole_window = 0;
1409 wine_tsx11_unlock();
1410 return 0;
1411 }
1412
Alexandre Julliard7d9739e2007-08-20 14:04:36 +02001413 set_initial_wm_hints( display, data );
Alexandre Julliard855308f2008-04-23 15:32:58 +02001414 set_wm_hints( display, data );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001415
Alexandre Julliardaf50ad62005-07-07 17:30:57 +00001416 SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
Alexandre Julliard395928d2008-01-23 16:30:18 +01001417
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001418 /* set the window text */
1419 if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
1420 sync_window_text( display, data->whole_window, text );
1421
Alexandre Julliard395928d2008-01-23 16:30:18 +01001422 /* set the window region */
Alexandre Julliard9d45cfd2008-09-08 15:51:08 +02001423 sync_window_region( display, data, (HRGN)1 );
1424
Alexandre Julliardbe3c3a52008-09-12 15:54:02 +02001425 /* set the window opacity */
1426 if (!GetLayeredWindowAttributes( data->hwnd, &key, &alpha, &layered_flags )) layered_flags = 0;
1427 sync_window_opacity( display, data->whole_window, key, alpha, layered_flags );
1428
Alexandre Julliard731d77f2008-04-09 20:24:27 +02001429 wine_tsx11_lock();
1430 XFlush( display ); /* make sure the window exists before we start painting to it */
1431 wine_tsx11_unlock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001432 return data->whole_window;
1433}
1434
1435
1436/**********************************************************************
Alexandre Julliardf777d702005-01-31 16:34:07 +00001437 * destroy_whole_window
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001438 *
Alexandre Julliardf777d702005-01-31 16:34:07 +00001439 * Destroy the whole X window for a given window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001440 */
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001441static void destroy_whole_window( Display *display, struct x11drv_win_data *data, BOOL already_destroyed )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001442{
Alexandre Julliardf777d702005-01-31 16:34:07 +00001443 struct x11drv_thread_data *thread_data = x11drv_thread_data();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001444
Alexandre Julliardf777d702005-01-31 16:34:07 +00001445 if (!data->whole_window) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001446
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001447 TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1448 if (thread_data->cursor_window == data->whole_window ||
1449 thread_data->cursor_window == data->client_window)
1450 thread_data->cursor_window = None;
Alexandre Julliard883cff42001-06-12 04:02:10 +00001451 wine_tsx11_lock();
Alexandre Julliardf777d702005-01-31 16:34:07 +00001452 XDeleteContext( display, data->whole_window, winContext );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001453 XDeleteContext( display, data->client_window, winContext );
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001454 if (!already_destroyed) XDestroyWindow( display, data->whole_window );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001455 data->whole_window = data->client_window = 0;
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001456 data->wm_state = WithdrawnState;
1457 data->net_wm_state = 0;
1458 data->mapped = FALSE;
Alexandre Julliardf777d702005-01-31 16:34:07 +00001459 if (data->xic)
1460 {
1461 XUnsetICFocus( data->xic );
1462 XDestroyIC( data->xic );
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001463 data->xic = 0;
Alexandre Julliardf777d702005-01-31 16:34:07 +00001464 }
Alexandre Julliard975f1b22006-05-09 17:32:40 +02001465 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1466 XFlush( display );
Alexandre Julliarddc07b6f2008-01-22 10:17:52 +01001467 XFree( data->wm_hints );
1468 data->wm_hints = NULL;
Alexandre Julliard883cff42001-06-12 04:02:10 +00001469 wine_tsx11_unlock();
Alexandre Julliardaf50ad62005-07-07 17:30:57 +00001470 RemovePropA( data->hwnd, whole_window_prop );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001471 RemovePropA( data->hwnd, client_window_prop );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001472}
1473
1474
1475/*****************************************************************
1476 * SetWindowText (X11DRV.@)
1477 */
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001478void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001479{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001480 Window win;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001481
Alexandre Julliarde7044cb2008-06-26 16:47:42 +02001482 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(gdi_display))
1483 {
1484 Display *display = thread_init_display();
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001485 sync_window_text( display, win, text );
Alexandre Julliarde7044cb2008-06-26 16:47:42 +02001486 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001487}
1488
1489
1490/***********************************************************************
Alexandre Julliard855308f2008-04-23 15:32:58 +02001491 * SetWindowStyle (X11DRV.@)
1492 *
1493 * Update the X state of a window to reflect a style change
1494 */
Alexandre Julliard2f112132008-09-12 14:55:07 +02001495void X11DRV_SetWindowStyle( HWND hwnd, INT offset, STYLESTRUCT *style )
Alexandre Julliard855308f2008-04-23 15:32:58 +02001496{
Alexandre Julliard855308f2008-04-23 15:32:58 +02001497 struct x11drv_win_data *data;
Alexandre Julliard2f112132008-09-12 14:55:07 +02001498 DWORD changed;
Alexandre Julliard855308f2008-04-23 15:32:58 +02001499
1500 if (hwnd == GetDesktopWindow()) return;
Alexandre Julliard2f112132008-09-12 14:55:07 +02001501 changed = style->styleNew ^ style->styleOld;
Alexandre Julliard855308f2008-04-23 15:32:58 +02001502
Alexandre Julliard2f112132008-09-12 14:55:07 +02001503 if (offset == GWL_STYLE && (changed & WS_VISIBLE) && (style->styleNew & WS_VISIBLE))
Alexandre Julliard855308f2008-04-23 15:32:58 +02001504 {
1505 /* we don't unmap windows, that causes trouble with the window manager */
1506 if (!(data = X11DRV_get_win_data( hwnd )) &&
1507 !(data = X11DRV_create_win_data( hwnd ))) return;
1508
1509 if (data->whole_window && is_window_rect_mapped( &data->window_rect ))
1510 {
Alexandre Julliarde7044cb2008-06-26 16:47:42 +02001511 Display *display = thread_display();
Alexandre Julliard855308f2008-04-23 15:32:58 +02001512 set_wm_hints( display, data );
Alexandre Julliard2f112132008-09-12 14:55:07 +02001513 if (!data->mapped) map_window( display, data, style->styleNew );
Alexandre Julliard855308f2008-04-23 15:32:58 +02001514 }
1515 }
1516
Alexandre Julliard2f112132008-09-12 14:55:07 +02001517 if (offset == GWL_STYLE && (changed & WS_DISABLED))
Alexandre Julliard855308f2008-04-23 15:32:58 +02001518 {
1519 data = X11DRV_get_win_data( hwnd );
1520 if (data && data->wm_hints)
1521 {
1522 wine_tsx11_lock();
Alexandre Julliard2f112132008-09-12 14:55:07 +02001523 data->wm_hints->input = !(style->styleNew & WS_DISABLED);
Alexandre Julliarde7044cb2008-06-26 16:47:42 +02001524 XSetWMHints( thread_display(), data->whole_window, data->wm_hints );
Alexandre Julliard855308f2008-04-23 15:32:58 +02001525 wine_tsx11_unlock();
1526 }
1527 }
Alexandre Julliardbe3c3a52008-09-12 15:54:02 +02001528
1529 if (offset == GWL_EXSTYLE && (changed & WS_EX_LAYERED))
1530 {
1531 /* changing WS_EX_LAYERED resets attributes */
1532 if ((data = X11DRV_get_win_data( hwnd )) && data->whole_window)
1533 sync_window_opacity( thread_display(), data->whole_window, 0, 0, 0 );
1534 }
Alexandre Julliard855308f2008-04-23 15:32:58 +02001535}
1536
1537
1538/***********************************************************************
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001539 * DestroyWindow (X11DRV.@)
1540 */
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001541void X11DRV_DestroyWindow( HWND hwnd )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001542{
Alexandre Julliard9428f062002-06-14 00:08:40 +00001543 struct x11drv_thread_data *thread_data = x11drv_thread_data();
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001544 struct x11drv_win_data *data;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001545
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001546 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001547
Chris Robinson37d835b2007-09-26 08:17:13 -07001548 if (data->pixmap)
1549 {
Chris Robinson37d835b2007-09-26 08:17:13 -07001550 wine_tsx11_lock();
Alexandre Julliard6e9dea82008-05-12 19:37:54 +02001551 destroy_glxpixmap(gdi_display, data->gl_drawable);
1552 XFreePixmap(gdi_display, data->pixmap);
Chris Robinson37d835b2007-09-26 08:17:13 -07001553 wine_tsx11_unlock();
1554 }
1555 else if (data->gl_drawable)
Chris Robinson00633e32007-09-25 22:43:38 -07001556 {
1557 wine_tsx11_lock();
Alexandre Julliard6e9dea82008-05-12 19:37:54 +02001558 XDestroyWindow(gdi_display, data->gl_drawable);
Chris Robinson00633e32007-09-25 22:43:38 -07001559 wine_tsx11_unlock();
1560 }
1561
Alexandre Julliard06a14072008-06-26 15:08:08 +02001562 destroy_whole_window( thread_data->display, data, FALSE );
1563 destroy_icon_window( thread_data->display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001564
Alexandre Julliarde9307d02008-02-21 20:23:32 +01001565 if (data->colormap)
1566 {
1567 wine_tsx11_lock();
Alexandre Julliard06a14072008-06-26 15:08:08 +02001568 XFreeColormap( thread_data->display, data->colormap );
Alexandre Julliarde9307d02008-02-21 20:23:32 +01001569 wine_tsx11_unlock();
1570 }
1571
Alexandre Julliardf777d702005-01-31 16:34:07 +00001572 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001573 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
1574 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001575 wine_tsx11_lock();
Alexandre Julliard06a14072008-06-26 15:08:08 +02001576 XDeleteContext( thread_data->display, (XID)hwnd, win_data_context );
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001577 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001578 HeapFree( GetProcessHeap(), 0, data );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001579}
1580
1581
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001582/***********************************************************************
1583 * X11DRV_DestroyNotify
1584 */
1585void X11DRV_DestroyNotify( HWND hwnd, XEvent *event )
1586{
1587 Display *display = event->xdestroywindow.display;
1588 struct x11drv_win_data *data;
1589
1590 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1591
1592 FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window );
1593 destroy_whole_window( display, data, TRUE );
1594}
1595
1596
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001597static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
1598{
1599 struct x11drv_win_data *data;
1600
Alexandre Julliard30d84fc2008-01-22 10:15:38 +01001601 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001602 {
Alexandre Julliard30d84fc2008-01-22 10:15:38 +01001603 data->hwnd = hwnd;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001604 wine_tsx11_lock();
1605 if (!winContext) winContext = XUniqueContext();
1606 if (!win_data_context) win_data_context = XUniqueContext();
1607 XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
1608 wine_tsx11_unlock();
1609 }
1610 return data;
1611}
1612
1613
Alexandre Julliardc19af912008-01-17 19:53:59 +01001614/* initialize the desktop window id in the desktop manager process */
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001615static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd )
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001616{
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001617 struct x11drv_win_data *data;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001618
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001619 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001620 data->whole_window = data->client_window = root_window;
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001621 data->managed = TRUE;
1622 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1623 SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001624 SetPropA( data->hwnd, client_window_prop, (HANDLE)root_window );
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001625 set_initial_wm_hints( display, data );
1626 return data;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001627}
1628
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001629/**********************************************************************
1630 * CreateDesktopWindow (X11DRV.@)
1631 */
1632BOOL X11DRV_CreateDesktopWindow( HWND hwnd )
1633{
Alexandre Julliardc19af912008-01-17 19:53:59 +01001634 unsigned int width, height;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001635
Alexandre Julliardc19af912008-01-17 19:53:59 +01001636 /* retrieve the real size of the desktop */
1637 SERVER_START_REQ( get_window_rectangles )
1638 {
1639 req->handle = hwnd;
1640 wine_server_call( req );
1641 width = reply->window.right - reply->window.left;
1642 height = reply->window.bottom - reply->window.top;
1643 }
1644 SERVER_END_REQ;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001645
Alexandre Julliardc19af912008-01-17 19:53:59 +01001646 if (!width && !height) /* not initialized yet */
1647 {
1648 SERVER_START_REQ( set_window_pos )
1649 {
1650 req->handle = hwnd;
1651 req->previous = 0;
1652 req->flags = SWP_NOZORDER;
1653 req->window.left = virtual_screen_rect.left;
1654 req->window.top = virtual_screen_rect.top;
1655 req->window.right = virtual_screen_rect.right;
1656 req->window.bottom = virtual_screen_rect.bottom;
1657 req->client = req->window;
1658 wine_server_call( req );
1659 }
1660 SERVER_END_REQ;
1661 }
1662 else
1663 {
1664 Window win = (Window)GetPropA( hwnd, whole_window_prop );
1665 if (win && win != root_window) X11DRV_init_desktop( win, width, height );
1666 }
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001667 return TRUE;
1668}
1669
1670
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001671/**********************************************************************
1672 * CreateWindow (X11DRV.@)
1673 */
Alexandre Julliardd6f67452008-01-24 11:23:09 +01001674BOOL X11DRV_CreateWindow( HWND hwnd )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001675{
Alexandre Julliarde7044cb2008-06-26 16:47:42 +02001676 if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( gdi_display ))
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001677 {
Alexandre Julliarde7044cb2008-06-26 16:47:42 +02001678 Display *display = thread_init_display();
1679
Alexandre Julliard026974f2008-01-24 10:20:51 +01001680 /* the desktop win data can't be created lazily */
1681 if (!create_desktop_win_data( display, hwnd )) return FALSE;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001682 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001683 return TRUE;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001684}
1685
1686
1687/***********************************************************************
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001688 * X11DRV_get_win_data
1689 *
1690 * Return the X11 data structure associated with a window.
1691 */
1692struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1693{
Alexandre Julliard06a14072008-06-26 15:08:08 +02001694 struct x11drv_thread_data *thread_data = x11drv_thread_data();
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001695 char *data;
Alexandre Julliarde5515552005-02-09 14:01:40 +00001696
Alexandre Julliard06a14072008-06-26 15:08:08 +02001697 if (!thread_data) return NULL;
1698 if (!hwnd) return NULL;
1699 if (XFindContext( thread_data->display, (XID)hwnd, win_data_context, &data )) data = NULL;
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001700 return (struct x11drv_win_data *)data;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001701}
1702
1703
1704/***********************************************************************
Alexandre Julliard026974f2008-01-24 10:20:51 +01001705 * X11DRV_create_win_data
1706 *
1707 * Create an X11 data window structure for an existing window.
1708 */
1709struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd )
1710{
Alexandre Julliarde7044cb2008-06-26 16:47:42 +02001711 Display *display;
Alexandre Julliard026974f2008-01-24 10:20:51 +01001712 struct x11drv_win_data *data;
1713 HWND parent;
1714
1715 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
Alexandre Julliarde7044cb2008-06-26 16:47:42 +02001716
Alexandre Julliard93a02e72008-06-26 16:49:09 +02001717 /* don't create win data for HWND_MESSAGE windows */
1718 if (parent != GetDesktopWindow() && !GetAncestor( parent, GA_PARENT )) return NULL;
1719
Alexandre Julliarde7044cb2008-06-26 16:47:42 +02001720 display = thread_init_display();
Alexandre Julliard026974f2008-01-24 10:20:51 +01001721 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1722
1723 GetWindowRect( hwnd, &data->window_rect );
1724 MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 );
1725 data->whole_rect = data->window_rect;
1726 GetClientRect( hwnd, &data->client_rect );
1727 MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 );
1728
1729 if (parent == GetDesktopWindow())
1730 {
1731 if (!create_whole_window( display, data ))
1732 {
1733 HeapFree( GetProcessHeap(), 0, data );
1734 return NULL;
1735 }
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001736 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1737 hwnd, data->whole_window, data->client_window, wine_dbgstr_rect( &data->window_rect ),
Alexandre Julliard026974f2008-01-24 10:20:51 +01001738 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
1739 }
Alexandre Julliard026974f2008-01-24 10:20:51 +01001740 return data;
1741}
1742
1743
1744/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001745 * X11DRV_get_whole_window
1746 *
1747 * Return the X window associated with the full area of a window
1748 */
1749Window X11DRV_get_whole_window( HWND hwnd )
1750{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001751 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001752
Alexandre Julliardc19af912008-01-17 19:53:59 +01001753 if (!data)
1754 {
1755 if (hwnd == GetDesktopWindow()) return root_window;
1756 return (Window)GetPropA( hwnd, whole_window_prop );
1757 }
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001758 return data->whole_window;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001759}
1760
1761
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001762/***********************************************************************
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001763 * X11DRV_get_client_window
1764 *
1765 * Return the X window associated with the client area of a window
1766 */
1767Window X11DRV_get_client_window( HWND hwnd )
1768{
1769 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1770
1771 if (!data)
1772 {
1773 if (hwnd == GetDesktopWindow()) return root_window;
1774 return (Window)GetPropA( hwnd, client_window_prop );
1775 }
1776 return data->client_window;
1777}
1778
1779
1780/***********************************************************************
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001781 * X11DRV_get_ic
1782 *
1783 * Return the X input context associated with a window
1784 */
1785XIC X11DRV_get_ic( HWND hwnd )
1786{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001787 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Kusanagi Kouichi185157c2008-04-04 20:44:36 +09001788 XIM xim;
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001789
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001790 if (!data) return 0;
Kusanagi Kouichi185157c2008-04-04 20:44:36 +09001791 if (data->xic) return data->xic;
1792 if (!(xim = x11drv_thread_data()->xim)) return 0;
1793 return X11DRV_CreateIC( xim, data );
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001794}
1795
1796
Alexandre Julliard1642fbc2008-02-25 15:59:19 +01001797/***********************************************************************
1798 * X11DRV_GetDC (X11DRV.@)
1799 */
1800void X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect,
1801 const RECT *top_rect, DWORD flags )
1802{
1803 struct x11drv_escape_set_drawable escape;
1804 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1805
1806 escape.code = X11DRV_SET_DRAWABLE;
1807 escape.mode = IncludeInferiors;
1808 escape.fbconfig_id = 0;
1809 escape.gl_drawable = 0;
1810 escape.pixmap = 0;
Alexandre Julliard2d9b3812008-05-28 17:52:06 +02001811 escape.gl_copy = FALSE;
Alexandre Julliard1642fbc2008-02-25 15:59:19 +01001812
1813 if (top == hwnd && data && IsIconic( hwnd ) && data->icon_window)
1814 {
1815 escape.drawable = data->icon_window;
1816 }
Alexandre Julliard2d9b3812008-05-28 17:52:06 +02001817 else if (top == hwnd)
Alexandre Julliard1642fbc2008-02-25 15:59:19 +01001818 {
Alexandre Julliard2d9b3812008-05-28 17:52:06 +02001819 escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop );
1820 /* GL draws to the client area even for window DCs */
1821 escape.gl_drawable = data ? data->client_window : X11DRV_get_client_window( hwnd );
1822 if (flags & DCX_WINDOW)
1823 escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd );
1824 else
1825 escape.drawable = escape.gl_drawable;
Alexandre Julliard1642fbc2008-02-25 15:59:19 +01001826 }
1827 else
1828 {
1829 escape.drawable = X11DRV_get_client_window( top );
1830 escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop );
1831 escape.gl_drawable = data ? data->gl_drawable : (Drawable)GetPropA( hwnd, gl_drawable_prop );
1832 escape.pixmap = data ? data->pixmap : (Pixmap)GetPropA( hwnd, pixmap_prop );
Alexandre Julliard2d9b3812008-05-28 17:52:06 +02001833 escape.gl_copy = (escape.gl_drawable != 0);
Alexandre Julliardaf369102008-03-18 12:42:25 +01001834 if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren;
Alexandre Julliard1642fbc2008-02-25 15:59:19 +01001835 }
1836
1837 escape.dc_rect.left = win_rect->left - top_rect->left;
1838 escape.dc_rect.top = win_rect->top - top_rect->top;
1839 escape.dc_rect.right = win_rect->right - top_rect->left;
1840 escape.dc_rect.bottom = win_rect->bottom - top_rect->top;
1841 escape.drawable_rect.left = top_rect->left;
1842 escape.drawable_rect.top = top_rect->top;
1843 escape.drawable_rect.right = top_rect->right;
1844 escape.drawable_rect.bottom = top_rect->bottom;
1845
1846 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1847}
1848
1849
1850/***********************************************************************
1851 * X11DRV_ReleaseDC (X11DRV.@)
1852 */
1853void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
1854{
1855 struct x11drv_escape_set_drawable escape;
1856
1857 escape.code = X11DRV_SET_DRAWABLE;
1858 escape.drawable = root_window;
1859 escape.mode = IncludeInferiors;
1860 escape.drawable_rect = virtual_screen_rect;
1861 SetRect( &escape.dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left,
1862 virtual_screen_rect.bottom - virtual_screen_rect.top );
1863 escape.fbconfig_id = 0;
1864 escape.gl_drawable = 0;
1865 escape.pixmap = 0;
1866 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1867}
1868
1869
Alexandre Julliarddc26f272008-03-12 15:01:24 +01001870/***********************************************************************
1871 * SetCapture (X11DRV.@)
1872 */
1873void X11DRV_SetCapture( HWND hwnd, UINT flags )
1874{
1875 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1876
Alexandre Julliard06a14072008-06-26 15:08:08 +02001877 if (!thread_data) return;
Alexandre Julliard78de7e32008-03-24 17:59:40 +01001878 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
Alexandre Julliarddc26f272008-03-12 15:01:24 +01001879
1880 if (hwnd)
1881 {
1882 Window grab_win = X11DRV_get_client_window( GetAncestor( hwnd, GA_ROOT ) );
1883
1884 if (!grab_win) return;
1885 wine_tsx11_lock();
1886 XFlush( gdi_display );
1887 XGrabPointer( thread_data->display, grab_win, False,
1888 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
Alexandre Julliard78de7e32008-03-24 17:59:40 +01001889 GrabModeAsync, GrabModeAsync, None, None, CurrentTime );
Alexandre Julliarddc26f272008-03-12 15:01:24 +01001890 wine_tsx11_unlock();
1891 thread_data->grab_window = grab_win;
1892 }
1893 else /* release capture */
1894 {
1895 wine_tsx11_lock();
1896 XFlush( gdi_display );
1897 XUngrabPointer( thread_data->display, CurrentTime );
1898 wine_tsx11_unlock();
1899 thread_data->grab_window = None;
1900 }
1901}
1902
1903
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001904/*****************************************************************
1905 * SetParent (X11DRV.@)
1906 */
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001907void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001908{
Alexandre Julliard43230042001-05-16 19:52:29 +00001909 Display *display = thread_display();
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001910 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001911
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001912 if (!data) return;
1913 if (parent == old_parent) return;
Alexandre Julliardfb0ff052001-10-16 21:58:58 +00001914
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001915 if (parent != GetDesktopWindow()) /* a child window */
Alexandre Julliard4d32a472005-03-25 10:38:56 +00001916 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001917 if (old_parent == GetDesktopWindow())
Alexandre Julliard4d32a472005-03-25 10:38:56 +00001918 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001919 /* destroy the old X windows */
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001920 destroy_whole_window( display, data, FALSE );
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001921 destroy_icon_window( display, data );
1922 if (data->managed)
Alexandre Julliardf777d702005-01-31 16:34:07 +00001923 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001924 data->managed = FALSE;
1925 RemovePropA( data->hwnd, managed_prop );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001926 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001927 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001928 }
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001929 else /* new top level window */
1930 {
1931 /* FIXME: we ignore errors since we can't really recover anyway */
Alexandre Julliardd147e022008-01-23 21:39:32 +01001932 create_whole_window( display, data );
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001933 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001934}
1935
1936
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001937/*****************************************************************
1938 * SetFocus (X11DRV.@)
1939 *
1940 * Set the X focus.
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001941 */
1942void X11DRV_SetFocus( HWND hwnd )
1943{
Alexandre Julliard43230042001-05-16 19:52:29 +00001944 Display *display = thread_display();
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001945 struct x11drv_win_data *data;
Alexandre Julliard125793d2008-02-18 17:22:51 +01001946 XWindowChanges changes;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001947
Alexandre Julliard9d53a1a2008-06-26 16:21:32 +02001948 if (!(hwnd = GetAncestor( hwnd, GA_ROOT ))) return;
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001949 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Todd Mokros88ac4b92005-08-22 09:14:21 +00001950 if (data->managed || !data->whole_window) return;
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001951
1952 /* Set X focus and install colormap */
1953 wine_tsx11_lock();
Alexandre Julliard125793d2008-02-18 17:22:51 +01001954 changes.stack_mode = Above;
1955 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
1956 if (root_window == DefaultRootWindow(display))
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001957 {
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001958 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1959 /* FIXME: this is not entirely correct */
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001960 XSetInputFocus( display, data->whole_window, RevertToParent,
Jeremy White77502e72005-01-14 17:06:40 +00001961 /* CurrentTime */
1962 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001963 }
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001964 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001965}
1966
1967
Alexandre Julliard855308f2008-04-23 15:32:58 +02001968/***********************************************************************
Alexandre Julliard89a3bd02008-07-02 15:40:10 +02001969 * WindowPosChanging (X11DRV.@)
Alexandre Julliard855308f2008-04-23 15:32:58 +02001970 */
Alexandre Julliard89a3bd02008-07-02 15:40:10 +02001971void X11DRV_WindowPosChanging( HWND hwnd, HWND insert_after, UINT swp_flags,
1972 const RECT *window_rect, const RECT *client_rect, RECT *visible_rect )
1973{
1974 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1975 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
1976
1977 if (!data)
1978 {
1979 /* create the win data if the window is being made visible */
1980 if (!(style & WS_VISIBLE) && !(swp_flags & SWP_SHOWWINDOW)) return;
1981 if (!(data = X11DRV_create_win_data( hwnd ))) return;
1982 }
1983
1984 /* check if we need to switch the window to managed */
1985 if (!data->managed && data->whole_window && is_window_managed( hwnd, swp_flags, window_rect ))
1986 {
1987 TRACE( "making win %p/%lx managed\n", hwnd, data->whole_window );
1988 if (data->mapped) unmap_window( thread_display(), data );
1989 data->managed = TRUE;
1990 SetPropA( hwnd, managed_prop, (HANDLE)1 );
1991 }
1992
1993 *visible_rect = *window_rect;
1994 X11DRV_window_to_X_rect( data, visible_rect );
1995}
1996
1997
1998/***********************************************************************
1999 * WindowPosChanged (X11DRV.@)
2000 */
2001void X11DRV_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_flags,
2002 const RECT *rectWindow, const RECT *rectClient,
2003 const RECT *visible_rect, const RECT *valid_rects )
Alexandre Julliard855308f2008-04-23 15:32:58 +02002004{
Alexandre Julliarde7044cb2008-06-26 16:47:42 +02002005 struct x11drv_thread_data *thread_data;
2006 Display *display;
Alexandre Julliard855308f2008-04-23 15:32:58 +02002007 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2008 DWORD new_style = GetWindowLongW( hwnd, GWL_STYLE );
Andrew Talbot51562192008-05-02 12:50:13 +01002009 RECT old_whole_rect, old_client_rect;
Alexandre Julliard855308f2008-04-23 15:32:58 +02002010 int event_type;
2011
Alexandre Julliard89a3bd02008-07-02 15:40:10 +02002012 if (!data) return;
Alexandre Julliard855308f2008-04-23 15:32:58 +02002013
Alexandre Julliarde7044cb2008-06-26 16:47:42 +02002014 thread_data = x11drv_thread_data();
2015 display = thread_data->display;
2016
Alexandre Julliard855308f2008-04-23 15:32:58 +02002017 old_whole_rect = data->whole_rect;
2018 old_client_rect = data->client_rect;
2019 data->window_rect = *rectWindow;
Alexandre Julliard89a3bd02008-07-02 15:40:10 +02002020 data->whole_rect = *visible_rect;
Alexandre Julliard855308f2008-04-23 15:32:58 +02002021 data->client_rect = *rectClient;
Alexandre Julliard855308f2008-04-23 15:32:58 +02002022
2023 TRACE( "win %p window %s client %s style %08x flags %08x\n",
2024 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style, swp_flags );
2025
2026 if (!IsRectEmpty( &valid_rects[0] ))
2027 {
2028 int x_offset = old_whole_rect.left - data->whole_rect.left;
2029 int y_offset = old_whole_rect.top - data->whole_rect.top;
2030
2031 /* if all that happened is that the whole window moved, copy everything */
2032 if (!(swp_flags & SWP_FRAMECHANGED) &&
2033 old_whole_rect.right - data->whole_rect.right == x_offset &&
2034 old_whole_rect.bottom - data->whole_rect.bottom == y_offset &&
2035 old_client_rect.left - data->client_rect.left == x_offset &&
2036 old_client_rect.right - data->client_rect.right == x_offset &&
2037 old_client_rect.top - data->client_rect.top == y_offset &&
2038 old_client_rect.bottom - data->client_rect.bottom == y_offset &&
2039 !memcmp( &valid_rects[0], &data->client_rect, sizeof(RECT) ))
2040 {
2041 /* if we have an X window the bits will be moved by the X server */
2042 if (!data->whole_window)
2043 move_window_bits( data, &old_whole_rect, &data->whole_rect, &old_client_rect );
2044 }
2045 else
2046 move_window_bits( data, &valid_rects[1], &valid_rects[0], &old_client_rect );
2047 }
2048
2049 wine_tsx11_lock();
2050 XFlush( gdi_display ); /* make sure painting is done before we move the window */
2051 wine_tsx11_unlock();
2052
2053 sync_client_position( display, data, swp_flags, &old_client_rect, &old_whole_rect );
2054
2055 if (!data->whole_window) return;
2056
2057 /* check if we are currently processing an event relevant to this window */
2058 event_type = 0;
2059 if (thread_data->current_event && thread_data->current_event->xany.window == data->whole_window)
2060 event_type = thread_data->current_event->type;
2061
2062 if (event_type != ConfigureNotify && event_type != PropertyNotify)
2063 event_type = 0; /* ignore other events */
2064
Alexandre Julliard6b9517a2008-05-01 17:45:17 +02002065 if (data->mapped)
2066 {
2067 if (((swp_flags & SWP_HIDEWINDOW) && !(new_style & WS_VISIBLE)) ||
2068 (!event_type && !is_window_rect_mapped( rectWindow )))
2069 unmap_window( display, data );
2070 }
Alexandre Julliard855308f2008-04-23 15:32:58 +02002071
2072 /* don't change position if we are about to minimize or maximize a managed window */
2073 if (!event_type &&
2074 !(data->managed && (swp_flags & SWP_STATECHANGED) && (new_style & (WS_MINIMIZE|WS_MAXIMIZE))))
2075 sync_window_position( display, data, swp_flags, &old_client_rect, &old_whole_rect );
2076
2077 if ((new_style & WS_VISIBLE) &&
2078 ((new_style & WS_MINIMIZE) || is_window_rect_mapped( rectWindow )))
2079 {
2080 if (!data->mapped || (swp_flags & (SWP_FRAMECHANGED|SWP_STATECHANGED)))
2081 set_wm_hints( display, data );
2082
2083 if (!data->mapped)
2084 {
2085 map_window( display, data, new_style );
2086 }
2087 else if ((swp_flags & SWP_STATECHANGED) && (!data->iconic != !(new_style & WS_MINIMIZE)))
2088 {
2089 data->iconic = (new_style & WS_MINIMIZE) != 0;
2090 TRACE( "changing win %p iconic state to %u\n", data->hwnd, data->iconic );
2091 wine_tsx11_lock();
2092 if (data->iconic)
2093 XIconifyWindow( display, data->whole_window, DefaultScreen(display) );
2094 else if (is_window_rect_mapped( rectWindow ))
2095 XMapWindow( display, data->whole_window );
2096 wine_tsx11_unlock();
2097 update_net_wm_states( display, data );
2098 }
2099 else if (!event_type)
2100 {
2101 update_net_wm_states( display, data );
2102 }
2103 }
2104
2105 wine_tsx11_lock();
2106 XFlush( display ); /* make sure changes are done before we start painting again */
2107 wine_tsx11_unlock();
2108}
2109
2110
Alexandre Julliard31b40612008-07-31 11:40:49 +02002111/***********************************************************************
2112 * ShowWindow (X11DRV.@)
2113 */
2114UINT X11DRV_ShowWindow( HWND hwnd, INT cmd, RECT *rect, UINT swp )
2115{
2116 int x, y;
2117 unsigned int width, height, border, depth;
2118 Window root, top;
2119 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
2120 struct x11drv_thread_data *thread_data = x11drv_thread_data();
2121 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2122
2123 if (!data || !data->whole_window || !data->managed || !data->mapped || data->iconic) return swp;
2124 if (style & WS_MINIMIZE) return swp;
Alexandre Julliard3cb23d32008-09-17 21:13:11 +02002125 if (IsRectEmpty( rect )) return swp;
Alexandre Julliard31b40612008-07-31 11:40:49 +02002126
2127 /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */
2128
2129 if (!thread_data->current_event || thread_data->current_event->xany.window != data->whole_window)
2130 return swp;
2131
2132 if (thread_data->current_event->type != ConfigureNotify &&
2133 thread_data->current_event->type != PropertyNotify)
2134 return swp;
2135
2136 TRACE( "win %p/%lx cmd %d at %s flags %08x\n",
2137 hwnd, data->whole_window, cmd, wine_dbgstr_rect(rect), swp );
2138
2139 wine_tsx11_lock();
2140 XGetGeometry( thread_data->display, data->whole_window,
2141 &root, &x, &y, &width, &height, &border, &depth );
2142 XTranslateCoordinates( thread_data->display, data->whole_window, root, 0, 0, &x, &y, &top );
2143 wine_tsx11_unlock();
2144 rect->left = x;
2145 rect->top = y;
2146 rect->right = x + width;
2147 rect->bottom = y + height;
2148 OffsetRect( rect, virtual_screen_rect.left, virtual_screen_rect.top );
2149 X11DRV_X_to_window_rect( data, rect );
2150 return swp & ~(SWP_NOMOVE | SWP_NOCLIENTMOVE | SWP_NOSIZE | SWP_NOCLIENTSIZE);
2151}
2152
2153
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002154/**********************************************************************
Patrik Stridvall01d5e5b2001-07-02 19:59:40 +00002155 * SetWindowIcon (X11DRV.@)
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002156 *
2157 * hIcon or hIconSm has changed (or is being initialised for the
2158 * first time). Complete the X11 driver-specific initialisation
2159 * and set the window hints.
2160 *
2161 * This is not entirely correct, may need to create
2162 * an icon window and set the pixmap as a background
2163 */
Alexandre Julliard446d8322003-12-31 23:51:52 +00002164void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002165{
Alexandre Julliard43230042001-05-16 19:52:29 +00002166 Display *display = thread_display();
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00002167 struct x11drv_win_data *data;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002168
Alexandre Julliard446d8322003-12-31 23:51:52 +00002169 if (type != ICON_BIG) return; /* nothing to do here */
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002170
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00002171 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Alexandre Julliardf777d702005-01-31 16:34:07 +00002172 if (!data->whole_window) return;
Alexandre Julliardd7726c32005-02-01 18:53:59 +00002173 if (!data->managed) return;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00002174
Alexandre Julliardbde89572007-08-16 23:27:37 +02002175 if (data->wm_hints)
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002176 {
Alexandre Julliardbde89572007-08-16 23:27:37 +02002177 set_icon_hints( display, data, icon );
Alexandre Julliarde9119c12002-09-24 18:36:51 +00002178 wine_tsx11_lock();
Alexandre Julliardbde89572007-08-16 23:27:37 +02002179 XSetWMHints( display, data->whole_window, data->wm_hints );
Alexandre Julliarde9119c12002-09-24 18:36:51 +00002180 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002181 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00002182}
Alexandre Julliard395928d2008-01-23 16:30:18 +01002183
2184
2185/***********************************************************************
2186 * SetWindowRgn (X11DRV.@)
2187 *
2188 * Assign specified region to window (for non-rectangular windows)
2189 */
2190int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
2191{
2192 struct x11drv_win_data *data;
2193
2194 if ((data = X11DRV_get_win_data( hwnd )))
2195 {
2196 sync_window_region( thread_display(), data, hrgn );
Alexandre Julliard395928d2008-01-23 16:30:18 +01002197 }
Alexandre Julliard9d45cfd2008-09-08 15:51:08 +02002198 else if (X11DRV_get_whole_window( hwnd ))
Alexandre Julliard395928d2008-01-23 16:30:18 +01002199 {
Alexandre Julliard9d45cfd2008-09-08 15:51:08 +02002200 SendMessageW( hwnd, WM_X11DRV_SET_WIN_REGION, 0, 0 );
Alexandre Julliard395928d2008-01-23 16:30:18 +01002201 }
Alexandre Julliard395928d2008-01-23 16:30:18 +01002202 return TRUE;
2203}
Alexandre Julliard24dbaa02008-04-17 16:13:34 +02002204
2205
Alexandre Julliardbe3c3a52008-09-12 15:54:02 +02002206/***********************************************************************
2207 * SetLayeredWindowAttributes (X11DRV.@)
2208 *
2209 * Set transparency attributes for a layered window.
2210 */
2211void X11DRV_SetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags )
2212{
Alexandre Julliardfb84ba52008-09-22 12:52:53 +02002213 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Alexandre Julliardbe3c3a52008-09-12 15:54:02 +02002214
Alexandre Julliardfb84ba52008-09-22 12:52:53 +02002215 if (data)
2216 {
2217 if (data->whole_window)
2218 sync_window_opacity( thread_display(), data->whole_window, key, alpha, flags );
2219 }
2220 else
2221 {
2222 Window win = X11DRV_get_whole_window( hwnd );
2223 if (win) sync_window_opacity( gdi_display, win, key, alpha, flags );
2224 }
Alexandre Julliardbe3c3a52008-09-12 15:54:02 +02002225}
2226
2227
Alexandre Julliard370368a2008-09-08 15:42:24 +02002228/**********************************************************************
2229 * X11DRV_WindowMessage (X11DRV.@)
2230 */
2231LRESULT X11DRV_WindowMessage( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
2232{
Alexandre Julliard9d45cfd2008-09-08 15:51:08 +02002233 struct x11drv_win_data *data;
2234
Alexandre Julliard370368a2008-09-08 15:42:24 +02002235 switch(msg)
2236 {
2237 case WM_X11DRV_ACQUIRE_SELECTION:
2238 return X11DRV_AcquireClipboard( hwnd );
2239 case WM_X11DRV_DELETE_WINDOW:
2240 return SendMessageW( hwnd, WM_SYSCOMMAND, SC_CLOSE, 0 );
2241 case WM_X11DRV_SET_WIN_FORMAT:
2242 return set_win_format( hwnd, (XID)wp );
Alexandre Julliard9d45cfd2008-09-08 15:51:08 +02002243 case WM_X11DRV_SET_WIN_REGION:
2244 if ((data = X11DRV_get_win_data( hwnd ))) sync_window_region( thread_display(), data, (HRGN)1 );
2245 return 0;
Alexandre Julliard370368a2008-09-08 15:42:24 +02002246 case WM_X11DRV_RESIZE_DESKTOP:
2247 X11DRV_resize_desktop( LOWORD(lp), HIWORD(lp) );
2248 return 0;
2249 default:
2250 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg, hwnd, wp, lp );
2251 return 0;
2252 }
2253}
2254
2255
Alexandre Julliard24dbaa02008-04-17 16:13:34 +02002256/***********************************************************************
2257 * is_netwm_supported
2258 */
2259static BOOL is_netwm_supported( Display *display, Atom atom )
2260{
2261 static Atom *net_supported;
2262 static int net_supported_count = -1;
2263 int i;
2264
2265 wine_tsx11_lock();
2266 if (net_supported_count == -1)
2267 {
2268 Atom type;
2269 int format;
2270 unsigned long count, remaining;
2271
2272 if (!XGetWindowProperty( display, DefaultRootWindow(display), x11drv_atom(_NET_SUPPORTED), 0,
2273 ~0UL, False, XA_ATOM, &type, &format, &count,
2274 &remaining, (unsigned char **)&net_supported ))
2275 net_supported_count = get_property_size( format, count ) / sizeof(Atom);
2276 else
2277 net_supported_count = 0;
2278 }
2279 wine_tsx11_unlock();
2280
2281 for (i = 0; i < net_supported_count; i++)
2282 if (net_supported[i] == atom) return TRUE;
2283 return FALSE;
2284}
2285
2286
2287/***********************************************************************
2288 * SysCommand (X11DRV.@)
2289 *
2290 * Perform WM_SYSCOMMAND handling.
2291 */
2292LRESULT X11DRV_SysCommand( HWND hwnd, WPARAM wparam, LPARAM lparam )
2293{
2294 WPARAM hittest = wparam & 0x0f;
2295 DWORD dwPoint;
2296 int x, y, dir;
2297 XEvent xev;
2298 Display *display = thread_display();
2299 struct x11drv_win_data *data;
2300
2301 if (!(data = X11DRV_get_win_data( hwnd ))) return -1;
2302 if (!data->whole_window || !data->managed || !data->mapped) return -1;
2303
2304 switch (wparam & 0xfff0)
2305 {
2306 case SC_MOVE:
2307 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
2308 else dir = _NET_WM_MOVERESIZE_MOVE;
2309 break;
2310 case SC_SIZE:
2311 /* windows without WS_THICKFRAME are not resizable through the window manager */
2312 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) return -1;
2313
2314 switch (hittest)
2315 {
2316 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
2317 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
2318 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
2319 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
2320 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
2321 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
2322 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
2323 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
2324 default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break;
2325 }
2326 break;
2327
2328 case SC_KEYMENU:
2329 /* prevent a simple ALT press+release from activating the system menu,
2330 * as that can get confusing on managed windows */
2331 if ((WCHAR)lparam) return -1; /* got an explicit char */
2332 if (GetMenu( hwnd )) return -1; /* window has a real menu */
2333 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_SYSMENU)) return -1; /* no system menu */
2334 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam, lparam );
2335 return 0;
2336
2337 default:
2338 return -1;
2339 }
2340
2341 if (IsZoomed(hwnd)) return -1;
2342
2343 if (!is_netwm_supported( display, x11drv_atom(_NET_WM_MOVERESIZE) ))
2344 {
2345 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
2346 return -1;
2347 }
2348
2349 dwPoint = GetMessagePos();
2350 x = (short)LOWORD(dwPoint);
2351 y = (short)HIWORD(dwPoint);
2352
2353 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd, x, y, dir);
2354
2355 xev.xclient.type = ClientMessage;
2356 xev.xclient.window = X11DRV_get_whole_window(hwnd);
2357 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
2358 xev.xclient.serial = 0;
2359 xev.xclient.display = display;
2360 xev.xclient.send_event = True;
2361 xev.xclient.format = 32;
Alexandre Julliard9fab7b42008-09-12 11:03:26 +02002362 xev.xclient.data.l[0] = x - virtual_screen_rect.left; /* x coord */
2363 xev.xclient.data.l[1] = y - virtual_screen_rect.top; /* y coord */
Alexandre Julliard24dbaa02008-04-17 16:13:34 +02002364 xev.xclient.data.l[2] = dir; /* direction */
2365 xev.xclient.data.l[3] = 1; /* button */
2366 xev.xclient.data.l[4] = 0; /* unused */
2367
2368 /* need to ungrab the pointer that may have been automatically grabbed
2369 * with a ButtonPress event */
2370 wine_tsx11_lock();
2371 XUngrabPointer( display, CurrentTime );
2372 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
2373 wine_tsx11_unlock();
2374 return 0;
2375}