Skip to content

Commit

Permalink
winex11.drv: Use desktop cursor notification message.
Browse files Browse the repository at this point in the history
Instead of manually synchronizing the cursor.
  • Loading branch information
rbernon authored and aeikum committed May 14, 2021
1 parent 6780066 commit ec72c4a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 57 deletions.
63 changes: 10 additions & 53 deletions dlls/winex11.drv/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ static const UINT button_up_data[NB_BUTTONS] =

XContext cursor_context = 0;

static HWND cursor_window;
static HCURSOR last_cursor;
static DWORD last_cursor_change;
static RECT clip_rect;
static Cursor create_cursor( HANDLE handle );

Expand Down Expand Up @@ -237,24 +234,6 @@ void set_window_cursor( Window window, HCURSOR handle )
XFlush( gdi_display );
}

/***********************************************************************
* sync_window_cursor
*/
void sync_window_cursor( Window window )
{
HCURSOR cursor;

SERVER_START_REQ( set_cursor )
{
req->flags = 0;
wine_server_call( req );
cursor = reply->prev_count >= 0 ? wine_server_ptr_handle( reply->prev_handle ) : 0;
}
SERVER_END_REQ;

set_window_cursor( window, cursor );
}

struct mouse_button_mapping
{
int deviceid;
Expand Down Expand Up @@ -458,6 +437,7 @@ static BOOL grab_clipping_window( const RECT *clip )
{
static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0};
struct x11drv_thread_data *data = x11drv_thread_data();
HCURSOR cursor;
Window clip_window;
HWND msg_hwnd = 0;
POINT pos;
Expand Down Expand Up @@ -514,15 +494,22 @@ static BOOL grab_clipping_window( const RECT *clip )
GrabModeAsync, GrabModeAsync, clip_window, None, CurrentTime ))
clipping_cursor = TRUE;

SERVER_START_REQ( set_cursor )
{
req->flags = 0;
wine_server_call( req );
cursor = reply->prev_count >= 0 ? wine_server_ptr_handle( reply->prev_handle ) : 0;
}
SERVER_END_REQ;
set_window_cursor( clip_window, cursor );

if (!clipping_cursor)
{
X11DRV_XInput2_Disable();
DestroyWindow( msg_hwnd );
return FALSE;
}
clip_rect = *clip;
if (!data->clip_hwnd) sync_window_cursor( clip_window );
InterlockedExchangePointer( (void **)&cursor_window, msg_hwnd );
data->clip_hwnd = msg_hwnd;
SendNotifyMessageW( GetDesktopWindow(), WM_X11DRV_CLIP_CURSOR_NOTIFY, 0, (LPARAM)msg_hwnd );
return TRUE;
Expand Down Expand Up @@ -707,8 +694,6 @@ static POINT map_event_coords(const XButtonEvent *event, HWND hwnd)
*/
static void send_mouse_input( HWND hwnd, Window window, unsigned int state, INPUT *input )
{
struct x11drv_win_data *data;

input->type = INPUT_MOUSE;

if (!hwnd)
Expand All @@ -719,12 +704,6 @@ static void send_mouse_input( HWND hwnd, Window window, unsigned int state, INPU

if (!clip_hwnd) return;
if (thread_data->clip_window != window) return;
if (InterlockedExchangePointer( (void **)&cursor_window, clip_hwnd ) != clip_hwnd ||
input->u.mi.time - last_cursor_change > 100)
{
sync_window_cursor( window );
last_cursor_change = input->u.mi.time;
}

pt.x = clip_rect.left;
pt.y = clip_rect.top;
Expand All @@ -741,15 +720,6 @@ static void send_mouse_input( HWND hwnd, Window window, unsigned int state, INPU
return;
}

if ((InterlockedExchangePointer( (void **)&cursor_window, hwnd ) != hwnd ||
input->u.mi.time - last_cursor_change > 100) &&
(data = get_win_data( hwnd )))
{
sync_window_cursor( data->whole_window );
last_cursor_change = input->u.mi.time;
release_win_data( data );
}

if (hwnd != GetDesktopWindow())
{
hwnd = GetAncestor( hwnd, GA_ROOT );
Expand Down Expand Up @@ -1544,19 +1514,6 @@ void CDECL X11DRV_DestroyCursorIcon( HCURSOR handle )
}
}

/***********************************************************************
* SetCursor (X11DRV.@)
*/
void CDECL X11DRV_SetCursor( HCURSOR handle )
{
if (InterlockedExchangePointer( (void **)&last_cursor, handle ) != handle ||
GetTickCount() - last_cursor_change > 100)
{
last_cursor_change = GetTickCount();
if (cursor_window) SendNotifyMessageW( cursor_window, WM_X11DRV_SET_CURSOR, 0, (LPARAM)handle );
}
}

/***********************************************************************
* SetCursorPos (X11DRV.@)
*/
Expand Down
14 changes: 12 additions & 2 deletions dlls/winex11.drv/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -1891,8 +1891,6 @@ static void create_whole_window( struct x11drv_win_data *data )

XFlush( data->display ); /* make sure the window exists before we start painting to it */

sync_window_cursor( data->whole_window );

done:
if (win_rgn) DeleteObject( win_rgn );
}
Expand Down Expand Up @@ -2098,6 +2096,15 @@ BOOL CDECL X11DRV_CreateDesktopWindow( HWND hwnd )

