Adapt Escape-OneShot plugin to KeyEvent handlers

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

@ -26,21 +26,20 @@ namespace plugin {
Key EscapeOneShot::cancel_oneshot_key_{Key_Escape}; Key EscapeOneShot::cancel_oneshot_key_{Key_Escape};
EventHandlerResult EscapeOneShot::onKeyswitchEvent( EventHandlerResult EscapeOneShot::onKeyEvent(KeyEvent &event) {
Key &key, KeyAddr key_addr, uint8_t key_state) {
// We only act on an escape key (or `cancel_oneshot_key_`, if that has been // 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 // 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 // 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. // sticky. Last, only if there are no OneShot keys currently being held.
if (key == cancel_oneshot_key_ && if (event.key == cancel_oneshot_key_ &&
keyToggledOn(key_state) && keyToggledOn(event.state) &&
!(key_state & INJECTED) && (event.state & INJECTED) == 0 &&
::OneShot.isActive()) { ::OneShot.isActive()) {
// Cancel all OneShot keys // Cancel all OneShot keys
::OneShot.cancel(true); ::OneShot.cancel(true);
// Change the cancellation key to a blank key, and signal that event // Change the cancellation key to a blank key, and signal that event
// processing is complete. // processing is complete.
key = Key_NoKey; event.key = Key_NoKey;
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }

@ -27,7 +27,7 @@ class EscapeOneShot : public kaleidoscope::Plugin {
public: public:
EscapeOneShot(void) {} EscapeOneShot(void) {}
EventHandlerResult onKeyswitchEvent(Key &key, KeyAddr key_addr, uint8_t key_state); EventHandlerResult onKeyEvent(KeyEvent &event);
void setCancelKey(Key cancel_key) { void setCancelKey(Key cancel_key) {
cancel_oneshot_key_ = cancel_key; cancel_oneshot_key_ = cancel_key;

Loading…
Cancel
Save