From 22fe8eabceb88d43422dc731996d95838bec8519 Mon Sep 17 00:00:00 2001 From: JJGadgets Date: Thu, 14 Mar 2024 15:39:40 +0800 Subject: [PATCH] feat(sweep): shortcut behaviour functions --- config/cradio.keymap | 121 +++++++------------------------------- functions/behaviours.dtsi | 42 +++++++++++++ 2 files changed, 63 insertions(+), 100 deletions(-) create mode 100644 functions/behaviours.dtsi diff --git a/config/cradio.keymap b/config/cradio.keymap index 9bcb412..6a16414 100644 --- a/config/cradio.keymap +++ b/config/cradio.keymap @@ -9,6 +9,9 @@ #include #include +// my own code +#include "../functions/behaviours.dtsi" + // Layers name to integer definition #define DEFAULT 0 #define NUM_KEYS 1 @@ -24,10 +27,10 @@ #define MT 10 #define EMPTYLAYER \ - &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans \ - &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans \ - &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans \ - &trans &trans &trans &trans + &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans \ + &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans \ + &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans \ + &trans &trans &trans &trans &mt { bindings = <&sk>, <&kp>; @@ -46,102 +49,20 @@ / { behaviors { - /omit-if-no-ref/ mmsc: mod_morph_semicolon { - compatible = "zmk,behavior-mod-morph"; - #binding-cells = <0>; - bindings = <&kp COLON>, <&kp SEMICOLON>; - mods = <(MOD_LSFT)>; - }; - /omit-if-no-ref/ mmsa: mod_morph_delete_semicolon { - compatible = "zmk,behavior-mod-morph"; - #binding-cells = <0>; - bindings = <&mmsc>, <&kp APOSTROPHE>; - mods = <(MOD_RALT)>; - }; - /omit-if-no-ref/ mmgrave: mod_morph_grave { - compatible = "zmk,behavior-mod-morph"; - #binding-cells = <0>; - bindings = <&kp TILDE>, <&kp GRAVE>; - mods = <(MOD_LSFT)>; - }; - /omit-if-no-ref/ mmqgr: mod_morph_q_grave { - compatible = "zmk,behavior-mod-morph"; - #binding-cells = <0>; - bindings = <&kp Q>, <&mmgrave>; - mods = <(MOD_RALT)>; - }; - /omit-if-no-ref/ mmat: mod_morph_a_tab { - compatible = "zmk,behavior-mod-morph"; - #binding-cells = <0>; - bindings = <&kp A>, <&kp TAB>; - mods = <(MOD_RALT|MOD_RGUI)>; - keep-mods = <(MOD_RALT|MOD_RGUI)>; - }; - /omit-if-no-ref/ mmec: mod_morph_esc_caps { - compatible = "zmk,behavior-mod-morph"; - #binding-cells = <0>; - bindings = <&kp ESC>, <&caps_word>; - mods = <(MOD_LSFT)>; - }; - /omit-if-no-ref/ esc: esc_ctrl { - compatible = "zmk,behavior-hold-tap"; - #binding-cells = <2>; - flavor = "hold-preferred"; - tapping-term-ms = <200>; - bindings = <&kp>, <&mmec>; - }; - /omit-if-no-ref/ rm: repeat_mod { - compatible = "zmk,behavior-hold-tap"; - #binding-cells = <2>; - flavor = "hold-preferred"; - tapping-term-ms = <200>; - bindings = <&kp>, <&key_repeat>; - }; - /omit-if-no-ref/ mto: mod_tap_to_layer { - compatible = "zmk,behavior-hold-tap"; - #binding-cells = <2>; - flavor = "hold-preferred"; - tapping-term-ms = <200>; - bindings = <&sk>, <&to>; - }; - /omit-if-no-ref/ mtog: mod_tap_toggle_layer { - compatible = "zmk,behavior-hold-tap"; - #binding-cells = <2>; - flavor = "hold-preferred"; - tapping-term-ms = <200>; - bindings = <&sk>, <&tog>; - }; - /omit-if-no-ref/ lt2: layer_tap_2 { - compatible = "zmk,behavior-hold-tap"; - #binding-cells = <2>; - flavor = "hold-preferred"; - tapping-term-ms = <200>; - bindings = <&mo>, <&to>; - }; - /omit-if-no-ref/ mmzd: mod_morph_z_delete { - compatible = "zmk,behavior-mod-morph"; - #binding-cells = <0>; - bindings = <&kp Z>, <&kp DEL>; - mods = <(MOD_RALT)>; - }; - /omit-if-no-ref/ ltz: layer_tap_z { - compatible = "zmk,behavior-hold-tap"; - #binding-cells = <2>; - flavor = "tap-preferred"; - tapping-term-ms = <280>; - quick-tap-ms = <175>; - require-prior-idle-ms = <150>; - bindings = <&mo>, <&mmzd>; - }; - /omit-if-no-ref/ hm: homerow_mods { - compatible = "zmk,behavior-hold-tap"; - #binding-cells = <2>; - flavor = "tap-preferred"; - tapping-term-ms = <280>; - quick-tap-ms = <175>; - require-prior-idle-ms = <150>; - bindings = <&kp>, <&kp>; - }; + JJ_MM(mmsc, mod_morph_semicolon, mods = <(MOD_LSFT)>; bindings = <&kp COLON>, <&kp SEMICOLON>;) + JJ_MM(mmsa, mod_morph_delete_semicolon, mods = <(MOD_RALT)>; bindings = <&mmsc>, <&kp APOSTROPHE>;) + JJ_MM(mmgrave, mod_morph_grave, mods = <(MOD_LSFT)>; bindings = <&kp TILDE>, <&kp GRAVE>;) + JJ_MM(mmqgr, mod_morph_q_grave, mods = <(MOD_RALT)>; bindings = <&kp Q>, <&mmgrave>;) + JJ_MM(mmat, mod_morph_a_tab, mods = <(MOD_RALT|MOD_RGUI)>; keep-mods = <(MOD_RALT|MOD_RGUI)>; bindings = <&kp A>, <&kp TAB>;) + JJ_MM(mmec, mod_morph_esc_caps, mods = <(MOD_LSFT)>; bindings = <&kp ESC>, <&caps_word>;) + JJ_HT_HOLD(esc, esc_ctrl, bindings = <&kp>, <&mmec>;) + JJ_HT_HOLD(rm, repeat_mod, bindings = <&kp>, <&key_repeat>;) + JJ_HT_HOLD(mto, mod_tap_to_layer, bindings = <&sk>, <&to>;) + JJ_HT_HOLD(mtog, mod_tap_toggle_layer, bindings = <&sk>, <&tog>;) + JJ_HT_HOLD(lt2, layer_tap_2, bindings = <&mo>, <&to>;) + JJ_MM(mmzd, mod_morph_z_delete, mods = <(MOD_RALT)>; bindings = <&kp Z>, <&kp DEL>;) + JJ_HT_TAP(ltz, layer_tap_z, bindings = <&mo>, <&mmzd>;) + JJ_HT_TAP(hm, homerow_mods, bindings = <&kp>, <&kp>;) }; keymap { compatible = "zmk,keymap"; diff --git a/functions/behaviours.dtsi b/functions/behaviours.dtsi new file mode 100644 index 0000000..5fbc12e --- /dev/null +++ b/functions/behaviours.dtsi @@ -0,0 +1,42 @@ +// vi: ft=c +#define JJ(name,desc,compat,cells...) \ +/omit-if-no-ref/ name: desc { \ + compatible = compat; \ + #binding-cells = ; \ + __VA_ARGS__ \ +}; + +#define JJ_MM(name,desc,...) \ +/omit-if-no-ref/ name: desc { \ + compatible = "zmk,behavior-mod-morph"; \ + #binding-cells = <0>; \ + __VA_ARGS__ \ +}; + +#define JJ_HT(name,desc,flav...) \ +/omit-if-no-ref/ name: desc { \ + compatible = "zmk,behavior-hold-tap"; \ + #binding-cells = <2>; \ + flavor = flav; \ + __VA_ARGS__ \ +}; + +#define JJ_HT_HOLD(name,desc,...) \ +/omit-if-no-ref/ name: desc { \ + compatible = "zmk,behavior-hold-tap"; \ + #binding-cells = <2>; \ + flavor = "hold-preferred"; \ + tapping-term-ms = <200>; \ + __VA_ARGS__ \ +}; + +#define JJ_HT_TAP(name,desc,...) \ +/omit-if-no-ref/ name: desc { \ + compatible = "zmk,behavior-hold-tap"; \ + #binding-cells = <2>; \ + flavor = "tap-preferred"; \ + tapping-term-ms = <280>; \ + quick-tap-ms = <175>; \ + require-prior-idle-ms = <150>; \ + __VA_ARGS__ \ +};