Escape-OneShot: Change the key mapping instead of masking

We want to remove the use of key masking, so instead of masking the key when
escaping a OneShot, map it to `NoKey` instead, and continue doing so until
released. Which is effectively what masking did, but localized and simpler.

Doing this will make our cache have `NoKey` for the key until release, and we'll
avoid sending unintended Escape keycodes, without having to use the global
masking functions.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/886/head
Gergely Nagy 4 years ago
parent c797a95fb2
commit 9dfe51a238
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -23,18 +23,20 @@
namespace kaleidoscope {
namespace plugin {
bool EscapeOneShot::did_escape_;
EventHandlerResult EscapeOneShot::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t keyState) {
if (mapped_key != Key_Escape ||
(keyState & INJECTED) ||
!keyToggledOn(keyState))
if (mapped_key != Key_Escape || (keyState & INJECTED))
return EventHandlerResult::OK;
if (did_escape_)
mapped_key = Key_NoKey;
did_escape_ = !keyToggledOff(keyState);
if ((!::OneShot.isActive() || ::OneShot.isPressed()) && !::OneShot.isSticky()) {
return EventHandlerResult::OK;
}
Runtime.device().maskKey(key_addr);
::OneShot.cancel(true);
return EventHandlerResult::EVENT_CONSUMED;
}

@ -26,6 +26,9 @@ class EscapeOneShot : public kaleidoscope::Plugin {
EscapeOneShot(void) {}
EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t keyState);
private:
static bool did_escape_;
};
}
}

Loading…
Cancel
Save