From 8ccbdc79231454f51a09f3a0505902f1e50a0218 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 24 Sep 2019 18:13:56 -0700 Subject: [PATCH] Fix Start button not working on some MFi controllers on iOS 13 --- Limelight/Input/ControllerSupport.m | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Limelight/Input/ControllerSupport.m b/Limelight/Input/ControllerSupport.m index f5bdece..79b0617 100644 --- a/Limelight/Input/ControllerSupport.m +++ b/Limelight/Input/ControllerSupport.m @@ -214,12 +214,21 @@ -(void) registerControllerCallbacks:(GCController*) controller { if (controller != NULL) { - // On iOS 13, we want to use the new buttonMenu property which lets users hold down Start. - // On prior versions, we must use the controllerPausedHandler. + // iOS 13 allows the Start button to behave like a normal button, however + // older MFi controllers can send an instant down+up event for the start button + // which means the button will not be down long enough to register on the PC. + // To work around this issue, use the old controllerPausedHandler if the controller + // doesn't have a Select button (which indicates it probably doesn't have a proper + // Start button either). + BOOL useLegacyPausedHandler = YES; if (@available(iOS 13.0, tvOS 13.0, *)) { - // Nothing - buttonMenu is already handled in valueChangedHandler + if (controller.extendedGamepad != nil && + controller.extendedGamepad.buttonOptions != nil) { + useLegacyPausedHandler = NO; + } } - else { + + if (useLegacyPausedHandler) { controller.controllerPausedHandler = ^(GCController *controller) { Controller* limeController = [self->_controllers objectForKey:[NSNumber numberWithInteger:controller.playerIndex]]; @@ -268,12 +277,13 @@ } if (@available(iOS 13.0, tvOS 13.0, *)) { - // Menu button is mandatory, so no need to check for nil - UPDATE_BUTTON_FLAG(limeController, PLAY_FLAG, gamepad.buttonMenu.pressed); - // Options button is optional (only present on Xbox One S and PS4 gamepads) if (gamepad.buttonOptions != nil) { UPDATE_BUTTON_FLAG(limeController, BACK_FLAG, gamepad.buttonOptions.pressed); + + // For older MFi gamepads, the menu button will already be handled by + // the controllerPausedHandler. + UPDATE_BUTTON_FLAG(limeController, PLAY_FLAG, gamepad.buttonMenu.pressed); } }