summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorokke <okke@formsma.nl>2022-01-26 20:42:14 +0100
committerPete Johanson <peter@peterjohanson.com>2022-02-07 14:45:07 -0500
commitcfd0d3d81af858dc08fb72f26b31a59a0938b51f (patch)
treebb53800c02e8b3835b31a1063528090fe422b4bd
parentc18c3d910653557db3c3e65b1440ee805f1d38cf (diff)
Behaviors: Add 'ignore-modifiers' option to sticky keys
To combine multiple sticky modifiers, the sticky keys must ignore other (sticky) modifier keypresses. This behavior is important for "callum-style mods", where all modifiers are sticky mods. Fixes #829
-rw-r--r--app/dts/behaviors/sticky_key.dtsi1
-rw-r--r--app/dts/bindings/behaviors/zmk,behavior-sticky-key.yaml2
-rw-r--r--app/src/behaviors/behavior_sticky_key.c9
-rw-r--r--app/tests/sticky-keys/10-callum-mods/events.patterns1
-rw-r--r--app/tests/sticky-keys/10-callum-mods/keycode_events.snapshot8
-rw-r--r--app/tests/sticky-keys/10-callum-mods/native_posix.keymap43
6 files changed, 63 insertions, 1 deletions
diff --git a/app/dts/behaviors/sticky_key.dtsi b/app/dts/behaviors/sticky_key.dtsi
index 6403208..886d35b 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 1c2ab7f..c04883c 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 825ec7a..3c75a7a 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 0000000..b1342af
--- /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 0000000..fd2217a
--- /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 0000000..9febf08
--- /dev/null
+++ b/app/tests/sticky-keys/10-callum-mods/native_posix.keymap
@@ -0,0 +1,43 @@
+#include <dt-bindings/zmk/keys.h>
+#include <behaviors.dtsi>
+#include <dt-bindings/zmk/kscan_mock.h>
+
+/ {
+ 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