Implement Start+Select+L1+R1 shortcut to quit

Fixes #548
This commit is contained in:
Cameron Gutman
2023-03-05 19:10:28 -06:00
parent 7ddf4e12ed
commit c57e89a0bd
4 changed files with 34 additions and 12 deletions
+3 -2
View File
@@ -11,16 +11,17 @@
@class OnScreenControls; @class OnScreenControls;
@protocol InputPresenceDelegate <NSObject> @protocol ControllerSupportDelegate <NSObject>
- (void) gamepadPresenceChanged; - (void) gamepadPresenceChanged;
- (void) mousePresenceChanged; - (void) mousePresenceChanged;
- (void) streamExitRequested;
@end @end
@interface ControllerSupport : NSObject @interface ControllerSupport : NSObject
-(id) initWithConfig:(StreamConfiguration*)streamConfig presenceDelegate:(id<InputPresenceDelegate>)delegate; -(id) initWithConfig:(StreamConfiguration*)streamConfig delegate:(id<ControllerSupportDelegate>)delegate;
-(void) initAutoOnScreenControlMode:(OnScreenControls*)osc; -(void) initAutoOnScreenControlMode:(OnScreenControls*)osc;
-(void) cleanup; -(void) cleanup;
+22 -7
View File
@@ -29,7 +29,7 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
NSLock *_controllerStreamLock; NSLock *_controllerStreamLock;
NSMutableDictionary *_controllers; NSMutableDictionary *_controllers;
id<InputPresenceDelegate> _presenceDelegate; id<ControllerSupportDelegate> _delegate;
float accumulatedDeltaX; float accumulatedDeltaX;
float accumulatedDeltaY; float accumulatedDeltaY;
@@ -200,13 +200,28 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
-(void) updateFinished:(Controller*)controller -(void) updateFinished:(Controller*)controller
{ {
BOOL exitRequested = NO;
[_controllerStreamLock lock]; [_controllerStreamLock lock];
@synchronized(controller) { @synchronized(controller) {
// Handle Start+Select+L1+R1 gamepad quit combo
if (controller.lastButtonFlags == (PLAY_FLAG | BACK_FLAG | LB_FLAG | RB_FLAG)) {
controller.lastButtonFlags = 0;
exitRequested = YES;
}
// Player 1 is always present for OSC // Player 1 is always present for OSC
LiSendMultiControllerEvent(_multiController ? controller.playerIndex : 0, LiSendMultiControllerEvent(_multiController ? controller.playerIndex : 0,
(_multiController ? _controllerNumbers : 1) | (_oscEnabled ? 1 : 0), controller.lastButtonFlags, controller.lastLeftTrigger, controller.lastRightTrigger, controller.lastLeftStickX, controller.lastLeftStickY, controller.lastRightStickX, controller.lastRightStickY); (_multiController ? _controllerNumbers : 1) | (_oscEnabled ? 1 : 0), controller.lastButtonFlags, controller.lastLeftTrigger, controller.lastRightTrigger, controller.lastLeftStickX, controller.lastLeftStickY, controller.lastRightStickX, controller.lastRightStickY);
} }
[_controllerStreamLock unlock]; [_controllerStreamLock unlock];
if (exitRequested) {
// Invoke the delegate callback on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
[self->_delegate streamExitRequested];
});
}
} }
+(BOOL) hasKeyboardOrMouse { +(BOOL) hasKeyboardOrMouse {
@@ -645,7 +660,7 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
return _controllers.count; return _controllers.count;
} }
-(id) initWithConfig:(StreamConfiguration*)streamConfig presenceDelegate:(id<InputPresenceDelegate>)delegate -(id) initWithConfig:(StreamConfiguration*)streamConfig delegate:(id<ControllerSupportDelegate>)delegate
{ {
self = [super init]; self = [super init];
@@ -654,7 +669,7 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
_controllerNumbers = 0; _controllerNumbers = 0;
_multiController = streamConfig.multiController; _multiController = streamConfig.multiController;
_swapABXYButtons = streamConfig.swapABXYButtons; _swapABXYButtons = streamConfig.swapABXYButtons;
_presenceDelegate = delegate; _delegate = delegate;
_player0osc = [[Controller alloc] init]; _player0osc = [[Controller alloc] init];
_player0osc.playerIndex = 0; _player0osc.playerIndex = 0;
@@ -697,7 +712,7 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
[self updateAutoOnScreenControlMode]; [self updateAutoOnScreenControlMode];
// Notify the delegate // Notify the delegate
[self->_presenceDelegate gamepadPresenceChanged]; [self->_delegate gamepadPresenceChanged];
}]; }];
_controllerDisconnectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidDisconnectNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { _controllerDisconnectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidDisconnectNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
Log(LOG_I, @"Controller disconnected!"); Log(LOG_I, @"Controller disconnected!");
@@ -729,7 +744,7 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
[self updateAutoOnScreenControlMode]; [self updateAutoOnScreenControlMode];
// Notify the delegate // Notify the delegate
[self->_presenceDelegate gamepadPresenceChanged]; [self->_delegate gamepadPresenceChanged];
}]; }];
if (@available(iOS 14.0, tvOS 14.0, *)) { if (@available(iOS 14.0, tvOS 14.0, *)) {
@@ -745,7 +760,7 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
[self updateAutoOnScreenControlMode]; [self updateAutoOnScreenControlMode];
// Notify the delegate // Notify the delegate
[self->_presenceDelegate mousePresenceChanged]; [self->_delegate mousePresenceChanged];
}]; }];
_mouseDisconnectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:GCMouseDidDisconnectNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { _mouseDisconnectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:GCMouseDidDisconnectNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
Log(LOG_I, @"Mouse disconnected!"); Log(LOG_I, @"Mouse disconnected!");
@@ -759,7 +774,7 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
[self updateAutoOnScreenControlMode]; [self updateAutoOnScreenControlMode];
// Notify the delegate // Notify the delegate
[self->_presenceDelegate mousePresenceChanged]; [self->_delegate mousePresenceChanged];
}]; }];
_keyboardConnectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:GCKeyboardDidConnectNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { _keyboardConnectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:GCKeyboardDidConnectNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
Log(LOG_I, @"Keyboard connected!"); Log(LOG_I, @"Keyboard connected!");
@@ -15,9 +15,9 @@
#if TARGET_OS_TV #if TARGET_OS_TV
@import GameController; @import GameController;
@interface StreamFrameViewController : GCEventViewController <ConnectionCallbacks, InputPresenceDelegate, UserInteractionDelegate, UIScrollViewDelegate> @interface StreamFrameViewController : GCEventViewController <ConnectionCallbacks, ControllerSupportDelegate, UserInteractionDelegate, UIScrollViewDelegate>
#else #else
@interface StreamFrameViewController : UIViewController <ConnectionCallbacks, InputPresenceDelegate, UserInteractionDelegate, UIScrollViewDelegate> @interface StreamFrameViewController : UIViewController <ConnectionCallbacks, ControllerSupportDelegate, UserInteractionDelegate, UIScrollViewDelegate>
#endif #endif
@property (nonatomic) StreamConfiguration* streamConfig; @property (nonatomic) StreamConfiguration* streamConfig;
@@ -104,7 +104,7 @@
[_spinner startAnimating]; [_spinner startAnimating];
_spinner.center = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height / 2 - _stageLabel.frame.size.height - _spinner.frame.size.height); _spinner.center = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height / 2 - _stageLabel.frame.size.height - _spinner.frame.size.height);
_controllerSupport = [[ControllerSupport alloc] initWithConfig:self.streamConfig presenceDelegate:self]; _controllerSupport = [[ControllerSupport alloc] initWithConfig:self.streamConfig delegate:self];
_inactivityTimer = nil; _inactivityTimer = nil;
_streamView = [[StreamView alloc] initWithFrame:self.view.frame]; _streamView = [[StreamView alloc] initWithFrame:self.view.frame];
@@ -615,6 +615,12 @@
#endif #endif
} }
- (void) streamExitRequested {
Log(LOG_I, @"Gamepad combo requested stream exit");
[self returnToMainFrame];
}
- (void)userInteractionBegan { - (void)userInteractionBegan {
// Disable hiding home bar when user is interacting. // Disable hiding home bar when user is interacting.
// iOS will force it to be shown anyway, but it will // iOS will force it to be shown anyway, but it will