From 319f40e0c999e936d982bda2b900d8eb5a8ec91b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 24 Sep 2018 11:48:20 +0200 Subject: HeadphoneKey: Get switching to mode working * Update to latest dome-key-map, which handles in-mode internally using a `State` struct * Make a `State *` ivar to store the current dome-key-map state, and let it do the work of mode handling Currently doesn't handle exiting a mode, only entering one. But that last part actually does finally work now, yay! Still requires cleanup to get rid of the old `in_mode` handling. --- DomeKey/HeadphoneKey.h | 1 + DomeKey/HeadphoneKey.m | 7 ++++--- lib/dome-key-map | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/DomeKey/HeadphoneKey.h b/DomeKey/HeadphoneKey.h index 9a8bab1..3be7148 100644 --- a/DomeKey/HeadphoneKey.h +++ b/DomeKey/HeadphoneKey.h @@ -24,6 +24,7 @@ static const unsigned int TIMEOUT_MILLISECONDS = 1000; NSMutableArray *_key_buffer; // const Trigger *_in_mode; Trigger *_in_mode; + State *_state; } - (void)handleDeadKey:(HeadphoneButton)button; diff --git a/DomeKey/HeadphoneKey.m b/DomeKey/HeadphoneKey.m index 47583a7..44fd4e6 100644 --- a/DomeKey/HeadphoneKey.m +++ b/DomeKey/HeadphoneKey.m @@ -16,6 +16,7 @@ if (self) { _key_buffer = [[NSMutableArray alloc] initWithCapacity:5]; _in_mode = NULL; + _state = state_new(); _mikeys = [DDHidAppleMikey allMikeys]; [_mikeys makeObjectsPerformSelector:@selector(setDelegate:) @@ -80,7 +81,7 @@ .length = count }; - const CKeyActionResult *result = c_run_key_action(trigger, _in_mode); + const CKeyActionResult *result = c_run_key_action(_state, trigger, _in_mode); // if ([self maybeSwitchToMode:result]) { // goto cleanup; @@ -98,8 +99,8 @@ } else if (*result->kind == ActionKind_Mode) { // [self maybeSwitchToMode:result]; - _in_mode = malloc(sizeof(Trigger)) - *_in_mode = *result->in_mode; + // _in_mode = malloc(sizeof(Trigger)) + // *_in_mode = *result->in_mode; // memcpy(_in_mode, result->in_mode, sizeof(const Trigger)); } } diff --git a/lib/dome-key-map b/lib/dome-key-map index ce1eca3..882dfbe 160000 --- a/lib/dome-key-map +++ b/lib/dome-key-map @@ -1 +1 @@ -Subproject commit ce1eca32e2249a72692c6eb01052361d98af29c3 +Subproject commit 882dfbe6f0aad091613839841d2f54334e37b32e -- cgit v1.2.3