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++) {
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;

@ -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

@ -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

Loading…
Cancel
Save