Skip to content

Commit

Permalink
feat: Add the ability to keep behavior for a given build.
Browse files Browse the repository at this point in the history
* Use defines to keep either all behavior, or selective behavior, before
  including `behavior.dtsi` in keymaps.
  • Loading branch information
petejohanson committed Aug 10, 2024
1 parent 07db402 commit 8f753ed
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/boards/native_posix_64.overlay
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <behaviors.dtsi>

#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/kscan_mock.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: MIT
*/

#define ZMK_STUDIO_BEHAVIORS_KEEP_ALL 1

#include <behaviors.dtsi>
#include <dt-bindings/zmk/keys.h>

Expand Down
5 changes: 4 additions & 1 deletion app/dts/behaviors/backlight.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 4 additions & 1 deletion app/dts/behaviors/bluetooth.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
7 changes: 6 additions & 1 deletion app/dts/behaviors/caps_word.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@

#include <dt-bindings/zmk/keys.h>

#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 = <UNDERSCORE BACKSPACE DELETE>;
Expand Down
5 changes: 4 additions & 1 deletion app/dts/behaviors/gresc.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
6 changes: 4 additions & 2 deletions app/dts/behaviors/key_press.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 4 additions & 1 deletion app/dts/behaviors/key_repeat.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <HID_USAGE_KEY>;
Expand Down
5 changes: 4 additions & 1 deletion app/dts/behaviors/key_toggle.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 4 additions & 1 deletion app/dts/behaviors/layer_tap.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 4 additions & 1 deletion app/dts/behaviors/mod_tap.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 4 additions & 1 deletion app/dts/behaviors/momentary_layer.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 4 additions & 1 deletion app/dts/behaviors/mouse_key_press.dtsi
Original file line number Diff line number Diff line change
@@ -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>;
};
Expand Down
5 changes: 4 additions & 1 deletion app/dts/behaviors/none.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 4 additions & 1 deletion app/dts/behaviors/outputs.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 4 additions & 1 deletion app/dts/behaviors/soft_off.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions app/dts/behaviors/sticky_key.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@

/ {
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>;
bindings = <&kp>;
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>;
Expand Down
5 changes: 4 additions & 1 deletion app/dts/behaviors/to_layer.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 4 additions & 1 deletion app/dts/behaviors/toggle_layer.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 4 additions & 1 deletion app/dts/behaviors/transparent.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 8f753ed

Please sign in to comment.