From f0b3ad2b14dc02092c901800cced5227116b1d93 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 30 Jul 2017 10:54:22 +0200 Subject: [PATCH] Implement key masking for momentary layer keys The goal is to ignore key events from still-held keys in a situation where we just turned a layer off. Thus, if one holds a momentary layer key, then presses and holds another key, releases the layer key, we want to ignore the other held keys until they are released. This is accomplished by masking all held keys when a momentary layer has been turned off, and ignoring all masked key events in `handleKeyswitchEvent` until they are released, when we unmask them. This should address #150, but requires keyboardio/Kaleidoscope-Hardware-Model01#9. Signed-off-by: Gergely Nagy --- src/key_events.cpp | 8 ++++++++ src/layers.cpp | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/key_events.cpp b/src/key_events.cpp index 85f01679..7639cf5b 100644 --- a/src/key_events.cpp +++ b/src/key_events.cpp @@ -47,6 +47,14 @@ void handleKeyswitchEvent(Key mappedKey, byte row, byte col, uint8_t keyState) { if (!(keyState & INJECTED)) { mappedKey = Layer.lookup(row, col); } + + if (KeyboardHardware.isKeyMasked(row, col)) { + if (keyToggledOff(keyState)) { + KeyboardHardware.unMaskKey(row, col); + } + return; + } + for (byte i = 0; Kaleidoscope.eventHandlers[i] != NULL && i < HOOK_MAX; i++) { Kaleidoscope_::eventHandlerHook handler = Kaleidoscope.eventHandlers[i]; mappedKey = (*handler)(mappedKey, row, col, keyState); diff --git a/src/layers.cpp b/src/layers.cpp index cd48ed46..2d693175 100644 --- a/src/layers.cpp +++ b/src/layers.cpp @@ -28,6 +28,8 @@ static void handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) { } else { Layer.off(target); } + + KeyboardHardware.maskHeldKeys(); } // switch keymap and stay there