From a9edfaac60349a0aeff803ee7451ccbfafa42d83 Mon Sep 17 00:00:00 2001 From: Erez Volk Date: Sat, 23 Dec 2017 12:30:25 +0200 Subject: [PATCH 1/6] Added an option to gray out when paused --- Credits.rtf | 3 +- PreferencesWindowController.h | 2 + PreferencesWindowController.m | 2 + PreferencesWindowController.xib | 785 ++++---------------------------- ThymeAppDelegate.m | 19 +- 5 files changed, 118 insertions(+), 693 deletions(-) diff --git a/Credits.rtf b/Credits.rtf index 7e7d2da..8214871 100644 --- a/Credits.rtf +++ b/Credits.rtf @@ -15,4 +15,5 @@ \ls1\ilvl0\cf0 {\listtext \'95 }{\field{\*\fldinst{HYPERLINK "https://github.com/dimonzozo"}}{\fldrslt Dmitriy}}\ {\listtext \'95 }{\field{\*\fldinst{HYPERLINK "https://github.com/jaysonlane"}}{\fldrslt Jason Lane}}\ {\listtext \'95 }{\field{\*\fldinst{HYPERLINK "https://github.com/tilden"}}{\fldrslt Dan Tilden}}\ -} \ No newline at end of file +{\listtext \'95 }{\field{\*\fldinst{HYPERLINK "https://github.com/ErezVolk"}}{\fldrslt Erez Volk}}\ +} diff --git a/PreferencesWindowController.h b/PreferencesWindowController.h index c15d760..bc822b2 100644 --- a/PreferencesWindowController.h +++ b/PreferencesWindowController.h @@ -15,6 +15,7 @@ SRRecorderControl *finishShortcutRecorder; NSButton *pauseOnSleepButton; NSButton *pauseOnScreensaverButton; + NSButton *appearDisabledWhilePaused; } @property (nonatomic, retain) IBOutlet SRRecorderControl *startPauseShortcutRecorder; @@ -22,5 +23,6 @@ @property (nonatomic, retain) IBOutlet SRRecorderControl *finishShortcutRecorder; @property (nonatomic, retain) IBOutlet NSButton *pauseOnSleepButton; @property (nonatomic, retain) IBOutlet NSButton *pauseOnScreensaverButton; +@property (nonatomic, retain) IBOutlet NSButton *appearDisabledWhilePaused; @end diff --git a/PreferencesWindowController.m b/PreferencesWindowController.m index afccce8..9334102 100644 --- a/PreferencesWindowController.m +++ b/PreferencesWindowController.m @@ -19,6 +19,7 @@ @implementation PreferencesWindowController @synthesize finishShortcutRecorder; @synthesize pauseOnSleepButton; @synthesize pauseOnScreensaverButton; +@synthesize appearDisabledWhilePaused; - (id)initWithWindow:(NSWindow *)window { @@ -42,6 +43,7 @@ - (void)windowDidLoad [self.pauseOnSleepButton bind:NSValueBinding toObject:defaults withKeyPath:@"values.pauseOnSleep" options:nil]; [self.pauseOnScreensaverButton bind:NSValueBinding toObject:defaults withKeyPath:@"values.pauseOnScreensaver" options:nil]; + [self.appearDisabledWhilePaused bind:NSValueBinding toObject:defaults withKeyPath:@"values.appearDisabledWhilePaused" options:nil]; [self.startPauseShortcutRecorder clearButtonRect]; diff --git a/PreferencesWindowController.xib b/PreferencesWindowController.xib index 485d86c..5ace995 100644 --- a/PreferencesWindowController.xib +++ b/PreferencesWindowController.xib @@ -1,687 +1,100 @@ - - - 101000 - 14C1510 - 6751 - 1344.72 - 757.30 - - com.apple.InterfaceBuilder.CocoaPlugin - 6751 - - - NSButton - NSButtonCell - NSCustomObject - NSCustomView - NSTextField - NSTextFieldCell - NSView - NSWindowTemplate - - - com.apple.InterfaceBuilder.CocoaPlugin - - - PluginDependencyRecalculationVersion - - - - - PreferencesWindowController - - - FirstResponder - - - NSApplication - - - 19 - 2 - {{566, 207}, {318, 179}} - -1535638528 - Thyme Preferences - NSPanel - - - - - 256 - - - - 268 - {{123, 135}, {183, 24}} - - - - _NS:9 - SRRecorderControl - - - - 268 - {{123, 71}, {183, 24}} - - - - _NS:9 - SRRecorderControl - - - - 268 - {{29, 139}, {89, 17}} - - - - _NS:1535 - YES - - 68157504 - 71304192 - Start / Pause: - - YES - 13 - 1044 - - _NS:1535 - - - 6 - System - controlColor - - 3 - MC42NjY2NjY2NjY3AA - - - - 6 - System - controlTextColor - - 3 - MAA - - - - NO - 1 - - - - 268 - {{35, 74}, {82, 18}} - - - - _NS:1535 - YES - - 68157504 - 71304192 - Finish: - - _NS:1535 - - - - - NO - 1 - - - - 268 - {{123, 103}, {183, 24}} - - - - _NS:9 - SRRecorderControl - - - - 268 - {{36, 106}, {82, 18}} - - - - _NS:1535 - YES - - 68157504 - 71304192 - Restart: - - _NS:1535 - - - - - NO - 1 - - - - 268 - {{18, 38}, {290, 18}} - - - - _NS:9 - YES - - 67108864 - 268435456 - Pause during sleep - - _NS:9 - - 1211912448 - 2 - - NSImage - NSSwitch - - - NSSwitch - - - - 200 - 25 - - NO - - - - 268 - {{18, 18}, {290, 18}} - - - - _NS:9 - YES - - 67108864 - 268435456 - Pause during screensaver / screen lock - - _NS:9 - - 1211912448 - 2 - - - - - 200 - 25 - - NO - - - {318, 179} - - - - _NS:21 - - {{0, 0}, {1440, 877}} - {10000000000000, 10000000000000} - YES - - - - - - - window - - - - 8 - - - - finishShortcutRecorder - - - - 98 - - - - startPauseShortcutRecorder - - - - 99 - - - - restartShortcutRecorder - - - - 114 - - - - pauseOnSleepButton - - - - 126 - - - - pauseOnScreensaverButton - - - - 129 - - - - delegate - - - - 7 - - - - - - 0 - - - - - - -2 - - - File's Owner - - - -1 - - - First Responder - - - -3 - - - Application - - - 5 - - - - - - - - 6 - - - - - - - - - - - - - - - 9 - - - - - 28 - - - - - - - - 29 - - - - - 60 - - - - - - - - 62 - - - - - 93 - - - - - 111 - - - - - 112 - - - - - - - - 113 - - - - - 117 - - - - - - - - 118 - - - - - 127 - - - - - - - - 128 - - - - - - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - - {461, 421.5} - com.apple.InterfaceBuilder.CocoaPlugin - - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - - - - - 129 - - - - - PreferencesWindowController - NSWindowController - - SRRecorderControl - NSButton - NSButton - SRRecorderControl - SRRecorderControl - - - - finishShortcutRecorder - SRRecorderControl - - - pauseOnScreensaverButton - NSButton - - - pauseOnSleepButton - NSButton - - - restartShortcutRecorder - SRRecorderControl - - - startPauseShortcutRecorder - SRRecorderControl - - - - IBProjectSource - ../PreferencesWindowController.h - - - - SRRecorderControl - NSView - - delegate - NSObject - - - delegate - - delegate - NSObject - - - - IBProjectSource - ../ShortcutRecorder/SRRecorderControl.h - - - - - - NSActionCell - NSCell - - IBFrameworkSource - AppKit.framework/Headers/NSActionCell.h - - - - NSApplication - NSResponder - - IBFrameworkSource - AppKit.framework/Headers/NSApplication.h - - - - NSButton - NSControl - - IBFrameworkSource - AppKit.framework/Headers/NSButton.h - - - - NSButtonCell - NSActionCell - - IBFrameworkSource - AppKit.framework/Headers/NSButtonCell.h - - - - NSCell - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSCell.h - - - - NSControl - NSView - - IBFrameworkSource - AppKit.framework/Headers/NSControl.h - - - - NSFormatter - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSFormatter.h - - - - NSMenu - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSMenu.h - - - - NSPanel - NSWindow - - IBFrameworkSource - AppKit.framework/Headers/NSPanel.h - - - - NSResponder - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSResponder.h - - - - NSTextField - NSControl - - IBFrameworkSource - AppKit.framework/Headers/NSTextField.h - - - - NSTextFieldCell - NSActionCell - - IBFrameworkSource - AppKit.framework/Headers/NSTextFieldCell.h - - - - NSView - NSResponder - - IBFrameworkSource - AppKit.framework/Headers/NSView.h - - - - NSWindow - NSResponder - - IBFrameworkSource - AppKit.framework/Headers/NSWindow.h - - - - NSWindowController - NSResponder - - showWindow: - id - - - showWindow: - - showWindow: - id - - - - IBFrameworkSource - AppKit.framework/Headers/NSWindowController.h - - - - SRRecorderControl - NSView - - delegate - NSObject - - - delegate - - delegate - NSObject - - - - IBFrameworkSource - ShortcutRecorder.framework/Headers/SRRecorderControl.h - - - - - 0 - IBCocoaFramework - NO - - com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 - - - YES - 3 - - NSSwitch - {15, 15} - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ThymeAppDelegate.m b/ThymeAppDelegate.m index b4638bc..964c932 100644 --- a/ThymeAppDelegate.m +++ b/ThymeAppDelegate.m @@ -214,17 +214,24 @@ - (IBAction)onAboutClick:(id)sender { } - (void)updateStatusBar { + NSStatusBarButton *button = [statusItem button]; + if ([self.stopwatch isStopped]) { - [statusItem setLength:26.0]; - [statusItem setTitle:@""]; - NSImage *logo = [NSImage imageNamed:@"logo_small"]; [logo setTemplate:YES]; - [statusItem setImage: logo]; + [statusItem setLength:26.0]; + [button setTitle:@""]; + [button setImage:logo]; + [button setAppearsDisabled:false]; } else { [statusItem setLength:[self.stopwatch value] > 3600 ? 72.0 : 46.0]; - [statusItem setTitle:[self.stopwatch description]]; - [statusItem setImage:nil]; + [button setTitle:[self.stopwatch description]]; + [button setImage:nil]; + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"appearDisabledWhilePaused"]) { + [button setAppearsDisabled:![self.stopwatch isActive]]; + } else { + [button setAppearsDisabled:false]; + } } } From 9f32d5e9302a9716f04bc1da89647c645e0a88ad Mon Sep 17 00:00:00 2001 From: ErezVolk Date: Sun, 12 May 2019 17:50:26 +0300 Subject: [PATCH 2/6] Update PreferencesWindowController.h Fix by @smokris for `Failed to connect (appearDisabledWhilePausedButton) outlet from (PreferencesWindowController) to (NSButton)` Co-Authored-By: Steve Mokris --- PreferencesWindowController.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PreferencesWindowController.h b/PreferencesWindowController.h index bc822b2..047c324 100644 --- a/PreferencesWindowController.h +++ b/PreferencesWindowController.h @@ -15,7 +15,7 @@ SRRecorderControl *finishShortcutRecorder; NSButton *pauseOnSleepButton; NSButton *pauseOnScreensaverButton; - NSButton *appearDisabledWhilePaused; + NSButton *appearDisabledWhilePausedButton; } @property (nonatomic, retain) IBOutlet SRRecorderControl *startPauseShortcutRecorder; From 66026db5bf86a51dd7e99caa7a4bd96085140a72 Mon Sep 17 00:00:00 2001 From: ErezVolk Date: Sun, 12 May 2019 17:50:38 +0300 Subject: [PATCH 3/6] Update PreferencesWindowController.h Fix by @smokris for `Failed to connect (appearDisabledWhilePausedButton) outlet from (PreferencesWindowController) to (NSButton)` Co-Authored-By: Steve Mokris --- PreferencesWindowController.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PreferencesWindowController.h b/PreferencesWindowController.h index 047c324..709d972 100644 --- a/PreferencesWindowController.h +++ b/PreferencesWindowController.h @@ -23,6 +23,6 @@ @property (nonatomic, retain) IBOutlet SRRecorderControl *finishShortcutRecorder; @property (nonatomic, retain) IBOutlet NSButton *pauseOnSleepButton; @property (nonatomic, retain) IBOutlet NSButton *pauseOnScreensaverButton; -@property (nonatomic, retain) IBOutlet NSButton *appearDisabledWhilePaused; +@property (nonatomic, retain) IBOutlet NSButton *appearDisabledWhilePausedButton; @end From a4054b85760982d9fa2b0ed4f14d1e7eb3cf446a Mon Sep 17 00:00:00 2001 From: ErezVolk Date: Sun, 12 May 2019 17:50:46 +0300 Subject: [PATCH 4/6] Update PreferencesWindowController.m Fix by @smokris for `Failed to connect (appearDisabledWhilePausedButton) outlet from (PreferencesWindowController) to (NSButton)` Co-Authored-By: Steve Mokris --- PreferencesWindowController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PreferencesWindowController.m b/PreferencesWindowController.m index 9334102..9c080f1 100644 --- a/PreferencesWindowController.m +++ b/PreferencesWindowController.m @@ -43,7 +43,7 @@ - (void)windowDidLoad [self.pauseOnSleepButton bind:NSValueBinding toObject:defaults withKeyPath:@"values.pauseOnSleep" options:nil]; [self.pauseOnScreensaverButton bind:NSValueBinding toObject:defaults withKeyPath:@"values.pauseOnScreensaver" options:nil]; - [self.appearDisabledWhilePaused bind:NSValueBinding toObject:defaults withKeyPath:@"values.appearDisabledWhilePaused" options:nil]; + [self.appearDisabledWhilePausedButton bind:NSValueBinding toObject:defaults withKeyPath:@"values.appearDisabledWhilePaused" options:nil]; [self.startPauseShortcutRecorder clearButtonRect]; From 8421e1b2494809fb931556d571dc739042a5e16d Mon Sep 17 00:00:00 2001 From: ErezVolk Date: Sun, 12 May 2019 17:50:56 +0300 Subject: [PATCH 5/6] Update PreferencesWindowController.m Fix by @smokris for `Failed to connect (appearDisabledWhilePausedButton) outlet from (PreferencesWindowController) to (NSButton)` Co-Authored-By: Steve Mokris --- PreferencesWindowController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PreferencesWindowController.m b/PreferencesWindowController.m index 9c080f1..e283cbf 100644 --- a/PreferencesWindowController.m +++ b/PreferencesWindowController.m @@ -19,7 +19,7 @@ @implementation PreferencesWindowController @synthesize finishShortcutRecorder; @synthesize pauseOnSleepButton; @synthesize pauseOnScreensaverButton; -@synthesize appearDisabledWhilePaused; +@synthesize appearDisabledWhilePausedButton; - (id)initWithWindow:(NSWindow *)window { From 54c6ce4017ea488dbb666340c180e56fd45efd4f Mon Sep 17 00:00:00 2001 From: Erez Volk Date: Fri, 31 Jan 2020 11:06:49 +0200 Subject: [PATCH 6/6] Updated DDHotKey usage --- DDHotKeyCenter.h | 27 ++++++++++++--------------- DDHotKeyCenter.m | 42 +++++++++++++++--------------------------- DDHotKeyUtilities.h | 2 +- DDHotKeyUtilities.m | 19 +++++++++---------- TagWindowController.m | 4 ++++ ThymeAppDelegate.m | 7 ++++--- 6 files changed, 45 insertions(+), 56 deletions(-) diff --git a/DDHotKeyCenter.h b/DDHotKeyCenter.h index 7261e2f..6f79bbb 100644 --- a/DDHotKeyCenter.h +++ b/DDHotKeyCenter.h @@ -10,20 +10,18 @@ #import -NS_ASSUME_NONNULL_BEGIN - //a convenient typedef for the required signature of a hotkey block callback typedef void (^DDHotKeyTask)(NSEvent*); @interface DDHotKey : NSObject // creates a new hotkey but does not register it -+ (instancetype)hotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags task:(DDHotKeyTask _Nullable)task; ++ (instancetype)hotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags task:(DDHotKeyTask)task; -@property (nonatomic, assign, readonly, nullable) id target; -@property (nonatomic, readonly, nullable) SEL action; -@property (nonatomic, strong, readonly, nullable) id object; -@property (nonatomic, copy, readonly, nullable) DDHotKeyTask task; +@property (nonatomic, assign, readonly) id target; +@property (nonatomic, readonly) SEL action; +@property (nonatomic, strong, readonly) id object; +@property (nonatomic, copy, readonly) DDHotKeyTask task; @property (nonatomic, readonly) unsigned short keyCode; @property (nonatomic, readonly) NSUInteger modifierFlags; @@ -34,26 +32,26 @@ typedef void (^DDHotKeyTask)(NSEvent*); @interface DDHotKeyCenter : NSObject -@property (class, readonly, nonnull) DDHotKeyCenter *sharedHotKeyCenter; ++ (instancetype)sharedHotKeyCenter; /** Register a hotkey. */ -- (DDHotKey * _Nullable)registerHotKey:(DDHotKey *)hotKey withError:(NSError **)error; +- (DDHotKey *)registerHotKey:(DDHotKey *)hotKey; /** Register a target/action hotkey. - The modifierFlags must be a bitwise OR of NSEventModifierFlagCommand, NSEventModifierFlagOption, NSEventModifierFlagControl, or NSEventModifierFlagShift; + The modifierFlags must be a bitwise OR of NSCommandKeyMask, NSAlternateKeyMask, NSControlKeyMask, or NSShiftKeyMask; Returns the hotkey registered. If registration failed, returns nil. */ -- (DDHotKey * _Nullable)registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags target:(id)target action:(SEL)action object:(id)object error:(NSError **)error; +- (DDHotKey *)registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags target:(id)target action:(SEL)action object:(id)object; /** Register a block callback hotkey. - The modifierFlags must be a bitwise OR of NSEventModifierFlagCommand, NSEventModifierFlagOption, NSEventModifierFlagControl, or NSEventModifierFlagShift; + The modifierFlags must be a bitwise OR of NSCommandKeyMask, NSAlternateKeyMask, NSControlKeyMask, or NSShiftKeyMask; Returns the hotkey registered. If registration failed, returns nil. */ -- (DDHotKey * _Nullable)registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags task:(DDHotKeyTask)task error:(NSError **)error; +- (DDHotKey *)registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags task:(DDHotKeyTask)task; /** See if a hotkey exists with the specified keycode and modifier flags. @@ -89,8 +87,7 @@ typedef void (^DDHotKeyTask)(NSEvent*); /** Returns a set of currently registered hotkeys **/ -- (NSSet *)registeredHotKeys; +- (NSSet *)registeredHotKeys; @end -NS_ASSUME_NONNULL_END diff --git a/DDHotKeyCenter.m b/DDHotKeyCenter.m index 217f326..e2d5997 100644 --- a/DDHotKeyCenter.m +++ b/DDHotKeyCenter.m @@ -48,7 +48,6 @@ + (instancetype)hotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInte - (void) dealloc { [[DDHotKeyCenter sharedHotKeyCenter] unregisterHotKey:self]; - [super dealloc]; } - (NSUInteger)hash { @@ -66,10 +65,10 @@ - (BOOL)isEqual:(id)object { - (NSString *)description { NSMutableArray *bits = [NSMutableArray array]; - if ((_modifierFlags & NSEventModifierFlagControl) > 0) { [bits addObject:@"NSEventModifierFlagControl"]; } - if ((_modifierFlags & NSEventModifierFlagCommand) > 0) { [bits addObject:@"NSEventModifierFlagCommand"]; } - if ((_modifierFlags & NSEventModifierFlagShift) > 0) { [bits addObject:@"NSEventModifierFlagShift"]; } - if ((_modifierFlags & NSEventModifierFlagOption) > 0) { [bits addObject:@"NSEventModifierFlagOption"]; } + if ((_modifierFlags & NSControlKeyMask) > 0) { [bits addObject:@"NSControlKeyMask"]; } + if ((_modifierFlags & NSCommandKeyMask) > 0) { [bits addObject:@"NSCommandKeyMask"]; } + if ((_modifierFlags & NSShiftKeyMask) > 0) { [bits addObject:@"NSShiftKeyMask"]; } + if ((_modifierFlags & NSAlternateKeyMask) > 0) { [bits addObject:@"NSAlternateKeyMask"]; } NSString *flags = [NSString stringWithFormat:@"(%@)", [bits componentsJoinedByString:@" | "]]; NSString *invokes = @"(block)"; @@ -143,10 +142,7 @@ - (BOOL)hasRegisteredHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NS }].count > 0; } -- (DDHotKey *)_registerHotKey:(DDHotKey *)hotKey withError:(NSError **)error { - - error = error ?: &(NSError * __autoreleasing){ nil }; - +- (DDHotKey *)_registerHotKey:(DDHotKey *)hotKey { if ([_registeredHotKeys containsObject:hotKey]) { return hotKey; } @@ -160,10 +156,7 @@ - (DDHotKey *)_registerHotKey:(DDHotKey *)hotKey withError:(NSError **)error { OSStatus err = RegisterEventHotKey([hotKey keyCode], flags, keyID, GetEventDispatcherTarget(), 0, &carbonHotKey); //error registering hot key - if (err != 0) { - *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil]; - return nil; - } + if (err != 0) { return nil; } NSValue *refValue = [NSValue valueWithPointer:carbonHotKey]; [hotKey setHotKeyRef:refValue]; @@ -175,8 +168,8 @@ - (DDHotKey *)_registerHotKey:(DDHotKey *)hotKey withError:(NSError **)error { return hotKey; } -- (DDHotKey *)registerHotKey:(DDHotKey *)hotKey withError:(NSError **)error { - return [self _registerHotKey:hotKey withError:error]; +- (DDHotKey *)registerHotKey:(DDHotKey *)hotKey { + return [self _registerHotKey:hotKey]; } - (void)unregisterHotKey:(DDHotKey *)hotKey { @@ -190,26 +183,21 @@ - (void)unregisterHotKey:(DDHotKey *)hotKey { [_registeredHotKeys removeObject:hotKey]; } -- (DDHotKey *)registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags task:(DDHotKeyTask)task error:(NSError **)error { - error = error ?: &(NSError * __autoreleasing){ nil }; - +- (DDHotKey *)registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags task:(DDHotKeyTask)task { //we can't add a new hotkey if something already has this combo - if ([self hasRegisteredHotKeyWithKeyCode:keyCode modifierFlags:flags]) { return nil; } + if ([self hasRegisteredHotKeyWithKeyCode:keyCode modifierFlags:flags]) { return NO; } DDHotKey *newHotKey = [[DDHotKey alloc] init]; [newHotKey _setTask:task]; [newHotKey _setKeyCode:keyCode]; [newHotKey _setModifierFlags:flags]; - return [self _registerHotKey:newHotKey withError:error]; + return [self _registerHotKey:newHotKey]; } -- (DDHotKey *)registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags target:(id)target action:(SEL)action object:(id)object error:(NSError **)error { - - error = error ?: &(NSError * __autoreleasing){ nil }; - +- (DDHotKey *)registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags target:(id)target action:(SEL)action object:(id)object { //we can't add a new hotkey if something already has this combo - if ([self hasRegisteredHotKeyWithKeyCode:keyCode modifierFlags:flags]) { return nil; } + if ([self hasRegisteredHotKeyWithKeyCode:keyCode modifierFlags:flags]) { return NO; } //build the hotkey object: DDHotKey *newHotKey = [[DDHotKey alloc] init]; @@ -218,7 +206,7 @@ - (DDHotKey *)registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(N [newHotKey _setObject:object]; [newHotKey _setKeyCode:keyCode]; [newHotKey _setModifierFlags:flags]; - return [self _registerHotKey:newHotKey withError:error]; + return [self _registerHotKey:newHotKey]; } - (void)unregisterHotKeysMatching:(BOOL(^)(DDHotKey *hotkey))matcher { @@ -278,7 +266,7 @@ OSStatus dd_hotKeyHandler(EventHandlerCallRef nextHandler, EventRef theEvent, vo DDHotKey *matchingHotKey = [matchingHotKeys anyObject]; NSEvent *event = [NSEvent eventWithEventRef:theEvent]; - NSEvent *keyEvent = [NSEvent keyEventWithType:NSEventTypeKeyUp + NSEvent *keyEvent = [NSEvent keyEventWithType:NSKeyUp location:[event locationInWindow] modifierFlags:[event modifierFlags] timestamp:[event timestamp] diff --git a/DDHotKeyUtilities.h b/DDHotKeyUtilities.h index ce7dd76..54b25a4 100644 --- a/DDHotKeyUtilities.h +++ b/DDHotKeyUtilities.h @@ -10,5 +10,5 @@ #import -extern NSString * _Nonnull DDStringFromKeyCode(unsigned short keyCode, NSUInteger modifiers); +extern NSString *DDStringFromKeyCode(unsigned short keyCode, NSUInteger modifiers); extern UInt32 DDCarbonModifierFlagsFromCocoaModifiers(NSUInteger flags); diff --git a/DDHotKeyUtilities.m b/DDHotKeyUtilities.m index 8298563..f298a43 100644 --- a/DDHotKeyUtilities.m +++ b/DDHotKeyUtilities.m @@ -10,7 +10,6 @@ #import "DDHotKeyUtilities.h" #import -#import static NSDictionary *_DDKeyCodeToCharacterMap(void); static NSDictionary *_DDKeyCodeToCharacterMap(void) { @@ -74,16 +73,16 @@ NSMutableString *final = [NSMutableString stringWithString:@""]; NSDictionary *characterMap = _DDKeyCodeToCharacterMap(); - if (modifiers & NSEventModifierFlagControl) { + if (modifiers & NSControlKeyMask) { [final appendString:[characterMap objectForKey:@(kVK_Control)]]; } - if (modifiers & NSEventModifierFlagOption) { + if (modifiers & NSAlternateKeyMask) { [final appendString:[characterMap objectForKey:@(kVK_Option)]]; } - if (modifiers & NSEventModifierFlagShift) { + if (modifiers & NSShiftKeyMask) { [final appendString:[characterMap objectForKey:@(kVK_Shift)]]; } - if (modifiers & NSEventModifierFlagCommand) { + if (modifiers & NSCommandKeyMask) { [final appendString:[characterMap objectForKey:@(kVK_Command)]]; } @@ -136,10 +135,10 @@ UInt32 DDCarbonModifierFlagsFromCocoaModifiers(NSUInteger flags) { UInt32 newFlags = 0; - if ((flags & NSEventModifierFlagControl) > 0) { newFlags |= controlKey; } - if ((flags & NSEventModifierFlagCommand) > 0) { newFlags |= cmdKey; } - if ((flags & NSEventModifierFlagShift) > 0) { newFlags |= shiftKey; } - if ((flags & NSEventModifierFlagOption) > 0) { newFlags |= optionKey; } - if ((flags & NSEventModifierFlagCapsLock) > 0) { newFlags |= alphaLock; } + if ((flags & NSControlKeyMask) > 0) { newFlags |= controlKey; } + if ((flags & NSCommandKeyMask) > 0) { newFlags |= cmdKey; } + if ((flags & NSShiftKeyMask) > 0) { newFlags |= shiftKey; } + if ((flags & NSAlternateKeyMask) > 0) { newFlags |= optionKey; } + if ((flags & NSAlphaShiftKeyMask) > 0) { newFlags |= alphaLock; } return newFlags; } diff --git a/TagWindowController.m b/TagWindowController.m index 7b07bc4..334e6d0 100644 --- a/TagWindowController.m +++ b/TagWindowController.m @@ -35,6 +35,10 @@ - (void)windowDidLoad //[self.okButton bind:NSValueBinding toObject:defaults withKeyPath:@"values.askForTagOnFinishButton" options:nil]; } +- (void)onWindowResignKey { + [self.window close]; +} + #pragma mark SRRecorderControlDelegate @end diff --git a/ThymeAppDelegate.m b/ThymeAppDelegate.m index 7912b9a..8bf591c 100644 --- a/ThymeAppDelegate.m +++ b/ThymeAppDelegate.m @@ -485,9 +485,10 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification startOnScreensaverEnd = NO; // Setup the hotkey center - DDHotKeyCenter *center = [[DDHotKeyCenter alloc] init]; - self.hotKeyCenter = center; - [center release]; + //DDHotKeyCenter *center = [[DDHotKeyCenter alloc] init]; + //self.hotKeyCenter = center; + //[center release]; + self.hotKeyCenter = [DDHotKeyCenter sharedHotKeyCenter]; // Setup Growl [GrowlApplicationBridge setGrowlDelegate:self];