diff --git a/app/dts/behaviors/sticky_key.dtsi b/app/dts/behaviors/sticky_key.dtsi index 64032085..886d35b7 100644 --- a/app/dts/behaviors/sticky_key.dtsi +++ b/app/dts/behaviors/sticky_key.dtsi @@ -12,6 +12,7 @@ #binding-cells = <1>; release-after-ms = <1000>; bindings = <&kp>; + ignore-modifiers; }; /omit-if-no-ref/ sl: behavior_sticky_layer { compatible = "zmk,behavior-sticky-key"; diff --git a/app/dts/bindings/behaviors/zmk,behavior-sticky-key.yaml b/app/dts/bindings/behaviors/zmk,behavior-sticky-key.yaml index 1c2ab7f3..c04883c0 100644 --- a/app/dts/bindings/behaviors/zmk,behavior-sticky-key.yaml +++ b/app/dts/bindings/behaviors/zmk,behavior-sticky-key.yaml @@ -15,3 +15,5 @@ properties: type: int quick-release: type: boolean + ignore-modifiers: + type: boolean diff --git a/app/src/behaviors/behavior_sticky_key.c b/app/src/behaviors/behavior_sticky_key.c index 825ec7a6..3c75a7a3 100644 --- a/app/src/behaviors/behavior_sticky_key.c +++ b/app/src/behaviors/behavior_sticky_key.c @@ -31,6 +31,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); struct behavior_sticky_key_config { uint32_t release_after_ms; bool quick_release; + bool ignore_modifiers; struct zmk_behavior_binding behavior; }; @@ -201,7 +202,7 @@ static int sticky_key_keycode_state_changed_listener(const zmk_event_t *eh) { continue; } - // If events were queued, the timer event may be queued late or not at all. + // If this event was queued, the timer may be triggered late or not at all. // Release the sticky key if the timer should've run out in the meantime. if (sticky_key->release_at != 0 && ev->timestamp > sticky_key->release_at) { stop_timer(sticky_key); @@ -210,6 +211,11 @@ static int sticky_key_keycode_state_changed_listener(const zmk_event_t *eh) { } if (ev->state) { // key down + if (sticky_key->config->ignore_modifiers && is_mod(ev->usage_page, ev->keycode)) { + // ignore modifier key press so we can stack sticky keys and combine with other + // modifiers + continue; + } if (sticky_key->modified_key_usage_page != 0 || sticky_key->modified_key_keycode != 0) { // this sticky key is already in use for a keycode continue; @@ -270,6 +276,7 @@ static struct behavior_sticky_key_data behavior_sticky_key_data; static struct behavior_sticky_key_config behavior_sticky_key_config_##n = { \ .behavior = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ .release_after_ms = DT_INST_PROP(n, release_after_ms), \ + .ignore_modifiers = DT_INST_PROP(n, ignore_modifiers), \ .quick_release = DT_INST_PROP(n, quick_release), \ }; \ DEVICE_DT_INST_DEFINE(n, behavior_sticky_key_init, device_pm_control_nop, \ diff --git a/app/tests/sticky-keys/10-callum-mods/events.patterns b/app/tests/sticky-keys/10-callum-mods/events.patterns new file mode 100644 index 00000000..b1342af4 --- /dev/null +++ b/app/tests/sticky-keys/10-callum-mods/events.patterns @@ -0,0 +1 @@ +s/.*hid_listener_keycode_//p diff --git a/app/tests/sticky-keys/10-callum-mods/keycode_events.snapshot b/app/tests/sticky-keys/10-callum-mods/keycode_events.snapshot new file mode 100644 index 00000000..fd2217a5 --- /dev/null +++ b/app/tests/sticky-keys/10-callum-mods/keycode_events.snapshot @@ -0,0 +1,8 @@ +pressed: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00 +pressed: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0xe0 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 +released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 diff --git a/app/tests/sticky-keys/10-callum-mods/native_posix.keymap b/app/tests/sticky-keys/10-callum-mods/native_posix.keymap new file mode 100644 index 00000000..9febf08c --- /dev/null +++ b/app/tests/sticky-keys/10-callum-mods/native_posix.keymap @@ -0,0 +1,43 @@ +#include +#include +#include + +/ { + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &sk E &sl 1 + &kp A &kp B>; + }; + + lower_layer { + bindings = < + &sk LEFT_CONTROL &kp X + &sk LEFT_SHIFT &kp Z>; + }; + }; +}; + +&kscan { + events = < + /* press sl lower_layer */ + ZMK_MOCK_PRESS(0,1,10) + /* tap sk LEFT_CONTROL */ + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + /* tap sk LEFT_SHIFT */ + ZMK_MOCK_PRESS(1,0,10) + ZMK_MOCK_RELEASE(1,0,10) + /* release sl lower_layer */ + ZMK_MOCK_RELEASE(0,1,10) + /* tap A (with left control and left shift enabled) */ + ZMK_MOCK_PRESS(1,0,10) + ZMK_MOCK_RELEASE(1,0,10) + /* tap A (no sticky keys anymore) */ + ZMK_MOCK_PRESS(1,0,10) + ZMK_MOCK_RELEASE(1,0,10) + >; +}; \ No newline at end of file