From 1ff9bb81c230f24a11c7f5d8f1e3813f39f0278b Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Tue, 6 Apr 2021 18:59:31 -0500 Subject: [PATCH] Adapt Escape-OneShot plugin to KeyEvent handlers Signed-off-by: Michael Richters --- .../src/kaleidoscope/plugin/Escape-OneShot.cpp | 11 +++++------ .../src/kaleidoscope/plugin/Escape-OneShot.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.cpp b/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.cpp index 2f60bf5d..1e6a9637 100644 --- a/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.cpp +++ b/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.cpp @@ -26,21 +26,20 @@ namespace plugin { Key EscapeOneShot::cancel_oneshot_key_{Key_Escape}; -EventHandlerResult EscapeOneShot::onKeyswitchEvent( - Key &key, KeyAddr key_addr, uint8_t key_state) { +EventHandlerResult EscapeOneShot::onKeyEvent(KeyEvent &event) { // We only act on an escape key (or `cancel_oneshot_key_`, if that has been // set) that has just been pressed, and not generated by some other // plugin. Also, only if at least one OneShot key is active and/or // sticky. Last, only if there are no OneShot keys currently being held. - if (key == cancel_oneshot_key_ && - keyToggledOn(key_state) && - !(key_state & INJECTED) && + if (event.key == cancel_oneshot_key_ && + keyToggledOn(event.state) && + (event.state & INJECTED) == 0 && ::OneShot.isActive()) { // Cancel all OneShot keys ::OneShot.cancel(true); // Change the cancellation key to a blank key, and signal that event // processing is complete. - key = Key_NoKey; + event.key = Key_NoKey; return EventHandlerResult::EVENT_CONSUMED; } diff --git a/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.h b/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.h index 4e0393cd..ce9af5b0 100644 --- a/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.h +++ b/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.h @@ -27,7 +27,7 @@ class EscapeOneShot : public kaleidoscope::Plugin { public: EscapeOneShot(void) {} - EventHandlerResult onKeyswitchEvent(Key &key, KeyAddr key_addr, uint8_t key_state); + EventHandlerResult onKeyEvent(KeyEvent &event); void setCancelKey(Key cancel_key) { cancel_oneshot_key_ = cancel_key;