Modern Apps git

← Modern-Apps.git

games/kart: fix isGamepad seating keyboards as gamepads

Commit
037bd8fdc1211d633b33e3ba1978dc666261a025
Author
Vayun Mathur <[email protected]>
When
2026-11-07 06:11 UTC (29 days ago)
Parents
92bd8e6
GamepadDirect.isGamepad masked device.sources with
(SOURCE_GAMEPAD or SOURCE_JOYSTICK) and accepted any nonzero result.
SOURCE_GAMEPAD carries the SOURCE_CLASS_BUTTON bit, which keyboards,
remotes and other button-class devices also report, so a plain
keyboard took a race seat - the opposite of the class contract that
only gamepads and joysticks seat. Require the full gamepad or
joystick mask instead.

Found by a Robolectric test that seats a SOURCE_KEYBOARD device and
asserts its keys fall through; it failed before this fix and passes
after.

(cherry picked from commit 37e6b4a890293fcf27501c074a08fdbb668d0c7b)

Diff

games/kart/src/main/java/com/vayunmathur/games/kart/platform/GamepadDirect.kt
diff --git a/games/kart/src/main/java/com/vayunmathur/games/kart/platform/GamepadDirect.kt b/games/kart/src/main/java/com/vayunmathur/games/kart/platform/GamepadDirect.ktindex 5dac97322f..cdb0a12b7a 100644--- a/games/kart/src/main/java/com/vayunmathur/games/kart/platform/GamepadDirect.kt+++ b/games/kart/src/main/java/com/vayunmathur/games/kart/platform/GamepadDirect.kt@@ -209,7 +209,8 @@ class GamepadDirect(          * their keys always fall through to the system.          */         fun isGamepad(device: InputDevice): Boolean =-            (device.sources and (InputDevice.SOURCE_GAMEPAD or InputDevice.SOURCE_JOYSTICK)) != 0+            (device.sources and InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD ||+                (device.sources and InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK          /** A hardware value inside the device's own noise floor is rest, not input. */         fun Float.zeroWithin(flat: Float): Float =