diff --git a/VoidLink/Input/ControllerSupport.m b/VoidLink/Input/ControllerSupport.m index 0f65679c..687cd342 100644 --- a/VoidLink/Input/ControllerSupport.m +++ b/VoidLink/Input/ControllerSupport.m @@ -73,7 +73,6 @@ static const double MOUSE_SPEED_DIVISOR = 1.25; OnScreenControls *_osc; VoidController *_oscController; - NSMutableSet* _activeGCControllers; TemporarySettings* tempSettings; OSCProfile* oscProfile; OSCProfilesManager* oscProfileMan; @@ -1218,7 +1217,6 @@ double rc_expo(double x, double expo) { CGFloat rightStickXRaw = gamepad.rightThumbstick.xAxis.value * self->stickMaxOffset; CGFloat rightStickYRaw = gamepad.rightThumbstick.yAxis.value * self->stickMaxOffset; - CGVector leftStickOffset = [ControllerUtil compensatedWithOffsetVector:CGVectorMake(leftStickXRaw, leftStickYRaw) minOffset:self->_leftStickMinOffset circulate:false]; @@ -1601,7 +1599,7 @@ double rc_expo(double x, double expo) { -(VoidController* )assignController:(GCController*)controller { NSLog(@"run assignController"); - bool newGCControllerArrival = ![_activeGCControllers containsObject:controller]; + bool newGCControllerArrival = ![ControllerUtil.activeGCControllers containsObject:controller]; if(!newGCControllerArrival){ VoidController* voidController = [_voidControllers objectForKey:@(controller.playerIndex)]; @@ -1623,7 +1621,7 @@ double rc_expo(double x, double expo) { VoidController* voidController = [[VoidController alloc] init]; - [_activeGCControllers addObject:controller]; + [ControllerUtil.activeGCControllers addObject:controller]; controller.playerIndex = i; voidController.playerIndex = i; [self updateVoidController:voidController withGCController:controller]; @@ -1701,9 +1699,9 @@ double rc_expo(double x, double expo) { - (void)assignControllers{ for (GCController* controller in [GCController controllers]) { NSLog(@"controller count: iterating"); - + if ([ControllerSupport isSupportedGamepad:controller]) { - NSLog(@"controller count: is supported,is contained by dict: %d", [_activeGCControllers containsObject:controller]); + NSLog(@"controller count: is supported,is contained by dict: %d", [ControllerUtil.activeGCControllers containsObject:controller]); NSLog(@"controller obj +1 in dic"); [self assignController:controller]; NSLog(@"controller obj num in dict: %lu", (unsigned long)_voidControllers.allValues.count); @@ -1820,7 +1818,7 @@ double rc_expo(double x, double expo) { _delegate = delegate; _controllerStreamLock = [[NSLock alloc] init]; _voidControllers = [[NSMutableDictionary alloc] init]; - _activeGCControllers = [[NSMutableSet alloc] init]; + [ControllerUtil.activeGCControllers removeAllObjects]; _controllerNumbers = 0; _captureMouse = (streamConfig.localMousePointerMode == 0); @@ -1873,8 +1871,8 @@ double rc_expo(double x, double expo) { [self unregisterControllerCallbacks:controller]; - if([self->_activeGCControllers containsObject:controller]){ - [self->_activeGCControllers removeObject:controller]; + if([ControllerUtil.activeGCControllers containsObject:controller]){ + [ControllerUtil.activeGCControllers removeObject:controller]; self->_controllerNumbers &= ~(1 << controller.playerIndex); } Log(LOG_I, @"Unassigning controller index: %ld", (long)controller.playerIndex); diff --git a/VoidLink/Input/ControllerUtil.swift b/VoidLink/Input/ControllerUtil.swift index 67d41aa7..e2ab5a8e 100644 --- a/VoidLink/Input/ControllerUtil.swift +++ b/VoidLink/Input/ControllerUtil.swift @@ -53,7 +53,9 @@ import GameController @objc class ControllerUtil: NSObject { static private let stickMaxOffset:CGFloat = 0x7FFE - + @objc static var navigationActionTriggered:Bool = false + @objc static private(set) var navigationActionTriggeredPrivate:Bool = false + @objc static func listen( controller: GCController, swapABXY: Bool, @@ -73,6 +75,22 @@ import GameController // 单一 gamepad.valueChangedHandler gamepad.valueChangedHandler = { gamepad, element in + navigationActionTriggeredPrivate = (gamepad.dpad.up.isPressed + || gamepad.dpad.down.isPressed + || gamepad.dpad.left.isPressed + || gamepad.dpad.right.isPressed + || gamepad.rightThumbstick.xAxis.value != 0 + || gamepad.rightThumbstick.yAxis.value != 0 + || gamepad.leftThumbstick.xAxis.value != 0 + || gamepad.leftThumbstick.yAxis.value != 0) + if navigationActionTriggeredPrivate { navigationActionTriggered = true} + else { + DispatchQueue.global().asyncAfter(deadline: .now() + 0.02) { + if !navigationActionTriggeredPrivate { + navigationActionTriggered = false + } + } + } handler(buttonDict, gamepad, element) } } @@ -156,6 +174,8 @@ import GameController return result } + @objc static var activeGCControllers:NSMutableSet = NSMutableSet() + @objc static func string(for button: ControllerButton) -> String { switch button { case .a: return "A" diff --git a/VoidLink/Input/KeyboardSupport.m b/VoidLink/Input/KeyboardSupport.m index 23e987d9..621d729a 100644 --- a/VoidLink/Input/KeyboardSupport.m +++ b/VoidLink/Input/KeyboardSupport.m @@ -8,6 +8,7 @@ #import "KeyboardSupport.h" #include +#include "VoidLink-Swift.h" @implementation KeyboardSupport @@ -17,7 +18,6 @@ } else { short keyCode; - switch (press.type) { case UIPressTypeUpArrow: keyCode = 0x26; @@ -36,9 +36,14 @@ return NO; } - LiSendKeyboardEvent(0x8000 | keyCode, - down ? KEY_ACTION_DOWN : KEY_ACTION_UP, - 0); + bool physicalGamepadConnected = ControllerUtil.activeGCControllers.count>0; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, physicalGamepadConnected ? 0.005*NSEC_PER_SEC : 0), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + if(!physicalGamepadConnected + || !ControllerUtil.navigationActionTriggered) + LiSendKeyboardEvent(0x8000 | keyCode, + down ? KEY_ACTION_DOWN : KEY_ACTION_UP, + 0); + }); return YES; }