diff options
Diffstat (limited to 'quantum/action_tapping.c')
| -rw-r--r-- | quantum/action_tapping.c | 106 |
1 files changed, 93 insertions, 13 deletions
diff --git a/quantum/action_tapping.c b/quantum/action_tapping.c index 60e56fb81..0586fad42 100644 --- a/quantum/action_tapping.c +++ b/quantum/action_tapping.c | |||
| @@ -44,6 +44,10 @@ __attribute__((weak)) bool get_permissive_hold(uint16_t keycode, keyrecord_t *re | |||
| 44 | __attribute__((weak)) bool get_hold_on_other_key_press(uint16_t keycode, keyrecord_t *record) { return false; } | 44 | __attribute__((weak)) bool get_hold_on_other_key_press(uint16_t keycode, keyrecord_t *record) { return false; } |
| 45 | # endif | 45 | # endif |
| 46 | 46 | ||
| 47 | # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) | ||
| 48 | # include "process_auto_shift.h" | ||
| 49 | # endif | ||
| 50 | |||
| 47 | static keyrecord_t tapping_key = {}; | 51 | static keyrecord_t tapping_key = {}; |
| 48 | static keyrecord_t waiting_buffer[WAITING_BUFFER_SIZE] = {}; | 52 | static keyrecord_t waiting_buffer[WAITING_BUFFER_SIZE] = {}; |
| 49 | static uint8_t waiting_buffer_head = 0; | 53 | static uint8_t waiting_buffer_head = 0; |
| @@ -107,12 +111,29 @@ void action_tapping_process(keyrecord_t record) { | |||
| 107 | /* return true when key event is processed or consumed. */ | 111 | /* return true when key event is processed or consumed. */ |
| 108 | bool process_tapping(keyrecord_t *keyp) { | 112 | bool process_tapping(keyrecord_t *keyp) { |
| 109 | keyevent_t event = keyp->event; | 113 | keyevent_t event = keyp->event; |
| 114 | # if (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)) || defined(TAPPING_TERM_PER_KEY) || defined(PERMISSIVE_HOLD_PER_KEY) || defined(TAPPING_FORCE_HOLD_PER_KEY) || defined(HOLD_ON_OTHER_KEYPRESS_PER_KEY) | ||
| 115 | uint16_t tapping_keycode = get_record_keycode(&tapping_key, false); | ||
| 116 | # endif | ||
| 110 | 117 | ||
| 111 | // if tapping | 118 | // if tapping |
| 112 | if (IS_TAPPING_PRESSED()) { | 119 | if (IS_TAPPING_PRESSED()) { |
| 113 | if (WITHIN_TAPPING_TERM(event)) { | 120 | // clang-format off |
| 121 | if (WITHIN_TAPPING_TERM(event) | ||
| 122 | # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) | ||
| 123 | || ( | ||
| 124 | # ifdef RETRO_TAPPING_PER_KEY | ||
| 125 | get_retro_tapping(tapping_keycode, keyp) && | ||
| 126 | # endif | ||
| 127 | (RETRO_SHIFT + 0) != 0 && TIMER_DIFF_16(event.time, tapping_key.event.time) < (RETRO_SHIFT + 0) | ||
| 128 | ) | ||
| 129 | # endif | ||
| 130 | ) { | ||
| 131 | // clang-format on | ||
| 114 | if (tapping_key.tap.count == 0) { | 132 | if (tapping_key.tap.count == 0) { |
| 115 | if (IS_TAPPING_RECORD(keyp) && !event.pressed) { | 133 | if (IS_TAPPING_RECORD(keyp) && !event.pressed) { |
| 134 | # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) | ||
| 135 | retroshift_swap_times(); | ||
| 136 | # endif | ||
| 116 | // first tap! | 137 | // first tap! |
| 117 | debug("Tapping: First tap(0->1).\n"); | 138 | debug("Tapping: First tap(0->1).\n"); |
| 118 | tapping_key.tap.count = 1; | 139 | tapping_key.tap.count = 1; |
| @@ -128,22 +149,70 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 128 | * This can register the key before settlement of tapping, | 149 | * This can register the key before settlement of tapping, |
| 129 | * useful for long TAPPING_TERM but may prevent fast typing. | 150 | * useful for long TAPPING_TERM but may prevent fast typing. |
| 130 | */ | 151 | */ |
| 131 | # if defined(TAPPING_TERM_PER_KEY) || (TAPPING_TERM >= 500) || defined(PERMISSIVE_HOLD) || defined(PERMISSIVE_HOLD_PER_KEY) | 152 | // clang-format off |
| 132 | else if ((( | 153 | # if defined(TAPPING_TERM_PER_KEY) || (TAPPING_TERM >= 500) || defined(PERMISSIVE_HOLD) || defined(PERMISSIVE_HOLD_PER_KEY) || (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)) |
| 154 | else if ( | ||
| 155 | ( | ||
| 156 | ( | ||
| 157 | ( | ||
| 133 | # ifdef TAPPING_TERM_PER_KEY | 158 | # ifdef TAPPING_TERM_PER_KEY |
| 134 | get_tapping_term(get_record_keycode(&tapping_key, false), keyp) | 159 | get_tapping_term(tapping_keycode, keyp) |
| 135 | # else | 160 | # else |
| 136 | TAPPING_TERM | 161 | TAPPING_TERM |
| 137 | # endif | 162 | # endif |
| 138 | >= 500) | 163 | >= 500 |
| 164 | ) | ||
| 139 | 165 | ||
| 140 | # ifdef PERMISSIVE_HOLD_PER_KEY | 166 | # ifdef PERMISSIVE_HOLD_PER_KEY |
| 141 | || get_permissive_hold(get_record_keycode(&tapping_key, false), keyp) | 167 | || get_permissive_hold(tapping_keycode, keyp) |
| 142 | # elif defined(PERMISSIVE_HOLD) | 168 | # elif defined(PERMISSIVE_HOLD) |
| 143 | || true | 169 | || true |
| 170 | # endif | ||
| 171 | ) && IS_RELEASED(event) && waiting_buffer_typed(event) | ||
| 172 | ) | ||
| 173 | // Causes nested taps to not wait past TAPPING_TERM/RETRO_SHIFT | ||
| 174 | // unnecessarily and fixes them for Layer Taps. | ||
| 175 | # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) | ||
| 176 | || ( | ||
| 177 | # ifdef RETRO_TAPPING_PER_KEY | ||
| 178 | get_retro_tapping(tapping_keycode, keyp) && | ||
| 179 | # endif | ||
| 180 | ( | ||
| 181 | // Rolled over the two keys. | ||
| 182 | ( | ||
| 183 | ( | ||
| 184 | false | ||
| 185 | # if defined(HOLD_ON_OTHER_KEYPRESS) || defined(HOLD_ON_OTHER_KEYPRESS_PER_KEY) | ||
| 186 | || ( | ||
| 187 | IS_LT(tapping_keycode) | ||
| 188 | # ifdef HOLD_ON_OTHER_KEYPRESS_PER_KEY | ||
| 189 | && get_hold_on_other_keypress(tapping_keycode, keyp) | ||
| 190 | # endif | ||
| 191 | ) | ||
| 192 | # endif | ||
| 193 | # if !defined(IGNORE_MOD_TAP_INTERRUPT) || defined(IGNORE_MOD_TAP_INTERRUPT_PER_KEY) | ||
| 194 | || ( | ||
| 195 | IS_MT(tapping_keycode) | ||
| 196 | # ifdef IGNORE_MOD_TAP_INTERRUPT_PER_KEY | ||
| 197 | && !get_ignore_mod_tap_interrupt(tapping_keycode, keyp) | ||
| 198 | # endif | ||
| 199 | ) | ||
| 200 | # endif | ||
| 201 | ) && tapping_key.tap.interrupted == true | ||
| 202 | ) | ||
| 203 | // Makes Retro Shift ignore [IGNORE_MOD_TAP_INTERRUPT's | ||
| 204 | // effects on nested taps for MTs and the default | ||
| 205 | // behavior of LTs] below TAPPING_TERM or RETRO_SHIFT. | ||
| 206 | || ( | ||
| 207 | IS_RETRO(tapping_keycode) | ||
| 208 | && (event.key.col != tapping_key.event.key.col || event.key.row != tapping_key.event.key.row) | ||
| 209 | && IS_RELEASED(event) && waiting_buffer_typed(event) | ||
| 210 | ) | ||
| 211 | ) | ||
| 212 | ) | ||
| 144 | # endif | 213 | # endif |
| 145 | ) && | 214 | ) { |
| 146 | IS_RELEASED(event) && waiting_buffer_typed(event)) { | 215 | // clang-format on |
| 147 | debug("Tapping: End. No tap. Interfered by typing key\n"); | 216 | debug("Tapping: End. No tap. Interfered by typing key\n"); |
| 148 | process_record(&tapping_key); | 217 | process_record(&tapping_key); |
| 149 | tapping_key = (keyrecord_t){}; | 218 | tapping_key = (keyrecord_t){}; |
| @@ -181,7 +250,7 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 181 | tapping_key.tap.interrupted = true; | 250 | tapping_key.tap.interrupted = true; |
| 182 | # if defined(HOLD_ON_OTHER_KEY_PRESS) || defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) | 251 | # if defined(HOLD_ON_OTHER_KEY_PRESS) || defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) |
| 183 | # if defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) | 252 | # if defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) |
| 184 | if (get_hold_on_other_key_press(get_record_keycode(&tapping_key, false), keyp)) | 253 | if (get_hold_on_other_key_press(tapping_keycode, keyp)) |
| 185 | # endif | 254 | # endif |
| 186 | { | 255 | { |
| 187 | debug("Tapping: End. No tap. Interfered by pressed key\n"); | 256 | debug("Tapping: End. No tap. Interfered by pressed key\n"); |
| @@ -284,14 +353,25 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 284 | } | 353 | } |
| 285 | } | 354 | } |
| 286 | } else if (IS_TAPPING_RELEASED()) { | 355 | } else if (IS_TAPPING_RELEASED()) { |
| 287 | if (WITHIN_TAPPING_TERM(event)) { | 356 | // clang-format off |
| 357 | if (WITHIN_TAPPING_TERM(event) | ||
| 358 | # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) | ||
| 359 | || ( | ||
| 360 | # ifdef RETRO_TAPPING_PER_KEY | ||
| 361 | get_retro_tapping(tapping_keycode, keyp) && | ||
| 362 | # endif | ||
| 363 | (RETRO_SHIFT + 0) != 0 && TIMER_DIFF_16(event.time, tapping_key.event.time) < (RETRO_SHIFT + 0) | ||
| 364 | ) | ||
| 365 | # endif | ||
| 366 | ) { | ||
| 367 | // clang-format on | ||
| 288 | if (event.pressed) { | 368 | if (event.pressed) { |
| 289 | if (IS_TAPPING_RECORD(keyp)) { | 369 | if (IS_TAPPING_RECORD(keyp)) { |
| 290 | //# ifndef TAPPING_FORCE_HOLD | 370 | //# ifndef TAPPING_FORCE_HOLD |
| 291 | # if !defined(TAPPING_FORCE_HOLD) || defined(TAPPING_FORCE_HOLD_PER_KEY) | 371 | # if !defined(TAPPING_FORCE_HOLD) || defined(TAPPING_FORCE_HOLD_PER_KEY) |
| 292 | if ( | 372 | if ( |
| 293 | # ifdef TAPPING_FORCE_HOLD_PER_KEY | 373 | # ifdef TAPPING_FORCE_HOLD_PER_KEY |
| 294 | !get_tapping_force_hold(get_record_keycode(&tapping_key, false), keyp) && | 374 | !get_tapping_force_hold(tapping_keycode, keyp) && |
| 295 | # endif | 375 | # endif |
| 296 | !tapping_key.tap.interrupted && tapping_key.tap.count > 0) { | 376 | !tapping_key.tap.interrupted && tapping_key.tap.count > 0) { |
| 297 | // sequential tap. | 377 | // sequential tap. |
