diff --git a/Limelight/Input/StreamView.h b/Limelight/Input/StreamView.h index 2b4e364d..a92659a2 100644 --- a/Limelight/Input/StreamView.h +++ b/Limelight/Input/StreamView.h @@ -18,6 +18,7 @@ @property (nonatomic, retain) IBOutlet UITextField* keyInputField; +- (void) setupStreamView; - (void) setupOnScreenControls:(ControllerSupport*)controllerSupport swipeDelegate:(id)swipeDelegate; - (void) setMouseDeltaFactors:(float)x y:(float)y; diff --git a/Limelight/Input/StreamView.m b/Limelight/Input/StreamView.m index 347f9c4a..a67c3aa6 100644 --- a/Limelight/Input/StreamView.m +++ b/Limelight/Input/StreamView.m @@ -26,6 +26,11 @@ float yDeltaFactor; float screenFactor; +#if TARGET_OS_TV + UIGestureRecognizer* remotePressRecognizer; + UIGestureRecognizer* remoteLongPressRecognizer; +#endif + NSDictionary *dictCodes; } @@ -36,6 +41,19 @@ screenFactor = [[UIScreen mainScreen] scale]; } +- (void) setupStreamView { +#if TARGET_OS_TV + remotePressRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(remoteButtonPressed:)]; + remotePressRecognizer.allowedPressTypes = @[@(UIPressTypeSelect)]; + + remoteLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(remoteButtonLongPressed:)]; + remoteLongPressRecognizer.allowedPressTypes = @[@(UIPressTypeSelect)]; + + [self addGestureRecognizer:remotePressRecognizer]; + [self addGestureRecognizer:remoteLongPressRecognizer]; +#endif +} + - (void) setupOnScreenControls:(ControllerSupport*)controllerSupport swipeDelegate:(id)swipeDelegate { onScreenControls = [[OnScreenControls alloc] initWithView:self controllerSup:controllerSupport swipeDelegate:swipeDelegate]; DataManager* dataMan = [[DataManager alloc] init]; @@ -199,6 +217,30 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { } +#if TARGET_OS_TV +- (void)remoteButtonPressed:(id)sender { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ + Log(LOG_D, @"Sending left mouse button press"); + + // Mark this as touchMoved to avoid a duplicate press on touch up + self->touchMoved = true; + + LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_LEFT); + + // Wait 100 ms to simulate a real button press + usleep(100 * 1000); + + LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT); + }); +} +- (void)remoteButtonLongPressed:(id)sender { + Log(LOG_D, @"Holding left mouse button"); + + isDragging = true; + LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_LEFT); +} +#endif + - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { // Disable all gesture recognizers to prevent them from eating our touches. // This can happen on iOS 13 where the 3 finger tap gesture is taken over for diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index 635b0ee6..31a72dbb 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -50,6 +50,8 @@ [self.navigationController setNavigationBarHidden:YES animated:YES]; + [(StreamView*)self.view setupStreamView]; + [self.stageLabel setText:[NSString stringWithFormat:@"Starting %@...", self.streamConfig.appName]]; [self.stageLabel sizeToFit]; self.stageLabel.textAlignment = NSTextAlignmentCenter;