From e1fbf6f13dce7e7c9e6cb5b95b25c6a9e140727e Mon Sep 17 00:00:00 2001 From: Ilya Zhuravlev Date: Sat, 2 Apr 2022 16:39:12 -0600 Subject: [PATCH] qmk_settings: wrap TAPPING_TOGGLE --- quantum/action.c | 10 +++++----- quantum/process_keycode/process_haptic.c | 3 ++- quantum/qmk_settings.c | 2 ++ quantum/qmk_settings.h | 10 +++++++++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/quantum/action.c b/quantum/action.c index 0f9ea2120a..6403d4b664 100644 --- a/quantum/action.c +++ b/quantum/action.c @@ -392,11 +392,11 @@ if (QS_oneshot_tap_toggle > 1) { # endif case MODS_TAP_TOGGLE: if (event.pressed) { - if (tap_count <= TAPPING_TOGGLE) { + if (tap_count <= QS_tapping_toggle) { register_mods(mods); } } else { - if (tap_count < TAPPING_TOGGLE) { + if (tap_count < QS_tapping_toggle) { unregister_mods(mods); } } @@ -549,11 +549,11 @@ if (QS_oneshot_tap_toggle > 1) { case OP_TAP_TOGGLE: /* tap toggle */ if (event.pressed) { - if (tap_count < TAPPING_TOGGLE) { + if (tap_count < QS_tapping_toggle) { layer_invert(action.layer_tap.val); } } else { - if (tap_count <= TAPPING_TOGGLE) { + if (tap_count <= QS_tapping_toggle) { layer_invert(action.layer_tap.val); } } @@ -688,7 +688,7 @@ if (QS_oneshot_tap_toggle > 1) { swap_hands = !swap_hands; } } else { - if (tap_count < TAPPING_TOGGLE) { + if (tap_count < QS_tapping_toggle) { swap_hands = !swap_hands; } } diff --git a/quantum/process_keycode/process_haptic.c b/quantum/process_keycode/process_haptic.c index 0f07f9ac75..a17dbb3d1f 100644 --- a/quantum/process_keycode/process_haptic.c +++ b/quantum/process_keycode/process_haptic.c @@ -18,6 +18,7 @@ #include "quantum_keycodes.h" #include "action_tapping.h" #include "usb_device_state.h" +#include "qmk_settings.h" __attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record) { switch (keycode) { @@ -26,7 +27,7 @@ __attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t if (record->tap.count == 0) return false; break; case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX: - if (record->tap.count != TAPPING_TOGGLE) return false; + if (record->tap.count != QS_tapping_toggle) return false; break; case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: if (record->tap.count == 0) return false; diff --git a/quantum/qmk_settings.c b/quantum/qmk_settings.c index 6bb11f866d..9d20b1bda5 100644 --- a/quantum/qmk_settings.c +++ b/quantum/qmk_settings.c @@ -54,6 +54,7 @@ static const qmk_settings_proto_t protos[] PROGMEM = { #endif DECLARE_SETTING(18, tap_code_delay), DECLARE_SETTING(19, tap_hold_caps_delay), + DECLARE_SETTING(20, tapping_toggle), }; static const qmk_settings_proto_t *find_setting(uint16_t qsid) { @@ -116,6 +117,7 @@ void qmk_settings_reset(void) { QS.tapping = 0; QS.tap_code_delay = TAP_CODE_DELAY; QS.tap_hold_caps_delay = TAP_HOLD_CAPS_DELAY; + QS.tapping_toggle = TAPPING_TOGGLE; save_settings(); /* to trigger all callbacks */ diff --git a/quantum/qmk_settings.h b/quantum/qmk_settings.h index 4ce67103c3..15ee483b96 100644 --- a/quantum/qmk_settings.h +++ b/quantum/qmk_settings.h @@ -120,8 +120,10 @@ typedef struct { uint8_t tapping; uint16_t tap_code_delay; uint16_t tap_hold_caps_delay; + uint8_t tapping_toggle; + uint8_t unused; } qmk_settings_t; -_Static_assert(sizeof(qmk_settings_t) == 34, "unexpected size of the qmk_settings_t structure"); +_Static_assert(sizeof(qmk_settings_t) == 36, "unexpected size of the qmk_settings_t structure"); typedef void (*qmk_setting_callback_t)(void); @@ -170,6 +172,9 @@ extern qmk_settings_t QS; #define QS_tap_code_delay (QS.tap_code_delay) #define QS_tap_hold_caps_delay (QS.tap_hold_caps_delay) +/* Tapping Toggle */ +#define QS_tapping_toggle (QS.tapping_toggle) + #else /* dynamic settings framework is disabled => hardcode the settings and let the compiler optimize extra branches out */ @@ -202,6 +207,9 @@ extern qmk_settings_t QS; #define QS_tap_code_delay TAP_CODE_DELAY #define QS_tap_hold_caps_delay TAP_HOLD_CAPS_DELAY +/* Tapping Toggle */ +#define QS_tapping_toggle TAPPING_TOGGLE + #endif #if defined(__AVR__) && defined(QMK_SETTINGS)