From 6e63873e661be7dcf206077679e601fd5cae35bd Mon Sep 17 00:00:00 2001 From: MicahChase Date: Wed, 11 Dec 2013 15:13:01 -0600 Subject: [PATCH] bluetooth keyboard fix --- .../Controllers/RDPSessionViewController.h | 2 +- .../Controllers/RDPSessionViewController.m | 61 +++++++++++-------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/client/iOS/Controllers/RDPSessionViewController.h b/client/iOS/Controllers/RDPSessionViewController.h index fb4904b38..36e64a93d 100644 --- a/client/iOS/Controllers/RDPSessionViewController.h +++ b/client/iOS/Controllers/RDPSessionViewController.h @@ -57,7 +57,7 @@ AdvancedKeyboardView* _advanced_keyboard_view; BOOL _advanced_keyboard_visible; BOOL _requesting_advanced_keyboard; - CGFloat _keyboard_height_delta; + CGFloat _keyboard_last_height; // delayed mouse move event sending NSTimer* _mouse_move_event_timer; diff --git a/client/iOS/Controllers/RDPSessionViewController.m b/client/iOS/Controllers/RDPSessionViewController.m index 1e4958040..c312cef96 100644 --- a/client/iOS/Controllers/RDPSessionViewController.m +++ b/client/iOS/Controllers/RDPSessionViewController.m @@ -51,7 +51,7 @@ _advanced_keyboard_view = nil; _advanced_keyboard_visible = NO; _requesting_advanced_keyboard = NO; - _keyboard_height_delta = 0; + _keyboard_last_height = 0; _session_toolbar_visible = NO; @@ -549,25 +549,46 @@ #pragma mark - #pragma mark iOS Keyboard Notification Handlers -- (void)keyboardWillShow:(NSNotification *)notification -{ - CGRect keyboardEndFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; - CGRect keyboardFrame = [[self view] convertRect:keyboardEndFrame toView:nil]; +// the keyboard is given in a portrait frame of reference +- (BOOL)isLandscape { + + UIInterfaceOrientation ori = [[UIApplication sharedApplication] statusBarOrientation]; + return ( ori == UIInterfaceOrientationLandscapeLeft || ori == UIInterfaceOrientationLandscapeRight ); + +} - CGFloat newHeightDelta = (keyboardFrame.size.height - _keyboard_height_delta); - if (newHeightDelta < 0.1 && newHeightDelta > -0.1) - return; // nothing changed - - [UIView beginAnimations:nil context:NULL]; +- (void)shiftKeyboard: (NSNotification*)notification { + + CGRect keyboardEndFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; + + CGFloat previousHeight = _keyboard_last_height; + + if( [self isLandscape] ) { + // landscape has the keyboard based on x, so x can go negative + _keyboard_last_height = keyboardEndFrame.size.width + keyboardEndFrame.origin.x; + } else { + // portrait has the keyboard based on the difference of the height and the frames y. + CGFloat height = [[UIScreen mainScreen] bounds].size.height; + _keyboard_last_height = height - keyboardEndFrame.origin.y; + } + + CGFloat shiftHeight = _keyboard_last_height - previousHeight; + + [UIView beginAnimations:nil context:NULL]; [UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]]; [UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]]; CGRect frame = [_session_scrollview frame]; - frame.size.height -= newHeightDelta; - _keyboard_height_delta += newHeightDelta; + frame.size.height -= shiftHeight; [_session_scrollview setFrame:frame]; - [_touchpointer_view setFrame:frame]; + [_touchpointer_view setFrame:frame]; [UIView commitAnimations]; + +} +- (void)keyboardWillShow:(NSNotification *)notification +{ + [self shiftKeyboard: notification]; + [_touchpointer_view ensurePointerIsVisible]; } @@ -583,17 +604,9 @@ - (void)keyboardWillHide:(NSNotification *)notification { - CGRect keyboardEndFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; - - [UIView beginAnimations:nil context:NULL]; - [UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]]; - [UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]]; - CGRect frame = [_session_scrollview frame]; - frame.size.height += [[self view] convertRect:keyboardEndFrame toView:nil].size.height; - [_session_scrollview setFrame:frame]; - [_touchpointer_view setFrame:frame]; - [UIView commitAnimations]; - _keyboard_height_delta = 0; + + [self shiftKeyboard: notification]; + } - (void)keyboardDidHide:(NSNotification*)notification