winex11: Replace the clipping message HWND with a BOOL flag.

We don't need the window anymore, it was only used to send ClipCursor
notifications. This improves cursor clipping performance a lot as it
avoids re-creating a window every time.
This commit is contained in:
Rémi Bernon 2023-06-14 00:12:03 +02:00 committed by Alexandre Julliard
parent 1f90d03b78
commit 272f712b60
2 changed files with 8 additions and 22 deletions

View file

@ -348,11 +348,8 @@ static void disable_xinput2(void)
static BOOL grab_clipping_window( const RECT *clip ) static BOOL grab_clipping_window( const RECT *clip )
{ {
#ifdef HAVE_X11_EXTENSIONS_XINPUT2_H #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0};
struct x11drv_thread_data *data = x11drv_thread_data(); struct x11drv_thread_data *data = x11drv_thread_data();
UNICODE_STRING class_name = RTL_CONSTANT_STRING( messageW );
Window clip_window; Window clip_window;
HWND msg_hwnd = 0;
HCURSOR cursor; HCURSOR cursor;
POINT pos; POINT pos;
@ -364,11 +361,6 @@ static BOOL grab_clipping_window( const RECT *clip )
if (!data) return FALSE; if (!data) return FALSE;
if (!(clip_window = init_clip_window())) return TRUE; if (!(clip_window = init_clip_window())) return TRUE;
if (!(msg_hwnd = NtUserCreateWindowEx( 0, &class_name, &class_name, NULL, 0, 0, 0, 0, 0,
HWND_MESSAGE, 0, NtCurrentTeb()->Peb->ImageBaseAddress,
NULL, 0, NULL, 0, FALSE )))
return TRUE;
if (keyboard_grabbed) if (keyboard_grabbed)
{ {
WARN( "refusing to clip to %s\n", wine_dbgstr_rect(clip) ); WARN( "refusing to clip to %s\n", wine_dbgstr_rect(clip) );
@ -376,26 +368,25 @@ static BOOL grab_clipping_window( const RECT *clip )
} }
/* enable XInput2 unless we are already clipping */ /* enable XInput2 unless we are already clipping */
if (!data->clip_hwnd) enable_xinput2(); if (!data->clipping_cursor) enable_xinput2();
if (data->xi2_state != xi_enabled) if (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) );
NtUserDestroyWindow( msg_hwnd );
NtUserClipCursor( NULL ); NtUserClipCursor( NULL );
return TRUE; return TRUE;
} }
TRACE( "clipping to %s win %lx\n", wine_dbgstr_rect(clip), clip_window ); TRACE( "clipping to %s win %lx\n", wine_dbgstr_rect(clip), clip_window );
if (!data->clip_hwnd) XUnmapWindow( data->display, clip_window ); if (!data->clipping_cursor) XUnmapWindow( data->display, clip_window );
pos = virtual_screen_to_root( clip->left, clip->top ); pos = virtual_screen_to_root( clip->left, clip->top );
XMoveResizeWindow( data->display, clip_window, pos.x, pos.y, XMoveResizeWindow( data->display, clip_window, pos.x, pos.y,
max( 1, clip->right - clip->left ), max( 1, clip->bottom - clip->top ) ); max( 1, clip->right - clip->left ), max( 1, clip->bottom - clip->top ) );
XMapWindow( data->display, clip_window ); XMapWindow( data->display, clip_window );
/* if the rectangle is shrinking we may get a pointer warp */ /* if the rectangle is shrinking we may get a pointer warp */
if (!data->clip_hwnd || clip->left > clip_rect.left || clip->top > clip_rect.top || if (!data->clipping_cursor || clip->left > clip_rect.left || clip->top > clip_rect.top ||
clip->right < clip_rect.right || clip->bottom < clip_rect.bottom) clip->right < clip_rect.right || clip->bottom < clip_rect.bottom)
data->warp_serial = NextRequest( data->display ); data->warp_serial = NextRequest( data->display );
@ -418,11 +409,10 @@ static BOOL grab_clipping_window( const RECT *clip )
if (!clipping_cursor) if (!clipping_cursor)
{ {
disable_xinput2(); disable_xinput2();
NtUserDestroyWindow( msg_hwnd );
return FALSE; return FALSE;
} }
clip_rect = *clip; clip_rect = *clip;
data->clip_hwnd = msg_hwnd; data->clipping_cursor = TRUE;
return TRUE; return TRUE;
#else #else
WARN( "XInput2 was not available at compile time\n" ); WARN( "XInput2 was not available at compile time\n" );
@ -446,8 +436,7 @@ void ungrab_clipping_window(void)
XUnmapWindow( data->display, clip_window ); XUnmapWindow( data->display, clip_window );
if (clipping_cursor) XUngrabPointer( data->display, CurrentTime ); if (clipping_cursor) XUngrabPointer( data->display, CurrentTime );
clipping_cursor = FALSE; clipping_cursor = FALSE;
NtUserDestroyWindow( data->clip_hwnd ); data->clipping_cursor = FALSE;
data->clip_hwnd = 0;
disable_xinput2(); disable_xinput2();
} }
@ -495,7 +484,7 @@ static void map_event_coords( HWND hwnd, Window window, Window event_root, int x
if (!hwnd) if (!hwnd)
{ {
thread_data = x11drv_thread_data(); thread_data = x11drv_thread_data();
if (!thread_data->clip_hwnd) return; if (!thread_data->clipping_cursor) return;
if (thread_data->clip_window != window) return; if (thread_data->clip_window != window) return;
pt.x += clip_rect.left; pt.x += clip_rect.left;
pt.y += clip_rect.top; pt.y += clip_rect.top;
@ -539,10 +528,7 @@ static void send_mouse_input( HWND hwnd, Window window, unsigned int state, INPU
if (!hwnd) if (!hwnd)
{ {
struct x11drv_thread_data *thread_data = x11drv_thread_data(); struct x11drv_thread_data *thread_data = x11drv_thread_data();
HWND clip_hwnd = thread_data->clip_hwnd; if (!thread_data->clipping_cursor || thread_data->clip_window != window) return;
if (!clip_hwnd) return;
if (thread_data->clip_window != window) return;
__wine_send_input( hwnd, input, NULL ); __wine_send_input( hwnd, input, NULL );
return; return;
} }

View file

@ -388,7 +388,7 @@ struct x11drv_thread_data
Window selection_wnd; /* window used for selection interactions */ Window selection_wnd; /* window used for selection interactions */
unsigned long warp_serial; /* serial number of last pointer warp request */ unsigned long warp_serial; /* serial number of last pointer warp request */
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 */ BOOL clipping_cursor; /* whether thread is currently clipping the cursor */
#ifdef HAVE_X11_EXTENSIONS_XINPUT2_H #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
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 */
void *xi2_devices; /* list of XInput2 devices (valid when state is enabled) */ void *xi2_devices; /* list of XInput2 devices (valid when state is enabled) */