pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
773 stars 120 forks source link

Fixed mouse.set_pos under wayland #2807

Closed mzivic7 closed 2 months ago

mzivic7 commented 2 months ago

I found the reason why mouse.set_pos() is not working under wayland (xwyland), in one of blender bug reports:

The issue is that the cursor cannot be warped as long as it is visible. The way things work currently is, if a cursor is hidden and it is warped, we lie to X11 clients and say it is actually warped. While doing so, we lock the pointer via the available Wayland protocols. When the cursor is made visible or that for some other reason the lock is broken (for example the user Alt-tab:ed away), we stop lying and where the visible cursor is displayed is the position we tell the clients about. This works for the majority of use cases we have run into (including Blender uses, excluding the one discussed in this report). We handle confinement in a more direct way. In other words, if the patch implements a behavior where the pointer cursor is warped while visible, it wont work. If the pointer cursor is confined using X11 protocol, or hidden then warped, and it doesn't work, it could very much be an Xwayland issue.

I tried this:

pygame.mouse.set_visible(False)
pygame.mouse.set_pos(300, 300)
pygame.mouse.set_visible(True)

and it worked!

So, I just added PG_HideCursor(); before and PG_ShowCursor(); after this line.

mzivic7 commented 2 months ago

Closes #2799

mzivic7 commented 2 months ago

I reported issue upstream to SDL: here

Starbuck5 commented 2 months ago

So SDL has fixed it, but only for SDL3. Great research and effort @mzivic7!

I just asked on your issue there whether they think it's worth back-porting to SDL2. If they do back-port, I say we let them handle this hack instead of putting it into our own code.

If they don't want to back-port, we'll have to think further about how much we care about this. One thing for sure though, if we put this into our code I want comments in the codebase explaining exactly why.

ankith26 commented 2 months ago

Update: the SDL devs have backported the fix to SDL2

Thanks @mzivic7 for reporting the issue upstream and suggesting the fix. Now to get this fix on our side we just gotta bump SDL when they release the next release.

mzivic7 commented 2 months ago

Great, I will close this pr and issue, since this is no longer related to pygame-ce code.