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
25 #include <X11/Xutil.h>
33 #include "wine/wingdi16.h"
38 #include "wine/server.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
43 #define SWP_AGG_NOPOSCHANGE \
44 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
46 #define SWP_EX_NOCOPY 0x0001
47 #define SWP_EX_PAINTSELF 0x0002
48 #define SWP_EX_NONCLIENT 0x0004
50 #define HAS_THICKFRAME(style) \
51 (((style) & WS_THICKFRAME) && \
52 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
54 #define ON_LEFT_BORDER(hit) \
55 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
56 #define ON_RIGHT_BORDER(hit) \
57 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
58 #define ON_TOP_BORDER(hit) \
59 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
60 #define ON_BOTTOM_BORDER(hit) \
61 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
63 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
64 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
65 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
66 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
67 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
68 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
69 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
70 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
71 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
72 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
73 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
75 #define _NET_WM_STATE_REMOVE 0
76 #define _NET_WM_STATE_ADD 1
77 #define _NET_WM_STATE_TOGGLE 2
79 static const char managed_prop
[] = "__wine_x11_managed";
81 /***********************************************************************
84 void X11DRV_Expose( HWND hwnd
, XEvent
*xev
)
86 XExposeEvent
*event
= &xev
->xexpose
;
88 struct x11drv_win_data
*data
;
89 int flags
= RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
;
91 TRACE( "win %p (%lx) %d,%d %dx%d\n",
92 hwnd
, event
->window
, event
->x
, event
->y
, event
->width
, event
->height
);
94 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
96 if (event
->window
== data
->whole_window
)
98 rect
.left
= data
->whole_rect
.left
+ event
->x
;
99 rect
.top
= data
->whole_rect
.top
+ event
->y
;
104 rect
.left
= data
->client_rect
.left
+ event
->x
;
105 rect
.top
= data
->client_rect
.top
+ event
->y
;
107 rect
.right
= rect
.left
+ event
->width
;
108 rect
.bottom
= rect
.top
+ event
->height
;
110 if (event
->window
== root_window
)
111 OffsetRect( &rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
113 SERVER_START_REQ( update_window_zorder
)
116 req
->rect
.left
= rect
.left
;
117 req
->rect
.top
= rect
.top
;
118 req
->rect
.right
= rect
.right
;
119 req
->rect
.bottom
= rect
.bottom
;
120 wine_server_call( req
);
124 /* make position relative to client area instead of parent */
125 OffsetRect( &rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
126 RedrawWindow( hwnd
, &rect
, 0, flags
);
129 /***********************************************************************
130 * SetWindowStyle (X11DRV.@)
132 * Update the X state of a window to reflect a style change
134 void X11DRV_SetWindowStyle( HWND hwnd
, DWORD old_style
)
136 Display
*display
= thread_display();
137 struct x11drv_win_data
*data
;
138 DWORD new_style
, changed
;
140 if (hwnd
== GetDesktopWindow()) return;
141 new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
142 changed
= new_style
^ old_style
;
144 if ((changed
& WS_VISIBLE
) && (new_style
& WS_VISIBLE
))
146 /* we don't unmap windows, that causes trouble with the window manager */
147 if (!(data
= X11DRV_get_win_data( hwnd
)) &&
148 !(data
= X11DRV_create_win_data( hwnd
))) return;
150 if (data
->whole_window
&& X11DRV_is_window_rect_mapped( &data
->window_rect
))
152 X11DRV_set_wm_hints( display
, data
);
155 TRACE( "mapping win %p\n", hwnd
);
156 wait_for_withdrawn_state( display
, data
);
157 X11DRV_sync_window_style( display
, data
);
159 XMapWindow( display
, data
->whole_window
);
162 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
167 if (changed
& WS_DISABLED
)
169 data
= X11DRV_get_win_data( hwnd
);
170 if (data
&& data
->wm_hints
)
173 data
->wm_hints
->input
= !(new_style
& WS_DISABLED
);
174 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
181 /***********************************************************************
182 * update_net_wm_states
184 static void update_net_wm_states( Display
*display
, struct x11drv_win_data
*data
)
186 static const unsigned int state_atoms
[NB_NET_WM_STATES
] =
188 XATOM__NET_WM_STATE_FULLSCREEN
,
189 XATOM__NET_WM_STATE_ABOVE
,
190 XATOM__NET_WM_STATE_SKIP_PAGER
,
191 XATOM__NET_WM_STATE_SKIP_TASKBAR
194 DWORD i
, ex_style
, new_state
= 0;
197 if (!data
->managed
) return;
198 if (!data
->mapped
) return;
200 if (data
->whole_rect
.left
<= 0 && data
->whole_rect
.right
>= screen_width
&&
201 data
->whole_rect
.top
<= 0 && data
->whole_rect
.bottom
>= screen_height
)
202 new_state
|= (1 << NET_WM_STATE_FULLSCREEN
);
204 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
205 if (ex_style
& WS_EX_TOPMOST
)
206 new_state
|= (1 << NET_WM_STATE_ABOVE
);
207 if (ex_style
& WS_EX_TOOLWINDOW
)
208 new_state
|= (1 << NET_WM_STATE_SKIP_TASKBAR
) | (1 << NET_WM_STATE_SKIP_PAGER
);
210 xev
.xclient
.type
= ClientMessage
;
211 xev
.xclient
.window
= data
->whole_window
;
212 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
213 xev
.xclient
.serial
= 0;
214 xev
.xclient
.display
= display
;
215 xev
.xclient
.send_event
= True
;
216 xev
.xclient
.format
= 32;
217 xev
.xclient
.data
.l
[2] = 0;
218 xev
.xclient
.data
.l
[3] = 1;
220 for (i
= 0; i
< NB_NET_WM_STATES
; i
++)
222 if (!((data
->net_wm_state
^ new_state
) & (1 << i
))) continue; /* unchanged */
224 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
225 i
, data
->hwnd
, data
->whole_window
,
226 (new_state
& (1 << i
)) != 0, (data
->net_wm_state
& (1 << i
)) != 0 );
228 xev
.xclient
.data
.l
[0] = (new_state
& (1 << i
)) ? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
229 xev
.xclient
.data
.l
[1] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
231 XSendEvent( display
, root_window
, False
, SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
234 data
->net_wm_state
= new_state
;
238 /***********************************************************************
241 * Move the window bits when a window is moved.
243 static void move_window_bits( struct x11drv_win_data
*data
, const RECT
*old_rect
, const RECT
*new_rect
,
244 const RECT
*old_client_rect
)
246 RECT src_rect
= *old_rect
;
247 RECT dst_rect
= *new_rect
;
248 HDC hdc_src
, hdc_dst
;
253 if (!data
->whole_window
)
255 OffsetRect( &dst_rect
, -data
->window_rect
.left
, -data
->window_rect
.top
);
256 parent
= GetAncestor( data
->hwnd
, GA_PARENT
);
257 hdc_src
= GetDCEx( parent
, 0, DCX_CACHE
);
258 hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
262 OffsetRect( &dst_rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
263 /* make src rect relative to the old position of the window */
264 OffsetRect( &src_rect
, -old_client_rect
->left
, -old_client_rect
->top
);
265 if (dst_rect
.left
== src_rect
.left
&& dst_rect
.top
== src_rect
.top
) return;
266 hdc_src
= hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
);
269 code
= X11DRV_START_EXPOSURES
;
270 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
272 TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n",
273 data
->hwnd
, data
->whole_window
, data
->client_window
,
274 wine_dbgstr_rect(&src_rect
), wine_dbgstr_rect(&dst_rect
) );
275 BitBlt( hdc_dst
, dst_rect
.left
, dst_rect
.top
,
276 dst_rect
.right
- dst_rect
.left
, dst_rect
.bottom
- dst_rect
.top
,
277 hdc_src
, src_rect
.left
, src_rect
.top
, SRCCOPY
);
279 code
= X11DRV_END_EXPOSURES
;
280 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, sizeof(rgn
), (LPSTR
)&rgn
);
282 ReleaseDC( data
->hwnd
, hdc_dst
);
283 if (hdc_src
!= hdc_dst
) ReleaseDC( parent
, hdc_src
);
287 if (!data
->whole_window
)
289 /* map region to client rect since we are using DCX_WINDOW */
290 OffsetRgn( rgn
, data
->window_rect
.left
- data
->client_rect
.left
,
291 data
->window_rect
.top
- data
->client_rect
.top
);
292 RedrawWindow( data
->hwnd
, NULL
, rgn
,
293 RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
295 else RedrawWindow( data
->hwnd
, NULL
, rgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
300 /***********************************************************************
301 * SetWindowPos (X11DRV.@)
303 void X11DRV_SetWindowPos( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
304 const RECT
*rectWindow
, const RECT
*rectClient
,
305 const RECT
*visible_rect
, const RECT
*valid_rects
)
307 Display
*display
= thread_display();
308 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
309 DWORD new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
310 RECT old_window_rect
, old_whole_rect
, old_client_rect
;
314 /* create the win data if the window is being made visible */
315 if (!(new_style
& WS_VISIBLE
)) return;
316 if (!(data
= X11DRV_create_win_data( hwnd
))) return;
319 /* check if we need to switch the window to managed */
320 if (!data
->managed
&& data
->whole_window
&& is_window_managed( hwnd
, swp_flags
, rectWindow
))
322 TRACE( "making win %p/%lx managed\n", hwnd
, data
->whole_window
);
323 data
->managed
= TRUE
;
324 SetPropA( hwnd
, managed_prop
, (HANDLE
)1 );
328 XUnmapWindow( display
, data
->whole_window
);
330 data
->mapped
= FALSE
;
334 old_window_rect
= data
->window_rect
;
335 old_whole_rect
= data
->whole_rect
;
336 old_client_rect
= data
->client_rect
;
337 data
->window_rect
= *rectWindow
;
338 data
->whole_rect
= *rectWindow
;
339 data
->client_rect
= *rectClient
;
340 X11DRV_window_to_X_rect( data
, &data
->whole_rect
);
341 if (memcmp( &visible_rect
, &data
->whole_rect
, sizeof(RECT
) ))
343 TRACE( "%p: need to update visible rect %s -> %s\n", hwnd
,
344 wine_dbgstr_rect(visible_rect
), wine_dbgstr_rect(&data
->whole_rect
) );
345 SERVER_START_REQ( set_window_visible_rect
)
348 req
->flags
= swp_flags
;
349 req
->visible
.left
= data
->whole_rect
.left
;
350 req
->visible
.top
= data
->whole_rect
.top
;
351 req
->visible
.right
= data
->whole_rect
.right
;
352 req
->visible
.bottom
= data
->whole_rect
.bottom
;
353 wine_server_call( req
);
358 TRACE( "win %p window %s client %s style %08x flags %08x\n",
359 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
, swp_flags
);
361 if (!IsRectEmpty( &valid_rects
[0] ))
363 int x_offset
= old_whole_rect
.left
- data
->whole_rect
.left
;
364 int y_offset
= old_whole_rect
.top
- data
->whole_rect
.top
;
366 /* if all that happened is that the whole window moved, copy everything */
367 if (!(swp_flags
& SWP_FRAMECHANGED
) &&
368 old_whole_rect
.right
- data
->whole_rect
.right
== x_offset
&&
369 old_whole_rect
.bottom
- data
->whole_rect
.bottom
== y_offset
&&
370 old_client_rect
.left
- data
->client_rect
.left
== x_offset
&&
371 old_client_rect
.right
- data
->client_rect
.right
== x_offset
&&
372 old_client_rect
.top
- data
->client_rect
.top
== y_offset
&&
373 old_client_rect
.bottom
- data
->client_rect
.bottom
== y_offset
&&
374 !memcmp( &valid_rects
[0], &data
->client_rect
, sizeof(RECT
) ))
376 /* if we have an X window the bits will be moved by the X server */
377 if (!data
->whole_window
)
378 move_window_bits( data
, &old_whole_rect
, &data
->whole_rect
, &old_client_rect
);
381 move_window_bits( data
, &valid_rects
[1], &valid_rects
[0], &old_client_rect
);
384 X11DRV_sync_client_position( display
, data
, swp_flags
, &old_client_rect
, &old_whole_rect
);
386 if (!data
->whole_window
|| data
->lock_changes
) return; /* nothing more to do */
388 if (data
->mapped
&& (!(new_style
& WS_VISIBLE
) || !X11DRV_is_window_rect_mapped( rectWindow
)))
390 TRACE( "unmapping win %p/%lx\n", hwnd
, data
->whole_window
);
392 if (data
->managed
) XWithdrawWindow( display
, data
->whole_window
, DefaultScreen(display
) );
393 else XUnmapWindow( display
, data
->whole_window
);
395 data
->mapped
= FALSE
;
396 data
->net_wm_state
= 0;
399 /* don't change position if we are about to minimize a managed window */
400 if (!(data
->managed
&& (swp_flags
& SWP_STATECHANGED
) && (new_style
& WS_MINIMIZE
)))
401 X11DRV_sync_window_position( display
, data
, swp_flags
, &old_client_rect
, &old_whole_rect
);
403 if ((new_style
& WS_VISIBLE
) &&
404 ((new_style
& WS_MINIMIZE
) || X11DRV_is_window_rect_mapped( rectWindow
)))
406 if (!data
->mapped
|| (swp_flags
& (SWP_FRAMECHANGED
|SWP_STATECHANGED
)))
407 X11DRV_set_wm_hints( display
, data
);
411 TRACE( "mapping win %p/%lx\n", hwnd
, data
->whole_window
);
412 wait_for_withdrawn_state( display
, data
);
413 X11DRV_sync_window_style( display
, data
);
415 XMapWindow( display
, data
->whole_window
);
419 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
421 else if ((swp_flags
& SWP_STATECHANGED
) && (!data
->iconic
!= !(new_style
& WS_MINIMIZE
)))
423 data
->iconic
= (new_style
& WS_MINIMIZE
) != 0;
424 TRACE( "changing win %p iconic state to %u\n", data
->hwnd
, data
->iconic
);
427 XIconifyWindow( display
, data
->whole_window
, DefaultScreen(display
) );
428 else if (X11DRV_is_window_rect_mapped( rectWindow
))
429 XMapWindow( display
, data
->whole_window
);
432 update_net_wm_states( display
, data
);
437 /**********************************************************************
440 void X11DRV_MapNotify( HWND hwnd
, XEvent
*event
)
442 struct x11drv_win_data
*data
;
445 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
446 if (!data
->mapped
) return;
450 HWND hwndFocus
= GetFocus();
451 if (hwndFocus
&& IsChild( hwnd
, hwndFocus
)) X11DRV_SetFocus(hwndFocus
); /* FIXME */
455 state
= get_window_wm_state( event
->xmap
.display
, data
);
456 if (state
== NormalState
)
459 unsigned int width
, height
, border
, depth
;
466 XGetGeometry( event
->xmap
.display
, data
->whole_window
, &root
, &x
, &y
, &width
, &height
,
468 XTranslateCoordinates( event
->xmap
.display
, data
->whole_window
, root
, 0, 0, &x
, &y
, &top
);
472 rect
.right
= x
+ width
;
473 rect
.bottom
= y
+ height
;
474 OffsetRect( &rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
475 X11DRV_X_to_window_rect( data
, &rect
);
477 wp
.length
= sizeof(wp
);
479 wp
.showCmd
= SW_RESTORE
;
480 wp
.rcNormalPosition
= rect
;
482 TRACE( "restoring win %p/%lx\n", hwnd
, data
->whole_window
);
483 data
->iconic
= FALSE
;
484 data
->lock_changes
++;
485 SetWindowPlacement( hwnd
, &wp
);
486 data
->lock_changes
--;
488 else TRACE( "win %p/%lx ignoring since state=%d\n", hwnd
, data
->whole_window
, state
);
492 /**********************************************************************
495 void X11DRV_UnmapNotify( HWND hwnd
, XEvent
*event
)
497 struct x11drv_win_data
*data
;
500 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
501 if (!data
->managed
|| !data
->mapped
) return;
503 state
= get_window_wm_state( event
->xunmap
.display
, data
);
504 if (state
== IconicState
)
506 TRACE( "minimizing win %p/%lx\n", hwnd
, data
->whole_window
);
508 data
->lock_changes
++;
509 ShowWindow( hwnd
, SW_MINIMIZE
);
510 data
->lock_changes
--;
512 else TRACE( "win %p/%lx ignoring since state=%d\n", hwnd
, data
->whole_window
, state
);
515 struct desktop_resize_data
517 RECT old_screen_rect
;
518 RECT old_virtual_rect
;
521 static BOOL CALLBACK
update_windows_on_desktop_resize( HWND hwnd
, LPARAM lparam
)
523 struct x11drv_win_data
*data
;
524 Display
*display
= thread_display();
525 struct desktop_resize_data
*resize_data
= (struct desktop_resize_data
*)lparam
;
528 if (!(data
= X11DRV_get_win_data( hwnd
))) return TRUE
;
530 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)
532 /* update the full screen state */
533 update_net_wm_states( display
, data
);
536 if (resize_data
->old_virtual_rect
.left
!= virtual_screen_rect
.left
) mask
|= CWX
;
537 if (resize_data
->old_virtual_rect
.top
!= virtual_screen_rect
.top
) mask
|= CWY
;
538 if (mask
&& data
->whole_window
)
540 XWindowChanges changes
;
543 changes
.x
= data
->whole_rect
.left
- virtual_screen_rect
.left
;
544 changes
.y
= data
->whole_rect
.top
- virtual_screen_rect
.top
;
545 XReconfigureWMWindow( display
, data
->whole_window
,
546 DefaultScreen(display
), mask
, &changes
);
553 /***********************************************************************
554 * X11DRV_resize_desktop
556 void X11DRV_resize_desktop( unsigned int width
, unsigned int height
)
558 HWND hwnd
= GetDesktopWindow();
559 struct desktop_resize_data resize_data
;
561 SetRect( &resize_data
.old_screen_rect
, 0, 0, screen_width
, screen_height
);
562 resize_data
.old_virtual_rect
= virtual_screen_rect
;
564 xinerama_init( width
, height
);
566 if (GetWindowThreadProcessId( hwnd
, NULL
) != GetCurrentThreadId())
568 SendMessageW( hwnd
, WM_X11DRV_RESIZE_DESKTOP
, 0, MAKELPARAM( width
, height
) );
572 TRACE( "desktop %p change to (%dx%d)\n", hwnd
, width
, height
);
573 SetWindowPos( hwnd
, 0, virtual_screen_rect
.left
, virtual_screen_rect
.top
,
574 virtual_screen_rect
.right
- virtual_screen_rect
.left
,
575 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
,
576 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_DEFERERASE
);
577 SendMessageTimeoutW( HWND_BROADCAST
, WM_DISPLAYCHANGE
, screen_bpp
,
578 MAKELPARAM( width
, height
), SMTO_ABORTIFHUNG
, 2000, NULL
);
581 EnumWindows( update_windows_on_desktop_resize
, (LPARAM
)&resize_data
);
585 /***********************************************************************
586 * X11DRV_ConfigureNotify
588 void X11DRV_ConfigureNotify( HWND hwnd
, XEvent
*xev
)
590 XConfigureEvent
*event
= &xev
->xconfigure
;
591 struct x11drv_win_data
*data
;
594 int cx
, cy
, x
= event
->x
, y
= event
->y
;
597 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
601 if (!event
->send_event
) /* normal event, need to map coordinates to the root */
605 XTranslateCoordinates( event
->display
, data
->whole_window
, root_window
,
606 0, 0, &x
, &y
, &child
);
611 rect
.right
= x
+ event
->width
;
612 rect
.bottom
= y
+ event
->height
;
613 OffsetRect( &rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
614 TRACE( "win %p new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
615 hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
616 event
->x
, event
->y
, event
->width
, event
->height
);
617 X11DRV_X_to_window_rect( data
, &rect
);
621 cx
= rect
.right
- rect
.left
;
622 cy
= rect
.bottom
- rect
.top
;
623 flags
= SWP_NOACTIVATE
| SWP_NOZORDER
;
625 /* Compare what has changed */
627 GetWindowRect( hwnd
, &rect
);
628 if (rect
.left
== x
&& rect
.top
== y
) flags
|= SWP_NOMOVE
;
630 TRACE( "%p moving from (%d,%d) to (%d,%d)\n",
631 hwnd
, rect
.left
, rect
.top
, x
, y
);
633 if ((rect
.right
- rect
.left
== cx
&& rect
.bottom
- rect
.top
== cy
) ||
635 (IsRectEmpty( &rect
) && event
->width
== 1 && event
->height
== 1))
637 if (flags
& SWP_NOMOVE
) return; /* if nothing changed, don't do anything */
641 TRACE( "%p resizing from (%dx%d) to (%dx%d)\n",
642 hwnd
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, cx
, cy
);
644 data
->lock_changes
++;
645 SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
646 data
->lock_changes
--;
650 /***********************************************************************
653 * Draw the frame used when moving or resizing window.
655 * FIXME: This causes problems in Win95 mode. (why?)
657 static void draw_moving_frame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
661 const int width
= GetSystemMetrics(SM_CXFRAME
);
662 const int height
= GetSystemMetrics(SM_CYFRAME
);
664 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
665 PatBlt( hdc
, rect
->left
, rect
->top
,
666 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
667 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
668 rect
->bottom
- rect
->top
- height
, PATINVERT
);
669 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
670 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
671 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
672 rect
->bottom
- rect
->top
- height
, PATINVERT
);
673 SelectObject( hdc
, hbrush
);
675 else DrawFocusRect( hdc
, rect
);
679 /***********************************************************************
682 * Initialization of a move or resize, when initiated from a menu choice.
683 * Return hit test code for caption or sizing border.
685 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
692 GetWindowRect( hwnd
, &rectWindow
);
694 if ((wParam
& 0xfff0) == SC_MOVE
)
696 /* Move pointer at the center of the caption */
697 RECT rect
= rectWindow
;
698 /* Note: to be exactly centered we should take the different types
699 * of border into account, but it shouldn't make more than a few pixels
700 * of difference so let's not bother with that */
701 rect
.top
+= GetSystemMetrics(SM_CYBORDER
);
702 if (style
& WS_SYSMENU
)
703 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
704 if (style
& WS_MINIMIZEBOX
)
705 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
706 if (style
& WS_MAXIMIZEBOX
)
707 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
708 pt
.x
= (rect
.right
+ rect
.left
) / 2;
709 pt
.y
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
718 GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
);
719 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
725 hittest
= SendMessageW( hwnd
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
726 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
)) hittest
= 0;
737 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
738 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
742 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
743 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
747 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
748 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
752 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
753 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
756 case VK_ESCAPE
: return 0;
762 SetCursorPos( pt
.x
, pt
.y
);
763 SendMessageW( hwnd
, WM_SETCURSOR
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
768 /***********************************************************************
769 * set_movesize_capture
771 static void set_movesize_capture( HWND hwnd
)
775 SERVER_START_REQ( set_capture_window
)
778 req
->flags
= CAPTURE_MOVESIZE
;
779 if (!wine_server_call_err( req
))
781 previous
= reply
->previous
;
782 hwnd
= reply
->full_handle
;
786 if (previous
&& previous
!= hwnd
)
787 SendMessageW( previous
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
790 /***********************************************************************
791 * X11DRV_WMMoveResizeWindow
793 * Tells the window manager to initiate a move or resize operation.
796 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
797 * or search for "_NET_WM_MOVERESIZE"
799 static BOOL
X11DRV_WMMoveResizeWindow( HWND hwnd
, int x
, int y
, WPARAM wparam
)
801 WPARAM syscommand
= wparam
& 0xfff0;
802 WPARAM hittest
= wparam
& 0x0f;
805 Display
*display
= thread_display();
807 if (syscommand
== SC_MOVE
)
809 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
810 else dir
= _NET_WM_MOVERESIZE_MOVE
;
814 /* windows without WS_THICKFRAME are not resizable through the window manager */
815 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_THICKFRAME
)) return FALSE
;
819 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
820 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
821 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
822 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
823 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
824 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
825 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
826 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
827 default: dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
; break;
831 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd
, x
, y
, dir
);
833 xev
.xclient
.type
= ClientMessage
;
834 xev
.xclient
.window
= X11DRV_get_whole_window(hwnd
);
835 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_MOVERESIZE
);
836 xev
.xclient
.serial
= 0;
837 xev
.xclient
.display
= display
;
838 xev
.xclient
.send_event
= True
;
839 xev
.xclient
.format
= 32;
840 xev
.xclient
.data
.l
[0] = x
; /* x coord */
841 xev
.xclient
.data
.l
[1] = y
; /* y coord */
842 xev
.xclient
.data
.l
[2] = dir
; /* direction */
843 xev
.xclient
.data
.l
[3] = 1; /* button */
844 xev
.xclient
.data
.l
[4] = 0; /* unused */
846 /* need to ungrab the pointer that may have been automatically grabbed
847 * with a ButtonPress event */
849 XUngrabPointer( display
, CurrentTime
);
850 XSendEvent(display
, root_window
, False
, SubstructureNotifyMask
, &xev
);
855 /***********************************************************************
856 * SysCommandSizeMove (X11DRV.@)
858 * Perform SC_MOVE and SC_SIZE commands.
860 void X11DRV_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
863 RECT sizingRect
, mouseRect
, origRect
;
866 LONG hittest
= (LONG
)(wParam
& 0x0f);
867 WPARAM syscommand
= wParam
& 0xfff0;
868 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
869 POINT minTrack
, maxTrack
;
870 POINT capturePoint
, pt
;
871 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
872 BOOL thickframe
= HAS_THICKFRAME( style
);
873 BOOL iconic
= style
& WS_MINIMIZE
;
875 DWORD dwPoint
= GetMessagePos ();
876 BOOL DragFullWindows
= TRUE
;
877 Window parent_win
, grab_win
;
878 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
879 struct x11drv_win_data
*data
;
881 pt
.x
= (short)LOWORD(dwPoint
);
882 pt
.y
= (short)HIWORD(dwPoint
);
885 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
)) return;
887 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
889 TRACE("hwnd %p (%smanaged), command %04lx, hittest %d, pos %d,%d\n",
890 hwnd
, data
->managed
? "" : "NOT ", syscommand
, hittest
, pt
.x
, pt
.y
);
892 /* if we are managed then we let the WM do all the work */
893 if (data
->managed
&& X11DRV_WMMoveResizeWindow( hwnd
, pt
.x
, pt
.y
, wParam
)) return;
895 if (syscommand
== SC_MOVE
)
897 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
898 if (!hittest
) return;
902 if ( hittest
&& (syscommand
!= SC_MOUSEMENU
) )
903 hittest
+= (HTLEFT
- WMSZ_LEFT
);
906 set_movesize_capture( hwnd
);
907 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
910 set_movesize_capture(0);
916 /* Get min/max info */
918 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
919 GetWindowRect( hwnd
, &sizingRect
);
920 if (style
& WS_CHILD
)
922 parent
= GetParent(hwnd
);
923 /* make sizing rect relative to parent */
924 MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
925 GetClientRect( parent
, &mouseRect
);
930 mouseRect
= virtual_screen_rect
;
932 origRect
= sizingRect
;
934 if (ON_LEFT_BORDER(hittest
))
936 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
937 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
939 else if (ON_RIGHT_BORDER(hittest
))
941 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
942 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
944 if (ON_TOP_BORDER(hittest
))
946 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
947 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
949 else if (ON_BOTTOM_BORDER(hittest
))
951 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
952 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
954 if (parent
) MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
956 /* Retrieve a default cache DC (without using the window style) */
957 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
959 if( iconic
) /* create a cursor for dragging */
961 hDragCursor
= (HCURSOR
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
962 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
963 if( !hDragCursor
) iconic
= FALSE
;
966 /* repaint the window before moving it around */
967 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
969 SendMessageW( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
970 set_movesize_capture( hwnd
);
972 /* we only allow disabling the full window drag for child windows, or in desktop mode */
973 /* otherwise we'd need to grab the server and we want to avoid that */
974 if (parent
|| (root_window
!= DefaultRootWindow(gdi_display
)))
975 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
977 grab_win
= X11DRV_get_client_window( GetAncestor(hwnd
,GA_ROOT
) );
978 parent_win
= parent
? X11DRV_get_client_window( GetAncestor(parent
,GA_ROOT
) ) : root_window
;
981 XGrabPointer( thread_data
->display
, grab_win
, False
,
982 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
983 GrabModeAsync
, GrabModeAsync
, parent_win
, None
, CurrentTime
);
985 thread_data
->grab_window
= grab_win
;
991 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
992 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
994 /* Exit on button-up, Return, or Esc */
995 if ((msg
.message
== WM_LBUTTONUP
) ||
996 ((msg
.message
== WM_KEYDOWN
) &&
997 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
999 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
1001 TranslateMessage( &msg
);
1002 DispatchMessageW( &msg
);
1003 continue; /* We are not interested in other messages */
1008 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
1010 case VK_UP
: pt
.y
-= 8; break;
1011 case VK_DOWN
: pt
.y
+= 8; break;
1012 case VK_LEFT
: pt
.x
-= 8; break;
1013 case VK_RIGHT
: pt
.x
+= 8; break;
1016 pt
.x
= max( pt
.x
, mouseRect
.left
);
1017 pt
.x
= min( pt
.x
, mouseRect
.right
);
1018 pt
.y
= max( pt
.y
, mouseRect
.top
);
1019 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
1021 dx
= pt
.x
- capturePoint
.x
;
1022 dy
= pt
.y
- capturePoint
.y
;
1030 if( iconic
) /* ok, no system popup tracking */
1032 hOldCursor
= SetCursor(hDragCursor
);
1034 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1036 else if(!DragFullWindows
)
1037 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1040 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
1043 RECT newRect
= sizingRect
;
1044 WPARAM wpSizingHit
= 0;
1046 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
1047 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
1048 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
1049 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
1050 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
1051 if(!iconic
&& !DragFullWindows
) draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1054 /* determine the hit location */
1055 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
1056 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
1057 SendMessageW( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
1061 if(!DragFullWindows
)
1062 draw_moving_frame( hdc
, &newRect
, thickframe
);
1064 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
1065 newRect
.right
- newRect
.left
,
1066 newRect
.bottom
- newRect
.top
,
1067 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1069 sizingRect
= newRect
;
1074 set_movesize_capture(0);
1077 if( moved
) /* restore cursors, show icon title later on */
1079 ShowCursor( FALSE
);
1080 SetCursor( hOldCursor
);
1083 else if (moved
&& !DragFullWindows
)
1085 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1086 /* make sure the moving frame is erased before we move the window */
1088 XFlush( gdi_display
);
1089 wine_tsx11_unlock();
1092 ReleaseDC( parent
, hdc
);
1095 XUngrabPointer( thread_data
->display
, CurrentTime
);
1096 wine_tsx11_unlock();
1097 thread_data
->grab_window
= None
;
1099 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
1102 SendMessageW( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
1103 SendMessageW( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
1105 /* window moved or resized */
1108 /* if the moving/resizing isn't canceled call SetWindowPos
1109 * with the new position or the new size of the window
1111 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
1113 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1114 if(!DragFullWindows
)
1115 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
1116 sizingRect
.right
- sizingRect
.left
,
1117 sizingRect
.bottom
- sizingRect
.top
,
1118 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1121 { /* restore previous size/position */
1123 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
1124 origRect
.right
- origRect
.left
,
1125 origRect
.bottom
- origRect
.top
,
1126 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1132 /* Single click brings up the system menu when iconized */
1136 if(style
& WS_SYSMENU
)
1137 SendMessageW( hwnd
, WM_SYSCOMMAND
,
1138 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
1140 else WINPOS_ShowIconTitle( hwnd
, TRUE
);