From 9afefe517764be1f79b42a010c75881bb5972378 Mon Sep 17 00:00:00 2001 From: Nick Conway Date: Fri, 2 Jun 2023 20:56:24 -0400 Subject: [PATCH] Retro tap binding --- .../behaviors/zmk,behavior-hold-tap.yaml | 9 +++++++ app/src/behaviors/behavior_hold_tap.c | 22 +++++++++++++++- docs/docs/behaviors/hold-tap.md | 26 +++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml b/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml index a2affbf2..7d49bd39 100644 --- a/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml +++ b/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml @@ -33,6 +33,15 @@ properties: - "tap-unless-interrupted" retro-tap: type: boolean + retro-tap-behavior: + type: string + default: "" + retro-tap-param1: + type: int + default: 0 + retro-tap-param2: + type: int + default: 0 hold-trigger-key-positions: type: array required: false diff --git a/app/src/behaviors/behavior_hold_tap.c b/app/src/behaviors/behavior_hold_tap.c index 30350ef2..584fb366 100644 --- a/app/src/behaviors/behavior_hold_tap.c +++ b/app/src/behaviors/behavior_hold_tap.c @@ -40,6 +40,7 @@ enum flavor { enum status { STATUS_UNDECIDED, STATUS_TAP, + STATUS_RETRO_TAP, STATUS_HOLD_INTERRUPT, STATUS_HOLD_TIMER, }; @@ -60,6 +61,9 @@ struct behavior_hold_tap_config { bool global_quick_tap; enum flavor flavor; bool retro_tap; + char *retro_tap_behavior; + uint32_t retro_tap_param1; + uint32_t retro_tap_param2; bool hold_trigger_on_release; int32_t hold_trigger_key_positions_len; int32_t hold_trigger_key_positions[]; @@ -372,6 +376,11 @@ static int press_binding(struct active_hold_tap *hold_tap) { if (hold_tap->status == STATUS_HOLD_TIMER || hold_tap->status == STATUS_HOLD_INTERRUPT) { binding.behavior_dev = hold_tap->config->hold_behavior_dev; binding.param1 = hold_tap->param_hold; + } else if (hold_tap->status == STATUS_RETRO_TAP) { + binding.behavior_dev = hold_tap->config->retro_tap_behavior; + binding.param1 = hold_tap->config->retro_tap_param1; + binding.param2 = hold_tap->config->retro_tap_param2; + store_last_hold_tapped(hold_tap); } else { binding.behavior_dev = hold_tap->config->tap_behavior_dev; binding.param1 = hold_tap->param_tap; @@ -394,6 +403,10 @@ static int release_binding(struct active_hold_tap *hold_tap) { if (hold_tap->status == STATUS_HOLD_TIMER || hold_tap->status == STATUS_HOLD_INTERRUPT) { binding.behavior_dev = hold_tap->config->hold_behavior_dev; binding.param1 = hold_tap->param_hold; + } else if (hold_tap->status == STATUS_RETRO_TAP) { + binding.behavior_dev = hold_tap->config->retro_tap_behavior; + binding.param1 = hold_tap->config->retro_tap_param1; + binding.param2 = hold_tap->config->retro_tap_param2; } else { binding.behavior_dev = hold_tap->config->tap_behavior_dev; binding.param1 = hold_tap->param_tap; @@ -484,7 +497,11 @@ static void decide_retro_tap(struct active_hold_tap *hold_tap) { if (hold_tap->status == STATUS_HOLD_TIMER) { release_binding(hold_tap); LOG_DBG("%d retro tap", hold_tap->position); - hold_tap->status = STATUS_TAP; + if (strcmp(hold_tap->config->retro_tap_behavior, "") == 0) { + hold_tap->status = STATUS_TAP; + } else { + hold_tap->status = STATUS_RETRO_TAP; + } press_binding(hold_tap); return; } @@ -706,6 +723,9 @@ static int behavior_hold_tap_init(const struct device *dev) { .global_quick_tap = DT_INST_PROP(n, global_quick_tap), \ .flavor = DT_ENUM_IDX(DT_DRV_INST(n), flavor), \ .retro_tap = DT_INST_PROP(n, retro_tap), \ + .retro_tap_behavior = DT_INST_PROP(n, retro_tap_behavior), \ + .retro_tap_param1 = DT_INST_PROP(n, retro_tap_param1), \ + .retro_tap_param2 = DT_INST_PROP(n, retro_tap_param2), \ .hold_trigger_on_release = DT_INST_PROP(n, hold_trigger_on_release), \ .hold_trigger_key_positions = DT_INST_PROP(n, hold_trigger_key_positions), \ .hold_trigger_key_positions_len = DT_INST_PROP_LEN(n, hold_trigger_key_positions), \ diff --git a/docs/docs/behaviors/hold-tap.md b/docs/docs/behaviors/hold-tap.md index f0096606..6c4a126a 100644 --- a/docs/docs/behaviors/hold-tap.md +++ b/docs/docs/behaviors/hold-tap.md @@ -84,6 +84,32 @@ For example, if you press `&mt LEFT_SHIFT A` and then release it without pressin }; ``` +To define a behavior to use instead of the tap behavior, include `retro-tap-behavior`, `retro-tap-param1`, and/or `retro-tap-param2` in your hold-tap definition. + +- `retro-tap-behavior` refers to the label string of the desired behavior. See below for a list of these label strings for built-in behaviors. +- `retro-tap-param1` refers to the first thing that comes after the behavior in your keymap. e.g. for `&mt LSHFT A`, LSHFT will be param1. +- `retro-tap-param2` refers to the second thing that comes after the behavior in your keymap. e.g. for `&mt LSHFT A`, A will be param2. + +List of built-in behaviors and their corresponding label strings: + +- &bl - "BCKLGHT" +- &bt - "BLUETOOTH" +- &caps_word - "CAPS_WORD" +- &ext_power - "EXTPOWER" +- &gresc - "GRAVE_ESCAPE" +- &kp - "KEY_PRESS" +- &key_repeat - "KEY_REPEAT" +- &none - "NONE" +- &out - "OUTPUTS" +- &reset - "RESET" +- &bootloader - "BOOTLOAD" +- &rgb_ug - "RGB_UG" +- &sk - "STICKY_KEY" +- &sl - "STICKY_LAYER" +- &to - "TO_LAYER" +- &tog - "TOGGLE_LAYER" +- &trans - "TRANS" + #### Positional hold-tap and `hold-trigger-key-positions` Including `hold-trigger-key-positions` in your hold-tap definition turns on the positional hold-tap feature. With positional hold-tap enabled, if you press any key **NOT** listed in `hold-trigger-key-positions` before `tapping-term-ms` expires, it will produce a tap.