diff options
author | Teddy Wing | 2018-09-21 12:10:21 +0200 |
---|---|---|
committer | Teddy Wing | 2018-09-21 12:10:21 +0200 |
commit | 342a2bebed69e57be8a827ff977d636ae9392924 (patch) | |
tree | 78706a21188abb7ce372f5da0461eb6a37c3e53d | |
parent | f6eb63bc9f55f76b5ad2d7496cbeb9afd0a5a0f4 (diff) | |
download | DomeKey-342a2bebed69e57be8a827ff977d636ae9392924.tar.bz2 |
HeadphoneKey: Start of mode handling (WIP)
A nearly-wroking stab at making mode handling work. Here we store the
current mode in the `HeadphoneKey` object. We try to save it when
getting a mode back from `c_run_key_action()`, and use it as a filter
when running `c_run_key_action()`.
I had discovered a problem, though. During debugging, I found that the
`_in_mode` ivar would end up pointing to the same thing as the current
`trigger`. Guessed that this had to do with it being a const pointer, so
I started to write some code to store the `Trigger` by value instead of
by reference in `HeadphoneKey` `_in_mode`.
At this point, a little frustrated, I thought about the overall problem
of mode handling again. It occurred to me that I no longer like this
idea of storing the current mode in the Objective-C object, as this
recent work has left a bad taste in my mouth. Instead, I'm going to try
moving mode handling into the Rust library, and make it opaque to the
Objective-C code. Hoping that that approach will be a more pleasant
endeavor.
-rw-r--r-- | DomeKey/HeadphoneKey.h | 3 | ||||
-rw-r--r-- | DomeKey/HeadphoneKey.m | 33 |
2 files changed, 25 insertions, 11 deletions
diff --git a/DomeKey/HeadphoneKey.h b/DomeKey/HeadphoneKey.h index cad78ab..9a8bab1 100644 --- a/DomeKey/HeadphoneKey.h +++ b/DomeKey/HeadphoneKey.h @@ -22,7 +22,8 @@ static const unsigned int TIMEOUT_MILLISECONDS = 1000; @interface HeadphoneKey : NSObject { NSArray *_mikeys; NSMutableArray *_key_buffer; - const Trigger *_in_mode; +// const Trigger *_in_mode; + Trigger *_in_mode; } - (void)handleDeadKey:(HeadphoneButton)button; diff --git a/DomeKey/HeadphoneKey.m b/DomeKey/HeadphoneKey.m index b55c171..47583a7 100644 --- a/DomeKey/HeadphoneKey.m +++ b/DomeKey/HeadphoneKey.m @@ -15,6 +15,7 @@ self = [super init]; if (self) { _key_buffer = [[NSMutableArray alloc] initWithCapacity:5]; + _in_mode = NULL; _mikeys = [DDHidAppleMikey allMikeys]; [_mikeys makeObjectsPerformSelector:@selector(setDelegate:) @@ -79,19 +80,31 @@ .length = count }; - const CKeyActionResult *result = c_run_key_action(trigger, NULL); - - if (result->kind && - *result->kind == ActionKind_Map) { - const char *c = result->action; - int i = 0; - while (*c) { - [KeyboardSimulator simpleKeyPressWithKey:result->action[i]]; - i++; - *c++; + const CKeyActionResult *result = c_run_key_action(trigger, _in_mode); + +// if ([self maybeSwitchToMode:result]) { +// goto cleanup; +// } + + if (result->kind) { + if (*result->kind == ActionKind_Map) { + const char *c = result->action; + int i = 0; + while (*c) { + [KeyboardSimulator simpleKeyPressWithKey:result->action[i]]; + i++; + *c++; + } + } + else if (*result->kind == ActionKind_Mode) { +// [self maybeSwitchToMode:result]; + _in_mode = malloc(sizeof(Trigger)) + *_in_mode = *result->in_mode; +// memcpy(_in_mode, result->in_mode, sizeof(const Trigger)); } } +cleanup: [_key_buffer removeAllObjects]; } |