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/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/PreferencesWindowController.h b/PreferencesWindowController.h index eb7439c..0173d34 100644 --- a/PreferencesWindowController.h +++ b/PreferencesWindowController.h @@ -16,6 +16,7 @@ NSButton *pauseOnSleepButton; NSButton *pauseOnScreensaverButton; NSButton *askForTagOnFinishButton; + NSButton *appearDisabledWhilePausedButton; } @property (nonatomic, retain) IBOutlet SRRecorderControl *startPauseShortcutRecorder; @@ -24,5 +25,6 @@ @property (nonatomic, retain) IBOutlet NSButton *pauseOnSleepButton; @property (nonatomic, retain) IBOutlet NSButton *pauseOnScreensaverButton; @property (nonatomic, retain) IBOutlet NSButton *askForTagOnFinishButton; +@property (nonatomic, retain) IBOutlet NSButton *appearDisabledWhilePausedButton; @end diff --git a/PreferencesWindowController.m b/PreferencesWindowController.m index 353d73a..ecdff45 100644 --- a/PreferencesWindowController.m +++ b/PreferencesWindowController.m @@ -20,6 +20,7 @@ @implementation PreferencesWindowController @synthesize pauseOnSleepButton; @synthesize pauseOnScreensaverButton; @synthesize askForTagOnFinishButton; +@synthesize appearDisabledWhilePausedButton; - (id)initWithWindow:(NSWindow *)window { @@ -44,6 +45,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.askForTagOnFinishButton bind:NSValueBinding toObject:defaults withKeyPath:@"values.askForTagOnFinishButton" options:nil]; + [self.appearDisabledWhilePausedButton bind:NSValueBinding toObject:defaults withKeyPath:@"values.appearDisabledWhilePaused" options:nil]; [self.startPauseShortcutRecorder clearButtonRect]; diff --git a/PreferencesWindowController.xib b/PreferencesWindowController.xib index e7148b1..6a007b5 100644 --- a/PreferencesWindowController.xib +++ b/PreferencesWindowController.xib @@ -1,13 +1,13 @@ - + - - + + @@ -18,24 +18,24 @@ - - + + - - + + - + - + - + @@ -44,7 +44,7 @@ - + @@ -53,11 +53,11 @@ - + - + @@ -66,7 +66,7 @@ - - - + 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 716f399..8bf591c 100644 --- a/ThymeAppDelegate.m +++ b/ThymeAppDelegate.m @@ -266,17 +266,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]; + } } } @@ -478,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];