From c840cedef9bf106912ff363ac0098e4e6dbf06e6 Mon Sep 17 00:00:00 2001 From: Tom Bogle Date: Wed, 27 Jun 2018 01:32:18 -0400 Subject: [PATCH] [Mac] Prevent permanently hiding OSK when a menu is dropped down This *might* possibly fix #894, but not likely --- mac/Keyman4MacIM/Keyman4MacIM/KMInputController.m | 8 ++++---- .../Keyman4MacIM/KMInputMethodAppDelegate.h | 4 ++-- .../Keyman4MacIM/KMInputMethodAppDelegate.m | 13 +++++++++++-- .../KeymanEngine4Mac/KME/OnScreenKeyboard/OSKView.m | 9 +-------- mac/history.md | 3 +++ 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/mac/Keyman4MacIM/Keyman4MacIM/KMInputController.m b/mac/Keyman4MacIM/Keyman4MacIM/KMInputController.m index 88bedaa42c..742d06c0f2 100644 --- a/mac/Keyman4MacIM/Keyman4MacIM/KMInputController.m +++ b/mac/Keyman4MacIM/Keyman4MacIM/KMInputController.m @@ -57,7 +57,7 @@ NSMutableArray *servers; @synchronized(servers) { [sender overrideKeyboardWithKeyboardNamed:@"com.apple.keylayout.US"]; - [self.AppDelegate wakeUp]; + [self.AppDelegate wakeUpWith:sender]; [servers addObject:sender]; if (_eventHandler != nil) { @@ -102,19 +102,19 @@ NSMutableArray *servers; if ([self.AppDelegate debugMode]) { NSLog(@"No known active server for Keyman IM. Starting countdown to sleep..."); } - [self performSelector:@selector(timerAction:) withObject:nil afterDelay:0.7]; + [self performSelector:@selector(timerAction:) withObject:sender afterDelay:0.7]; } } } -- (void)timerAction:(NSTimer *)timer { +- (void)timerAction:(id)lastServer { @synchronized(servers) { if (servers.count == 0) { if (_eventHandler != nil) { [_eventHandler deactivate]; _eventHandler = nil; } - [self.AppDelegate sleep]; + [self.AppDelegate sleepFollowingDeactivationOfServer:lastServer]; } } } diff --git a/mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodAppDelegate.h b/mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodAppDelegate.h index 85960e9af3..4fc27105ea 100644 --- a/mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodAppDelegate.h +++ b/mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodAppDelegate.h @@ -92,8 +92,8 @@ extern NSString *const kWebSite; - (void)showAboutWindow; - (void)showOSK; - (void)showConfigurationWindow; -- (void)sleep; -- (void)wakeUp; +- (void)sleepFollowingDeactivationOfServer:(id)lastServer; +- (void)wakeUpWith:(id)newServer; - (void)handleKeyEvent:(NSEvent *)event; - (BOOL)unzipFile:(NSString *)filePath; - (NSWindowController *)downloadKBWindow_; diff --git a/mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodAppDelegate.m b/mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodAppDelegate.m index 391569c8c9..335d2f2bed 100644 --- a/mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodAppDelegate.m +++ b/mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodAppDelegate.m @@ -63,6 +63,8 @@ typedef enum { @synthesize contextBuffer = _contextBuffer; @synthesize alwaysShowOSK = _alwaysShowOSK; +id _lastServerWithOSKShowing = nil; + - (id)init { self = [super init]; if (self) { @@ -188,7 +190,7 @@ typedef enum { return (KMInputMethodAppDelegate *)[NSApp delegate]; } --(void) sleep { +-(void) sleepFollowingDeactivationOfServer:(id)lastServer { if ([self debugMode]) { NSLog(@"Keyman no longer active IM."); } @@ -197,6 +199,9 @@ typedef enum { if ([self debugMode]) { NSLog(@"Hiding OSK."); } + // Storing this ensures that if the deactivation is temporary, resulting from dropping down a menu, + // the OSK will re-display when that client application re-activates. + _lastServerWithOSKShowing = lastServer; [self.oskWindow.window setIsVisible:NO]; } if (self.lowLevelEventTap) { @@ -207,7 +212,7 @@ typedef enum { } } --(void) wakeUp { +-(void) wakeUpWith:(id)newServer { self.sleeping = NO; if (self.lowLevelEventTap && !CGEventTapIsEnabled(self.lowLevelEventTap)) { if ([self debugMode]) { @@ -215,6 +220,10 @@ typedef enum { } CGEventTapEnable(self.lowLevelEventTap, YES); } + // See note in sleepFollowingDeactivationOfServer. + if (_kvk != nil && (_alwaysShowOSK || _lastServerWithOSKShowing == newServer)) { + [self showOSK]; + } } CGEventRef eventTapFunction(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) { diff --git a/mac/KeymanEngine4Mac/KeymanEngine4Mac/KME/OnScreenKeyboard/OSKView.m b/mac/KeymanEngine4Mac/KeymanEngine4Mac/KME/OnScreenKeyboard/OSKView.m index 9feb69b4f4..292b948aed 100644 --- a/mac/KeymanEngine4Mac/KeymanEngine4Mac/KME/OnScreenKeyboard/OSKView.m +++ b/mac/KeymanEngine4Mac/KeymanEngine4Mac/KME/OnScreenKeyboard/OSKView.m @@ -359,14 +359,7 @@ - (void)keyAction:(id)sender { KeyView *keyView = (KeyView *)sender; - NSUInteger keyCode; - @try { - keyCode = [keyView.key keyCode]; - } - @catch (NSException *exception) { - NSLog(@"Exception in keyAction:sender - %@", exception); - return; - } + NSUInteger keyCode = [keyView.key keyCode]; if (keyCode < 0x100) { ProcessSerialNumber psn; GetFrontProcess(&psn); diff --git a/mac/history.md b/mac/history.md index 3cf206fb9f..6d3db26ecf 100644 --- a/mac/history.md +++ b/mac/history.md @@ -1,5 +1,8 @@ # Keyman for macOS Version History +## 2018-06-27 10.0.52 beta +* Prevented permanently hiding OSK when a menu is dropped down (#1031) + ## 2018-06-26 10.0.51 beta * Prevented calling CFRelease() with a NULL argument (#1019)