Browse Source

Android: TouchDevice -1 is reserved for SDL synthetic devce (See #5322)

Sylvain 3 years ago
parent
commit
68dd84f1de
1 changed files with 11 additions and 1 deletions
  1. 11 1
      android-project/app/src/main/java/org/libsdl/app/SDLActivity.java

+ 11 - 1
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java

@@ -1205,7 +1205,17 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
         for (int id : ids) {
             InputDevice device = InputDevice.getDevice(id);
             if (device != null && (device.getSources() & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) {
-                nativeAddTouch(device.getId(), device.getName());
+                int touchDevId = device.getId();
+                /*
+                 * 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;
+                }
+                nativeAddTouch(touchDevId, device.getName());
             }
         }
     }