From a0f13881bf053335bba498a6b4e0e2a348621a7c Mon Sep 17 00:00:00 2001 From: xzzpig Date: Sun, 1 Dec 2024 01:30:17 +0800 Subject: [PATCH] Add key combo support --- Limelight/Input/KeyboardSupport.m | 3 ++ Limelight/Input/StreamView.h | 4 ++ Limelight/Input/StreamView.m | 26 +++++++++++++ .../StreamFrameViewController.m | 38 +++++++++++++++++++ 4 files changed, 71 insertions(+) diff --git a/Limelight/Input/KeyboardSupport.m b/Limelight/Input/KeyboardSupport.m index 8cbf7a33..23e987d9 100644 --- a/Limelight/Input/KeyboardSupport.m +++ b/Limelight/Input/KeyboardSupport.m @@ -248,6 +248,9 @@ case UIKeyboardHIDUsageKeyboardRightAlt: keyCode = 0xA5; break; + case UIKeyboardHIDUsageKeyboardErrorUndefined: + NSLog(@"Undefined key pressed"); + return false; case 669: // This value corresponds to the "Globe" or "Language" key on most Apple branded iPad keyboards. keyCode = 0x1B; // This value corresponds to "Escape", which is missing from most Apple branded iPad keyboards. break; diff --git a/Limelight/Input/StreamView.h b/Limelight/Input/StreamView.h index 7790a8e0..5006026b 100644 --- a/Limelight/Input/StreamView.h +++ b/Limelight/Input/StreamView.h @@ -15,6 +15,10 @@ - (void) userInteractionBegan; - (void) userInteractionEnded; +- (void) streamExitRequested; +- (void) toggleStatsOverlay; +- (void) toggleMouseCapture; +- (void) toggleMouseVisible; @end diff --git a/Limelight/Input/StreamView.m b/Limelight/Input/StreamView.m index ed69488b..4eb92597 100644 --- a/Limelight/Input/StreamView.m +++ b/Limelight/Input/StreamView.m @@ -64,12 +64,15 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; UIHoverGestureRecognizer *stylusHoverRecognizer; #endif CGFloat HeightViewLiftedTo; + + UIKeyModifierFlags comboKeyModifierFlags; } - (void) setupStreamView:(ControllerSupport*)controllerSupport interactionDelegate:(id)interactionDelegate config:(StreamConfiguration*)streamConfig streamFrameTopLayerView:(UIView* )topLayerView{ + self->comboKeyModifierFlags = (UIKeyModifierControl|UIKeyModifierAlternate|UIKeyModifierShift); self->streamFrameTopLayerView = topLayerView; self.streamFrameTopLayerView = topLayerView; // this will be used as a read-only pointer for other class @@ -755,11 +758,34 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; else if(![onScreenControls handleTouchMovedEvent:touches]) [touchHandler touchesMoved:touches withEvent:event]; } +- (void) handleKeyCombos:(UIPress*) press{ + if(press.key.modifierFlags != comboKeyModifierFlags){ + return; + } + switch (press.key.keyCode) { + case UIKeyboardHIDUsageKeyboardQ: + [interactionDelegate streamExitRequested]; + break; + case UIKeyboardHIDUsageKeyboardS: + [interactionDelegate toggleStatsOverlay]; + break; + case UIKeyboardHIDUsageKeyboardM: + [interactionDelegate toggleMouseCapture]; + break; + case UIKeyboardHIDUsageKeyboardC: + [interactionDelegate toggleMouseVisible]; + break; + default: + break; + } +} + - (void)pressesBegan:(NSSet *)presses withEvent:(UIPressesEvent *)event { BOOL handled = NO; if (@available(iOS 13.4, tvOS 13.4, *)) { for (UIPress* press in presses) { + [self handleKeyCombos:press]; // For now, we'll treated it as handled if we handle at least one of the // UIPress events inside the set. if ([KeyboardSupport sendKeyEventForPress:press down:YES]) { diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index 2ec28416..79487db4 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -936,6 +936,44 @@ #endif } +- (void)toggleStatsOverlay{ + DataManager* dataMan = [[DataManager alloc] init]; + Settings *currentSettings = [dataMan retrieveSettings]; + + currentSettings.statsOverlay = !currentSettings.statsOverlay; + + [dataMan saveData]; + [self reConfigStreamViewRealtime]; +} + +- (void)toggleMouseCapture{ + DataManager* dataMan = [[DataManager alloc] init]; + Settings *currentSettings = [dataMan retrieveSettings]; + + if(currentSettings.mouseMode.intValue == 0){ + currentSettings.mouseMode = @1; + }else{ + currentSettings.mouseMode = @0; + } + + [dataMan saveData]; + [self reConfigStreamViewRealtime]; +} + +- (void)toggleMouseVisible{ + DataManager* dataMan = [[DataManager alloc] init]; + Settings *currentSettings = [dataMan retrieveSettings]; + + if(currentSettings.mouseMode.intValue == 2){ + currentSettings.mouseMode = @1; + }else{ + currentSettings.mouseMode = @2; + } + + [dataMan saveData]; + [self reConfigStreamViewRealtime]; +} + #if !TARGET_OS_TV // Require a confirmation when streaming to activate a system gesture - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures {