summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/keymap.c10
-rw-r--r--app/tests/momentary-layer/1-normal/events.patterns (renamed from app/tests/momentary-layer/early-key-release/events.patterns)0
-rw-r--r--app/tests/momentary-layer/1-normal/keycode_events.snapshot4
-rw-r--r--app/tests/momentary-layer/1-normal/native_posix.keymap32
-rw-r--r--app/tests/momentary-layer/2-early-key-release/events.patterns (renamed from app/tests/momentary-layer/normal/events.patterns)0
-rw-r--r--app/tests/momentary-layer/2-early-key-release/keycode_events.snapshot (renamed from app/tests/momentary-layer/early-key-release/keycode_events.snapshot)0
-rw-r--r--app/tests/momentary-layer/2-early-key-release/native_posix.keymap32
-rw-r--r--app/tests/momentary-layer/3-covered/events.patterns3
-rw-r--r--app/tests/momentary-layer/3-covered/keycode_events.snapshot2
-rw-r--r--app/tests/momentary-layer/3-covered/native_posix.keymap33
-rw-r--r--app/tests/momentary-layer/4-nested/events.patterns3
-rw-r--r--app/tests/momentary-layer/4-nested/keycode_events.snapshot6
-rw-r--r--app/tests/momentary-layer/4-nested/native_posix.keymap39
-rw-r--r--app/tests/momentary-layer/5-nested-early-key-release/events.patterns3
-rw-r--r--app/tests/momentary-layer/5-nested-early-key-release/keycode_events.snapshot6
-rw-r--r--app/tests/momentary-layer/5-nested-early-key-release/native_posix.keymap39
-rw-r--r--app/tests/momentary-layer/behavior_keymap.dtsi12
-rw-r--r--app/tests/momentary-layer/early-key-release/native_posix.keymap8
-rw-r--r--app/tests/momentary-layer/normal/keycode_events.snapshot4
-rw-r--r--app/tests/momentary-layer/normal/native_posix.keymap8
20 files changed, 209 insertions, 35 deletions
diff --git a/app/src/keymap.c b/app/src/keymap.c
index 1d289e5..70db2fa 100644
--- a/app/src/keymap.c
+++ b/app/src/keymap.c
@@ -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;
diff --git a/app/tests/momentary-layer/early-key-release/events.patterns b/app/tests/momentary-layer/1-normal/events.patterns
index bd7b488..bd7b488 100644
--- a/app/tests/momentary-layer/early-key-release/events.patterns
+++ b/app/tests/momentary-layer/1-normal/events.patterns
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 <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)
+ >;
+}; \ No newline at end of file
diff --git a/app/tests/momentary-layer/normal/events.patterns b/app/tests/momentary-layer/2-early-key-release/events.patterns
index bd7b488..bd7b488 100644
--- a/app/tests/momentary-layer/normal/events.patterns
+++ b/app/tests/momentary-layer/2-early-key-release/events.patterns
diff --git a/app/tests/momentary-layer/early-key-release/keycode_events.snapshot b/app/tests/momentary-layer/2-early-key-release/keycode_events.snapshot
index 82ebc67..82ebc67 100644
--- a/app/tests/momentary-layer/early-key-release/keycode_events.snapshot
+++ b/app/tests/momentary-layer/2-early-key-release/keycode_events.snapshot
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 <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)
+ >;
+}; \ 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 <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)
+ >;
+};
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 <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)
+ >;
+}; \ 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 <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)
+ >;
+}; \ 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/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 <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)>;
-}; \ 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 <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)>;
-}; \ No newline at end of file