diff options
| author | Jouke Witteveen <j.witteveen@gmail.com> | 2022-04-16 20:24:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-16 11:24:09 -0700 |
| commit | 8f585153c470b07bb0c529ff49b39ef45f68d37e (patch) | |
| tree | 5441986fa041cd2d966b800af3f82d69b55e4d58 /quantum/action_tapping.c | |
| parent | cad0af09a8a280d918b726eb472c86065dc5c079 (diff) | |
Add GET_TAPPING_TERM macro to reduce duplicate code (#16681)
* Add GET_TAPPING_TERM macro to reduce duplicate code
The macro gives the right tapping term depending on whether per-key
tapping terms and/or dynamic tapping terms are enabled. Unnecessary
function calls and variable resolution are avoided.
Fixes #16472.
* Use GET_TAPPING_TERM for Cirque trackpads
Co-authored-by: Stefan Kerkmann <karlk90@pm.me>
Diffstat (limited to 'quantum/action_tapping.c')
| -rw-r--r-- | quantum/action_tapping.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/quantum/action_tapping.c b/quantum/action_tapping.c index e436619428..3c8b5678b7 100644 --- a/quantum/action_tapping.c +++ b/quantum/action_tapping.c | |||
| @@ -24,17 +24,20 @@ | |||
| 24 | # else | 24 | # else |
| 25 | # define IS_TAPPING_RECORD(r) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (r->event.key)) && tapping_key.keycode == r->keycode) | 25 | # define IS_TAPPING_RECORD(r) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (r->event.key)) && tapping_key.keycode == r->keycode) |
| 26 | # endif | 26 | # endif |
| 27 | # define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < GET_TAPPING_TERM(get_record_keycode(&tapping_key, false), &tapping_key)) | ||
| 27 | 28 | ||
| 29 | # ifdef DYNAMIC_TAPPING_TERM_ENABLE | ||
| 28 | uint16_t g_tapping_term = TAPPING_TERM; | 30 | uint16_t g_tapping_term = TAPPING_TERM; |
| 31 | # endif | ||
| 29 | 32 | ||
| 33 | # ifdef TAPPING_TERM_PER_KEY | ||
| 30 | __attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { | 34 | __attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { |
| 35 | # ifdef DYNAMIC_TAPPING_TERM_ENABLE | ||
| 31 | return g_tapping_term; | 36 | return g_tapping_term; |
| 37 | # else | ||
| 38 | return TAPPING_TERM; | ||
| 39 | # endif | ||
| 32 | } | 40 | } |
| 33 | |||
| 34 | # ifdef TAPPING_TERM_PER_KEY | ||
| 35 | # define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_record_keycode(&tapping_key, false), &tapping_key)) | ||
| 36 | # else | ||
| 37 | # define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < g_tapping_term) | ||
| 38 | # endif | 41 | # endif |
| 39 | 42 | ||
| 40 | # ifdef TAPPING_FORCE_HOLD_PER_KEY | 43 | # ifdef TAPPING_FORCE_HOLD_PER_KEY |
| @@ -165,15 +168,7 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 165 | else if ( | 168 | else if ( |
| 166 | ( | 169 | ( |
| 167 | ( | 170 | ( |
| 168 | ( | 171 | GET_TAPPING_TERM(tapping_keycode, &tapping_key) >= 500 |
| 169 | # ifdef TAPPING_TERM_PER_KEY | ||
| 170 | get_tapping_term(tapping_keycode, &tapping_key) | ||
| 171 | # else | ||
| 172 | g_tapping_term | ||
| 173 | # endif | ||
| 174 | >= 500 | ||
| 175 | ) | ||
| 176 | |||
| 177 | # ifdef PERMISSIVE_HOLD_PER_KEY | 172 | # ifdef PERMISSIVE_HOLD_PER_KEY |
| 178 | || get_permissive_hold(tapping_keycode, &tapping_key) | 173 | || get_permissive_hold(tapping_keycode, &tapping_key) |
| 179 | # elif defined(PERMISSIVE_HOLD) | 174 | # elif defined(PERMISSIVE_HOLD) |
