process_combo.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /* Copyright 2016 Jack Humbert
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "print.h"
  17. #include "process_combo.h"
  18. #include "action_tapping.h"
  19. #include "action.h"
  20. #ifdef COMBO_COUNT
  21. __attribute__((weak)) combo_t key_combos[COMBO_COUNT];
  22. uint16_t COMBO_LEN = COMBO_COUNT;
  23. #else
  24. extern combo_t key_combos[];
  25. extern uint16_t COMBO_LEN;
  26. #endif
  27. __attribute__((weak)) void process_combo_event(uint16_t combo_index, bool pressed) {}
  28. #ifdef COMBO_MUST_HOLD_PER_COMBO
  29. __attribute__((weak)) bool get_combo_must_hold(uint16_t index, combo_t *combo) { return false; }
  30. #endif
  31. #ifdef COMBO_MUST_TAP_PER_COMBO
  32. __attribute__((weak)) bool get_combo_must_tap(uint16_t index, combo_t *combo) { return false; }
  33. #endif
  34. #ifdef COMBO_TERM_PER_COMBO
  35. __attribute__((weak)) uint16_t get_combo_term(uint16_t index, combo_t *combo) { return COMBO_TERM; }
  36. #endif
  37. #ifdef COMBO_MUST_PRESS_IN_ORDER_PER_COMBO
  38. __attribute__((weak)) bool get_combo_must_press_in_order(uint16_t combo_index, combo_t *combo) { return true; }
  39. #endif
  40. #ifdef COMBO_PROCESS_KEY_RELEASE
  41. __attribute__((weak)) bool process_combo_key_release(uint16_t combo_index, combo_t *combo, uint8_t key_index, uint16_t keycode) { return false; }
  42. #endif
  43. #ifdef COMBO_SHOULD_TRIGGER
  44. __attribute__((weak)) bool combo_should_trigger(uint16_t combo_index, combo_t *combo, uint16_t keycode, keyrecord_t *record) { return true; }
  45. #endif
  46. #ifndef COMBO_NO_TIMER
  47. static uint16_t timer = 0;
  48. #endif
  49. static bool b_combo_enable = true; // defaults to enabled
  50. static uint16_t longest_term = 0;
  51. typedef struct {
  52. keyrecord_t record;
  53. uint16_t combo_index;
  54. uint16_t keycode;
  55. } queued_record_t;
  56. static uint8_t key_buffer_size = 0;
  57. static queued_record_t key_buffer[COMBO_KEY_BUFFER_LENGTH];
  58. typedef struct {
  59. uint16_t combo_index;
  60. } queued_combo_t;
  61. static uint8_t combo_buffer_write = 0;
  62. static uint8_t combo_buffer_read = 0;
  63. static queued_combo_t combo_buffer[COMBO_BUFFER_LENGTH];
  64. #define INCREMENT_MOD(i) i = (i + 1) % COMBO_BUFFER_LENGTH
  65. #define COMBO_KEY_POS ((keypos_t){.col = 254, .row = 254})
  66. #ifndef EXTRA_SHORT_COMBOS
  67. /* flags are their own elements in combo_t struct. */
  68. # define COMBO_ACTIVE(combo) (combo->active)
  69. # define COMBO_DISABLED(combo) (combo->disabled)
  70. # define COMBO_STATE(combo) (combo->state)
  71. # define ACTIVATE_COMBO(combo) \
  72. do { \
  73. combo->active = true; \
  74. } while (0)
  75. # define DEACTIVATE_COMBO(combo) \
  76. do { \
  77. combo->active = false; \
  78. } while (0)
  79. # define DISABLE_COMBO(combo) \
  80. do { \
  81. combo->disabled = true; \
  82. } while (0)
  83. # define RESET_COMBO_STATE(combo) \
  84. do { \
  85. combo->disabled = false; \
  86. combo->state = 0; \
  87. } while (0)
  88. #else
  89. /* flags are at the two high bits of state. */
  90. # define COMBO_ACTIVE(combo) (combo->state & 0x80)
  91. # define COMBO_DISABLED(combo) (combo->state & 0x40)
  92. # define COMBO_STATE(combo) (combo->state & 0x3F)
  93. # define ACTIVATE_COMBO(combo) \
  94. do { \
  95. combo->state |= 0x80; \
  96. } while (0)
  97. # define DEACTIVATE_COMBO(combo) \
  98. do { \
  99. combo->state &= ~0x80; \
  100. } while (0)
  101. # define DISABLE_COMBO(combo) \
  102. do { \
  103. combo->state |= 0x40; \
  104. } while (0)
  105. # define RESET_COMBO_STATE(combo) \
  106. do { \
  107. combo->state &= ~0x7F; \
  108. } while (0)
  109. #endif
  110. static inline void release_combo(uint16_t combo_index, combo_t *combo) {
  111. if (combo->keycode) {
  112. keyrecord_t record = {
  113. .event =
  114. {
  115. .key = COMBO_KEY_POS,
  116. .time = timer_read() | 1,
  117. .pressed = false,
  118. },
  119. .keycode = combo->keycode,
  120. };
  121. #ifndef NO_ACTION_TAPPING
  122. action_tapping_process(record);
  123. #else
  124. process_record(&record);
  125. #endif
  126. } else {
  127. process_combo_event(combo_index, false);
  128. }
  129. DEACTIVATE_COMBO(combo);
  130. }
  131. static inline bool _get_combo_must_hold(uint16_t combo_index, combo_t *combo) {
  132. #ifdef COMBO_NO_TIMER
  133. return false;
  134. #elif defined(COMBO_MUST_HOLD_PER_COMBO)
  135. return get_combo_must_hold(combo_index, combo);
  136. #elif defined(COMBO_MUST_HOLD_MODS)
  137. return (KEYCODE_IS_MOD(combo->keycode) || (combo->keycode >= QK_MOMENTARY && combo->keycode <= QK_MOMENTARY_MAX));
  138. #endif
  139. return false;
  140. }
  141. static inline uint16_t _get_wait_time(uint16_t combo_index, combo_t *combo) {
  142. if (_get_combo_must_hold(combo_index, combo)
  143. #ifdef COMBO_MUST_TAP_PER_COMBO
  144. || get_combo_must_tap(combo_index, combo)
  145. #endif
  146. ) {
  147. if (longest_term < COMBO_HOLD_TERM) {
  148. return COMBO_HOLD_TERM;
  149. }
  150. }
  151. return longest_term;
  152. }
  153. static inline uint16_t _get_combo_term(uint16_t combo_index, combo_t *combo) {
  154. #if defined(COMBO_TERM_PER_COMBO)
  155. return get_combo_term(combo_index, combo);
  156. #endif
  157. return COMBO_TERM;
  158. }
  159. void clear_combos(void) {
  160. uint16_t index = 0;
  161. longest_term = 0;
  162. for (index = 0; index < COMBO_LEN; ++index) {
  163. combo_t *combo = &key_combos[index];
  164. if (!COMBO_ACTIVE(combo)) {
  165. RESET_COMBO_STATE(combo);
  166. }
  167. }
  168. }
  169. static inline void dump_key_buffer(void) {
  170. /* First call start from 0 index; recursive calls need to start from i+1 index */
  171. static uint8_t key_buffer_next = 0;
  172. #if TAP_CODE_DELAY > 0
  173. bool delay_done = false;
  174. #endif
  175. if (key_buffer_size == 0) {
  176. return;
  177. }
  178. for (uint8_t key_buffer_i = key_buffer_next; key_buffer_i < key_buffer_size; key_buffer_i++) {
  179. key_buffer_next = key_buffer_i + 1;
  180. queued_record_t *qrecord = &key_buffer[key_buffer_i];
  181. keyrecord_t * record = &qrecord->record;
  182. if (IS_NOEVENT(record->event)) {
  183. continue;
  184. }
  185. if (!record->keycode && qrecord->combo_index != (uint16_t)-1) {
  186. process_combo_event(qrecord->combo_index, true);
  187. } else {
  188. #ifndef NO_ACTION_TAPPING
  189. action_tapping_process(*record);
  190. #else
  191. process_record(record);
  192. #endif
  193. }
  194. record->event.time = 0;
  195. clear_weak_mods();
  196. #if TAP_CODE_DELAY > 0
  197. // only delay once and for a non-tapping key
  198. if (!delay_done && !is_tap_record(record)) {
  199. delay_done = true;
  200. wait_ms(TAP_CODE_DELAY);
  201. }
  202. #endif
  203. }
  204. key_buffer_next = key_buffer_size = 0;
  205. }
  206. #define NO_COMBO_KEYS_ARE_DOWN (0 == COMBO_STATE(combo))
  207. #define ALL_COMBO_KEYS_ARE_DOWN(state, key_count) (((1 << key_count) - 1) == state)
  208. #define ONLY_ONE_KEY_IS_DOWN(state) !(state & (state - 1))
  209. #define KEY_NOT_YET_RELEASED(state, key_index) ((1 << key_index) & state)
  210. #define KEY_STATE_DOWN(state, key_index) \
  211. do { \
  212. state |= (1 << key_index); \
  213. } while (0)
  214. #define KEY_STATE_UP(state, key_index) \
  215. do { \
  216. state &= ~(1 << key_index); \
  217. } while (0)
  218. static inline void _find_key_index_and_count(const uint16_t *keys, uint16_t keycode, uint16_t *key_index, uint8_t *key_count) {
  219. while (true) {
  220. uint16_t key = pgm_read_word(&keys[*key_count]);
  221. if (keycode == key) *key_index = *key_count;
  222. if (COMBO_END == key) break;
  223. (*key_count)++;
  224. }
  225. }
  226. void drop_combo_from_buffer(uint16_t combo_index) {
  227. /* Mark a combo as processed from the buffer. If the buffer is in the
  228. * beginning of the buffer, drop it. */
  229. uint8_t i = combo_buffer_read;
  230. while (i != combo_buffer_write) {
  231. queued_combo_t *qcombo = &combo_buffer[i];
  232. if (qcombo->combo_index == combo_index) {
  233. combo_t *combo = &key_combos[combo_index];
  234. DISABLE_COMBO(combo);
  235. if (i == combo_buffer_read) {
  236. INCREMENT_MOD(combo_buffer_read);
  237. }
  238. break;
  239. }
  240. INCREMENT_MOD(i);
  241. }
  242. }
  243. void apply_combo(uint16_t combo_index, combo_t *combo) {
  244. /* Apply combo's result keycode to the last chord key of the combo and
  245. * disable the other keys. */
  246. if (COMBO_DISABLED(combo)) {
  247. return;
  248. }
  249. // state to check against so we find the last key of the combo from the buffer
  250. #if defined(EXTRA_EXTRA_LONG_COMBOS)
  251. uint32_t state = 0;
  252. #elif defined(EXTRA_LONG_COMBOS)
  253. uint16_t state = 0;
  254. #else
  255. uint8_t state = 0;
  256. #endif
  257. for (uint8_t key_buffer_i = 0; key_buffer_i < key_buffer_size; key_buffer_i++) {
  258. queued_record_t *qrecord = &key_buffer[key_buffer_i];
  259. keyrecord_t * record = &qrecord->record;
  260. uint16_t keycode = qrecord->keycode;
  261. uint8_t key_count = 0;
  262. uint16_t key_index = -1;
  263. _find_key_index_and_count(combo->keys, keycode, &key_index, &key_count);
  264. if (-1 == (int16_t)key_index) {
  265. // key not part of this combo
  266. continue;
  267. }
  268. KEY_STATE_DOWN(state, key_index);
  269. if (ALL_COMBO_KEYS_ARE_DOWN(state, key_count)) {
  270. // this in the end executes the combo when the key_buffer is dumped.
  271. record->keycode = combo->keycode;
  272. record->event.key = COMBO_KEY_POS;
  273. qrecord->combo_index = combo_index;
  274. ACTIVATE_COMBO(combo);
  275. break;
  276. } else {
  277. // key was part of the combo but not the last one, "disable" it
  278. // by making it a TICK event.
  279. record->event.time = 0;
  280. }
  281. }
  282. drop_combo_from_buffer(combo_index);
  283. }
  284. static inline void apply_combos(void) {
  285. // Apply all buffered normal combos.
  286. for (uint8_t i = combo_buffer_read; i != combo_buffer_write; INCREMENT_MOD(i)) {
  287. queued_combo_t *buffered_combo = &combo_buffer[i];
  288. combo_t * combo = &key_combos[buffered_combo->combo_index];
  289. #ifdef COMBO_MUST_TAP_PER_COMBO
  290. if (get_combo_must_tap(buffered_combo->combo_index, combo)) {
  291. // Tap-only combos are applied on key release only, so let's drop 'em here.
  292. drop_combo_from_buffer(buffered_combo->combo_index);
  293. continue;
  294. }
  295. #endif
  296. apply_combo(buffered_combo->combo_index, combo);
  297. }
  298. dump_key_buffer();
  299. clear_combos();
  300. }
  301. combo_t *overlaps(combo_t *combo1, combo_t *combo2) {
  302. /* Checks if the combos overlap and returns the combo that should be
  303. * dropped from the combo buffer.
  304. * The combo that has less keys will be dropped. If they have the same
  305. * amount of keys, drop combo1. */
  306. uint8_t idx1 = 0, idx2 = 0;
  307. uint16_t key1, key2;
  308. bool overlaps = false;
  309. while ((key1 = pgm_read_word(&combo1->keys[idx1])) != COMBO_END) {
  310. idx2 = 0;
  311. while ((key2 = pgm_read_word(&combo2->keys[idx2])) != COMBO_END) {
  312. if (key1 == key2) overlaps = true;
  313. idx2 += 1;
  314. }
  315. idx1 += 1;
  316. }
  317. if (!overlaps) return NULL;
  318. if (idx2 < idx1) return combo2;
  319. return combo1;
  320. }
  321. #if defined(COMBO_MUST_PRESS_IN_ORDER) || defined(COMBO_MUST_PRESS_IN_ORDER_PER_COMBO)
  322. static bool keys_pressed_in_order(uint16_t combo_index, combo_t *combo, uint16_t key_index, uint16_t keycode, keyrecord_t *record) {
  323. # ifdef COMBO_MUST_PRESS_IN_ORDER_PER_COMBO
  324. if (!get_combo_must_press_in_order(combo_index, combo)) {
  325. return true;
  326. }
  327. # endif
  328. if (
  329. // The `state` bit for the key being pressed.
  330. (1 << key_index) ==
  331. // The *next* combo key's bit.
  332. (COMBO_STATE(combo) + 1)
  333. // E.g. two keys already pressed: `state == 11`.
  334. // Next possible `state` is `111`.
  335. // So the needed bit is `100` which we get with `11 + 1`.
  336. ) {
  337. return true;
  338. }
  339. return false;
  340. }
  341. #endif
  342. static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *record, uint16_t combo_index) {
  343. uint8_t key_count = 0;
  344. uint16_t key_index = -1;
  345. _find_key_index_and_count(combo->keys, keycode, &key_index, &key_count);
  346. /* Continue processing if key isn't part of current combo. */
  347. if (-1 == (int16_t)key_index) {
  348. return false;
  349. }
  350. bool key_is_part_of_combo = (!COMBO_DISABLED(combo) && is_combo_enabled()
  351. #if defined(COMBO_MUST_PRESS_IN_ORDER) || defined(COMBO_MUST_PRESS_IN_ORDER_PER_COMBO)
  352. && keys_pressed_in_order(combo_index, combo, key_index, keycode, record)
  353. #endif
  354. #ifdef COMBO_SHOULD_TRIGGER
  355. && combo_should_trigger(combo_index, combo, keycode, record)
  356. #endif
  357. );
  358. if (record->event.pressed && key_is_part_of_combo) {
  359. uint16_t time = _get_combo_term(combo_index, combo);
  360. if (!COMBO_ACTIVE(combo)) {
  361. KEY_STATE_DOWN(combo->state, key_index);
  362. if (longest_term < time) {
  363. longest_term = time;
  364. }
  365. }
  366. if (ALL_COMBO_KEYS_ARE_DOWN(COMBO_STATE(combo), key_count)) {
  367. /* Combo was fully pressed */
  368. /* Buffer the combo so we can fire it after COMBO_TERM */
  369. #ifndef COMBO_NO_TIMER
  370. /* Don't buffer this combo if its combo term has passed. */
  371. if (timer && timer_elapsed(timer) > time) {
  372. DISABLE_COMBO(combo);
  373. return true;
  374. } else
  375. #endif
  376. {
  377. // disable readied combos that overlap with this combo
  378. combo_t *drop = NULL;
  379. for (uint8_t combo_buffer_i = combo_buffer_read; combo_buffer_i != combo_buffer_write; INCREMENT_MOD(combo_buffer_i)) {
  380. queued_combo_t *qcombo = &combo_buffer[combo_buffer_i];
  381. combo_t * buffered_combo = &key_combos[qcombo->combo_index];
  382. if ((drop = overlaps(buffered_combo, combo))) {
  383. DISABLE_COMBO(drop);
  384. if (drop == combo) {
  385. // stop checking for overlaps if dropped combo was current combo.
  386. break;
  387. } else if (combo_buffer_i == combo_buffer_read && drop == buffered_combo) {
  388. /* Drop the disabled buffered combo from the buffer if
  389. * it is in the beginning of the buffer. */
  390. INCREMENT_MOD(combo_buffer_read);
  391. }
  392. }
  393. }
  394. if (drop != combo) {
  395. // save this combo to buffer
  396. combo_buffer[combo_buffer_write] = (queued_combo_t){
  397. .combo_index = combo_index,
  398. };
  399. INCREMENT_MOD(combo_buffer_write);
  400. // get possible longer waiting time for tap-/hold-only combos.
  401. longest_term = _get_wait_time(combo_index, combo);
  402. }
  403. } // if timer elapsed end
  404. }
  405. } else {
  406. // chord releases
  407. if (!COMBO_ACTIVE(combo) && ALL_COMBO_KEYS_ARE_DOWN(COMBO_STATE(combo), key_count)) {
  408. /* First key quickly released */
  409. if (COMBO_DISABLED(combo) || _get_combo_must_hold(combo_index, combo)) {
  410. // combo wasn't tappable, disable it and drop it from buffer.
  411. drop_combo_from_buffer(combo_index);
  412. key_is_part_of_combo = false;
  413. }
  414. #ifdef COMBO_MUST_TAP_PER_COMBO
  415. else if (get_combo_must_tap(combo_index, combo)) {
  416. // immediately apply tap-only combo
  417. apply_combo(combo_index, combo);
  418. apply_combos(); // also apply other prepared combos and dump key buffer
  419. # ifdef COMBO_PROCESS_KEY_RELEASE
  420. if (process_combo_key_release(combo_index, combo, key_index, keycode)) {
  421. release_combo(combo_index, combo);
  422. }
  423. # endif
  424. }
  425. #endif
  426. } else if (COMBO_ACTIVE(combo) && ONLY_ONE_KEY_IS_DOWN(COMBO_STATE(combo)) && KEY_NOT_YET_RELEASED(COMBO_STATE(combo), key_index)) {
  427. /* last key released */
  428. release_combo(combo_index, combo);
  429. key_is_part_of_combo = true;
  430. #ifdef COMBO_PROCESS_KEY_RELEASE
  431. process_combo_key_release(combo_index, combo, key_index, keycode);
  432. #endif
  433. } else if (COMBO_ACTIVE(combo) && KEY_NOT_YET_RELEASED(COMBO_STATE(combo), key_index)) {
  434. /* first or middle key released */
  435. key_is_part_of_combo = true;
  436. #ifdef COMBO_PROCESS_KEY_RELEASE
  437. if (process_combo_key_release(combo_index, combo, key_index, keycode)) {
  438. release_combo(combo_index, combo);
  439. }
  440. #endif
  441. } else {
  442. /* The released key was part of an incomplete combo */
  443. key_is_part_of_combo = false;
  444. }
  445. KEY_STATE_UP(combo->state, key_index);
  446. }
  447. return key_is_part_of_combo;
  448. }
  449. bool process_combo(uint16_t keycode, keyrecord_t *record) {
  450. bool is_combo_key = false;
  451. bool no_combo_keys_pressed = true;
  452. if (keycode == CMB_ON && record->event.pressed) {
  453. combo_enable();
  454. return true;
  455. }
  456. if (keycode == CMB_OFF && record->event.pressed) {
  457. combo_disable();
  458. return true;
  459. }
  460. if (keycode == CMB_TOG && record->event.pressed) {
  461. combo_toggle();
  462. return true;
  463. }
  464. #ifdef COMBO_ONLY_FROM_LAYER
  465. /* Only check keycodes from one layer. */
  466. keycode = keymap_key_to_keycode(COMBO_ONLY_FROM_LAYER, record->event.key);
  467. #endif
  468. for (uint16_t idx = 0; idx < COMBO_LEN; ++idx) {
  469. combo_t *combo = &key_combos[idx];
  470. is_combo_key |= process_single_combo(combo, keycode, record, idx);
  471. no_combo_keys_pressed = no_combo_keys_pressed && (NO_COMBO_KEYS_ARE_DOWN || COMBO_ACTIVE(combo) || COMBO_DISABLED(combo));
  472. }
  473. if (record->event.pressed && is_combo_key) {
  474. #ifndef COMBO_NO_TIMER
  475. # ifdef COMBO_STRICT_TIMER
  476. if (!timer) {
  477. // timer is set only on the first key
  478. timer = timer_read();
  479. }
  480. # else
  481. timer = timer_read();
  482. # endif
  483. #endif
  484. if (key_buffer_size < COMBO_KEY_BUFFER_LENGTH) {
  485. key_buffer[key_buffer_size++] = (queued_record_t){
  486. .record = *record,
  487. .keycode = keycode,
  488. .combo_index = -1, // this will be set when applying combos
  489. };
  490. }
  491. } else {
  492. if (combo_buffer_read != combo_buffer_write) {
  493. // some combo is prepared
  494. apply_combos();
  495. } else {
  496. // reset state if there are no combo keys pressed at all
  497. dump_key_buffer();
  498. #ifndef COMBO_NO_TIMER
  499. timer = 0;
  500. #endif
  501. clear_combos();
  502. }
  503. }
  504. return !is_combo_key;
  505. }
  506. void combo_task(void) {
  507. if (!b_combo_enable) {
  508. return;
  509. }
  510. #ifndef COMBO_NO_TIMER
  511. if (timer && timer_elapsed(timer) > longest_term) {
  512. if (combo_buffer_read != combo_buffer_write) {
  513. apply_combos();
  514. longest_term = 0;
  515. timer = 0;
  516. } else {
  517. dump_key_buffer();
  518. timer = 0;
  519. clear_combos();
  520. }
  521. }
  522. #endif
  523. }
  524. void combo_enable(void) { b_combo_enable = true; }
  525. void combo_disable(void) {
  526. #ifndef COMBO_NO_TIMER
  527. timer = 0;
  528. #endif
  529. b_combo_enable = false;
  530. combo_buffer_read = combo_buffer_write;
  531. clear_combos();
  532. dump_key_buffer();
  533. }
  534. void combo_toggle(void) {
  535. if (b_combo_enable) {
  536. combo_disable();
  537. } else {
  538. combo_enable();
  539. }
  540. }
  541. bool is_combo_enabled(void) { return b_combo_enable; }