Don't use pointer lock if the mouse isn't compatible with GCMouse

This commit is contained in:
Cameron Gutman
2020-09-18 18:48:35 -05:00
parent 5043fadace
commit 88c18ad397
4 changed files with 25 additions and 7 deletions
+3 -2
View File
@@ -11,15 +11,16 @@
@class OnScreenControls; @class OnScreenControls;
@protocol GamepadPresenceDelegate <NSObject> @protocol InputPresenceDelegate <NSObject>
- (void) gamepadPresenceChanged; - (void) gamepadPresenceChanged;
- (void) mousePresenceChanged;
@end @end
@interface ControllerSupport : NSObject @interface ControllerSupport : NSObject
-(id) initWithConfig:(StreamConfiguration*)streamConfig presenceDelegate:(id<GamepadPresenceDelegate>)delegate; -(id) initWithConfig:(StreamConfiguration*)streamConfig presenceDelegate:(id<InputPresenceDelegate>)delegate;
-(void) initAutoOnScreenControlMode:(OnScreenControls*)osc; -(void) initAutoOnScreenControlMode:(OnScreenControls*)osc;
-(void) cleanup; -(void) cleanup;
+8 -2
View File
@@ -29,7 +29,7 @@ static const double MOUSE_SPEED_DIVISOR = 2.5;
NSLock *_controllerStreamLock; NSLock *_controllerStreamLock;
NSMutableDictionary *_controllers; NSMutableDictionary *_controllers;
id<GamepadPresenceDelegate> _presenceDelegate; id<InputPresenceDelegate> _presenceDelegate;
float accumulatedDeltaX; float accumulatedDeltaX;
float accumulatedDeltaY; float accumulatedDeltaY;
@@ -560,7 +560,7 @@ static const double MOUSE_SPEED_DIVISOR = 2.5;
return _controllers.count; return _controllers.count;
} }
-(id) initWithConfig:(StreamConfiguration*)streamConfig presenceDelegate:(id<GamepadPresenceDelegate>)delegate -(id) initWithConfig:(StreamConfiguration*)streamConfig presenceDelegate:(id<InputPresenceDelegate>)delegate
{ {
self = [super init]; self = [super init];
@@ -657,6 +657,9 @@ static const double MOUSE_SPEED_DIVISOR = 2.5;
// Re-evaluate the on-screen control mode // Re-evaluate the on-screen control mode
[self updateAutoOnScreenControlMode]; [self updateAutoOnScreenControlMode];
// Notify the delegate
[self->_presenceDelegate 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!");
@@ -668,6 +671,9 @@ static const double MOUSE_SPEED_DIVISOR = 2.5;
// Re-evaluate the on-screen control mode // Re-evaluate the on-screen control mode
[self updateAutoOnScreenControlMode]; [self updateAutoOnScreenControlMode];
// Notify the delegate
[self->_presenceDelegate 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, EdgeDetectionDelegate, GamepadPresenceDelegate, UserInteractionDelegate> @interface StreamFrameViewController : GCEventViewController <ConnectionCallbacks, EdgeDetectionDelegate, InputPresenceDelegate, UserInteractionDelegate>
#else #else
@interface StreamFrameViewController : UIViewController <ConnectionCallbacks, EdgeDetectionDelegate, GamepadPresenceDelegate, UserInteractionDelegate> @interface StreamFrameViewController : UIViewController <ConnectionCallbacks, EdgeDetectionDelegate, InputPresenceDelegate, UserInteractionDelegate>
#endif #endif
@property (strong, nonatomic) IBOutlet UILabel *stageLabel; @property (strong, nonatomic) IBOutlet UILabel *stageLabel;
@property (strong, nonatomic) IBOutlet UILabel *tipLabel; @property (strong, nonatomic) IBOutlet UILabel *tipLabel;
@@ -383,6 +383,14 @@
#endif #endif
} }
- (void)mousePresenceChanged {
#if !TARGET_OS_TV
if (@available(iOS 14.0, *)) {
[self setNeedsUpdateOfPrefersPointerLocked];
}
#endif
}
- (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
@@ -434,7 +442,10 @@
} }
- (BOOL)prefersPointerLocked { - (BOOL)prefersPointerLocked {
return YES; // Pointer lock breaks the UIKit mouse APIs, which is a problem because
// GCMouse is horribly broken on iOS 14.0 for certain mice. Only lock
// the cursor if there is a GCMouse present.
return [GCMouse mice].count > 0;
} }
#endif #endif