qmk_settings: wrap TAP_CODE_DELAY and TAP_HOLD_CAPS_DELAY

This commit is contained in:
Ilya Zhuravlev
2021-07-08 23:02:17 -04:00
parent a284336819
commit fa26d6e1bc
6 changed files with 33 additions and 24 deletions

View File

@ -110,9 +110,7 @@ if (QS_auto_shift_repeat && !QS_auto_shift_no_auto_repeat) {
} }
} }
# if TAP_CODE_DELAY > 0 wait_ms(QS_tap_code_delay);
wait_ms(TAP_CODE_DELAY);
# endif
unregister_code(autoshift_lastkey); unregister_code(autoshift_lastkey);
del_weak_mods(MOD_BIT(KC_LSFT)); del_weak_mods(MOD_BIT(KC_LSFT));
} else { } else {

View File

@ -48,6 +48,8 @@ static const qmk_settings_proto_t protos[] PROGMEM = {
DECLARE_SETTING_CB(15, mousekey_wheel_interval, mousekey_apply), DECLARE_SETTING_CB(15, mousekey_wheel_interval, mousekey_apply),
DECLARE_SETTING_CB(16, mousekey_wheel_max_speed, mousekey_apply), DECLARE_SETTING_CB(16, mousekey_wheel_max_speed, mousekey_apply),
DECLARE_SETTING_CB(17, mousekey_wheel_time_to_max, mousekey_apply), DECLARE_SETTING_CB(17, mousekey_wheel_time_to_max, mousekey_apply),
DECLARE_SETTING(18, tap_code_delay),
DECLARE_SETTING(19, tap_hold_caps_delay),
}; };
static const qmk_settings_proto_t *find_setting(uint16_t qsid) { static const qmk_settings_proto_t *find_setting(uint16_t qsid) {
@ -106,6 +108,8 @@ void qmk_settings_reset(void) {
QS.combo_term = COMBO_TERM; QS.combo_term = COMBO_TERM;
QS.tapping_term = TAPPING_TERM; QS.tapping_term = TAPPING_TERM;
QS.tapping = 0; QS.tapping = 0;
QS.tap_code_delay = TAP_CODE_DELAY;
QS.tap_hold_caps_delay = TAP_HOLD_CAPS_DELAY;
save_settings(); save_settings();
/* to trigger all callbacks */ /* to trigger all callbacks */

View File

@ -5,6 +5,13 @@
/* take qmk config macros and set up helper variables for default settings */ /* take qmk config macros and set up helper variables for default settings */
#ifndef TAP_CODE_DELAY
# define TAP_CODE_DELAY 0
#endif
#ifndef TAP_HOLD_CAPS_DELAY
# define TAP_HOLD_CAPS_DELAY 80
#endif
/* ========================================================================== */ /* ========================================================================== */
/* Grave escape */ /* Grave escape */
/* ========================================================================== */ /* ========================================================================== */
@ -111,8 +118,10 @@ typedef struct {
uint8_t auto_shift; uint8_t auto_shift;
uint8_t osk_tap_toggle; uint8_t osk_tap_toggle;
uint8_t tapping; uint8_t tapping;
uint16_t tap_code_delay;
uint16_t tap_hold_caps_delay;
} qmk_settings_t; } qmk_settings_t;
_Static_assert(sizeof(qmk_settings_t) == 30, "unexpected size of the qmk_settings_t structure"); _Static_assert(sizeof(qmk_settings_t) == 34, "unexpected size of the qmk_settings_t structure");
typedef void (*qmk_setting_callback_t)(void); typedef void (*qmk_setting_callback_t)(void);
@ -157,6 +166,10 @@ extern qmk_settings_t QS;
/* Combo */ /* Combo */
#define QS_combo_term (QS.combo_term) #define QS_combo_term (QS.combo_term)
/* Tap delays */
#define QS_tap_code_delay (QS.tap_code_delay)
#define QS_tap_hold_caps_delay (QS.tap_hold_caps_delay)
#else #else
/* dynamic settings framework is disabled => hardcode the settings and let the compiler optimize extra branches out */ /* dynamic settings framework is disabled => hardcode the settings and let the compiler optimize extra branches out */
@ -185,4 +198,8 @@ extern qmk_settings_t QS;
/* Combo */ /* Combo */
#define QS_combo_term COMBO_TERM #define QS_combo_term COMBO_TERM
/* Tap delays */
#define QS_tap_code_delay TAP_CODE_DELAY
#define QS_tap_hold_caps_delay TAP_HOLD_CAPS_DELAY
#endif #endif

View File

@ -16,6 +16,7 @@
#include "quantum.h" #include "quantum.h"
#include "magic.h" #include "magic.h"
#include "qmk_settings.h"
#ifdef BLUETOOTH_ENABLE #ifdef BLUETOOTH_ENABLE
# include "outputselect.h" # include "outputselect.h"
@ -107,9 +108,7 @@ void unregister_code16(uint16_t code) {
void tap_code16(uint16_t code) { void tap_code16(uint16_t code) {
register_code16(code); register_code16(code);
#if TAP_CODE_DELAY > 0 wait_ms(QS_tap_code_delay);
wait_ms(TAP_CODE_DELAY);
#endif
unregister_code16(code); unregister_code16(code);
} }

View File

@ -286,11 +286,7 @@ static void vial_keycode_tap(uint16_t keycode) __attribute__((unused));
static void vial_keycode_tap(uint16_t keycode) { static void vial_keycode_tap(uint16_t keycode) {
vial_keycode_down(keycode); vial_keycode_down(keycode);
wait_ms(QS_tap_code_delay);
#if TAP_CODE_DELAY > 0
wait_ms(TAP_CODE_DELAY);
#endif
vial_keycode_up(keycode); vial_keycode_up(keycode);
} }
@ -429,6 +425,7 @@ static void on_dance_reset(qk_tap_dance_state_t *state, void *user_data) {
uint8_t index = (uintptr_t)user_data; uint8_t index = (uintptr_t)user_data;
if (dynamic_keymap_get_tap_dance(index, &td_entry) != 0) if (dynamic_keymap_get_tap_dance(index, &td_entry) != 0)
return; return;
wait_ms(QS_tap_code_delay);
uint8_t st = dance_state[index]; uint8_t st = dance_state[index];
state->count = 0; state->count = 0;
dance_state[index] = 0; dance_state[index] = 0;

View File

@ -56,12 +56,6 @@ __attribute__((weak)) bool get_ignore_mod_tap_interrupt(uint16_t keycode, keyrec
__attribute__((weak)) bool get_retro_tapping(uint16_t keycode, keyrecord_t *record) { return false; } __attribute__((weak)) bool get_retro_tapping(uint16_t keycode, keyrecord_t *record) { return false; }
#endif #endif
#ifndef TAP_CODE_DELAY
# define TAP_CODE_DELAY 0
#endif
#ifndef TAP_HOLD_CAPS_DELAY
# define TAP_HOLD_CAPS_DELAY 80
#endif
/** \brief Called to execute an action. /** \brief Called to execute an action.
* *
* FIXME: Needs documentation. * FIXME: Needs documentation.
@ -370,9 +364,9 @@ if (QS_oneshot_tap_toggle > 1) {
if (tap_count > 0) { if (tap_count > 0) {
dprint("MODS_TAP: Tap: unregister_code\n"); dprint("MODS_TAP: Tap: unregister_code\n");
if (action.layer_tap.code == KC_CAPS) { if (action.layer_tap.code == KC_CAPS) {
wait_ms(TAP_HOLD_CAPS_DELAY); wait_ms(QS_tap_hold_caps_delay);
} else { } else {
wait_ms(TAP_CODE_DELAY); wait_ms(QS_tap_code_delay);
} }
unregister_code(action.key.code); unregister_code(action.key.code);
} else { } else {
@ -595,9 +589,9 @@ if (QS_oneshot_tap_toggle > 1) {
if (tap_count > 0) { if (tap_count > 0) {
dprint("KEYMAP_TAP_KEY: Tap: unregister_code\n"); dprint("KEYMAP_TAP_KEY: Tap: unregister_code\n");
if (action.layer_tap.code == KC_CAPS) { if (action.layer_tap.code == KC_CAPS) {
wait_ms(TAP_HOLD_CAPS_DELAY); wait_ms(QS_tap_hold_caps_delay);
} else { } else {
wait_ms(TAP_CODE_DELAY); wait_ms(QS_tap_code_delay);
} }
unregister_code(action.layer_tap.code); unregister_code(action.layer_tap.code);
} else { } else {
@ -676,7 +670,7 @@ if (QS_oneshot_tap_toggle > 1) {
if (event.pressed) { if (event.pressed) {
register_code(action.swap.code); register_code(action.swap.code);
} else { } else {
wait_ms(TAP_CODE_DELAY); wait_ms(QS_tap_code_delay);
unregister_code(action.swap.code); unregister_code(action.swap.code);
*record = (keyrecord_t){}; // hack: reset tap mode *record = (keyrecord_t){}; // hack: reset tap mode
} }
@ -932,7 +926,7 @@ void tap_code_delay(uint8_t code, uint16_t delay) {
* *
* \param code The basic keycode to tap. If `code` is `KC_CAPS`, the delay will be `TAP_HOLD_CAPS_DELAY`, otherwise `TAP_CODE_DELAY`, if defined. * \param code The basic keycode to tap. If `code` is `KC_CAPS`, the delay will be `TAP_HOLD_CAPS_DELAY`, otherwise `TAP_CODE_DELAY`, if defined.
*/ */
void tap_code(uint8_t code) { tap_code_delay(code, code == KC_CAPS ? TAP_HOLD_CAPS_DELAY : TAP_CODE_DELAY); } void tap_code(uint8_t code) { tap_code_delay(code, code == KC_CAPS ? QS_tap_hold_caps_delay : QS_tap_code_delay); }
/** \brief Adds the given physically pressed modifiers and sends a keyboard report immediately. /** \brief Adds the given physically pressed modifiers and sends a keyboard report immediately.
* *