From e48a6b659c6da4afd56f2c3e3fa56d291ebf80e4 Mon Sep 17 00:00:00 2001 From: Okke Formsma Date: Wed, 11 Nov 2020 16:40:13 +0100 Subject: fix momentary layer bug when top layer is not &trans Key release events released keys on the wrong layer if the 'top layer' was not &trans above the &mo key. base <&mo 1> layer 1 <&kp B> This was caused by overwriting `zmk_keymap_active_behavior_layer[position]` after the &mo key was handled. --- app/tests/momentary-layer/1-normal/events.patterns | 2 ++ .../1-normal/keycode_events.snapshot | 4 +++ .../momentary-layer/1-normal/native_posix.keymap | 32 ++++++++++++++++++ .../2-early-key-release/events.patterns | 2 ++ .../2-early-key-release/keycode_events.snapshot | 4 +++ .../2-early-key-release/native_posix.keymap | 32 ++++++++++++++++++ .../momentary-layer/3-covered/events.patterns | 3 ++ .../3-covered/keycode_events.snapshot | 2 ++ .../momentary-layer/3-covered/native_posix.keymap | 33 ++++++++++++++++++ app/tests/momentary-layer/4-nested/events.patterns | 3 ++ .../4-nested/keycode_events.snapshot | 6 ++++ .../momentary-layer/4-nested/native_posix.keymap | 39 ++++++++++++++++++++++ .../5-nested-early-key-release/events.patterns | 3 ++ .../keycode_events.snapshot | 6 ++++ .../5-nested-early-key-release/native_posix.keymap | 39 ++++++++++++++++++++++ app/tests/momentary-layer/behavior_keymap.dtsi | 12 ++----- .../early-key-release/events.patterns | 2 -- .../early-key-release/keycode_events.snapshot | 4 --- .../early-key-release/native_posix.keymap | 8 ----- app/tests/momentary-layer/normal/events.patterns | 2 -- .../momentary-layer/normal/keycode_events.snapshot | 4 --- .../momentary-layer/normal/native_posix.keymap | 8 ----- 22 files changed, 213 insertions(+), 37 deletions(-) create mode 100644 app/tests/momentary-layer/1-normal/events.patterns create mode 100644 app/tests/momentary-layer/1-normal/keycode_events.snapshot create mode 100644 app/tests/momentary-layer/1-normal/native_posix.keymap create mode 100644 app/tests/momentary-layer/2-early-key-release/events.patterns create mode 100644 app/tests/momentary-layer/2-early-key-release/keycode_events.snapshot create mode 100644 app/tests/momentary-layer/2-early-key-release/native_posix.keymap create mode 100644 app/tests/momentary-layer/3-covered/events.patterns create mode 100644 app/tests/momentary-layer/3-covered/keycode_events.snapshot create mode 100644 app/tests/momentary-layer/3-covered/native_posix.keymap create mode 100644 app/tests/momentary-layer/4-nested/events.patterns create mode 100644 app/tests/momentary-layer/4-nested/keycode_events.snapshot create mode 100644 app/tests/momentary-layer/4-nested/native_posix.keymap create mode 100644 app/tests/momentary-layer/5-nested-early-key-release/events.patterns create mode 100644 app/tests/momentary-layer/5-nested-early-key-release/keycode_events.snapshot create mode 100644 app/tests/momentary-layer/5-nested-early-key-release/native_posix.keymap delete mode 100644 app/tests/momentary-layer/early-key-release/events.patterns delete mode 100644 app/tests/momentary-layer/early-key-release/keycode_events.snapshot delete mode 100644 app/tests/momentary-layer/early-key-release/native_posix.keymap delete mode 100644 app/tests/momentary-layer/normal/events.patterns delete mode 100644 app/tests/momentary-layer/normal/keycode_events.snapshot delete mode 100644 app/tests/momentary-layer/normal/native_posix.keymap (limited to 'app/tests') diff --git a/app/tests/momentary-layer/1-normal/events.patterns b/app/tests/momentary-layer/1-normal/events.patterns new file mode 100644 index 0000000..bd7b488 --- /dev/null +++ b/app/tests/momentary-layer/1-normal/events.patterns @@ -0,0 +1,2 @@ +s/.*hid_listener_keycode/kp/p +s/.*mo_keymap_binding/mo/p \ No newline at end of file diff --git a/app/tests/momentary-layer/1-normal/keycode_events.snapshot b/app/tests/momentary-layer/1-normal/keycode_events.snapshot new file mode 100644 index 0000000..608ce09 --- /dev/null +++ b/app/tests/momentary-layer/1-normal/keycode_events.snapshot @@ -0,0 +1,4 @@ +mo_pressed: position 1 layer 1 +kp_pressed: usage_page 0x07 keycode 0x06 mods 0x00 +kp_released: usage_page 0x07 keycode 0x06 mods 0x00 +mo_released: position 1 layer 1 diff --git a/app/tests/momentary-layer/1-normal/native_posix.keymap b/app/tests/momentary-layer/1-normal/native_posix.keymap new file mode 100644 index 0000000..2fc24d2 --- /dev/null +++ b/app/tests/momentary-layer/1-normal/native_posix.keymap @@ -0,0 +1,32 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +/ { + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &kp B &mo 1 + &none &none>; + }; + + layer_1 { + bindings = < + &kp C &trans + &none &none>; + }; + }; +}; + +&kscan { + events = < + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + ZMK_MOCK_RELEASE(0,1,10) + >; +}; \ No newline at end of file diff --git a/app/tests/momentary-layer/2-early-key-release/events.patterns b/app/tests/momentary-layer/2-early-key-release/events.patterns new file mode 100644 index 0000000..bd7b488 --- /dev/null +++ b/app/tests/momentary-layer/2-early-key-release/events.patterns @@ -0,0 +1,2 @@ +s/.*hid_listener_keycode/kp/p +s/.*mo_keymap_binding/mo/p \ No newline at end of file diff --git a/app/tests/momentary-layer/2-early-key-release/keycode_events.snapshot b/app/tests/momentary-layer/2-early-key-release/keycode_events.snapshot new file mode 100644 index 0000000..82ebc67 --- /dev/null +++ b/app/tests/momentary-layer/2-early-key-release/keycode_events.snapshot @@ -0,0 +1,4 @@ +kp_pressed: usage_page 0x07 keycode 0x05 mods 0x00 +mo_pressed: position 1 layer 1 +kp_released: usage_page 0x07 keycode 0x05 mods 0x00 +mo_released: position 1 layer 1 diff --git a/app/tests/momentary-layer/2-early-key-release/native_posix.keymap b/app/tests/momentary-layer/2-early-key-release/native_posix.keymap new file mode 100644 index 0000000..9ffa5f6 --- /dev/null +++ b/app/tests/momentary-layer/2-early-key-release/native_posix.keymap @@ -0,0 +1,32 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +/ { + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &kp B &mo 1 + &none &none>; + }; + + layer_1 { + bindings = < + &kp C &none + &none &none>; + }; + }; +}; + +&kscan { + events = < + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,0,10) + ZMK_MOCK_RELEASE(0,1,10) + >; +}; \ No newline at end of file diff --git a/app/tests/momentary-layer/3-covered/events.patterns b/app/tests/momentary-layer/3-covered/events.patterns new file mode 100644 index 0000000..08b1e98 --- /dev/null +++ b/app/tests/momentary-layer/3-covered/events.patterns @@ -0,0 +1,3 @@ +s/.*hid_listener_keycode/kp/p +s/.*mo_keymap_binding/mo/p +s/.*keymap_position_state_changed/kp_st/p \ No newline at end of file diff --git a/app/tests/momentary-layer/3-covered/keycode_events.snapshot b/app/tests/momentary-layer/3-covered/keycode_events.snapshot new file mode 100644 index 0000000..87d1281 --- /dev/null +++ b/app/tests/momentary-layer/3-covered/keycode_events.snapshot @@ -0,0 +1,2 @@ +mo_pressed: position 1 layer 1 +mo_released: position 1 layer 1 diff --git a/app/tests/momentary-layer/3-covered/native_posix.keymap b/app/tests/momentary-layer/3-covered/native_posix.keymap new file mode 100644 index 0000000..2484d8b --- /dev/null +++ b/app/tests/momentary-layer/3-covered/native_posix.keymap @@ -0,0 +1,33 @@ +#include +#include +#include + +/* +this test verifies that the correct key is released when a layer is enabled "on top" +and the original key is "covered". +*/ +/ { + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &trans &mo 1 + &trans &trans>; + }; + + layer_1 { + bindings = < + &trans &kp A + &trans &trans>; + }; + }; +}; + +&kscan { + events = < + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_RELEASE(0,1,10) + >; +}; diff --git a/app/tests/momentary-layer/4-nested/events.patterns b/app/tests/momentary-layer/4-nested/events.patterns new file mode 100644 index 0000000..08b1e98 --- /dev/null +++ b/app/tests/momentary-layer/4-nested/events.patterns @@ -0,0 +1,3 @@ +s/.*hid_listener_keycode/kp/p +s/.*mo_keymap_binding/mo/p +s/.*keymap_position_state_changed/kp_st/p \ No newline at end of file diff --git a/app/tests/momentary-layer/4-nested/keycode_events.snapshot b/app/tests/momentary-layer/4-nested/keycode_events.snapshot new file mode 100644 index 0000000..f03e4d5 --- /dev/null +++ b/app/tests/momentary-layer/4-nested/keycode_events.snapshot @@ -0,0 +1,6 @@ +mo_pressed: position 1 layer 1 +mo_pressed: position 0 layer 2 +kp_pressed: usage_page 0x07 keycode 0x05 mods 0x00 +kp_released: usage_page 0x07 keycode 0x05 mods 0x00 +mo_released: position 0 layer 2 +mo_released: position 1 layer 1 diff --git a/app/tests/momentary-layer/4-nested/native_posix.keymap b/app/tests/momentary-layer/4-nested/native_posix.keymap new file mode 100644 index 0000000..0eb77d2 --- /dev/null +++ b/app/tests/momentary-layer/4-nested/native_posix.keymap @@ -0,0 +1,39 @@ +#include +#include +#include + +/ { + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &none &mo 1 + &none &none>; + }; + + layer_1 { + bindings = < + &mo 2 &none + &none &none>; + }; + + layer_2 { + bindings = < + &none &none + &kp B &none>; + }; + }; +}; + +&kscan { + events = < + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_PRESS(1,0,10) + ZMK_MOCK_RELEASE(1,0,10) + ZMK_MOCK_RELEASE(0,0,10) + ZMK_MOCK_RELEASE(0,1,10) + >; +}; \ No newline at end of file diff --git a/app/tests/momentary-layer/5-nested-early-key-release/events.patterns b/app/tests/momentary-layer/5-nested-early-key-release/events.patterns new file mode 100644 index 0000000..08b1e98 --- /dev/null +++ b/app/tests/momentary-layer/5-nested-early-key-release/events.patterns @@ -0,0 +1,3 @@ +s/.*hid_listener_keycode/kp/p +s/.*mo_keymap_binding/mo/p +s/.*keymap_position_state_changed/kp_st/p \ No newline at end of file diff --git a/app/tests/momentary-layer/5-nested-early-key-release/keycode_events.snapshot b/app/tests/momentary-layer/5-nested-early-key-release/keycode_events.snapshot new file mode 100644 index 0000000..15be601 --- /dev/null +++ b/app/tests/momentary-layer/5-nested-early-key-release/keycode_events.snapshot @@ -0,0 +1,6 @@ +mo_pressed: position 1 layer 1 +mo_pressed: position 0 layer 2 +kp_pressed: usage_page 0x07 keycode 0x05 mods 0x00 +mo_released: position 1 layer 1 +mo_released: position 0 layer 2 +kp_released: usage_page 0x07 keycode 0x05 mods 0x00 diff --git a/app/tests/momentary-layer/5-nested-early-key-release/native_posix.keymap b/app/tests/momentary-layer/5-nested-early-key-release/native_posix.keymap new file mode 100644 index 0000000..a67035b --- /dev/null +++ b/app/tests/momentary-layer/5-nested-early-key-release/native_posix.keymap @@ -0,0 +1,39 @@ +#include +#include +#include + +/ { + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &none &mo 1 + &none &none>; + }; + + layer_1 { + bindings = < + &mo 2 &none + &none &none>; + }; + + layer_2 { + bindings = < + &none &none + &kp B &none>; + }; + }; +}; + +&kscan { + events = < + ZMK_MOCK_PRESS(0,1,10) + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_PRESS(1,0,10) + ZMK_MOCK_RELEASE(0,1,10) + ZMK_MOCK_RELEASE(0,0,10) + ZMK_MOCK_RELEASE(1,0,10) + >; +}; \ No newline at end of file diff --git a/app/tests/momentary-layer/behavior_keymap.dtsi b/app/tests/momentary-layer/behavior_keymap.dtsi index 6cc3140..a5b6c12 100644 --- a/app/tests/momentary-layer/behavior_keymap.dtsi +++ b/app/tests/momentary-layer/behavior_keymap.dtsi @@ -10,19 +10,13 @@ default_layer { bindings = < &kp B &mo 1 - &kp D &kp G>; + &trans &trans>; }; - lower_layer { + layer_1 { bindings = < &kp C_NEXT &trans - &kp L &kp J>; - }; - - raise_layer { - bindings = < - &kp W &kp U - &kp X &kp M>; + &trans &trans>; }; }; }; diff --git a/app/tests/momentary-layer/early-key-release/events.patterns b/app/tests/momentary-layer/early-key-release/events.patterns deleted file mode 100644 index bd7b488..0000000 --- a/app/tests/momentary-layer/early-key-release/events.patterns +++ /dev/null @@ -1,2 +0,0 @@ -s/.*hid_listener_keycode/kp/p -s/.*mo_keymap_binding/mo/p \ No newline at end of file diff --git a/app/tests/momentary-layer/early-key-release/keycode_events.snapshot b/app/tests/momentary-layer/early-key-release/keycode_events.snapshot deleted file mode 100644 index 82ebc67..0000000 --- a/app/tests/momentary-layer/early-key-release/keycode_events.snapshot +++ /dev/null @@ -1,4 +0,0 @@ -kp_pressed: usage_page 0x07 keycode 0x05 mods 0x00 -mo_pressed: position 1 layer 1 -kp_released: usage_page 0x07 keycode 0x05 mods 0x00 -mo_released: position 1 layer 1 diff --git a/app/tests/momentary-layer/early-key-release/native_posix.keymap b/app/tests/momentary-layer/early-key-release/native_posix.keymap deleted file mode 100644 index e7628c0..0000000 --- a/app/tests/momentary-layer/early-key-release/native_posix.keymap +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include -#include "../behavior_keymap.dtsi" - -&kscan { - events = ; -}; \ No newline at end of file diff --git a/app/tests/momentary-layer/normal/events.patterns b/app/tests/momentary-layer/normal/events.patterns deleted file mode 100644 index bd7b488..0000000 --- a/app/tests/momentary-layer/normal/events.patterns +++ /dev/null @@ -1,2 +0,0 @@ -s/.*hid_listener_keycode/kp/p -s/.*mo_keymap_binding/mo/p \ No newline at end of file diff --git a/app/tests/momentary-layer/normal/keycode_events.snapshot b/app/tests/momentary-layer/normal/keycode_events.snapshot deleted file mode 100644 index 247128f..0000000 --- a/app/tests/momentary-layer/normal/keycode_events.snapshot +++ /dev/null @@ -1,4 +0,0 @@ -mo_pressed: position 1 layer 1 -kp_pressed: usage_page 0x0c keycode 0xb5 mods 0x00 -kp_released: usage_page 0x0c keycode 0xb5 mods 0x00 -mo_released: position 1 layer 1 diff --git a/app/tests/momentary-layer/normal/native_posix.keymap b/app/tests/momentary-layer/normal/native_posix.keymap deleted file mode 100644 index 7f73690..0000000 --- a/app/tests/momentary-layer/normal/native_posix.keymap +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include -#include "../behavior_keymap.dtsi" - -&kscan { - events = ; -}; \ No newline at end of file -- cgit v1.2.3