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 | |
| parent | 1fb02d5ad87e69d459ae63235bbb3057083866ef (diff) | |
Improve test invocation, fix Retro Shift bugs, and add Auto+Retro Shift test cases (#15889)
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/action.c | 2 | ||||
| -rw-r--r-- | quantum/action_tapping.c | 78 | ||||
| -rw-r--r-- | quantum/process_keycode/process_auto_shift.c | 29 | ||||
| -rw-r--r-- | quantum/process_keycode/process_auto_shift.h | 1 |
4 files changed, 58 insertions, 52 deletions
diff --git a/quantum/action.c b/quantum/action.c index 6368f7398c..3b89431cea 100644 --- a/quantum/action.c +++ b/quantum/action.c | |||
| @@ -497,7 +497,7 @@ void process_action(keyrecord_t *record, action_t action) { | |||
| 497 | default: | 497 | default: |
| 498 | if (event.pressed) { | 498 | if (event.pressed) { |
| 499 | if (tap_count > 0) { | 499 | if (tap_count > 0) { |
| 500 | # ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY | 500 | # ifdef HOLD_ON_OTHER_KEY_PRESS |
| 501 | if ( | 501 | if ( |
| 502 | # ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY | 502 | # ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY |
| 503 | get_hold_on_other_key_press(get_event_keycode(record->event, false), record) && | 503 | get_hold_on_other_key_press(get_event_keycode(record->event, false), record) && |
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); |
diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index 9b78214e43..28a21c4b67 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c | |||
| @@ -66,7 +66,7 @@ __attribute__((weak)) bool get_custom_auto_shifted_key(uint16_t keycode, keyreco | |||
| 66 | return false; | 66 | return false; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | /** \brief Called on physical press, returns whether is Auto Shift key */ | 69 | /** \brief Called on physical press, returns whether key is an Auto Shift key */ |
| 70 | __attribute__((weak)) bool get_auto_shifted_key(uint16_t keycode, keyrecord_t *record) { | 70 | __attribute__((weak)) bool get_auto_shifted_key(uint16_t keycode, keyrecord_t *record) { |
| 71 | switch (keycode) { | 71 | switch (keycode) { |
| 72 | #ifndef NO_AUTO_SHIFT_ALPHA | 72 | #ifndef NO_AUTO_SHIFT_ALPHA |
| @@ -178,9 +178,8 @@ static bool autoshift_press(uint16_t keycode, uint16_t now, keyrecord_t *record) | |||
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | // Store record to be sent to user functions if there's no release record then. | 180 | // Store record to be sent to user functions if there's no release record then. |
| 181 | autoshift_lastrecord = *record; | 181 | autoshift_lastrecord = *record; |
| 182 | autoshift_lastrecord.event.pressed = false; | 182 | autoshift_lastrecord.event.time = 0; |
| 183 | autoshift_lastrecord.event.time = 0; | ||
| 184 | // clang-format off | 183 | // clang-format off |
| 185 | #if defined(AUTO_SHIFT_REPEAT) || defined(AUTO_SHIFT_REPEAT_PER_KEY) | 184 | #if defined(AUTO_SHIFT_REPEAT) || defined(AUTO_SHIFT_REPEAT_PER_KEY) |
| 186 | if (keycode == autoshift_lastkey && | 185 | if (keycode == autoshift_lastkey && |
| @@ -409,8 +408,12 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { | |||
| 409 | // If Retro Shift is disabled, possible custom actions shouldn't happen. | 408 | // If Retro Shift is disabled, possible custom actions shouldn't happen. |
| 410 | // clang-format off | 409 | // clang-format off |
| 411 | #if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING) | 410 | #if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING) |
| 412 | # ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY | 411 | # ifdef HOLD_ON_OTHER_KEY_PRESS |
| 413 | const bool is_hold_on_interrupt = get_hold_on_other_key_press(keycode, record); | 412 | const bool is_hold_on_interrupt = (IS_QK_MOD_TAP(keycode) |
| 413 | # ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY | ||
| 414 | && get_hold_on_other_key_press(keycode, record) | ||
| 415 | # endif | ||
| 416 | ); | ||
| 414 | # else | 417 | # else |
| 415 | const bool is_hold_on_interrupt = false; | 418 | const bool is_hold_on_interrupt = false; |
| 416 | # endif | 419 | # endif |
| @@ -450,8 +453,12 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { | |||
| 450 | #endif | 453 | #endif |
| 451 | ) { | 454 | ) { |
| 452 | // Fixes modifiers not being applied to rolls with AUTO_SHIFT_MODIFIERS set. | 455 | // Fixes modifiers not being applied to rolls with AUTO_SHIFT_MODIFIERS set. |
| 453 | #ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY | 456 | #ifdef HOLD_ON_OTHER_KEY_PRESS |
| 454 | if (autoshift_flags.in_progress && get_hold_on_other_key_press(keycode, record)) { | 457 | if (autoshift_flags.in_progress |
| 458 | # ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY | ||
| 459 | && get_hold_on_other_key_press(keycode, record) | ||
| 460 | # endif | ||
| 461 | ) { | ||
| 455 | autoshift_end(KC_NO, now, false, &autoshift_lastrecord); | 462 | autoshift_end(KC_NO, now, false, &autoshift_lastrecord); |
| 456 | } | 463 | } |
| 457 | #endif | 464 | #endif |
| @@ -488,10 +495,8 @@ void retroshift_poll_time(keyevent_t *event) { | |||
| 488 | } | 495 | } |
| 489 | // Used to swap the times of Retro Shifted key and Auto Shift key that interrupted it. | 496 | // Used to swap the times of Retro Shifted key and Auto Shift key that interrupted it. |
| 490 | void retroshift_swap_times(void) { | 497 | void retroshift_swap_times(void) { |
| 491 | if (last_retroshift_time != 0 && autoshift_flags.in_progress) { | 498 | if (autoshift_flags.in_progress) { |
| 492 | uint16_t temp = retroshift_time; | 499 | autoshift_time = last_retroshift_time; |
| 493 | retroshift_time = last_retroshift_time; | ||
| 494 | last_retroshift_time = temp; | ||
| 495 | } | 500 | } |
| 496 | } | 501 | } |
| 497 | #endif | 502 | #endif |
diff --git a/quantum/process_keycode/process_auto_shift.h b/quantum/process_keycode/process_auto_shift.h index 885a47b533..1353548aa6 100644 --- a/quantum/process_keycode/process_auto_shift.h +++ b/quantum/process_keycode/process_auto_shift.h | |||
| @@ -56,4 +56,5 @@ uint16_t (get_autoshift_timeout)(uint16_t keycode, keyrecord_t *record); | |||
| 56 | void set_autoshift_timeout(uint16_t timeout); | 56 | void set_autoshift_timeout(uint16_t timeout); |
| 57 | void autoshift_matrix_scan(void); | 57 | void autoshift_matrix_scan(void); |
| 58 | bool get_custom_auto_shifted_key(uint16_t keycode, keyrecord_t *record); | 58 | bool get_custom_auto_shifted_key(uint16_t keycode, keyrecord_t *record); |
| 59 | bool get_auto_shifted_key(uint16_t keycode, keyrecord_t *record); | ||
| 59 | // clang-format on | 60 | // clang-format on |
