diff --git a/plugins/Kaleidoscope-PrefixLayer/src/kaleidoscope/plugin/PrefixLayer.cpp b/plugins/Kaleidoscope-PrefixLayer/src/kaleidoscope/plugin/PrefixLayer.cpp index 5753771b..9c45014a 100644 --- a/plugins/Kaleidoscope-PrefixLayer/src/kaleidoscope/plugin/PrefixLayer.cpp +++ b/plugins/Kaleidoscope-PrefixLayer/src/kaleidoscope/plugin/PrefixLayer.cpp @@ -45,22 +45,21 @@ EventHandlerResult PrefixLayer::onKeyEvent(KeyEvent &event) { for (uint8_t i = 0; i < prefix_layers_length_; i++) { if (Layer.isActive(prefix_layers_[i].layer)) { - clear_modifiers_ = true; - Runtime.handleKeyEvent(KeyEvent{KeyAddr::none(), IS_PRESSED | INJECTED, prefix_layers_[i].prefix}); - Runtime.handleKeyEvent(KeyEvent{KeyAddr::none(), WAS_PRESSED | INJECTED, prefix_layers_[i].prefix}); - clear_modifiers_ = false; + current_prefix_ = prefix_layers_[i].prefix; + Runtime.handleKeyEvent(KeyEvent{KeyAddr::none(), IS_PRESSED | INJECTED, current_prefix_}); + Runtime.handleKeyEvent(KeyEvent{KeyAddr::none(), WAS_PRESSED | INJECTED, current_prefix_}); + current_prefix_ = Key_NoKey; } } return EventHandlerResult::OK; } -EventHandlerResult PrefixLayer::beforeReportingState(const KeyEvent &event) { - if (clear_modifiers_) { - for (uint8_t i = HID_KEYBOARD_FIRST_MODIFIER; i <= HID_KEYBOARD_LAST_MODIFIER; i++) { - Runtime.hid().keyboard().releaseKey(Key(i, KEY_FLAGS)); +EventHandlerResult PrefixLayer::onAddToReport(Key key) { + if (current_prefix_ != Key_NoKey) { + if (current_prefix_ != key) { + return EventHandlerResult::ABORT; } - Runtime.hid().keyboard().pressModifiers(event.key); } return EventHandlerResult::OK; diff --git a/plugins/Kaleidoscope-PrefixLayer/src/kaleidoscope/plugin/PrefixLayer.h b/plugins/Kaleidoscope-PrefixLayer/src/kaleidoscope/plugin/PrefixLayer.h index c87244e0..555a5691 100644 --- a/plugins/Kaleidoscope-PrefixLayer/src/kaleidoscope/plugin/PrefixLayer.h +++ b/plugins/Kaleidoscope-PrefixLayer/src/kaleidoscope/plugin/PrefixLayer.h @@ -31,7 +31,7 @@ namespace plugin { class PrefixLayer : public Plugin { public: EventHandlerResult onKeyEvent(KeyEvent &event); - EventHandlerResult beforeReportingState(const KeyEvent &event); + EventHandlerResult onAddToReport(Key key); struct Entry { uint8_t layer; @@ -48,7 +48,7 @@ class PrefixLayer : public Plugin { private: const Entry *prefix_layers_ PROGMEM = {}; uint8_t prefix_layers_length_ = 0; - bool clear_modifiers_ = false; + Key current_prefix_ = Key_NoKey; }; } // namespace plugin diff --git a/tests/plugins/PrefixLayer/basic/test.ktest b/tests/plugins/PrefixLayer/basic/test.ktest index bb201048..137f93fe 100644 --- a/tests/plugins/PrefixLayer/basic/test.ktest +++ b/tests/plugins/PrefixLayer/basic/test.ktest @@ -102,6 +102,8 @@ PRESS H RUN 1 cycle EXPECT keyboard-report Key_LCtrl Key_B # press B, Ctrl held EXPECT keyboard-report Key_LCtrl # release B, Ctrl held +EXPECT keyboard-report empty # release Ctrl +EXPECT keyboard-report Key_LCtrl # press Ctrl EXPECT keyboard-report Key_LCtrl Key_H # press H RUN 4 ms @@ -137,6 +139,8 @@ PRESS H RUN 1 cycle EXPECT keyboard-report Key_LCtrl Key_B # press B, Ctrl held EXPECT keyboard-report Key_LCtrl # release B, Ctrl held +EXPECT keyboard-report empty # release Ctrl +EXPECT keyboard-report Key_LCtrl # press Ctrl EXPECT keyboard-report Key_LCtrl Key_H # press H RUN 4 ms @@ -170,10 +174,10 @@ EXPECT no keyboard-report # no report after pressing PREFIX_B RUN 4 ms PRESS H RUN 1 cycle -EXPECT keyboard-report Key_LShift Key_LCtrl # press Ctrl -EXPECT keyboard-report Key_LCtrl # release pressed shift +EXPECT keyboard-report Key_LCtrl # release pressed Shift and press Ctrl EXPECT keyboard-report Key_LCtrl Key_B # press B, Ctrl held EXPECT keyboard-report Key_LCtrl # release B, Ctrl held +EXPECT keyboard-report empty # release Ctrl EXPECT keyboard-report Key_LShift # restoring pressed Shift EXPECT keyboard-report Key_LShift Key_H # press H @@ -208,10 +212,10 @@ EXPECT keyboard-report Key_LShift # press Shift RUN 4 ms PRESS H RUN 1 cycle -EXPECT keyboard-report Key_LShift Key_LCtrl # press Ctrl -EXPECT keyboard-report Key_LCtrl # release pressed shift +EXPECT keyboard-report Key_LCtrl # release pressed Shift and press Ctrl EXPECT keyboard-report Key_LCtrl Key_B # press B, Ctrl held EXPECT keyboard-report Key_LCtrl # release B, Ctrl held +EXPECT keyboard-report empty # release Ctrl EXPECT keyboard-report Key_LShift # restoring pressed Shift EXPECT keyboard-report Key_LShift Key_H # press H