feat: Add the ability to keep/omit behaviors for a given build.

* Use defines to keep either all behaviors with omits, or selective behaviors with
  explicit kept behavior, before including `behavior.dtsi` in keymaps.
* Default ZMK_BEHAVIORS_KEEP_ALL when building with the studio RPC
  endpoint snippet.
This commit is contained in:
Peter Johanson 2024-08-05 16:50:35 -06:00
parent 051deb50fe
commit f584318ddc
22 changed files with 129 additions and 21 deletions

View file

@ -1,4 +1,4 @@
#include <behaviors.dtsi>
#include <dt-bindings/zmk/keys.h> #include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/kscan_mock.h> #include <dt-bindings/zmk/kscan_mock.h>

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#define ZMK_BEHAVIORS_KEEP_ALL
#include <behaviors.dtsi> #include <behaviors.dtsi>
#include <dt-bindings/zmk/keys.h> #include <dt-bindings/zmk/keys.h>

View file

@ -4,10 +4,15 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
/ { / {
behaviors { behaviors {
#if ZMK_BEHAVIOR_OMIT(BL)
/omit-if-no-ref/
#endif
// Behavior can be invoked on peripherals, so name must be <= 8 characters. // Behavior can be invoked on peripherals, so name must be <= 8 characters.
/omit-if-no-ref/ bl: bcklight { bl: bcklight {
compatible = "zmk,behavior-backlight"; compatible = "zmk,behavior-backlight";
#binding-cells = <2>; #binding-cells = <2>;
display-name = "Backlight"; display-name = "Backlight";

View file

@ -4,9 +4,14 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ bt: bluetooth { #if ZMK_BEHAVIOR_OMIT(BT)
/omit-if-no-ref/
#endif
bt: bluetooth {
compatible = "zmk,behavior-bluetooth"; compatible = "zmk,behavior-bluetooth";
#binding-cells = <2>; #binding-cells = <2>;
display-name = "Bluetooth"; display-name = "Bluetooth";

View file

@ -4,11 +4,15 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
#include <dt-bindings/zmk/keys.h> #include <dt-bindings/zmk/keys.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ caps_word: caps_word { #if ZMK_BEHAVIOR_OMIT(CAPS_WORD)
/omit-if-no-ref/
#endif
caps_word: caps_word {
compatible = "zmk,behavior-caps-word"; compatible = "zmk,behavior-caps-word";
#binding-cells = <0>; #binding-cells = <0>;
continue-list = <UNDERSCORE BACKSPACE DELETE>; continue-list = <UNDERSCORE BACKSPACE DELETE>;

View file

@ -4,11 +4,16 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
#include <dt-bindings/zmk/keys.h> #include <dt-bindings/zmk/keys.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ gresc: grave_escape { #if ZMK_BEHAVIOR_OMIT(GRESC)
/omit-if-no-ref/
#endif
gresc: grave_escape {
compatible = "zmk,behavior-mod-morph"; compatible = "zmk,behavior-mod-morph";
#binding-cells = <0>; #binding-cells = <0>;
bindings = <&kp ESC>, <&kp GRAVE>; bindings = <&kp ESC>, <&kp GRAVE>;

View file

@ -4,10 +4,14 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
/ { / {
behaviors { behaviors {
/* DEPRECATED: `cp` will be removed in the future */ #if ZMK_BEHAVIOR_OMIT(KP)
/omit-if-no-ref/ cp: kp: key_press { /omit-if-no-ref/
#endif
kp: key_press {
compatible = "zmk,behavior-key-press"; compatible = "zmk,behavior-key-press";
#binding-cells = <1>; #binding-cells = <1>;
display-name = "Key Press"; display-name = "Key Press";

View file

@ -4,11 +4,15 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
#include <dt-bindings/zmk/keys.h> #include <dt-bindings/zmk/keys.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ key_repeat: key_repeat { #if ZMK_BEHAVIOR_OMIT(KEY_REPEAT)
/omit-if-no-ref/
#endif
key_repeat: key_repeat {
compatible = "zmk,behavior-key-repeat"; compatible = "zmk,behavior-key-repeat";
#binding-cells = <0>; #binding-cells = <0>;
usage-pages = <HID_USAGE_KEY>; usage-pages = <HID_USAGE_KEY>;

View file

@ -4,9 +4,14 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ kt: key_toggle { #if ZMK_BEHAVIOR_OMIT(KT)
/omit-if-no-ref/
#endif
kt: key_toggle {
compatible = "zmk,behavior-key-toggle"; compatible = "zmk,behavior-key-toggle";
#binding-cells = <1>; #binding-cells = <1>;
display-name = "Key Toggle"; display-name = "Key Toggle";

View file

@ -4,9 +4,14 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ lt: layer_tap { #if ZMK_BEHAVIOR_OMIT(LT)
/omit-if-no-ref/
#endif
lt: layer_tap {
compatible = "zmk,behavior-hold-tap"; compatible = "zmk,behavior-hold-tap";
#binding-cells = <2>; #binding-cells = <2>;
flavor = "tap-preferred"; flavor = "tap-preferred";

View file

@ -4,9 +4,14 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ mt: mod_tap { #if ZMK_BEHAVIOR_OMIT(MT)
/omit-if-no-ref/
#endif
mt: mod_tap {
compatible = "zmk,behavior-hold-tap"; compatible = "zmk,behavior-hold-tap";
#binding-cells = <2>; #binding-cells = <2>;
flavor = "hold-preferred"; flavor = "hold-preferred";

View file

@ -4,9 +4,14 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ mo: momentary_layer { #if ZMK_BEHAVIOR_OMIT(MO)
/omit-if-no-ref/
#endif
mo: momentary_layer {
compatible = "zmk,behavior-momentary-layer"; compatible = "zmk,behavior-momentary-layer";
#binding-cells = <1>; #binding-cells = <1>;
display-name = "Momentary Layer"; display-name = "Momentary Layer";

View file

@ -1,6 +1,17 @@
/*
* Copyright (c) 2023 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#include <dt-bindings/zmk/behaviors.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ mkp: mouse_key_press { #if ZMK_BEHAVIOR_OMIT(MKP)
/omit-if-no-ref/
#endif
mkp: mouse_key_press {
compatible = "zmk,behavior-mouse-key-press"; compatible = "zmk,behavior-mouse-key-press";
#binding-cells = <1>; #binding-cells = <1>;
}; };

View file

@ -4,9 +4,14 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ none: none { #if ZMK_BEHAVIOR_OMIT(NONE)
/omit-if-no-ref/
#endif
none: none {
compatible = "zmk,behavior-none"; compatible = "zmk,behavior-none";
#binding-cells = <0>; #binding-cells = <0>;
display-name = "None"; display-name = "None";

View file

@ -4,9 +4,14 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ out: outputs { #if ZMK_BEHAVIOR_OMIT(OUT)
/omit-if-no-ref/
#endif
out: outputs {
compatible = "zmk,behavior-outputs"; compatible = "zmk,behavior-outputs";
#binding-cells = <1>; #binding-cells = <1>;
display-name = "Output Selection"; display-name = "Output Selection";

View file

@ -4,9 +4,14 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ soft_off: z_so_off { #if ZMK_BEHAVIOR_OMIT(SOFT_OFF)
/omit-if-no-ref/
#endif
soft_off: z_so_off {
compatible = "zmk,behavior-soft-off"; compatible = "zmk,behavior-soft-off";
#binding-cells = <0>; #binding-cells = <0>;
split-peripheral-off-on-press; split-peripheral-off-on-press;

View file

@ -4,9 +4,14 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ sk: sticky_key { #if ZMK_BEHAVIOR_OMIT(SK)
/omit-if-no-ref/
#endif
sk: sticky_key {
compatible = "zmk,behavior-sticky-key"; compatible = "zmk,behavior-sticky-key";
#binding-cells = <1>; #binding-cells = <1>;
release-after-ms = <1000>; release-after-ms = <1000>;
@ -14,7 +19,10 @@
ignore-modifiers; ignore-modifiers;
display-name = "Sticky Key"; display-name = "Sticky Key";
}; };
/omit-if-no-ref/ sl: sticky_layer { #if ZMK_BEHAVIOR_OMIT(STICKY_LAYER)
/omit-if-no-ref/
#endif
sl: sticky_layer {
compatible = "zmk,behavior-sticky-key"; compatible = "zmk,behavior-sticky-key";
#binding-cells = <1>; #binding-cells = <1>;
release-after-ms = <1000>; release-after-ms = <1000>;

View file

@ -4,9 +4,14 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ to: to_layer { #if ZMK_BEHAVIOR_OMIT(TO)
/omit-if-no-ref/
#endif
to: to_layer {
compatible = "zmk,behavior-to-layer"; compatible = "zmk,behavior-to-layer";
#binding-cells = <1>; #binding-cells = <1>;
display-name = "To Layer"; display-name = "To Layer";

View file

@ -4,9 +4,14 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ tog: toggle_layer { #if ZMK_BEHAVIOR_OMIT(TOG)
/omit-if-no-ref/
#endif
tog: toggle_layer {
compatible = "zmk,behavior-toggle-layer"; compatible = "zmk,behavior-toggle-layer";
#binding-cells = <1>; #binding-cells = <1>;
display-name = "Toggle Layer"; display-name = "Toggle Layer";

View file

@ -4,9 +4,14 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <dt-bindings/zmk/behaviors.h>
/ { / {
behaviors { behaviors {
/omit-if-no-ref/ trans: transparent { #if ZMK_BEHAVIOR_OMIT(TRANS)
/omit-if-no-ref/
#endif
trans: transparent {
compatible = "zmk,behavior-transparent"; compatible = "zmk,behavior-transparent";
#binding-cells = <0>; #binding-cells = <0>;
display-name = "Transparent"; display-name = "Transparent";

View file

@ -0,0 +1,9 @@
/*
* Copyright (c) 2024 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#define ZMK_BEHAVIOR_OMIT(_name) \
!(defined(ZMK_BEHAVIORS_KEEP_##_name) || \
(defined(ZMK_BEHAVIORS_KEEP_ALL) && !defined(ZMK_BEHAVIORS_OMIT_##_name)))

View file

@ -3,5 +3,6 @@
name: studio-rpc-usb-uart name: studio-rpc-usb-uart
append: append:
DTS_EXTRA_CPPFLAGS: -DZMK_BEHAVIORS_KEEP_ALL
EXTRA_DTC_OVERLAY_FILE: studio-rpc-usb-uart.overlay EXTRA_DTC_OVERLAY_FILE: studio-rpc-usb-uart.overlay
EXTRA_CONF_FILE: studio-rpc-usb-uart.conf EXTRA_CONF_FILE: studio-rpc-usb-uart.conf