From 597aaa1bab8a52d7db8b319437524b39fc200c1e Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 11 Sep 2019 18:44:37 -0700 Subject: [PATCH] Cleanup controller support code using the iOS 13 SDK directly --- Limelight/Input/ControllerSupport.m | 44 +++++++++-------------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/Limelight/Input/ControllerSupport.m b/Limelight/Input/ControllerSupport.m index f3203cc..b460a42 100644 --- a/Limelight/Input/ControllerSupport.m +++ b/Limelight/Input/ControllerSupport.m @@ -213,7 +213,10 @@ 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. - if (![controller.extendedGamepad respondsToSelector:@selector(buttonMenu)]) { + if (@available(iOS 13.0, tvOS 13.0, *)) { + // Nothing - buttonMenu is already handled in valueChangedHandler + } + else { controller.controllerPausedHandler = ^(GCController *controller) { Controller* limeController = [self->_controllers objectForKey:[NSNumber numberWithInteger:controller.playerIndex]]; @@ -261,22 +264,13 @@ } } - // Until the iOS 13 SDK is released, we must use performSelector: and respondsToSelector: - // to exercise the new buttonMenu and buttonOptions properties. if (@available(iOS 13.0, tvOS 13.0, *)) { - if ([gamepad respondsToSelector:@selector(buttonMenu)]) { - GCControllerButtonInput* menuButton = [gamepad performSelector:@selector(buttonMenu)]; - - // Menu button is mandatory, so no need to check for nil - UPDATE_BUTTON_FLAG(limeController, PLAY_FLAG, menuButton.pressed); - } - if ([gamepad respondsToSelector:@selector(buttonOptions)]) { - GCControllerButtonInput* optionsButton = [gamepad performSelector:@selector(buttonOptions)]; - - // Options button is optional (only present on Xbox One S and PS4 gamepads) - if (optionsButton != nil) { - UPDATE_BUTTON_FLAG(limeController, BACK_FLAG, optionsButton.pressed); - } + // 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); } } @@ -339,23 +333,13 @@ if (@available(iOS 12.1, tvOS 12.1, *)) { if (controller.extendedGamepad.leftThumbstickButton != nil && controller.extendedGamepad.rightThumbstickButton != nil) { - GCControllerButtonInput* optionsButton = nil; - + level = OnScreenControlsLevelAutoGCExtendedGamepadWithStickButtons; if (@available(iOS 13.0, tvOS 13.0, *)) { - // TODO: Update when iOS 13 SDK is officially released - if ([controller.extendedGamepad respondsToSelector:@selector(buttonOptions)]) { - optionsButton = [controller.extendedGamepad performSelector:@selector(buttonOptions)]; + if (controller.extendedGamepad.buttonOptions != nil) { + // Has L3/R3 and Select, so we can show nothing :) + level = OnScreenControlsLevelOff; } } - - if (optionsButton != nil) { - // Has L3/R3 and Select, so we can show nothing :) - level = OnScreenControlsLevelOff; - } - else { - // Has L3/R3 but no Select button - level = OnScreenControlsLevelAutoGCExtendedGamepadWithStickButtons; - } } } break;