action.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /*
  2. Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "host.h"
  15. #include "keycode.h"
  16. #include "keyboard.h"
  17. #include "mousekey.h"
  18. #include "command.h"
  19. #include "led.h"
  20. #include "backlight.h"
  21. #include "action_layer.h"
  22. #include "action_tapping.h"
  23. #include "action_macro.h"
  24. #include "action_util.h"
  25. #include "action.h"
  26. #ifdef DEBUG_ACTION
  27. #include "debug.h"
  28. #else
  29. #include "nodebug.h"
  30. #endif
  31. void action_exec(keyevent_t event)
  32. {
  33. if (!IS_NOEVENT(event)) {
  34. dprint("\n---- action_exec: start -----\n");
  35. dprint("EVENT: "); debug_event(event); dprintln();
  36. }
  37. #ifdef ONEHAND_ENABLE
  38. if (!IS_NOEVENT(event)) {
  39. process_hand_swap(&event);
  40. }
  41. #endif
  42. keyrecord_t record = { .event = event };
  43. #ifndef NO_ACTION_TAPPING
  44. action_tapping_process(record);
  45. #else
  46. process_record(&record);
  47. if (!IS_NOEVENT(record.event)) {
  48. dprint("processed: "); debug_record(record); dprintln();
  49. }
  50. #endif
  51. }
  52. #ifdef ONEHAND_ENABLE
  53. bool swap_hands = false;
  54. void process_hand_swap(keyevent_t *event) {
  55. static swap_state_row_t swap_state[MATRIX_ROWS];
  56. keypos_t pos = event->key;
  57. swap_state_row_t col_bit = (swap_state_row_t)1<<pos.col;
  58. bool do_swap = event->pressed ? swap_hands :
  59. swap_state[pos.row] & (col_bit);
  60. if (do_swap) {
  61. event->key = hand_swap_config[pos.row][pos.col];
  62. swap_state[pos.row] |= col_bit;
  63. } else {
  64. swap_state[pos.row] &= ~(col_bit);
  65. }
  66. }
  67. #endif
  68. #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
  69. bool disable_action_cache = false;
  70. void process_record_nocache(keyrecord_t *record)
  71. {
  72. disable_action_cache = true;
  73. process_record(record);
  74. disable_action_cache = false;
  75. }
  76. #else
  77. void process_record_nocache(keyrecord_t *record)
  78. {
  79. process_record(record);
  80. }
  81. #endif
  82. __attribute__ ((weak))
  83. bool process_record_quantum(keyrecord_t *record) {
  84. return true;
  85. }
  86. void process_record(keyrecord_t *record)
  87. {
  88. if (IS_NOEVENT(record->event)) { return; }
  89. if(!process_record_quantum(record))
  90. return;
  91. action_t action = store_or_get_action(record->event.pressed, record->event.key);
  92. dprint("ACTION: "); debug_action(action);
  93. #ifndef NO_ACTION_LAYER
  94. dprint(" layer_state: "); layer_debug();
  95. dprint(" default_layer_state: "); default_layer_debug();
  96. #endif
  97. dprintln();
  98. process_action(record, action);
  99. }
  100. void process_action(keyrecord_t *record, action_t action)
  101. {
  102. bool do_release_oneshot = false;
  103. keyevent_t event = record->event;
  104. #ifndef NO_ACTION_TAPPING
  105. uint8_t tap_count = record->tap.count;
  106. #endif
  107. #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
  108. if (has_oneshot_layer_timed_out()) {
  109. dprintf("Oneshot layer: timeout\n");
  110. clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
  111. }
  112. #endif
  113. if (event.pressed) {
  114. // clear the potential weak mods left by previously pressed keys
  115. clear_weak_mods();
  116. }
  117. #ifndef NO_ACTION_ONESHOT
  118. // notice we only clear the one shot layer if the pressed key is not a modifier.
  119. if (is_oneshot_layer_active() && event.pressed && !IS_MOD(action.key.code)) {
  120. clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
  121. do_release_oneshot = !is_oneshot_layer_active();
  122. }
  123. #endif
  124. switch (action.kind.id) {
  125. /* Key and Mods */
  126. case ACT_LMODS:
  127. case ACT_RMODS:
  128. {
  129. uint8_t mods = (action.kind.id == ACT_LMODS) ? action.key.mods :
  130. action.key.mods<<4;
  131. if (event.pressed) {
  132. if (mods) {
  133. if (IS_MOD(action.key.code)) {
  134. // e.g. LSFT(KC_LGUI): we don't want the LSFT to be weak as it would make it useless.
  135. // this also makes LSFT(KC_LGUI) behave exactly the same as LGUI(KC_LSFT)
  136. add_mods(mods);
  137. } else {
  138. add_weak_mods(mods);
  139. }
  140. send_keyboard_report();
  141. }
  142. register_code(action.key.code);
  143. } else {
  144. unregister_code(action.key.code);
  145. if (mods) {
  146. if (IS_MOD(action.key.code)) {
  147. del_mods(mods);
  148. } else {
  149. del_weak_mods(mods);
  150. }
  151. send_keyboard_report();
  152. }
  153. }
  154. }
  155. break;
  156. #ifndef NO_ACTION_TAPPING
  157. case ACT_LMODS_TAP:
  158. case ACT_RMODS_TAP:
  159. {
  160. uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods :
  161. action.key.mods<<4;
  162. switch (action.layer_tap.code) {
  163. #ifndef NO_ACTION_ONESHOT
  164. case MODS_ONESHOT:
  165. // Oneshot modifier
  166. if (event.pressed) {
  167. if (tap_count == 0) {
  168. dprint("MODS_TAP: Oneshot: 0\n");
  169. register_mods(mods);
  170. } else if (tap_count == 1) {
  171. dprint("MODS_TAP: Oneshot: start\n");
  172. set_oneshot_mods(mods);
  173. #if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
  174. } else if (tap_count == ONESHOT_TAP_TOGGLE) {
  175. dprint("MODS_TAP: Toggling oneshot");
  176. clear_oneshot_mods();
  177. set_oneshot_locked_mods(mods);
  178. register_mods(mods);
  179. #endif
  180. } else {
  181. register_mods(mods);
  182. }
  183. } else {
  184. if (tap_count == 0) {
  185. clear_oneshot_mods();
  186. unregister_mods(mods);
  187. } else if (tap_count == 1) {
  188. // Retain Oneshot mods
  189. #if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
  190. if (mods & get_mods()) {
  191. clear_oneshot_locked_mods();
  192. clear_oneshot_mods();
  193. unregister_mods(mods);
  194. }
  195. } else if (tap_count == ONESHOT_TAP_TOGGLE) {
  196. // Toggle Oneshot Layer
  197. #endif
  198. } else {
  199. clear_oneshot_mods();
  200. unregister_mods(mods);
  201. }
  202. }
  203. break;
  204. #endif
  205. case MODS_TAP_TOGGLE:
  206. if (event.pressed) {
  207. if (tap_count <= TAPPING_TOGGLE) {
  208. register_mods(mods);
  209. }
  210. } else {
  211. if (tap_count < TAPPING_TOGGLE) {
  212. unregister_mods(mods);
  213. }
  214. }
  215. break;
  216. default:
  217. if (event.pressed) {
  218. if (tap_count > 0) {
  219. #ifndef IGNORE_MOD_TAP_INTERRUPT
  220. if (record->tap.interrupted) {
  221. dprint("mods_tap: tap: cancel: add_mods\n");
  222. // ad hoc: set 0 to cancel tap
  223. record->tap.count = 0;
  224. register_mods(mods);
  225. } else
  226. #endif
  227. {
  228. dprint("MODS_TAP: Tap: register_code\n");
  229. register_code(action.key.code);
  230. }
  231. } else {
  232. dprint("MODS_TAP: No tap: add_mods\n");
  233. register_mods(mods);
  234. }
  235. } else {
  236. if (tap_count > 0) {
  237. dprint("MODS_TAP: Tap: unregister_code\n");
  238. unregister_code(action.key.code);
  239. } else {
  240. dprint("MODS_TAP: No tap: add_mods\n");
  241. unregister_mods(mods);
  242. }
  243. }
  244. break;
  245. }
  246. }
  247. break;
  248. #endif
  249. #ifdef EXTRAKEY_ENABLE
  250. /* other HID usage */
  251. case ACT_USAGE:
  252. switch (action.usage.page) {
  253. case PAGE_SYSTEM:
  254. if (event.pressed) {
  255. host_system_send(action.usage.code);
  256. } else {
  257. host_system_send(0);
  258. }
  259. break;
  260. case PAGE_CONSUMER:
  261. if (event.pressed) {
  262. host_consumer_send(action.usage.code);
  263. } else {
  264. host_consumer_send(0);
  265. }
  266. break;
  267. }
  268. break;
  269. #endif
  270. #ifdef MOUSEKEY_ENABLE
  271. /* Mouse key */
  272. case ACT_MOUSEKEY:
  273. if (event.pressed) {
  274. mousekey_on(action.key.code);
  275. mousekey_send();
  276. } else {
  277. mousekey_off(action.key.code);
  278. mousekey_send();
  279. }
  280. break;
  281. #endif
  282. #ifndef NO_ACTION_LAYER
  283. case ACT_LAYER:
  284. if (action.layer_bitop.on == 0) {
  285. /* Default Layer Bitwise Operation */
  286. if (!event.pressed) {
  287. uint8_t shift = action.layer_bitop.part*4;
  288. uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift;
  289. uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0;
  290. switch (action.layer_bitop.op) {
  291. case OP_BIT_AND: default_layer_and(bits | mask); break;
  292. case OP_BIT_OR: default_layer_or(bits | mask); break;
  293. case OP_BIT_XOR: default_layer_xor(bits | mask); break;
  294. case OP_BIT_SET: default_layer_and(mask); default_layer_or(bits); break;
  295. }
  296. }
  297. } else {
  298. /* Layer Bitwise Operation */
  299. if (event.pressed ? (action.layer_bitop.on & ON_PRESS) :
  300. (action.layer_bitop.on & ON_RELEASE)) {
  301. uint8_t shift = action.layer_bitop.part*4;
  302. uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift;
  303. uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0;
  304. switch (action.layer_bitop.op) {
  305. case OP_BIT_AND: layer_and(bits | mask); break;
  306. case OP_BIT_OR: layer_or(bits | mask); break;
  307. case OP_BIT_XOR: layer_xor(bits | mask); break;
  308. case OP_BIT_SET: layer_and(mask); layer_or(bits); break;
  309. }
  310. }
  311. }
  312. break;
  313. #ifndef NO_ACTION_TAPPING
  314. case ACT_LAYER_TAP:
  315. case ACT_LAYER_TAP_EXT:
  316. switch (action.layer_tap.code) {
  317. case 0xe0 ... 0xef:
  318. /* layer On/Off with modifiers(left only) */
  319. if (event.pressed) {
  320. layer_on(action.layer_tap.val);
  321. register_mods(action.layer_tap.code & 0x0f);
  322. } else {
  323. layer_off(action.layer_tap.val);
  324. unregister_mods(action.layer_tap.code & 0x0f);
  325. }
  326. break;
  327. case OP_TAP_TOGGLE:
  328. /* tap toggle */
  329. if (event.pressed) {
  330. if (tap_count < TAPPING_TOGGLE) {
  331. layer_invert(action.layer_tap.val);
  332. }
  333. } else {
  334. if (tap_count <= TAPPING_TOGGLE) {
  335. layer_invert(action.layer_tap.val);
  336. }
  337. }
  338. break;
  339. case OP_ON_OFF:
  340. event.pressed ? layer_on(action.layer_tap.val) :
  341. layer_off(action.layer_tap.val);
  342. break;
  343. case OP_OFF_ON:
  344. event.pressed ? layer_off(action.layer_tap.val) :
  345. layer_on(action.layer_tap.val);
  346. break;
  347. case OP_SET_CLEAR:
  348. event.pressed ? layer_move(action.layer_tap.val) :
  349. layer_clear();
  350. break;
  351. #ifndef NO_ACTION_ONESHOT
  352. case OP_ONESHOT:
  353. // Oneshot modifier
  354. #if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
  355. do_release_oneshot = false;
  356. if (event.pressed) {
  357. del_mods(get_oneshot_locked_mods());
  358. if (get_oneshot_layer_state() == ONESHOT_TOGGLED) {
  359. reset_oneshot_layer();
  360. layer_off(action.layer_tap.val);
  361. break;
  362. } else if (tap_count < ONESHOT_TAP_TOGGLE) {
  363. layer_on(action.layer_tap.val);
  364. set_oneshot_layer(action.layer_tap.val, ONESHOT_START);
  365. }
  366. } else {
  367. add_mods(get_oneshot_locked_mods());
  368. if (tap_count >= ONESHOT_TAP_TOGGLE) {
  369. reset_oneshot_layer();
  370. clear_oneshot_locked_mods();
  371. set_oneshot_layer(action.layer_tap.val, ONESHOT_TOGGLED);
  372. } else {
  373. clear_oneshot_layer_state(ONESHOT_PRESSED);
  374. }
  375. }
  376. #else
  377. if (event.pressed) {
  378. layer_on(action.layer_tap.val);
  379. set_oneshot_layer(action.layer_tap.val, ONESHOT_START);
  380. } else {
  381. clear_oneshot_layer_state(ONESHOT_PRESSED);
  382. if (tap_count > 1) {
  383. clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
  384. }
  385. }
  386. #endif
  387. break;
  388. #endif
  389. default:
  390. /* tap key */
  391. if (event.pressed) {
  392. if (tap_count > 0) {
  393. dprint("KEYMAP_TAP_KEY: Tap: register_code\n");
  394. register_code(action.layer_tap.code);
  395. } else {
  396. dprint("KEYMAP_TAP_KEY: No tap: On on press\n");
  397. layer_on(action.layer_tap.val);
  398. }
  399. } else {
  400. if (tap_count > 0) {
  401. dprint("KEYMAP_TAP_KEY: Tap: unregister_code\n");
  402. unregister_code(action.layer_tap.code);
  403. } else {
  404. dprint("KEYMAP_TAP_KEY: No tap: Off on release\n");
  405. layer_off(action.layer_tap.val);
  406. }
  407. }
  408. break;
  409. }
  410. break;
  411. #endif
  412. #endif
  413. /* Extentions */
  414. #ifndef NO_ACTION_MACRO
  415. case ACT_MACRO:
  416. action_macro_play(action_get_macro(record, action.func.id, action.func.opt));
  417. break;
  418. #endif
  419. #ifdef BACKLIGHT_ENABLE
  420. case ACT_BACKLIGHT:
  421. if (!event.pressed) {
  422. switch (action.backlight.opt) {
  423. case BACKLIGHT_INCREASE:
  424. backlight_increase();
  425. break;
  426. case BACKLIGHT_DECREASE:
  427. backlight_decrease();
  428. break;
  429. case BACKLIGHT_TOGGLE:
  430. backlight_toggle();
  431. break;
  432. case BACKLIGHT_STEP:
  433. backlight_step();
  434. break;
  435. case BACKLIGHT_LEVEL:
  436. backlight_level(action.backlight.level);
  437. break;
  438. }
  439. }
  440. break;
  441. #endif
  442. case ACT_COMMAND:
  443. switch (action.command.id) {
  444. #ifdef ONEHAND_ENABLE
  445. case CMD_SWAP_HANDS:
  446. swap_hands = event.pressed;
  447. break;
  448. #endif
  449. }
  450. break;
  451. #ifndef NO_ACTION_FUNCTION
  452. case ACT_FUNCTION:
  453. action_function(record, action.func.id, action.func.opt);
  454. break;
  455. #endif
  456. default:
  457. break;
  458. }
  459. #ifndef NO_ACTION_ONESHOT
  460. /* Because we switch layers after a oneshot event, we need to release the
  461. * key before we leave the layer or no key up event will be generated.
  462. */
  463. if (do_release_oneshot && !(get_oneshot_layer_state() & ONESHOT_PRESSED ) ) {
  464. record->event.pressed = false;
  465. layer_on(get_oneshot_layer());
  466. process_record(record);
  467. layer_off(get_oneshot_layer());
  468. }
  469. #endif
  470. }
  471. /*
  472. * Utilities for actions.
  473. */
  474. void register_code(uint8_t code)
  475. {
  476. if (code == KC_NO) {
  477. return;
  478. }
  479. #ifdef LOCKING_SUPPORT_ENABLE
  480. else if (KC_LOCKING_CAPS == code) {
  481. #ifdef LOCKING_RESYNC_ENABLE
  482. // Resync: ignore if caps lock already is on
  483. if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) return;
  484. #endif
  485. add_key(KC_CAPSLOCK);
  486. send_keyboard_report();
  487. del_key(KC_CAPSLOCK);
  488. send_keyboard_report();
  489. }
  490. else if (KC_LOCKING_NUM == code) {
  491. #ifdef LOCKING_RESYNC_ENABLE
  492. if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) return;
  493. #endif
  494. add_key(KC_NUMLOCK);
  495. send_keyboard_report();
  496. del_key(KC_NUMLOCK);
  497. send_keyboard_report();
  498. }
  499. else if (KC_LOCKING_SCROLL == code) {
  500. #ifdef LOCKING_RESYNC_ENABLE
  501. if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) return;
  502. #endif
  503. add_key(KC_SCROLLLOCK);
  504. send_keyboard_report();
  505. del_key(KC_SCROLLLOCK);
  506. send_keyboard_report();
  507. }
  508. #endif
  509. else if IS_KEY(code) {
  510. // TODO: should push command_proc out of this block?
  511. if (command_proc(code)) return;
  512. #ifndef NO_ACTION_ONESHOT
  513. /* TODO: remove
  514. if (oneshot_state.mods && !oneshot_state.disabled) {
  515. uint8_t tmp_mods = get_mods();
  516. add_mods(oneshot_state.mods);
  517. add_key(code);
  518. send_keyboard_report();
  519. set_mods(tmp_mods);
  520. send_keyboard_report();
  521. oneshot_cancel();
  522. } else
  523. */
  524. #endif
  525. {
  526. add_key(code);
  527. send_keyboard_report();
  528. }
  529. }
  530. else if IS_MOD(code) {
  531. add_mods(MOD_BIT(code));
  532. send_keyboard_report();
  533. }
  534. else if IS_SYSTEM(code) {
  535. host_system_send(KEYCODE2SYSTEM(code));
  536. }
  537. else if IS_CONSUMER(code) {
  538. host_consumer_send(KEYCODE2CONSUMER(code));
  539. }
  540. }
  541. void unregister_code(uint8_t code)
  542. {
  543. if (code == KC_NO) {
  544. return;
  545. }
  546. #ifdef LOCKING_SUPPORT_ENABLE
  547. else if (KC_LOCKING_CAPS == code) {
  548. #ifdef LOCKING_RESYNC_ENABLE
  549. // Resync: ignore if caps lock already is off
  550. if (!(host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))) return;
  551. #endif
  552. add_key(KC_CAPSLOCK);
  553. send_keyboard_report();
  554. del_key(KC_CAPSLOCK);
  555. send_keyboard_report();
  556. }
  557. else if (KC_LOCKING_NUM == code) {
  558. #ifdef LOCKING_RESYNC_ENABLE
  559. if (!(host_keyboard_leds() & (1<<USB_LED_NUM_LOCK))) return;
  560. #endif
  561. add_key(KC_NUMLOCK);
  562. send_keyboard_report();
  563. del_key(KC_NUMLOCK);
  564. send_keyboard_report();
  565. }
  566. else if (KC_LOCKING_SCROLL == code) {
  567. #ifdef LOCKING_RESYNC_ENABLE
  568. if (!(host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK))) return;
  569. #endif
  570. add_key(KC_SCROLLLOCK);
  571. send_keyboard_report();
  572. del_key(KC_SCROLLLOCK);
  573. send_keyboard_report();
  574. }
  575. #endif
  576. else if IS_KEY(code) {
  577. del_key(code);
  578. send_keyboard_report();
  579. }
  580. else if IS_MOD(code) {
  581. del_mods(MOD_BIT(code));
  582. send_keyboard_report();
  583. }
  584. else if IS_SYSTEM(code) {
  585. host_system_send(0);
  586. }
  587. else if IS_CONSUMER(code) {
  588. host_consumer_send(0);
  589. }
  590. }
  591. void register_mods(uint8_t mods)
  592. {
  593. if (mods) {
  594. add_mods(mods);
  595. send_keyboard_report();
  596. }
  597. }
  598. void unregister_mods(uint8_t mods)
  599. {
  600. if (mods) {
  601. del_mods(mods);
  602. send_keyboard_report();
  603. }
  604. }
  605. void clear_keyboard(void)
  606. {
  607. clear_mods();
  608. clear_keyboard_but_mods();
  609. }
  610. void clear_keyboard_but_mods(void)
  611. {
  612. clear_weak_mods();
  613. clear_macro_mods();
  614. clear_keys();
  615. send_keyboard_report();
  616. #ifdef MOUSEKEY_ENABLE
  617. mousekey_clear();
  618. mousekey_send();
  619. #endif
  620. #ifdef EXTRAKEY_ENABLE
  621. host_system_send(0);
  622. host_consumer_send(0);
  623. #endif
  624. }
  625. bool is_tap_key(keypos_t key)
  626. {
  627. action_t action = layer_switch_get_action(key);
  628. switch (action.kind.id) {
  629. case ACT_LMODS_TAP:
  630. case ACT_RMODS_TAP:
  631. case ACT_LAYER_TAP:
  632. case ACT_LAYER_TAP_EXT:
  633. switch (action.layer_tap.code) {
  634. case 0x00 ... 0xdf:
  635. case OP_TAP_TOGGLE:
  636. case OP_ONESHOT:
  637. return true;
  638. }
  639. return false;
  640. case ACT_MACRO:
  641. case ACT_FUNCTION:
  642. if (action.func.opt & FUNC_TAP) { return true; }
  643. return false;
  644. }
  645. return false;
  646. }
  647. /*
  648. * debug print
  649. */
  650. void debug_event(keyevent_t event)
  651. {
  652. dprintf("%04X%c(%u)", (event.key.row<<8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time);
  653. }
  654. void debug_record(keyrecord_t record)
  655. {
  656. debug_event(record.event);
  657. #ifndef NO_ACTION_TAPPING
  658. dprintf(":%u%c", record.tap.count, (record.tap.interrupted ? '-' : ' '));
  659. #endif
  660. }
  661. void debug_action(action_t action)
  662. {
  663. switch (action.kind.id) {
  664. case ACT_LMODS: dprint("ACT_LMODS"); break;
  665. case ACT_RMODS: dprint("ACT_RMODS"); break;
  666. case ACT_LMODS_TAP: dprint("ACT_LMODS_TAP"); break;
  667. case ACT_RMODS_TAP: dprint("ACT_RMODS_TAP"); break;
  668. case ACT_USAGE: dprint("ACT_USAGE"); break;
  669. case ACT_MOUSEKEY: dprint("ACT_MOUSEKEY"); break;
  670. case ACT_LAYER: dprint("ACT_LAYER"); break;
  671. case ACT_LAYER_TAP: dprint("ACT_LAYER_TAP"); break;
  672. case ACT_LAYER_TAP_EXT: dprint("ACT_LAYER_TAP_EXT"); break;
  673. case ACT_MACRO: dprint("ACT_MACRO"); break;
  674. case ACT_COMMAND: dprint("ACT_COMMAND"); break;
  675. case ACT_FUNCTION: dprint("ACT_FUNCTION"); break;
  676. default: dprint("UNKNOWN"); break;
  677. }
  678. dprintf("[%X:%02X]", action.kind.param>>8, action.kind.param&0xff);
  679. }