PrefixLayer: use onAddToReport instead

Signed-off-by: iliana etaoin <iliana@buttslol.net>
pull/1187/head
iliana etaoin 3 years ago
parent a960f5a0cb
commit 06aebb42b9

@ -45,22 +45,21 @@ EventHandlerResult PrefixLayer::onKeyEvent(KeyEvent &event) {
for (uint8_t i = 0; i < prefix_layers_length_; i++) { for (uint8_t i = 0; i < prefix_layers_length_; i++) {
if (Layer.isActive(prefix_layers_[i].layer)) { if (Layer.isActive(prefix_layers_[i].layer)) {
clear_modifiers_ = true; current_prefix_ = prefix_layers_[i].prefix;
Runtime.handleKeyEvent(KeyEvent{KeyAddr::none(), IS_PRESSED | INJECTED, prefix_layers_[i].prefix}); Runtime.handleKeyEvent(KeyEvent{KeyAddr::none(), IS_PRESSED | INJECTED, current_prefix_});
Runtime.handleKeyEvent(KeyEvent{KeyAddr::none(), WAS_PRESSED | INJECTED, prefix_layers_[i].prefix}); Runtime.handleKeyEvent(KeyEvent{KeyAddr::none(), WAS_PRESSED | INJECTED, current_prefix_});
clear_modifiers_ = false; current_prefix_ = Key_NoKey;
} }
} }
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
EventHandlerResult PrefixLayer::beforeReportingState(const KeyEvent &event) { EventHandlerResult PrefixLayer::onAddToReport(Key key) {
if (clear_modifiers_) { if (current_prefix_ != Key_NoKey) {
for (uint8_t i = HID_KEYBOARD_FIRST_MODIFIER; i <= HID_KEYBOARD_LAST_MODIFIER; i++) { if (current_prefix_ != key) {
Runtime.hid().keyboard().releaseKey(Key(i, KEY_FLAGS)); return EventHandlerResult::ABORT;
} }
Runtime.hid().keyboard().pressModifiers(event.key);
} }
return EventHandlerResult::OK; return EventHandlerResult::OK;

@ -31,7 +31,7 @@ namespace plugin {
class PrefixLayer : public Plugin { class PrefixLayer : public Plugin {
public: public:
EventHandlerResult onKeyEvent(KeyEvent &event); EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult beforeReportingState(const KeyEvent &event); EventHandlerResult onAddToReport(Key key);
struct Entry { struct Entry {
uint8_t layer; uint8_t layer;
@ -48,7 +48,7 @@ class PrefixLayer : public Plugin {
private: private:
const Entry *prefix_layers_ PROGMEM = {}; const Entry *prefix_layers_ PROGMEM = {};
uint8_t prefix_layers_length_ = 0; uint8_t prefix_layers_length_ = 0;
bool clear_modifiers_ = false; Key current_prefix_ = Key_NoKey;
}; };
} // namespace plugin } // namespace plugin

@ -102,6 +102,8 @@ PRESS H
RUN 1 cycle RUN 1 cycle
EXPECT keyboard-report Key_LCtrl Key_B # press B, Ctrl held EXPECT keyboard-report Key_LCtrl Key_B # press B, Ctrl held
EXPECT keyboard-report Key_LCtrl # release 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 EXPECT keyboard-report Key_LCtrl Key_H # press H
RUN 4 ms RUN 4 ms
@ -137,6 +139,8 @@ PRESS H
RUN 1 cycle RUN 1 cycle
EXPECT keyboard-report Key_LCtrl Key_B # press B, Ctrl held EXPECT keyboard-report Key_LCtrl Key_B # press B, Ctrl held
EXPECT keyboard-report Key_LCtrl # release 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 EXPECT keyboard-report Key_LCtrl Key_H # press H
RUN 4 ms RUN 4 ms
@ -170,10 +174,10 @@ EXPECT no keyboard-report # no report after pressing PREFIX_B
RUN 4 ms RUN 4 ms
PRESS H PRESS H
RUN 1 cycle RUN 1 cycle
EXPECT keyboard-report Key_LShift Key_LCtrl # press Ctrl EXPECT keyboard-report Key_LCtrl # release pressed Shift and press Ctrl
EXPECT keyboard-report Key_LCtrl # release pressed shift
EXPECT keyboard-report Key_LCtrl Key_B # press B, Ctrl held EXPECT keyboard-report Key_LCtrl Key_B # press B, Ctrl held
EXPECT keyboard-report Key_LCtrl # release 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 # restoring pressed Shift
EXPECT keyboard-report Key_LShift Key_H # press H EXPECT keyboard-report Key_LShift Key_H # press H
@ -208,10 +212,10 @@ EXPECT keyboard-report Key_LShift # press Shift
RUN 4 ms RUN 4 ms
PRESS H PRESS H
RUN 1 cycle RUN 1 cycle
EXPECT keyboard-report Key_LShift Key_LCtrl # press Ctrl EXPECT keyboard-report Key_LCtrl # release pressed Shift and press Ctrl
EXPECT keyboard-report Key_LCtrl # release pressed shift
EXPECT keyboard-report Key_LCtrl Key_B # press B, Ctrl held EXPECT keyboard-report Key_LCtrl Key_B # press B, Ctrl held
EXPECT keyboard-report Key_LCtrl # release 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 # restoring pressed Shift
EXPECT keyboard-report Key_LShift Key_H # press H EXPECT keyboard-report Key_LShift Key_H # press H

Loading…
Cancel
Save