push 890e8d0be0529bec143455a9e70201bcaf74a118
[wine/hacks.git] / dlls / winex11.drv / winpos.c
blobf215f41a0449fa0a3ccc4700b48183059cc8ca79
1 /*
2 * Window position related functions.
4 * Copyright 1993, 1994, 1995, 2001 Alexandre Julliard
5 * Copyright 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winerror.h"
33 #include "wine/wingdi16.h"
35 #include "x11drv.h"
37 #include "wine/server.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
42 #define SWP_AGG_NOPOSCHANGE \
43 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
45 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
46 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
47 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
48 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
49 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
50 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
51 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
52 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
53 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
54 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
55 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
57 #define _NET_WM_STATE_REMOVE 0
58 #define _NET_WM_STATE_ADD 1
59 #define _NET_WM_STATE_TOGGLE 2
61 static const char managed_prop[] = "__wine_x11_managed";
63 /***********************************************************************
64 * X11DRV_Expose
66 void X11DRV_Expose( HWND hwnd, XEvent *xev )
68 XExposeEvent *event = &xev->xexpose;
69 RECT rect;
70 struct x11drv_win_data *data;
71 int flags = RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN;
73 TRACE( "win %p (%lx) %d,%d %dx%d\n",
74 hwnd, event->window, event->x, event->y, event->width, event->height );
76 if (!(data = X11DRV_get_win_data( hwnd ))) return;
78 if (event->window == data->whole_window)
80 rect.left = data->whole_rect.left + event->x;
81 rect.top = data->whole_rect.top + event->y;
82 flags |= RDW_FRAME;
84 else
86 rect.left = data->client_rect.left + event->x;
87 rect.top = data->client_rect.top + event->y;
89 rect.right = rect.left + event->width;
90 rect.bottom = rect.top + event->height;
92 if (event->window == root_window)
93 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
95 SERVER_START_REQ( update_window_zorder )
97 req->window = hwnd;
98 req->rect.left = rect.left;
99 req->rect.top = rect.top;
100 req->rect.right = rect.right;
101 req->rect.bottom = rect.bottom;
102 wine_server_call( req );
104 SERVER_END_REQ;
106 /* make position relative to client area instead of parent */
107 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
108 RedrawWindow( hwnd, &rect, 0, flags );
111 /***********************************************************************
112 * SetWindowStyle (X11DRV.@)
114 * Update the X state of a window to reflect a style change
116 void X11DRV_SetWindowStyle( HWND hwnd, DWORD old_style )
118 Display *display = thread_display();
119 struct x11drv_win_data *data;
120 DWORD new_style, changed;
122 if (hwnd == GetDesktopWindow()) return;
123 new_style = GetWindowLongW( hwnd, GWL_STYLE );
124 changed = new_style ^ old_style;
126 if ((changed & WS_VISIBLE) && (new_style & WS_VISIBLE))
128 /* we don't unmap windows, that causes trouble with the window manager */
129 if (!(data = X11DRV_get_win_data( hwnd )) &&
130 !(data = X11DRV_create_win_data( hwnd ))) return;
132 if (data->whole_window && X11DRV_is_window_rect_mapped( &data->window_rect ))
134 X11DRV_set_wm_hints( display, data );
135 if (!data->mapped)
137 TRACE( "mapping win %p/%lx\n", hwnd, data->whole_window );
138 wait_for_withdrawn_state( display, data, TRUE );
139 X11DRV_sync_window_style( display, data );
140 wine_tsx11_lock();
141 XMapWindow( display, data->whole_window );
142 wine_tsx11_unlock();
143 data->mapped = TRUE;
144 data->iconic = (new_style & WS_MINIMIZE) != 0;
149 if (changed & WS_DISABLED)
151 data = X11DRV_get_win_data( hwnd );
152 if (data && data->wm_hints)
154 wine_tsx11_lock();
155 data->wm_hints->input = !(new_style & WS_DISABLED);
156 XSetWMHints( display, data->whole_window, data->wm_hints );
157 wine_tsx11_unlock();
163 /***********************************************************************
164 * update_net_wm_states
166 static void update_net_wm_states( Display *display, struct x11drv_win_data *data )
168 static const unsigned int state_atoms[NB_NET_WM_STATES] =
170 XATOM__NET_WM_STATE_FULLSCREEN,
171 XATOM__NET_WM_STATE_ABOVE,
172 XATOM__NET_WM_STATE_MAXIMIZED_VERT,
173 XATOM__NET_WM_STATE_SKIP_PAGER,
174 XATOM__NET_WM_STATE_SKIP_TASKBAR
177 DWORD i, style, ex_style, new_state = 0;
178 XEvent xev;
180 if (!data->managed) return;
181 if (!data->mapped) return;
183 style = GetWindowLongW( data->hwnd, GWL_STYLE );
184 if (style & WS_MAXIMIZE) new_state |= (1 << NET_WM_STATE_MAXIMIZED);
186 if (!(style & WS_MAXIMIZE) &&
187 data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width &&
188 data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height)
189 new_state |= (1 << NET_WM_STATE_FULLSCREEN);
191 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
192 if (ex_style & WS_EX_TOPMOST)
193 new_state |= (1 << NET_WM_STATE_ABOVE);
194 if (ex_style & WS_EX_TOOLWINDOW)
195 new_state |= (1 << NET_WM_STATE_SKIP_TASKBAR) | (1 << NET_WM_STATE_SKIP_PAGER);
197 xev.xclient.type = ClientMessage;
198 xev.xclient.window = data->whole_window;
199 xev.xclient.message_type = x11drv_atom(_NET_WM_STATE);
200 xev.xclient.serial = 0;
201 xev.xclient.display = display;
202 xev.xclient.send_event = True;
203 xev.xclient.format = 32;
204 xev.xclient.data.l[3] = 1;
206 for (i = 0; i < NB_NET_WM_STATES; i++)
208 if (!((data->net_wm_state ^ new_state) & (1 << i))) continue; /* unchanged */
210 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
211 i, data->hwnd, data->whole_window,
212 (new_state & (1 << i)) != 0, (data->net_wm_state & (1 << i)) != 0 );
214 xev.xclient.data.l[0] = (new_state & (1 << i)) ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
215 xev.xclient.data.l[1] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM];
216 xev.xclient.data.l[2] = ((state_atoms[i] == XATOM__NET_WM_STATE_MAXIMIZED_VERT) ?
217 x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ) : 0);
218 wine_tsx11_lock();
219 XSendEvent( display, root_window, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev );
220 wine_tsx11_unlock();
222 data->net_wm_state = new_state;
226 /***********************************************************************
227 * move_window_bits
229 * Move the window bits when a window is moved.
231 static void move_window_bits( struct x11drv_win_data *data, const RECT *old_rect, const RECT *new_rect,
232 const RECT *old_client_rect )
234 RECT src_rect = *old_rect;
235 RECT dst_rect = *new_rect;
236 HDC hdc_src, hdc_dst;
237 INT code;
238 HRGN rgn = 0;
239 HWND parent = 0;
241 if (!data->whole_window)
243 OffsetRect( &dst_rect, -data->window_rect.left, -data->window_rect.top );
244 parent = GetAncestor( data->hwnd, GA_PARENT );
245 hdc_src = GetDCEx( parent, 0, DCX_CACHE );
246 hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE | DCX_WINDOW );
248 else
250 OffsetRect( &dst_rect, -data->client_rect.left, -data->client_rect.top );
251 /* make src rect relative to the old position of the window */
252 OffsetRect( &src_rect, -old_client_rect->left, -old_client_rect->top );
253 if (dst_rect.left == src_rect.left && dst_rect.top == src_rect.top) return;
254 hdc_src = hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE );
257 code = X11DRV_START_EXPOSURES;
258 ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
260 TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n",
261 data->hwnd, data->whole_window, data->client_window,
262 wine_dbgstr_rect(&src_rect), wine_dbgstr_rect(&dst_rect) );
263 BitBlt( hdc_dst, dst_rect.left, dst_rect.top,
264 dst_rect.right - dst_rect.left, dst_rect.bottom - dst_rect.top,
265 hdc_src, src_rect.left, src_rect.top, SRCCOPY );
267 code = X11DRV_END_EXPOSURES;
268 ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, sizeof(rgn), (LPSTR)&rgn );
270 ReleaseDC( data->hwnd, hdc_dst );
271 if (hdc_src != hdc_dst) ReleaseDC( parent, hdc_src );
273 if (rgn)
275 if (!data->whole_window)
277 /* map region to client rect since we are using DCX_WINDOW */
278 OffsetRgn( rgn, data->window_rect.left - data->client_rect.left,
279 data->window_rect.top - data->client_rect.top );
280 RedrawWindow( data->hwnd, NULL, rgn,
281 RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ALLCHILDREN );
283 else RedrawWindow( data->hwnd, NULL, rgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
284 DeleteObject( rgn );
288 /***********************************************************************
289 * SetWindowPos (X11DRV.@)
291 void X11DRV_SetWindowPos( HWND hwnd, HWND insert_after, UINT swp_flags,
292 const RECT *rectWindow, const RECT *rectClient,
293 const RECT *visible_rect, const RECT *valid_rects )
295 Display *display = thread_display();
296 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
297 DWORD new_style = GetWindowLongW( hwnd, GWL_STYLE );
298 RECT old_window_rect, old_whole_rect, old_client_rect;
300 if (!data)
302 /* create the win data if the window is being made visible */
303 if (!(new_style & WS_VISIBLE)) return;
304 if (!(data = X11DRV_create_win_data( hwnd ))) return;
307 /* check if we need to switch the window to managed */
308 if (!data->managed && data->whole_window && is_window_managed( hwnd, swp_flags, rectWindow ))
310 TRACE( "making win %p/%lx managed\n", hwnd, data->whole_window );
311 data->managed = TRUE;
312 SetPropA( hwnd, managed_prop, (HANDLE)1 );
313 if (data->mapped)
315 wine_tsx11_lock();
316 XUnmapWindow( display, data->whole_window );
317 wine_tsx11_unlock();
318 data->mapped = FALSE;
322 old_window_rect = data->window_rect;
323 old_whole_rect = data->whole_rect;
324 old_client_rect = data->client_rect;
325 data->window_rect = *rectWindow;
326 data->whole_rect = *rectWindow;
327 data->client_rect = *rectClient;
328 X11DRV_window_to_X_rect( data, &data->whole_rect );
329 if (memcmp( &visible_rect, &data->whole_rect, sizeof(RECT) ))
331 TRACE( "%p: need to update visible rect %s -> %s\n", hwnd,
332 wine_dbgstr_rect(visible_rect), wine_dbgstr_rect(&data->whole_rect) );
333 SERVER_START_REQ( set_window_visible_rect )
335 req->handle = hwnd;
336 req->flags = swp_flags;
337 req->visible.left = data->whole_rect.left;
338 req->visible.top = data->whole_rect.top;
339 req->visible.right = data->whole_rect.right;
340 req->visible.bottom = data->whole_rect.bottom;
341 wine_server_call( req );
343 SERVER_END_REQ;
346 TRACE( "win %p window %s client %s style %08x flags %08x\n",
347 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style, swp_flags );
349 if (!IsRectEmpty( &valid_rects[0] ))
351 int x_offset = old_whole_rect.left - data->whole_rect.left;
352 int y_offset = old_whole_rect.top - data->whole_rect.top;
354 /* if all that happened is that the whole window moved, copy everything */
355 if (!(swp_flags & SWP_FRAMECHANGED) &&
356 old_whole_rect.right - data->whole_rect.right == x_offset &&
357 old_whole_rect.bottom - data->whole_rect.bottom == y_offset &&
358 old_client_rect.left - data->client_rect.left == x_offset &&
359 old_client_rect.right - data->client_rect.right == x_offset &&
360 old_client_rect.top - data->client_rect.top == y_offset &&
361 old_client_rect.bottom - data->client_rect.bottom == y_offset &&
362 !memcmp( &valid_rects[0], &data->client_rect, sizeof(RECT) ))
364 /* if we have an X window the bits will be moved by the X server */
365 if (!data->whole_window)
366 move_window_bits( data, &old_whole_rect, &data->whole_rect, &old_client_rect );
368 else
369 move_window_bits( data, &valid_rects[1], &valid_rects[0], &old_client_rect );
372 X11DRV_sync_client_position( display, data, swp_flags, &old_client_rect, &old_whole_rect );
374 if (!data->whole_window || data->lock_changes) return; /* nothing more to do */
376 if (data->mapped && (!(new_style & WS_VISIBLE) || !X11DRV_is_window_rect_mapped( rectWindow )))
378 TRACE( "unmapping win %p/%lx\n", hwnd, data->whole_window );
379 wait_for_withdrawn_state( display, data, FALSE );
380 wine_tsx11_lock();
381 if (data->managed) XWithdrawWindow( display, data->whole_window, DefaultScreen(display) );
382 else XUnmapWindow( display, data->whole_window );
383 wine_tsx11_unlock();
384 data->mapped = FALSE;
385 data->net_wm_state = 0;
388 /* don't change position if we are about to minimize or maximize a managed window */
389 if (!(data->managed && (swp_flags & SWP_STATECHANGED) && (new_style & (WS_MINIMIZE|WS_MAXIMIZE))))
390 X11DRV_sync_window_position( display, data, swp_flags, &old_client_rect, &old_whole_rect );
392 if ((new_style & WS_VISIBLE) &&
393 ((new_style & WS_MINIMIZE) || X11DRV_is_window_rect_mapped( rectWindow )))
395 if (!data->mapped || (swp_flags & (SWP_FRAMECHANGED|SWP_STATECHANGED)))
396 X11DRV_set_wm_hints( display, data );
398 if (!data->mapped)
400 TRACE( "mapping win %p/%lx\n", hwnd, data->whole_window );
401 wait_for_withdrawn_state( display, data, TRUE );
402 X11DRV_sync_window_style( display, data );
403 wine_tsx11_lock();
404 XMapWindow( display, data->whole_window );
405 XFlush( display );
406 wine_tsx11_unlock();
407 data->mapped = TRUE;
408 data->iconic = (new_style & WS_MINIMIZE) != 0;
410 else if ((swp_flags & SWP_STATECHANGED) && (!data->iconic != !(new_style & WS_MINIMIZE)))
412 data->iconic = (new_style & WS_MINIMIZE) != 0;
413 TRACE( "changing win %p iconic state to %u\n", data->hwnd, data->iconic );
414 wine_tsx11_lock();
415 if (data->iconic)
416 XIconifyWindow( display, data->whole_window, DefaultScreen(display) );
417 else if (X11DRV_is_window_rect_mapped( rectWindow ))
418 XMapWindow( display, data->whole_window );
419 wine_tsx11_unlock();
421 update_net_wm_states( display, data );
426 /**********************************************************************
427 * X11DRV_MapNotify
429 void X11DRV_MapNotify( HWND hwnd, XEvent *event )
431 struct x11drv_win_data *data;
432 int state;
434 if (!(data = X11DRV_get_win_data( hwnd ))) return;
435 if (!data->mapped) return;
437 if (!data->managed)
439 HWND hwndFocus = GetFocus();
440 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
441 return;
443 if (!data->iconic) return;
445 state = get_window_wm_state( event->xmap.display, data );
446 if (state == NormalState)
448 int x, y;
449 unsigned int width, height, border, depth;
450 Window root, top;
451 WINDOWPLACEMENT wp;
452 RECT rect;
454 /* FIXME: hack */
455 wine_tsx11_lock();
456 XGetGeometry( event->xmap.display, data->whole_window, &root, &x, &y, &width, &height,
457 &border, &depth );
458 XTranslateCoordinates( event->xmap.display, data->whole_window, root, 0, 0, &x, &y, &top );
459 wine_tsx11_unlock();
460 rect.left = x;
461 rect.top = y;
462 rect.right = x + width;
463 rect.bottom = y + height;
464 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
465 X11DRV_X_to_window_rect( data, &rect );
467 wp.length = sizeof(wp);
468 GetWindowPlacement( hwnd, &wp );
469 wp.flags = 0;
470 wp.showCmd = SW_RESTORE;
471 wp.rcNormalPosition = rect;
473 TRACE( "restoring win %p/%lx\n", hwnd, data->whole_window );
474 data->iconic = FALSE;
475 data->lock_changes++;
476 SetWindowPlacement( hwnd, &wp );
477 data->lock_changes--;
479 else TRACE( "win %p/%lx ignoring since state=%d\n", hwnd, data->whole_window, state );
483 /**********************************************************************
484 * X11DRV_UnmapNotify
486 void X11DRV_UnmapNotify( HWND hwnd, XEvent *event )
488 struct x11drv_win_data *data;
489 int state;
491 if (!(data = X11DRV_get_win_data( hwnd ))) return;
492 if (!data->managed || !data->mapped || data->iconic) return;
494 state = get_window_wm_state( event->xunmap.display, data );
495 if (state == IconicState)
497 TRACE( "minimizing win %p/%lx\n", hwnd, data->whole_window );
498 data->iconic = TRUE;
499 data->lock_changes++;
500 ShowWindow( hwnd, SW_MINIMIZE );
501 data->lock_changes--;
503 else TRACE( "win %p/%lx ignoring since state=%d\n", hwnd, data->whole_window, state );
506 struct desktop_resize_data
508 RECT old_screen_rect;
509 RECT old_virtual_rect;
512 static BOOL CALLBACK update_windows_on_desktop_resize( HWND hwnd, LPARAM lparam )
514 struct x11drv_win_data *data;
515 Display *display = thread_display();
516 struct desktop_resize_data *resize_data = (struct desktop_resize_data *)lparam;
517 int mask = 0;
519 if (!(data = X11DRV_get_win_data( hwnd ))) return TRUE;
521 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)
523 /* update the full screen state */
524 update_net_wm_states( display, data );
527 if (resize_data->old_virtual_rect.left != virtual_screen_rect.left) mask |= CWX;
528 if (resize_data->old_virtual_rect.top != virtual_screen_rect.top) mask |= CWY;
529 if (mask && data->whole_window)
531 XWindowChanges changes;
533 wine_tsx11_lock();
534 changes.x = data->whole_rect.left - virtual_screen_rect.left;
535 changes.y = data->whole_rect.top - virtual_screen_rect.top;
536 XReconfigureWMWindow( display, data->whole_window,
537 DefaultScreen(display), mask, &changes );
538 wine_tsx11_unlock();
540 return TRUE;
544 /***********************************************************************
545 * X11DRV_resize_desktop
547 void X11DRV_resize_desktop( unsigned int width, unsigned int height )
549 HWND hwnd = GetDesktopWindow();
550 struct desktop_resize_data resize_data;
552 SetRect( &resize_data.old_screen_rect, 0, 0, screen_width, screen_height );
553 resize_data.old_virtual_rect = virtual_screen_rect;
555 xinerama_init( width, height );
557 if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
559 SendMessageW( hwnd, WM_X11DRV_RESIZE_DESKTOP, 0, MAKELPARAM( width, height ) );
561 else
563 TRACE( "desktop %p change to (%dx%d)\n", hwnd, width, height );
564 SetWindowPos( hwnd, 0, virtual_screen_rect.left, virtual_screen_rect.top,
565 virtual_screen_rect.right - virtual_screen_rect.left,
566 virtual_screen_rect.bottom - virtual_screen_rect.top,
567 SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE );
568 SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_bpp,
569 MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
572 EnumWindows( update_windows_on_desktop_resize, (LPARAM)&resize_data );
576 /***********************************************************************
577 * X11DRV_ConfigureNotify
579 void X11DRV_ConfigureNotify( HWND hwnd, XEvent *xev )
581 XConfigureEvent *event = &xev->xconfigure;
582 struct x11drv_win_data *data;
583 RECT rect;
584 UINT flags;
585 int cx, cy, x = event->x, y = event->y;
587 if (!hwnd) return;
588 if (!(data = X11DRV_get_win_data( hwnd ))) return;
590 /* Get geometry */
592 if (!event->send_event) /* normal event, need to map coordinates to the root */
594 Window child;
595 wine_tsx11_lock();
596 XTranslateCoordinates( event->display, data->whole_window, root_window,
597 0, 0, &x, &y, &child );
598 wine_tsx11_unlock();
600 rect.left = x;
601 rect.top = y;
602 rect.right = x + event->width;
603 rect.bottom = y + event->height;
604 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
605 TRACE( "win %p new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
606 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
607 event->x, event->y, event->width, event->height );
608 X11DRV_X_to_window_rect( data, &rect );
610 x = rect.left;
611 y = rect.top;
612 cx = rect.right - rect.left;
613 cy = rect.bottom - rect.top;
614 flags = SWP_NOACTIVATE | SWP_NOZORDER;
616 /* Compare what has changed */
618 GetWindowRect( hwnd, &rect );
619 if (rect.left == x && rect.top == y) flags |= SWP_NOMOVE;
620 else
621 TRACE( "%p moving from (%d,%d) to (%d,%d)\n",
622 hwnd, rect.left, rect.top, x, y );
624 if ((rect.right - rect.left == cx && rect.bottom - rect.top == cy) ||
625 IsIconic(hwnd) ||
626 (IsRectEmpty( &rect ) && event->width == 1 && event->height == 1))
628 if (flags & SWP_NOMOVE) return; /* if nothing changed, don't do anything */
629 flags |= SWP_NOSIZE;
631 else
632 TRACE( "%p resizing from (%dx%d) to (%dx%d)\n",
633 hwnd, rect.right - rect.left, rect.bottom - rect.top, cx, cy );
635 data->lock_changes++;
636 SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
637 data->lock_changes--;
641 /***********************************************************************
642 * is_netwm_supported
644 static BOOL is_netwm_supported( Display *display, Atom atom )
646 static Atom *net_supported;
647 static int net_supported_count = -1;
648 int i;
650 wine_tsx11_lock();
651 if (net_supported_count == -1)
653 Atom type;
654 int format;
655 unsigned long count, remaining;
657 if (!XGetWindowProperty( display, DefaultRootWindow(display), x11drv_atom(_NET_SUPPORTED), 0,
658 ~0UL, False, XA_ATOM, &type, &format, &count,
659 &remaining, (unsigned char **)&net_supported ))
660 net_supported_count = count * (format / 8) / sizeof(Atom);
661 else
662 net_supported_count = 0;
664 wine_tsx11_unlock();
666 for (i = 0; i < net_supported_count; i++)
667 if (net_supported[i] == atom) return TRUE;
668 return FALSE;
672 /***********************************************************************
673 * SysCommandSizeMove (X11DRV.@)
675 * Perform SC_MOVE and SC_SIZE commands.
677 BOOL X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wparam )
679 WPARAM syscommand = wparam & 0xfff0;
680 WPARAM hittest = wparam & 0x0f;
681 DWORD dwPoint;
682 int x, y, dir;
683 XEvent xev;
684 Display *display = thread_display();
685 struct x11drv_win_data *data;
687 if (!(data = X11DRV_get_win_data( hwnd ))) return FALSE;
688 if (!data->whole_window || !data->managed) return FALSE;
690 if (!is_netwm_supported( display, x11drv_atom(_NET_WM_MOVERESIZE) ))
692 TRACE( "_NET_WM_MOVERESIZE not supported\n" );
693 return FALSE;
696 if (syscommand == SC_MOVE)
698 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
699 else dir = _NET_WM_MOVERESIZE_MOVE;
701 else
703 /* windows without WS_THICKFRAME are not resizable through the window manager */
704 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) return FALSE;
706 switch (hittest)
708 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
709 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
710 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
711 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
712 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
713 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
714 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
715 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
716 default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break;
720 dwPoint = GetMessagePos();
721 x = (short)LOWORD(dwPoint);
722 y = (short)HIWORD(dwPoint);
724 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd, x, y, dir);
726 xev.xclient.type = ClientMessage;
727 xev.xclient.window = X11DRV_get_whole_window(hwnd);
728 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
729 xev.xclient.serial = 0;
730 xev.xclient.display = display;
731 xev.xclient.send_event = True;
732 xev.xclient.format = 32;
733 xev.xclient.data.l[0] = x; /* x coord */
734 xev.xclient.data.l[1] = y; /* y coord */
735 xev.xclient.data.l[2] = dir; /* direction */
736 xev.xclient.data.l[3] = 1; /* button */
737 xev.xclient.data.l[4] = 0; /* unused */
739 /* need to ungrab the pointer that may have been automatically grabbed
740 * with a ButtonPress event */
741 wine_tsx11_lock();
742 XUngrabPointer( display, CurrentTime );
743 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
744 wine_tsx11_unlock();
745 return TRUE;