From d430d83ba8a5b2d4aa47fd6e7f2cf4781806a874 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 16 Oct 2023 23:56:56 -0500 Subject: [PATCH] Add clickpad button emulation combo (Select+L1) --- .../binding/input/ControllerHandler.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/src/main/java/com/limelight/binding/input/ControllerHandler.java b/app/src/main/java/com/limelight/binding/input/ControllerHandler.java index 57cb3509..4541b311 100644 --- a/app/src/main/java/com/limelight/binding/input/ControllerHandler.java +++ b/app/src/main/java/com/limelight/binding/input/ControllerHandler.java @@ -63,6 +63,7 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD private static final int EMULATING_SPECIAL = 0x1; private static final int EMULATING_SELECT = 0x2; + private static final int EMULATING_TOUCHPAD = 0x4; private static final short MAX_GAMEPADS = 16; // Limited by bits in activeGamepadMask @@ -2494,6 +2495,19 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD } } + // Check if we're emulating the touchpad button + if ((context.emulatingButtonFlags & ControllerHandler.EMULATING_TOUCHPAD) != 0) + { + // If either select or LB is up, touchpad comes up too + if ((context.inputMap & ControllerPacket.BACK_FLAG) == 0 || + (context.inputMap & ControllerPacket.LB_FLAG) == 0) + { + context.inputMap &= ~ControllerPacket.TOUCHPAD_FLAG; + + context.emulatingButtonFlags &= ~ControllerHandler.EMULATING_TOUCHPAD; + } + } + sendControllerInputPacket(context); if (context.pendingExit && context.inputMap == 0) { @@ -2685,6 +2699,18 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD context.emulatingButtonFlags |= ControllerHandler.EMULATING_SELECT; } } + else if (context.needsClickpadEmulation) { + // Select+LB acts like the clickpad when we're faking a PS4 controller for motion support + if (context.inputMap == (ControllerPacket.BACK_FLAG | ControllerPacket.LB_FLAG) || + (context.inputMap == ControllerPacket.BACK_FLAG && + event.getEventTime() - context.lastLbUpTime <= MAXIMUM_BUMPER_UP_DELAY_MS)) + { + context.inputMap &= ~(ControllerPacket.BACK_FLAG | ControllerPacket.LB_FLAG); + context.inputMap |= ControllerPacket.TOUCHPAD_FLAG; + + context.emulatingButtonFlags |= ControllerHandler.EMULATING_TOUCHPAD; + } + } // If there is a physical select button, we'll use Start+Select as the special button combo // otherwise we'll use Start+RB. @@ -2914,6 +2940,7 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD public boolean hasMode; public boolean hasPaddles; public boolean hasShare; + public boolean needsClickpadEmulation; // Used for OUYA bumper state tracking since they force all buttons // up when the OUYA button goes down. We watch the last time we get @@ -3072,6 +3099,9 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD // Override the detected controller type if we're emulating motion sensors on an Xbox controller Toast.makeText(activityContext, activityContext.getResources().getText(R.string.toast_controller_type_changed), Toast.LENGTH_LONG).show(); reportedType = MoonBridge.LI_CTYPE_UNKNOWN; + + // Remember that we should enable the clickpad emulation combo (Select+LB) for this device + needsClickpadEmulation = true; } else { // Report the true type to the host PC if we're not emulating motion sensors @@ -3128,6 +3158,9 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD this.sensorManager = deviceSensorManager; } + // Copy state initialized in reportControllerArrival() + this.needsClickpadEmulation = oldContext.needsClickpadEmulation; + // Re-enable sensors on the new context enableSensors();