From d48690b32071316d944b7653e0ad94b608a7a19f Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 29 Jun 2023 00:17:43 -0500 Subject: [PATCH] Implement controller touchpad support --- Limelight/Input/Controller.h | 5 +++ Limelight/Input/ControllerSupport.m | 48 +++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/Limelight/Input/Controller.h b/Limelight/Input/Controller.h index c16bcb7..b7d664c 100644 --- a/Limelight/Input/Controller.h +++ b/Limelight/Input/Controller.h @@ -25,6 +25,11 @@ @property (nonatomic) short lastRightStickX; @property (nonatomic) short lastRightStickY; +@property (nonatomic) float lastPrimaryTouchX; +@property (nonatomic) float lastPrimaryTouchY; +@property (nonatomic) float lastSecondaryTouchX; +@property (nonatomic) float lastSecondaryTouchY; + @property (nonatomic) HapticContext* _Nullable lowFreqMotor; @property (nonatomic) HapticContext* _Nullable highFreqMotor; @property (nonatomic) HapticContext* _Nullable leftTriggerMotor; diff --git a/Limelight/Input/ControllerSupport.m b/Limelight/Input/ControllerSupport.m index 31225ea..db1c46b 100644 --- a/Limelight/Input/ControllerSupport.m +++ b/Limelight/Input/ControllerSupport.m @@ -422,6 +422,46 @@ static const double MOUSE_SPEED_DIVISOR = 1.25; } } +-(void) handleControllerTouchpad:(Controller*)controller primaryTouch:(GCControllerDirectionPad*)primaryTouch secondaryTouch:(GCControllerDirectionPad*)secondaryTouch +{ + // If we went from a touch to no touch, generate a touch up event + if ((controller.lastPrimaryTouchX || controller.lastPrimaryTouchY) && (!primaryTouch.xAxis.value && !primaryTouch.yAxis.value)) { + LiSendTouchEvent(LI_TOUCH_EVENT_UP, 0, primaryTouch.xAxis.value, primaryTouch.yAxis.value, 1.0f); + } + else if (primaryTouch.xAxis.value || primaryTouch.yAxis.value) { + // If we went from no touch to a touch, generate a touch down event + if (!controller.lastPrimaryTouchX && !controller.lastPrimaryTouchY) { + LiSendTouchEvent(LI_TOUCH_EVENT_DOWN, 0, primaryTouch.xAxis.value, primaryTouch.yAxis.value, 1.0f); + } + else if (controller.lastPrimaryTouchX != primaryTouch.xAxis.value || + controller.lastPrimaryTouchY != primaryTouch.yAxis.value) { + // Otherwise it's just a move + LiSendTouchEvent(LI_TOUCH_EVENT_MOVE, 0, primaryTouch.xAxis.value, primaryTouch.yAxis.value, 1.0f); + } + } + controller.lastPrimaryTouchX = primaryTouch.xAxis.value; + controller.lastPrimaryTouchY = primaryTouch.yAxis.value; + + + // If we went from a touch to no touch, generate a touch up event + if ((controller.lastSecondaryTouchX || controller.lastSecondaryTouchY) && (!secondaryTouch.xAxis.value && !secondaryTouch.yAxis.value)) { + LiSendTouchEvent(LI_TOUCH_EVENT_UP, 1, secondaryTouch.xAxis.value, secondaryTouch.yAxis.value, 1.0f); + } + else if (secondaryTouch.xAxis.value || secondaryTouch.yAxis.value) { + // If we went from no touch to a touch, generate a touch down event + if (!controller.lastSecondaryTouchX && !controller.lastSecondaryTouchY) { + LiSendTouchEvent(LI_TOUCH_EVENT_DOWN, 1, secondaryTouch.xAxis.value, secondaryTouch.yAxis.value, 1.0f); + } + else if (controller.lastSecondaryTouchX != secondaryTouch.xAxis.value || + controller.lastSecondaryTouchY != secondaryTouch.yAxis.value) { + // Otherwise it's just a move + LiSendTouchEvent(LI_TOUCH_EVENT_MOVE, 1, secondaryTouch.xAxis.value, secondaryTouch.yAxis.value, 1.0f); + } + } + controller.lastSecondaryTouchX = secondaryTouch.xAxis.value; + controller.lastSecondaryTouchY = secondaryTouch.yAxis.value; +} + -(void) registerControllerCallbacks:(GCController*) controller { if (controller != NULL) { @@ -549,6 +589,10 @@ static const double MOUSE_SPEED_DIVISOR = 1.25; if (dualShockGamepad.touchpadButton) { UPDATE_BUTTON_FLAG(limeController, TOUCHPAD_FLAG, dualShockGamepad.touchpadButton.pressed); } + + [self handleControllerTouchpad:limeController + primaryTouch:dualShockGamepad.touchpadPrimary + secondaryTouch:dualShockGamepad.touchpadSecondary]; } if (@available(iOS 14.5, tvOS 14.5, *)) { @@ -558,6 +602,10 @@ static const double MOUSE_SPEED_DIVISOR = 1.25; if (dualSenseGamepad.touchpadButton) { UPDATE_BUTTON_FLAG(limeController, TOUCHPAD_FLAG, dualSenseGamepad.touchpadButton.pressed); } + + [self handleControllerTouchpad:limeController + primaryTouch:dualSenseGamepad.touchpadPrimary + secondaryTouch:dualSenseGamepad.touchpadSecondary]; } } }