mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
fix(input): L2/R2 keys stop overriding analog trigger axes (#2205)
fix(input): stop L2/R2 keys from overriding analog trigger axes Pads such as the GameSir X2 Pro send KEYCODE_BUTTON_L2/R2 alongside their analog trigger axes. Each key-down and every key repeat set the trigger to full, and the next motion event set it back to the axis value, so a held trigger jumped to full. Android repeats only the most recently pressed key, so with both triggers held one side kept being forced to full while the other tracked its axis. When a device reports an analog axis for a trigger side (LTRIGGER or BRAKE, RTRIGGER or GAS, or the wired Xbox Z/RZ layout), its key no longer drives that trigger. Key repeats never change a trigger value. Pads with digital-only triggers keep the key behaviour unchanged.
This commit is contained in:
1 parent
2476c824f6
commit
7f0427b830
2 files changed
+89
-9
No files matched your search
@@ -94,10 +94,71 @@ class PadPartialAxesTest {
|
||||
assertTrue(pad().down)
|
||||
}
|
||||
|
||||
@Test fun analogTriggerAxesWinOverTheirKeys() {
|
||||
val device = device(MotionEvent.AXIS_LTRIGGER, MotionEvent.AXIS_RTRIGGER)
|
||||
motion(device, MotionEvent.AXIS_LTRIGGER to 0.3f)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2)
|
||||
assertEquals(0.3f, pad().leftTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2, repeat = 1)
|
||||
assertEquals(0.3f, pad().leftTrigger)
|
||||
motion(device, MotionEvent.AXIS_LTRIGGER to 0.6f)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2, repeat = 2)
|
||||
assertEquals(0.6f, pad().leftTrigger)
|
||||
motion(device, MotionEvent.AXIS_LTRIGGER to 0f)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2, KeyEvent.ACTION_UP)
|
||||
assertEquals(0f, pad().leftTrigger)
|
||||
}
|
||||
|
||||
@Test fun bothAnalogTriggersHeldStayIndependent() {
|
||||
val device = device(MotionEvent.AXIS_BRAKE, MotionEvent.AXIS_GAS)
|
||||
motion(device, MotionEvent.AXIS_BRAKE to 0.4f)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2)
|
||||
motion(device, MotionEvent.AXIS_BRAKE to 0.4f, MotionEvent.AXIS_GAS to 0.7f)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2, repeat = 1)
|
||||
assertEquals(0.4f, pad().leftTrigger)
|
||||
assertEquals(0.7f, pad().rightTrigger)
|
||||
motion(device, MotionEvent.AXIS_BRAKE to 0.9f, MotionEvent.AXIS_GAS to 0.2f)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2, repeat = 2)
|
||||
assertEquals(0.9f, pad().leftTrigger)
|
||||
assertEquals(0.2f, pad().rightTrigger)
|
||||
}
|
||||
|
||||
@Test fun wiredXboxTriggerKeysDoNotOverrideTheirAxes() {
|
||||
val device = device(MotionEvent.AXIS_RX, MotionEvent.AXIS_RY, MotionEvent.AXIS_Z, MotionEvent.AXIS_RZ, wired = true)
|
||||
motion(device, MotionEvent.AXIS_Z to 0f, MotionEvent.AXIS_RZ to -1f)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2)
|
||||
assertEquals(0.5f, pad().leftTrigger)
|
||||
assertEquals(0f, pad().rightTrigger)
|
||||
}
|
||||
|
||||
@Test fun digitalTriggerKeysStillPressAndRelease() {
|
||||
val device = device()
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2, repeat = 1)
|
||||
assertEquals(1f, pad().leftTrigger)
|
||||
assertEquals(1f, pad().rightTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_L2, KeyEvent.ACTION_UP)
|
||||
assertEquals(0f, pad().leftTrigger)
|
||||
assertEquals(1f, pad().rightTrigger)
|
||||
key(device, KeyEvent.KEYCODE_BUTTON_R2, KeyEvent.ACTION_UP)
|
||||
assertEquals(0f, pad().rightTrigger)
|
||||
}
|
||||
|
||||
@Test fun keyTriggerDecision() {
|
||||
assertEquals(1f, PadBridge.keyTrigger(0f, true, 0, false))
|
||||
assertEquals(0f, PadBridge.keyTrigger(1f, false, 0, false))
|
||||
assertEquals(0.25f, PadBridge.keyTrigger(0.25f, true, 1, false))
|
||||
assertEquals(0.25f, PadBridge.keyTrigger(0.25f, true, 0, true))
|
||||
assertEquals(0.25f, PadBridge.keyTrigger(0.25f, false, 0, true))
|
||||
}
|
||||
|
||||
private fun pad(): PadState = requireNotNull(JoyConPadTest.RecordingWriter.pads[0])
|
||||
|
||||
private fun key(device: InputDevice, code: Int) {
|
||||
assertTrue(bridge.onKeyEvent(KeyEvent(0L, 0L, KeyEvent.ACTION_DOWN, code, 0, 0,
|
||||
private fun key(device: InputDevice, code: Int, action: Int = KeyEvent.ACTION_DOWN, repeat: Int = 0) {
|
||||
assertTrue(bridge.onKeyEvent(KeyEvent(0L, 0L, action, code, repeat, 0,
|
||||
device.id, 0, 0, InputDevice.SOURCE_GAMEPAD)))
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user