diff options
-rw-r--r-- | DomeKey/HeadphoneKey.h | 3 | ||||
-rw-r--r-- | DomeKey/HeadphoneKey.m | 14 | ||||
-rw-r--r-- | DomeKey/Mappings.h | 9 | ||||
-rw-r--r-- | DomeKey/Mappings.m | 32 | ||||
-rw-r--r-- | DomeKey/main.m | 2 |
5 files changed, 44 insertions, 16 deletions
diff --git a/DomeKey/HeadphoneKey.h b/DomeKey/HeadphoneKey.h index 1d12e10..4496785 100644 --- a/DomeKey/HeadphoneKey.h +++ b/DomeKey/HeadphoneKey.h @@ -9,6 +9,7 @@ #import <Foundation/Foundation.h> #import <DDHidLib/DDHidAppleMikey.h> +#import "Mappings.h" #import "Sounds.h" #import "dome_key_map.h" #import "log.h" @@ -23,7 +24,7 @@ static const Milliseconds TIMEOUT_DEFAULT = 500; @interface HeadphoneKey : NSObject { NSArray *_mikeys; NSMutableArray *_key_buffer; - State *_state; + Mappings *_mappings; Milliseconds _timeout; } diff --git a/DomeKey/HeadphoneKey.m b/DomeKey/HeadphoneKey.m index aec9598..a16dbc0 100644 --- a/DomeKey/HeadphoneKey.m +++ b/DomeKey/HeadphoneKey.m @@ -18,7 +18,10 @@ static BOOL _play_audio; self = [super init]; if (self) { _key_buffer = [[NSMutableArray alloc] initWithCapacity:5]; - _state = dome_key_state_new(); + + _mappings = [[Mappings alloc] init]; + [_mappings reloadMappings]; + [_mappings observeReloadNotification]; // Should never be used. We initialise it just in case, but the real // default should always come from a `Config`, set in the Rust library. @@ -26,8 +29,6 @@ static BOOL _play_audio; _play_audio = NO; - dome_key_state_load_map_group(_state); - _mikeys = [DDHidAppleMikey allMikeys]; [_mikeys makeObjectsPerformSelector:@selector(setDelegate:) withObject:self]; @@ -52,11 +53,6 @@ static BOOL _play_audio; return self; } -- (void)dealloc -{ - dome_key_state_free(_state); -} - - (void)ddhidAppleMikey:(DDHidAppleMikey *)mikey press:(unsigned)usageId upOrDown:(BOOL)upOrDown @@ -110,7 +106,7 @@ static BOOL _play_audio; .length = count }; - dome_key_run_key_action(_state, trigger, on_mode_change); + dome_key_run_key_action([_mappings state], trigger, on_mode_change); [_key_buffer removeAllObjects]; } diff --git a/DomeKey/Mappings.h b/DomeKey/Mappings.h index 136dc87..acd3546 100644 --- a/DomeKey/Mappings.h +++ b/DomeKey/Mappings.h @@ -9,9 +9,16 @@ #import <Foundation/Foundation.h> #include <notify.h> +#import "dome_key_map.h" + @interface Mappings : NSObject -+ (void)observeReloadNotification; +- (State *)state; + +- (void)observeReloadNotification; + +- (void)reloadMappings; ++ (void)reloadMappings; + (uint32_t)dispatchReload; @end diff --git a/DomeKey/Mappings.m b/DomeKey/Mappings.m index 62098fe..f130ba6 100644 --- a/DomeKey/Mappings.m +++ b/DomeKey/Mappings.m @@ -12,9 +12,21 @@ static const CFStringRef CFNOTIFICATION_NAME_RELOAD = CFSTR(NOTIFICATION_NAME_RELOAD); +static State *_state; + @implementation Mappings -+ (void)observeReloadNotification +- (void)dealloc +{ + dome_key_state_free(_state); +} + +- (State *)state +{ + return _state; +} + +- (void)observeReloadNotification { CFNotificationCenterRef center = CFNotificationCenterGetDarwinNotifyCenter(); @@ -39,15 +51,29 @@ void reload_mappings( ) { if (CFStringCompare(name, CFNOTIFICATION_NAME_RELOAD, 0) == kCFCompareEqualTo) { - // Reload mappings - NSLog(@"TODO: reload mappings"); + // TODO: Mappings reloaded message + + [Mappings reloadMappings]; } } +- (void)reloadMappings +{ + [Mappings reloadMappings]; +} + ++ (void)reloadMappings +{ + dome_key_state_free(_state); + _state = dome_key_state_new(); + dome_key_state_load_map_group(_state); +} + + (uint32_t)dispatchReload { uint32_t status = notify_post(NOTIFICATION_NAME_RELOAD); if (status != 0) { + // TODO: print to stderr // Notification failed NSLog(@"Reload notification failed"); } diff --git a/DomeKey/main.m b/DomeKey/main.m index 0b33a55..7c2f1c7 100644 --- a/DomeKey/main.m +++ b/DomeKey/main.m @@ -50,8 +50,6 @@ int main(int argc, const char * argv[]) { // insert code here... NSLog(@"Hello, World!"); - [Mappings observeReloadNotification]; - [NSApp run]; } } else if (config->args.version) { |