ericgebhart.c 21 KB

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