detect_wm( gdi_display );

SERVER_START_REQ( set_cursor )
{
req->flags = SET_CURSOR_HANDLE;
req->handle = 0;
req->change_msg = WM_X11DRV_DESKTOP_SET_WINDOW_CURSOR;
wine_server_call( req );
}
SERVER_END_REQ;

/* retrieve the real size of the desktop */
SERVER_START_REQ( get_window_rectangles )
{
Expand Down Expand Up @@ -3147,6 +3154,9 @@ LRESULT CDECL X11DRV_WindowMessage( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
}
if (clipping_cursor) set_window_cursor( x11drv_thread_data()->clip_window, (HCURSOR)lp );
return 0;
case WM_X11DRV_DESKTOP_SET_WINDOW_CURSOR:
SendNotifyMessageW( (HWND)wp, WM_X11DRV_SET_CURSOR, 0, lp );
return 0;
case WM_X11DRV_CLIP_CURSOR_NOTIFY:
return clip_cursor_notify( hwnd, (HWND)wp, (HWND)lp );
case WM_X11DRV_CLIP_CURSOR_REQUEST:
Expand Down
1 change: 0 additions & 1 deletion dlls/winex11.drv/winex11.drv.spec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
@ cdecl UnloadKeyboardLayout(long) X11DRV_UnloadKeyboardLayout
@ cdecl VkKeyScanEx(long long) X11DRV_VkKeyScanEx
@ cdecl DestroyCursorIcon(long) X11DRV_DestroyCursorIcon
@ cdecl SetCursor(long) X11DRV_SetCursor
@ cdecl GetCursorPos(ptr) X11DRV_GetCursorPos
@ cdecl SetCursorPos(long long) X11DRV_SetCursorPos
@ cdecl ClipCursor(ptr) X11DRV_ClipCursor
Expand Down
2 changes: 1 addition & 1 deletion dlls/winex11.drv/x11drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ enum x11drv_window_messages
WM_X11DRV_SET_WIN_REGION,
WM_X11DRV_RESIZE_DESKTOP,
WM_X11DRV_SET_CURSOR,
WM_X11DRV_DESKTOP_SET_WINDOW_CURSOR,
WM_X11DRV_CLIP_CURSOR_NOTIFY,
WM_X11DRV_CLIP_CURSOR_REQUEST,
WM_X11DRV_RELEASE_CURSOR
Expand Down Expand Up @@ -665,7 +666,6 @@ extern XContext cursor_context DECLSPEC_HIDDEN;
extern void X11DRV_InitClipboard(void) DECLSPEC_HIDDEN;
extern void CDECL X11DRV_SetFocus( HWND hwnd ) DECLSPEC_HIDDEN;
extern void set_window_cursor( Window window, HCURSOR handle ) DECLSPEC_HIDDEN;
extern void sync_window_cursor( Window window ) DECLSPEC_HIDDEN;
extern LRESULT clip_cursor_notify( HWND hwnd, HWND prev_clip_hwnd, HWND new_clip_hwnd ) DECLSPEC_HIDDEN;
extern LRESULT clip_cursor_request( HWND hwnd, BOOL fullscreen, BOOL reset ) DECLSPEC_HIDDEN;
extern void ungrab_clipping_window(void) DECLSPEC_HIDDEN;
Expand Down

0 comments on commit ec72c4a

Please sign in to comment.