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 <gedankenexperimenter@gmail.com>
f/keymap-cache-redesign
Michael Richters 4 years ago committed by Jesse Vincent
parent e5ba44a6da
commit 03a8872a95
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -21,27 +21,16 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
Key Redial::key_to_redial_;
Key Redial::last_key_; Key Redial::last_key_;
bool Redial::redial_held_ = false;
EventHandlerResult Redial::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) { EventHandlerResult Redial::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) {
if (keyToggledOn(key_state)) {
if (mapped_key == Key_Redial) { if (mapped_key == Key_Redial) {
if (keyToggledOff(key_state)) mapped_key = last_key_;
key_to_redial_ = last_key_; } else if (shouldRemember(mapped_key)) {
mapped_key = key_to_redial_;
redial_held_ = keyIsPressed(key_state);
return EventHandlerResult::OK;
}
if (keyToggledOn(key_state) && shouldRemember(mapped_key)) {
last_key_ = mapped_key; last_key_ = mapped_key;
if (!redial_held_)
key_to_redial_ = mapped_key;
} }
}
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }

@ -34,9 +34,7 @@ class Redial : public kaleidoscope::Plugin {
EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state); EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state);
private: private:
static Key key_to_redial_;
static Key last_key_; static Key last_key_;
static bool redial_held_;
}; };
} }

Loading…
Cancel
Save