rust-mobile / android-activity

Glue for building Rust applications on Android with NativeActivity or GameActivity
238 stars 46 forks source link

Can't get multitouch to work with native activity #146

Closed griffi-gh closed 7 months ago

griffi-gh commented 9 months ago

Not sure who to blame here (me, android-activity or winit), but after switching from ndk_glue to this crate + latest winit version my application no longer receives Touch start/end/cancel events for the second finger, only move ones; and even those are broken (position is in the center of two fingers)

griffi-gh commented 9 months ago

Code_0deOcabduw

rib commented 8 months ago

Curious - I'm working with multi-touch based on android-activity and as far as I know, multi touch should be working ok.

I work on an application that has independent camera controls for moving the camera with one finger and rotating the camera with another and that's been working for some time so I'd be surprised if start/end/cancel events weren't being sent as expected for multiple fingers. (Also based on Winit)

Maybe you could try out one of the egui examples here: https://github.com/rust-mobile/rust-android-examples and see if the multitouch input is working as expected there.

I'm also hoping to update those examples and can aim to double check the behaviour of multitouch.

ArthurCose commented 8 months ago

There's an order to the inputs that makes it hard to reproduce, it might not always be visible.

Releasing the first-touch first will allow the second touch to receive start/end/cancel events. Releasing the second-touch first will create a MotionAction::__Unknown that's ignored by winit.

The __Unknown appears to be created from ndk_sys::AKeyEvent_getAction() returning a number that stores the "pointer index".

The issue disappeared for me when I applied the same filter used by game activity: https://github.com/rust-mobile/android-activity/blob/9fce89021959a6f6ea8853221367bfa305803369/android-activity/src/game_activity/input.rs#L66

rib commented 7 months ago

This should be fixed by https://github.com/rust-mobile/android-activity/pull/147 (thanks @ArthurCose)

I'll look at rolling a 0.5.2 release now.