| Summary: | Mouse events simulation doesn't work on Android 11 | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Deve <deveee> |
| Component: | events | Assignee: | Sam Lantinga <slouken> |
| Status: | NEW --- | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | sylvain.becker |
| Version: | HG 2.1 | ||
| Hardware: | All | ||
| OS: | Android (All) | ||
| Attachments: | screenshot gamepad | ||
|
Description
Deve
2020-10-02 20:47:18 UTC
Just the context: SDL2 is creating Mouse (resp. Touch.) 'synthetic' events when the user move the real Touch (resp. Mouse) device. They appear with an id -1. And only if the hints are enabled. https://hg.libsdl.org/SDL/file/1b1fae168557/include/SDL_touch.h#l60 /* Used as the device ID for mouse events simulated with touch input */ #define SDL_TOUCH_MOUSEID ((Uint32)-1) /* Used as the SDL_TouchID for touch events simulated with mouse input */ #define SDL_MOUSE_TOUCHID ((Sint64)-1) https://hg.libsdl.org/SDL/file/1b1fae168557/include/SDL_hints.h#l350 See the hints: SDL_HINT_MOUSE_TOUCH_EVENTS SDL_HINT_TOUCH_MOUSE_EVENTS ... you can add traces in SDLActivity.java: public boolean onTouch(View v, MotionEvent event): trace the value of "touchDevId", it should be a real value, not -1. ( https://developer.android.com/reference/android/view/MotionEvent#getDeviceId() ) But maybe the simulator reports a virtual device. And maybe you can dump the "event.getSource()" too. (If needed, other places: src/video/android/SDL_androidtouch.c: Android_OnTouchAndroid_OnTouch() src/video/android/SDL_androidmouse.c: Android_OnMouse() ) Maybe there are stuff in the bug report: "Android, some issue with InputDevice checks" https://bugzilla.libsdl.org/show_bug.cgi?id=3958 I saw various strange checks. If Android just send -1 as a valid id, the easiest patch for SDL2, would be to add: "if (touchDevId < 0) touchDevId -= 1;" So that -1 is restrict to the synthetic events. https://hg.libsdl.org/SDL/file/1b1fae168557/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java#l1952 Also, maybe please dump stuffs from "initTouch()" https://hg.libsdl.org/SDL/file/1b1fae168557/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java#l1220 I tried with Android 11 emulator rev8, and I also got -1 id when using adb shell. to send mouse and touch events. When using the real mouse or real touch screen, it worked though. Here's a fix, can you double check: https://hg.libsdl.org/SDL/rev/e1c4081a20db I think just make sure that touchDevId is not equal to SDL_MOUSE_TOUCHID should be enough, so your fix should work. I will test today. Though in theory it's possible on other platforms too, so maybe better use additional parameter, something like this? int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window, SDL_bool down, float x, float y, float pressure, bool simulated = false); And are you able to test real gamepad device? It seems that it returns -1 too... - We don't want to drop the -1 id coming from Android, it's valid even if it's a virtual device. we re-affect it to -2, and other n negative to n - 1. We keep -1 for internal sdl synthetic id. We could change the function, as well, not sure why we didn't do that. I have no real android 11 so I used the emulator. Also I can't connect a gamepad and only use the shell commands. id -1 seems to be the joystick named Virtual This probably need to be changed to accept -1 : https://hg.libsdl.org/SDL/file/6b1b46ba0a2d/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java#l95 I see the joystick appearing, but I could get it working neither with android 11 nor old android. The check here might be wrong https://hg.libsdl.org/SDL/file/6b1b46ba0a2d/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java#l95 could be: int source = event.getSource(); if (source == InputDevice.SOURCE_JOYSTICK || source == InputDevice.SOURCE_GAMEPAD || source == InputDevice.SOURCE_DPAD) { Just after, all MotionEvent.ACTION_* are not handle. so, we might want to return "true" for ACTION_MOVE and false otherwise... and/or move the code onNativePad{Up,Down} from SDLActivity. Not really sure ... If you get Virtual -1, then it's the same what gets that guy on his Pixel 4 XL Phone with Android 11 and Logitech USB controller (see the screenshot). And he already tested my quick fix with changing SDL_MOUSE_TOUCHID to different value and it fixed these mouse events for him. I can ask him to test your patch if you need to try it on real device. I also tested your patch on android emulator and it works for me too. Created attachment 4474 [details]
screenshot gamepad
Please don't use your patch (eg. As a quick fix we changed SDL_MOUSE_TOUCHID to different value, so that it doesn't conflict with the id=-1. ) Ask the user to test: with this first patch in https://hg.libsdl.org/SDL/rev/e1c4081a20db Also, in addition, with this second patch (to be made) to accept -1: https://hg.libsdl.org/SDL/file/6b1b46ba0a2d/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java#l95 replace: if ((device == null) || (deviceId < 0)) { by if (device == null) { Please tell if all is ok with those two patches, thanks NB: by default, even on non Android 10, and without gamepad connected,
my phone report a device id with -1,
Virtual id=-1
device id == 769 (512 + 256 + 1)
which is CLASS={ BUTTON }
source(s): DPAD and KEYBOARD
So maybe your issue with gamepad, is totally different: HID not compiled ? gamecontrollerdb.h entry missing ?
I asked that guy to test your patches, will tell you when I will get some information. The "if (device == null)" will not work for multiple gamepads if all gamepads will have device id -1 (would be useful eg. on Android TV). But not sure how to solve it... if device id = -1 then generate id based on device name? And I wonder if it's maybe a bug in android, because it's a bit strange behavior... I had a quick look and there is one related commit https://android.googlesource.com/platform/frameworks/native/+/0d8ed6e8ade20652cea20f579f40b1d698ce8fc0 But it's for injected events, so I'm not sure if/how it affects real touch/gamepad events. |