From 4eb08a6154b2a54ca9cf9178b60335485e9d8a56 Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Thu, 13 Jun 2024 12:39:20 -0400 Subject: [PATCH] x11: Ungrab before attempting a confinement grab with XInput2 enabled If XInput2 is enabled, it will grab the pointer on button presses, which results in XGrabPointer returning AlreadyGrabbed. Clear any existing grabs before attempting the confinement grab to avoid a timeout scenario. --- src/video/x11/SDL_x11window.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 7f0b75de9b..d696ced794 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -1855,6 +1855,14 @@ int X11_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool return 0; } + /* If XInput2 is enabled, it will grab the pointer on button presses, + * which results in XGrabPointer returning AlreadyGrabbed. Clear any + * existing grabs before attempting the confinement grab. + */ + if (data->xinput2_mouse_enabled) { + X11_XUngrabPointer(display, CurrentTime); + } + /* Try to grab the mouse */ if (!data->videodata->broken_pointer_grab) { const unsigned int mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask;