mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-04-18 14:29:59 +00:00
Implement controller touchpad support
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user