winex11: Avoid passing a window data structure to functions that can send messages.

This commit is contained in:
Alexandre Julliard 2012-09-13 20:08:01 +02:00
parent c982e5f64b
commit c8ea1e50dc
5 changed files with 93 additions and 74 deletions

View File

@ -1080,7 +1080,7 @@ static void X11DRV_GravityNotify( HWND hwnd, XEvent *xev )
/***********************************************************************
* get_window_wm_state
*/
static int get_window_wm_state( Display *display, struct x11drv_win_data *data )
static int get_window_wm_state( Display *display, Window window )
{
struct
{
@ -1091,7 +1091,7 @@ static int get_window_wm_state( Display *display, struct x11drv_win_data *data )
int format, ret = -1;
unsigned long count, remaining;
if (!XGetWindowProperty( display, data->whole_window, x11drv_atom(WM_STATE), 0,
if (!XGetWindowProperty( display, window, x11drv_atom(WM_STATE), 0,
sizeof(*state)/sizeof(CARD32), False, x11drv_atom(WM_STATE),
&type, &format, &count, &remaining, (unsigned char **)&state ))
{
@ -1108,11 +1108,13 @@ static int get_window_wm_state( Display *display, struct x11drv_win_data *data )
*
* Handle a PropertyNotify for WM_STATE.
*/
static void handle_wm_state_notify( struct x11drv_win_data *data, XPropertyEvent *event,
BOOL update_window )
static void handle_wm_state_notify( HWND hwnd, XPropertyEvent *event, BOOL update_window )
{
struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
DWORD style;
if (!data) return;
switch(event->state)
{
case PropertyDelete:
@ -1122,7 +1124,7 @@ static void handle_wm_state_notify( struct x11drv_win_data *data, XPropertyEvent
case PropertyNewValue:
{
int old_state = data->wm_state;
int new_state = get_window_wm_state( event->display, data );
int new_state = get_window_wm_state( event->display, data->whole_window );
if (new_state != -1 && new_state != data->wm_state)
{
TRACE( "%p/%lx: new WM_STATE %d from %d\n",
@ -1179,12 +1181,9 @@ static void handle_wm_state_notify( struct x11drv_win_data *data, XPropertyEvent
static void X11DRV_PropertyNotify( HWND hwnd, XEvent *xev )
{
XPropertyEvent *event = &xev->xproperty;
struct x11drv_win_data *data;
if (!hwnd) return;
if (!(data = X11DRV_get_win_data( hwnd ))) return;
if (event->atom == x11drv_atom(WM_STATE)) handle_wm_state_notify( data, event, TRUE );
if (event->atom == x11drv_atom(WM_STATE)) handle_wm_state_notify( hwnd, event, TRUE );
}
@ -1199,11 +1198,13 @@ static Bool is_wm_state_notify( Display *display, XEvent *event, XPointer arg )
/***********************************************************************
* wait_for_withdrawn_state
*/
void wait_for_withdrawn_state( Display *display, struct x11drv_win_data *data, BOOL set )
void wait_for_withdrawn_state( HWND hwnd, BOOL set )
{
Display *display = thread_display();
struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
DWORD end = GetTickCount() + 2000;
if (!data->managed) return;
if (!data || !data->managed) return;
TRACE( "waiting for window %p/%lx to become %swithdrawn\n",
data->hwnd, data->whole_window, set ? "" : "not " );
@ -1218,7 +1219,7 @@ void wait_for_withdrawn_state( Display *display, struct x11drv_win_data *data, B
count++;
if (XFilterEvent( &event, None )) continue; /* filtered, ignore it */
if (event.type == DestroyNotify) call_event_handler( display, &event );
else handle_wm_state_notify( data, &event.xproperty, FALSE );
else handle_wm_state_notify( hwnd, &event.xproperty, FALSE );
}
if (!count)

View File

@ -1305,14 +1305,17 @@ BOOL CDECL X11DRV_ClipCursor( LPCRECT clip )
/***********************************************************************
* move_resize_window
*/
void move_resize_window( Display *display, struct x11drv_win_data *data, int dir )
void move_resize_window( HWND hwnd, int dir )
{
Display *display = thread_display();
DWORD pt;
int x, y, rootX, rootY, button = 0;
XEvent xev;
Window root, child;
Window win, root, child;
unsigned int xstate;
if (!(win = X11DRV_get_whole_window( hwnd ))) return;
pt = GetMessagePos();
x = (short)LOWORD( pt );
y = (short)HIWORD( pt );
@ -1321,11 +1324,10 @@ void move_resize_window( Display *display, struct x11drv_win_data *data, int dir
else if (GetKeyState( VK_MBUTTON ) & 0x8000) button = 2;
else if (GetKeyState( VK_RBUTTON ) & 0x8000) button = 3;
TRACE( "hwnd %p/%lx, x %d, y %d, dir %d, button %d\n",
data->hwnd, data->whole_window, x, y, dir, button );
TRACE( "hwnd %p/%lx, x %d, y %d, dir %d, button %d\n", hwnd, win, x, y, dir, button );
xev.xclient.type = ClientMessage;
xev.xclient.window = data->whole_window;
xev.xclient.window = win;
xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
xev.xclient.serial = 0;
xev.xclient.display = display;
@ -1363,7 +1365,7 @@ void move_resize_window( Display *display, struct x11drv_win_data *data, int dir
input.u.mi.dwFlags = button_up_flags[button - 1] | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
input.u.mi.time = GetTickCount();
input.u.mi.dwExtraInfo = 0;
__wine_send_input( data->hwnd, &input );
__wine_send_input( hwnd, &input );
}
while (PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ))
@ -1379,7 +1381,7 @@ void move_resize_window( Display *display, struct x11drv_win_data *data, int dir
MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
}
TRACE( "hwnd %p/%lx done\n", data->hwnd, data->whole_window );
TRACE( "hwnd %p/%lx done\n", hwnd, win );
}

View File

@ -510,21 +510,20 @@ static BOOL init_systray(void)
/* dock the given icon with the NETWM system tray */
static void dock_systray_icon( Display *display, struct tray_icon *icon, Window systray_window )
{
struct x11drv_win_data *data;
Window window;
XEvent ev;
XSetWindowAttributes attr;
icon->window = CreateWindowW( icon_classname, NULL, WS_CLIPSIBLINGS | WS_POPUP,
CW_USEDEFAULT, CW_USEDEFAULT, icon_cx, icon_cy,
NULL, NULL, NULL, icon );
if (!(data = X11DRV_get_win_data( icon->window ))) return;
TRACE( "icon window %p/%lx managed %u\n", data->hwnd, data->whole_window, data->managed );
make_window_embedded( display, data );
make_window_embedded( icon->window );
create_tooltip( icon );
ShowWindow( icon->window, SW_SHOWNA );
if (!(window = X11DRV_get_whole_window( icon->window ))) return;
TRACE( "icon window %p/%lx\n", icon->window, window );
/* send the docking request message */
ev.xclient.type = ClientMessage;
ev.xclient.window = systray_window;
@ -532,13 +531,13 @@ static void dock_systray_icon( Display *display, struct tray_icon *icon, Window
ev.xclient.format = 32;
ev.xclient.data.l[0] = CurrentTime;
ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
ev.xclient.data.l[2] = data->whole_window;
ev.xclient.data.l[2] = window;
ev.xclient.data.l[3] = 0;
ev.xclient.data.l[4] = 0;
XSendEvent( display, systray_window, False, NoEventMask, &ev );
attr.background_pixmap = ParentRelative;
attr.bit_gravity = ForgetGravity;
XChangeWindowAttributes( display, data->whole_window, CWBackPixmap | CWBitGravity, &attr );
XChangeWindowAttributes( display, window, CWBackPixmap | CWBitGravity, &attr );
}
/* dock systray windows again with the new owner */

View File

@ -575,10 +575,10 @@ failed:
*
* Set the icon wm hints
*/
static void set_icon_hints( Display *display, struct x11drv_win_data *data,
HICON icon_big, HICON icon_small )
static void set_icon_hints( HWND hwnd, HICON icon_big, HICON icon_small )
{
XWMHints *hints = data->wm_hints;
Display *display = thread_display();
struct x11drv_win_data *data;
ICONINFO ii, ii_small;
HDC hDC;
unsigned int size;
@ -586,19 +586,22 @@ static void set_icon_hints( Display *display, struct x11drv_win_data *data,
if (!icon_big)
{
icon_big = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_BIG, 0 );
if (!icon_big) icon_big = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICON );
icon_big = (HICON)SendMessageW( hwnd, WM_GETICON, ICON_BIG, 0 );
if (!icon_big) icon_big = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON );
if (!icon_big) icon_big = LoadIconW( 0, (LPWSTR)IDI_WINLOGO );
}
if (!icon_small)
{
icon_small = (HICON)SendMessageW( data->hwnd, WM_GETICON, ICON_SMALL, 0 );
if (!icon_small) icon_small = (HICON)GetClassLongPtrW( data->hwnd, GCLP_HICONSM );
icon_small = (HICON)SendMessageW( hwnd, WM_GETICON, ICON_SMALL, 0 );
if (!icon_small) icon_small = (HICON)GetClassLongPtrW( hwnd, GCLP_HICONSM );
}
if (!(data = X11DRV_get_win_data( hwnd ))) return;
if (data->icon_pixmap) XFreePixmap( gdi_display, data->icon_pixmap );
if (data->icon_mask) XFreePixmap( gdi_display, data->icon_mask );
data->icon_pixmap = data->icon_mask = 0;
data->wm_hints->flags &= ~(IconPixmapHint | IconMaskHint);
if (!GetIconInfo(icon_big, &ii)) return;
@ -633,9 +636,9 @@ static void set_icon_hints( Display *display, struct x11drv_win_data *data,
if (create_icon_pixmaps( hDC, &ii, data ))
{
hints->icon_pixmap = data->icon_pixmap;
hints->icon_mask = data->icon_mask;
hints->flags |= IconPixmapHint | IconMaskHint;
data->wm_hints->icon_pixmap = data->icon_pixmap;
data->wm_hints->icon_mask = data->icon_mask;
data->wm_hints->flags |= IconPixmapHint | IconMaskHint;
}
DeleteObject( ii.hbmColor );
DeleteObject( ii.hbmMask );
@ -757,8 +760,10 @@ static char *get_process_name(void)
*
* Set the window manager hints that don't change over the lifetime of a window.
*/
static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data )
static void set_initial_wm_hints( HWND hwnd )
{
Display *display = thread_display();
struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
long i;
Atom protocols[3];
Atom dndVersion = WINE_XDND_VERSION;
@ -803,7 +808,7 @@ static void set_initial_wm_hints( Display *display, struct x11drv_win_data *data
if (data->wm_hints)
{
data->wm_hints->flags = 0;
set_icon_hints( display, data, 0, 0 );
set_icon_hints( hwnd, 0, 0 );
}
}
@ -836,15 +841,17 @@ static Window get_owner_whole_window( HWND owner, BOOL force_managed )
*
* Set the window manager hints for a newly-created window
*/
static void set_wm_hints( Display *display, struct x11drv_win_data *data )
static void set_wm_hints( HWND hwnd )
{
Display *display = thread_display();
struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
Window group_leader = data->whole_window;
Window owner_win = 0;
Atom window_type;
DWORD style, ex_style;
HWND owner;
if (data->hwnd == GetDesktopWindow())
if (hwnd == GetDesktopWindow())
{
/* force some styles for the desktop to get the correct decorations */
style = WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
@ -853,9 +860,9 @@ static void set_wm_hints( Display *display, struct x11drv_win_data *data )
}
else
{
style = GetWindowLongW( data->hwnd, GWL_STYLE );
ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
owner = GetWindow( data->hwnd, GW_OWNER );
style = GetWindowLongW( hwnd, GWL_STYLE );
ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE );
owner = GetWindow( hwnd, GW_OWNER );
if ((owner_win = get_owner_whole_window( owner, data->managed ))) group_leader = owner_win;
}
@ -1035,13 +1042,16 @@ static void set_xembed_flags( Display *display, struct x11drv_win_data *data, un
/***********************************************************************
* map_window
*/
static void map_window( Display *display, struct x11drv_win_data *data, DWORD new_style )
static void map_window( HWND hwnd, DWORD new_style )
{
Display *display = thread_display();
struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
TRACE( "win %p/%lx\n", data->hwnd, data->whole_window );
remove_startup_notification( display, data->whole_window );
wait_for_withdrawn_state( display, data, TRUE );
wait_for_withdrawn_state( hwnd, TRUE );
if (!data->embedded)
{
@ -1059,13 +1069,16 @@ static void map_window( Display *display, struct x11drv_win_data *data, DWORD ne
/***********************************************************************
* unmap_window
*/
static void unmap_window( Display *display, struct x11drv_win_data *data )
static void unmap_window( HWND hwnd )
{
Display *display = thread_display();
struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
TRACE( "win %p/%lx\n", data->hwnd, data->whole_window );
if (!data->embedded)
{
wait_for_withdrawn_state( display, data, FALSE );
wait_for_withdrawn_state( hwnd, FALSE );
if (data->managed) XWithdrawWindow( display, data->whole_window, DefaultScreen(display) );
else XUnmapWindow( display, data->whole_window );
}
@ -1079,19 +1092,22 @@ static void unmap_window( Display *display, struct x11drv_win_data *data )
/***********************************************************************
* make_window_embedded
*/
void make_window_embedded( Display *display, struct x11drv_win_data *data )
void make_window_embedded( HWND hwnd )
{
Display *display = thread_display();
struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
BOOL was_mapped = data->mapped;
/* the window cannot be mapped before being embedded */
if (data->mapped) unmap_window( display, data );
if (data->mapped) unmap_window( hwnd );
data->embedded = TRUE;
data->managed = TRUE;
SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
SetPropA( hwnd, managed_prop, (HANDLE)1 );
sync_window_style( display, data );
if (was_mapped)
map_window( display, data, 0 );
map_window( hwnd, 0 );
else
set_xembed_flags( display, data, 0 );
}
@ -1227,9 +1243,10 @@ static void sync_window_position( Display *display, struct x11drv_win_data *data
*
* Move the window bits when a window is moved.
*/
static void move_window_bits( struct x11drv_win_data *data, const RECT *old_rect, const RECT *new_rect,
static void move_window_bits( HWND hwnd, const RECT *old_rect, const RECT *new_rect,
const RECT *old_client_rect )
{
struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
RECT src_rect = *old_rect;
RECT dst_rect = *new_rect;
HDC hdc_src, hdc_dst;
@ -1295,8 +1312,10 @@ static void move_window_bits( struct x11drv_win_data *data, const RECT *old_rect
*
* Create the whole X window for a given window
*/
static Window create_whole_window( Display *display, struct x11drv_win_data *data )
static Window create_whole_window( HWND hwnd )
{
Display *display = thread_display();
struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
int cx, cy, mask;
XSetWindowAttributes attr;
WCHAR text[1024];
@ -1336,8 +1355,8 @@ static Window create_whole_window( Display *display, struct x11drv_win_data *dat
visual, mask, &attr );
if (!data->whole_window) goto done;
set_initial_wm_hints( display, data );
set_wm_hints( display, data );
set_initial_wm_hints( hwnd );
set_wm_hints( hwnd );
XSaveContext( display, data->whole_window, winContext, (char *)data->hwnd );
SetPropA( data->hwnd, whole_window_prop, (HANDLE)data->whole_window );
@ -1441,8 +1460,7 @@ void CDECL X11DRV_SetWindowStyle( HWND hwnd, INT offset, STYLESTRUCT *style )
changed = style->styleNew ^ style->styleOld;
if (offset == GWL_STYLE && (changed & WS_DISABLED))
set_wm_hints( thread_display(), data );
if (offset == GWL_STYLE && (changed & WS_DISABLED)) set_wm_hints( hwnd );
if (offset == GWL_EXSTYLE && (changed & WS_EX_LAYERED)) /* changing WS_EX_LAYERED resets attributes */
{
@ -1513,7 +1531,7 @@ static struct x11drv_win_data *create_desktop_win_data( Display *display, HWND h
data->managed = TRUE;
SetPropA( data->hwnd, managed_prop, (HANDLE)1 );
SetPropA( data->hwnd, whole_window_prop, (HANDLE)root_window );
set_initial_wm_hints( display, data );
set_initial_wm_hints( hwnd );
return data;
}
@ -1630,7 +1648,7 @@ static struct x11drv_win_data *X11DRV_create_win_data( HWND hwnd, const RECT *wi
if (parent == GetDesktopWindow())
{
if (!create_whole_window( display, data ))
if (!create_whole_window( hwnd ))
{
HeapFree( GetProcessHeap(), 0, data );
return NULL;
@ -1913,7 +1931,7 @@ void CDECL X11DRV_SetParent( HWND hwnd, HWND parent, HWND old_parent )
else /* new top level window */
{
/* FIXME: we ignore errors since we can't really recover anyway */
create_whole_window( display, data );
create_whole_window( hwnd );
}
}
@ -1982,7 +2000,7 @@ void CDECL X11DRV_WindowPosChanging( HWND hwnd, HWND insert_after, UINT swp_flag
if (!data->managed && data->whole_window && is_window_managed( hwnd, swp_flags, window_rect ))
{
TRACE( "making win %p/%lx managed\n", hwnd, data->whole_window );
if (data->mapped) unmap_window( thread_display(), data );
if (data->mapped) unmap_window( hwnd );
data->managed = TRUE;
SetPropA( hwnd, managed_prop, (HANDLE)1 );
}
@ -2075,10 +2093,10 @@ void CDECL X11DRV_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_flags
{
/* if we have an X window the bits will be moved by the X server */
if (!data->whole_window && (x_offset != 0 || y_offset != 0))
move_window_bits( data, &old_whole_rect, &data->whole_rect, &old_client_rect );
move_window_bits( hwnd, &old_whole_rect, &data->whole_rect, &old_client_rect );
}
else
move_window_bits( data, &valid_rects[1], &valid_rects[0], &old_client_rect );
move_window_bits( hwnd, &valid_rects[1], &valid_rects[0], &old_client_rect );
}
XFlush( gdi_display ); /* make sure painting is done before we move the window */
@ -2102,7 +2120,7 @@ void CDECL X11DRV_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_flags
(!event_type &&
!is_window_rect_mapped( rectWindow ) && is_window_rect_mapped( &old_window_rect )))
{
unmap_window( display, data );
unmap_window( hwnd );
if (is_window_rect_fullscreen( &old_window_rect )) reset_clipping_window();
}
}
@ -2116,12 +2134,11 @@ void CDECL X11DRV_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_flags
if ((new_style & WS_VISIBLE) &&
((new_style & WS_MINIMIZE) || is_window_rect_mapped( rectWindow )))
{
if (!data->mapped || (swp_flags & (SWP_FRAMECHANGED|SWP_STATECHANGED)))
set_wm_hints( display, data );
if (!data->mapped || (swp_flags & (SWP_FRAMECHANGED|SWP_STATECHANGED))) set_wm_hints( hwnd );
if (!data->mapped)
{
map_window( display, data, new_style );
map_window( hwnd, new_style );
}
else if ((swp_flags & SWP_STATECHANGED) && (!data->iconic != !(new_style & WS_MINIMIZE)))
{
@ -2206,8 +2223,8 @@ void CDECL X11DRV_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
if (data->wm_hints)
{
if (type == ICON_BIG) set_icon_hints( display, data, icon, 0 );
else set_icon_hints( display, data, 0, icon );
if (type == ICON_BIG) set_icon_hints( hwnd, icon, 0 );
else set_icon_hints( hwnd, 0, icon );
XSetWMHints( display, data->whole_window, data->wm_hints );
}
}
@ -2386,6 +2403,6 @@ LRESULT CDECL X11DRV_SysCommand( HWND hwnd, WPARAM wparam, LPARAM lparam )
return -1;
}
move_resize_window( display, data, dir );
move_resize_window( hwnd, dir );
return 0;
}

View File

@ -562,11 +562,11 @@ extern BOOL has_gl_drawable( HWND hwnd ) DECLSPEC_HIDDEN;
extern void sync_gl_drawable( HWND hwnd, const RECT *visible_rect, const RECT *client_rect ) DECLSPEC_HIDDEN;
extern void destroy_gl_drawable( HWND hwnd ) DECLSPEC_HIDDEN;
extern void wait_for_withdrawn_state( Display *display, struct x11drv_win_data *data, BOOL set ) DECLSPEC_HIDDEN;
extern void wait_for_withdrawn_state( HWND hwnd, BOOL set ) DECLSPEC_HIDDEN;
extern Window init_clip_window(void) DECLSPEC_HIDDEN;
extern void update_user_time( Time time ) DECLSPEC_HIDDEN;
extern void update_net_wm_states( Display *display, struct x11drv_win_data *data ) DECLSPEC_HIDDEN;
extern void make_window_embedded( Display *display, struct x11drv_win_data *data ) DECLSPEC_HIDDEN;
extern void make_window_embedded( HWND hwnd ) DECLSPEC_HIDDEN;
extern void change_systray_owner( Display *display, Window systray_window ) DECLSPEC_HIDDEN;
extern void update_systray_balloon_position(void) DECLSPEC_HIDDEN;
extern HWND create_foreign_window( Display *display, Window window ) DECLSPEC_HIDDEN;
@ -610,7 +610,7 @@ extern LRESULT clip_cursor_notify( HWND hwnd, HWND new_clip_hwnd ) DECLSPEC_HIDD
extern void ungrab_clipping_window(void) DECLSPEC_HIDDEN;
extern void reset_clipping_window(void) DECLSPEC_HIDDEN;
extern BOOL clip_fullscreen_window( HWND hwnd, BOOL reset ) DECLSPEC_HIDDEN;
extern void move_resize_window( Display *display, struct x11drv_win_data *data, int dir ) DECLSPEC_HIDDEN;
extern void move_resize_window( HWND hwnd, int dir ) DECLSPEC_HIDDEN;
extern void X11DRV_InitKeyboard( Display *display ) DECLSPEC_HIDDEN;
extern DWORD CDECL X11DRV_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, DWORD timeout,
DWORD mask, DWORD flags ) DECLSPEC_HIDDEN;