winex11: Make the cursor window global instead of per-thread, and send it a message...
[wine/multimedia.git] / dlls / winex11.drv / window.c
blob8cd3bf34560eb04289c1023e763da1c0a5352085
1 /*
2 * Window related functions
4 * Copyright 1993, 1994, 1995, 1996, 2001 Alexandre Julliard
5 * Copyright 1993 David Metcalfe
6 * Copyright 1995, 1996 Alex Korobka
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.
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.
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
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
25 #include <stdarg.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #ifdef HAVE_UNISTD_H
29 # include <unistd.h>
30 #endif
32 #include <X11/Xlib.h>
33 #include <X11/Xresource.h>
34 #include <X11/Xutil.h>
35 #ifdef HAVE_LIBXSHAPE
36 #include <X11/extensions/shape.h>
37 #endif /* HAVE_LIBXSHAPE */
39 #include "windef.h"
40 #include "winbase.h"
41 #include "wingdi.h"
42 #include "winuser.h"
43 #include "wine/unicode.h"
45 #include "x11drv.h"
46 #include "xcomposite.h"
47 #include "wine/debug.h"
48 #include "wine/server.h"
49 #include "mwm.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
53 #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
65 #define _NET_WM_STATE_REMOVE 0
66 #define _NET_WM_STATE_ADD 1
67 #define _NET_WM_STATE_TOGGLE 2
69 #define SWP_AGG_NOPOSCHANGE (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
71 /* X context to associate a hwnd to an X window */
72 XContext winContext = 0;
74 /* X context to associate a struct x11drv_win_data to an hwnd */
75 static XContext win_data_context;
77 static const char whole_window_prop[] = "__wine_x11_whole_window";
78 static const char client_window_prop[]= "__wine_x11_client_window";
79 static const char icon_window_prop[] = "__wine_x11_icon_window";
80 static const char fbconfig_id_prop[] = "__wine_x11_fbconfig_id";
81 static const char gl_drawable_prop[] = "__wine_x11_gl_drawable";
82 static const char pixmap_prop[] = "__wine_x11_pixmap";
83 static const char managed_prop[] = "__wine_x11_managed";
86 /***********************************************************************
87 * http://standards.freedesktop.org/startup-notification-spec
89 static void remove_startup_notification(Display *display, Window window)
91 static LONG startup_notification_removed = 0;
92 char id[1024];
93 char message[1024];
94 int i;
95 int pos;
96 XEvent xevent;
97 const char *src;
98 int srclen;
100 if (InterlockedCompareExchange(&startup_notification_removed, 1, 0) != 0)
101 return;
103 if (GetEnvironmentVariableA("DESKTOP_STARTUP_ID", id, sizeof(id)) == 0)
104 return;
105 SetEnvironmentVariableA("DESKTOP_STARTUP_ID", NULL);
107 pos = snprintf(message, sizeof(message), "remove: ID=");
108 message[pos++] = '"';
109 for (i = 0; id[i] && pos < sizeof(message) - 2; i++)
111 if (id[i] == '"' || id[i] == '\\')
112 message[pos++] = '\\';
113 message[pos++] = id[i];
115 message[pos++] = '"';
116 message[pos++] = '\0';
118 xevent.xclient.type = ClientMessage;
119 xevent.xclient.message_type = x11drv_atom(_NET_STARTUP_INFO_BEGIN);
120 xevent.xclient.display = display;
121 xevent.xclient.window = window;
122 xevent.xclient.format = 8;
124 src = message;
125 srclen = strlen(src) + 1;
127 wine_tsx11_lock();
128 while (srclen > 0)
130 int msglen = srclen;
131 if (msglen > 20)
132 msglen = 20;
133 memset(&xevent.xclient.data.b[0], 0, 20);
134 memcpy(&xevent.xclient.data.b[0], src, msglen);
135 src += msglen;
136 srclen -= msglen;
138 XSendEvent( display, DefaultRootWindow( display ), False, PropertyChangeMask, &xevent );
139 xevent.xclient.message_type = x11drv_atom(_NET_STARTUP_INFO);
141 wine_tsx11_unlock();
145 struct has_popup_result
147 HWND hwnd;
148 BOOL found;
151 static BOOL CALLBACK has_popup( HWND hwnd, LPARAM lparam )
153 struct has_popup_result *result = (struct has_popup_result *)lparam;
155 if (hwnd == result->hwnd) return FALSE; /* popups are always above owner */
156 result->found = (GetWindow( hwnd, GW_OWNER ) == result->hwnd);
157 return !result->found;
160 static BOOL has_owned_popups( HWND hwnd )
162 struct has_popup_result result;
164 result.hwnd = hwnd;
165 result.found = FALSE;
166 EnumWindows( has_popup, (LPARAM)&result );
167 return result.found;
170 /***********************************************************************
171 * is_window_managed
173 * Check if a given window should be managed
175 static BOOL is_window_managed( HWND hwnd, UINT swp_flags, const RECT *window_rect )
177 DWORD style, ex_style;
179 if (!managed_mode) return FALSE;
181 /* child windows are not managed */
182 style = GetWindowLongW( hwnd, GWL_STYLE );
183 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD) return FALSE;
184 /* activated windows are managed */
185 if (!(swp_flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) return TRUE;
186 if (hwnd == GetActiveWindow()) return TRUE;
187 /* windows with caption are managed */
188 if ((style & WS_CAPTION) == WS_CAPTION) return TRUE;
189 /* windows with thick frame are managed */
190 if (style & WS_THICKFRAME) return TRUE;
191 if (style & WS_POPUP)
193 HMONITOR hmon;
194 MONITORINFO mi;
196 /* popup with sysmenu == caption are managed */
197 if (style & WS_SYSMENU) return TRUE;
198 /* full-screen popup windows are managed */
199 hmon = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY );
200 mi.cbSize = sizeof( mi );
201 GetMonitorInfoW( hmon, &mi );
202 if (window_rect->left <= mi.rcWork.left && window_rect->right >= mi.rcWork.right &&
203 window_rect->top <= mi.rcWork.top && window_rect->bottom >= mi.rcWork.bottom)
204 return TRUE;
206 /* application windows are managed */
207 ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE );
208 if (ex_style & WS_EX_APPWINDOW) return TRUE;
209 /* windows that own popups are managed */
210 if (has_owned_popups( hwnd )) return TRUE;
211 /* default: not managed */
212 return FALSE;
216 /***********************************************************************
217 * X11DRV_is_window_rect_mapped
219 * Check if the X whole window should be mapped based on its rectangle
221 static BOOL is_window_rect_mapped( const RECT *rect )
223 /* don't map if rect is empty */
224 if (IsRectEmpty( rect )) return FALSE;
226 /* don't map if rect is off-screen */
227 if (rect->left >= virtual_screen_rect.right ||
228 rect->top >= virtual_screen_rect.bottom ||
229 rect->right <= virtual_screen_rect.left ||
230 rect->bottom <= virtual_screen_rect.top)
231 return FALSE;
233 return TRUE;
237 /***********************************************************************
238 * is_window_resizable
240 * Check if window should be made resizable by the window manager
242 static inline BOOL is_window_resizable( struct x11drv_win_data *data, DWORD style )
244 if (style & WS_THICKFRAME) return TRUE;
245 /* Metacity needs the window to be resizable to make it fullscreen */
246 return (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width &&
247 data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height);
251 /***********************************************************************
252 * get_window_owner
254 static HWND get_window_owner( HWND hwnd )
256 RECT rect;
257 HWND owner = GetWindow( hwnd, GW_OWNER );
258 /* ignore the zero-size owners used by Delphi apps */
259 if (owner && GetWindowRect( owner, &rect ) && IsRectEmpty( &rect )) owner = 0;
260 return owner;
264 /***********************************************************************
265 * get_mwm_decorations
267 static unsigned long get_mwm_decorations( struct x11drv_win_data *data,
268 DWORD style, DWORD ex_style )
270 unsigned long ret = 0;
272 if (!decorated_mode) return 0;
274 if (IsRectEmpty( &data->window_rect )) return 0;
275 if (data->shaped) return 0;
277 if (ex_style & WS_EX_TOOLWINDOW) return 0;
279 if ((style & WS_CAPTION) == WS_CAPTION)
281 ret |= MWM_DECOR_TITLE | MWM_DECOR_BORDER;
282 if (style & WS_SYSMENU) ret |= MWM_DECOR_MENU;
283 if (style & WS_MINIMIZEBOX) ret |= MWM_DECOR_MINIMIZE;
284 if (style & WS_MAXIMIZEBOX) ret |= MWM_DECOR_MAXIMIZE;
286 if (ex_style & WS_EX_DLGMODALFRAME) ret |= MWM_DECOR_BORDER;
287 else if (style & WS_THICKFRAME) ret |= MWM_DECOR_BORDER | MWM_DECOR_RESIZEH;
288 else if ((style & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME) ret |= MWM_DECOR_BORDER;
289 return ret;
293 /***********************************************************************
294 * get_x11_rect_offset
296 * Helper for X11DRV_window_to_X_rect and X11DRV_X_to_window_rect.
298 static void get_x11_rect_offset( struct x11drv_win_data *data, RECT *rect )
300 DWORD style, ex_style, style_mask = 0, ex_style_mask = 0;
301 unsigned long decor;
303 rect->top = rect->bottom = rect->left = rect->right = 0;
305 style = GetWindowLongW( data->hwnd, GWL_STYLE );
306 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
307 decor = get_mwm_decorations( data, style, ex_style );
309 if (decor & MWM_DECOR_TITLE) style_mask |= WS_CAPTION;
310 if (decor & MWM_DECOR_BORDER)
312 style_mask |= WS_DLGFRAME | WS_THICKFRAME;
313 ex_style_mask |= WS_EX_DLGMODALFRAME;
316 AdjustWindowRectEx( rect, style & style_mask, FALSE, ex_style & ex_style_mask );
320 /***********************************************************************
321 * get_window_attributes
323 * Fill the window attributes structure for an X window.
325 static int get_window_attributes( Display *display, struct x11drv_win_data *data,
326 XSetWindowAttributes *attr )
328 attr->override_redirect = !data->managed;
329 attr->colormap = X11DRV_PALETTE_PaletteXColormap;
330 attr->save_under = ((GetClassLongW( data->hwnd, GCL_STYLE ) & CS_SAVEBITS) != 0);
331 attr->bit_gravity = NorthWestGravity;
332 attr->win_gravity = StaticGravity;
333 attr->backing_store = NotUseful;
334 attr->event_mask = (ExposureMask | PointerMotionMask |
335 ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
336 KeyPressMask | KeyReleaseMask | FocusChangeMask |
337 KeymapStateMask | StructureNotifyMask);
338 if (data->managed) attr->event_mask |= PropertyChangeMask;
340 return (CWOverrideRedirect | CWSaveUnder | CWColormap |
341 CWEventMask | CWBitGravity | CWBackingStore);
345 /***********************************************************************
346 * create_client_window
348 static Window create_client_window( Display *display, struct x11drv_win_data *data, XVisualInfo *vis )
350 int cx, cy, mask;
351 XSetWindowAttributes attr;
352 Window client;
353 Visual *client_visual = vis ? vis->visual : visual;
355 attr.bit_gravity = NorthWestGravity;
356 attr.win_gravity = NorthWestGravity;
357 attr.backing_store = NotUseful;
358 attr.event_mask = (ExposureMask | PointerMotionMask |
359 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
360 mask = CWEventMask | CWBitGravity | CWWinGravity | CWBackingStore;
362 if ((cx = data->client_rect.right - data->client_rect.left) <= 0) cx = 1;
363 else if (cx > 65535) cx = 65535;
364 if ((cy = data->client_rect.bottom - data->client_rect.top) <= 0) cy = 1;
365 else if (cy > 65535) cy = 65535;
367 wine_tsx11_lock();
369 if (vis)
371 attr.colormap = XCreateColormap( display, root_window, vis->visual,
372 (vis->class == PseudoColor || vis->class == GrayScale ||
373 vis->class == DirectColor) ? AllocAll : AllocNone );
374 mask |= CWColormap;
377 client = XCreateWindow( display, data->whole_window,
378 data->client_rect.left - data->whole_rect.left,
379 data->client_rect.top - data->whole_rect.top,
380 cx, cy, 0, screen_depth, InputOutput,
381 client_visual, mask, &attr );
382 if (!client)
384 wine_tsx11_unlock();
385 return 0;
388 if (data->client_window)
390 XDeleteContext( display, data->client_window, winContext );
391 XDestroyWindow( display, data->client_window );
393 data->client_window = client;
394 data->visualid = XVisualIDFromVisual( client_visual );
396 if (data->colormap) XFreeColormap( display, data->colormap );
397 data->colormap = vis ? attr.colormap : 0;
399 XMapWindow( display, data->client_window );
400 XSaveContext( display, data->client_window, winContext, (char *)data->hwnd );
401 wine_tsx11_unlock();
403 SetPropA( data->hwnd, client_window_prop, (HANDLE)data->client_window );
404 return data->client_window;
408 /***********************************************************************
409 * sync_window_style
411 * Change the X window attributes when the window style has changed.
413 static void sync_window_style( Display *display, struct x11drv_win_data *data )
415 if (data->whole_window != root_window)
417 XSetWindowAttributes attr;
418 int mask = get_window_attributes( display, data, &attr );
420 wine_tsx11_lock();
421 XChangeWindowAttributes( display, data->whole_window, mask, &attr );
422 wine_tsx11_unlock();
427 /***********************************************************************
428 * sync_window_region
430 * Update the X11 window region.
432 static void sync_window_region( Display *display, struct x11drv_win_data *data, HRGN win_region )
434 #ifdef HAVE_LIBXSHAPE
435 HRGN hrgn = win_region;
437 if (!data->whole_window) return;
438 data->shaped = FALSE;
440 if (hrgn == (HRGN)1) /* hack: win_region == 1 means retrieve region from server */
442 if (!(hrgn = CreateRectRgn( 0, 0, 0, 0 ))) return;
443 if (GetWindowRgn( data->hwnd, hrgn ) == ERROR)
445 DeleteObject( hrgn );
446 hrgn = 0;
450 if (!hrgn)
452 wine_tsx11_lock();
453 XShapeCombineMask( display, data->whole_window, ShapeBounding, 0, 0, None, ShapeSet );
454 wine_tsx11_unlock();
456 else
458 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
459 if (pRegionData)
461 wine_tsx11_lock();
462 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
463 data->window_rect.left - data->whole_rect.left,
464 data->window_rect.top - data->whole_rect.top,
465 (XRectangle *)pRegionData->Buffer,
466 pRegionData->rdh.nCount, ShapeSet, YXBanded );
467 wine_tsx11_unlock();
468 HeapFree(GetProcessHeap(), 0, pRegionData);
469 data->shaped = TRUE;
472 if (hrgn && hrgn != win_region) DeleteObject( hrgn );
473 #endif /* HAVE_LIBXSHAPE */
477 /***********************************************************************
478 * sync_window_opacity
480 static void sync_window_opacity( Display *display, Window win,
481 COLORREF key, BYTE alpha, DWORD flags )
483 unsigned long opacity = 0xffffffff;
485 if (flags & LWA_ALPHA) opacity = (0xffffffff / 0xff) * alpha;
487 if (flags & LWA_COLORKEY) FIXME("LWA_COLORKEY not supported\n");
489 wine_tsx11_lock();
490 if (opacity == 0xffffffff)
491 XDeleteProperty( display, win, x11drv_atom(_NET_WM_WINDOW_OPACITY) );
492 else
493 XChangeProperty( display, win, x11drv_atom(_NET_WM_WINDOW_OPACITY),
494 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&opacity, 1 );
495 wine_tsx11_unlock();
499 /***********************************************************************
500 * sync_window_text
502 static void sync_window_text( Display *display, Window win, const WCHAR *text )
504 UINT count;
505 char *buffer, *utf8_buffer;
506 XTextProperty prop;
508 /* allocate new buffer for window text */
509 count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
510 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, count ))) return;
511 WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
513 count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
514 if (!(utf8_buffer = HeapAlloc( GetProcessHeap(), 0, count )))
516 HeapFree( GetProcessHeap(), 0, buffer );
517 return;
519 WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
521 wine_tsx11_lock();
522 if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
524 XSetWMName( display, win, &prop );
525 XSetWMIconName( display, win, &prop );
526 XFree( prop.value );
529 Implements a NET_WM UTF-8 title. It should be without a trailing \0,
530 according to the standard
531 ( http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text ).
533 XChangeProperty( display, win, x11drv_atom(_NET_WM_NAME), x11drv_atom(UTF8_STRING),
534 8, PropModeReplace, (unsigned char *) utf8_buffer, count);
535 wine_tsx11_unlock();
537 HeapFree( GetProcessHeap(), 0, utf8_buffer );
538 HeapFree( GetProcessHeap(), 0, buffer );
542 /***********************************************************************
543 * set_win_format
545 static BOOL set_win_format( HWND hwnd, XID fbconfig_id )
547 struct x11drv_win_data *data;
548 XVisualInfo *vis;
549 int w, h;
551 if (!(data = X11DRV_get_win_data(hwnd)) &&
552 !(data = X11DRV_create_win_data(hwnd))) return FALSE;
554 if (!(vis = visual_from_fbconfig_id(fbconfig_id))) return FALSE;
556 if (data->whole_window)
558 Display *display = thread_display();
559 Window client = data->client_window;
561 if (vis->visualid != data->visualid)
563 client = create_client_window( display, data, vis );
564 TRACE( "re-created client window %lx for %p fbconfig %lx\n", client, data->hwnd, fbconfig_id );
566 wine_tsx11_lock();
567 XFree(vis);
568 XFlush( display );
569 wine_tsx11_unlock();
570 if (client) goto done;
571 return FALSE;
574 w = data->client_rect.right - data->client_rect.left;
575 h = data->client_rect.bottom - data->client_rect.top;
577 if(w <= 0) w = 1;
578 if(h <= 0) h = 1;
580 #ifdef SONAME_LIBXCOMPOSITE
581 if(usexcomposite)
583 XSetWindowAttributes attrib;
584 static Window dummy_parent;
586 wine_tsx11_lock();
587 attrib.override_redirect = True;
588 if (!dummy_parent)
590 dummy_parent = XCreateWindow( gdi_display, root_window, -1, -1, 1, 1, 0, screen_depth,
591 InputOutput, visual, CWOverrideRedirect, &attrib );
592 XMapWindow( gdi_display, dummy_parent );
594 data->colormap = XCreateColormap(gdi_display, dummy_parent, vis->visual,
595 (vis->class == PseudoColor ||
596 vis->class == GrayScale ||
597 vis->class == DirectColor) ?
598 AllocAll : AllocNone);
599 attrib.colormap = data->colormap;
600 XInstallColormap(gdi_display, attrib.colormap);
602 if(data->gl_drawable) XDestroyWindow(gdi_display, data->gl_drawable);
603 data->gl_drawable = XCreateWindow(gdi_display, dummy_parent, -w, 0, w, h, 0,
604 vis->depth, InputOutput, vis->visual,
605 CWColormap | CWOverrideRedirect,
606 &attrib);
607 if(data->gl_drawable)
609 pXCompositeRedirectWindow(gdi_display, data->gl_drawable,
610 CompositeRedirectManual);
611 XMapWindow(gdi_display, data->gl_drawable);
613 XFree(vis);
614 XFlush( gdi_display );
615 wine_tsx11_unlock();
617 else
618 #endif
620 WARN("XComposite is not available, using GLXPixmap hack\n");
622 wine_tsx11_lock();
624 if(data->pixmap) XFreePixmap(gdi_display, data->pixmap);
625 data->pixmap = XCreatePixmap(gdi_display, root_window, w, h, vis->depth);
626 if(!data->pixmap)
628 XFree(vis);
629 wine_tsx11_unlock();
630 return FALSE;
633 if(data->gl_drawable) destroy_glxpixmap(gdi_display, data->gl_drawable);
634 data->gl_drawable = create_glxpixmap(gdi_display, vis, data->pixmap);
635 if(!data->gl_drawable)
637 XFreePixmap(gdi_display, data->pixmap);
638 data->pixmap = 0;
640 XFree(vis);
641 XFlush( gdi_display );
642 wine_tsx11_unlock();
643 if (data->pixmap) SetPropA(hwnd, pixmap_prop, (HANDLE)data->pixmap);
646 if (!data->gl_drawable) return FALSE;
648 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n",
649 data->gl_drawable, fbconfig_id);
650 SetPropA(hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
652 done:
653 data->fbconfig_id = fbconfig_id;
654 SetPropA(hwnd, fbconfig_id_prop, (HANDLE)data->fbconfig_id);
655 /* force DCE invalidation */
656 SetWindowPos( hwnd, 0, 0, 0, 0, 0,
657 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE |
658 SWP_NOREDRAW | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_STATECHANGED);
659 return TRUE;
662 /***********************************************************************
663 * sync_gl_drawable
665 static void sync_gl_drawable(struct x11drv_win_data *data)
667 int w = data->client_rect.right - data->client_rect.left;
668 int h = data->client_rect.bottom - data->client_rect.top;
669 XVisualInfo *vis;
670 Drawable glxp;
671 Pixmap pix;
673 if (w <= 0) w = 1;
674 if (h <= 0) h = 1;
676 TRACE("Resizing GL drawable 0x%lx to %dx%d\n", data->gl_drawable, w, h);
677 #ifdef SONAME_LIBXCOMPOSITE
678 if(usexcomposite)
680 wine_tsx11_lock();
681 XMoveResizeWindow(gdi_display, data->gl_drawable, -w, 0, w, h);
682 wine_tsx11_unlock();
683 return;
685 #endif
687 if (!(vis = visual_from_fbconfig_id(data->fbconfig_id))) return;
689 wine_tsx11_lock();
690 pix = XCreatePixmap(gdi_display, root_window, w, h, vis->depth);
691 if(!pix)
693 ERR("Failed to create pixmap for offscreen rendering\n");
694 XFree(vis);
695 wine_tsx11_unlock();
696 return;
699 glxp = create_glxpixmap(gdi_display, vis, pix);
700 if(!glxp)
702 ERR("Failed to create drawable for offscreen rendering\n");
703 XFreePixmap(gdi_display, pix);
704 XFree(vis);
705 wine_tsx11_unlock();
706 return;
709 XFree(vis);
711 mark_drawable_dirty(data->gl_drawable, glxp);
713 XFreePixmap(gdi_display, data->pixmap);
714 destroy_glxpixmap(gdi_display, data->gl_drawable);
715 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp, data->gl_drawable );
717 data->pixmap = pix;
718 data->gl_drawable = glxp;
720 XFlush( gdi_display );
721 wine_tsx11_unlock();
723 SetPropA(data->hwnd, gl_drawable_prop, (HANDLE)data->gl_drawable);
724 SetPropA(data->hwnd, pixmap_prop, (HANDLE)data->pixmap);
728 /***********************************************************************
729 * get_window_changes
731 * fill the window changes structure
733 static int get_window_changes( XWindowChanges *changes, const RECT *old, const RECT *new )
735 int mask = 0;
737 if (old->right - old->left != new->right - new->left )
739 if ((changes->width = new->right - new->left) <= 0) changes->width = 1;
740 else if (changes->width > 65535) changes->width = 65535;
741 mask |= CWWidth;
743 if (old->bottom - old->top != new->bottom - new->top)
745 if ((changes->height = new->bottom - new->top) <= 0) changes->height = 1;
746 else if (changes->height > 65535) changes->height = 65535;
747 mask |= CWHeight;
749 if (old->left != new->left)
751 changes->x = new->left;
752 mask |= CWX;
754 if (old->top != new->top)
756 changes->y = new->top;
757 mask |= CWY;
759 return mask;
763 /***********************************************************************
764 * create_icon_window
766 static Window create_icon_window( Display *display, struct x11drv_win_data *data )
768 XSetWindowAttributes attr;
770 attr.event_mask = (ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
771 ButtonPressMask | ButtonReleaseMask | EnterWindowMask);
772 attr.bit_gravity = NorthWestGravity;
773 attr.backing_store = NotUseful/*WhenMapped*/;
774 attr.colormap = X11DRV_PALETTE_PaletteXColormap; /* Needed due to our visual */
776 wine_tsx11_lock();
777 data->icon_window = XCreateWindow( display, root_window, 0, 0,
778 GetSystemMetrics( SM_CXICON ),
779 GetSystemMetrics( SM_CYICON ),
780 0, screen_depth,
781 InputOutput, visual,
782 CWEventMask | CWBitGravity | CWBackingStore | CWColormap, &attr );
783 XSaveContext( display, data->icon_window, winContext, (char *)data->hwnd );
784 XFlush( display ); /* make sure the window exists before we start painting to it */
785 wine_tsx11_unlock();
787 TRACE( "created %lx\n", data->icon_window );
788 SetPropA( data->hwnd, icon_window_prop, (HANDLE)data->icon_window );
789 return data->icon_window;
794 /***********************************************************************
795 * destroy_icon_window
797 static void destroy_icon_window( Display *display, struct x11drv_win_data *data )
799 if (!data->icon_window) return;
800 wine_tsx11_lock();
801 XDeleteContext( display, data->icon_window, winContext );
802 XDestroyWindow( display, data->icon_window );
803 data->icon_window = 0;
804 wine_tsx11_unlock();
805 RemovePropA( data->hwnd, icon_window_prop );
809 /***********************************************************************
810 * get_bitmap_argb
812 * Return the bitmap bits in ARGB format. Helper for setting icon hints.
814 static unsigned long *get_bitmap_argb( HDC hdc, HBITMAP color, HBITMAP mask, unsigned int *size )
816 BITMAP bm;
817 BITMAPINFO *info;
818 unsigned int *ptr, *bits = NULL;
819 unsigned char *mask_bits = NULL;
820 int i, j, has_alpha = 0;
822 if (!GetObjectW( color, sizeof(bm), &bm )) return NULL;
823 if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) return NULL;
824 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
825 info->bmiHeader.biWidth = bm.bmWidth;
826 info->bmiHeader.biHeight = -bm.bmHeight;
827 info->bmiHeader.biPlanes = 1;
828 info->bmiHeader.biBitCount = 32;
829 info->bmiHeader.biCompression = BI_RGB;
830 info->bmiHeader.biSizeImage = bm.bmWidth * bm.bmHeight * 4;
831 info->bmiHeader.biXPelsPerMeter = 0;
832 info->bmiHeader.biYPelsPerMeter = 0;
833 info->bmiHeader.biClrUsed = 0;
834 info->bmiHeader.biClrImportant = 0;
835 *size = bm.bmWidth * bm.bmHeight + 2;
836 if (!(bits = HeapAlloc( GetProcessHeap(), 0, *size * sizeof(long) ))) goto failed;
837 if (!GetDIBits( hdc, color, 0, bm.bmHeight, bits + 2, info, DIB_RGB_COLORS )) goto failed;
839 bits[0] = bm.bmWidth;
840 bits[1] = bm.bmHeight;
842 for (i = 0; i < bm.bmWidth * bm.bmHeight; i++)
843 if ((has_alpha = (bits[i + 2] & 0xff000000) != 0)) break;
845 if (!has_alpha)
847 unsigned int width_bytes = (bm.bmWidth + 31) / 32 * 4;
848 /* generate alpha channel from the mask */
849 info->bmiHeader.biBitCount = 1;
850 info->bmiHeader.biSizeImage = width_bytes * bm.bmHeight;
851 if (!(mask_bits = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage ))) goto failed;
852 if (!GetDIBits( hdc, mask, 0, bm.bmHeight, mask_bits, info, DIB_RGB_COLORS )) goto failed;
853 ptr = bits + 2;
854 for (i = 0; i < bm.bmHeight; i++)
855 for (j = 0; j < bm.bmWidth; j++, ptr++)
856 if (!((mask_bits[i * width_bytes + j / 8] << (j % 8)) & 0x80)) *ptr |= 0xff000000;
857 HeapFree( GetProcessHeap(), 0, mask_bits );
859 HeapFree( GetProcessHeap(), 0, info );
861 /* convert to array of longs */
862 if (bits && sizeof(long) > sizeof(int))
863 for (i = *size - 1; i >= 0; i--) ((unsigned long *)bits)[i] = bits[i];
865 return (unsigned long *)bits;
867 failed:
868 HeapFree( GetProcessHeap(), 0, info );
869 HeapFree( GetProcessHeap(), 0, bits );
870 HeapFree( GetProcessHeap(), 0, mask_bits );
871 return NULL;
875 /***********************************************************************
876 * set_icon_hints
878 * Set the icon wm hints
880 static void set_icon_hints( Display *display, struct x11drv_win_data *data,
881 HICON icon_big, HICON icon_small )
883 XWMHints *hints = data->wm_hints;
885 if (!icon_big)
887 icon_big = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 );
888 if (!icon_big) icon_big = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON );
890 if (!icon_small)
892 icon_small = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_SMALL, 0 );
893 if (!icon_small) icon_small = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICONSM );
896 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
897 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
898 data->hWMIconBitmap = 0;
899 data->hWMIconMask = 0;
901 if (!icon_big)
903 if (!data->icon_window) create_icon_window( display, data );
904 hints->icon_window = data->icon_window;
905 hints->flags = (hints->flags & ~(IconPixmapHint | IconMaskHint)) | IconWindowHint;
907 else
909 HBITMAP hbmOrig;
910 RECT rcMask;
911 BITMAP bm;
912 ICONINFO ii;
913 HDC hDC;
914 unsigned int size;
915 unsigned long *bits;
917 GetIconInfo(icon_big, &ii);
919 GetObjectW(ii.hbmMask, sizeof(bm), &bm);
920 rcMask.top = 0;
921 rcMask.left = 0;
922 rcMask.right = bm.bmWidth;
923 rcMask.bottom = bm.bmHeight;
925 hDC = CreateCompatibleDC(0);
926 bits = get_bitmap_argb( hDC, ii.hbmColor, ii.hbmMask, &size );
927 if (GetIconInfo( icon_small, &ii ))
929 unsigned int size_small;
930 unsigned long *bits_small, *new;
932 if ((bits_small = get_bitmap_argb( hDC, ii.hbmColor, ii.hbmMask, &size_small )) &&
933 (bits_small[0] != bits[0] || bits_small[1] != bits[1])) /* size must be different */
935 if ((new = HeapReAlloc( GetProcessHeap(), 0, bits,
936 (size + size_small) * sizeof(unsigned long) )))
938 bits = new;
939 memcpy( bits + size, bits_small, size_small * sizeof(unsigned long) );
940 size += size_small;
943 HeapFree( GetProcessHeap(), 0, bits_small );
944 DeleteObject( ii.hbmColor );
945 DeleteObject( ii.hbmMask );
947 wine_tsx11_lock();
948 if (bits)
949 XChangeProperty( display, data->whole_window, x11drv_atom(_NET_WM_ICON),
950 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)bits, size );
951 else
952 XDeleteProperty( display, data->whole_window, x11drv_atom(_NET_WM_ICON) );
953 wine_tsx11_unlock();
954 HeapFree( GetProcessHeap(), 0, bits );
956 hbmOrig = SelectObject(hDC, ii.hbmMask);
957 InvertRect(hDC, &rcMask);
958 SelectObject(hDC, ii.hbmColor); /* force the color bitmap to x11drv mode too */
959 SelectObject(hDC, hbmOrig);
961 data->hWMIconBitmap = ii.hbmColor;
962 data->hWMIconMask = ii.hbmMask;
964 hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap);
965 hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask);
966 destroy_icon_window( display, data );
967 hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
969 DeleteDC(hDC);
974 /***********************************************************************
975 * set_size_hints
977 * set the window size hints
979 static void set_size_hints( Display *display, struct x11drv_win_data *data, DWORD style )
981 XSizeHints* size_hints;
983 if (!(size_hints = XAllocSizeHints())) return;
985 size_hints->win_gravity = StaticGravity;
986 size_hints->flags |= PWinGravity;
988 /* don't update size hints if window is not in normal state */
989 if (!(style & (WS_MINIMIZE | WS_MAXIMIZE)))
991 if (data->hwnd != GetDesktopWindow()) /* don't force position of desktop */
993 size_hints->x = data->whole_rect.left;
994 size_hints->y = data->whole_rect.top;
995 size_hints->flags |= PPosition;
998 if (!is_window_resizable( data, style ))
1000 size_hints->max_width = data->whole_rect.right - data->whole_rect.left;
1001 size_hints->max_height = data->whole_rect.bottom - data->whole_rect.top;
1002 size_hints->min_width = size_hints->max_width;
1003 size_hints->min_height = size_hints->max_height;
1004 size_hints->flags |= PMinSize | PMaxSize;
1007 XSetWMNormalHints( display, data->whole_window, size_hints );
1008 XFree( size_hints );
1012 /***********************************************************************
1013 * get_process_name
1015 * get the name of the current process for setting class hints
1017 static char *get_process_name(void)
1019 static char *name;
1021 if (!name)
1023 WCHAR module[MAX_PATH];
1024 DWORD len = GetModuleFileNameW( 0, module, MAX_PATH );
1025 if (len && len < MAX_PATH)
1027 char *ptr;
1028 WCHAR *p, *appname = module;
1030 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
1031 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
1032 len = WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, NULL, 0, NULL, NULL );
1033 if ((ptr = HeapAlloc( GetProcessHeap(), 0, len )))
1035 WideCharToMultiByte( CP_UNIXCP, 0, appname, -1, ptr, len, NULL, NULL );
1036 name = ptr;
1040 return name;
1044 /***********************************************************************
1045 * set_initial_wm_hints
1047 * Set the window manager hints that don't change over the lifetime of a window.
1049 static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data )
1051 long i;
1052 Atom protocols[3];
1053 Atom dndVersion = WINE_XDND_VERSION;
1054 XClassHint *class_hints;
1055 char *process_name = get_process_name();
1056 Cursor cursor;
1058 wine_tsx11_lock();
1060 /* wm protocols */
1061 i = 0;
1062 protocols[i++] = x11drv_atom(WM_DELETE_WINDOW);
1063 protocols[i++] = x11drv_atom(_NET_WM_PING);
1064 if (use_take_focus) protocols[i++] = x11drv_atom(WM_TAKE_FOCUS);
1065 XChangeProperty( display, data->whole_window, x11drv_atom(WM_PROTOCOLS),
1066 XA_ATOM, 32, PropModeReplace, (unsigned char *)protocols, i );
1068 /* class hints */
1069 if ((class_hints = XAllocClassHint()))
1071 static char wine[] = "Wine";
1073 class_hints->res_name = process_name;
1074 class_hints->res_class = wine;
1075 XSetClassHint( display, data->whole_window, class_hints );
1076 XFree( class_hints );
1079 /* set the WM_CLIENT_MACHINE and WM_LOCALE_NAME properties */
1080 XSetWMProperties(display, data->whole_window, NULL, NULL, NULL, 0, NULL, NULL, NULL);
1081 /* set the pid. together, these properties are needed so the window manager can kill us if we freeze */
1082 i = getpid();
1083 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_PID),
1084 XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&i, 1);
1086 XChangeProperty( display, data->whole_window, x11drv_atom(XdndAware),
1087 XA_ATOM, 32, PropModeReplace, (unsigned char*)&dndVersion, 1 );
1089 if ((cursor = get_x11_cursor( data->cursor )))
1090 XDefineCursor( gdi_display, data->whole_window, cursor );
1092 data->wm_hints = XAllocWMHints();
1093 wine_tsx11_unlock();
1095 if (data->wm_hints)
1097 data->wm_hints->flags = 0;
1098 set_icon_hints( display, data, 0, 0 );
1103 /***********************************************************************
1104 * get_owner_whole_window
1106 * Retrieve an owner's window, creating it if necessary.
1108 static Window get_owner_whole_window( HWND owner, BOOL force_managed )
1110 struct x11drv_win_data *data;
1112 if (!owner) return 0;
1114 if (!(data = X11DRV_get_win_data( owner )))
1116 if (GetWindowThreadProcessId( owner, NULL ) != GetCurrentThreadId() ||
1117 !(data = X11DRV_create_win_data( owner )))
1118 return (Window)GetPropA( owner, whole_window_prop );
1120 else if (!data->managed && force_managed) /* make it managed */
1122 SetWindowPos( owner, 0, 0, 0, 0, 0,
1123 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE |
1124 SWP_NOREDRAW | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_STATECHANGED );
1126 return data->whole_window;
1130 /***********************************************************************
1131 * set_wm_hints
1133 * Set the window manager hints for a newly-created window
1135 static void set_wm_hints( Display *display, struct x11drv_win_data *data )
1137 Window group_leader = data->whole_window;
1138 Window owner_win = 0;
1139 Atom window_type;
1140 MwmHints mwm_hints;
1141 DWORD style, ex_style;
1142 HWND owner;
1144 if (data->hwnd == GetDesktopWindow())
1146 /* force some styles for the desktop to get the correct decorations */
1147 style = WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
1148 ex_style = WS_EX_APPWINDOW;
1149 owner = 0;
1151 else
1153 style = GetWindowLongW( data->hwnd, GWL_STYLE );
1154 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
1155 owner = get_window_owner( data->hwnd );
1156 if ((owner_win = get_owner_whole_window( owner, data->managed ))) group_leader = owner_win;
1159 wine_tsx11_lock();
1161 if (owner_win) XSetTransientForHint( display, data->whole_window, owner_win );
1163 /* size hints */
1164 set_size_hints( display, data, style );
1166 /* set the WM_WINDOW_TYPE */
1167 if (style & WS_THICKFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
1168 else if (ex_style & WS_EX_APPWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
1169 else if (style & WS_DLGFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
1170 else if (ex_style & WS_EX_DLGMODALFRAME) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
1171 else if ((style & WS_POPUP) && owner) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_DIALOG);
1172 #if 0 /* many window managers don't handle utility windows very well */
1173 else if (ex_style & WS_EX_TOOLWINDOW) window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_UTILITY);
1174 #endif
1175 else window_type = x11drv_atom(_NET_WM_WINDOW_TYPE_NORMAL);
1177 XChangeProperty(display, data->whole_window, x11drv_atom(_NET_WM_WINDOW_TYPE),
1178 XA_ATOM, 32, PropModeReplace, (unsigned char*)&window_type, 1);
1180 mwm_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
1181 mwm_hints.decorations = get_mwm_decorations( data, style, ex_style );
1182 mwm_hints.functions = MWM_FUNC_MOVE;
1183 if (is_window_resizable( data, style )) mwm_hints.functions |= MWM_FUNC_RESIZE;
1184 if (!(style & WS_DISABLED))
1186 if (style & WS_MINIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MINIMIZE;
1187 if (style & WS_MAXIMIZEBOX) mwm_hints.functions |= MWM_FUNC_MAXIMIZE;
1188 if (style & WS_SYSMENU) mwm_hints.functions |= MWM_FUNC_CLOSE;
1191 XChangeProperty( display, data->whole_window, x11drv_atom(_MOTIF_WM_HINTS),
1192 x11drv_atom(_MOTIF_WM_HINTS), 32, PropModeReplace,
1193 (unsigned char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
1195 /* wm hints */
1196 if (data->wm_hints)
1198 data->wm_hints->flags |= InputHint | StateHint | WindowGroupHint;
1199 data->wm_hints->input = !use_take_focus && !(style & WS_DISABLED);
1200 data->wm_hints->initial_state = (style & WS_MINIMIZE) ? IconicState : NormalState;
1201 data->wm_hints->window_group = group_leader;
1202 XSetWMHints( display, data->whole_window, data->wm_hints );
1205 wine_tsx11_unlock();
1209 /***********************************************************************
1210 * update_net_wm_states
1212 void update_net_wm_states( Display *display, struct x11drv_win_data *data )
1214 static const unsigned int state_atoms[NB_NET_WM_STATES] =
1216 XATOM__NET_WM_STATE_FULLSCREEN,
1217 XATOM__NET_WM_STATE_ABOVE,
1218 XATOM__NET_WM_STATE_MAXIMIZED_VERT,
1219 XATOM__NET_WM_STATE_SKIP_PAGER,
1220 XATOM__NET_WM_STATE_SKIP_TASKBAR
1223 DWORD i, style, ex_style, new_state = 0;
1225 if (!data->managed) return;
1226 if (data->whole_window == root_window) return;
1228 style = GetWindowLongW( data->hwnd, GWL_STYLE );
1229 if (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width &&
1230 data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height)
1232 if ((style & WS_MAXIMIZE) && (style & WS_CAPTION) == WS_CAPTION)
1233 new_state |= (1 << NET_WM_STATE_MAXIMIZED);
1234 else if (!(style & WS_MINIMIZE))
1235 new_state |= (1 << NET_WM_STATE_FULLSCREEN);
1237 else if (style & WS_MAXIMIZE)
1238 new_state |= (1 << NET_WM_STATE_MAXIMIZED);
1240 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
1241 if (ex_style & WS_EX_TOPMOST)
1242 new_state |= (1 << NET_WM_STATE_ABOVE);
1243 if (ex_style & WS_EX_TOOLWINDOW)
1244 new_state |= (1 << NET_WM_STATE_SKIP_TASKBAR) | (1 << NET_WM_STATE_SKIP_PAGER);
1245 if (!(ex_style & WS_EX_APPWINDOW) && get_window_owner( data->hwnd ))
1246 new_state |= (1 << NET_WM_STATE_SKIP_TASKBAR);
1248 if (!data->mapped) /* set the _NET_WM_STATE atom directly */
1250 Atom atoms[NB_NET_WM_STATES+1];
1251 DWORD count;
1253 for (i = count = 0; i < NB_NET_WM_STATES; i++)
1255 if (!(new_state & (1 << i))) continue;
1256 TRACE( "setting wm state %u for unmapped window %p/%lx\n",
1257 i, data->hwnd, data->whole_window );
1258 atoms[count++] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM];
1259 if (state_atoms[i] == XATOM__NET_WM_STATE_MAXIMIZED_VERT)
1260 atoms[count++] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ);
1262 wine_tsx11_lock();
1263 XChangeProperty( display, data->whole_window, x11drv_atom(_NET_WM_STATE), XA_ATOM,
1264 32, PropModeReplace, (unsigned char *)atoms, count );
1265 wine_tsx11_unlock();
1267 else /* ask the window manager to do it for us */
1269 XEvent xev;
1271 xev.xclient.type = ClientMessage;
1272 xev.xclient.window = data->whole_window;
1273 xev.xclient.message_type = x11drv_atom(_NET_WM_STATE);
1274 xev.xclient.serial = 0;
1275 xev.xclient.display = display;
1276 xev.xclient.send_event = True;
1277 xev.xclient.format = 32;
1278 xev.xclient.data.l[3] = 1;
1280 for (i = 0; i < NB_NET_WM_STATES; i++)
1282 if (!((data->net_wm_state ^ new_state) & (1 << i))) continue; /* unchanged */
1284 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
1285 i, data->hwnd, data->whole_window,
1286 (new_state & (1 << i)) != 0, (data->net_wm_state & (1 << i)) != 0 );
1288 xev.xclient.data.l[0] = (new_state & (1 << i)) ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1289 xev.xclient.data.l[1] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM];
1290 xev.xclient.data.l[2] = ((state_atoms[i] == XATOM__NET_WM_STATE_MAXIMIZED_VERT) ?
1291 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ) : 0);
1292 wine_tsx11_lock();
1293 XSendEvent( display, root_window, False,
1294 SubstructureRedirectMask | SubstructureNotifyMask, &xev );
1295 wine_tsx11_unlock();
1298 data->net_wm_state = new_state;
1302 /***********************************************************************
1303 * set_xembed_flags
1305 static void set_xembed_flags( Display *display, struct x11drv_win_data *data, unsigned long flags )
1307 unsigned long info[2];
1309 info[0] = 0; /* protocol version */
1310 info[1] = flags;
1311 wine_tsx11_lock();
1312 XChangeProperty( display, data->whole_window, x11drv_atom(_XEMBED_INFO),
1313 x11drv_atom(_XEMBED_INFO), 32, PropModeReplace, (unsigned char*)info, 2 );
1314 wine_tsx11_unlock();
1318 /***********************************************************************
1319 * map_window
1321 static void map_window( Display *display, struct x11drv_win_data *data, DWORD new_style )
1323 TRACE( "win %p/%lx\n", data->hwnd, data->whole_window );
1325 remove_startup_notification( display, data->whole_window );
1327 wait_for_withdrawn_state( display, data, TRUE );
1329 if (!data->embedded)
1331 update_net_wm_states( display, data );
1332 sync_window_style( display, data );
1333 wine_tsx11_lock();
1334 XMapWindow( display, data->whole_window );
1335 wine_tsx11_unlock();
1337 else set_xembed_flags( display, data, XEMBED_MAPPED );
1339 data->mapped = TRUE;
1340 data->iconic = (new_style & WS_MINIMIZE) != 0;
1344 /***********************************************************************
1345 * unmap_window
1347 static void unmap_window( Display *display, struct x11drv_win_data *data )
1349 TRACE( "win %p/%lx\n", data->hwnd, data->whole_window );
1351 if (!data->embedded)
1353 wait_for_withdrawn_state( display, data, FALSE );
1354 wine_tsx11_lock();
1355 if (data->managed) XWithdrawWindow( display, data->whole_window, DefaultScreen(display) );
1356 else XUnmapWindow( display, data->whole_window );
1357 wine_tsx11_unlock();
1359 else set_xembed_flags( display, data, 0 );
1361 data->mapped = FALSE;
1362 data->net_wm_state = 0;
1366 /***********************************************************************
1367 * make_window_embedded
1369 void make_window_embedded( Display *display, struct x11drv_win_data *data )
1371 if (data->mapped)
1373 /* the window cannot be mapped before being embedded */
1374 unmap_window( display, data );
1375 data->embedded = TRUE;
1376 map_window( display, data, 0 );
1378 else
1380 data->embedded = TRUE;
1381 set_xembed_flags( display, data, 0 );
1386 /***********************************************************************
1387 * X11DRV_window_to_X_rect
1389 * Convert a rect from client to X window coordinates
1391 static void X11DRV_window_to_X_rect( struct x11drv_win_data *data, RECT *rect )
1393 RECT rc;
1395 if (!data->managed) return;
1396 if (IsRectEmpty( rect )) return;
1398 get_x11_rect_offset( data, &rc );
1400 rect->left -= rc.left;
1401 rect->right -= rc.right;
1402 rect->top -= rc.top;
1403 rect->bottom -= rc.bottom;
1404 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1405 if (rect->left >= rect->right) rect->right = rect->left + 1;
1409 /***********************************************************************
1410 * X11DRV_X_to_window_rect
1412 * Opposite of X11DRV_window_to_X_rect
1414 void X11DRV_X_to_window_rect( struct x11drv_win_data *data, RECT *rect )
1416 RECT rc;
1418 if (!data->managed) return;
1419 if (IsRectEmpty( rect )) return;
1421 get_x11_rect_offset( data, &rc );
1423 rect->left += rc.left;
1424 rect->right += rc.right;
1425 rect->top += rc.top;
1426 rect->bottom += rc.bottom;
1427 if (rect->top >= rect->bottom) rect->bottom = rect->top + 1;
1428 if (rect->left >= rect->right) rect->right = rect->left + 1;
1432 /***********************************************************************
1433 * sync_window_position
1435 * Synchronize the X window position with the Windows one
1437 static void sync_window_position( Display *display, struct x11drv_win_data *data,
1438 UINT swp_flags, const RECT *old_window_rect,
1439 const RECT *old_whole_rect, const RECT *old_client_rect )
1441 DWORD style = GetWindowLongW( data->hwnd, GWL_STYLE );
1442 XWindowChanges changes;
1443 unsigned int mask = 0;
1445 if (data->managed && data->iconic) return;
1447 /* resizing a managed maximized window is not allowed */
1448 if (!(style & WS_MAXIMIZE) || !data->managed)
1450 changes.width = data->whole_rect.right - data->whole_rect.left;
1451 changes.height = data->whole_rect.bottom - data->whole_rect.top;
1452 /* if window rect is empty force size to 1x1 */
1453 if (changes.width <= 0 || changes.height <= 0) changes.width = changes.height = 1;
1454 if (changes.width > 65535) changes.width = 65535;
1455 if (changes.height > 65535) changes.height = 65535;
1456 mask |= CWWidth | CWHeight;
1459 /* only the size is allowed to change for the desktop window */
1460 if (data->whole_window != root_window)
1462 changes.x = data->whole_rect.left - virtual_screen_rect.left;
1463 changes.y = data->whole_rect.top - virtual_screen_rect.top;
1464 mask |= CWX | CWY;
1467 if (!(swp_flags & SWP_NOZORDER) || (swp_flags & SWP_SHOWWINDOW))
1469 /* find window that this one must be after */
1470 HWND prev = GetWindow( data->hwnd, GW_HWNDPREV );
1471 while (prev && !(GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE))
1472 prev = GetWindow( prev, GW_HWNDPREV );
1473 if (!prev) /* top child */
1475 changes.stack_mode = Above;
1476 mask |= CWStackMode;
1478 /* should use stack_mode Below but most window managers don't get it right */
1479 /* and Above with a sibling doesn't work so well either, so we ignore it */
1482 wine_tsx11_lock();
1483 set_size_hints( display, data, style );
1484 data->configure_serial = NextRequest( display );
1485 XReconfigureWMWindow( display, data->whole_window,
1486 DefaultScreen(display), mask, &changes );
1487 #ifdef HAVE_LIBXSHAPE
1488 if (data->shaped)
1490 int old_x_offset = old_window_rect->left - old_whole_rect->left;
1491 int old_y_offset = old_window_rect->top - old_whole_rect->top;
1492 int new_x_offset = data->window_rect.left - data->whole_rect.left;
1493 int new_y_offset = data->window_rect.top - data->whole_rect.top;
1494 if (old_x_offset != new_x_offset || old_y_offset != new_y_offset)
1495 XShapeOffsetShape( display, data->whole_window, ShapeBounding,
1496 new_x_offset - old_x_offset, new_y_offset - old_y_offset );
1498 #endif
1499 wine_tsx11_unlock();
1501 TRACE( "win %p/%lx pos %d,%d,%dx%d after %lx changes=%x serial=%lu\n",
1502 data->hwnd, data->whole_window, data->whole_rect.left, data->whole_rect.top,
1503 data->whole_rect.right - data->whole_rect.left,
1504 data->whole_rect.bottom - data->whole_rect.top,
1505 changes.sibling, mask, data->configure_serial );
1509 /***********************************************************************
1510 * sync_client_position
1512 * Synchronize the X client window position with the Windows one
1514 static void sync_client_position( Display *display, struct x11drv_win_data *data,
1515 UINT swp_flags, const RECT *old_client_rect,
1516 const RECT *old_whole_rect )
1518 int mask;
1519 XWindowChanges changes;
1520 RECT old = *old_client_rect;
1521 RECT new = data->client_rect;
1523 OffsetRect( &old, -old_whole_rect->left, -old_whole_rect->top );
1524 OffsetRect( &new, -data->whole_rect.left, -data->whole_rect.top );
1525 if (!(mask = get_window_changes( &changes, &old, &new ))) return;
1527 if (data->client_window)
1529 TRACE( "setting client win %lx pos %d,%d,%dx%d changes=%x\n",
1530 data->client_window, new.left, new.top,
1531 new.right - new.left, new.bottom - new.top, mask );
1532 wine_tsx11_lock();
1533 XConfigureWindow( display, data->client_window, mask, &changes );
1534 wine_tsx11_unlock();
1537 if (data->gl_drawable && (mask & (CWWidth|CWHeight))) sync_gl_drawable( data );
1541 /***********************************************************************
1542 * move_window_bits
1544 * Move the window bits when a window is moved.
1546 static void move_window_bits( struct x11drv_win_data *data, const RECT *old_rect, const RECT *new_rect,
1547 const RECT *old_client_rect )
1549 RECT src_rect = *old_rect;
1550 RECT dst_rect = *new_rect;
1551 HDC hdc_src, hdc_dst;
1552 INT code;
1553 HRGN rgn = 0;
1554 HWND parent = 0;
1556 if (!data->whole_window)
1558 OffsetRect( &dst_rect, -data->window_rect.left, -data->window_rect.top );
1559 parent = GetAncestor( data->hwnd, GA_PARENT );
1560 hdc_src = GetDCEx( parent, 0, DCX_CACHE );
1561 hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE | DCX_WINDOW );
1563 else
1565 OffsetRect( &dst_rect, -data->client_rect.left, -data->client_rect.top );
1566 /* make src rect relative to the old position of the window */
1567 OffsetRect( &src_rect, -old_client_rect->left, -old_client_rect->top );
1568 if (dst_rect.left == src_rect.left && dst_rect.top == src_rect.top) return;
1569 hdc_src = hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE );
1572 code = X11DRV_START_EXPOSURES;
1573 ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1575 TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n",
1576 data->hwnd, data->whole_window, data->client_window,
1577 wine_dbgstr_rect(&src_rect), wine_dbgstr_rect(&dst_rect) );
1578 BitBlt( hdc_dst, dst_rect.left, dst_rect.top,
1579 dst_rect.right - dst_rect.left, dst_rect.bottom - dst_rect.top,
1580 hdc_src, src_rect.left, src_rect.top, SRCCOPY );
1582 code = X11DRV_END_EXPOSURES;
1583 ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, sizeof(rgn), (LPSTR)&rgn );
1585 ReleaseDC( data->hwnd, hdc_dst );
1586 if (hdc_src != hdc_dst) ReleaseDC( parent, hdc_src );
1588 if (rgn)
1590 if (!data->whole_window)
1592 /* map region to client rect since we are using DCX_WINDOW */
1593 OffsetRgn( rgn, data->window_rect.left - data->client_rect.left,
1594 data->window_rect.top - data->client_rect.top );
1595 RedrawWindow( data->hwnd, NULL, rgn,
1596 RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ALLCHILDREN );
1598 else RedrawWindow( data->hwnd, NULL, rgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
1599 DeleteObject( rgn );
1604 /**********************************************************************
1605 * create_whole_window
1607 * Create the whole X window for a given window
1609 static Window create_whole_window( Display *display, struct x11drv_win_data *data )
1611 int cx, cy, mask;
1612 XSetWindowAttributes attr;
1613 WCHAR text[1024];
1614 COLORREF key;
1615 BYTE alpha;
1616 DWORD layered_flags;
1617 HRGN win_rgn;
1619 if (!data->managed && is_window_managed( data->hwnd, SWP_NOACTIVATE, &data->window_rect ))
1621 TRACE( "making win %p/%lx managed\n", data->hwnd, data->whole_window );
1622 data->managed = TRUE;
1623 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1626 if ((win_rgn = CreateRectRgn( 0, 0, 0, 0 )) &&
1627 GetWindowRgn( data->hwnd, win_rgn ) == ERROR)
1629 DeleteObject( win_rgn );
1630 win_rgn = 0;
1632 data->shaped = (win_rgn != 0);
1634 mask = get_window_attributes( display, data, &attr );
1636 data->whole_rect = data->window_rect;
1637 X11DRV_window_to_X_rect( data, &data->whole_rect );
1638 if (!(cx = data->whole_rect.right - data->whole_rect.left)) cx = 1;
1639 else if (cx > 65535) cx = 65535;
1640 if (!(cy = data->whole_rect.bottom - data->whole_rect.top)) cy = 1;
1641 else if (cy > 65535) cy = 65535;
1643 wine_tsx11_lock();
1644 data->whole_window = XCreateWindow( display, root_window,
1645 data->whole_rect.left - virtual_screen_rect.left,
1646 data->whole_rect.top - virtual_screen_rect.top,
1647 cx, cy, 0, screen_depth, InputOutput,
1648 visual, mask, &attr );
1650 if (data->whole_window) XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
1651 wine_tsx11_unlock();
1653 if (!data->whole_window) goto done;
1655 if (!create_client_window( display, data, NULL ))
1657 wine_tsx11_lock();
1658 XDeleteContext( display, data->whole_window, winContext );
1659 XDestroyWindow( display, data->whole_window );
1660 data->whole_window = 0;
1661 wine_tsx11_unlock();
1662 goto done;
1665 set_initial_wm_hints( display, data );
1666 set_wm_hints( display, data );
1668 SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
1670 /* set the window text */
1671 if (!InternalGetWindowText( data->hwnd, text, sizeof(text)/sizeof(WCHAR) )) text[0] = 0;
1672 sync_window_text( display, data->whole_window, text );
1674 /* set the window region */
1675 if (win_rgn) sync_window_region( display, data, win_rgn );
1677 /* set the window opacity */
1678 if (!GetLayeredWindowAttributes( data->hwnd, &key, &alpha, &layered_flags )) layered_flags = 0;
1679 sync_window_opacity( display, data->whole_window, key, alpha, layered_flags );
1681 wine_tsx11_lock();
1682 XFlush( display ); /* make sure the window exists before we start painting to it */
1683 wine_tsx11_unlock();
1684 done:
1685 if (win_rgn) DeleteObject( win_rgn );
1686 return data->whole_window;
1690 /**********************************************************************
1691 * destroy_whole_window
1693 * Destroy the whole X window for a given window.
1695 static void destroy_whole_window( Display *display, struct x11drv_win_data *data, BOOL already_destroyed )
1697 if (!data->whole_window) return;
1699 TRACE( "win %p xwin %lx/%lx\n", data->hwnd, data->whole_window, data->client_window );
1700 wine_tsx11_lock();
1701 XDeleteContext( display, data->whole_window, winContext );
1702 XDeleteContext( display, data->client_window, winContext );
1703 if (!already_destroyed) XDestroyWindow( display, data->whole_window );
1704 data->whole_window = data->client_window = 0;
1705 data->wm_state = WithdrawnState;
1706 data->net_wm_state = 0;
1707 data->mapped = FALSE;
1708 if (data->xic)
1710 XUnsetICFocus( data->xic );
1711 XDestroyIC( data->xic );
1712 data->xic = 0;
1714 /* Outlook stops processing messages after destroying a dialog, so we need an explicit flush */
1715 XFlush( display );
1716 XFree( data->wm_hints );
1717 data->wm_hints = NULL;
1718 wine_tsx11_unlock();
1719 RemovePropA( data->hwnd, whole_window_prop );
1720 RemovePropA( data->hwnd, client_window_prop );
1724 /*****************************************************************
1725 * SetWindowText (X11DRV.@)
1727 void CDECL X11DRV_SetWindowText( HWND hwnd, LPCWSTR text )
1729 Window win;
1731 if ((win = X11DRV_get_whole_window( hwnd )) && win != DefaultRootWindow(gdi_display))
1733 Display *display = thread_init_display();
1734 sync_window_text( display, win, text );
1739 /***********************************************************************
1740 * SetWindowStyle (X11DRV.@)
1742 * Update the X state of a window to reflect a style change
1744 void CDECL X11DRV_SetWindowStyle( HWND hwnd, INT offset, STYLESTRUCT *style )
1746 struct x11drv_win_data *data;
1747 DWORD changed;
1749 if (hwnd == GetDesktopWindow()) return;
1750 changed = style->styleNew ^ style->styleOld;
1752 if (offset == GWL_STYLE && (changed & WS_VISIBLE) && (style->styleNew & WS_VISIBLE))
1754 /* we don't unmap windows, that causes trouble with the window manager */
1755 if (!(data = X11DRV_get_win_data( hwnd )) &&
1756 !(data = X11DRV_create_win_data( hwnd ))) return;
1758 if (data->whole_window && is_window_rect_mapped( &data->window_rect ))
1760 Display *display = thread_display();
1761 set_wm_hints( display, data );
1762 if (!data->mapped) map_window( display, data, style->styleNew );
1766 if (offset == GWL_STYLE && (changed & WS_DISABLED))
1768 data = X11DRV_get_win_data( hwnd );
1769 if (data && data->whole_window)
1770 set_wm_hints( thread_display(), data );
1773 if (offset == GWL_EXSTYLE && (changed & WS_EX_LAYERED))
1775 /* changing WS_EX_LAYERED resets attributes */
1776 if ((data = X11DRV_get_win_data( hwnd )) && data->whole_window)
1777 sync_window_opacity( thread_display(), data->whole_window, 0, 0, 0 );
1782 /***********************************************************************
1783 * DestroyWindow (X11DRV.@)
1785 void CDECL X11DRV_DestroyWindow( HWND hwnd )
1787 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1788 struct x11drv_win_data *data;
1790 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1792 if (data->pixmap)
1794 wine_tsx11_lock();
1795 destroy_glxpixmap(gdi_display, data->gl_drawable);
1796 XFreePixmap(gdi_display, data->pixmap);
1797 wine_tsx11_unlock();
1799 else if (data->gl_drawable)
1801 wine_tsx11_lock();
1802 XDestroyWindow(gdi_display, data->gl_drawable);
1803 wine_tsx11_unlock();
1806 destroy_whole_window( thread_data->display, data, FALSE );
1807 destroy_icon_window( thread_data->display, data );
1809 if (data->colormap)
1811 wine_tsx11_lock();
1812 XFreeColormap( thread_data->display, data->colormap );
1813 wine_tsx11_unlock();
1816 if (thread_data->last_focus == hwnd) thread_data->last_focus = 0;
1817 if (data->hWMIconBitmap) DeleteObject( data->hWMIconBitmap );
1818 if (data->hWMIconMask) DeleteObject( data->hWMIconMask);
1819 wine_tsx11_lock();
1820 XDeleteContext( thread_data->display, (XID)hwnd, win_data_context );
1821 wine_tsx11_unlock();
1822 HeapFree( GetProcessHeap(), 0, data );
1826 /***********************************************************************
1827 * X11DRV_DestroyNotify
1829 void X11DRV_DestroyNotify( HWND hwnd, XEvent *event )
1831 Display *display = event->xdestroywindow.display;
1832 struct x11drv_win_data *data;
1834 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1836 FIXME( "window %p/%lx destroyed from the outside\n", hwnd, data->whole_window );
1837 destroy_whole_window( display, data, TRUE );
1841 static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
1843 struct x11drv_win_data *data;
1845 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
1847 data->hwnd = hwnd;
1848 wine_tsx11_lock();
1849 if (!winContext) winContext = XUniqueContext();
1850 if (!win_data_context) win_data_context = XUniqueContext();
1851 XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
1852 wine_tsx11_unlock();
1854 return data;
1858 /* initialize the desktop window id in the desktop manager process */
1859 static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND hwnd )
1861 struct x11drv_win_data *data;
1863 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1864 data->whole_window = data->client_window = root_window;
1865 data->managed = TRUE;
1866 SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
1867 SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
1868 SetPropA( data->hwnd, client_window_prop, (HANDLE)root_window );
1869 set_initial_wm_hints( display, data );
1870 return data;
1873 /**********************************************************************
1874 * CreateDesktopWindow (X11DRV.@)
1876 BOOL CDECL X11DRV_CreateDesktopWindow( HWND hwnd )
1878 unsigned int width, height;
1880 /* retrieve the real size of the desktop */
1881 SERVER_START_REQ( get_window_rectangles )
1883 req->handle = wine_server_user_handle( hwnd );
1884 wine_server_call( req );
1885 width = reply->window.right - reply->window.left;
1886 height = reply->window.bottom - reply->window.top;
1888 SERVER_END_REQ;
1890 if (!width && !height) /* not initialized yet */
1892 SERVER_START_REQ( set_window_pos )
1894 req->handle = wine_server_user_handle( hwnd );
1895 req->previous = 0;
1896 req->flags = SWP_NOZORDER;
1897 req->window.left = virtual_screen_rect.left;
1898 req->window.top = virtual_screen_rect.top;
1899 req->window.right = virtual_screen_rect.right;
1900 req->window.bottom = virtual_screen_rect.bottom;
1901 req->client = req->window;
1902 wine_server_call( req );
1904 SERVER_END_REQ;
1906 else
1908 Window win = (Window)GetPropA( hwnd, whole_window_prop );
1909 if (win && win != root_window) X11DRV_init_desktop( win, width, height );
1911 return TRUE;
1915 /**********************************************************************
1916 * CreateWindow (X11DRV.@)
1918 BOOL CDECL X11DRV_CreateWindow( HWND hwnd )
1920 if (hwnd == GetDesktopWindow() && root_window != DefaultRootWindow( gdi_display ))
1922 Display *display = thread_init_display();
1924 /* the desktop win data can't be created lazily */
1925 if (!create_desktop_win_data( display, hwnd )) return FALSE;
1927 return TRUE;
1931 /***********************************************************************
1932 * X11DRV_get_win_data
1934 * Return the X11 data structure associated with a window.
1936 struct x11drv_win_data *X11DRV_get_win_data( HWND hwnd )
1938 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1939 char *data;
1941 if (!thread_data) return NULL;
1942 if (!hwnd) return NULL;
1943 if (XFindContext( thread_data->display, (XID)hwnd, win_data_context, &data )) data = NULL;
1944 return (struct x11drv_win_data *)data;
1948 /***********************************************************************
1949 * X11DRV_create_win_data
1951 * Create an X11 data window structure for an existing window.
1953 struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd )
1955 Display *display;
1956 struct x11drv_win_data *data;
1957 HWND parent;
1959 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop */
1961 /* don't create win data for HWND_MESSAGE windows */
1962 if (parent != GetDesktopWindow() && !GetAncestor( parent, GA_PARENT )) return NULL;
1964 display = thread_init_display();
1965 if (!(data = alloc_win_data( display, hwnd ))) return NULL;
1967 GetWindowRect( hwnd, &data->window_rect );
1968 MapWindowPoints( 0, parent, (POINT *)&data->window_rect, 2 );
1969 data->whole_rect = data->window_rect;
1970 GetClientRect( hwnd, &data->client_rect );
1971 MapWindowPoints( hwnd, parent, (POINT *)&data->client_rect, 2 );
1973 if (parent == GetDesktopWindow())
1975 if (!create_whole_window( display, data ))
1977 HeapFree( GetProcessHeap(), 0, data );
1978 return NULL;
1980 TRACE( "win %p/%lx/%lx window %s whole %s client %s\n",
1981 hwnd, data->whole_window, data->client_window, wine_dbgstr_rect( &data->window_rect ),
1982 wine_dbgstr_rect( &data->whole_rect ), wine_dbgstr_rect( &data->client_rect ));
1984 return data;
1988 /***********************************************************************
1989 * X11DRV_get_whole_window
1991 * Return the X window associated with the full area of a window
1993 Window X11DRV_get_whole_window( HWND hwnd )
1995 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
1997 if (!data)
1999 if (hwnd == GetDesktopWindow()) return root_window;
2000 return (Window)GetPropA( hwnd, whole_window_prop );
2002 return data->whole_window;
2006 /***********************************************************************
2007 * X11DRV_get_client_window
2009 * Return the X window associated with the client area of a window
2011 static Window X11DRV_get_client_window( HWND hwnd )
2013 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2015 if (!data)
2017 if (hwnd == GetDesktopWindow()) return root_window;
2018 return (Window)GetPropA( hwnd, client_window_prop );
2020 return data->client_window;
2024 /***********************************************************************
2025 * X11DRV_get_ic
2027 * Return the X input context associated with a window
2029 XIC X11DRV_get_ic( HWND hwnd )
2031 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2032 XIM xim;
2034 if (!data) return 0;
2035 if (data->xic) return data->xic;
2036 if (!(xim = x11drv_thread_data()->xim)) return 0;
2037 return X11DRV_CreateIC( xim, data );
2041 /***********************************************************************
2042 * X11DRV_GetDC (X11DRV.@)
2044 void CDECL X11DRV_GetDC( HDC hdc, HWND hwnd, HWND top, const RECT *win_rect,
2045 const RECT *top_rect, DWORD flags )
2047 struct x11drv_escape_set_drawable escape;
2048 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2050 escape.code = X11DRV_SET_DRAWABLE;
2051 escape.mode = IncludeInferiors;
2052 escape.fbconfig_id = 0;
2053 escape.gl_drawable = 0;
2054 escape.pixmap = 0;
2055 escape.gl_copy = FALSE;
2057 if (top == hwnd)
2059 escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop );
2060 /* GL draws to the client area even for window DCs */
2061 escape.gl_drawable = data ? data->client_window : X11DRV_get_client_window( hwnd );
2062 if (data && IsIconic( hwnd ) && data->icon_window)
2064 escape.drawable = data->icon_window;
2066 else if (flags & DCX_WINDOW)
2067 escape.drawable = data ? data->whole_window : X11DRV_get_whole_window( hwnd );
2068 else
2069 escape.drawable = escape.gl_drawable;
2071 else
2073 escape.drawable = X11DRV_get_client_window( top );
2074 escape.fbconfig_id = data ? data->fbconfig_id : (XID)GetPropA( hwnd, fbconfig_id_prop );
2075 escape.gl_drawable = data ? data->gl_drawable : (Drawable)GetPropA( hwnd, gl_drawable_prop );
2076 escape.pixmap = data ? data->pixmap : (Pixmap)GetPropA( hwnd, pixmap_prop );
2077 escape.gl_copy = (escape.gl_drawable != 0);
2078 if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren;
2081 escape.dc_rect.left = win_rect->left - top_rect->left;
2082 escape.dc_rect.top = win_rect->top - top_rect->top;
2083 escape.dc_rect.right = win_rect->right - top_rect->left;
2084 escape.dc_rect.bottom = win_rect->bottom - top_rect->top;
2085 escape.drawable_rect.left = top_rect->left;
2086 escape.drawable_rect.top = top_rect->top;
2087 escape.drawable_rect.right = top_rect->right;
2088 escape.drawable_rect.bottom = top_rect->bottom;
2090 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2094 /***********************************************************************
2095 * X11DRV_ReleaseDC (X11DRV.@)
2097 void CDECL X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
2099 struct x11drv_escape_set_drawable escape;
2101 escape.code = X11DRV_SET_DRAWABLE;
2102 escape.drawable = root_window;
2103 escape.mode = IncludeInferiors;
2104 escape.drawable_rect = virtual_screen_rect;
2105 SetRect( &escape.dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left,
2106 virtual_screen_rect.bottom - virtual_screen_rect.top );
2107 OffsetRect( &escape.dc_rect, -escape.drawable_rect.left, -escape.drawable_rect.top );
2108 escape.fbconfig_id = 0;
2109 escape.gl_drawable = 0;
2110 escape.pixmap = 0;
2111 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2115 /***********************************************************************
2116 * SetCapture (X11DRV.@)
2118 void CDECL X11DRV_SetCapture( HWND hwnd, UINT flags )
2120 struct x11drv_thread_data *thread_data = x11drv_thread_data();
2122 if (!thread_data) return;
2123 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
2125 if (hwnd)
2127 Window grab_win = X11DRV_get_client_window( GetAncestor( hwnd, GA_ROOT ) );
2129 if (!grab_win) return;
2130 wine_tsx11_lock();
2131 XFlush( gdi_display );
2132 XGrabPointer( thread_data->display, grab_win, False,
2133 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
2134 GrabModeAsync, GrabModeAsync, None, None, CurrentTime );
2135 wine_tsx11_unlock();
2136 thread_data->grab_window = grab_win;
2138 else /* release capture */
2140 wine_tsx11_lock();
2141 XFlush( gdi_display );
2142 XUngrabPointer( thread_data->display, CurrentTime );
2143 XFlush( thread_data->display );
2144 wine_tsx11_unlock();
2145 thread_data->grab_window = None;
2150 /*****************************************************************
2151 * SetParent (X11DRV.@)
2153 void CDECL X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
2155 Display *display = thread_display();
2156 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2158 if (!data) return;
2159 if (parent == old_parent) return;
2161 if (parent != GetDesktopWindow()) /* a child window */
2163 if (old_parent == GetDesktopWindow())
2165 /* destroy the old X windows */
2166 destroy_whole_window( display, data, FALSE );
2167 destroy_icon_window( display, data );
2168 if (data->managed)
2170 data->managed = FALSE;
2171 RemovePropA( data->hwnd, managed_prop );
2175 else /* new top level window */
2177 /* FIXME: we ignore errors since we can't really recover anyway */
2178 create_whole_window( display, data );
2183 /*****************************************************************
2184 * SetFocus (X11DRV.@)
2186 * Set the X focus.
2188 void CDECL X11DRV_SetFocus( HWND hwnd )
2190 Display *display = thread_display();
2191 struct x11drv_win_data *data;
2192 XWindowChanges changes;
2193 DWORD timestamp;
2195 if (!(hwnd = GetAncestor( hwnd, GA_ROOT ))) return;
2196 if (!(data = X11DRV_get_win_data( hwnd ))) return;
2197 if (data->managed || !data->whole_window) return;
2199 if (EVENT_x11_time_to_win32_time(0))
2200 /* ICCCM says don't use CurrentTime, so try to use last message time if possible */
2201 /* FIXME: this is not entirely correct */
2202 timestamp = GetMessageTime() - EVENT_x11_time_to_win32_time(0);
2203 else
2204 timestamp = CurrentTime;
2206 /* Set X focus and install colormap */
2207 wine_tsx11_lock();
2208 changes.stack_mode = Above;
2209 XConfigureWindow( display, data->whole_window, CWStackMode, &changes );
2210 XSetInputFocus( display, data->whole_window, RevertToParent, timestamp );
2211 wine_tsx11_unlock();
2215 /***********************************************************************
2216 * WindowPosChanging (X11DRV.@)
2218 void CDECL X11DRV_WindowPosChanging( HWND hwnd, HWND insert_after, UINT swp_flags,
2219 const RECT *window_rect, const RECT *client_rect, RECT *visible_rect )
2221 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2222 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
2224 if (!data)
2226 /* create the win data if the window is being made visible */
2227 if (!(style & WS_VISIBLE) && !(swp_flags & SWP_SHOWWINDOW)) return;
2228 if (!(data = X11DRV_create_win_data( hwnd ))) return;
2231 /* check if we need to switch the window to managed */
2232 if (!data->managed && data->whole_window && is_window_managed( hwnd, swp_flags, window_rect ))
2234 TRACE( "making win %p/%lx managed\n", hwnd, data->whole_window );
2235 if (data->mapped) unmap_window( thread_display(), data );
2236 data->managed = TRUE;
2237 SetPropA( hwnd, managed_prop, (HANDLE)1 );
2240 *visible_rect = *window_rect;
2241 X11DRV_window_to_X_rect( data, visible_rect );
2245 /***********************************************************************
2246 * WindowPosChanged (X11DRV.@)
2248 void CDECL X11DRV_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_flags,
2249 const RECT *rectWindow, const RECT *rectClient,
2250 const RECT *visible_rect, const RECT *valid_rects )
2252 struct x11drv_thread_data *thread_data;
2253 Display *display;
2254 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2255 DWORD new_style = GetWindowLongW( hwnd, GWL_STYLE );
2256 RECT old_window_rect, old_whole_rect, old_client_rect;
2257 int event_type;
2259 if (!data) return;
2261 thread_data = x11drv_thread_data();
2262 display = thread_data->display;
2264 old_window_rect = data->window_rect;
2265 old_whole_rect = data->whole_rect;
2266 old_client_rect = data->client_rect;
2267 data->window_rect = *rectWindow;
2268 data->whole_rect = *visible_rect;
2269 data->client_rect = *rectClient;
2271 TRACE( "win %p window %s client %s style %08x flags %08x\n",
2272 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style, swp_flags );
2274 if (!IsRectEmpty( &valid_rects[0] ))
2276 int x_offset = old_whole_rect.left - data->whole_rect.left;
2277 int y_offset = old_whole_rect.top - data->whole_rect.top;
2279 /* if all that happened is that the whole window moved, copy everything */
2280 if (!(swp_flags & SWP_FRAMECHANGED) &&
2281 old_whole_rect.right - data->whole_rect.right == x_offset &&
2282 old_whole_rect.bottom - data->whole_rect.bottom == y_offset &&
2283 old_client_rect.left - data->client_rect.left == x_offset &&
2284 old_client_rect.right - data->client_rect.right == x_offset &&
2285 old_client_rect.top - data->client_rect.top == y_offset &&
2286 old_client_rect.bottom - data->client_rect.bottom == y_offset &&
2287 !memcmp( &valid_rects[0], &data->client_rect, sizeof(RECT) ))
2289 /* if we have an X window the bits will be moved by the X server */
2290 if (!data->whole_window)
2291 move_window_bits( data, &old_whole_rect, &data->whole_rect, &old_client_rect );
2293 else
2294 move_window_bits( data, &valid_rects[1], &valid_rects[0], &old_client_rect );
2297 wine_tsx11_lock();
2298 XFlush( gdi_display ); /* make sure painting is done before we move the window */
2299 wine_tsx11_unlock();
2301 sync_client_position( display, data, swp_flags, &old_client_rect, &old_whole_rect );
2303 if (!data->whole_window) return;
2305 /* check if we are currently processing an event relevant to this window */
2306 event_type = 0;
2307 if (thread_data->current_event && thread_data->current_event->xany.window == data->whole_window)
2308 event_type = thread_data->current_event->type;
2310 if (event_type != ConfigureNotify && event_type != PropertyNotify)
2311 event_type = 0; /* ignore other events */
2313 if (data->mapped)
2315 if (((swp_flags & SWP_HIDEWINDOW) && !(new_style & WS_VISIBLE)) ||
2316 (!event_type && !is_window_rect_mapped( rectWindow )))
2317 unmap_window( display, data );
2320 /* don't change position if we are about to minimize or maximize a managed window */
2321 if (!event_type &&
2322 !(data->managed && (swp_flags & SWP_STATECHANGED) && (new_style & (WS_MINIMIZE|WS_MAXIMIZE))))
2323 sync_window_position( display, data, swp_flags,
2324 &old_window_rect, &old_whole_rect, &old_client_rect );
2326 if ((new_style & WS_VISIBLE) &&
2327 ((new_style & WS_MINIMIZE) || is_window_rect_mapped( rectWindow )))
2329 if (!data->mapped || (swp_flags & (SWP_FRAMECHANGED|SWP_STATECHANGED)))
2330 set_wm_hints( display, data );
2332 if (!data->mapped)
2334 map_window( display, data, new_style );
2336 else if ((swp_flags & SWP_STATECHANGED) && (!data->iconic != !(new_style & WS_MINIMIZE)))
2338 data->iconic = (new_style & WS_MINIMIZE) != 0;
2339 TRACE( "changing win %p iconic state to %u\n", data->hwnd, data->iconic );
2340 wine_tsx11_lock();
2341 if (data->iconic)
2342 XIconifyWindow( display, data->whole_window, DefaultScreen(display) );
2343 else if (is_window_rect_mapped( rectWindow ))
2344 XMapWindow( display, data->whole_window );
2345 wine_tsx11_unlock();
2346 update_net_wm_states( display, data );
2348 else if (!event_type)
2350 update_net_wm_states( display, data );
2354 wine_tsx11_lock();
2355 XFlush( display ); /* make sure changes are done before we start painting again */
2356 wine_tsx11_unlock();
2360 /***********************************************************************
2361 * ShowWindow (X11DRV.@)
2363 UINT CDECL X11DRV_ShowWindow( HWND hwnd, INT cmd, RECT *rect, UINT swp )
2365 int x, y;
2366 unsigned int width, height, border, depth;
2367 Window root, top;
2368 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
2369 struct x11drv_thread_data *thread_data = x11drv_thread_data();
2370 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2372 if (!data || !data->whole_window || !data->managed || !data->mapped || data->iconic) return swp;
2373 if (style & WS_MINIMIZE) return swp;
2374 if (IsRectEmpty( rect )) return swp;
2376 /* only fetch the new rectangle if the ShowWindow was a result of a window manager event */
2378 if (!thread_data->current_event || thread_data->current_event->xany.window != data->whole_window)
2379 return swp;
2381 if (thread_data->current_event->type != ConfigureNotify &&
2382 thread_data->current_event->type != PropertyNotify)
2383 return swp;
2385 TRACE( "win %p/%lx cmd %d at %s flags %08x\n",
2386 hwnd, data->whole_window, cmd, wine_dbgstr_rect(rect), swp );
2388 wine_tsx11_lock();
2389 XGetGeometry( thread_data->display, data->whole_window,
2390 &root, &x, &y, &width, &height, &border, &depth );
2391 XTranslateCoordinates( thread_data->display, data->whole_window, root, 0, 0, &x, &y, &top );
2392 wine_tsx11_unlock();
2393 rect->left = x;
2394 rect->top = y;
2395 rect->right = x + width;
2396 rect->bottom = y + height;
2397 OffsetRect( rect, virtual_screen_rect.left, virtual_screen_rect.top );
2398 X11DRV_X_to_window_rect( data, rect );
2399 return swp & ~(SWP_NOMOVE | SWP_NOCLIENTMOVE | SWP_NOSIZE | SWP_NOCLIENTSIZE);
2403 /**********************************************************************
2404 * SetWindowIcon (X11DRV.@)
2406 * hIcon or hIconSm has changed (or is being initialised for the
2407 * first time). Complete the X11 driver-specific initialisation
2408 * and set the window hints.
2410 * This is not entirely correct, may need to create
2411 * an icon window and set the pixmap as a background
2413 void CDECL X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
2415 Display *display = thread_display();
2416 struct x11drv_win_data *data;
2419 if (!(data = X11DRV_get_win_data( hwnd ))) return;
2420 if (!data->whole_window) return;
2421 if (!data->managed) return;
2423 if (data->wm_hints)
2425 if (type == ICON_BIG) set_icon_hints( display, data, icon, 0 );
2426 else set_icon_hints( display, data, 0, icon );
2427 wine_tsx11_lock();
2428 XSetWMHints( display, data->whole_window, data->wm_hints );
2429 wine_tsx11_unlock();
2434 /***********************************************************************
2435 * SetWindowRgn (X11DRV.@)
2437 * Assign specified region to window (for non-rectangular windows)
2439 int CDECL X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
2441 struct x11drv_win_data *data;
2443 if ((data = X11DRV_get_win_data( hwnd )))
2445 sync_window_region( thread_display(), data, hrgn );
2447 else if (X11DRV_get_whole_window( hwnd ))
2449 SendMessageW( hwnd, WM_X11DRV_SET_WIN_REGION, 0, 0 );
2451 return TRUE;
2455 /***********************************************************************
2456 * SetLayeredWindowAttributes (X11DRV.@)
2458 * Set transparency attributes for a layered window.
2460 void CDECL X11DRV_SetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags )
2462 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
2464 if (data)
2466 if (data->whole_window)
2467 sync_window_opacity( thread_display(), data->whole_window, key, alpha, flags );
2469 else
2471 Window win = X11DRV_get_whole_window( hwnd );
2472 if (win) sync_window_opacity( gdi_display, win, key, alpha, flags );
2477 /**********************************************************************
2478 * X11DRV_WindowMessage (X11DRV.@)
2480 LRESULT CDECL X11DRV_WindowMessage( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
2482 struct x11drv_win_data *data;
2484 switch(msg)
2486 case WM_X11DRV_ACQUIRE_SELECTION:
2487 return X11DRV_AcquireClipboard( hwnd );
2488 case WM_X11DRV_SET_WIN_FORMAT:
2489 return set_win_format( hwnd, (XID)wp );
2490 case WM_X11DRV_SET_WIN_REGION:
2491 if ((data = X11DRV_get_win_data( hwnd ))) sync_window_region( thread_display(), data, (HRGN)1 );
2492 return 0;
2493 case WM_X11DRV_RESIZE_DESKTOP:
2494 X11DRV_resize_desktop( LOWORD(lp), HIWORD(lp) );
2495 return 0;
2496 case WM_X11DRV_SET_CURSOR:
2497 set_window_cursor( hwnd, (HCURSOR)lp );
2498 return 0;
2499 default:
2500 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg, hwnd, wp, lp );
2501 return 0;
2506 /***********************************************************************
2507 * is_netwm_supported
2509 static BOOL is_netwm_supported( Display *display, Atom atom )
2511 static Atom *net_supported;
2512 static int net_supported_count = -1;
2513 int i;
2515 wine_tsx11_lock();
2516 if (net_supported_count == -1)
2518 Atom type;
2519 int format;
2520 unsigned long count, remaining;
2522 if (!XGetWindowProperty( display, DefaultRootWindow(display), x11drv_atom(_NET_SUPPORTED), 0,
2523 ~0UL, False, XA_ATOM, &type, &format, &count,
2524 &remaining, (unsigned char **)&net_supported ))
2525 net_supported_count = get_property_size( format, count ) / sizeof(Atom);
2526 else
2527 net_supported_count = 0;
2529 wine_tsx11_unlock();
2531 for (i = 0; i < net_supported_count; i++)
2532 if (net_supported[i] == atom) return TRUE;
2533 return FALSE;
2537 /***********************************************************************
2538 * SysCommand (X11DRV.@)
2540 * Perform WM_SYSCOMMAND handling.
2542 LRESULT CDECL X11DRV_SysCommand( HWND hwnd, WPARAM wparam, LPARAM lparam )
2544 WPARAM hittest = wparam & 0x0f;
2545 DWORD dwPoint;
2546 int x, y, dir;
2547 XEvent xev;
2548 Display *display = thread_display();
2549 struct x11drv_win_data *data;
2551 if (!(data = X11DRV_get_win_data( hwnd ))) return -1;
2552 if (!data->whole_window || !data->managed || !data->mapped) return -1;
2554 switch (wparam & 0xfff0)
2556 case SC_MOVE:
2557 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
2558 else dir = _NET_WM_MOVERESIZE_MOVE;
2559 break;
2560 case SC_SIZE:
2561 /* windows without WS_THICKFRAME are not resizable through the window manager */
2562 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) return -1;
2564 switch (hittest)
2566 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
2567 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
2568 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
2569 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
2570 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
2571 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
2572 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
2573 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
2574 default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break;
2576 break;
2578 case SC_KEYMENU:
2579 /* prevent a simple ALT press+release from activating the system menu,
2580 * as that can get confusing on managed windows */
2581 if ((WCHAR)lparam) return -1; /* got an explicit char */
2582 if (GetMenu( hwnd )) return -1; /* window has a real menu */
2583 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_SYSMENU)) return -1; /* no system menu */
2584 TRACE( "ignoring SC_KEYMENU wp %lx lp %lx\n", wparam, lparam );
2585 return 0;
2587 default:
2588 return -1;
2591 if (IsZoomed(hwnd)) return -1;
2593 if (!is_netwm_supported( display, x11drv_atom(_NET_WM_MOVERESIZE) ))
2595 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
2596 return -1;
2599 dwPoint = GetMessagePos();
2600 x = (short)LOWORD(dwPoint);
2601 y = (short)HIWORD(dwPoint);
2603 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd, x, y, dir);
2605 xev.xclient.type = ClientMessage;
2606 xev.xclient.window = X11DRV_get_whole_window(hwnd);
2607 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
2608 xev.xclient.serial = 0;
2609 xev.xclient.display = display;
2610 xev.xclient.send_event = True;
2611 xev.xclient.format = 32;
2612 xev.xclient.data.l[0] = x - virtual_screen_rect.left; /* x coord */
2613 xev.xclient.data.l[1] = y - virtual_screen_rect.top; /* y coord */
2614 xev.xclient.data.l[2] = dir; /* direction */
2615 xev.xclient.data.l[3] = 1; /* button */
2616 xev.xclient.data.l[4] = 0; /* unused */
2618 /* need to ungrab the pointer that may have been automatically grabbed
2619 * with a ButtonPress event */
2620 wine_tsx11_lock();
2621 XUngrabPointer( display, CurrentTime );
2622 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
2623 wine_tsx11_unlock();
2624 return 0;