We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5352 - SDL_SetRelativeMouseMode broken on Linux/X11 after workspace switch
Summary: SDL_SetRelativeMouseMode broken on Linux/X11 after workspace switch
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: HG 2.0
Hardware: All Linux
: P2 major
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-13 12:41 UTC by Lee Salzman
Modified: 2020-11-24 02:08 UTC (History)
3 users (show)

See Also:


Attachments
Patch to only attempt to grab the X11 window if it is actually mapped (1.55 KB, patch)
2020-11-13 18:33 UTC, Lee Salzman
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Lee Salzman 2020-11-13 12:41:01 UTC
The implementation of SDL_SetRelativeMouseMode on X11 calls XGrabPointer while the window is unmapped after an UnmapNotify event gets sent on a workspace switch. This is because XGrabPointer (and XGrabKeyboard) returns GrabNotViewable and sets the broken_pointer_grab variable to true thereafter, so that relative mouse mode forever after no longer tries to grab the mouse until the application is restarted.

XGrabPointer should only be called after switching back to the workspace when MapNotify is finally called. But it is instead called when SDL_SetKeyboardFocus is called from FocusIn before the MapNotify is received.

The sequence of events on the workspace switch look like:

UnmapNotify
FocusOut
 ... XUngrabPointer
FocusIn
 ... XGrabPointer ("WARN: The X server refused to let us grab the mouse. You might experience input bugs.")
MapNotify

So somehow SDL_UpdateWindowGrab needs to be fixed to only get called after the window is properly mapped back in to avoid XGrabPointer rturning GrabNotViewable.
Comment 1 Lee Salzman 2020-11-13 12:42:53 UTC
This sequence of X11 events seems to occur as well when it gets minimized, not just from the workspace switch.
Comment 2 Lee Salzman 2020-11-13 18:33:05 UTC
Created attachment 4520 [details]
Patch to only attempt to grab the X11 window if it is actually mapped

The fix here seems somewhat simple. In the MapNotify handler I add an extra check to update the window grab if the window is no longer hidden and we have input focus.

Otherwise, in the actual X11_SetWindowGrab function I made it only try to grab the window if the window is actually mapped.

This should prevent the broken_point_grab condition from triggering unless pointer grabbing broke for some other reason than the window not being viewable.
Comment 3 Ryan C. Gordon 2020-11-24 02:08:11 UTC
This patch is now https://hg.libsdl.org/SDL/rev/71ba33032c2f, thanks!

--ryan.