blob: e0e8ea154a8d628e20ffed8d604466c92f911776 [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 Julliard9ae0fe52001-04-24 23:28:52 +000053/* X context to associate a hwnd to an X window */
54XContext winContext = 0;
55
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +000056/* X context to associate a struct x11drv_win_data to an hwnd */
57static XContext win_data_context;
58
Alexandre Julliardaf50ad62005-07-07 17:30:57 +000059static const char whole_window_prop[] = "__wine_x11_whole_window";
Alexandre Julliard8ee07d42008-02-21 12:29:36 +010060static const char client_window_prop[]= "__wine_x11_client_window";
Alexandre Julliardaf50ad62005-07-07 17:30:57 +000061static const char icon_window_prop[] = "__wine_x11_icon_window";
Chris Robinsond9571c92007-09-15 13:02:32 -070062static const char fbconfig_id_prop[] = "__wine_x11_fbconfig_id";
Chris Robinsona8124f92007-09-25 10:20:58 -070063static const char gl_drawable_prop[] = "__wine_x11_gl_drawable";
Chris Robinson37d835b2007-09-26 08:17:13 -070064static const char pixmap_prop[] = "__wine_x11_pixmap";
Alexandre Julliardaf50ad62005-07-07 17:30:57 +000065static const char managed_prop[] = "__wine_x11_managed";
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000066
Chris Robinson00633e32007-09-25 22:43:38 -070067extern int usexcomposite;
68
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000069/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +000070 * is_window_managed
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000071 *
Alexandre Julliarddc4fe772001-06-04 21:55:17 +000072 * Check if a given window should be managed
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000073 */
Alexandre Julliardeffdfa72007-08-27 12:37:14 +020074BOOL is_window_managed( HWND hwnd, UINT swp_flags, const RECT *window_rect )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +000075{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000076 DWORD style, ex_style;
77
Alexandre Julliard89131822008-01-24 10:21:07 +010078 if (!managed_mode) return FALSE;
79
Alexandre Julliarddc4fe772001-06-04 21:55:17 +000080 /* child windows are not managed */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000081 style = GetWindowLongW( hwnd, GWL_STYLE );
Peter Dons Tychsend0b21ab2007-07-25 04:09:50 +020082 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD) return FALSE;
Alexandre Julliardeffdfa72007-08-27 12:37:14 +020083 /* activated windows are managed */
84 if (!(swp_flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) return TRUE;
85 if (hwnd == GetActiveWindow()) return TRUE;
Mike Hearn27d972f2003-12-04 21:54:13 +000086 /* windows with caption are managed */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000087 if ((style & WS_CAPTION) == WS_CAPTION) return TRUE;
Mike Hearn27d972f2003-12-04 21:54:13 +000088 /* tool windows are not managed */
Alexandre Julliardcbdf1292008-01-23 21:40:45 +010089 ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE );
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000090 if (ex_style & WS_EX_TOOLWINDOW) return FALSE;
Mike Hearn27d972f2003-12-04 21:54:13 +000091 /* windows with thick frame are managed */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000092 if (style & WS_THICKFRAME) return TRUE;
Jerry Jenkins4e6fab52003-12-13 00:05:53 +000093 /* application windows are managed */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000094 if (ex_style & WS_EX_APPWINDOW) return TRUE;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +000095 if (style & WS_POPUP)
Alex Pasadynd18c8ca2004-02-06 05:17:55 +000096 {
Vitaliy Margolenabcbcc32007-02-10 10:40:50 -070097 /* popup with sysmenu == caption are managed */
98 if (style & WS_SYSMENU) return TRUE;
99 /* full-screen popup windows are managed */
Alexandre Julliarddba8ad52008-02-25 19:48:07 +0100100 if (window_rect->left <= 0 && window_rect->right >= screen_width &&
101 window_rect->top <= 0 && window_rect->bottom >= screen_height)
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000102 return TRUE;
Alex Pasadynd18c8ca2004-02-06 05:17:55 +0000103 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000104 /* default: not managed */
105 return FALSE;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000106}
107
108
109/***********************************************************************
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000110 * X11DRV_is_window_rect_mapped
111 *
112 * Check if the X whole window should be mapped based on its rectangle
113 */
114BOOL X11DRV_is_window_rect_mapped( const RECT *rect )
115{
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000116 /* don't map if rect is off-screen */
Alexandre Julliard3c305f92006-10-23 14:37:17 +0200117 if (rect->left >= virtual_screen_rect.right ||
118 rect->top >= virtual_screen_rect.bottom ||
119 rect->right <= virtual_screen_rect.left ||
120 rect->bottom <= virtual_screen_rect.top)
121 return FALSE;
Alexandre Julliard59b7d342004-04-27 23:32:01 +0000122
123 return TRUE;
124}
125
126
127/***********************************************************************
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200128 * is_window_resizable
129 *
130 * Check if window should be made resizable by the window manager
131 */
132static inline BOOL is_window_resizable( struct x11drv_win_data *data, DWORD style )
133{
134 if (style & WS_THICKFRAME) return TRUE;
135 /* Metacity needs the window to be resizable to make it fullscreen */
136 return (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width &&
137 data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height);
138}
139
140
141/***********************************************************************
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200142 * get_mwm_decorations
143 */
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900144static unsigned long get_mwm_decorations( struct x11drv_win_data *data,
145 DWORD style, DWORD ex_style )
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200146{
147 unsigned long ret = 0;
148
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900149 if (!decorated_mode) return 0;
150
151 if (IsRectEmpty( &data->window_rect )) return 0;
Matthew D'Asaro4217fcb2008-04-10 12:53:45 -0700152
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200153 if (ex_style & WS_EX_TOOLWINDOW) return 0;
154
155 if ((style & WS_CAPTION) == WS_CAPTION)
156 {
157 ret |= MWM_DECOR_TITLE | MWM_DECOR_BORDER;
158 if (style & WS_SYSMENU) ret |= MWM_DECOR_MENU;
159 if (style & WS_MINIMIZEBOX) ret |= MWM_DECOR_MINIMIZE;
160 if (style & WS_MAXIMIZEBOX) ret |= MWM_DECOR_MAXIMIZE;
161 }
162 if (ex_style & WS_EX_DLGMODALFRAME) ret |= MWM_DECOR_BORDER;
163 else if (style & WS_THICKFRAME) ret |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
164 else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) ret |= MWM_DECOR_BORDER;
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200165 return ret;
166}
167
168
169/***********************************************************************
170 * get_x11_rect_offset
171 *
172 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
173 */
174static void get_x11_rect_offset( struct x11drv_win_data *data, RECT *rect )
175{
176 DWORD style, ex_style, style_mask = 0, ex_style_mask = 0;
177 unsigned long decor;
178
179 rect->top = rect->bottom = rect->left = rect->right = 0;
180
181 style = GetWindowLongW( data->hwnd, GWL_STYLE );
182 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900183 decor = get_mwm_decorations( data, style, ex_style );
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200184
185 if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION;
186 if (decor & MWM_DECOR_BORDER)
187 {
188 style_mask |= WS_DLGFRAME | WS_THICKFRAME;
189 ex_style_mask |= WS_EX_DLGMODALFRAME;
190 }
191
192 AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask );
193}
194
195
196/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000197 * get_window_attributes
198 *
Alexandre Julliard883cff42001-06-12 04:02:10 +0000199 * Fill the window attributes structure for an X window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000200 */
Alexandre Julliard6bb18e22006-03-27 15:33:43 +0200201static int get_window_attributes( Display *display, struct x11drv_win_data *data,
202 XSetWindowAttributes *attr )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000203{
Alexandre Julliardd7726c32005-02-01 18:53:59 +0000204 attr->override_redirect = !data->managed;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000205 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000206 attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0);
Alexandre Julliard9428f062002-06-14 00:08:40 +0000207 attr->cursor = x11drv_thread_data()->cursor;
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200208 attr->bit_gravity = NorthWestGravity;
209 attr->backing_store = NotUseful;
210 attr->event_mask = (ExposureMask | PointerMotionMask |
211 ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
212 KeyPressMask | KeyReleaseMask | FocusChangeMask | KeymapStateMask);
Alexandre Julliard5a5344b2008-02-27 19:11:43 +0100213 if (data->managed) attr->event_mask |= StructureNotifyMask | PropertyChangeMask;
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200214
215 return (CWOverrideRedirect | CWSaveUnder | CWColormap | CWCursor |
216 CWEventMask | CWBitGravity | CWBackingStore);
Alexandre Julliard883cff42001-06-12 04:02:10 +0000217}
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000218
Alexandre Julliard883cff42001-06-12 04:02:10 +0000219
220/***********************************************************************
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100221 * create_client_window
222 */
223static Window create_client_window( Display *display, struct x11drv_win_data *data, XVisualInfo *vis )
224{
225 int cx, cy, mask;
226 XSetWindowAttributes attr;
227 Window client;
228
229 attr.bit_gravity = NorthWestGravity;
230 attr.win_gravity = NorthWestGravity;
231 attr.backing_store = NotUseful;
232 attr.event_mask = (ExposureMask | PointerMotionMask |
233 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
234 mask = CWEventMask | CWBitGravity | CWWinGravity | CWBackingStore;
235
236 if ((cx = data->client_rect.right - data->client_rect.left) <= 0) cx = 1;
237 if ((cy = data->client_rect.bottom - data->client_rect.top) <= 0) cy = 1;
238
239 wine_tsx11_lock();
240
241 if (vis)
242 {
243 attr.colormap = XCreateColormap( display, root_window, vis->visual,
244 (vis->class == PseudoColor || vis->class == GrayScale ||
245 vis->class == DirectColor) ? AllocAll : AllocNone );
246 mask |= CWColormap;
247 }
248
249 client = XCreateWindow( display, data->whole_window,
250 data->client_rect.left - data->whole_rect.left,
251 data->client_rect.top - data->whole_rect.top,
252 cx, cy, 0, screen_depth, InputOutput,
253 vis ? vis->visual : visual, mask, &attr );
254 if (!client)
255 {
256 wine_tsx11_unlock();
257 return 0;
258 }
259
260 if (data->client_window)
261 {
Alexandre Julliard51d3d622008-03-05 20:52:14 +0100262 struct x11drv_thread_data *thread_data = x11drv_thread_data();
263 if (thread_data->cursor_window == data->client_window) thread_data->cursor_window = None;
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100264 XDeleteContext( display, data->client_window, winContext );
265 XDestroyWindow( display, data->client_window );
266 }
267 data->client_window = client;
268
269 if (data->colormap) XFreeColormap( display, data->colormap );
270 data->colormap = vis ? attr.colormap : 0;
271
272 XMapWindow( display, data->client_window );
273 XSaveContext( display, data->client_window, winContext, (char *)data->hwnd );
274 wine_tsx11_unlock();
275
276 SetPropA( data->hwnd, client_window_prop, (HANDLE)data->client_window );
277 return data->client_window;
278}
279
280
281/***********************************************************************
Alexandre Julliard911a1772002-08-20 00:36:45 +0000282 * X11DRV_sync_window_style
Alexandre Julliard883cff42001-06-12 04:02:10 +0000283 *
284 * Change the X window attributes when the window style has changed.
285 */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000286void X11DRV_sync_window_style( Display *display, struct x11drv_win_data *data )
Alexandre Julliard883cff42001-06-12 04:02:10 +0000287{
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200288 if (data->whole_window != root_window)
289 {
290 XSetWindowAttributes attr;
291 int mask = get_window_attributes( display, data, &attr );
Alexandre Julliard883cff42001-06-12 04:02:10 +0000292
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200293 wine_tsx11_lock();
Alexandre Julliard6d5f5442006-03-06 21:02:59 +0100294 XChangeWindowAttributes( display, data->whole_window, mask, &attr );
Alexandre Julliard0ce71872007-08-20 14:23:10 +0200295 wine_tsx11_unlock();
296 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000297}
298
299
300/***********************************************************************
Alexandre Julliard395928d2008-01-23 16:30:18 +0100301 * sync_window_region
302 *
303 * Update the X11 window region.
304 */
305static void sync_window_region( Display *display, struct x11drv_win_data *data, HRGN hrgn )
306{
307#ifdef HAVE_LIBXSHAPE
308 if (!data->whole_window) return;
309
310 if (!hrgn)
311 {
312 wine_tsx11_lock();
313 XShapeCombineMask( display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet );
314 wine_tsx11_unlock();
315 }
316 else
317 {
318 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
319 if (pRegionData)
320 {
321 wine_tsx11_lock();
322 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
323 data->window_rect.left - data->whole_rect.left,
324 data->window_rect.top - data->whole_rect.top,
325 (XRectangle *)pRegionData->Buffer,
326 pRegionData->rdh.nCount, ShapeSet, YXBanded );
327 wine_tsx11_unlock();
328 HeapFree(GetProcessHeap(), 0, pRegionData);
329 }
330 }
331#endif /* HAVE_LIBXSHAPE */
332}
333
334
335/***********************************************************************
Alexandre Julliard3ba20252008-01-23 16:32:55 +0100336 * sync_window_text
337 */
338static void sync_window_text( Display *display, Window win, const WCHAR *text )
339{
340 UINT count;
341 char *buffer, *utf8_buffer;
342 XTextProperty prop;
343
344 /* allocate new buffer for window text */
345 count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
346 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) return;
347 WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
348
349 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
350 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
351 {
352 HeapFree( GetProcessHeap(), 0, buffer );
353 return;
354 }
355 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
356
357 wine_tsx11_lock();
358 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
359 {
360 XSetWMName( display, win, &prop );
361 XSetWMIconName( display, win, &prop );
362 XFree( prop.value );
363 }
364 /*
365 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
366 according to the standard
367 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
368 */
369 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
370 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
371 wine_tsx11_unlock();
372
373 HeapFree( GetProcessHeap(), 0, utf8_buffer );
374 HeapFree( GetProcessHeap(), 0, buffer );
375}
376
377
378/***********************************************************************
Chris Robinsond9571c92007-09-15 13:02:32 -0700379 * X11DRV_set_win_format
380 */
381BOOL X11DRV_set_win_format( HWND hwnd, XID fbconfig_id )
382{
Chris Robinson00633e32007-09-25 22:43:38 -0700383 Display *display = thread_display();
Chris Robinsond9571c92007-09-15 13:02:32 -0700384 struct x11drv_win_data *data;
Chris Robinson00633e32007-09-25 22:43:38 -0700385 XVisualInfo *vis;
Chris Robinson00633e32007-09-25 22:43:38 -0700386 int w, h;
Chris Robinsond9571c92007-09-15 13:02:32 -0700387
Alexandre Julliard026974f2008-01-24 10:20:51 +0100388 if (!(data = X11DRV_get_win_data(hwnd)) &&
389 !(data = X11DRV_create_win_data(hwnd))) return FALSE;
Chris Robinsond9571c92007-09-15 13:02:32 -0700390
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100391 if (data->fbconfig_id) return FALSE; /* can't change it twice */
392
Chris Robinson00633e32007-09-25 22:43:38 -0700393 wine_tsx11_lock();
Chris Robinson00633e32007-09-25 22:43:38 -0700394 vis = visual_from_fbconfig_id(fbconfig_id);
Chris Robinson00633e32007-09-25 22:43:38 -0700395 wine_tsx11_unlock();
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100396 if (!vis) return FALSE;
Chris Robinson00633e32007-09-25 22:43:38 -0700397
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100398 if (data->whole_window)
Chris Robinson00633e32007-09-25 22:43:38 -0700399 {
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100400 Window client = data->client_window;
401
402 if (vis->visualid != XVisualIDFromVisual(visual))
Chris Robinson00633e32007-09-25 22:43:38 -0700403 {
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100404 client = create_client_window( display, data, vis );
405 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client, data->hwnd, fbconfig_id );
Chris Robinson00633e32007-09-25 22:43:38 -0700406 }
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100407 wine_tsx11_lock();
408 XFree(vis);
409 wine_tsx11_unlock();
410 if (client) goto done;
411 return FALSE;
Chris Robinson00633e32007-09-25 22:43:38 -0700412 }
413
414 w = data->client_rect.right - data->client_rect.left;
415 h = data->client_rect.bottom - data->client_rect.top;
416
417 if(w <= 0) w = 1;
418 if(h <= 0) h = 1;
419
Chris Robinson00633e32007-09-25 22:43:38 -0700420#ifdef SONAME_LIBXCOMPOSITE
421 if(usexcomposite)
422 {
423 XSetWindowAttributes attrib;
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100424 Window parent = X11DRV_get_whole_window( GetAncestor( hwnd, GA_ROOT ));
Chris Robinson00633e32007-09-25 22:43:38 -0700425
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100426 if (!parent) parent = root_window;
427 wine_tsx11_lock();
Alexandre Julliarde9307d02008-02-21 20:23:32 +0100428 data->colormap = XCreateColormap(display, parent, vis->visual,
429 (vis->class == PseudoColor ||
430 vis->class == GrayScale ||
431 vis->class == DirectColor) ?
432 AllocAll : AllocNone);
Chris Robinson00633e32007-09-25 22:43:38 -0700433 attrib.override_redirect = True;
Alexandre Julliarde9307d02008-02-21 20:23:32 +0100434 attrib.colormap = data->colormap;
Chris Robinson00633e32007-09-25 22:43:38 -0700435 XInstallColormap(gdi_display, attrib.colormap);
436
437 data->gl_drawable = XCreateWindow(display, parent, -w, 0, w, h, 0,
438 vis->depth, InputOutput, vis->visual,
439 CWColormap | CWOverrideRedirect,
440 &attrib);
441 if(data->gl_drawable)
442 {
443 pXCompositeRedirectWindow(display, data->gl_drawable,
444 CompositeRedirectManual);
445 XMapWindow(display, data->gl_drawable);
446 }
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100447 XFree(vis);
448 wine_tsx11_unlock();
Chris Robinson00633e32007-09-25 22:43:38 -0700449 }
Chris Robinson37d835b2007-09-26 08:17:13 -0700450 else
Chris Robinson00633e32007-09-25 22:43:38 -0700451#endif
Chris Robinson37d835b2007-09-26 08:17:13 -0700452 {
453 WARN("XComposite is not available, using GLXPixmap hack\n");
454
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100455 wine_tsx11_lock();
456 data->pixmap = XCreatePixmap(display, root_window, w, h, vis->depth);
Chris Robinson37d835b2007-09-26 08:17:13 -0700457 if(!data->pixmap)
458 {
Chris Robinson37d835b2007-09-26 08:17:13 -0700459 XFree(vis);
460 wine_tsx11_unlock();
461 return FALSE;
462 }
463
464 data->gl_drawable = create_glxpixmap(display, vis, data->pixmap);
465 if(!data->gl_drawable)
466 {
467 XFreePixmap(display, data->pixmap);
468 data->pixmap = 0;
469 }
Chris Robinson00633e32007-09-25 22:43:38 -0700470 XFree(vis);
471 wine_tsx11_unlock();
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100472 if (data->pixmap) SetPropA(hwnd, pixmap_prop, (HANDLE)data->pixmap);
Chris Robinson00633e32007-09-25 22:43:38 -0700473 }
474
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100475 if (!data->gl_drawable) return FALSE;
Chris Robinson00633e32007-09-25 22:43:38 -0700476
477 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
478 data->gl_drawable, fbconfig_id);
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100479 SetPropA(hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
Chris Robinson00633e32007-09-25 22:43:38 -0700480
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100481done:
Chris Robinsond9571c92007-09-15 13:02:32 -0700482 data->fbconfig_id = fbconfig_id;
483 SetPropA(hwnd, fbconfig_id_prop, (HANDLE)data->fbconfig_id);
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100484 wine_tsx11_lock();
485 XFlush( display );
486 wine_tsx11_unlock();
Alexandre Julliard1642fbc2008-02-25 15:59:19 +0100487 WIN_invalidate_dce( hwnd, NULL );
Chris Robinsond9571c92007-09-15 13:02:32 -0700488 return TRUE;
489}
490
Alexandre Julliardbbfbe242008-01-23 12:28:01 +0100491/***********************************************************************
Alexandre Julliard8ee07d42008-02-21 12:29:36 +0100492 * sync_gl_drawable
Alexandre Julliardbbfbe242008-01-23 12:28:01 +0100493 */
Alexandre Julliard8ee07d42008-02-21 12:29:36 +0100494static void sync_gl_drawable(Display *display, struct x11drv_win_data *data)
Chris Robinson00633e32007-09-25 22:43:38 -0700495{
496 int w = data->client_rect.right - data->client_rect.left;
497 int h = data->client_rect.bottom - data->client_rect.top;
Chris Robinson37d835b2007-09-26 08:17:13 -0700498 XVisualInfo *vis;
Chris Robinson37d835b2007-09-26 08:17:13 -0700499 Drawable glxp;
500 Pixmap pix;
Chris Robinson00633e32007-09-25 22:43:38 -0700501
Alexandre Julliardf13ef6b2008-02-22 16:30:10 +0100502 if (w <= 0) w = 1;
503 if (h <= 0) h = 1;
504
Chris Robinson00633e32007-09-25 22:43:38 -0700505 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data->gl_drawable, w, h);
506#ifdef SONAME_LIBXCOMPOSITE
507 if(usexcomposite)
508 {
509 wine_tsx11_lock();
510 XMoveResizeWindow(display, data->gl_drawable, -w, 0, w, h);
511 wine_tsx11_unlock();
512 return;
513 }
514#endif
Chris Robinson37d835b2007-09-26 08:17:13 -0700515
Chris Robinson37d835b2007-09-26 08:17:13 -0700516 wine_tsx11_lock();
517
518 vis = visual_from_fbconfig_id(data->fbconfig_id);
Michael Stefaniuc4e2eef22007-10-21 01:15:53 +0200519 if(!vis)
520 {
521 wine_tsx11_unlock();
522 return;
523 }
Chris Robinson37d835b2007-09-26 08:17:13 -0700524
Alexandre Julliard42ad3452008-02-22 10:40:22 +0100525 pix = XCreatePixmap(display, root_window, w, h, vis->depth);
Chris Robinson37d835b2007-09-26 08:17:13 -0700526 if(!pix)
527 {
528 ERR("Failed to create pixmap for offscreen rendering\n");
529 XFree(vis);
530 wine_tsx11_unlock();
531 return;
532 }
533
534 glxp = create_glxpixmap(display, vis, pix);
535 if(!glxp)
536 {
537 ERR("Failed to create drawable for offscreen rendering\n");
538 XFreePixmap(display, pix);
539 XFree(vis);
540 wine_tsx11_unlock();
541 return;
542 }
543
544 XFree(vis);
545
546 mark_drawable_dirty(data->gl_drawable, glxp);
547
548 XFreePixmap(display, data->pixmap);
549 destroy_glxpixmap(display, data->gl_drawable);
550
551 data->pixmap = pix;
552 data->gl_drawable = glxp;
553
Alexandre Julliard70ef99e2008-04-10 14:47:19 +0200554 XFlush( display );
Chris Robinson37d835b2007-09-26 08:17:13 -0700555 wine_tsx11_unlock();
556
557 SetPropA(data->hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
558 SetPropA(data->hwnd, pixmap_prop, (HANDLE)data->pixmap);
Chris Robinson00633e32007-09-25 22:43:38 -0700559}
560
Chris Robinsond9571c92007-09-15 13:02:32 -0700561
562/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000563 * get_window_changes
564 *
565 * fill the window changes structure
566 */
567static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
568{
569 int mask = 0;
570
571 if (old->right - old->left != new->right - new->left )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000572 {
Alexandre Julliard8ee07d42008-02-21 12:29:36 +0100573 if ((changes->width = new->right - new->left) <= 0) changes->width = 1;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000574 mask |= CWWidth;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000575 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000576 if (old->bottom - old->top != new->bottom - new->top)
577 {
Alexandre Julliard8ee07d42008-02-21 12:29:36 +0100578 if ((changes->height = new->bottom - new->top) <= 0) changes->height = 1;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000579 mask |= CWHeight;
580 }
581 if (old->left != new->left)
582 {
583 changes->x = new->left;
584 mask |= CWX;
585 }
586 if (old->top != new->top)
587 {
588 changes->y = new->top;
589 mask |= CWY;
590 }
591 return mask;
592}
593
594
595/***********************************************************************
596 * create_icon_window
597 */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000598static Window create_icon_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000599{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000600 XSetWindowAttributes attr;
601
602 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
Alexandre Julliard9428f062002-06-14 00:08:40 +0000603 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000604 attr.bit_gravity = NorthWestGravity;
605 attr.backing_store = NotUseful/*WhenMapped*/;
Lionel Ulmer1fc39be2001-07-12 22:27:56 +0000606 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000607
Alexandre Julliard649637f2001-06-26 21:10:11 +0000608 wine_tsx11_lock();
609 data->icon_window = XCreateWindow( display, root_window, 0, 0,
610 GetSystemMetrics( SM_CXICON ),
611 GetSystemMetrics( SM_CYICON ),
612 0, screen_depth,
613 InputOutput, visual,
Lionel Ulmer1fc39be2001-07-12 22:27:56 +0000614 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000615 XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd );
Alexandre Julliard731d77f2008-04-09 20:24:27 +0200616 XFlush( display ); /* make sure the window exists before we start painting to it */
Alexandre Julliard649637f2001-06-26 21:10:11 +0000617 wine_tsx11_unlock();
618
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000619 TRACE( "created %lx\n", data->icon_window );
Alexandre Julliardaf50ad62005-07-07 17:30:57 +0000620 SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000621 return data->icon_window;
622}
623
624
625
626/***********************************************************************
627 * destroy_icon_window
628 */
Alexandre Julliardf777d702005-01-31 16:34:07 +0000629static void destroy_icon_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000630{
631 if (!data->icon_window) return;
Alexandre Julliard9428f062002-06-14 00:08:40 +0000632 if (x11drv_thread_data()->cursor_window == data->icon_window)
633 x11drv_thread_data()->cursor_window = None;
Alexandre Julliard704d0352001-07-12 02:49:31 +0000634 wine_tsx11_lock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000635 XDeleteContext( display, data->icon_window, winContext );
636 XDestroyWindow( display, data->icon_window );
637 data->icon_window = 0;
Alexandre Julliard704d0352001-07-12 02:49:31 +0000638 wine_tsx11_unlock();
Alexandre Julliardaf50ad62005-07-07 17:30:57 +0000639 RemovePropA( data->hwnd, icon_window_prop );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000640}
641
642
643/***********************************************************************
644 * set_icon_hints
645 *
646 * Set the icon wm hints
647 */
Alexandre Julliardbde89572007-08-16 23:27:37 +0200648static void set_icon_hints( Display *display, struct x11drv_win_data *data, HICON hIcon )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000649{
Alexandre Julliardbde89572007-08-16 23:27:37 +0200650 XWMHints *hints = data->wm_hints;
651
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000652 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
653 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
Alexandre Julliard883cff42001-06-12 04:02:10 +0000654 data->hWMIconBitmap = 0;
655 data->hWMIconMask = 0;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000656
Alexandre Julliard12d1d402008-01-23 16:40:19 +0100657 if (!hIcon)
Alexandre Julliard883cff42001-06-12 04:02:10 +0000658 {
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000659 if (!data->icon_window) create_icon_window( display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000660 hints->icon_window = data->icon_window;
661 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000662 }
663 else
664 {
665 HBITMAP hbmOrig;
666 RECT rcMask;
667 BITMAP bmMask;
668 ICONINFO ii;
669 HDC hDC;
670
671 GetIconInfo(hIcon, &ii);
672
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000673 GetObjectA(ii.hbmMask, sizeof(bmMask), &bmMask);
674 rcMask.top = 0;
675 rcMask.left = 0;
676 rcMask.right = bmMask.bmWidth;
677 rcMask.bottom = bmMask.bmHeight;
678
679 hDC = CreateCompatibleDC(0);
680 hbmOrig = SelectObject(hDC, ii.hbmMask);
681 InvertRect(hDC, &rcMask);
Alexandre Julliardd8a92442002-05-31 18:43:22 +0000682 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000683 SelectObject(hDC, hbmOrig);
684 DeleteDC(hDC);
685
686 data->hWMIconBitmap = ii.hbmColor;
687 data->hWMIconMask = ii.hbmMask;
688
Alexandre Julliard5fd13262005-03-27 18:30:51 +0000689 hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap);
690 hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask);
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000691 destroy_icon_window( display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000692 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000693 }
694}
695
696
697/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000698 * set_size_hints
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000699 *
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000700 * set the window size hints
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000701 */
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000702static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +0000703{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000704 XSizeHints* size_hints;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000705
Alexandre Julliardcf9d3e32008-04-04 11:28:30 +0200706 if (!(size_hints = XAllocSizeHints())) return;
Alexandre Julliardba1517f2006-03-27 22:16:04 +0200707
Alexandre Julliardcf9d3e32008-04-04 11:28:30 +0200708 /* don't update size hints if window is not in normal state */
709 if (!(style & (WS_MINIMIZE | WS_MAXIMIZE)))
710 {
Alexandre Julliardba1517f2006-03-27 22:16:04 +0200711 if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */
712 {
713 size_hints->win_gravity = StaticGravity;
714 size_hints->x = data->whole_rect.left;
715 size_hints->y = data->whole_rect.top;
716 size_hints->flags |= PWinGravity | PPosition;
717 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000718
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200719 if (!is_window_resizable( data, style ))
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000720 {
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200721 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
722 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
723 size_hints->min_width = size_hints->max_width;
724 size_hints->min_height = size_hints->max_height;
725 size_hints->flags |= PMinSize | PMaxSize;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000726 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000727 }
Alexandre Julliardcf9d3e32008-04-04 11:28:30 +0200728 XSetWMNormalHints( display, data->whole_window, size_hints );
729 XFree( size_hints );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000730}
731
732
733/***********************************************************************
Alexandre Julliardc7dbffc2005-07-01 16:16:00 +0000734 * get_process_name
735 *
736 * get the name of the current process for setting class hints
737 */
738static char *get_process_name(void)
739{
740 static char *name;
741
742 if (!name)
743 {
744 WCHAR module[MAX_PATH];
745 DWORD len = GetModuleFileNameW( 0, module, MAX_PATH );
746 if (len && len < MAX_PATH)
747 {
748 char *ptr;
749 WCHAR *p, *appname = module;
750
751 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
752 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
753 len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL );
754 if ((ptr = HeapAlloc( GetProcessHeap(), 0, len )))
755 {
756 WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL );
757 name = ptr;
758 }
759 }
760 }
761 return name;
762}
763
764
765/***********************************************************************
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200766 * set_initial_wm_hints
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000767 *
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200768 * Set the window manager hints that don't change over the lifetime of a window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000769 */
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200770static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000771{
Alexandre Julliard3bfa90e2008-04-07 11:41:54 +0200772 long i;
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200773 Atom protocols[3];
774 Atom dndVersion = 4;
775 XClassHint *class_hints;
Alexandre Julliardc7dbffc2005-07-01 16:16:00 +0000776 char *process_name = get_process_name();
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000777
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000778 wine_tsx11_lock();
779
780 /* wm protocols */
781 i = 0;
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000782 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
783 protocols[i++] = x11drv_atom(_NET_WM_PING);
784 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
785 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
Hans Leidekkerac147fe2005-03-22 21:17:34 +0000786 XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000787
788 /* class hints */
789 if ((class_hints = XAllocClassHint()))
790 {
Andrew Talbot55e20a72006-06-26 20:56:16 +0100791 static char wine[] = "Wine";
792
Alexandre Julliardc7dbffc2005-07-01 16:16:00 +0000793 class_hints->res_name = process_name;
Andrew Talbot55e20a72006-06-26 20:56:16 +0100794 class_hints->res_class = wine;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000795 XSetClassHint( display, data->whole_window, class_hints );
796 XFree( class_hints );
797 }
798
Mike Hearn34dd4552003-05-04 02:27:20 +0000799 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
800 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
801 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
802 i = getpid();
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000803 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
Hans Leidekkerac147fe2005-03-22 21:17:34 +0000804 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
Ove Kaaven77e7fd72002-01-21 18:41:27 +0000805
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200806 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
807 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
808
Alexandre Julliarddc07b6f2008-01-22 10:17:52 +0100809 data->wm_hints = XAllocWMHints();
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200810 wine_tsx11_unlock();
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100811
812 if (data->wm_hints)
813 {
Alexandre Julliarde929e3b2008-01-23 16:40:54 +0100814 HICON icon = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 );
815 if (!icon) icon = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON );
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100816 data->wm_hints->flags = 0;
Alexandre Julliarde929e3b2008-01-23 16:40:54 +0100817 set_icon_hints( display, data, icon );
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100818 }
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200819}
820
821
822/***********************************************************************
823 * X11DRV_set_wm_hints
824 *
825 * Set the window manager hints for a newly-created window
826 */
827void X11DRV_set_wm_hints( Display *display, struct x11drv_win_data *data )
828{
829 Window group_leader;
830 Atom window_type;
831 MwmHints mwm_hints;
Alexandre Julliard18f4fb92008-04-14 13:27:38 +0200832 DWORD style, ex_style;
833 HWND owner;
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200834
835 if (data->hwnd == GetDesktopWindow())
836 {
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200837 /* force some styles for the desktop to get the correct decorations */
Alexandre Julliard18f4fb92008-04-14 13:27:38 +0200838 style = WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
839 ex_style = WS_EX_APPWINDOW;
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200840 owner = 0;
841 }
Alexandre Julliard18f4fb92008-04-14 13:27:38 +0200842 else
843 {
844 style = GetWindowLongW( data->hwnd, GWL_STYLE );
845 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
846 owner = GetWindow( data->hwnd, GW_OWNER );
847 }
Alexandre Julliard7d9739e2007-08-20 14:04:36 +0200848
849 /* transient for hint */
850 if (owner)
851 {
852 Window owner_win = X11DRV_get_whole_window( owner );
853 wine_tsx11_lock();
854 XSetTransientForHint( display, data->whole_window, owner_win );
855 wine_tsx11_unlock();
856 group_leader = owner_win;
857 }
858 else group_leader = data->whole_window;
859
860 wine_tsx11_lock();
861
862 /* size hints */
863 set_size_hints( display, data, style );
864
Nickolay V. Shmyrev1a1b9022006-10-11 19:32:22 +0400865 /* set the WM_WINDOW_TYPE */
Dmitry Timoshkov751a71a2008-04-07 13:37:44 +0900866 if (style & WS_THICKFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
Alexandre Julliard9bf9c0b2008-04-14 13:27:19 +0200867 else if (ex_style & WS_EX_APPWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
Nickolay V. Shmyrev1a1b9022006-10-11 19:32:22 +0400868 else if (style & WS_DLGFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
869 else if (ex_style & WS_EX_DLGMODALFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
Dmitry Timoshkov1bf824e2008-04-07 22:17:47 +0900870#if 0 /* many window managers don't handle utility windows very well */
Dmitry Timoshkov751a71a2008-04-07 13:37:44 +0900871 else if (ex_style & WS_EX_TOOLWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
Dmitry Timoshkov1bf824e2008-04-07 22:17:47 +0900872#endif
Alexandre Julliard9bf9c0b2008-04-14 13:27:19 +0200873 else window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
Nickolay V. Shmyrev1a1b9022006-10-11 19:32:22 +0400874
875 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
876 XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1);
Mike Hearn27d972f2003-12-04 21:54:13 +0000877
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000878 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
Dmitry Timoshkov15c0bcb2008-04-16 16:50:29 +0900879 mwm_hints.decorations = get_mwm_decorations( data, style, ex_style );
Dmitry Timoshkovac387bb2006-10-05 23:16:36 +0900880 mwm_hints.functions = MWM_FUNC_MOVE;
Alexandre Julliard4d14adf2008-04-04 11:25:48 +0200881 if (is_window_resizable( data, style )) mwm_hints.functions |= MWM_FUNC_RESIZE;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +0000882 if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
883 if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
Alexandre Julliard74cd76c2007-08-29 12:02:57 +0200884 if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
Alexandre Julliardd09c3282003-11-20 04:24:18 +0000885
886 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
887 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
Hans Leidekkerac147fe2005-03-22 21:17:34 +0000888 (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000889
Alexandre Julliard704d0352001-07-12 02:49:31 +0000890 /* wm hints */
Alexandre Julliardbde89572007-08-16 23:27:37 +0200891 if (data->wm_hints)
Alexandre Julliard704d0352001-07-12 02:49:31 +0000892 {
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100893 data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint;
Alexandre Julliardbde89572007-08-16 23:27:37 +0200894 data->wm_hints->input = !(style & WS_DISABLED);
895 data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
896 data->wm_hints->window_group = group_leader;
Alexandre Julliardbde89572007-08-16 23:27:37 +0200897 XSetWMHints( display, data->whole_window, data->wm_hints );
Alexandre Julliard704d0352001-07-12 02:49:31 +0000898 }
Alexandre Julliard6a23bd82008-01-18 14:34:57 +0100899
900 wine_tsx11_unlock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000901}
902
903
904/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000905 * X11DRV_window_to_X_rect
906 *
907 * Convert a rect from client to X window coordinates
908 */
Alexandre Julliardd7726c32005-02-01 18:53:59 +0000909void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000910{
Alexandre Julliard8cd1f712001-07-20 18:37:37 +0000911 RECT rc;
912
Alexandre Julliardd7726c32005-02-01 18:53:59 +0000913 if (!data->managed) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000914 if (IsRectEmpty( rect )) return;
915
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200916 get_x11_rect_offset( data, &rc );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000917
Alexandre Julliard8cd1f712001-07-20 18:37:37 +0000918 rect->left -= rc.left;
919 rect->right -= rc.right;
920 rect->top -= rc.top;
921 rect->bottom -= rc.bottom;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000922 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
923 if (rect->left >= rect->right) rect->right = rect->left + 1;
924}
925
926
927/***********************************************************************
928 * X11DRV_X_to_window_rect
929 *
930 * Opposite of X11DRV_window_to_X_rect
931 */
Alexandre Julliardd7726c32005-02-01 18:53:59 +0000932void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000933{
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200934 RECT rc;
Alexandre Julliard74cd76c2007-08-29 12:02:57 +0200935
Alexandre Julliardd7726c32005-02-01 18:53:59 +0000936 if (!data->managed) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000937 if (IsRectEmpty( rect )) return;
938
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200939 get_x11_rect_offset( data, &rc );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000940
Alexandre Julliardc4e20e72007-10-11 12:24:27 +0200941 rect->left += rc.left;
942 rect->right += rc.right;
943 rect->top += rc.top;
944 rect->bottom += rc.bottom;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000945 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
946 if (rect->left >= rect->right) rect->right = rect->left + 1;
947}
948
949
950/***********************************************************************
Alexandre Julliardf777d702005-01-31 16:34:07 +0000951 * X11DRV_sync_window_position
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000952 *
Alexandre Julliardf777d702005-01-31 16:34:07 +0000953 * Synchronize the X window position with the Windows one
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000954 */
Alexandre Julliardf777d702005-01-31 16:34:07 +0000955void X11DRV_sync_window_position( Display *display, struct x11drv_win_data *data,
Alexandre Julliardbbfbe242008-01-23 12:28:01 +0100956 UINT swp_flags, const RECT *old_client_rect,
957 const RECT *old_whole_rect )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000958{
Alexandre Julliardcef3bc62008-04-04 11:20:45 +0200959 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000960 XWindowChanges changes;
Alexandre Julliardcef3bc62008-04-04 11:20:45 +0200961 int mask = CWWidth | CWHeight;
962
963 if (data->managed && data->iconic) return;
964
965 if ((changes.width = data->whole_rect.right - data->whole_rect.left) <= 0) changes.width = 1;
966 if ((changes.height = data->whole_rect.bottom - data->whole_rect.top) <= 0) changes.height = 1;
967
968 /* only the size is allowed to change for the desktop window */
969 if (data->whole_window != root_window)
970 {
971 changes.x = data->whole_rect.left - virtual_screen_rect.left;
972 changes.y = data->whole_rect.top - virtual_screen_rect.top;
973 mask |= CWX | CWY;
974 }
Alexandre Julliardf777d702005-01-31 16:34:07 +0000975
976 if (!(swp_flags & SWP_NOZORDER))
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000977 {
Alexandre Julliardf777d702005-01-31 16:34:07 +0000978 /* find window that this one must be after */
979 HWND prev = GetWindow( data->hwnd, GW_HWNDPREV );
980 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
981 prev = GetWindow( prev, GW_HWNDPREV );
982 if (!prev) /* top child */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000983 {
Alexandre Julliardf777d702005-01-31 16:34:07 +0000984 changes.stack_mode = Above;
985 mask |= CWStackMode;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000986 }
Alexandre Julliard5787c122008-03-24 15:47:28 +0100987 /* should use stack_mode Below but most window managers don't get it right */
988 /* and Above with a sibling doesn't work so well either, so we ignore it */
Alexandre Julliarddc4fe772001-06-04 21:55:17 +0000989 }
990
Alexandre Julliardcef3bc62008-04-04 11:20:45 +0200991 TRACE( "setting win %p/%lx pos %d,%d,%dx%d after %lx changes=%x\n",
992 data->hwnd, data->whole_window, data->whole_rect.left, data->whole_rect.top,
993 data->whole_rect.right - data->whole_rect.left,
994 data->whole_rect.bottom - data->whole_rect.top, changes.sibling, mask );
Alexandre Julliardc19af912008-01-17 19:53:59 +0100995
Alexandre Julliardcef3bc62008-04-04 11:20:45 +0200996 wine_tsx11_lock();
997 set_size_hints( display, data, style );
998 XReconfigureWMWindow( display, data->whole_window,
999 DefaultScreen(display), mask, &changes );
1000 wine_tsx11_unlock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001001}
1002
1003
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001004/***********************************************************************
1005 * X11DRV_sync_client_position
1006 *
1007 * Synchronize the X client window position with the Windows one
1008 */
1009void X11DRV_sync_client_position( Display *display, struct x11drv_win_data *data,
1010 UINT swp_flags, const RECT *old_client_rect,
1011 const RECT *old_whole_rect )
1012{
1013 int mask;
1014 XWindowChanges changes;
1015 RECT old = *old_client_rect;
1016 RECT new = data->client_rect;
1017
1018 OffsetRect( &old, -old_whole_rect->left, -old_whole_rect->top );
1019 OffsetRect( &new, -data->whole_rect.left, -data->whole_rect.top );
1020 if (!(mask = get_window_changes( &changes, &old, &new ))) return;
1021
1022 if (data->client_window)
1023 {
1024 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1025 data->client_window, new.left, new.top,
1026 new.right - new.left, new.bottom - new.top, mask );
1027 wine_tsx11_lock();
1028 XConfigureWindow( display, data->client_window, mask, &changes );
1029 wine_tsx11_unlock();
1030 }
1031
1032 if (data->gl_drawable && (mask & (CWWidth|CWHeight))) sync_gl_drawable( display, data );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001033}
1034
1035
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001036/**********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001037 * create_whole_window
1038 *
1039 * Create the whole X window for a given window
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001040 */
Alexandre Julliardd147e022008-01-23 21:39:32 +01001041static Window create_whole_window( Display *display, struct x11drv_win_data *data )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001042{
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001043 int cx, cy, mask;
1044 XSetWindowAttributes attr;
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001045 WCHAR text[1024];
Alexandre Julliard395928d2008-01-23 16:30:18 +01001046 HRGN hrgn;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001047
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001048 if (!(cx = data->window_rect.right - data->window_rect.left)) cx = 1;
1049 if (!(cy = data->window_rect.bottom - data->window_rect.top)) cy = 1;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001050
Alexandre Julliarde6dfbcb2008-01-25 12:07:11 +01001051 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1052 {
1053 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1054 data->managed = TRUE;
1055 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1056 }
1057
Alexandre Julliard6bb18e22006-03-27 15:33:43 +02001058 mask = get_window_attributes( display, data, &attr );
Alexandre Julliard883cff42001-06-12 04:02:10 +00001059
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001060 wine_tsx11_lock();
1061
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001062 data->whole_rect = data->window_rect;
Alexandre Julliarda06aeab2006-10-26 12:53:59 +02001063 data->whole_window = XCreateWindow( display, root_window,
Alexandre Julliardac98e0c2007-08-20 22:06:33 +02001064 data->window_rect.left - virtual_screen_rect.left,
1065 data->window_rect.top - virtual_screen_rect.top,
Alexandre Julliarda06aeab2006-10-26 12:53:59 +02001066 cx, cy, 0, screen_depth, InputOutput,
1067 visual, mask, &attr );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001068
Alexandre Julliard42ad3452008-02-22 10:40:22 +01001069 if (data->whole_window) XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
1070 wine_tsx11_unlock();
1071
1072 if (!data->whole_window) return 0;
1073
1074 if (!create_client_window( display, data, NULL ))
Alexandre Julliard704d0352001-07-12 02:49:31 +00001075 {
Alexandre Julliard42ad3452008-02-22 10:40:22 +01001076 wine_tsx11_lock();
1077 XDeleteContext( display, data->whole_window, winContext );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001078 XDestroyWindow( display, data->whole_window );
1079 data->whole_window = 0;
1080 wine_tsx11_unlock();
1081 return 0;
1082 }
1083
Alexandre Julliard7d9739e2007-08-20 14:04:36 +02001084 set_initial_wm_hints( display, data );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001085 X11DRV_set_wm_hints( display, data );
1086
Alexandre Julliardaf50ad62005-07-07 17:30:57 +00001087 SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
Alexandre Julliard395928d2008-01-23 16:30:18 +01001088
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001089 /* set the window text */
1090 if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
1091 sync_window_text( display, data->whole_window, text );
1092
Alexandre Julliard395928d2008-01-23 16:30:18 +01001093 /* set the window region */
1094 if ((hrgn = CreateRectRgn( 0, 0, 0, 0 )))
1095 {
1096 if (GetWindowRgn( data->hwnd, hrgn ) != ERROR) sync_window_region( display, data, hrgn );
1097 DeleteObject( hrgn );
1098 }
Alexandre Julliard731d77f2008-04-09 20:24:27 +02001099 wine_tsx11_lock();
1100 XFlush( display ); /* make sure the window exists before we start painting to it */
1101 wine_tsx11_unlock();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001102 return data->whole_window;
1103}
1104
1105
1106/**********************************************************************
Alexandre Julliardf777d702005-01-31 16:34:07 +00001107 * destroy_whole_window
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001108 *
Alexandre Julliardf777d702005-01-31 16:34:07 +00001109 * Destroy the whole X window for a given window.
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001110 */
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001111static void destroy_whole_window( Display *display, struct x11drv_win_data *data, BOOL already_destroyed )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001112{
Alexandre Julliardf777d702005-01-31 16:34:07 +00001113 struct x11drv_thread_data *thread_data = x11drv_thread_data();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001114
Alexandre Julliardf777d702005-01-31 16:34:07 +00001115 if (!data->whole_window) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001116
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001117 TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1118 if (thread_data->cursor_window == data->whole_window ||
1119 thread_data->cursor_window == data->client_window)
1120 thread_data->cursor_window = None;
Alexandre Julliard883cff42001-06-12 04:02:10 +00001121 wine_tsx11_lock();
Alexandre Julliardf777d702005-01-31 16:34:07 +00001122 XDeleteContext( display, data->whole_window, winContext );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001123 XDeleteContext( display, data->client_window, winContext );
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001124 if (!already_destroyed) XDestroyWindow( display, data->whole_window );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001125 data->whole_window = data->client_window = 0;
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001126 data->wm_state = WithdrawnState;
1127 data->net_wm_state = 0;
1128 data->mapped = FALSE;
Alexandre Julliardf777d702005-01-31 16:34:07 +00001129 if (data->xic)
1130 {
1131 XUnsetICFocus( data->xic );
1132 XDestroyIC( data->xic );
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001133 data->xic = 0;
Alexandre Julliardf777d702005-01-31 16:34:07 +00001134 }
Alexandre Julliard975f1b22006-05-09 17:32:40 +02001135 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1136 XFlush( display );
Alexandre Julliarddc07b6f2008-01-22 10:17:52 +01001137 XFree( data->wm_hints );
1138 data->wm_hints = NULL;
Alexandre Julliard883cff42001-06-12 04:02:10 +00001139 wine_tsx11_unlock();
Alexandre Julliardaf50ad62005-07-07 17:30:57 +00001140 RemovePropA( data->hwnd, whole_window_prop );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001141 RemovePropA( data->hwnd, client_window_prop );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001142}
1143
1144
1145/*****************************************************************
1146 * SetWindowText (X11DRV.@)
1147 */
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001148void X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001149{
Alexandre Julliard43230042001-05-16 19:52:29 +00001150 Display *display = thread_display();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001151 Window win;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001152
Alexandre Julliardc44410d2006-03-28 12:21:37 +02001153 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(display))
Alexandre Julliard3ba20252008-01-23 16:32:55 +01001154 sync_window_text( display, win, text );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001155}
1156
1157
1158/***********************************************************************
1159 * DestroyWindow (X11DRV.@)
1160 */
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001161void X11DRV_DestroyWindow( HWND hwnd )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001162{
Alexandre Julliard9428f062002-06-14 00:08:40 +00001163 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1164 Display *display = thread_data->display;
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001165 struct x11drv_win_data *data;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001166
Alexandre Julliard2997fc52005-07-18 13:20:18 +00001167 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001168
Chris Robinson37d835b2007-09-26 08:17:13 -07001169 if (data->pixmap)
1170 {
1171 destroy_glxpixmap(display, data->gl_drawable);
1172 wine_tsx11_lock();
1173 XFreePixmap(display, data->pixmap);
1174 wine_tsx11_unlock();
1175 }
1176 else if (data->gl_drawable)
Chris Robinson00633e32007-09-25 22:43:38 -07001177 {
1178 wine_tsx11_lock();
1179 XDestroyWindow(display, data->gl_drawable);
1180 wine_tsx11_unlock();
1181 }
1182
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001183 destroy_whole_window( display, data, FALSE );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001184 destroy_icon_window( display, data );
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001185
Alexandre Julliarde9307d02008-02-21 20:23:32 +01001186 if (data->colormap)
1187 {
1188 wine_tsx11_lock();
1189 XFreeColormap( display, data->colormap );
1190 wine_tsx11_unlock();
1191 }
1192
Alexandre Julliardf777d702005-01-31 16:34:07 +00001193 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001194 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
1195 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001196 wine_tsx11_lock();
Alexandre Julliarde5515552005-02-09 14:01:40 +00001197 XDeleteContext( display, (XID)hwnd, win_data_context );
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001198 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001199 HeapFree( GetProcessHeap(), 0, data );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001200}
1201
1202
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001203/***********************************************************************
1204 * X11DRV_DestroyNotify
1205 */
1206void X11DRV_DestroyNotify( HWND hwnd, XEvent *event )
1207{
1208 Display *display = event->xdestroywindow.display;
1209 struct x11drv_win_data *data;
1210
1211 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1212
1213 FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window );
1214 destroy_whole_window( display, data, TRUE );
1215}
1216
1217
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001218static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
1219{
1220 struct x11drv_win_data *data;
1221
Alexandre Julliard30d84fc2008-01-22 10:15:38 +01001222 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001223 {
Alexandre Julliard30d84fc2008-01-22 10:15:38 +01001224 data->hwnd = hwnd;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001225 wine_tsx11_lock();
1226 if (!winContext) winContext = XUniqueContext();
1227 if (!win_data_context) win_data_context = XUniqueContext();
1228 XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
1229 wine_tsx11_unlock();
1230 }
1231 return data;
1232}
1233
1234
Alexandre Julliardc19af912008-01-17 19:53:59 +01001235/* initialize the desktop window id in the desktop manager process */
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001236static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd )
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001237{
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001238 struct x11drv_win_data *data;
1239 VisualID visualid;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001240
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001241 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1242 wine_tsx11_lock();
1243 visualid = XVisualIDFromVisual(visual);
1244 wine_tsx11_unlock();
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001245 data->whole_window = data->client_window = root_window;
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001246 data->managed = TRUE;
1247 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1248 SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001249 SetPropA( data->hwnd, client_window_prop, (HANDLE)root_window );
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001250 set_initial_wm_hints( display, data );
1251 return data;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001252}
1253
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001254/**********************************************************************
1255 * CreateDesktopWindow (X11DRV.@)
1256 */
1257BOOL X11DRV_CreateDesktopWindow( HWND hwnd )
1258{
Alexandre Julliardc19af912008-01-17 19:53:59 +01001259 unsigned int width, height;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001260
Alexandre Julliardc19af912008-01-17 19:53:59 +01001261 /* retrieve the real size of the desktop */
1262 SERVER_START_REQ( get_window_rectangles )
1263 {
1264 req->handle = hwnd;
1265 wine_server_call( req );
1266 width = reply->window.right - reply->window.left;
1267 height = reply->window.bottom - reply->window.top;
1268 }
1269 SERVER_END_REQ;
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001270
Alexandre Julliardc19af912008-01-17 19:53:59 +01001271 if (!width && !height) /* not initialized yet */
1272 {
1273 SERVER_START_REQ( set_window_pos )
1274 {
1275 req->handle = hwnd;
1276 req->previous = 0;
1277 req->flags = SWP_NOZORDER;
1278 req->window.left = virtual_screen_rect.left;
1279 req->window.top = virtual_screen_rect.top;
1280 req->window.right = virtual_screen_rect.right;
1281 req->window.bottom = virtual_screen_rect.bottom;
1282 req->client = req->window;
1283 wine_server_call( req );
1284 }
1285 SERVER_END_REQ;
1286 }
1287 else
1288 {
1289 Window win = (Window)GetPropA( hwnd, whole_window_prop );
1290 if (win && win != root_window) X11DRV_init_desktop( win, width, height );
1291 }
Alexandre Julliarde419cb82005-07-07 20:33:29 +00001292 return TRUE;
1293}
1294
1295
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001296/**********************************************************************
1297 * CreateWindow (X11DRV.@)
1298 */
Alexandre Julliardd6f67452008-01-24 11:23:09 +01001299BOOL X11DRV_CreateWindow( HWND hwnd )
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001300{
1301 Display *display = thread_display();
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001302
Alexandre Julliard026974f2008-01-24 10:20:51 +01001303 if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( display ))
Alexandre Julliardb6cc7f92008-01-24 10:20:11 +01001304 {
Alexandre Julliard026974f2008-01-24 10:20:51 +01001305 /* the desktop win data can't be created lazily */
1306 if (!create_desktop_win_data( display, hwnd )) return FALSE;
Alexandre Julliarddb6608a2006-03-27 22:43:03 +02001307 }
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001308 return TRUE;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001309}
1310
1311
1312/***********************************************************************
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001313 * X11DRV_get_win_data
1314 *
1315 * Return the X11 data structure associated with a window.
1316 */
1317struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1318{
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001319 char *data;
Alexandre Julliarde5515552005-02-09 14:01:40 +00001320
1321 if (!hwnd || XFindContext( thread_display(), (XID)hwnd, win_data_context, &data )) data = NULL;
Alexandre Julliardd56ccaa2005-01-28 17:25:50 +00001322 return (struct x11drv_win_data *)data;
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001323}
1324
1325
1326/***********************************************************************
Alexandre Julliard026974f2008-01-24 10:20:51 +01001327 * X11DRV_create_win_data
1328 *
1329 * Create an X11 data window structure for an existing window.
1330 */
1331struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd )
1332{
1333 Display *display = thread_display();
1334 struct x11drv_win_data *data;
1335 HWND parent;
1336
1337 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
1338 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1339
1340 GetWindowRect( hwnd, &data->window_rect );
1341 MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 );
1342 data->whole_rect = data->window_rect;
1343 GetClientRect( hwnd, &data->client_rect );
1344 MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 );
1345
1346 if (parent == GetDesktopWindow())
1347 {
1348 if (!create_whole_window( display, data ))
1349 {
1350 HeapFree( GetProcessHeap(), 0, data );
1351 return NULL;
1352 }
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001353 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1354 hwnd, data->whole_window, data->client_window, wine_dbgstr_rect( &data->window_rect ),
Alexandre Julliard026974f2008-01-24 10:20:51 +01001355 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
1356 }
Alexandre Julliard026974f2008-01-24 10:20:51 +01001357 return data;
1358}
1359
1360
1361/***********************************************************************
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001362 * X11DRV_get_whole_window
1363 *
1364 * Return the X window associated with the full area of a window
1365 */
1366Window X11DRV_get_whole_window( HWND hwnd )
1367{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001368 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001369
Alexandre Julliardc19af912008-01-17 19:53:59 +01001370 if (!data)
1371 {
1372 if (hwnd == GetDesktopWindow()) return root_window;
1373 return (Window)GetPropA( hwnd, whole_window_prop );
1374 }
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001375 return data->whole_window;
Alexandre Julliarddc4fe772001-06-04 21:55:17 +00001376}
1377
1378
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001379/***********************************************************************
Alexandre Julliard8ee07d42008-02-21 12:29:36 +01001380 * X11DRV_get_client_window
1381 *
1382 * Return the X window associated with the client area of a window
1383 */
1384Window X11DRV_get_client_window( HWND hwnd )
1385{
1386 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1387
1388 if (!data)
1389 {
1390 if (hwnd == GetDesktopWindow()) return root_window;
1391 return (Window)GetPropA( hwnd, client_window_prop );
1392 }
1393 return data->client_window;
1394}
1395
1396
1397/***********************************************************************
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001398 * X11DRV_get_ic
1399 *
1400 * Return the X input context associated with a window
1401 */
1402XIC X11DRV_get_ic( HWND hwnd )
1403{
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001404 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Kusanagi Kouichi185157c2008-04-04 20:44:36 +09001405 XIM xim;
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001406
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001407 if (!data) return 0;
Kusanagi Kouichi185157c2008-04-04 20:44:36 +09001408 if (data->xic) return data->xic;
1409 if (!(xim = x11drv_thread_data()->xim)) return 0;
1410 return X11DRV_CreateIC( xim, data );
Alexandre Julliard8b6a2192003-01-23 01:28:12 +00001411}
1412
1413
Alexandre Julliard1642fbc2008-02-25 15:59:19 +01001414/***********************************************************************
1415 * X11DRV_GetDC (X11DRV.@)
1416 */
1417void X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect,
1418 const RECT *top_rect, DWORD flags )
1419{
1420 struct x11drv_escape_set_drawable escape;
1421 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1422
1423 escape.code = X11DRV_SET_DRAWABLE;
1424 escape.mode = IncludeInferiors;
1425 escape.fbconfig_id = 0;
1426 escape.gl_drawable = 0;
1427 escape.pixmap = 0;
1428
1429 if (top == hwnd && data && IsIconic( hwnd ) && data->icon_window)
1430 {
1431 escape.drawable = data->icon_window;
1432 }
1433 else if (top == hwnd && (flags & DCX_WINDOW))
1434 {
1435 escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd );
1436 }
1437 else
1438 {
1439 escape.drawable = X11DRV_get_client_window( top );
1440 escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop );
1441 escape.gl_drawable = data ? data->gl_drawable : (Drawable)GetPropA( hwnd, gl_drawable_prop );
1442 escape.pixmap = data ? data->pixmap : (Pixmap)GetPropA( hwnd, pixmap_prop );
Alexandre Julliardaf369102008-03-18 12:42:25 +01001443 if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren;
Alexandre Julliard1642fbc2008-02-25 15:59:19 +01001444 }
1445
1446 escape.dc_rect.left = win_rect->left - top_rect->left;
1447 escape.dc_rect.top = win_rect->top - top_rect->top;
1448 escape.dc_rect.right = win_rect->right - top_rect->left;
1449 escape.dc_rect.bottom = win_rect->bottom - top_rect->top;
1450 escape.drawable_rect.left = top_rect->left;
1451 escape.drawable_rect.top = top_rect->top;
1452 escape.drawable_rect.right = top_rect->right;
1453 escape.drawable_rect.bottom = top_rect->bottom;
1454
1455 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1456}
1457
1458
1459/***********************************************************************
1460 * X11DRV_ReleaseDC (X11DRV.@)
1461 */
1462void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
1463{
1464 struct x11drv_escape_set_drawable escape;
1465
1466 escape.code = X11DRV_SET_DRAWABLE;
1467 escape.drawable = root_window;
1468 escape.mode = IncludeInferiors;
1469 escape.drawable_rect = virtual_screen_rect;
1470 SetRect( &escape.dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left,
1471 virtual_screen_rect.bottom - virtual_screen_rect.top );
1472 escape.fbconfig_id = 0;
1473 escape.gl_drawable = 0;
1474 escape.pixmap = 0;
1475 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1476}
1477
1478
Alexandre Julliarddc26f272008-03-12 15:01:24 +01001479/***********************************************************************
1480 * SetCapture (X11DRV.@)
1481 */
1482void X11DRV_SetCapture( HWND hwnd, UINT flags )
1483{
1484 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1485
Alexandre Julliard78de7e32008-03-24 17:59:40 +01001486 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
Alexandre Julliarddc26f272008-03-12 15:01:24 +01001487
1488 if (hwnd)
1489 {
1490 Window grab_win = X11DRV_get_client_window( GetAncestor( hwnd, GA_ROOT ) );
1491
1492 if (!grab_win) return;
1493 wine_tsx11_lock();
1494 XFlush( gdi_display );
1495 XGrabPointer( thread_data->display, grab_win, False,
1496 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
Alexandre Julliard78de7e32008-03-24 17:59:40 +01001497 GrabModeAsync, GrabModeAsync, None, None, CurrentTime );
Alexandre Julliarddc26f272008-03-12 15:01:24 +01001498 wine_tsx11_unlock();
1499 thread_data->grab_window = grab_win;
1500 }
1501 else /* release capture */
1502 {
1503 wine_tsx11_lock();
1504 XFlush( gdi_display );
1505 XUngrabPointer( thread_data->display, CurrentTime );
1506 wine_tsx11_unlock();
1507 thread_data->grab_window = None;
1508 }
1509}
1510
1511
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001512/*****************************************************************
1513 * SetParent (X11DRV.@)
1514 */
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001515void X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001516{
Alexandre Julliard43230042001-05-16 19:52:29 +00001517 Display *display = thread_display();
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001518 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001519
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001520 if (!data) return;
1521 if (parent == old_parent) return;
Alexandre Julliardfb0ff052001-10-16 21:58:58 +00001522
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001523 if (parent != GetDesktopWindow()) /* a child window */
Alexandre Julliard4d32a472005-03-25 10:38:56 +00001524 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001525 if (old_parent == GetDesktopWindow())
Alexandre Julliard4d32a472005-03-25 10:38:56 +00001526 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001527 /* destroy the old X windows */
Alexandre Julliard3b6f95c2008-03-05 16:51:09 +01001528 destroy_whole_window( display, data, FALSE );
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001529 destroy_icon_window( display, data );
1530 if (data->managed)
Alexandre Julliardf777d702005-01-31 16:34:07 +00001531 {
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001532 data->managed = FALSE;
1533 RemovePropA( data->hwnd, managed_prop );
Alexandre Julliardf777d702005-01-31 16:34:07 +00001534 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001535 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001536 }
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001537 else /* new top level window */
1538 {
1539 /* FIXME: we ignore errors since we can't really recover anyway */
Alexandre Julliardd147e022008-01-23 21:39:32 +01001540 create_whole_window( display, data );
Pierre d'Herbemont221b0442006-12-10 23:21:28 +01001541 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001542}
1543
1544
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001545/*****************************************************************
1546 * SetFocus (X11DRV.@)
1547 *
1548 * Set the X focus.
1549 * Explicit colormap management seems to work only with OLVWM.
1550 */
1551void X11DRV_SetFocus( HWND hwnd )
1552{
Alexandre Julliard43230042001-05-16 19:52:29 +00001553 Display *display = thread_display();
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001554 struct x11drv_win_data *data;
Alexandre Julliard125793d2008-02-18 17:22:51 +01001555 XWindowChanges changes;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001556
Alexandre Julliard125793d2008-02-18 17:22:51 +01001557 /* If setting the focus to 0, uninstall the colormap */
1558 if (!hwnd && root_window == DefaultRootWindow(display))
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001559 {
Alexandre Julliard2496c082003-11-21 00:17:33 +00001560 wine_tsx11_lock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001561 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
Alexandre Julliard2496c082003-11-21 00:17:33 +00001562 XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
1563 wine_tsx11_unlock();
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001564 return;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001565 }
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001566
1567 hwnd = GetAncestor( hwnd, GA_ROOT );
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001568
1569 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Todd Mokros88ac4b92005-08-22 09:14:21 +00001570 if (data->managed || !data->whole_window) return;
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001571
1572 /* Set X focus and install colormap */
1573 wine_tsx11_lock();
Alexandre Julliard125793d2008-02-18 17:22:51 +01001574 changes.stack_mode = Above;
1575 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
1576 if (root_window == DefaultRootWindow(display))
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001577 {
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001578 /* we must not use CurrentTime (ICCCM), so try to use last message time instead */
1579 /* FIXME: this is not entirely correct */
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001580 XSetInputFocus( display, data->whole_window, RevertToParent,
Jeremy White77502e72005-01-14 17:06:40 +00001581 /* CurrentTime */
1582 GetMessageTime() - EVENT_x11_time_to_win32_time(0));
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001583 if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
1584 XInstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001585 }
Alexandre Julliard0801ffc2001-08-24 00:26:59 +00001586 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001587}
1588
1589
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001590/**********************************************************************
Patrik Stridvall01d5e5b2001-07-02 19:59:40 +00001591 * SetWindowIcon (X11DRV.@)
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001592 *
1593 * hIcon or hIconSm has changed (or is being initialised for the
1594 * first time). Complete the X11 driver-specific initialisation
1595 * and set the window hints.
1596 *
1597 * This is not entirely correct, may need to create
1598 * an icon window and set the pixmap as a background
1599 */
Alexandre Julliard446d8322003-12-31 23:51:52 +00001600void X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001601{
Alexandre Julliard43230042001-05-16 19:52:29 +00001602 Display *display = thread_display();
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001603 struct x11drv_win_data *data;
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001604
Alexandre Julliard446d8322003-12-31 23:51:52 +00001605 if (type != ICON_BIG) return; /* nothing to do here */
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001606
Alexandre Julliardfc5ce142005-01-17 19:17:47 +00001607 if (!(data = X11DRV_get_win_data( hwnd ))) return;
Alexandre Julliardf777d702005-01-31 16:34:07 +00001608 if (!data->whole_window) return;
Alexandre Julliardd7726c32005-02-01 18:53:59 +00001609 if (!data->managed) return;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001610
Alexandre Julliardbde89572007-08-16 23:27:37 +02001611 if (data->wm_hints)
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001612 {
Alexandre Julliardbde89572007-08-16 23:27:37 +02001613 set_icon_hints( display, data, icon );
Alexandre Julliarde9119c12002-09-24 18:36:51 +00001614 wine_tsx11_lock();
Alexandre Julliardbde89572007-08-16 23:27:37 +02001615 XSetWMHints( display, data->whole_window, data->wm_hints );
Alexandre Julliarde9119c12002-09-24 18:36:51 +00001616 wine_tsx11_unlock();
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001617 }
Alexandre Julliard9ae0fe52001-04-24 23:28:52 +00001618}
Alexandre Julliard395928d2008-01-23 16:30:18 +01001619
1620
1621/***********************************************************************
1622 * SetWindowRgn (X11DRV.@)
1623 *
1624 * Assign specified region to window (for non-rectangular windows)
1625 */
1626int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1627{
1628 struct x11drv_win_data *data;
1629
1630 if ((data = X11DRV_get_win_data( hwnd )))
1631 {
1632 sync_window_region( thread_display(), data, hrgn );
Alexandre Julliard395928d2008-01-23 16:30:18 +01001633 }
1634 else if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
1635 {
1636 FIXME( "not supported on other thread window %p\n", hwnd );
1637 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1638 return FALSE;
1639 }
1640
1641 return TRUE;
1642}