Commit a59c7cc8 authored by Alexandre Julliard's avatar Alexandre Julliard

winex11: Automatically clip the pointer when the foreground window is full-screen.

parent a07b8411
...@@ -200,6 +200,7 @@ static BOOL CALLBACK update_windows_on_desktop_resize( HWND hwnd, LPARAM lparam ...@@ -200,6 +200,7 @@ static BOOL CALLBACK update_windows_on_desktop_resize( HWND hwnd, LPARAM lparam
DefaultScreen(display), mask, &changes ); DefaultScreen(display), mask, &changes );
wine_tsx11_unlock(); wine_tsx11_unlock();
} }
if (hwnd == GetForegroundWindow()) clip_fullscreen_window( hwnd );
return TRUE; return TRUE;
} }
......
...@@ -714,7 +714,11 @@ static void X11DRV_FocusIn( HWND hwnd, XEvent *xev ) ...@@ -714,7 +714,11 @@ static void X11DRV_FocusIn( HWND hwnd, XEvent *xev )
XSetICFocus( xic ); XSetICFocus( xic );
wine_tsx11_unlock(); wine_tsx11_unlock();
} }
if (use_take_focus) return; /* ignore FocusIn if we are using take focus */ if (use_take_focus)
{
if (hwnd == GetForegroundWindow()) clip_fullscreen_window( hwnd );
return;
}
if (!can_activate_window(hwnd)) if (!can_activate_window(hwnd))
{ {
......
...@@ -373,7 +373,7 @@ static HWND create_clipping_msg_window(void) ...@@ -373,7 +373,7 @@ static HWND create_clipping_msg_window(void)
* *
* Start a pointer grab on the clip window. * Start a pointer grab on the clip window.
*/ */
static BOOL grab_clipping_window( const RECT *clip ) static BOOL grab_clipping_window( const RECT *clip, BOOL only_with_xinput )
{ {
struct x11drv_thread_data *data = x11drv_thread_data(); struct x11drv_thread_data *data = x11drv_thread_data();
Window clip_window; Window clip_window;
...@@ -390,7 +390,8 @@ static BOOL grab_clipping_window( const RECT *clip ) ...@@ -390,7 +390,8 @@ static BOOL grab_clipping_window( const RECT *clip )
} }
/* don't clip to 1x1 rectangle if we don't have XInput */ /* don't clip to 1x1 rectangle if we don't have XInput */
if (data->xi2_state != xi_enabled && clip->right - clip->left == 1 && clip->bottom - clip->top == 1) if (clip->right - clip->left == 1 && clip->bottom - clip->top == 1) only_with_xinput = TRUE;
if (only_with_xinput && data->xi2_state != xi_enabled)
{ {
WARN( "XInput2 not supported, refusing to clip to %s\n", wine_dbgstr_rect(clip) ); WARN( "XInput2 not supported, refusing to clip to %s\n", wine_dbgstr_rect(clip) );
if (msg_hwnd) DestroyWindow( msg_hwnd ); if (msg_hwnd) DestroyWindow( msg_hwnd );
...@@ -480,6 +481,7 @@ LRESULT clip_cursor_notify( HWND hwnd, HWND new_clip_hwnd ) ...@@ -480,6 +481,7 @@ LRESULT clip_cursor_notify( HWND hwnd, HWND new_clip_hwnd )
else if (hwnd == data->clip_hwnd) /* this is a notification that clipping has been reset */ else if (hwnd == data->clip_hwnd) /* this is a notification that clipping has been reset */
{ {
data->clip_hwnd = 0; data->clip_hwnd = 0;
data->clip_reset = GetTickCount();
disable_xinput2(); disable_xinput2();
DestroyWindow( hwnd ); DestroyWindow( hwnd );
} }
...@@ -490,12 +492,39 @@ LRESULT clip_cursor_notify( HWND hwnd, HWND new_clip_hwnd ) ...@@ -490,12 +492,39 @@ LRESULT clip_cursor_notify( HWND hwnd, HWND new_clip_hwnd )
GetClipCursor( &clip ); GetClipCursor( &clip );
if (clip.left > virtual_screen_rect.left || clip.right < virtual_screen_rect.right || if (clip.left > virtual_screen_rect.left || clip.right < virtual_screen_rect.right ||
clip.top > virtual_screen_rect.top || clip.bottom < virtual_screen_rect.bottom) clip.top > virtual_screen_rect.top || clip.bottom < virtual_screen_rect.bottom)
return grab_clipping_window( &clip ); return grab_clipping_window( &clip, FALSE );
} }
return 0; return 0;
} }
/*********************************************************************** /***********************************************************************
* clip_fullscreen_window
*
* Turn on clipping if the active window is fullscreen.
*/
BOOL clip_fullscreen_window( HWND hwnd )
{
struct x11drv_win_data *data;
RECT rect;
DWORD style;
if (hwnd == GetDesktopWindow()) return FALSE;
if (!(data = X11DRV_get_win_data( hwnd ))) return FALSE;
style = GetWindowLongW( hwnd, GWL_STYLE );
if (!(style & WS_VISIBLE)) return FALSE;
if ((style & (WS_POPUP | WS_CHILD)) == WS_CHILD) return FALSE;
/* maximized windows don't count as full screen */
if ((style & WS_MAXIMIZE) && (style & WS_CAPTION) == WS_CAPTION) return FALSE;
if (!is_window_rect_fullscreen( &data->whole_rect )) return FALSE;
if (GetTickCount() - x11drv_thread_data()->clip_reset < 1000) return FALSE;
SetRect( &rect, 0, 0, screen_width, screen_height );
if (!EqualRect( &rect, &virtual_screen_rect )) return FALSE;
if (root_window != DefaultRootWindow( gdi_display )) return FALSE;
TRACE( "win %p clipping fullscreen\n", hwnd );
return grab_clipping_window( &rect, TRUE );
}
/***********************************************************************
* send_mouse_input * send_mouse_input
* *
* Update the various window states on a mouse event. * Update the various window states on a mouse event.
...@@ -540,7 +569,12 @@ static void send_mouse_input( HWND hwnd, Window window, unsigned int state, INPU ...@@ -540,7 +569,12 @@ static void send_mouse_input( HWND hwnd, Window window, unsigned int state, INPU
last_cursor_change = GetTickCount(); last_cursor_change = GetTickCount();
} }
if (hwnd != GetDesktopWindow()) hwnd = GetAncestor( hwnd, GA_ROOT ); if (hwnd != GetDesktopWindow())
{
hwnd = GetAncestor( hwnd, GA_ROOT );
if ((input->u.mi.dwFlags & (MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_RIGHTDOWN)) && hwnd == GetForegroundWindow())
clip_fullscreen_window( hwnd );
}
/* update the wine server Z-order */ /* update the wine server Z-order */
...@@ -1221,25 +1255,31 @@ BOOL CDECL X11DRV_ClipCursor( LPCRECT clip ) ...@@ -1221,25 +1255,31 @@ BOOL CDECL X11DRV_ClipCursor( LPCRECT clip )
if (GetWindowThreadProcessId( GetDesktopWindow(), NULL ) == GetCurrentThreadId()) if (GetWindowThreadProcessId( GetDesktopWindow(), NULL ) == GetCurrentThreadId())
return TRUE; /* don't clip in the desktop process */ return TRUE; /* don't clip in the desktop process */
/* we are clipping if the clip rectangle is smaller than the screen */ if (grab_pointer)
if (grab_pointer && (clip->left > virtual_screen_rect.left ||
clip->right < virtual_screen_rect.right ||
clip->top > virtual_screen_rect.top ||
clip->bottom < virtual_screen_rect.bottom))
{ {
DWORD tid, pid;
HWND foreground = GetForegroundWindow(); HWND foreground = GetForegroundWindow();
/* forward request to the foreground window if it's in a different thread */ /* we are clipping if the clip rectangle is smaller than the screen */
tid = GetWindowThreadProcessId( foreground, &pid ); if (clip->left > virtual_screen_rect.left || clip->right < virtual_screen_rect.right ||
if (tid && tid != GetCurrentThreadId() && pid == GetCurrentProcessId()) clip->top > virtual_screen_rect.top || clip->bottom < virtual_screen_rect.bottom)
{ {
TRACE( "forwarding clip request to %p\n", foreground ); DWORD tid, pid;
if (SendMessageW( foreground, WM_X11DRV_CLIP_CURSOR, 0, 0 )) return TRUE;
/* forward request to the foreground window if it's in a different thread */
tid = GetWindowThreadProcessId( foreground, &pid );
if (tid && tid != GetCurrentThreadId() && pid == GetCurrentProcessId())
{
TRACE( "forwarding clip request to %p\n", foreground );
if (SendMessageW( foreground, WM_X11DRV_CLIP_CURSOR, 0, 0 )) return TRUE;
}
else if (grab_clipping_window( clip, FALSE )) return TRUE;
}
else /* if currently clipping, check if we should switch to fullscreen clipping */
{
struct x11drv_thread_data *data = x11drv_thread_data();
if (data && data->clip_hwnd && clip_fullscreen_window( foreground )) return TRUE;
} }
else if (grab_clipping_window( clip )) return TRUE;
} }
ungrab_clipping_window(); ungrab_clipping_window();
return TRUE; return TRUE;
} }
......
...@@ -552,6 +552,7 @@ struct x11drv_thread_data ...@@ -552,6 +552,7 @@ struct x11drv_thread_data
Window selection_wnd; /* window used for selection interactions */ Window selection_wnd; /* window used for selection interactions */
Window clip_window; /* window used for cursor clipping */ Window clip_window; /* window used for cursor clipping */
HWND clip_hwnd; /* message window stored in desktop while clipping is active */ HWND clip_hwnd; /* message window stored in desktop while clipping is active */
DWORD clip_reset; /* time when clipping was last reset */
HKL kbd_layout; /* active keyboard layout */ HKL kbd_layout; /* active keyboard layout */
enum { xi_unavailable = -1, xi_unknown, xi_disabled, xi_enabled } xi2_state; /* XInput2 state */ enum { xi_unavailable = -1, xi_unknown, xi_disabled, xi_enabled } xi2_state; /* XInput2 state */
}; };
...@@ -844,6 +845,7 @@ extern void sync_window_cursor( Window window ); ...@@ -844,6 +845,7 @@ extern void sync_window_cursor( Window window );
extern LRESULT clip_cursor_notify( HWND hwnd, HWND new_clip_hwnd ); extern LRESULT clip_cursor_notify( HWND hwnd, HWND new_clip_hwnd );
extern void ungrab_clipping_window(void); extern void ungrab_clipping_window(void);
extern void reset_clipping_window(void); extern void reset_clipping_window(void);
extern BOOL clip_fullscreen_window( HWND hwnd );
extern void X11DRV_InitKeyboard( Display *display ); extern void X11DRV_InitKeyboard( Display *display );
extern DWORD CDECL X11DRV_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, DWORD timeout, extern DWORD CDECL X11DRV_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, DWORD timeout,
DWORD mask, DWORD flags ); DWORD mask, DWORD flags );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment