From 2e38c9495056e3e634bd3fed8e59a4f3aec4c218 Mon Sep 17 00:00:00 2001 From: Sylvain Becker Date: Mon, 5 Oct 2020 09:56:03 +0200 Subject: [PATCH] Fix bug 5303 - Touch/Mouse events simulation doesn't work on Android 11 --- .../src/main/java/org/libsdl/app/SDLActivity.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index 05b83db3d..32d944671 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -1923,7 +1923,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, @Override public boolean onTouch(View v, MotionEvent event) { /* Ref: http://developer.android.com/training/gestures/multi.html */ - final int touchDevId = event.getDeviceId(); + int touchDevId = event.getDeviceId(); final int pointerCount = event.getPointerCount(); int action = event.getActionMasked(); int pointerFingerId; @@ -1931,6 +1931,16 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, int i = -1; float x,y,p; + /** + * Prevent id to be -1, since it's used in SDL internal for synthetic events + * Appears when using Android emulator, eg: + * adb shell input mouse tap 100 100 + * adb shell input touchscreen tap 100 100 + */ + if (touchDevId < 0) { + touchDevId -= 1; + } + // 12290 = Samsung DeX mode desktop mouse // 12290 = 0x3002 = 0x2002 | 0x1002 = SOURCE_MOUSE | SOURCE_TOUCHSCREEN // 0x2 = SOURCE_CLASS_POINTER