From 354bb52573ad017a7c11b74b065756513fb69321 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 5 Aug 2024 16:50:35 -0600 Subject: [PATCH] feat: Add the ability to keep behavior for a given build. * Use defines to keep either all behavior, or selective behavior, before including `behavior.dtsi` in keymaps. --- app/boards/native_posix_64.overlay | 2 +- .../minivan_studio_tester/minivan_studio_tester.keymap | 2 ++ app/dts/behaviors/backlight.dtsi | 5 ++++- app/dts/behaviors/bluetooth.dtsi | 5 ++++- app/dts/behaviors/caps_word.dtsi | 7 ++++++- app/dts/behaviors/gresc.dtsi | 5 ++++- app/dts/behaviors/key_press.dtsi | 6 ++++-- app/dts/behaviors/key_repeat.dtsi | 5 ++++- app/dts/behaviors/key_toggle.dtsi | 5 ++++- app/dts/behaviors/layer_tap.dtsi | 5 ++++- app/dts/behaviors/mod_tap.dtsi | 5 ++++- app/dts/behaviors/momentary_layer.dtsi | 5 ++++- app/dts/behaviors/mouse_key_press.dtsi | 5 ++++- app/dts/behaviors/none.dtsi | 5 ++++- app/dts/behaviors/outputs.dtsi | 5 ++++- app/dts/behaviors/soft_off.dtsi | 5 ++++- app/dts/behaviors/sticky_key.dtsi | 10 ++++++++-- app/dts/behaviors/to_layer.dtsi | 5 ++++- app/dts/behaviors/toggle_layer.dtsi | 5 ++++- app/dts/behaviors/transparent.dtsi | 5 ++++- 20 files changed, 81 insertions(+), 21 deletions(-) diff --git a/app/boards/native_posix_64.overlay b/app/boards/native_posix_64.overlay index d0526ca38eb2..2e571c4b71d0 100644 --- a/app/boards/native_posix_64.overlay +++ b/app/boards/native_posix_64.overlay @@ -1,4 +1,4 @@ -#include + #include #include diff --git a/app/boards/shields/minivan_studio_tester/minivan_studio_tester.keymap b/app/boards/shields/minivan_studio_tester/minivan_studio_tester.keymap index 531d8e0ccadf..307861ea39b5 100644 --- a/app/boards/shields/minivan_studio_tester/minivan_studio_tester.keymap +++ b/app/boards/shields/minivan_studio_tester/minivan_studio_tester.keymap @@ -4,6 +4,8 @@ * SPDX-License-Identifier: MIT */ +#define ZMK_STUDIO_BEHAVIORS_KEEP_ALL 1 + #include #include diff --git a/app/dts/behaviors/backlight.dtsi b/app/dts/behaviors/backlight.dtsi index dd045effed3c..da11e30880a6 100644 --- a/app/dts/behaviors/backlight.dtsi +++ b/app/dts/behaviors/backlight.dtsi @@ -6,8 +6,11 @@ / { behaviors { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_BL) + /omit-if-no-ref/ +#endif // Behavior can be invoked on peripherals, so name must be <= 8 characters. - /omit-if-no-ref/ bl: bcklight { + bl: bcklight { compatible = "zmk,behavior-backlight"; #binding-cells = <2>; display-name = "Backlight"; diff --git a/app/dts/behaviors/bluetooth.dtsi b/app/dts/behaviors/bluetooth.dtsi index bece156f8fb2..d5b1b5f087e6 100644 --- a/app/dts/behaviors/bluetooth.dtsi +++ b/app/dts/behaviors/bluetooth.dtsi @@ -6,7 +6,10 @@ / { behaviors { - /omit-if-no-ref/ bt: bluetooth { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_BT) + /omit-if-no-ref/ +#endif + bt: bluetooth { compatible = "zmk,behavior-bluetooth"; #binding-cells = <2>; display-name = "Bluetooth"; diff --git a/app/dts/behaviors/caps_word.dtsi b/app/dts/behaviors/caps_word.dtsi index 05431bd8db20..5939b82a47ff 100644 --- a/app/dts/behaviors/caps_word.dtsi +++ b/app/dts/behaviors/caps_word.dtsi @@ -6,9 +6,14 @@ #include +#define ZMK_STUDIO_BEHAVIORS_KEEP_CAPS_WORD BALES + / { behaviors { - /omit-if-no-ref/ caps_word: caps_word { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_CAPS_WORD) + /omit-if-no-ref/ +#endif + caps_word: caps_word { compatible = "zmk,behavior-caps-word"; #binding-cells = <0>; continue-list = ; diff --git a/app/dts/behaviors/gresc.dtsi b/app/dts/behaviors/gresc.dtsi index 2643a383d814..d64acc7a7e29 100644 --- a/app/dts/behaviors/gresc.dtsi +++ b/app/dts/behaviors/gresc.dtsi @@ -8,7 +8,10 @@ / { behaviors { - /omit-if-no-ref/ gresc: grave_escape { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_GRAVE_ESCAPE) + /omit-if-no-ref/ +#endif + gresc: grave_escape { compatible = "zmk,behavior-mod-morph"; #binding-cells = <0>; bindings = <&kp ESC>, <&kp GRAVE>; diff --git a/app/dts/behaviors/key_press.dtsi b/app/dts/behaviors/key_press.dtsi index 2435699b6abc..ffea2cc07ee6 100644 --- a/app/dts/behaviors/key_press.dtsi +++ b/app/dts/behaviors/key_press.dtsi @@ -6,8 +6,10 @@ / { behaviors { - /* DEPRECATED: `cp` will be removed in the future */ - /omit-if-no-ref/ cp: kp: key_press { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_KEY_PRESS) + /omit-if-no-ref/ +#endif + kp: key_press { compatible = "zmk,behavior-key-press"; #binding-cells = <1>; display-name = "Key Press"; diff --git a/app/dts/behaviors/key_repeat.dtsi b/app/dts/behaviors/key_repeat.dtsi index cd5d3771dcbd..4537cb9091c8 100644 --- a/app/dts/behaviors/key_repeat.dtsi +++ b/app/dts/behaviors/key_repeat.dtsi @@ -8,7 +8,10 @@ / { behaviors { - /omit-if-no-ref/ key_repeat: key_repeat { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_KEY_REPEAT) + /omit-if-no-ref/ +#endif + key_repeat: key_repeat { compatible = "zmk,behavior-key-repeat"; #binding-cells = <0>; usage-pages = ; diff --git a/app/dts/behaviors/key_toggle.dtsi b/app/dts/behaviors/key_toggle.dtsi index a7b66aab1afb..e2f17be3b71a 100644 --- a/app/dts/behaviors/key_toggle.dtsi +++ b/app/dts/behaviors/key_toggle.dtsi @@ -6,7 +6,10 @@ / { behaviors { - /omit-if-no-ref/ kt: key_toggle { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_KEY_TOGGLE) + /omit-if-no-ref/ +#endif + kt: key_toggle { compatible = "zmk,behavior-key-toggle"; #binding-cells = <1>; display-name = "Key Toggle"; diff --git a/app/dts/behaviors/layer_tap.dtsi b/app/dts/behaviors/layer_tap.dtsi index 2858bf17bc5b..39aa1e304aeb 100644 --- a/app/dts/behaviors/layer_tap.dtsi +++ b/app/dts/behaviors/layer_tap.dtsi @@ -6,7 +6,10 @@ / { behaviors { - /omit-if-no-ref/ lt: layer_tap { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_LAYER_TAP) + /omit-if-no-ref/ +#endif + lt: layer_tap { compatible = "zmk,behavior-hold-tap"; #binding-cells = <2>; flavor = "tap-preferred"; diff --git a/app/dts/behaviors/mod_tap.dtsi b/app/dts/behaviors/mod_tap.dtsi index 0b46f77e739c..741fb9d72e79 100644 --- a/app/dts/behaviors/mod_tap.dtsi +++ b/app/dts/behaviors/mod_tap.dtsi @@ -6,7 +6,10 @@ / { behaviors { - /omit-if-no-ref/ mt: mod_tap { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_MOD_TAP) + /omit-if-no-ref/ +#endif + mt: mod_tap { compatible = "zmk,behavior-hold-tap"; #binding-cells = <2>; flavor = "hold-preferred"; diff --git a/app/dts/behaviors/momentary_layer.dtsi b/app/dts/behaviors/momentary_layer.dtsi index cae08d5f1013..6f3ba35d247e 100644 --- a/app/dts/behaviors/momentary_layer.dtsi +++ b/app/dts/behaviors/momentary_layer.dtsi @@ -6,7 +6,10 @@ / { behaviors { - /omit-if-no-ref/ mo: momentary_layer { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_MOMENTARY_LAYER) + /omit-if-no-ref/ +#endif + mo: momentary_layer { compatible = "zmk,behavior-momentary-layer"; #binding-cells = <1>; display-name = "Momentary Layer"; diff --git a/app/dts/behaviors/mouse_key_press.dtsi b/app/dts/behaviors/mouse_key_press.dtsi index 975c24aaafbd..872b43075bad 100644 --- a/app/dts/behaviors/mouse_key_press.dtsi +++ b/app/dts/behaviors/mouse_key_press.dtsi @@ -1,6 +1,9 @@ / { behaviors { - /omit-if-no-ref/ mkp: mouse_key_press { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_MOUSE_KEY_PRESS) + /omit-if-no-ref/ +#endif + mkp: mouse_key_press { compatible = "zmk,behavior-mouse-key-press"; #binding-cells = <1>; }; diff --git a/app/dts/behaviors/none.dtsi b/app/dts/behaviors/none.dtsi index a9a820c30b52..1e9116963722 100644 --- a/app/dts/behaviors/none.dtsi +++ b/app/dts/behaviors/none.dtsi @@ -6,7 +6,10 @@ / { behaviors { - /omit-if-no-ref/ none: none { +#if !defined(ZMK_STUDIO_BUILD) + /omit-if-no-ref/ +#endif + none: none { compatible = "zmk,behavior-none"; #binding-cells = <0>; display-name = "None"; diff --git a/app/dts/behaviors/outputs.dtsi b/app/dts/behaviors/outputs.dtsi index 3047852adcec..3760744a33bc 100644 --- a/app/dts/behaviors/outputs.dtsi +++ b/app/dts/behaviors/outputs.dtsi @@ -6,7 +6,10 @@ / { behaviors { - /omit-if-no-ref/ out: outputs { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_OUT) + /omit-if-no-ref/ +#endif + out: outputs { compatible = "zmk,behavior-outputs"; #binding-cells = <1>; display-name = "Output Selection"; diff --git a/app/dts/behaviors/soft_off.dtsi b/app/dts/behaviors/soft_off.dtsi index a5c9d255bc18..4523b139f65f 100644 --- a/app/dts/behaviors/soft_off.dtsi +++ b/app/dts/behaviors/soft_off.dtsi @@ -6,7 +6,10 @@ / { behaviors { - /omit-if-no-ref/ soft_off: z_so_off { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_SOFT_OFF) + /omit-if-no-ref/ +#endif + soft_off: z_so_off { compatible = "zmk,behavior-soft-off"; #binding-cells = <0>; split-peripheral-off-on-press; diff --git a/app/dts/behaviors/sticky_key.dtsi b/app/dts/behaviors/sticky_key.dtsi index 382a7254e7bc..cc34b515e056 100644 --- a/app/dts/behaviors/sticky_key.dtsi +++ b/app/dts/behaviors/sticky_key.dtsi @@ -6,7 +6,10 @@ / { behaviors { - /omit-if-no-ref/ sk: sticky_key { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_STICKY_KEY) + /omit-if-no-ref/ +#endif + sk: sticky_key { compatible = "zmk,behavior-sticky-key"; #binding-cells = <1>; release-after-ms = <1000>; @@ -14,7 +17,10 @@ ignore-modifiers; display-name = "Sticky Key"; }; - /omit-if-no-ref/ sl: sticky_layer { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_STICKY_LAYER) + /omit-if-no-ref/ +#endif + sl: sticky_layer { compatible = "zmk,behavior-sticky-key"; #binding-cells = <1>; release-after-ms = <1000>; diff --git a/app/dts/behaviors/to_layer.dtsi b/app/dts/behaviors/to_layer.dtsi index 3c740209cb1c..bce2711ce921 100644 --- a/app/dts/behaviors/to_layer.dtsi +++ b/app/dts/behaviors/to_layer.dtsi @@ -6,7 +6,10 @@ / { behaviors { - /omit-if-no-ref/ to: to_layer { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_TO_LAYER) + /omit-if-no-ref/ +#endif + to: to_layer { compatible = "zmk,behavior-to-layer"; #binding-cells = <1>; display-name = "To Layer"; diff --git a/app/dts/behaviors/toggle_layer.dtsi b/app/dts/behaviors/toggle_layer.dtsi index ea9b25b7c1d3..597ce4f524b8 100644 --- a/app/dts/behaviors/toggle_layer.dtsi +++ b/app/dts/behaviors/toggle_layer.dtsi @@ -6,7 +6,10 @@ / { behaviors { - /omit-if-no-ref/ tog: toggle_layer { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_TOGGLE_LAYER) + /omit-if-no-ref/ +#endif + tog: toggle_layer { compatible = "zmk,behavior-toggle-layer"; #binding-cells = <1>; display-name = "Toggle Layer"; diff --git a/app/dts/behaviors/transparent.dtsi b/app/dts/behaviors/transparent.dtsi index 03ec36a64e85..0ed28b0d1888 100644 --- a/app/dts/behaviors/transparent.dtsi +++ b/app/dts/behaviors/transparent.dtsi @@ -6,7 +6,10 @@ / { behaviors { - /omit-if-no-ref/ trans: transparent { +#if !defined(ZMK_STUDIO_BEHAVIORS_KEEP_ALL) && !defined(ZMK_STUDIO_BEHAVIORS_KEEP_TRANS) + /omit-if-no-ref/ +#endif + trans: transparent { compatible = "zmk,behavior-transparent"; #binding-cells = <0>; display-name = "Transparent";