From cd26c65b4b30fc94d435587206008bf9747a6719 Mon Sep 17 00:00:00 2001 From: Mark Jerde Date: Sat, 1 Aug 2020 22:59:23 -0500 Subject: [PATCH] Make bezel close when it loses focus The bezel doesn't provide any UI indication when it loses focus and this no longer responds to input. This ranges anywhere from being klunky to being a bug. Users have reported that they believed Flycut to have hung when encountering this. This defines a protocol for the BezelWindow's delegate, which had previously just been a blind id delegate and makes the new delegate inherit from NSWindowDelegate so that AppController can receive windowDidResignKey: to indicate when focus is lost and immediately close the bezel. --- AppController.h | 3 ++- AppController.m | 8 +++++++- UI/BezelWindow.h | 13 ++++++++++--- UI/BezelWindow.m | 5 +++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/AppController.h b/AppController.h index d829182..0ccfead 100755 --- a/AppController.h +++ b/AppController.h @@ -22,7 +22,7 @@ @class SGHotKey; -@interface AppController : NSObject { +@interface AppController : NSObject { BezelWindow *bezel; SGHotKey *mainHotKey; IBOutlet SRRecorderControl *mainRecorder; @@ -97,6 +97,7 @@ -(void) processBezelKeyDown:(NSEvent *)theEvent; -(void) processBezelMouseEvents:(NSEvent *)theEvent; -(void) metaKeysReleased; +-(void) windowDidResignKey:(NSNotification *)notification; // Menu related -(void) updateMenu; diff --git a/AppController.m b/AppController.m index 1940775..7d308f8 100755 --- a/AppController.m +++ b/AppController.m @@ -758,6 +758,12 @@ - (void)metaKeysReleased } } +- (void)windowDidResignKey:(NSNotification *)notification { + if ( isBezelPinned ) { + [self hideApp]; + } +} + -(void)fakeKey:(NSNumber*) keyCode withCommandFlag:(BOOL) setFlag /*" +fakeKey synthesizes keyboard events. "*/ { @@ -1059,8 +1065,8 @@ - (void) hideBezel -(void)hideApp { - [self hideBezel]; isBezelPinned = NO; + [self hideBezel]; [NSApp hide:self]; } diff --git a/UI/BezelWindow.h b/UI/BezelWindow.h index 946a1f0..0a6f9a6 100755 --- a/UI/BezelWindow.h +++ b/UI/BezelWindow.h @@ -14,6 +14,13 @@ #import "RoundRecBezierPath.h" #import "RoundRecTextField.h" +@protocol BezelWindowDelegate + +-(void)processBezelKeyDown:(NSEvent *)theEvent; +-(void)processBezelMouseEvents:(NSEvent *)theEvent; +-(void)metaKeysReleased; + +@end @interface BezelWindow : NSPanel { // "n of n" text in bezel @@ -33,7 +40,7 @@ RoundRecTextField *textField; RoundRecTextField *charField; NSImageView *iconView; - id delegate; + id delegate; Boolean color; } @@ -57,7 +64,7 @@ - (void)setDate:(NSString *)newDate; - (void)setSourceIcon:(NSImage *)newSourceIcon; -- (id)delegate; -- (void)setDelegate:(id)newDelegate; +- (id)delegate; +- (void)setDelegate:(id)newDelegate; @end diff --git a/UI/BezelWindow.m b/UI/BezelWindow.m index 676bf3c..c45135d 100755 --- a/UI/BezelWindow.m +++ b/UI/BezelWindow.m @@ -365,12 +365,13 @@ - (void)flagsChanged:(NSEvent *)theEvent { } } -- (id)delegate { +- (id)delegate { return delegate; } -- (void)setDelegate:(id)newDelegate { +- (void)setDelegate:(id)newDelegate { delegate = newDelegate; + super.delegate = newDelegate; } @end