Adapt ShapeShifter plugin to KeyEvent handlers

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/1024/head
Michael Richters 4 years ago
parent 9352117e74
commit abba881257
No known key found for this signature in database
GPG Key ID: 1288FD13E4EEF0C0

@ -22,12 +22,10 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
const ShapeShifter::dictionary_t *ShapeShifter::dictionary = NULL; const ShapeShifter::dictionary_t *ShapeShifter::dictionary = nullptr;
EventHandlerResult ShapeShifter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) { EventHandlerResult ShapeShifter::onKeyEvent(KeyEvent &event) {
// Only act on keys that toggle on to prevent cycles (if the dictionary has if (dictionary == nullptr)
// two keys mapped to each other).
if (!keyToggledOn(key_state))
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (!dictionary) if (!dictionary)
@ -41,7 +39,7 @@ EventHandlerResult ShapeShifter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_a
orig = dictionary[i].original.readFromProgmem(); orig = dictionary[i].original.readFromProgmem();
i++; i++;
} while (orig != Key_NoKey && } while (orig != Key_NoKey &&
orig != mapped_key); orig != event.key);
i--; i--;
// If not found, bail out. // If not found, bail out.
@ -60,7 +58,7 @@ EventHandlerResult ShapeShifter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_a
repl = dictionary[i].replacement.readFromProgmem(); repl = dictionary[i].replacement.readFromProgmem();
// If found, handle the alternate key instead // If found, handle the alternate key instead
mapped_key = repl; event.key = repl;
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }

@ -32,7 +32,7 @@ class ShapeShifter : public kaleidoscope::Plugin {
static const dictionary_t *dictionary; static const dictionary_t *dictionary;
EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state); EventHandlerResult onKeyEvent(KeyEvent &event);
}; };
} }

Loading…
Cancel
Save