Adapt Redial to keyboard state array

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
keyboard state array by doing away with unnecessary state variables, including
`redial_held_`.

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

@ -22,31 +22,20 @@
namespace kaleidoscope {
namespace plugin {
Key Redial::key_to_redial_;
Key Redial::last_key_;
bool Redial::redial_held_ = false;
EventHandlerResult Redial::onNameQuery() {
return ::Focus.sendName(F("Redial"));
}
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;
}

@ -35,9 +35,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_;
};
}

Loading…
Cancel
Save