From f85b736c97e37bb4ae67927e9d984d6e0e6f579d Mon Sep 17 00:00:00 2001 From: True Zhuanjia Date: Thu, 16 May 2024 17:44:18 +0800 Subject: [PATCH] improve keyboard toggle by adding keyboard notification. minor UI string change --- Limelight/Input/StreamView.m | 29 +++++++++++++++---- .../ViewControllers/SettingsViewController.m | 4 +-- .../StreamFrameViewController.m | 1 + iPad.storyboard | 10 +++---- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Limelight/Input/StreamView.m b/Limelight/Input/StreamView.m index c2cc2f73..2bb00293 100644 --- a/Limelight/Input/StreamView.m +++ b/Limelight/Input/StreamView.m @@ -75,6 +75,15 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; keyboardToggleRecognizer.tapDownTimeThreshold = 300.0; // tap down time threshold in milli seconds. keyboardToggleRecognizer.delaysTouchesBegan = NO; keyboardToggleRecognizer.delaysTouchesEnded = NO; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillShow) + name:UIKeyboardWillShowNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillHide) + name:UIKeyboardWillHideNotification + object:nil]; [self addGestureRecognizer:keyboardToggleRecognizer]; #if TARGET_OS_TV @@ -143,15 +152,25 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; [self becomeFirstResponder]; } +- (void)keyboardWillShow{ + isInputingText = true; + // NSLog(@"keyboard will show"); +} + +- (void)keyboardWillHide{ + isInputingText = false; + // NSLog(@"keyboard will hide"); +} + + - (void)toggleKeyboard{ - if (false){ - isInputingText = false; - } if (isInputingText) { Log(LOG_D, @"Closing the keyboard"); + // NSLog(@"Closing the keyboard"); [keyInputField resignFirstResponder]; isInputingText = false; } else { + // NSLog(@"Opening the keyboard"); Log(LOG_D, @"Opening the keyboard"); // Prepare the textbox used to capture keyboard events. keyInputField.delegate = self; @@ -178,7 +197,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; [keyInputField addTarget:self action:@selector(onKeyboardPressed:) forControlEvents:UIControlEventEditingChanged]; // Undo causes issues for our state management, so turn it off [keyInputField.undoManager disableUndoRegistration]; - isInputingText = true; + //isInputingText = true; } } @@ -489,7 +508,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; // activation of one or two finger gestures when a three finger gesture // is triggered. [touchHandler touchesBegan:touches withEvent:event]; - + // I refactored keyboard toggle by the CustomTapGestureRecognizer // if ([[event allTouches] count] == keyboardToggleFingers) [self toggleKeyboard]; } } diff --git a/Limelight/ViewControllers/SettingsViewController.m b/Limelight/ViewControllers/SettingsViewController.m index d86106f7..71d20633 100644 --- a/Limelight/ViewControllers/SettingsViewController.m +++ b/Limelight/ViewControllers/SettingsViewController.m @@ -264,7 +264,7 @@ BOOL isCustomResolution(CGSize res) { [self updateBitrateText]; [self updateResolutionDisplayViewText]; [self.keyboardToggleFingerNumSlider setValue:(CGFloat)currentSettings.keyboardToggleFingers.intValue animated:YES]; // Load old setting. old setting was converted to uint32_t before saving. - [self.keyboardToggleFingerNumLabel setText:[NSString stringWithFormat:@"Fingers to Tap on Local Keyboard: %@", @((uint16_t)self.keyboardToggleFingerNumSlider.value)]]; // Initiate label display + [self.keyboardToggleFingerNumLabel setText:[NSString stringWithFormat:@"Fingers to Tap-Toggle Local Keyboard: %@", @((uint16_t)self.keyboardToggleFingerNumSlider.value)]]; // Initiate label display [self.keyboardToggleFingerNumSlider addTarget:self action:@selector(keyboardToggleFingerNumSliderMoved) forControlEvents:(UIControlEventValueChanged)]; // Update label display when slider is being moved. } @@ -460,7 +460,7 @@ BOOL isCustomResolution(CGSize res) { } - (void) keyboardToggleFingerNumSliderMoved{ - [self.keyboardToggleFingerNumLabel setText:[NSString stringWithFormat:@"Fingers to Tap on Local Keyboard: %@", @((uint8_t)self.keyboardToggleFingerNumSlider.value)]]; + [self.keyboardToggleFingerNumLabel setText:[NSString stringWithFormat:@"Fingers to Tap-Toggle Local Keyboard: %@", @((uint8_t)self.keyboardToggleFingerNumSlider.value)]]; } diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index 9a859048..7998f956 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -179,6 +179,7 @@ #if 0 // FIXME: This doesn't work reliably on iPad for some reason. Showing and hiding the keyboard // several times in a row will not correctly restore the state of the UIScrollView. + // I add this notification to the StreamView, works well on ipad mini6. [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(keyboardWillShow:) name: UIKeyboardWillShowNotification diff --git a/iPad.storyboard b/iPad.storyboard index e1bbf1fa..224584ec 100644 --- a/iPad.storyboard +++ b/iPad.storyboard @@ -1,6 +1,6 @@ - + @@ -130,11 +130,11 @@ - + - + @@ -319,8 +319,8 @@ -