From 8844fba607fd73696f172ddf8d6c5868bb843359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=BC=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=83=91=E3=83=BC?= <76888457+filterpaper@users.noreply.github.com> Date: Sat, 12 Oct 2024 07:13:31 +0800 Subject: [PATCH] Update combo user function variable (#24467) --- docs/features/combo.md | 26 ++++++++++++++++--------- quantum/process_keycode/process_combo.c | 6 +++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/docs/features/combo.md b/docs/features/combo.md index 10e33b72a63..afe202ad54a 100644 --- a/docs/features/combo.md +++ b/docs/features/combo.md @@ -152,14 +152,15 @@ In order to use these features, the following configuration options and function | Config Flag | Function | Description | |-----------------------------|-----------------------------------------------------------|--------------------------------------------------------------------------------------------------------| -| `COMBO_TERM_PER_COMBO` | uint16_t get_combo_term(uint16_t index, combo_t \*combo) | Optional per-combo timeout window. (default: `COMBO_TERM`) | -| `COMBO_MUST_HOLD_PER_COMBO` | bool get_combo_must_hold(uint16_t index, combo_t \*combo) | Controls if a given combo should fire immediately on tap or if it needs to be held. (default: `false`) | -| `COMBO_MUST_TAP_PER_COMBO` | bool get_combo_must_tap(uint16_t index, combo_t \*combo) | Controls if a given combo should fire only if tapped within `COMBO_HOLD_TERM`. (default: `false`) | -| `COMBO_MUST_PRESS_IN_ORDER_PER_COMBO` | bool get_combo_must_press_in_order(uint16_t index, combo_t \*combo) | Controls if a given combo should fire only if its keys are pressed in order. (default: `true`) | +| `COMBO_TERM_PER_COMBO` | `uint16_t get_combo_term(uint16_t combo_index, combo_t *combo)` | Optional per-combo timeout window. (default: `COMBO_TERM`) | +| `COMBO_MUST_HOLD_PER_COMBO` | `bool get_combo_must_hold(uint16_t combo_index, combo_t *combo)` | Controls if a given combo should fire immediately on tap or if it needs to be held. (default: `false`) | +| `COMBO_MUST_TAP_PER_COMBO` | `bool get_combo_must_tap(uint16_t combo_index, combo_t *combo)` | Controls if a given combo should fire only if tapped within `COMBO_HOLD_TERM`. (default: `false`) | +| `COMBO_MUST_PRESS_IN_ORDER_PER_COMBO` | `bool get_combo_must_press_in_order(uint16_t combo_index, combo_t *combo)` | Controls if a given combo should fire only if its keys are pressed in order. (default: `true`) | Examples: ```c -uint16_t get_combo_term(uint16_t index, combo_t *combo) { +#ifdef COMBO_TERM_PER_COMBO +uint16_t get_combo_term(uint16_t combo_index, combo_t *combo) { // decide by combo->keycode switch (combo->keycode) { case KC_X: @@ -167,7 +168,7 @@ uint16_t get_combo_term(uint16_t index, combo_t *combo) { } // or with combo index, i.e. its name from enum. - switch (index) { + switch (combo_index) { case COMBO_NAME_HERE: return 9001; } @@ -182,8 +183,10 @@ uint16_t get_combo_term(uint16_t index, combo_t *combo) { return COMBO_TERM; } +#endif -bool get_combo_must_hold(uint16_t index, combo_t *combo) { +#ifdef COMBO_MUST_HOLD_PER_COMBO +bool get_combo_must_hold(uint16_t combo_index, combo_t *combo) { // Same as above, decide by keycode, the combo index, or by the keys in the chord. if (KEYCODE_IS_MOD(combo->keycode) || @@ -192,15 +195,17 @@ bool get_combo_must_hold(uint16_t index, combo_t *combo) { return true; } - switch (index) { + switch (combo_index) { case COMBO_NAME_HERE: return true; } return false; } +#endif -bool get_combo_must_tap(uint16_t index, combo_t *combo) { +#ifdef COMBO_MUST_TAP_PER_COMBO +bool get_combo_must_tap(uint16_t combo_index, combo_t *combo) { // If you want all combos to be tap-only, just uncomment the next line // return true @@ -219,7 +224,9 @@ bool get_combo_must_tap(uint16_t index, combo_t *combo) { return false; } +#endif +#ifdef COMBO_MUST_PRESS_IN_ORDER_PER_COMBO bool get_combo_must_press_in_order(uint16_t combo_index, combo_t *combo) { switch (combo_index) { /* List combos here that you want to only activate if their keys @@ -231,6 +238,7 @@ bool get_combo_must_press_in_order(uint16_t combo_index, combo_t *combo) { return false; } } +#endif ``` ### Generic hook to (dis)allow a combo activation diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index 38171c2f54b..c99a66a74b0 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -36,19 +36,19 @@ __attribute__((weak)) uint8_t combo_ref_from_layer(uint8_t layer) { #endif #ifdef COMBO_MUST_HOLD_PER_COMBO -__attribute__((weak)) bool get_combo_must_hold(uint16_t index, combo_t *combo) { +__attribute__((weak)) bool get_combo_must_hold(uint16_t combo_index, combo_t *combo) { return false; } #endif #ifdef COMBO_MUST_TAP_PER_COMBO -__attribute__((weak)) bool get_combo_must_tap(uint16_t index, combo_t *combo) { +__attribute__((weak)) bool get_combo_must_tap(uint16_t combo_index, combo_t *combo) { return false; } #endif #ifdef COMBO_TERM_PER_COMBO -__attribute__((weak)) uint16_t get_combo_term(uint16_t index, combo_t *combo) { +__attribute__((weak)) uint16_t get_combo_term(uint16_t combo_index, combo_t *combo) { return COMBO_TERM; } #endif