From 52a4366e544fbaf6571d914361dbac323467206a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 25 Nov 2025 14:29:05 -0800 Subject: [PATCH] x11: don't grab the pointer while buttons are pressed Grabbing the mouse interrupts touch events in progress, so if someone enables relative mode while a button is pressed, wait for the button to be released before grabbing the mouse. --- src/video/x11/SDL_x11events.c | 4 ++++ src/video/x11/SDL_x11window.c | 4 +++- src/video/x11/SDL_x11window.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index 960d254ddf..eec3f4cd56 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -1180,6 +1180,10 @@ void X11_HandleButtonRelease(SDL_VideoDevice *_this, SDL_WindowData *windowdata, button -= (8 - SDL_BUTTON_X1); } SDL_SendMouseButton(timestamp, window, mouseID, button, false); + + if (window->internal->pending_grab) { + X11_SetWindowMouseGrab(_this, window, true); + } } } diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 375d471a19..b446908788 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -2058,6 +2058,7 @@ bool X11_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool gra return SDL_SetError("Invalid window data"); } data->mouse_grabbed = false; + data->pending_grab = false; display = data->videodata->display; @@ -2075,7 +2076,8 @@ bool X11_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool gra * the confinement grab. */ if (data->xinput2_mouse_enabled && SDL_GetMouseState(NULL, NULL)) { - X11_XUngrabPointer(display, CurrentTime); + data->pending_grab = true; + return true; } // Try to grab the mouse diff --git a/src/video/x11/SDL_x11window.h b/src/video/x11/SDL_x11window.h index 36e259a77f..a7fad8982b 100644 --- a/src/video/x11/SDL_x11window.h +++ b/src/video/x11/SDL_x11window.h @@ -118,6 +118,7 @@ struct SDL_WindowData bool was_shown; bool emit_size_move_after_property_notify; SDL_HitTestResult hit_test_result; + bool pending_grab; XPoint xim_spot; char *preedit_text;