You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

638 lines
21 KiB

  1. /*
  2. Copyright 2018 Eric Gebhart <e.a.gebhart@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 "ericgebhart.h"
  15. #include "quantum.h"
  16. #include "version.h"
  17. #include "action.h"
  18. #include "action_layer.h"
  19. #include "process_keycode/process_tap_dance.h"
  20. #include "keymap_bepo.h"
  21. float tone_copy[][2] = SONG(SCROLL_LOCK_ON_SOUND);
  22. float tone_paste[][2] = SONG(SCROLL_LOCK_OFF_SOUND);
  23. static uint16_t copy_paste_timer;
  24. userspace_config_t userspace_config;
  25. void tap(uint16_t keycode){ register_code(keycode); unregister_code(keycode); };
  26. // Add reconfigurable functions here, for keymap customization
  27. // This allows for a global, userspace functions, and continued
  28. // customization of the keymap. Use _keymap instead of _user
  29. // functions in the keymaps
  30. __attribute__ ((weak))
  31. void matrix_init_keymap(void) {}
  32. __attribute__ ((weak))
  33. void matrix_scan_keymap(void) {}
  34. __attribute__ ((weak))
  35. bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  36. return true;
  37. }
  38. __attribute__ ((weak))
  39. bool process_record_secrets(uint16_t keycode, keyrecord_t *record) {
  40. return true;
  41. }
  42. __attribute__ ((weak))
  43. uint32_t layer_state_set_keymap (uint32_t state) {
  44. return state;
  45. }
  46. __attribute__ ((weak))
  47. void led_set_keymap(uint8_t usb_led) {}
  48. // check default layerstate to see which layer we are on.
  49. // if (biton32(layer_state) == _DIABLO) { --- current layer
  50. // if (biton32(default_layer_state) == _DIABLO) { --- current default layer
  51. // check for left shift on.
  52. // if (mods & MOD_BIT(KC_LSFT)) register_code(KC_LSFT);
  53. static void switch_default_layer(uint8_t layer) {
  54. default_layer_set(1UL<<layer);
  55. clear_keyboard();
  56. }
  57. // so the keyboard remembers which layer it's in after power disconnect.
  58. /*
  59. uint32_t default_layer_state_set_kb(uint32_t state) {
  60. eeconfig_update_default_layer(state);
  61. return state;
  62. }
  63. */
  64. // These are the keys for dvorak on bepo. column one is the keycode and mods for
  65. // the unshifted key, the second column is the keycode and mods for the shifted key.
  66. // GR is Good Range. It subtracts SAFE_RANGE from the keycode so we can make a
  67. // reasnably sized array without difficulties. The macro is for the constant declarations
  68. // the function is for when we use it.
  69. const uint8_t key_translations[][2][2] = {
  70. [GR(DB_1)] = {{BP_DQUO, MOD_LSFT}, {BP_DCIR, MOD_LSFT}},
  71. [GR(DB_2)] = {{BP_LDAQ, MOD_LSFT}, {BP_AT, MOD_NONE}},
  72. [GR(DB_3)] = {{BP_RDAQ, MOD_LSFT}, {BP_DLR, MOD_LSFT}},
  73. [GR(DB_4)] = {{BP_LPRN, MOD_LSFT}, {BP_DLR, MOD_NONE}},
  74. [GR(DB_5)] = {{BP_RPRN, MOD_LSFT}, {BP_PERC, MOD_NONE}},
  75. [GR(DB_6)] = {{BP_AT, MOD_LSFT}, {BP_AT, MOD_BIT(KC_RALT)}},
  76. [GR(DB_7)] = {{BP_PLUS, MOD_LSFT}, {BP_P, MOD_BIT(KC_RALT)}},
  77. [GR(DB_8)] = {{BP_MINS, MOD_LSFT}, {BP_ASTR, MOD_NONE}},
  78. [GR(DB_9)] = {{BP_SLSH, MOD_LSFT}, {BP_LPRN, MOD_NONE}},
  79. [GR(DB_0)] = {{BP_ASTR, MOD_LSFT}, {BP_RPRN, MOD_NONE}},
  80. [GR(DB_GRV)] = {{BP_PERC, MOD_LSFT}, {BP_K, MOD_BIT(KC_RALT)}},
  81. [GR(DB_SCOLON)] = {{BP_COMM, MOD_LSFT}, {BP_DOT, MOD_LSFT}},
  82. [GR(DB_SLASH)] = {{BP_SLSH, MOD_NONE}, {BP_QUOT, MOD_LSFT}},
  83. [GR(DB_BACKSLASH)] = {{BP_AGRV, MOD_BIT(KC_RALT)}, {BP_B, MOD_BIT(KC_RALT)}},
  84. [GR(DB_EQL)] = {{BP_EQL, MOD_NONE}, {BP_PLUS, MOD_NONE}},
  85. [GR(DB_COMM)] = {{BP_COMM, MOD_NONE}, {BP_LDAQ, MOD_BIT(KC_RALT)}},
  86. [GR(DB_DOT)] = {{BP_DOT, MOD_NONE}, {BP_RDAQ, MOD_BIT(KC_RALT)}},
  87. [GR(DB_QUOT)] = {{BP_QUOT, MOD_NONE}, {BP_DQUO, MOD_NONE}},
  88. [GR(DB_MINUS)] = {{BP_MINS, MOD_NONE}, {KC_SPC, MOD_BIT(KC_RALT)}},
  89. [GR(DB_LPRN)] = {{BP_LPRN, MOD_NONE}, {BP_LPRN, MOD_BIT(KC_RALT)}},
  90. [GR(DB_RPRN)] = {{BP_RPRN, MOD_NONE}, {BP_RPRN, MOD_BIT(KC_RALT)}},
  91. [GR(DB_LBRC)] = {{BP_Y, MOD_BIT(KC_RALT)}, {BP_LPRN, MOD_BIT(KC_RALT)}},
  92. [GR(DB_RBRC)] = {{BP_X, MOD_BIT(KC_RALT)}, {BP_RPRN, MOD_BIT(KC_RALT)}},
  93. // For the symbol layer
  94. [GR(DB_HASH)] = {{BP_DLR, MOD_LSFT}, {BP_DLR, MOD_LSFT}},
  95. [GR(DB_LCBR)] = {{BP_LPRN, MOD_BIT(KC_RALT)}, {BP_LPRN, MOD_BIT(KC_RALT)}},
  96. [GR(DB_RCBR)] = {{BP_LPRN, MOD_BIT(KC_RALT)}, {BP_RPRN, MOD_BIT(KC_RALT)}},
  97. [GR(DB_PIPE)] = {{BP_B, MOD_BIT(KC_RALT)}, {BP_B, MOD_BIT(KC_RALT)}},
  98. [GR(DB_TILD)] = {{BP_K, MOD_BIT(KC_RALT)}, {BP_K, MOD_BIT(KC_RALT)}},
  99. [GR(DB_CIRC)] = {{BP_AT, MOD_BIT(KC_RALT)}, {BP_AT, MOD_BIT(KC_RALT)}},
  100. [GR(DB_LESS)] = {{BP_LDAQ, MOD_BIT(KC_RALT)}, {BP_LDAQ, MOD_BIT(KC_RALT)}},
  101. [GR(DB_GRTR)] = {{BP_RDAQ, MOD_BIT(KC_RALT)}, {BP_RDAQ, MOD_BIT(KC_RALT)}},
  102. };
  103. uint8_t gr(uint8_t kc){
  104. return (kc - SAFE_RANGE);
  105. }
  106. // send the right keycode for the right mod.
  107. // remove the mods we are taking care of,
  108. // send our keycodes then restore them.
  109. // all so we can make dvorak keys from bepo keycodes.
  110. void send_keycode(uint8_t kc){
  111. uint8_t tmp_mods = get_mods();
  112. bool is_shifted = ( tmp_mods & (MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT)) );
  113. //uint8_t key[2][2] = key_translations[GR(kc)];
  114. // need to turn of the shift if it is on.
  115. unregister_mods((MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT)));
  116. if(is_shifted){
  117. register_mods(SHIFTED_MODS(kc));
  118. register_code(SHIFTED_KEY(kc));
  119. unregister_code(SHIFTED_KEY(kc));
  120. unregister_mods(SHIFTED_MODS(kc));
  121. } else{
  122. register_mods(UNSHIFTED_MODS(kc));
  123. register_code(UNSHIFTED_KEY(kc));
  124. unregister_code(UNSHIFTED_KEY(kc));
  125. unregister_mods(UNSHIFTED_MODS(kc));
  126. }
  127. clear_mods();
  128. register_mods(tmp_mods);
  129. }
  130. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  131. // If console is enabled, it will print the matrix position and status of each key pressed
  132. #ifdef KEYLOGGER_ENABLE
  133. xprintf("KL: row: %u, column: %u, pressed: %u\n", record->event.key.col, record->event.key.row, record->event.pressed);
  134. #endif //KEYLOGGER_ENABLE
  135. // still dont know how to make #&_ And RALT is not ALTGR, That isn't working in the bepo keyboard
  136. // either. No {} either probably for the same reasons. ALtGR is the key to some of these.
  137. switch (keycode) {
  138. // Handle the key translations for Dvorak on bepo. It's best if these are the first
  139. // enums after SAFE_RANGE.
  140. case DB_1:
  141. case DB_2:
  142. case DB_3:
  143. case DB_4:
  144. case DB_5:
  145. case DB_6:
  146. case DB_7:
  147. case DB_8:
  148. case DB_9:
  149. case DB_0:
  150. case DB_GRV:
  151. case DB_SCOLON:
  152. case DB_SLASH:
  153. case DB_BACKSLASH:
  154. case DB_EQL:
  155. case DB_DOT:
  156. case DB_COMM:
  157. case DB_QUOT:
  158. case DB_MINUS:
  159. case DB_LPRN:
  160. case DB_RPRN:
  161. case DB_LBRC:
  162. case DB_RBRC:
  163. if(record->event.pressed)
  164. send_keycode(keycode);
  165. unregister_code(keycode);
  166. break;
  167. case KC_QWERTY:
  168. if (record->event.pressed) {
  169. set_single_persistent_default_layer(QWERTY);
  170. }
  171. return false;
  172. break;
  173. case KC_COLEMAK:
  174. if (record->event.pressed) {
  175. set_single_persistent_default_layer(COLEMAK);
  176. }
  177. return false;
  178. break;
  179. case KC_DVORAK:
  180. if (record->event.pressed) {
  181. set_single_persistent_default_layer(DVORAK);
  182. }
  183. return false;
  184. break;
  185. case KC_WORKMAN:
  186. if (record->event.pressed) {
  187. set_single_persistent_default_layer(WORKMAN);
  188. }
  189. return false;
  190. break;
  191. case KC_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader
  192. if (!record->event.pressed) {
  193. SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP
  194. #if (defined(BOOTLOADER_DFU) || defined(BOOTLOADER_LUFA_DFU) || defined(BOOTLOADER_QMK_DFU))
  195. ":dfu"
  196. #elif defined(BOOTLOADER_HALFKAY)
  197. ":teensy"
  198. #elif defined(BOOTLOADER_CATERINA)
  199. ":avrdude"
  200. #endif // bootloader options
  201. SS_TAP(X_ENTER));
  202. }
  203. return false;
  204. break;
  205. case KC_RESET: // Custom RESET code
  206. if (!record->event.pressed) {
  207. reset_keyboard();
  208. }
  209. return false;
  210. break;
  211. case EPRM: // Resets EEPROM
  212. if (record->event.pressed) {
  213. eeconfig_init();
  214. default_layer_set(1UL<<eeconfig_read_default_layer());
  215. layer_state_set(layer_state);
  216. }
  217. return false;
  218. break;
  219. case VRSN: // Prints firmware version
  220. if (record->event.pressed) {
  221. SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE);
  222. }
  223. return false;
  224. break;
  225. /* Code has been depreciated
  226. case KC_SECRET_1 ... KC_SECRET_5: // Secrets! Externally defined strings, not stored in repo
  227. if (!record->event.pressed) {
  228. clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
  229. send_string(decoy_secret[keycode - KC_SECRET_1]);
  230. }
  231. return false;
  232. break;
  233. */
  234. // These are a serious of gaming macros.
  235. // Only enables for the viterbi, basically,
  236. // to save on firmware space, since it's limited.
  237. #ifdef MACROS_ENABLED
  238. case KC_OVERWATCH: // Toggle's if we hit "ENTER" or "BACKSPACE" to input macros
  239. if (record->event.pressed) { userspace_config.is_overwatch ^= 1; eeprom_update_byte(EECONFIG_USER, userspace_config.raw); }
  240. return false; break;
  241. #endif // MACROS_ENABLED
  242. case KC_CCCV: // One key copy/paste
  243. if(record->event.pressed){
  244. copy_paste_timer = timer_read();
  245. } else {
  246. if (timer_elapsed(copy_paste_timer) > TAPPING_TERM) { // Hold, copy
  247. register_code(KC_LCTL);
  248. tap(KC_C);
  249. unregister_code(KC_LCTL);
  250. #ifdef AUDIO_ENABLE
  251. PLAY_SONG(tone_copy);
  252. #endif
  253. } else { // Tap, paste
  254. register_code(KC_LCTL);
  255. tap(KC_V);
  256. unregister_code(KC_LCTL);
  257. #ifdef AUDIO_ENABLE
  258. PLAY_SONG(tone_paste);
  259. #endif
  260. }
  261. }
  262. return false;
  263. break;
  264. case CLICKY_TOGGLE:
  265. #ifdef AUDIO_CLICKY
  266. userspace_config.clicky_enable = clicky_enable;
  267. eeprom_update_byte(EECONFIG_USER, userspace_config.raw);
  268. #endif
  269. break;
  270. #ifdef UNICODE_ENABLE
  271. case UC_FLIP: // (╯°□°)╯ ︵ ┻━┻
  272. if (record->event.pressed) {
  273. register_code(KC_RSFT);
  274. tap(KC_9);
  275. unregister_code(KC_RSFT);
  276. process_unicode((0x256F | QK_UNICODE), record); // Arm
  277. process_unicode((0x00B0 | QK_UNICODE), record); // Eye
  278. process_unicode((0x25A1 | QK_UNICODE), record); // Mouth
  279. process_unicode((0x00B0 | QK_UNICODE), record); // Eye
  280. register_code(KC_RSFT);
  281. tap(KC_0);
  282. unregister_code(KC_RSFT);
  283. process_unicode((0x256F | QK_UNICODE), record); // Arm
  284. tap(KC_SPC);
  285. process_unicode((0x0361 | QK_UNICODE), record); // Flippy
  286. tap(KC_SPC);
  287. process_unicode((0x253B | QK_UNICODE), record); // Table
  288. process_unicode((0x2501 | QK_UNICODE), record); // Table
  289. process_unicode((0x253B | QK_UNICODE), record); // Table
  290. }
  291. return false;
  292. break;
  293. #endif // UNICODE_ENABLE
  294. }
  295. return true;
  296. // return process_record_keymap(keycode, record) && process_record_secrets(keycode, record);
  297. }
  298. void tap_dance_mouse_btns (qk_tap_dance_state_t *state, void *user_data) {
  299. switch(state->count){
  300. case 1:
  301. register_code(KC_BTN1);
  302. break;
  303. case 2:
  304. register_code(KC_BTN2);
  305. break;
  306. case 3:
  307. register_code(KC_BTN3);
  308. break;
  309. case 4:
  310. register_code(KC_BTN4);
  311. break;
  312. case 5:
  313. register_code(KC_BTN5);
  314. break;
  315. default:
  316. break;
  317. }
  318. reset_tap_dance(state);
  319. }
  320. // counting on all the qwerty layers to be less than dvorak_on_bepo
  321. int on_qwerty(){
  322. uint8_t deflayer = (biton32(default_layer_state));
  323. return (deflayer < DVORAK_ON_BEPO);
  324. }
  325. void tap_dance_df_bepo_layers_switch (qk_tap_dance_state_t *state, void *user_data) {
  326. switch(state->count){
  327. case 1:
  328. switch_default_layer(DVORAK_ON_BEPO);
  329. break;
  330. case 2:
  331. switch_default_layer(BEPO);
  332. break;
  333. case 3:
  334. layer_invert(LAYERS);
  335. break;
  336. default:
  337. break;
  338. }
  339. reset_tap_dance(state);
  340. }
  341. void tap_dance_layer_switch (qk_tap_dance_state_t *state, void *user_data) {
  342. switch(state->count){
  343. case 1:
  344. if(on_qwerty())
  345. layer_invert(SYMB);
  346. else
  347. layer_invert(SYMB_ON_BEPO);
  348. break;
  349. case 2:
  350. layer_invert(MDIA);
  351. break;
  352. case 3:
  353. layer_invert(LAYERS);
  354. break;
  355. case 4:
  356. if(on_qwerty())
  357. layer_invert(KEYPAD);
  358. else
  359. layer_invert(KEYPAD_ON_BEPO);
  360. break;
  361. default:
  362. break;
  363. }
  364. reset_tap_dance(state);
  365. }
  366. void tap_dance_default_layer_switch (qk_tap_dance_state_t *state, void *user_data) {
  367. switch(state->count){
  368. case 1:
  369. switch_default_layer(DVORAK);
  370. break;
  371. case 2:
  372. switch_default_layer(DVORAK_ON_BEPO);
  373. break;
  374. case 3:
  375. switch_default_layer(BEPO);
  376. break;
  377. default:
  378. break;
  379. }
  380. reset_tap_dance(state);
  381. }
  382. // switch the default layer to another qwerty based layer.
  383. void switch_default_layer_on_qwerty(int count) {
  384. switch(count){
  385. case 1:
  386. switch_default_layer(DVORAK);
  387. break;
  388. case 2:
  389. switch_default_layer(QWERTY);
  390. break;
  391. case 3:
  392. switch_default_layer(COLEMAK);
  393. break;
  394. case 4:
  395. switch_default_layer(WORKMAN);
  396. break;
  397. case 5:
  398. switch_default_layer(NORMAN);
  399. break;
  400. default:
  401. switch_default_layer(DVORAK);
  402. break;
  403. }
  404. }
  405. // switch the default layer to another bepo based layer.
  406. void switch_default_layer_on_bepo(int count) {
  407. switch(count){
  408. case 1:
  409. switch_default_layer(DVORAK_ON_BEPO);
  410. break;
  411. case 2:
  412. switch_default_layer(BEPO);
  413. break;
  414. default:
  415. switch_default_layer(DVORAK_ON_BEPO);
  416. break;
  417. }
  418. }
  419. // tap to change the default layer. Distinguishes between layers that are based on
  420. // a qwerty software keyboard and a bepo software keyboard.
  421. // if shifted, choose layers based on the other software keyboard, otherwise choose only
  422. // layers that work on the current software keyboard.
  423. void tap_dance_default_os_layer_switch (qk_tap_dance_state_t *state, void *user_data) {
  424. //uint8_t shifted = (get_mods() & MOD_BIT(KC_LSFT|KC_RSFT));
  425. bool shifted = ( keyboard_report->mods & (MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT)) );
  426. int qwerty = on_qwerty();
  427. // shifted, choose between layers on the other software keyboard
  428. if(shifted){
  429. if (qwerty)
  430. switch_default_layer_on_bepo(state->count);
  431. else
  432. switch_default_layer_on_qwerty(state->count);
  433. // not shifted, choose between layers on the same software keyboard
  434. } else {
  435. if (qwerty)
  436. switch_default_layer_on_qwerty(state->count);
  437. else
  438. switch_default_layer_on_bepo(state->count);
  439. }
  440. reset_tap_dance(state);
  441. }
  442. /* Return an integer that corresponds to what kind of tap dance should be executed.
  443. *
  444. * How to figure out tap dance state: interrupted and pressed.
  445. *
  446. * Interrupted: If the state of a dance dance is "interrupted", that means that another key has been hit
  447. * under the tapping term. This is typically indicitive that you are trying to "tap" the key.
  448. *
  449. * Pressed: Whether or not the key is still being pressed. If this value is true, that means the tapping term
  450. * has ended, but the key is still being pressed down. This generally means the key is being "held".
  451. *
  452. * One thing that is currenlty not possible with qmk software in regards to tap dance is to mimic the "permissive hold"
  453. * feature. In general, advanced tap dances do not work well if they are used with commonly typed letters.
  454. * For example "A". Tap dances are best used on non-letter keys that are not hit while typing letters.
  455. *
  456. * Good places to put an advanced tap dance:
  457. * z,q,x,j,k,v,b, any function key, home/end, comma, semi-colon
  458. *
  459. * Criteria for "good placement" of a tap dance key:
  460. * Not a key that is hit frequently in a sentence
  461. * Not a key that is used frequently to double tap, for example 'tab' is often double tapped in a terminal, or
  462. * in a web form. So 'tab' would be a poor choice for a tap dance.
  463. * Letters used in common words as a double. For example 'p' in 'pepper'. If a tap dance function existed on the
  464. * letter 'p', the word 'pepper' would be quite frustating to type.
  465. *
  466. * For the third point, there does exist the 'DOUBLE_SINGLE_TAP', however this is not fully tested
  467. *
  468. */
  469. int cur_dance (qk_tap_dance_state_t *state) {
  470. if (state->count == 1) {
  471. if (state->interrupted || !state->pressed) return SINGLE_TAP;
  472. //key has not been interrupted, but they key is still held. Means you want to send a 'HOLD'.
  473. else return SINGLE_HOLD;
  474. }
  475. else if (state->count == 2) {
  476. /*
  477. * DOUBLE_SINGLE_TAP is to distinguish between typing "pepper", and actually wanting a double tap
  478. * action when hitting 'pp'. Suggested use case for this return value is when you want to send two
  479. * keystrokes of the key, and not the 'double tap' action/macro.
  480. */
  481. if (state->interrupted) return DOUBLE_SINGLE_TAP;
  482. else if (state->pressed) return DOUBLE_HOLD;
  483. else return DOUBLE_TAP;
  484. }
  485. //Assumes no one is trying to type the same letter three times (at least not quickly).
  486. //If your tap dance key is 'KC_W', and you want to type "www." quickly - then you will need to add
  487. //an exception here to return a 'TRIPLE_SINGLE_TAP', and define that enum just like 'DOUBLE_SINGLE_TAP'
  488. if (state->count == 3) {
  489. if (state->interrupted || !state->pressed) return TRIPLE_TAP;
  490. else return TRIPLE_HOLD;
  491. }
  492. else return 8; //magic number. At some point this method will expand to work for more presses
  493. }
  494. //instanalize an instance of 'tap' for the 'x' tap dance.
  495. static tdtap xtap_state = {
  496. .is_press_action = true,
  497. .state = 0
  498. };
  499. /*
  500. This so I can have a single key that acts like LGUI in DVORAK no
  501. matter which keymap is my current default.
  502. It also allows for the
  503. shift gui and ctl gui, on the same key, So the same key is Escape,
  504. and the mostcommon modifiers in my xmonad control keymap, while also
  505. insuring that dvorak is active for the xmonad command key
  506. Single tap = ESC
  507. tap and hold = dvorak with L_GUI
  508. double tap = One shot dvorak layer with LSFT LGUI mods
  509. double hold = dvorak with LCTL LGUI
  510. double single tap = esc.
  511. */
  512. int get_xmonad_layer(){
  513. int qwerty = on_qwerty();
  514. if (qwerty)
  515. return(XMONAD);
  516. else
  517. return(XMONAD_FR);
  518. }
  519. void x_finished (qk_tap_dance_state_t *state, void *user_data) {
  520. int xmonad_layer = get_xmonad_layer();
  521. xtap_state.state = cur_dance(state);
  522. switch (xtap_state.state) {
  523. case SINGLE_TAP:
  524. register_code(KC_ESC);
  525. break;
  526. case SINGLE_HOLD:
  527. layer_on(xmonad_layer);
  528. set_oneshot_mods (MOD_LGUI);
  529. //set_oneshot_layer (DVORAK, ONESHOT_START);
  530. break;
  531. case DOUBLE_TAP:
  532. set_oneshot_mods ((MOD_LCTL | MOD_LGUI));
  533. layer_on (xmonad_layer);
  534. set_oneshot_layer (xmonad_layer, ONESHOT_START);
  535. break;
  536. case DOUBLE_HOLD:
  537. set_oneshot_mods (MOD_LSFT | MOD_LGUI);
  538. if (xmonad_layer != -1)
  539. layer_on(xmonad_layer);
  540. break;
  541. case DOUBLE_SINGLE_TAP:
  542. register_code(KC_ESC);
  543. unregister_code(KC_ESC);
  544. register_code(KC_ESC);
  545. //Last case is for fast typing. Assuming your key is `f`:
  546. //For example, when typing the word `buffer`, and you want to make sure that you send `ff` and not `Esc`.
  547. //In order to type `ff` when typing fast, the next character will have to be hit within the `TAPPING_TERM`, which by default is 200ms.
  548. }
  549. }
  550. void x_reset (qk_tap_dance_state_t *state, void *user_data) {
  551. int xmonad_layer = get_xmonad_layer();
  552. switch (xtap_state.state) {
  553. case SINGLE_TAP:
  554. unregister_code(KC_ESC);
  555. break;
  556. case SINGLE_HOLD:
  557. layer_off(xmonad_layer);
  558. break;
  559. case DOUBLE_TAP:
  560. set_oneshot_layer (xmonad_layer, ONESHOT_PRESSED);
  561. break;
  562. case DOUBLE_HOLD:
  563. layer_off(xmonad_layer);
  564. break;
  565. case DOUBLE_SINGLE_TAP:
  566. unregister_code(KC_ESC);
  567. }
  568. xtap_state.state = 0;
  569. }
  570. //Tap Dance Definitions
  571. qk_tap_dance_action_t tap_dance_actions[] = {
  572. //Tap once for Esc, twice for Caps Lock
  573. [TD_ESC_CAPS] = ACTION_TAP_DANCE_DOUBLE(KC_ESC, KC_CAPS),
  574. [TD_TAB_BKTAB] = ACTION_TAP_DANCE_DOUBLE(KC_TAB, LSFT(KC_TAB)),
  575. [TD_MDIA_SYMB] = ACTION_TAP_DANCE_FN(tap_dance_layer_switch),
  576. [TD_DVORAK_BEPO] = ACTION_TAP_DANCE_FN(tap_dance_df_bepo_layers_switch),
  577. [TD_DEF_LAYER_SW] = ACTION_TAP_DANCE_FN(tap_dance_default_layer_switch),
  578. [TD_DEF_OS_LAYER_SW] = ACTION_TAP_DANCE_FN(tap_dance_default_os_layer_switch),
  579. [TD_HOME_END] = ACTION_TAP_DANCE_DOUBLE(KC_HOME, KC_END),
  580. [TD_XMONAD_ESC] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, x_finished, x_reset),
  581. [TD_MOUSE_BTNS] = ACTION_TAP_DANCE_FN(tap_dance_mouse_btns)
  582. };