action_tapping.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  1. #include <stdint.h>
  2. #include <stdbool.h>
  3. #include "action.h"
  4. #include "action_layer.h"
  5. #include "action_tapping.h"
  6. #include "action_util.h"
  7. #include "keycode.h"
  8. #include "keycode_config.h"
  9. #include "quantum_keycodes.h"
  10. #include "timer.h"
  11. #include "wait.h"
  12. #ifndef NO_ACTION_TAPPING
  13. # if defined(IGNORE_MOD_TAP_INTERRUPT_PER_KEY)
  14. # error "IGNORE_MOD_TAP_INTERRUPT_PER_KEY has been removed; the code needs to be ported to use HOLD_ON_OTHER_KEY_PRESS_PER_KEY instead."
  15. # elif defined(IGNORE_MOD_TAP_INTERRUPT)
  16. # error "IGNORE_MOD_TAP_INTERRUPT is no longer necessary as it is now the default behavior of mod-tap keys. Please remove it from your config."
  17. # endif
  18. # ifndef COMBO_ENABLE
  19. # define IS_TAPPING_RECORD(r) (KEYEQ(tapping_key.event.key, (r->event.key)))
  20. # else
  21. # define IS_TAPPING_RECORD(r) (KEYEQ(tapping_key.event.key, (r->event.key)) && tapping_key.keycode == r->keycode)
  22. # endif
  23. # 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))
  24. # define WITHIN_QUICK_TAP_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < GET_QUICK_TAP_TERM(get_record_keycode(&tapping_key, false), &tapping_key))
  25. # ifdef DYNAMIC_TAPPING_TERM_ENABLE
  26. uint16_t g_tapping_term = TAPPING_TERM;
  27. # endif
  28. # ifdef TAPPING_TERM_PER_KEY
  29. __attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) {
  30. # ifdef DYNAMIC_TAPPING_TERM_ENABLE
  31. return g_tapping_term;
  32. # else
  33. return TAPPING_TERM;
  34. # endif
  35. }
  36. # endif
  37. # ifdef QUICK_TAP_TERM_PER_KEY
  38. __attribute__((weak)) uint16_t get_quick_tap_term(uint16_t keycode, keyrecord_t *record) {
  39. return QUICK_TAP_TERM;
  40. }
  41. # endif
  42. # ifdef PERMISSIVE_HOLD_PER_KEY
  43. __attribute__((weak)) bool get_permissive_hold(uint16_t keycode, keyrecord_t *record) {
  44. return false;
  45. }
  46. # endif
  47. # ifdef SPECULATIVE_HOLD
  48. typedef struct {
  49. keypos_t key;
  50. uint8_t mods;
  51. } speculative_key_t;
  52. # define SPECULATIVE_KEYS_SIZE 8
  53. static speculative_key_t speculative_keys[SPECULATIVE_KEYS_SIZE] = {};
  54. static uint8_t num_speculative_keys = 0;
  55. static uint8_t prev_speculative_mods = 0;
  56. static uint8_t speculative_mods = 0;
  57. /** Handler to be called on incoming press events. */
  58. static void speculative_key_press(keyrecord_t *record);
  59. # endif // SPECULATIVE_HOLD
  60. # if defined(CHORDAL_HOLD) || defined(FLOW_TAP_TERM)
  61. # define REGISTERED_TAPS_SIZE 8
  62. // Array of tap-hold keys that have been settled as tapped but not yet released.
  63. static keypos_t registered_taps[REGISTERED_TAPS_SIZE] = {};
  64. static uint8_t num_registered_taps = 0;
  65. /** Adds `key` to the registered_taps array. */
  66. static void registered_taps_add(keypos_t key);
  67. /** Returns the index of `key` in registered_taps, or -1 if not found. */
  68. static int8_t registered_tap_find(keypos_t key);
  69. /** Removes index `i` from the registered_taps array. */
  70. static void registered_taps_del_index(uint8_t i);
  71. /** Logs the registered_taps array for debugging. */
  72. static void debug_registered_taps(void);
  73. static bool is_mt_or_lt(uint16_t keycode) {
  74. return IS_QK_MOD_TAP(keycode) || IS_QK_LAYER_TAP(keycode);
  75. }
  76. # endif // defined(CHORDAL_HOLD) || defined(FLOW_TAP_TERM)
  77. # if defined(CHORDAL_HOLD)
  78. extern const char chordal_hold_layout[MATRIX_ROWS][MATRIX_COLS] PROGMEM;
  79. /** \brief Finds which queued events should be held according to Chordal Hold.
  80. *
  81. * In a situation with multiple unsettled tap-hold key presses, scan the queue
  82. * up until the first release, non-tap-hold, or one-shot event and find the
  83. * latest event in the queue that settles as held according to
  84. * get_chordal_hold().
  85. *
  86. * \return Index of the first tap, or equivalently, one past the latest hold.
  87. */
  88. static uint8_t waiting_buffer_find_chordal_hold_tap(void);
  89. /** Processes queued events up to and including `key` as tapped. */
  90. static void waiting_buffer_chordal_hold_taps_until(keypos_t key);
  91. /** \brief Processes and pops buffered events until the first tap-hold event. */
  92. static void waiting_buffer_process_regular(void);
  93. # endif // CHORDAL_HOLD
  94. # ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY
  95. __attribute__((weak)) bool get_hold_on_other_key_press(uint16_t keycode, keyrecord_t *record) {
  96. return false;
  97. }
  98. # endif
  99. # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)
  100. # include "process_auto_shift.h"
  101. # endif
  102. # if defined(FLOW_TAP_TERM)
  103. static uint16_t flow_tap_prev_keycode = KC_NO;
  104. static uint16_t flow_tap_prev_time = 0;
  105. static bool flow_tap_expired = true;
  106. static bool flow_tap_key_if_within_term(keyrecord_t *record, uint16_t prev_time);
  107. # endif // defined(FLOW_TAP_TERM)
  108. static keyrecord_t tapping_key = {};
  109. static keyrecord_t waiting_buffer[WAITING_BUFFER_SIZE] = {};
  110. static uint8_t waiting_buffer_head = 0;
  111. static uint8_t waiting_buffer_tail = 0;
  112. static bool process_tapping(keyrecord_t *record);
  113. static bool waiting_buffer_enq(keyrecord_t record);
  114. static void waiting_buffer_clear(void);
  115. static bool waiting_buffer_typed(keyevent_t event);
  116. static bool waiting_buffer_has_anykey_pressed(void);
  117. static void waiting_buffer_scan_tap(void);
  118. static void debug_tapping_key(void);
  119. static void debug_waiting_buffer(void);
  120. /** \brief Action Tapping Process
  121. *
  122. * FIXME: Needs doc
  123. */
  124. void action_tapping_process(keyrecord_t record) {
  125. # ifdef SPECULATIVE_HOLD
  126. prev_speculative_mods = speculative_mods;
  127. if (record.event.pressed) {
  128. speculative_key_press(&record);
  129. }
  130. # endif // SPECULATIVE_HOLD
  131. if (process_tapping(&record)) {
  132. if (IS_EVENT(record.event)) {
  133. ac_dprintf("processed: ");
  134. debug_record(record);
  135. ac_dprintf("\n");
  136. }
  137. } else {
  138. if (!waiting_buffer_enq(record)) {
  139. // clear all in case of overflow.
  140. ac_dprintf("OVERFLOW: CLEAR ALL STATES\n");
  141. clear_keyboard();
  142. waiting_buffer_clear();
  143. tapping_key = (keyrecord_t){0};
  144. }
  145. }
  146. # ifdef SPECULATIVE_HOLD
  147. if (speculative_mods != prev_speculative_mods) {
  148. send_keyboard_report();
  149. }
  150. # endif // SPECULATIVE_HOLD
  151. // process waiting_buffer
  152. if (IS_EVENT(record.event) && waiting_buffer_head != waiting_buffer_tail) {
  153. ac_dprintf("---- action_exec: process waiting_buffer -----\n");
  154. }
  155. for (; waiting_buffer_tail != waiting_buffer_head; waiting_buffer_tail = (waiting_buffer_tail + 1) % WAITING_BUFFER_SIZE) {
  156. if (process_tapping(&waiting_buffer[waiting_buffer_tail])) {
  157. ac_dprintf("processed: waiting_buffer[%u] =", waiting_buffer_tail);
  158. debug_record(waiting_buffer[waiting_buffer_tail]);
  159. ac_dprintf("\n\n");
  160. } else {
  161. break;
  162. }
  163. }
  164. if (IS_EVENT(record.event)) {
  165. ac_dprintf("\n");
  166. } else {
  167. # ifdef FLOW_TAP_TERM
  168. if (!flow_tap_expired && TIMER_DIFF_16(record.event.time, flow_tap_prev_time) >= INT16_MAX / 2) {
  169. flow_tap_expired = true;
  170. }
  171. # endif // FLOW_TAP_TERM
  172. }
  173. }
  174. /* Some conditionally defined helper macros to keep process_tapping more
  175. * readable. The conditional definition of tapping_keycode and all the
  176. * conditional uses of it are hidden inside macros named TAP_...
  177. */
  178. # define TAP_DEFINE_KEYCODE const uint16_t tapping_keycode = get_record_keycode(&tapping_key, false)
  179. # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)
  180. # ifdef RETRO_TAPPING_PER_KEY
  181. # define TAP_GET_RETRO_TAPPING(keyp) get_auto_shifted_key(tapping_keycode, keyp) && get_retro_tapping(tapping_keycode, &tapping_key)
  182. # else
  183. # define TAP_GET_RETRO_TAPPING(keyp) get_auto_shifted_key(tapping_keycode, keyp)
  184. # endif
  185. /* Used to extend TAPPING_TERM:
  186. * indefinitely if RETRO_SHIFT does not have a value
  187. * to RETRO_SHIFT if RETRO_SHIFT is set
  188. * for possibly retro shifted keys.
  189. */
  190. # 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)))
  191. # define TAP_IS_LT IS_QK_LAYER_TAP(tapping_keycode)
  192. # define TAP_IS_MT IS_QK_MOD_TAP(tapping_keycode)
  193. # define TAP_IS_RETRO IS_RETRO(tapping_keycode)
  194. # else
  195. # define TAP_GET_RETRO_TAPPING(keyp) false
  196. # define MAYBE_RETRO_SHIFTING(ev, kp) false
  197. # define TAP_IS_LT false
  198. # define TAP_IS_MT false
  199. # define TAP_IS_RETRO false
  200. # endif
  201. # ifdef PERMISSIVE_HOLD_PER_KEY
  202. # define TAP_GET_PERMISSIVE_HOLD get_permissive_hold(tapping_keycode, &tapping_key)
  203. # elif defined(PERMISSIVE_HOLD)
  204. # define TAP_GET_PERMISSIVE_HOLD true
  205. # else
  206. # define TAP_GET_PERMISSIVE_HOLD false
  207. # endif
  208. # ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY
  209. # define TAP_GET_HOLD_ON_OTHER_KEY_PRESS get_hold_on_other_key_press(tapping_keycode, &tapping_key)
  210. # elif defined(HOLD_ON_OTHER_KEY_PRESS)
  211. # define TAP_GET_HOLD_ON_OTHER_KEY_PRESS true
  212. # else
  213. # define TAP_GET_HOLD_ON_OTHER_KEY_PRESS false
  214. # endif
  215. /** \brief Tapping
  216. *
  217. * Rule: Tap key is typed(pressed and released) within TAPPING_TERM.
  218. * (without interfering by typing other key)
  219. */
  220. /* return true when key event is processed or consumed. */
  221. bool process_tapping(keyrecord_t *keyp) {
  222. const keyevent_t event = keyp->event;
  223. # if defined(CHORDAL_HOLD) || defined(FLOW_TAP_TERM)
  224. if (!event.pressed) {
  225. const int8_t i = registered_tap_find(event.key);
  226. if (i != -1) {
  227. // If a tap-hold key was previously settled as tapped, set its
  228. // tap.count correspondingly on release.
  229. keyp->tap.count = 1;
  230. registered_taps_del_index(i);
  231. ac_dprintf("Found tap release for [%d]\n", i);
  232. debug_registered_taps();
  233. }
  234. }
  235. # endif // defined(CHORDAL_HOLD) || defined(FLOW_TAP_TERM)
  236. // state machine is in the "reset" state, no tapping key is to be
  237. // processed
  238. if (IS_NOEVENT(tapping_key.event)) {
  239. if (!IS_EVENT(event)) {
  240. // early return for tick events
  241. } else if (event.pressed && is_tap_record(keyp)) {
  242. // the currently pressed key is a tapping key, therefore transition
  243. // into the "pressed" tapping key state
  244. # if defined(FLOW_TAP_TERM)
  245. if (flow_tap_key_if_within_term(keyp, flow_tap_prev_time)) {
  246. return true;
  247. }
  248. # endif // defined(FLOW_TAP_TERM)
  249. ac_dprintf("Tapping: Start(Press tap key).\n");
  250. tapping_key = *keyp;
  251. process_record_tap_hint(&tapping_key);
  252. waiting_buffer_scan_tap();
  253. debug_tapping_key();
  254. } else {
  255. // the current key is just a regular key, pass it on for regular
  256. // processing
  257. process_record(keyp);
  258. }
  259. return true;
  260. }
  261. # if (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)) || defined(PERMISSIVE_HOLD_PER_KEY) || defined(CHORDAL_HOLD) || defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY)
  262. TAP_DEFINE_KEYCODE;
  263. # endif
  264. // process "pressed" tapping key state
  265. if (tapping_key.event.pressed) {
  266. if (WITHIN_TAPPING_TERM(event) || MAYBE_RETRO_SHIFTING(event, keyp)) {
  267. if (IS_NOEVENT(event)) {
  268. // early return for tick events
  269. return true;
  270. }
  271. if (tapping_key.tap.count == 0) {
  272. if (IS_TAPPING_RECORD(keyp) && !event.pressed) {
  273. // first tap!
  274. ac_dprintf("Tapping: First tap(0->1).\n");
  275. tapping_key.tap.count = 1;
  276. debug_tapping_key();
  277. process_record(&tapping_key);
  278. // copy tapping state
  279. keyp->tap = tapping_key.tap;
  280. # if defined(FLOW_TAP_TERM)
  281. // Now that tapping_key has settled as tapped, check whether
  282. // Flow Tap applies to following yet-unsettled keys.
  283. uint16_t prev_time = tapping_key.event.time;
  284. for (; waiting_buffer_tail != waiting_buffer_head; waiting_buffer_tail = (waiting_buffer_tail + 1) % WAITING_BUFFER_SIZE) {
  285. keyrecord_t *record = &waiting_buffer[waiting_buffer_tail];
  286. if (!record->event.pressed) {
  287. break;
  288. }
  289. const int16_t next_time = record->event.time;
  290. if (!is_tap_record(record)) {
  291. process_record(record);
  292. } else if (!flow_tap_key_if_within_term(record, prev_time)) {
  293. break;
  294. }
  295. prev_time = next_time;
  296. }
  297. debug_waiting_buffer();
  298. # endif // defined(FLOW_TAP_TERM)
  299. // enqueue
  300. return false;
  301. }
  302. # if defined(CHORDAL_HOLD)
  303. else if (is_mt_or_lt(tapping_keycode) && !event.pressed && waiting_buffer_typed(event) && !get_chordal_hold(tapping_keycode, &tapping_key, get_record_keycode(keyp, false), keyp)) {
  304. // Key release that is not a chord with the tapping key.
  305. // Settle the tapping key and any other pending tap-hold
  306. // keys preceding the press of this key as tapped.
  307. ac_dprintf("Tapping: End. Chord considered a tap\n");
  308. tapping_key.tap.count = 1;
  309. registered_taps_add(tapping_key.event.key);
  310. process_record(&tapping_key);
  311. tapping_key = (keyrecord_t){0};
  312. waiting_buffer_chordal_hold_taps_until(event.key);
  313. debug_registered_taps();
  314. debug_waiting_buffer();
  315. // enqueue
  316. return false;
  317. }
  318. # endif // CHORDAL_HOLD
  319. /* Process a key typed within TAPPING_TERM
  320. * This can register the key before settlement of tapping,
  321. * useful for long TAPPING_TERM but may prevent fast typing.
  322. */
  323. // clang-format off
  324. else if (
  325. !event.pressed && waiting_buffer_typed(event) &&
  326. (
  327. TAP_GET_PERMISSIVE_HOLD ||
  328. // Causes nested taps to not wait past TAPPING_TERM/RETRO_SHIFT
  329. // unnecessarily and fixes them for Layer Taps.
  330. TAP_GET_RETRO_TAPPING(keyp)
  331. )
  332. ) {
  333. // clang-format on
  334. ac_dprintf("Tapping: End. No tap. Interfered by typing key\n");
  335. process_record(&tapping_key);
  336. # if defined(CHORDAL_HOLD)
  337. uint8_t first_tap = waiting_buffer_find_chordal_hold_tap();
  338. ac_dprintf("first_tap = %u\n", first_tap);
  339. if (first_tap < WAITING_BUFFER_SIZE) {
  340. for (; waiting_buffer_tail != first_tap; waiting_buffer_tail = (waiting_buffer_tail + 1) % WAITING_BUFFER_SIZE) {
  341. ac_dprintf("Processing [%u]\n", waiting_buffer_tail);
  342. process_record(&waiting_buffer[waiting_buffer_tail]);
  343. }
  344. }
  345. waiting_buffer_chordal_hold_taps_until(event.key);
  346. debug_registered_taps();
  347. debug_waiting_buffer();
  348. # endif // CHORDAL_HOLD
  349. tapping_key = (keyrecord_t){0};
  350. debug_tapping_key();
  351. // enqueue
  352. return false;
  353. }
  354. /* Process release event of a key pressed before tapping starts
  355. * Without this unexpected repeating will occur with having fast repeating setting
  356. * https://github.com/tmk/tmk_keyboard/issues/60
  357. *
  358. * NOTE: This workaround causes events to process out of order,
  359. * e.g. in a rolled press of three tap-hold keys like
  360. *
  361. * "A down, B down, C down, A up, B up, C up"
  362. *
  363. * events are processed as
  364. *
  365. * "A down, B down, A up, B up, C down, C up"
  366. *
  367. * It seems incorrect to process keyp before the tapping key.
  368. * This workaround is old, from 2013. This might no longer
  369. * be needed for the original problem it was meant to address.
  370. */
  371. else if (!event.pressed && !waiting_buffer_typed(event)) {
  372. // Modifier/Layer should be retained till end of this tapping.
  373. action_t action = layer_switch_get_action(event.key);
  374. switch (action.kind.id) {
  375. case ACT_LMODS:
  376. case ACT_RMODS:
  377. if (action.key.mods && !action.key.code) return false;
  378. if (IS_MODIFIER_KEYCODE(action.key.code)) return false;
  379. break;
  380. case ACT_LMODS_TAP:
  381. case ACT_RMODS_TAP:
  382. if (action.key.mods && keyp->tap.count == 0) return false;
  383. if (IS_MODIFIER_KEYCODE(action.key.code)) return false;
  384. break;
  385. case ACT_LAYER_TAP:
  386. case ACT_LAYER_TAP_EXT:
  387. switch (action.layer_tap.code) {
  388. case 0 ...(OP_TAP_TOGGLE - 1):
  389. case OP_ON_OFF:
  390. case OP_OFF_ON:
  391. case OP_SET_CLEAR:
  392. return false;
  393. }
  394. break;
  395. }
  396. // Release of key should be process immediately.
  397. ac_dprintf("Tapping: release event of a key pressed before tapping\n");
  398. process_record(keyp);
  399. return true;
  400. } else {
  401. // set interrupted flag when other key pressed during tapping
  402. if (event.pressed) {
  403. tapping_key.tap.interrupted = true;
  404. # if defined(CHORDAL_HOLD)
  405. if (is_mt_or_lt(tapping_keycode) && !get_chordal_hold(tapping_keycode, &tapping_key, get_record_keycode(keyp, false), keyp)) {
  406. // In process_action(), HOLD_ON_OTHER_KEY_PRESS
  407. // will revert interrupted events to holds, so
  408. // this needs to be set false.
  409. tapping_key.tap.interrupted = false;
  410. if (!is_tap_record(keyp)) {
  411. ac_dprintf("Tapping: End. Chord considered a tap\n");
  412. tapping_key.tap.count = 1;
  413. registered_taps_add(tapping_key.event.key);
  414. debug_registered_taps();
  415. process_record(&tapping_key);
  416. tapping_key = (keyrecord_t){0};
  417. }
  418. } else
  419. # endif // CHORDAL_HOLD
  420. if (TAP_GET_HOLD_ON_OTHER_KEY_PRESS
  421. # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)
  422. // Auto Shift cannot evaluate this early
  423. // Retro Shift uses the hold action for all nested taps even without HOLD_ON_OTHER_KEY_PRESS, so this is fine to skip
  424. && !(MAYBE_RETRO_SHIFTING(event, keyp) && get_auto_shifted_key(get_record_keycode(keyp, false), keyp))
  425. # endif
  426. ) {
  427. // Settle the tapping key as *held*, since
  428. // HOLD_ON_OTHER_KEY_PRESS is enabled for this key.
  429. ac_dprintf("Tapping: End. No tap. Interfered by pressed key\n");
  430. process_record(&tapping_key);
  431. # if defined(CHORDAL_HOLD)
  432. if (waiting_buffer_tail != waiting_buffer_head && is_tap_record(&waiting_buffer[waiting_buffer_tail])) {
  433. tapping_key = waiting_buffer[waiting_buffer_tail];
  434. // Pop tail from the queue.
  435. waiting_buffer_tail = (waiting_buffer_tail + 1) % WAITING_BUFFER_SIZE;
  436. debug_waiting_buffer();
  437. } else
  438. # endif // CHORDAL_HOLD
  439. {
  440. tapping_key = (keyrecord_t){0};
  441. }
  442. debug_tapping_key();
  443. # if defined(CHORDAL_HOLD)
  444. waiting_buffer_process_regular();
  445. # endif // CHORDAL_HOLD
  446. }
  447. }
  448. // enqueue
  449. return false;
  450. }
  451. }
  452. // tap_count > 0
  453. else {
  454. if (IS_TAPPING_RECORD(keyp) && !event.pressed) {
  455. ac_dprintf("Tapping: Tap release(%u)\n", tapping_key.tap.count);
  456. keyp->tap = tapping_key.tap;
  457. process_record(keyp);
  458. tapping_key = *keyp;
  459. debug_tapping_key();
  460. return true;
  461. } else if (is_tap_record(keyp) && event.pressed) {
  462. if (tapping_key.tap.count > 1) {
  463. ac_dprintf("Tapping: Start new tap with releasing last tap(>1).\n");
  464. // unregister key
  465. process_record(&(keyrecord_t){
  466. .tap = tapping_key.tap,
  467. .event.key = tapping_key.event.key,
  468. .event.time = event.time,
  469. .event.pressed = false,
  470. .event.type = tapping_key.event.type,
  471. # ifdef COMBO_ENABLE
  472. .keycode = tapping_key.keycode,
  473. # endif
  474. });
  475. } else {
  476. ac_dprintf("Tapping: Start while last tap(1).\n");
  477. }
  478. tapping_key = *keyp;
  479. waiting_buffer_scan_tap();
  480. debug_tapping_key();
  481. return true;
  482. } else {
  483. ac_dprintf("Tapping: key event while last tap(>0).\n");
  484. # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)
  485. retroshift_swap_times();
  486. # endif
  487. process_record(keyp);
  488. return true;
  489. }
  490. }
  491. }
  492. // after TAPPING_TERM
  493. else {
  494. if (tapping_key.tap.count == 0) {
  495. ac_dprintf("Tapping: End. Timeout. Not tap(0): ");
  496. debug_event(event);
  497. ac_dprintf("\n");
  498. process_record(&tapping_key);
  499. tapping_key = (keyrecord_t){0};
  500. debug_tapping_key();
  501. return false;
  502. } else {
  503. if (IS_NOEVENT(event)) {
  504. return true;
  505. }
  506. if (IS_TAPPING_RECORD(keyp) && !event.pressed) {
  507. ac_dprintf("Tapping: End. last timeout tap release(>0).");
  508. keyp->tap = tapping_key.tap;
  509. process_record(keyp);
  510. tapping_key = (keyrecord_t){0};
  511. return true;
  512. } else if (is_tap_record(keyp) && event.pressed) {
  513. if (tapping_key.tap.count > 1) {
  514. ac_dprintf("Tapping: Start new tap with releasing last timeout tap(>1).\n");
  515. // unregister key
  516. process_record(&(keyrecord_t){
  517. .tap = tapping_key.tap,
  518. .event.key = tapping_key.event.key,
  519. .event.time = event.time,
  520. .event.pressed = false,
  521. .event.type = tapping_key.event.type,
  522. # ifdef COMBO_ENABLE
  523. .keycode = tapping_key.keycode,
  524. # endif
  525. });
  526. } else {
  527. ac_dprintf("Tapping: Start while last timeout tap(1).\n");
  528. }
  529. tapping_key = *keyp;
  530. waiting_buffer_scan_tap();
  531. debug_tapping_key();
  532. return true;
  533. } else {
  534. ac_dprintf("Tapping: key event while last timeout tap(>0).\n");
  535. process_record(keyp);
  536. return true;
  537. }
  538. }
  539. }
  540. }
  541. // process "released" tapping key state
  542. else {
  543. if (WITHIN_TAPPING_TERM(event) || MAYBE_RETRO_SHIFTING(event, keyp)) {
  544. if (IS_NOEVENT(event)) {
  545. // early return for tick events
  546. return true;
  547. }
  548. if (event.pressed) {
  549. if (IS_TAPPING_RECORD(keyp)) {
  550. if (WITHIN_QUICK_TAP_TERM(event) && !tapping_key.tap.interrupted && tapping_key.tap.count > 0) {
  551. // sequential tap.
  552. keyp->tap = tapping_key.tap;
  553. if (keyp->tap.count < 15) keyp->tap.count += 1;
  554. ac_dprintf("Tapping: Tap press(%u)\n", keyp->tap.count);
  555. process_record(keyp);
  556. tapping_key = *keyp;
  557. debug_tapping_key();
  558. return true;
  559. }
  560. // FIX: start new tap again
  561. tapping_key = *keyp;
  562. return true;
  563. } else if (is_tap_record(keyp)) {
  564. // Sequential tap can be interfered with other tap key.
  565. # if defined(FLOW_TAP_TERM)
  566. if (flow_tap_key_if_within_term(keyp, flow_tap_prev_time)) {
  567. tapping_key = (keyrecord_t){0};
  568. debug_tapping_key();
  569. return true;
  570. }
  571. # endif // defined(FLOW_TAP_TERM)
  572. ac_dprintf("Tapping: Start with interfering other tap.\n");
  573. tapping_key = *keyp;
  574. waiting_buffer_scan_tap();
  575. debug_tapping_key();
  576. return true;
  577. } else {
  578. // should none in buffer
  579. // FIX: interrupted when other key is pressed
  580. tapping_key.tap.interrupted = true;
  581. process_record(keyp);
  582. return true;
  583. }
  584. } else {
  585. ac_dprintf("Tapping: other key just after tap.\n");
  586. process_record(keyp);
  587. return true;
  588. }
  589. } else {
  590. // Timeout - reset state machine.
  591. ac_dprintf("Tapping: End(Timeout after releasing last tap): ");
  592. debug_event(event);
  593. ac_dprintf("\n");
  594. tapping_key = (keyrecord_t){0};
  595. debug_tapping_key();
  596. return false;
  597. }
  598. }
  599. }
  600. /** \brief Waiting buffer enq
  601. *
  602. * FIXME: Needs docs
  603. */
  604. bool waiting_buffer_enq(keyrecord_t record) {
  605. if (IS_NOEVENT(record.event)) {
  606. return true;
  607. }
  608. if ((waiting_buffer_head + 1) % WAITING_BUFFER_SIZE == waiting_buffer_tail) {
  609. ac_dprintf("waiting_buffer_enq: Over flow.\n");
  610. return false;
  611. }
  612. waiting_buffer[waiting_buffer_head] = record;
  613. waiting_buffer_head = (waiting_buffer_head + 1) % WAITING_BUFFER_SIZE;
  614. ac_dprintf("waiting_buffer_enq: ");
  615. debug_waiting_buffer();
  616. return true;
  617. }
  618. /** \brief Waiting buffer clear
  619. *
  620. * FIXME: Needs docs
  621. */
  622. void waiting_buffer_clear(void) {
  623. waiting_buffer_head = 0;
  624. waiting_buffer_tail = 0;
  625. }
  626. /** \brief Waiting buffer typed
  627. *
  628. * FIXME: Needs docs
  629. */
  630. bool waiting_buffer_typed(keyevent_t event) {
  631. for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
  632. if (KEYEQ(event.key, waiting_buffer[i].event.key) && event.pressed != waiting_buffer[i].event.pressed) {
  633. return true;
  634. }
  635. }
  636. return false;
  637. }
  638. /** \brief Waiting buffer has anykey pressed
  639. *
  640. * FIXME: Needs docs
  641. */
  642. __attribute__((unused)) bool waiting_buffer_has_anykey_pressed(void) {
  643. for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
  644. if (waiting_buffer[i].event.pressed) return true;
  645. }
  646. return false;
  647. }
  648. /** \brief Scan buffer for tapping
  649. *
  650. * FIXME: Needs docs
  651. */
  652. void waiting_buffer_scan_tap(void) {
  653. // early return if:
  654. // - tapping already is settled
  655. // - invalid state: tapping_key released && tap.count == 0
  656. if ((tapping_key.tap.count > 0) || !tapping_key.event.pressed) {
  657. return;
  658. }
  659. # if (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT))
  660. TAP_DEFINE_KEYCODE;
  661. # endif
  662. for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
  663. keyrecord_t *candidate = &waiting_buffer[i];
  664. // clang-format off
  665. if (IS_EVENT(candidate->event) && KEYEQ(candidate->event.key, tapping_key.event.key) && !candidate->event.pressed && (
  666. WITHIN_TAPPING_TERM(waiting_buffer[i].event) || MAYBE_RETRO_SHIFTING(waiting_buffer[i].event, &tapping_key)
  667. )) {
  668. // clang-format on
  669. tapping_key.tap.count = 1;
  670. candidate->tap.count = 1;
  671. process_record(&tapping_key);
  672. ac_dprintf("waiting_buffer_scan_tap: found at [%u]\n", i);
  673. debug_waiting_buffer();
  674. return;
  675. }
  676. }
  677. }
  678. # ifdef SPECULATIVE_HOLD
  679. static void debug_speculative_keys(void) {
  680. ac_dprintf("mods = { ");
  681. for (int8_t i = 0; i < num_speculative_keys; ++i) {
  682. ac_dprintf("%02X ", speculative_keys[i].mods);
  683. }
  684. ac_dprintf("}, keys = { ");
  685. for (int8_t i = 0; i < num_speculative_keys; ++i) {
  686. ac_dprintf("%02X%02X ", speculative_keys[i].key.row, speculative_keys[i].key.col);
  687. }
  688. ac_dprintf("}\n");
  689. }
  690. // Find key in speculative_keys. Returns num_speculative_keys if not found.
  691. static int8_t speculative_keys_find(keypos_t key) {
  692. uint8_t i;
  693. for (i = 0; i < num_speculative_keys; ++i) {
  694. if (KEYEQ(speculative_keys[i].key, key)) {
  695. break;
  696. }
  697. }
  698. return i;
  699. }
  700. static void speculative_key_press(keyrecord_t *record) {
  701. if (num_speculative_keys >= SPECULATIVE_KEYS_SIZE) { // Overflow!
  702. ac_dprintf("SPECULATIVE KEYS OVERFLOW: IGNORING EVENT\n");
  703. return; // Don't trigger: speculative_keys is full.
  704. }
  705. if (speculative_keys_find(record->event.key) < num_speculative_keys) {
  706. return; // Don't trigger: key is already in speculative_keys.
  707. }
  708. const uint16_t keycode = get_record_keycode(record, false);
  709. if (!IS_QK_MOD_TAP(keycode)) {
  710. return; // Don't trigger: not a mod-tap key.
  711. }
  712. uint8_t mods = mod_config(QK_MOD_TAP_GET_MODS(keycode));
  713. if ((mods & 0x10) != 0) { // Unpack 5-bit mods to 8-bit representation.
  714. mods <<= 4;
  715. }
  716. if ((~(get_mods() | speculative_mods) & mods) == 0) {
  717. return; // Don't trigger: mods are already active.
  718. }
  719. // Don't do Speculative Hold when there are non-speculated buffered events,
  720. // since that could result in sending keys out of order.
  721. for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
  722. if (!waiting_buffer[i].tap.speculated) {
  723. return;
  724. }
  725. }
  726. if (get_speculative_hold(keycode, record)) {
  727. record->tap.speculated = true;
  728. speculative_mods |= mods;
  729. // Remember the keypos and mods associated with this key.
  730. speculative_keys[num_speculative_keys] = (speculative_key_t){
  731. .key = record->event.key,
  732. .mods = mods,
  733. };
  734. ++num_speculative_keys;
  735. ac_dprintf("Speculative Hold: ");
  736. debug_speculative_keys();
  737. }
  738. }
  739. uint8_t get_speculative_mods(void) {
  740. return speculative_mods;
  741. }
  742. __attribute__((weak)) bool get_speculative_hold(uint16_t keycode, keyrecord_t *record) {
  743. const uint8_t mods = mod_config(QK_MOD_TAP_GET_MODS(keycode));
  744. return (mods & (MOD_LCTL | MOD_LSFT)) == (mods & (MOD_HYPR));
  745. }
  746. void speculative_key_settled(keyrecord_t *record) {
  747. if (num_speculative_keys == 0) {
  748. return; // Early return when there are no active speculative keys.
  749. }
  750. uint8_t i = speculative_keys_find(record->event.key);
  751. const uint16_t keycode = get_record_keycode(record, false);
  752. if (IS_QK_MOD_TAP(keycode) && record->tap.count == 0) { // MT hold press.
  753. if (i < num_speculative_keys) {
  754. --num_speculative_keys;
  755. const uint8_t cleared_mods = speculative_keys[i].mods;
  756. if (num_speculative_keys) {
  757. speculative_mods &= ~cleared_mods;
  758. // Don't call send_keyboard_report() here; allow default
  759. // handling to reapply the mod before the next report.
  760. // Remove the ith entry from speculative_keys.
  761. for (uint8_t j = i; j < num_speculative_keys; ++j) {
  762. speculative_keys[j] = speculative_keys[j + 1];
  763. }
  764. } else {
  765. speculative_mods = 0;
  766. }
  767. ac_dprintf("Speculative Hold: settled %02x, ", cleared_mods);
  768. debug_speculative_keys();
  769. }
  770. } else { // Tap press event; cancel speculatively-held mod.
  771. if (i >= num_speculative_keys) {
  772. i = 0;
  773. }
  774. // Clear mods for the ith key and all keys that follow.
  775. uint8_t cleared_mods = 0;
  776. for (uint8_t j = i; j < num_speculative_keys; ++j) {
  777. cleared_mods |= speculative_keys[j].mods;
  778. }
  779. num_speculative_keys = i; // Remove ith and following entries.
  780. if ((prev_speculative_mods & cleared_mods) != 0) {
  781. # ifdef DUMMY_MOD_NEUTRALIZER_KEYCODE
  782. neutralize_flashing_modifiers(get_mods() | prev_speculative_mods);
  783. # endif // DUMMY_MOD_NEUTRALIZER_KEYCODE
  784. }
  785. if (num_speculative_keys) {
  786. speculative_mods &= ~cleared_mods;
  787. } else {
  788. speculative_mods = 0;
  789. }
  790. send_keyboard_report();
  791. wait_ms(TAP_CODE_DELAY);
  792. ac_dprintf("Speculative Hold: canceled %02x, ", cleared_mods);
  793. debug_speculative_keys();
  794. }
  795. }
  796. # endif // SPECULATIVE_HOLD
  797. # if defined(CHORDAL_HOLD) || defined(FLOW_TAP_TERM)
  798. static void registered_taps_add(keypos_t key) {
  799. if (num_registered_taps >= REGISTERED_TAPS_SIZE) {
  800. ac_dprintf("TAPS OVERFLOW: CLEAR ALL STATES\n");
  801. clear_keyboard();
  802. num_registered_taps = 0;
  803. }
  804. registered_taps[num_registered_taps] = key;
  805. ++num_registered_taps;
  806. }
  807. static int8_t registered_tap_find(keypos_t key) {
  808. for (int8_t i = 0; i < num_registered_taps; ++i) {
  809. if (KEYEQ(registered_taps[i], key)) {
  810. return i;
  811. }
  812. }
  813. return -1;
  814. }
  815. static void registered_taps_del_index(uint8_t i) {
  816. if (i < num_registered_taps) {
  817. --num_registered_taps;
  818. if (i < num_registered_taps) {
  819. registered_taps[i] = registered_taps[num_registered_taps];
  820. }
  821. }
  822. }
  823. static void debug_registered_taps(void) {
  824. ac_dprintf("registered_taps = { ");
  825. for (int8_t i = 0; i < num_registered_taps; ++i) {
  826. ac_dprintf("%02X%02X ", registered_taps[i].row, registered_taps[i].col);
  827. }
  828. ac_dprintf("}\n");
  829. }
  830. # endif // defined(CHORDAL_HOLD) || defined(FLOW_TAP_TERM)
  831. # ifdef CHORDAL_HOLD
  832. __attribute__((weak)) bool get_chordal_hold(uint16_t tap_hold_keycode, keyrecord_t *tap_hold_record, uint16_t other_keycode, keyrecord_t *other_record) {
  833. return get_chordal_hold_default(tap_hold_record, other_record);
  834. }
  835. bool get_chordal_hold_default(keyrecord_t *tap_hold_record, keyrecord_t *other_record) {
  836. if (tap_hold_record->event.type != KEY_EVENT || other_record->event.type != KEY_EVENT) {
  837. return true; // Return true on combos or other non-key events.
  838. }
  839. char tap_hold_hand = chordal_hold_handedness(tap_hold_record->event.key);
  840. if (tap_hold_hand == '*') {
  841. return true;
  842. }
  843. char other_hand = chordal_hold_handedness(other_record->event.key);
  844. return other_hand == '*' || tap_hold_hand != other_hand;
  845. }
  846. __attribute__((weak)) char chordal_hold_handedness(keypos_t key) {
  847. return (char)pgm_read_byte(&chordal_hold_layout[key.row][key.col]);
  848. }
  849. static uint8_t waiting_buffer_find_chordal_hold_tap(void) {
  850. keyrecord_t *prev = &tapping_key;
  851. uint16_t prev_keycode = get_record_keycode(&tapping_key, false);
  852. uint8_t first_tap = WAITING_BUFFER_SIZE;
  853. for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
  854. keyrecord_t *cur = &waiting_buffer[i];
  855. const uint16_t cur_keycode = get_record_keycode(cur, false);
  856. if (!cur->event.pressed || !is_mt_or_lt(prev_keycode)) {
  857. break;
  858. } else if (get_chordal_hold(prev_keycode, prev, cur_keycode, cur)) {
  859. first_tap = i; // Track one index past the latest hold.
  860. }
  861. prev = cur;
  862. prev_keycode = cur_keycode;
  863. }
  864. return first_tap;
  865. }
  866. static void waiting_buffer_chordal_hold_taps_until(keypos_t key) {
  867. while (waiting_buffer_tail != waiting_buffer_head) {
  868. keyrecord_t *record = &waiting_buffer[waiting_buffer_tail];
  869. ac_dprintf("waiting_buffer_chordal_hold_taps_until: processing [%u]\n", waiting_buffer_tail);
  870. if (record->event.pressed && is_tap_record(record)) {
  871. record->tap.count = 1;
  872. registered_taps_add(record->event.key);
  873. }
  874. process_record(record);
  875. waiting_buffer_tail = (waiting_buffer_tail + 1) % WAITING_BUFFER_SIZE;
  876. if (KEYEQ(key, record->event.key) && record->event.pressed) {
  877. break;
  878. }
  879. }
  880. }
  881. static void waiting_buffer_process_regular(void) {
  882. for (; waiting_buffer_tail != waiting_buffer_head; waiting_buffer_tail = (waiting_buffer_tail + 1) % WAITING_BUFFER_SIZE) {
  883. if (is_tap_record(&waiting_buffer[waiting_buffer_tail])) {
  884. break; // Stop once a tap-hold key event is reached.
  885. }
  886. ac_dprintf("waiting_buffer_process_regular: processing [%u]\n", waiting_buffer_tail);
  887. process_record(&waiting_buffer[waiting_buffer_tail]);
  888. }
  889. debug_waiting_buffer();
  890. }
  891. # endif // CHORDAL_HOLD
  892. # ifdef FLOW_TAP_TERM
  893. void flow_tap_update_last_event(keyrecord_t *record) {
  894. const uint16_t keycode = get_record_keycode(record, false);
  895. // Don't update while a tap-hold key is unsettled.
  896. if (record->tap.count == 0 && (waiting_buffer_tail != waiting_buffer_head || (tapping_key.event.pressed && tapping_key.tap.count == 0))) {
  897. return;
  898. }
  899. // Ignore releases of modifiers and held layer switches.
  900. if (!record->event.pressed) {
  901. switch (keycode) {
  902. case MODIFIER_KEYCODE_RANGE:
  903. case QK_MOMENTARY ... QK_MOMENTARY_MAX:
  904. case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
  905. # ifndef NO_ACTION_ONESHOT // Ignore one-shot keys.
  906. case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX:
  907. case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:
  908. # endif // NO_ACTION_ONESHOT
  909. # ifdef TRI_LAYER_ENABLE // Ignore Tri Layer keys.
  910. case QK_TRI_LAYER_LOWER:
  911. case QK_TRI_LAYER_UPPER:
  912. # endif // TRI_LAYER_ENABLE
  913. return;
  914. case QK_MODS ... QK_MODS_MAX:
  915. if (QK_MODS_GET_BASIC_KEYCODE(keycode) == KC_NO) {
  916. return;
  917. }
  918. break;
  919. case QK_MOD_TAP ... QK_MOD_TAP_MAX:
  920. case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
  921. if (record->tap.count == 0) {
  922. return;
  923. }
  924. break;
  925. }
  926. }
  927. flow_tap_prev_keycode = keycode;
  928. flow_tap_prev_time = record->event.time;
  929. flow_tap_expired = false;
  930. }
  931. static bool flow_tap_key_if_within_term(keyrecord_t *record, uint16_t prev_time) {
  932. const uint16_t idle_time = TIMER_DIFF_16(record->event.time, prev_time);
  933. if (flow_tap_expired || idle_time >= 500) {
  934. return false;
  935. }
  936. const uint16_t keycode = get_record_keycode(record, false);
  937. if (is_mt_or_lt(keycode)) {
  938. uint16_t term = get_flow_tap_term(keycode, record, flow_tap_prev_keycode);
  939. if (term > 500) {
  940. term = 500;
  941. }
  942. if (idle_time < term) {
  943. debug_event(record->event);
  944. ac_dprintf(" within flow tap term (%u < %u) considered a tap\n", idle_time, term);
  945. record->tap.count = 1;
  946. registered_taps_add(record->event.key);
  947. debug_registered_taps();
  948. process_record(record);
  949. return true;
  950. }
  951. }
  952. return false;
  953. }
  954. // Checks both flow_tap_expired flag and elapsed time to determine
  955. // if the key is within the flow tap term.
  956. bool within_flow_tap_term(uint16_t keycode, keyrecord_t *record) {
  957. uint16_t term = get_flow_tap_term(keycode, record, flow_tap_prev_keycode);
  958. return !flow_tap_expired && TIMER_DIFF_16(record->event.time, flow_tap_prev_time) <= term;
  959. }
  960. // By default, enable Flow Tap for the keys in the main alphas area and Space.
  961. // This should work reasonably even if the layout is remapped on the host to an
  962. // alt layout or international layout (e.g. Dvorak or AZERTY), where these same
  963. // key positions are mostly used for typing letters.
  964. __attribute__((weak)) bool is_flow_tap_key(uint16_t keycode) {
  965. if ((get_mods() & (MOD_MASK_CG | MOD_BIT_LALT)) != 0) {
  966. return false; // Disable Flow Tap on hotkeys.
  967. }
  968. switch (get_tap_keycode(keycode)) {
  969. case KC_SPC:
  970. case KC_A ... KC_Z:
  971. case KC_DOT:
  972. case KC_COMM:
  973. case KC_SCLN:
  974. case KC_SLSH:
  975. return true;
  976. }
  977. return false;
  978. }
  979. __attribute__((weak)) uint16_t get_flow_tap_term(uint16_t keycode, keyrecord_t *record, uint16_t prev_keycode) {
  980. if (is_flow_tap_key(keycode) && is_flow_tap_key(prev_keycode)) {
  981. return FLOW_TAP_TERM;
  982. }
  983. return 0;
  984. }
  985. # endif // FLOW_TAP_TERM
  986. /** \brief Logs tapping key if ACTION_DEBUG is enabled. */
  987. static void debug_tapping_key(void) {
  988. ac_dprintf("TAPPING_KEY=");
  989. debug_record(tapping_key);
  990. ac_dprintf("\n");
  991. }
  992. /** \brief Logs waiting buffer if ACTION_DEBUG is enabled. */
  993. static void debug_waiting_buffer(void) {
  994. ac_dprintf("{");
  995. for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
  996. ac_dprintf(" [%u]=", i);
  997. debug_record(waiting_buffer[i]);
  998. }
  999. ac_dprintf("}\n");
  1000. }
  1001. #endif