-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SDL_SetWindowGrab doesn't work with mouse not hidden (SDL2, X11 video driver only) #9162
Comments
Thanks to this helpful comment I was able to test confinement with Sadly, many distributions still seem to ship SDL2 with SDL_VIDEODRIVER=x11 as a default and probably also without libdecor. Therefore, this bug still seems relevant today. |
@Kontrabant, is this possible to fix when XWayland is in use? |
Will look into this, although this might be a KDE bug, as it works fine on GNOME with XWayland. |
Something is definitely broken in KDE. When grabbing on my test system (Fedora 39 with all updates), the cursor is blocked on the sides and bottom, but can escape from the top in both this sample and when grabbing via ctrl+G in testsprite. When the cursor escapes from the top, no leave event occurs and mouse events continue to arrive when moving the mouse, even though the cursor is not over the window anymore. Note that on both GNOME and KDE, if a grab is initiated while the cursor is outside of the window, it won't be confined until the mouse is clicked while the cursor over the window. I'm guessing this is some internal XWayland behavior since it happens regardless of desktop. This needs to go upstream, as there's nothing that SDL can do to fix this. |
Thanks so much for looking into this! I filed a KDE bug here: https://bugs.kde.org/show_bug.cgi?id=482448 |
Since it seems like this is being fixed in KWin/KDE now, I'll close this here! Thanks again for your help. |
SDL_SetWindowGrab doesn't work with the mouse cursor still shown. The mouse is only confined to the window if SDL_ShowCursor is also set to SDL_FALSE, but the documentation of SDL_SetWindowGrab seems to claim that's not an intended precondition:
(Note no mention that the confinement depends on the mouse cursor being hidden.)
This is at least broken when using SDL 2.30.0-1.1 as packaged by OpenSUSE with KDE Plasma Shell 5.27.10 with a Wayland session, SDL defaulting to SDL_VIDEODRIVER=x11 with this setup. Not sure about whether this actually works on other platforms.
Edit: Here's code to reproduce it:
What happens, with the expected behavior that the mouse cursor is trapped to the window at least as long as the window has focus (I click it during the runtime of the video but it doesn't make any difference):
bug-sdl2-nomouseconfinement.webm
The text was updated successfully, but these errors were encountered: