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.
This commit is contained in:
Sam Lantinga
2025-11-25 14:29:05 -08:00
parent 7e5f3330ff
commit 52a4366e54
3 changed files with 8 additions and 1 deletions

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -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;