From 03a8872a954b8f75257c8f16fe364287cafd3de1 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Mon, 16 Nov 2020 17:02:27 -0600 Subject: [PATCH] Adapt Redial to active keys cache Because the active key for redial was getting cached as the key being pressed, Redial would only ever see a key toggled on event for `Key_Redial`. It would then set `redial_held_` to `true`, but it would never get set to `false` on the key's release. This change both fixes it and simplifies the plugin as it is adapted to the active keys cache by doing away with unnecessary state variables, including `redial_held_`. Signed-off-by: Michael Richters --- src/kaleidoscope/plugin/Redial.cpp | 23 ++++++----------------- src/kaleidoscope/plugin/Redial.h | 2 -- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/kaleidoscope/plugin/Redial.cpp b/src/kaleidoscope/plugin/Redial.cpp index 5b2e0263..886d8d70 100644 --- a/src/kaleidoscope/plugin/Redial.cpp +++ b/src/kaleidoscope/plugin/Redial.cpp @@ -21,27 +21,16 @@ namespace kaleidoscope { namespace plugin { -Key Redial::key_to_redial_; Key Redial::last_key_; -bool Redial::redial_held_ = false; EventHandlerResult Redial::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) { - if (mapped_key == Key_Redial) { - if (keyToggledOff(key_state)) - key_to_redial_ = last_key_; - - mapped_key = key_to_redial_; - redial_held_ = keyIsPressed(key_state); - - return EventHandlerResult::OK; + if (keyToggledOn(key_state)) { + if (mapped_key == Key_Redial) { + mapped_key = last_key_; + } else if (shouldRemember(mapped_key)) { + last_key_ = mapped_key; + } } - - if (keyToggledOn(key_state) && shouldRemember(mapped_key)) { - last_key_ = mapped_key; - if (!redial_held_) - key_to_redial_ = mapped_key; - } - return EventHandlerResult::OK; } diff --git a/src/kaleidoscope/plugin/Redial.h b/src/kaleidoscope/plugin/Redial.h index ad483e59..5987e079 100644 --- a/src/kaleidoscope/plugin/Redial.h +++ b/src/kaleidoscope/plugin/Redial.h @@ -34,9 +34,7 @@ class Redial : public kaleidoscope::Plugin { EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state); private: - static Key key_to_redial_; static Key last_key_; - static bool redial_held_; }; }