Skip to content

Commit 4473c4e

Browse files
committed
Merge remote-tracking branch 'upstream/master' into appear-disabled-while-paused
2 parents 8421e1b + 1d5a33a commit 4473c4e

21 files changed

+713
-221
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "ShortcutRecorder"]
22
path = ShortcutRecorder
3-
url = git://github.com/joaomoreno/ShortcutRecorder.git
3+
url = git@github.com:plopp/ShortcutRecorder.git

DDHotKeyCenter.h

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
DDHotKey -- DDHotKeyCenter.h
33
4-
Copyright (c) 2010, Dave DeLong <http://www.davedelong.com>
4+
Copyright (c) Dave DeLong <http://www.davedelong.com>
55
66
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
77
@@ -10,52 +10,87 @@
1010

1111
#import <Cocoa/Cocoa.h>
1212

13-
#define BUILD_FOR_SNOWLEOPARD (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
13+
NS_ASSUME_NONNULL_BEGIN
1414

15-
#if BUILD_FOR_SNOWLEOPARD
1615
//a convenient typedef for the required signature of a hotkey block callback
1716
typedef void (^DDHotKeyTask)(NSEvent*);
18-
#endif
1917

20-
@interface DDHotKeyCenter : NSObject {
18+
@interface DDHotKey : NSObject
2119

22-
}
20+
// creates a new hotkey but does not register it
21+
+ (instancetype)hotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags task:(DDHotKeyTask _Nullable)task;
22+
23+
@property (nonatomic, assign, readonly, nullable) id target;
24+
@property (nonatomic, readonly, nullable) SEL action;
25+
@property (nonatomic, strong, readonly, nullable) id object;
26+
@property (nonatomic, copy, readonly, nullable) DDHotKeyTask task;
27+
28+
@property (nonatomic, readonly) unsigned short keyCode;
29+
@property (nonatomic, readonly) NSUInteger modifierFlags;
30+
31+
@end
32+
33+
#pragma mark -
34+
35+
@interface DDHotKeyCenter : NSObject
36+
37+
@property (class, readonly, nonnull) DDHotKeyCenter *sharedHotKeyCenter;
38+
39+
/**
40+
Register a hotkey.
41+
*/
42+
- (DDHotKey * _Nullable)registerHotKey:(DDHotKey *)hotKey withError:(NSError **)error;
2343

2444
/**
2545
Register a target/action hotkey.
26-
The modifierFlags must be a bitwise OR of NSCommandKeyMask, NSAlternateKeyMask, NSControlKeyMask, or NSShiftKeyMask;
27-
Returns YES if the hotkey was registered; NO otherwise.
46+
The modifierFlags must be a bitwise OR of NSEventModifierFlagCommand, NSEventModifierFlagOption, NSEventModifierFlagControl, or NSEventModifierFlagShift;
47+
Returns the hotkey registered. If registration failed, returns nil.
2848
*/
29-
- (BOOL) registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags target:(id)target action:(SEL)action object:(id)object;
49+
- (DDHotKey * _Nullable)registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags target:(id)target action:(SEL)action object:(id)object error:(NSError **)error;
3050

31-
#if BUILD_FOR_SNOWLEOPARD
3251
/**
3352
Register a block callback hotkey.
34-
The modifierFlags must be a bitwise OR of NSCommandKeyMask, NSAlternateKeyMask, NSControlKeyMask, or NSShiftKeyMask;
35-
Returns YES if the hotkey was registered; NO otherwise.
53+
The modifierFlags must be a bitwise OR of NSEventModifierFlagCommand, NSEventModifierFlagOption, NSEventModifierFlagControl, or NSEventModifierFlagShift;
54+
Returns the hotkey registered. If registration failed, returns nil.
3655
*/
37-
- (BOOL) registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags task:(DDHotKeyTask)task;
38-
#endif
56+
- (DDHotKey * _Nullable)registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags task:(DDHotKeyTask)task error:(NSError **)error;
3957

4058
/**
4159
See if a hotkey exists with the specified keycode and modifier flags.
42-
NOTE: this will only check among hotkeys you have explicitly registered. This does not check all globally registered hotkeys.
60+
NOTE: this will only check among hotkeys you have explicitly registered with DDHotKeyCenter. This does not check all globally registered hotkeys.
4361
*/
44-
- (BOOL) hasRegisteredHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags;
62+
- (BOOL)hasRegisteredHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags;
63+
64+
/**
65+
Unregister a specific hotkey
66+
*/
67+
- (void)unregisterHotKey:(DDHotKey *)hotKey;
68+
69+
/**
70+
Unregister all hotkeys
71+
*/
72+
- (void)unregisterAllHotKeys;
4573

4674
/**
4775
Unregister all hotkeys with a specific target
4876
*/
49-
- (void) unregisterHotKeysWithTarget:(id)target;
77+
- (void)unregisterHotKeysWithTarget:(id)target;
5078

5179
/**
5280
Unregister all hotkeys with a specific target and action
5381
*/
54-
- (void) unregisterHotKeysWithTarget:(id)target action:(SEL)action;
82+
- (void)unregisterHotKeysWithTarget:(id)target action:(SEL)action;
5583

5684
/**
5785
Unregister a hotkey with a specific keycode and modifier flags
5886
*/
59-
- (void) unregisterHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags;
87+
- (void)unregisterHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags;
88+
89+
/**
90+
Returns a set of currently registered hotkeys
91+
**/
92+
- (NSSet<DDHotKey *> *)registeredHotKeys;
6093

6194
@end
95+
96+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)