fix(behaviors): Correct macro release state for parametrized macros (#2942)

test(behaviors): Add parametrized macro test that fails

fix(behaviors): Correct macro release state for parametrized
This commit is contained in:
Cem Aksoylar 2025-07-29 15:39:26 -07:00 committed by GitHub
parent d09087f4dc
commit 1bac680c4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 60 additions and 1 deletions

View File

@ -129,7 +129,9 @@ static int behavior_macro_init(const struct device *dev) {
LOG_DBG("Release will resume at %d", state->release_state.start_index);
break;
} else {
// Ignore regular invokable bindings
// Mostly ignore regular invokable bindings, except they will consume macro parameters
state->release_state.param1_source = PARAM_SOURCE_BINDING;
state->release_state.param2_source = PARAM_SOURCE_BINDING;
}
}

View File

@ -0,0 +1,2 @@
s/.*hid_listener_keycode/kp/p
s/.*mo_keymap_binding/mo/p

View File

@ -0,0 +1,8 @@
kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
mo_pressed: position 0 layer 1
kp_pressed: usage_page 0x07 keycode 0x1C implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x1C implicit_mods 0x00 explicit_mods 0x00
mo_released: position 0 layer 1
kp_pressed: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00
kp_released: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00

View File

@ -0,0 +1,47 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan_mock.h>
/ {
macros {
kp_l1: kp_l1 {
compatible = "zmk,behavior-macro-one-param";
#binding-cells = <1>;
wait-ms = <5>;
tap-ms = <5>;
bindings
= <&macro_param_1to1>
, <&macro_tap &kp MACRO_PLACEHOLDER>
, <&macro_press &mo 1>
, <&macro_pause_for_release>
, <&macro_release &mo 1>;
};
};
keymap {
compatible = "zmk,keymap";
default_layer {
bindings = <
&kp_l1 A &kp B
&kp C &none>;
};
other_layer {
bindings = <
&kp X &kp Y
&kp Z &none>;
};
};
};
&kscan {
events = <
ZMK_MOCK_PRESS(0,0,20) // press macro (taps A)
ZMK_MOCK_PRESS(0,1,20) // press Y
ZMK_MOCK_RELEASE(0,1,20) // release Y
ZMK_MOCK_RELEASE(0,0,20) // release macro
ZMK_MOCK_PRESS(1,0,10) // press C
ZMK_MOCK_RELEASE(1,0,10) // release C
>;
};