From 554f0c47bc42d5dc3cd79ae0ca66257575729901 Mon Sep 17 00:00:00 2001 From: Theodore Dubois Date: Sun, 31 May 2020 18:24:52 -0700 Subject: [PATCH] Revert "Add a setting that hides extra keys with a HW keyboard" Broke various keyboard related behaviors (#753) This reverts commit d7a915e9306bc775974c7eee4b59c9251cdf53ef. --- app/AboutExternalKeyboardViewController.m | 5 --- app/Base.lproj/About.storyboard | 36 +----------------- app/Base.lproj/Main.storyboard | 5 ++- app/TerminalViewController.m | 46 +++++++---------------- app/UserPreferences.h | 1 - app/UserPreferences.m | 8 ---- 6 files changed, 17 insertions(+), 84 deletions(-) diff --git a/app/AboutExternalKeyboardViewController.m b/app/AboutExternalKeyboardViewController.m index 8f914749d6..42250021a0 100644 --- a/app/AboutExternalKeyboardViewController.m +++ b/app/AboutExternalKeyboardViewController.m @@ -14,7 +14,6 @@ @interface AboutExternalKeyboardViewController () @property (weak, nonatomic) IBOutlet UISwitch *optionMetaSwitch; @property (weak, nonatomic) IBOutlet UISwitch *backtickEscapeSwitch; -@property (weak, nonatomic) IBOutlet UISwitch *hideExtraKeysWithExternalKeyboardSwitch; @end @@ -39,7 +38,6 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N - (void)_update { self.optionMetaSwitch.on = UserPreferences.shared.optionMapping == OptionMapEsc; self.backtickEscapeSwitch.on = UserPreferences.shared.backtickMapEscape; - self.hideExtraKeysWithExternalKeyboardSwitch.on = UserPreferences.shared.hideExtraKeysWithExternalKeyboard; } - (IBAction)optionMetaToggle:(UISwitch *)sender { @@ -48,9 +46,6 @@ - (IBAction)optionMetaToggle:(UISwitch *)sender { - (IBAction)backtickEscapeToggle:(UISwitch *)sender { UserPreferences.shared.backtickMapEscape = sender.on; } -- (IBAction)hideExtraKeysToggle:(UISwitch *)sender { - UserPreferences.shared.hideExtraKeysWithExternalKeyboard = sender.on; -} - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == kCapsLockMappingSection && cell.tag == UserPreferences.shared.capsLockMapping) diff --git a/app/Base.lproj/About.storyboard b/app/Base.lproj/About.storyboard index bd0406f6e8..e657d962de 100644 --- a/app/Base.lproj/About.storyboard +++ b/app/Base.lproj/About.storyboard @@ -372,7 +372,7 @@ - + @@ -402,39 +402,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -443,7 +410,6 @@ - diff --git a/app/Base.lproj/Main.storyboard b/app/Base.lproj/Main.storyboard index ff2854d38b..dc7d2302e1 100644 --- a/app/Base.lproj/Main.storyboard +++ b/app/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -21,6 +21,7 @@ + diff --git a/app/TerminalViewController.m b/app/TerminalViewController.m index fa72f90824..5e8048d1cd 100644 --- a/app/TerminalViewController.m +++ b/app/TerminalViewController.m @@ -45,9 +45,6 @@ @interface TerminalViewController () @property (nonatomic) Terminal *sessionTerminal; @property int sessionTerminalNumber; -@property BOOL ignoreKeyboardMotion; -@property (nonatomic) BOOL hasExternalKeyboard; - @end @implementation TerminalViewController @@ -73,10 +70,6 @@ - (void)viewDidLoad { selector:@selector(keyboardDidSomething:) name:UIKeyboardWillChangeFrameNotification object:nil]; - [center addObserver:self - selector:@selector(keyboardDidSomething:) - name:UIKeyboardDidChangeFrameNotification - object:nil]; [self _updateStyleFromPreferences:NO]; @@ -112,7 +105,6 @@ - (void)awakeFromNib { name:ProcessExitedNotification object:nil]; [[UserPreferences shared] addObserver:self forKeyPath:@"theme" options:NSKeyValueObservingOptionNew context:nil]; - [[UserPreferences shared] addObserver:self forKeyPath:@"hideExtraKeysWithExternalKeyboard" options:NSKeyValueObservingOptionNew context:nil]; } - (void)startNewSession { @@ -222,16 +214,6 @@ - (void)_updateStyleFromPreferences:(BOOL)animated { control.tintColor = tintColor; } }]; - if (UserPreferences.shared.hideExtraKeysWithExternalKeyboard && self.hasExternalKeyboard) { - self.termView.inputAccessoryView = nil; - } else { - self.termView.inputAccessoryView = self.barView; - } - if (self.termView.isFirstResponder) { - self.ignoreKeyboardMotion = YES; // avoid infinite recursion - [self.termView reloadInputViews]; - self.ignoreKeyboardMotion = NO; - } } - (UIStatusBarStyle)preferredStatusBarStyle { @@ -244,23 +226,26 @@ - (BOOL)prefersStatusBarHidden { } - (void)keyboardDidSomething:(NSNotification *)notification { - if (self.ignoreKeyboardMotion) - return; - + // NSLog(@"%@", notification); + BOOL initialLayout = self.termView.needsUpdateConstraints; + CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; - if (CGRectEqualToRect(keyboardFrame, CGRectZero)) - return; - NSLog(@"%@ %@", notification.name, [NSValue valueWithCGRect:keyboardFrame]); - self.hasExternalKeyboard = keyboardFrame.size.height < 100; - CGFloat pad = UIScreen.mainScreen.bounds.size.height - keyboardFrame.origin.y; + CGFloat pad; + if (keyboardFrame.origin.x == 0 && + keyboardFrame.origin.y == 0 && + keyboardFrame.size.height == 0 && + keyboardFrame.size.width == 0) { + pad = 0; + } else { + pad = UIScreen.mainScreen.bounds.size.height - keyboardFrame.origin.y; + } if (pad == 0) { pad = self.view.safeAreaInsets.bottom; } // NSLog(@"pad %f", pad); self.bottomConstraint.constant = -pad; - - BOOL initialLayout = self.termView.needsUpdateConstraints; [self.view setNeedsUpdateConstraints]; + if (!initialLayout) { // if initial layout hasn't happened yet, the terminal view is going to be at a really weird place, so animating it is going to look really bad NSNumber *interval = notification.userInfo[UIKeyboardAnimationDurationUserInfoKey]; @@ -275,11 +260,6 @@ - (void)keyboardDidSomething:(NSNotification *)notification { } } -- (void)setHasExternalKeyboard:(BOOL)hasExternalKeyboard { - _hasExternalKeyboard = hasExternalKeyboard; - [self _updateStyleFromPreferences:YES]; -} - - (void)ishExited:(NSNotification *)notification { [self performSelectorOnMainThread:@selector(displayExitThing) withObject:nil waitUntilDone:YES]; } diff --git a/app/UserPreferences.h b/app/UserPreferences.h index a2aa4c25db..bad6e1571a 100644 --- a/app/UserPreferences.h +++ b/app/UserPreferences.h @@ -43,7 +43,6 @@ extern NSString *const kThemeBackgroundColor; @property CapsLockMapping capsLockMapping; @property OptionMapping optionMapping; @property BOOL backtickMapEscape; -@property BOOL hideExtraKeysWithExternalKeyboard; @property (nonatomic) Theme *theme; @property BOOL shouldDisableDimming; @property NSString *fontFamily; diff --git a/app/UserPreferences.m b/app/UserPreferences.m index 2e251761e7..65e1851861 100644 --- a/app/UserPreferences.m +++ b/app/UserPreferences.m @@ -11,7 +11,6 @@ static NSString *const kPreferenceCapsLockMappingKey = @"Caps Lock Mapping"; static NSString *const kPreferenceOptionMappingKey = @"Option Mapping"; static NSString *const kPreferenceBacktickEscapeKey = @"Backtick Mapping Escape"; -static NSString *const kPreferenceHideExtraKeysWithExternalKeyboard = @"Hide Extra Keys With External Keyboard"; static NSString *const kPreferenceFontFamilyKey = @"Font Family"; static NSString *const kPreferenceFontSizeKey = @"Font Size"; static NSString *const kPreferenceThemeKey = @"Theme"; @@ -74,13 +73,6 @@ - (void)setBacktickMapEscape:(BOOL)backtickMapEscape { [_defaults setBool:backtickMapEscape forKey:kPreferenceBacktickEscapeKey]; } -- (BOOL)hideExtraKeysWithExternalKeyboard { - return [_defaults boolForKey:kPreferenceHideExtraKeysWithExternalKeyboard]; -} -- (void)setHideExtraKeysWithExternalKeyboard:(BOOL)hideExtraKeysWithExternalKeyboard { - [_defaults setBool:hideExtraKeysWithExternalKeyboard forKey:kPreferenceHideExtraKeysWithExternalKeyboard]; -} - - (NSNumber *)fontSize { return [_defaults objectForKey:kPreferenceFontSizeKey]; }