diff options
| author | Isaac Elenbaas <isaacelenbaas@gmail.com> | 2023-09-24 22:45:49 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-25 12:45:49 +1000 |
| commit | dd94877ec6d2ee5c4cdb0e71287abd76585b0268 (patch) | |
| tree | 26ded3ce8338286243d1b59d597f41329fea6ef4 /quantum/action_tapping.c | |
| parent | 1fb02d5ad87e69d459ae63235bbb3057083866ef (diff) | |
Improve test invocation, fix Retro Shift bugs, and add Auto+Retro Shift test cases (#15889)
Diffstat (limited to 'quantum/action_tapping.c')
| -rw-r--r-- | quantum/action_tapping.c | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/quantum/action_tapping.c b/quantum/action_tapping.c index f94e5e6f69..8f238490f2 100644 --- a/quantum/action_tapping.c +++ b/quantum/action_tapping.c | |||
| @@ -116,25 +116,26 @@ void action_tapping_process(keyrecord_t record) { | |||
| 116 | * readable. The conditional definition of tapping_keycode and all the | 116 | * readable. The conditional definition of tapping_keycode and all the |
| 117 | * conditional uses of it are hidden inside macros named TAP_... | 117 | * conditional uses of it are hidden inside macros named TAP_... |
| 118 | */ | 118 | */ |
| 119 | # if (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)) || defined(PERMISSIVE_HOLD_PER_KEY) || defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) | 119 | # define TAP_DEFINE_KEYCODE const uint16_t tapping_keycode = get_record_keycode(&tapping_key, false) |
| 120 | # define TAP_DEFINE_KEYCODE const uint16_t tapping_keycode = get_record_keycode(&tapping_key, false) | ||
| 121 | # else | ||
| 122 | # define TAP_DEFINE_KEYCODE | ||
| 123 | # endif | ||
| 124 | 120 | ||
| 125 | # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) | 121 | # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) |
| 126 | # ifdef RETRO_TAPPING_PER_KEY | 122 | # ifdef RETRO_TAPPING_PER_KEY |
| 127 | # define TAP_GET_RETRO_TAPPING get_retro_tapping(tapping_keycode, &tapping_key) | 123 | # define TAP_GET_RETRO_TAPPING(keyp) get_auto_shifted_key(tapping_keycode, keyp) && get_retro_tapping(tapping_keycode, &tapping_key) |
| 128 | # else | 124 | # else |
| 129 | # define TAP_GET_RETRO_TAPPING true | 125 | # define TAP_GET_RETRO_TAPPING(keyp) get_auto_shifted_key(tapping_keycode, keyp) |
| 130 | # endif | 126 | # endif |
| 131 | # define MAYBE_RETRO_SHIFTING(ev) (TAP_GET_RETRO_TAPPING && (RETRO_SHIFT + 0) != 0 && TIMER_DIFF_16((ev).time, tapping_key.event.time) < (RETRO_SHIFT + 0)) | 127 | /* Used to extend TAPPING_TERM: |
| 128 | * indefinitely if RETRO_SHIFT does not have a value | ||
| 129 | * to RETRO_SHIFT if RETRO_SHIFT is set | ||
| 130 | * for possibly retro shifted keys. | ||
| 131 | */ | ||
| 132 | # define MAYBE_RETRO_SHIFTING(ev, keyp) (get_auto_shifted_key(tapping_keycode, keyp) && TAP_GET_RETRO_TAPPING(keyp) && ((RETRO_SHIFT + 0) == 0 || TIMER_DIFF_16((ev).time, tapping_key.event.time) < (RETRO_SHIFT + 0))) | ||
| 132 | # define TAP_IS_LT IS_QK_LAYER_TAP(tapping_keycode) | 133 | # define TAP_IS_LT IS_QK_LAYER_TAP(tapping_keycode) |
| 133 | # define TAP_IS_MT IS_QK_MOD_TAP(tapping_keycode) | 134 | # define TAP_IS_MT IS_QK_MOD_TAP(tapping_keycode) |
| 134 | # define TAP_IS_RETRO IS_RETRO(tapping_keycode) | 135 | # define TAP_IS_RETRO IS_RETRO(tapping_keycode) |
| 135 | # else | 136 | # else |
| 136 | # define TAP_GET_RETRO_TAPPING false | 137 | # define TAP_GET_RETRO_TAPPING(keyp) false |
| 137 | # define MAYBE_RETRO_SHIFTING(ev) false | 138 | # define MAYBE_RETRO_SHIFTING(ev, kp) false |
| 138 | # define TAP_IS_LT false | 139 | # define TAP_IS_LT false |
| 139 | # define TAP_IS_MT false | 140 | # define TAP_IS_MT false |
| 140 | # define TAP_IS_RETRO false | 141 | # define TAP_IS_RETRO false |
| @@ -187,20 +188,19 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 187 | return true; | 188 | return true; |
| 188 | } | 189 | } |
| 189 | 190 | ||
| 191 | # if (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)) || defined(PERMISSIVE_HOLD_PER_KEY) || defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) | ||
| 190 | TAP_DEFINE_KEYCODE; | 192 | TAP_DEFINE_KEYCODE; |
| 193 | # endif | ||
| 191 | 194 | ||
| 192 | // process "pressed" tapping key state | 195 | // process "pressed" tapping key state |
| 193 | if (tapping_key.event.pressed) { | 196 | if (tapping_key.event.pressed) { |
| 194 | if (WITHIN_TAPPING_TERM(event) || MAYBE_RETRO_SHIFTING(event)) { | 197 | if (WITHIN_TAPPING_TERM(event) || MAYBE_RETRO_SHIFTING(event, keyp)) { |
| 195 | if (IS_NOEVENT(event)) { | 198 | if (IS_NOEVENT(event)) { |
| 196 | // early return for tick events | 199 | // early return for tick events |
| 197 | return true; | 200 | return true; |
| 198 | } | 201 | } |
| 199 | if (tapping_key.tap.count == 0) { | 202 | if (tapping_key.tap.count == 0) { |
| 200 | if (IS_TAPPING_RECORD(keyp) && !event.pressed) { | 203 | if (IS_TAPPING_RECORD(keyp) && !event.pressed) { |
| 201 | # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) | ||
| 202 | retroshift_swap_times(); | ||
| 203 | # endif | ||
| 204 | // first tap! | 204 | // first tap! |
| 205 | ac_dprintf("Tapping: First tap(0->1).\n"); | 205 | ac_dprintf("Tapping: First tap(0->1).\n"); |
| 206 | tapping_key.tap.count = 1; | 206 | tapping_key.tap.count = 1; |
| @@ -218,28 +218,12 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 218 | */ | 218 | */ |
| 219 | // clang-format off | 219 | // clang-format off |
| 220 | else if ( | 220 | else if ( |
| 221 | !event.pressed && waiting_buffer_typed(event) && | ||
| 221 | ( | 222 | ( |
| 222 | !event.pressed && waiting_buffer_typed(event) && | 223 | TAP_GET_PERMISSIVE_HOLD || |
| 223 | TAP_GET_PERMISSIVE_HOLD | 224 | // Causes nested taps to not wait past TAPPING_TERM/RETRO_SHIFT |
| 224 | ) | 225 | // unnecessarily and fixes them for Layer Taps. |
| 225 | // Causes nested taps to not wait past TAPPING_TERM/RETRO_SHIFT | 226 | TAP_GET_RETRO_TAPPING(keyp) |
| 226 | // unnecessarily and fixes them for Layer Taps. | ||
| 227 | || (TAP_GET_RETRO_TAPPING && | ||
| 228 | ( | ||
| 229 | // Rolled over the two keys. | ||
| 230 | (tapping_key.tap.interrupted == true && ( | ||
| 231 | (TAP_IS_LT && TAP_GET_HOLD_ON_OTHER_KEY_PRESS) || | ||
| 232 | (TAP_IS_MT && TAP_GET_HOLD_ON_OTHER_KEY_PRESS) | ||
| 233 | ) | ||
| 234 | ) | ||
| 235 | // Makes Retro Shift ignore the default behavior of | ||
| 236 | // MTs and LTs on nested taps below TAPPING_TERM or RETRO_SHIFT | ||
| 237 | || ( | ||
| 238 | TAP_IS_RETRO | ||
| 239 | && (event.key.col != tapping_key.event.key.col || event.key.row != tapping_key.event.key.row) | ||
| 240 | && !event.pressed && waiting_buffer_typed(event) | ||
| 241 | ) | ||
| 242 | ) | ||
| 243 | ) | 227 | ) |
| 244 | ) { | 228 | ) { |
| 245 | // clang-format on | 229 | // clang-format on |
| @@ -284,10 +268,16 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 284 | process_record(keyp); | 268 | process_record(keyp); |
| 285 | return true; | 269 | return true; |
| 286 | } else { | 270 | } else { |
| 287 | // set interrupted flag when other key preesed during tapping | 271 | // set interrupted flag when other key pressed during tapping |
| 288 | if (event.pressed) { | 272 | if (event.pressed) { |
| 289 | tapping_key.tap.interrupted = true; | 273 | tapping_key.tap.interrupted = true; |
| 290 | if (TAP_GET_HOLD_ON_OTHER_KEY_PRESS) { | 274 | if (TAP_GET_HOLD_ON_OTHER_KEY_PRESS |
| 275 | # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) | ||
| 276 | // Auto Shift cannot evaluate this early | ||
| 277 | // Retro Shift uses the hold action for all nested taps even without HOLD_ON_OTHER_KEY_PRESS, so this is fine to skip | ||
| 278 | && !(MAYBE_RETRO_SHIFTING(event, keyp) && get_auto_shifted_key(get_record_keycode(keyp, false), keyp)) | ||
| 279 | # endif | ||
| 280 | ) { | ||
| 291 | ac_dprintf("Tapping: End. No tap. Interfered by pressed key\n"); | 281 | ac_dprintf("Tapping: End. No tap. Interfered by pressed key\n"); |
| 292 | process_record(&tapping_key); | 282 | process_record(&tapping_key); |
| 293 | tapping_key = (keyrecord_t){0}; | 283 | tapping_key = (keyrecord_t){0}; |
| @@ -332,6 +322,9 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 332 | return true; | 322 | return true; |
| 333 | } else { | 323 | } else { |
| 334 | ac_dprintf("Tapping: key event while last tap(>0).\n"); | 324 | ac_dprintf("Tapping: key event while last tap(>0).\n"); |
| 325 | # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) | ||
| 326 | retroshift_swap_times(); | ||
| 327 | # endif | ||
| 335 | process_record(keyp); | 328 | process_record(keyp); |
| 336 | return true; | 329 | return true; |
| 337 | } | 330 | } |
| @@ -388,7 +381,7 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 388 | } | 381 | } |
| 389 | // process "released" tapping key state | 382 | // process "released" tapping key state |
| 390 | else { | 383 | else { |
| 391 | if (WITHIN_TAPPING_TERM(event) || MAYBE_RETRO_SHIFTING(event)) { | 384 | if (WITHIN_TAPPING_TERM(event) || MAYBE_RETRO_SHIFTING(event, keyp)) { |
| 392 | if (IS_NOEVENT(event)) { | 385 | if (IS_NOEVENT(event)) { |
| 393 | // early return for tick events | 386 | // early return for tick events |
| 394 | return true; | 387 | return true; |
| @@ -506,9 +499,16 @@ void waiting_buffer_scan_tap(void) { | |||
| 506 | return; | 499 | return; |
| 507 | } | 500 | } |
| 508 | 501 | ||
| 502 | # if (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)) | ||
| 503 | TAP_DEFINE_KEYCODE; | ||
| 504 | # endif | ||
| 509 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { | 505 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { |
| 510 | keyrecord_t *candidate = &waiting_buffer[i]; | 506 | keyrecord_t *candidate = &waiting_buffer[i]; |
| 511 | if (IS_EVENT(candidate->event) && KEYEQ(candidate->event.key, tapping_key.event.key) && !candidate->event.pressed && WITHIN_TAPPING_TERM(candidate->event)) { | 507 | // clang-format off |
| 508 | if (IS_EVENT(candidate->event) && KEYEQ(candidate->event.key, tapping_key.event.key) && !candidate->event.pressed && ( | ||
| 509 | WITHIN_TAPPING_TERM(waiting_buffer[i].event) || MAYBE_RETRO_SHIFTING(waiting_buffer[i].event, &tapping_key) | ||
| 510 | )) { | ||
| 511 | // clang-format on | ||
| 512 | tapping_key.tap.count = 1; | 512 | tapping_key.tap.count = 1; |
| 513 | candidate->tap.count = 1; | 513 | candidate->tap.count = 1; |
| 514 | process_record(&tapping_key); | 514 | process_record(&tapping_key); |
