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;