mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +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
@@ -405,8 +405,14 @@ public final class PadBridge {
|
||||
case KeyEvent.KEYCODE_BUTTON_C:
|
||||
if (isPrimary(event)) DeckControls.INSTANCE.setGrip(isNovaController(event.getDevice()) ? DeckControls.L4 : DeckControls.R4, pressed);
|
||||
break;
|
||||
case KeyEvent.KEYCODE_BUTTON_L2: pad.leftTrigger = pressed ? 1f : 0f; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_R2: pad.rightTrigger = pressed ? 1f : 0f; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_L2:
|
||||
pad.leftTrigger = keyTrigger(pad.leftTrigger, pressed, event.getRepeatCount(),
|
||||
analogTrigger(event.getDevice(), MotionEvent.AXIS_LTRIGGER, MotionEvent.AXIS_BRAKE));
|
||||
break;
|
||||
case KeyEvent.KEYCODE_BUTTON_R2:
|
||||
pad.rightTrigger = keyTrigger(pad.rightTrigger, pressed, event.getRepeatCount(),
|
||||
analogTrigger(event.getDevice(), MotionEvent.AXIS_RTRIGGER, MotionEvent.AXIS_GAS));
|
||||
break;
|
||||
case KeyEvent.KEYCODE_DPAD_UP: pad.up = pressed; break;
|
||||
case KeyEvent.KEYCODE_DPAD_RIGHT: pad.right = pressed; break;
|
||||
case KeyEvent.KEYCODE_DPAD_DOWN: pad.down = pressed; break;
|
||||
@@ -547,6 +553,16 @@ public final class PadBridge {
|
||||
return true;
|
||||
}
|
||||
|
||||
static float keyTrigger(float current, boolean pressed, int repeatCount, boolean analog) {
|
||||
if (analog || repeatCount > 0) return current;
|
||||
return pressed ? 1f : 0f;
|
||||
}
|
||||
|
||||
static boolean analogTrigger(InputDevice device, int... axes) {
|
||||
return wiredXboxLayout(device, InputDevice.SOURCE_JOYSTICK)
|
||||
|| hasAxis(device, InputDevice.SOURCE_JOYSTICK, axes);
|
||||
}
|
||||
|
||||
static boolean hasAxis(InputDevice device, int source, int... axes) {
|
||||
if (device == null) return false;
|
||||
for (int axis : axes) if (device.getMotionRange(axis, source) != null) return true;
|
||||
@@ -1126,14 +1142,17 @@ public final class PadBridge {
|
||||
}
|
||||
|
||||
public static boolean wiredXboxLayout(MotionEvent event) {
|
||||
InputDevice device = event.getDevice();
|
||||
return wiredXboxLayout(event.getDevice(), event.getSource());
|
||||
}
|
||||
|
||||
static boolean wiredXboxLayout(InputDevice device, int source) {
|
||||
return device != null
|
||||
&& ((device.getVendorId() == 0x20d6 && device.getProductId() == 0x2063)
|
||||
|| (device.getVendorId() == 0x0e6f && device.getProductId() == 0x02f0))
|
||||
&& device.getMotionRange(MotionEvent.AXIS_RX, event.getSource()) != null
|
||||
&& device.getMotionRange(MotionEvent.AXIS_RY, event.getSource()) != null
|
||||
&& device.getMotionRange(MotionEvent.AXIS_Z, event.getSource()) != null
|
||||
&& device.getMotionRange(MotionEvent.AXIS_RZ, event.getSource()) != null;
|
||||
&& device.getMotionRange(MotionEvent.AXIS_RX, source) != null
|
||||
&& device.getMotionRange(MotionEvent.AXIS_RY, source) != null
|
||||
&& device.getMotionRange(MotionEvent.AXIS_Z, source) != null
|
||||
&& device.getMotionRange(MotionEvent.AXIS_RZ, source) != null;
|
||||
}
|
||||
|
||||
public static float leftTrigger(MotionEvent event, boolean wired) {
|
||||
|
||||
Reference in new issue
Block a user