libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
10.15k stars 1.86k forks source link

Motion events emulation & multitouch gestures for touch events broken as of 2.0.22 on certain devices (X11) #5652

Closed mil closed 2 years ago

mil commented 2 years ago

As of upgrading to 2.0.22 on certain devices on X11, the emulation of motion events for touch devices is broken. Specifically I'm testing on the Pinephone on X11. What I've observed is that SDL_MOUSEBUTTONUP and SDL_MOUSEBUTTONDOWN are properly reported, however SDL_MOUSEMOTION events are not reported. Additionally gesture events (SDL_MULTIGESTURE) are not reported. Downgrading to 2.0.20 fixes these issues and SDL_MULTIGESTURE and SDL_MOUSEMOTION are then properly reported.

I've also noticed that setting the hint SDL_TOUCH_MOUSE_EVENTS to 0 restores the functionality of SDL_MULTIGESTURE events (but doesn't effect motion events..).

If I had to guess the root cause of this issue is: https://github.com/libsdl-org/SDL/commit/8f8b14cbb684603e71e5ee5ccf6e07f460efbb4c .. however I haven't tested beyond just downgrading to 2.0.20 and seeing things work.

I'm testing on X11/Alpine Linux edge (postmarketOS) on a Pinephone (aarch64). Two example applications packaged to test with are mepo and rue which both use touch events (and you can observe differences in application functionality between 2.0.22 and 2.0.20).

mil commented 2 years ago

https://github.com/koreader/koreader/issues/9091 ^ found this issue in researching as well, may be related

slouken commented 2 years ago

Can you check that commit and see if that's the problem? It doesn't look like that would have the effect you're describing, offhand.

mil commented 2 years ago

Hmm, so I tested reverting both: https://github.com/libsdl-org/SDL/commit/8f8b14cbb684603e71e5ee5ccf6e07f460efbb4c and https://github.com/libsdl-org/SDL/commit/96be9cddcc433f4ceeb7fa2c4df6b65196839b80 neither are the issue.

Not entirely sure on the root cause / where to investigate to determine cause of this issue. 2.0.20 is working as expected for me. Was there some rework to touch/motion events from 2.0.20 -> 2.0.22 that could be the cause.

slouken commented 2 years ago

Can you use git bisect to identify the breaking change?

mil commented 2 years ago

Offending commit is: 5ff42438e36e98c9d72ac70f5f5ce4599b96d3d2

Setting export SDL_MOUSE_AUTO_CAPTURE=0 fixes things on 2.0.22 for me; maybe auto capture should be disabled by default

slouken commented 2 years ago

Why does auto capture affect touch events?

sezero commented 2 years ago

That commit caused way too many issues

dos1 commented 2 years ago

Touch handling on X11 with auto capture enabled is broken in general, it's not just gestures or mouse emulation. SDL sends an FINGERUP event right after FINGERDOWN (sometimes there's a single FINGERMOTION in between in you move your finger fast), so the touches end as soon as they start.

slouken commented 2 years ago

@icculus, can you look into this?

ell1e commented 2 years ago

For what it's worth, here is a reproduction case for the single touch mouse motion emulation (with SDL_MOUSE_TOUCHID) that has some visualization: https://github.com/libsdl-org/SDL/issues/5924#issue-1306801715 Doesn't cover multi touch however.

icculus commented 2 years ago

Yeah, I'll take a look.

slouken commented 2 years ago

I can reproduce this here, I'm investigating.

slouken commented 2 years ago

Fixed, thanks!