Browse Source

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.
xmkb
Okke Formsma 4 years ago committed by Pete Johanson
parent
commit
e48a6b659c
  1. 10
      app/src/keymap.c
  2. 0
      app/tests/momentary-layer/1-normal/events.patterns
  3. 4
      app/tests/momentary-layer/1-normal/keycode_events.snapshot
  4. 32
      app/tests/momentary-layer/1-normal/native_posix.keymap
  5. 0
      app/tests/momentary-layer/2-early-key-release/events.patterns
  6. 0
      app/tests/momentary-layer/2-early-key-release/keycode_events.snapshot
  7. 32
      app/tests/momentary-layer/2-early-key-release/native_posix.keymap
  8. 3
      app/tests/momentary-layer/3-covered/events.patterns
  9. 2
      app/tests/momentary-layer/3-covered/keycode_events.snapshot
  10. 33
      app/tests/momentary-layer/3-covered/native_posix.keymap
  11. 3
      app/tests/momentary-layer/4-nested/events.patterns
  12. 6
      app/tests/momentary-layer/4-nested/keycode_events.snapshot
  13. 39
      app/tests/momentary-layer/4-nested/native_posix.keymap
  14. 3
      app/tests/momentary-layer/5-nested-early-key-release/events.patterns
  15. 6
      app/tests/momentary-layer/5-nested-early-key-release/keycode_events.snapshot
  16. 39
      app/tests/momentary-layer/5-nested-early-key-release/native_posix.keymap
  17. 12
      app/tests/momentary-layer/behavior_keymap.dtsi
  18. 8
      app/tests/momentary-layer/early-key-release/native_posix.keymap
  19. 4
      app/tests/momentary-layer/normal/keycode_events.snapshot
  20. 8
      app/tests/momentary-layer/normal/native_posix.keymap

10
app/src/keymap.c

@ -130,14 +130,12 @@ int zmk_keymap_apply_position_state(int layer, u32_t position, bool pressed, s64 @@ -130,14 +130,12 @@ int zmk_keymap_apply_position_state(int layer, u32_t position, bool pressed, s64
}
int zmk_keymap_position_state_changed(u32_t position, bool pressed, s64_t timestamp) {
if (pressed) {
zmk_keymap_active_behavior_layer[position] = zmk_keymap_layer_state;
}
for (int layer = ZMK_KEYMAP_LAYERS_LEN - 1; layer >= zmk_keymap_layer_default; layer--) {
u32_t layer_state =
pressed ? zmk_keymap_layer_state : zmk_keymap_active_behavior_layer[position];
if (is_active_layer(layer, layer_state)) {
if (is_active_layer(layer, zmk_keymap_active_behavior_layer[position])) {
int ret = zmk_keymap_apply_position_state(layer, position, pressed, timestamp);
zmk_keymap_active_behavior_layer[position] = zmk_keymap_layer_state;
if (ret > 0) {
LOG_DBG("behavior processing to continue to next layer");
continue;

0
app/tests/momentary-layer/early-key-release/events.patterns → app/tests/momentary-layer/1-normal/events.patterns

4
app/tests/momentary-layer/1-normal/keycode_events.snapshot

@ -0,0 +1,4 @@ @@ -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

32
app/tests/momentary-layer/1-normal/native_posix.keymap

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan-mock.h>
#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)
>;
};

0
app/tests/momentary-layer/normal/events.patterns → app/tests/momentary-layer/2-early-key-release/events.patterns

0
app/tests/momentary-layer/early-key-release/keycode_events.snapshot → app/tests/momentary-layer/2-early-key-release/keycode_events.snapshot

32
app/tests/momentary-layer/2-early-key-release/native_posix.keymap

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan-mock.h>
#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)
>;
};

3
app/tests/momentary-layer/3-covered/events.patterns

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
s/.*hid_listener_keycode/kp/p
s/.*mo_keymap_binding/mo/p
s/.*keymap_position_state_changed/kp_st/p

2
app/tests/momentary-layer/3-covered/keycode_events.snapshot

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
mo_pressed: position 1 layer 1
mo_released: position 1 layer 1

33
app/tests/momentary-layer/3-covered/native_posix.keymap

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan-mock.h>
/*
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)
>;
};

3
app/tests/momentary-layer/4-nested/events.patterns

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
s/.*hid_listener_keycode/kp/p
s/.*mo_keymap_binding/mo/p
s/.*keymap_position_state_changed/kp_st/p

6
app/tests/momentary-layer/4-nested/keycode_events.snapshot

@ -0,0 +1,6 @@ @@ -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

39
app/tests/momentary-layer/4-nested/native_posix.keymap

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
#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 = <
&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)
>;
};

3
app/tests/momentary-layer/5-nested-early-key-release/events.patterns

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
s/.*hid_listener_keycode/kp/p
s/.*mo_keymap_binding/mo/p
s/.*keymap_position_state_changed/kp_st/p

6
app/tests/momentary-layer/5-nested-early-key-release/keycode_events.snapshot

@ -0,0 +1,6 @@ @@ -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

39
app/tests/momentary-layer/5-nested-early-key-release/native_posix.keymap

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
#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 = <
&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)
>;
};

12
app/tests/momentary-layer/behavior_keymap.dtsi

@ -10,19 +10,13 @@ @@ -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>;
};
};
};

8
app/tests/momentary-layer/early-key-release/native_posix.keymap

@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan-mock.h>
#include "../behavior_keymap.dtsi"
&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)>;
};

4
app/tests/momentary-layer/normal/keycode_events.snapshot

@ -1,4 +0,0 @@ @@ -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

8
app/tests/momentary-layer/normal/native_posix.keymap

@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan-mock.h>
#include "../behavior_keymap.dtsi"
&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)>;
};
Loading…
Cancel
Save