mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-17 22:44:43 +00:00
- Remove GitHub Actions workflows and issue templates - Move legacy ShadowsocksX-NG project into Legacy/ - Remove git submodules; dependencies will use prebuilt binaries copied from upstream releases instead of building in-repo - Add ShadowsocksX-NG2/ directory for the new project - Update .gitignore paths for the new layout
45 lines
936 B
Objective-C
45 lines
936 B
Objective-C
#import "MASHotKey.h"
|
|
|
|
FourCharCode const MASHotKeySignature = 'MASS';
|
|
|
|
@interface MASHotKey ()
|
|
@property(assign) EventHotKeyRef hotKeyRef;
|
|
@property(assign) UInt32 carbonID;
|
|
@end
|
|
|
|
@implementation MASHotKey
|
|
|
|
- (instancetype) initWithShortcut: (MASShortcut*) shortcut
|
|
{
|
|
self = [super init];
|
|
|
|
static UInt32 CarbonHotKeyID = 0;
|
|
|
|
_carbonID = ++CarbonHotKeyID;
|
|
EventHotKeyID hotKeyID = { .signature = MASHotKeySignature, .id = _carbonID };
|
|
|
|
OSStatus status = RegisterEventHotKey([shortcut carbonKeyCode], [shortcut carbonFlags],
|
|
hotKeyID, GetEventDispatcherTarget(), 0, &_hotKeyRef);
|
|
|
|
if (status != noErr) {
|
|
return nil;
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
+ (instancetype) registeredHotKeyWithShortcut: (MASShortcut*) shortcut
|
|
{
|
|
return [[self alloc] initWithShortcut:shortcut];
|
|
}
|
|
|
|
- (void) dealloc
|
|
{
|
|
if (_hotKeyRef) {
|
|
UnregisterEventHotKey(_hotKeyRef);
|
|
_hotKeyRef = NULL;
|
|
}
|
|
}
|
|
|
|
@end
|