From 88c18ad397a7dadc3ba7142e57ec976f6ab8f6d4 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 18 Sep 2020 18:48:35 -0500 Subject: [PATCH] Don't use pointer lock if the mouse isn't compatible with GCMouse --- Limelight/Input/ControllerSupport.h | 5 +++-- Limelight/Input/ControllerSupport.m | 10 ++++++++-- .../ViewControllers/StreamFrameViewController.h | 4 ++-- .../ViewControllers/StreamFrameViewController.m | 13 ++++++++++++- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Limelight/Input/ControllerSupport.h b/Limelight/Input/ControllerSupport.h index f416c34..0b7dab4 100644 --- a/Limelight/Input/ControllerSupport.h +++ b/Limelight/Input/ControllerSupport.h @@ -11,15 +11,16 @@ @class OnScreenControls; -@protocol GamepadPresenceDelegate +@protocol InputPresenceDelegate - (void) gamepadPresenceChanged; +- (void) mousePresenceChanged; @end @interface ControllerSupport : NSObject --(id) initWithConfig:(StreamConfiguration*)streamConfig presenceDelegate:(id)delegate; +-(id) initWithConfig:(StreamConfiguration*)streamConfig presenceDelegate:(id)delegate; -(void) initAutoOnScreenControlMode:(OnScreenControls*)osc; -(void) cleanup; diff --git a/Limelight/Input/ControllerSupport.m b/Limelight/Input/ControllerSupport.m index f47e460..c7f1870 100644 --- a/Limelight/Input/ControllerSupport.m +++ b/Limelight/Input/ControllerSupport.m @@ -29,7 +29,7 @@ static const double MOUSE_SPEED_DIVISOR = 2.5; NSLock *_controllerStreamLock; NSMutableDictionary *_controllers; - id _presenceDelegate; + id _presenceDelegate; float accumulatedDeltaX; float accumulatedDeltaY; @@ -560,7 +560,7 @@ static const double MOUSE_SPEED_DIVISOR = 2.5; return _controllers.count; } --(id) initWithConfig:(StreamConfiguration*)streamConfig presenceDelegate:(id)delegate +-(id) initWithConfig:(StreamConfiguration*)streamConfig presenceDelegate:(id)delegate { self = [super init]; @@ -657,6 +657,9 @@ static const double MOUSE_SPEED_DIVISOR = 2.5; // Re-evaluate the on-screen control mode [self updateAutoOnScreenControlMode]; + + // Notify the delegate + [self->_presenceDelegate mousePresenceChanged]; }]; _mouseDisconnectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:GCMouseDidDisconnectNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { Log(LOG_I, @"Mouse disconnected!"); @@ -668,6 +671,9 @@ static const double MOUSE_SPEED_DIVISOR = 2.5; // Re-evaluate the on-screen control mode [self updateAutoOnScreenControlMode]; + + // Notify the delegate + [self->_presenceDelegate mousePresenceChanged]; }]; _keyboardConnectObserver = [[NSNotificationCenter defaultCenter] addObserverForName:GCKeyboardDidConnectNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { Log(LOG_I, @"Keyboard connected!"); diff --git a/Limelight/ViewControllers/StreamFrameViewController.h b/Limelight/ViewControllers/StreamFrameViewController.h index b8418a8..01aa666 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.h +++ b/Limelight/ViewControllers/StreamFrameViewController.h @@ -15,9 +15,9 @@ #if TARGET_OS_TV @import GameController; -@interface StreamFrameViewController : GCEventViewController +@interface StreamFrameViewController : GCEventViewController #else -@interface StreamFrameViewController : UIViewController +@interface StreamFrameViewController : UIViewController #endif @property (strong, nonatomic) IBOutlet UILabel *stageLabel; @property (strong, nonatomic) IBOutlet UILabel *tipLabel; diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index a97990a..4800f8b 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -383,6 +383,14 @@ #endif } +- (void)mousePresenceChanged { +#if !TARGET_OS_TV + if (@available(iOS 14.0, *)) { + [self setNeedsUpdateOfPrefersPointerLocked]; + } +#endif +} + - (void)userInteractionBegan { // Disable hiding home bar when user is interacting. // iOS will force it to be shown anyway, but it will @@ -434,7 +442,10 @@ } - (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