keymap.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* Copyright 2017 Brian Fong
  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 QMK_KEYBOARD_H
  17. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  18. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  19. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  20. // entirely and just use numbers.
  21. #define _QW 0
  22. #define DIR 1
  23. #define NUM 2
  24. #define ETC 3
  25. // Readability keycodes
  26. #define _______ KC_TRNS
  27. /////////////// TAP DANCE SECTION START ///////////////
  28. //Tap Dance Declarations (list of my tap dance configurations)
  29. enum {
  30. TD_SFT_CAPS = 0
  31. ,TD_Q_ESC
  32. ,ENT_TAP_DANCE
  33. ,DEL_TAP_DANCE
  34. };
  35. ///// QUAD FUNCTION TAP DANCE GENERAL SETUP SECTION START /////
  36. ///// (no need to edit this section) /////
  37. //Enums used to clearly convey the state of the tap dance
  38. enum {
  39. SINGLE_TAP = 1,
  40. SINGLE_HOLD = 2,
  41. DOUBLE_TAP = 3,
  42. DOUBLE_HOLD = 4,
  43. DOUBLE_SINGLE_TAP = 5 //send SINGLE_TAP twice - NOT DOUBLE_TAP
  44. // Add more enums here if you want for triple, quadruple, etc.
  45. };
  46. typedef struct {
  47. bool is_press_action;
  48. int state;
  49. } tap;
  50. int cur_dance (qk_tap_dance_state_t *state) {
  51. if (state->count == 1) {
  52. //If count = 1, and it has been interrupted - it doesn't matter if it is pressed or not: Send SINGLE_TAP
  53. if (state->interrupted || !state->pressed) return SINGLE_TAP;
  54. if (state->interrupted) return SINGLE_TAP;
  55. else return SINGLE_HOLD;
  56. }
  57. //If count = 2, and it has been interrupted - assume that user is trying to type the letter associated
  58. //with single tap.
  59. else if (state->count == 2) {
  60. if (state->interrupted) return DOUBLE_SINGLE_TAP;
  61. else if (state->pressed) return DOUBLE_HOLD;
  62. else return DOUBLE_TAP;
  63. }
  64. else return 6; //magic number. At some point this method will expand to work for more presses
  65. }
  66. ///// QUAD FUNCTION TAP DANCE GENERAL SETUP SECTION END /////
  67. ///// QUAD FUNCTION TAP DANCE PERSONALIZATION SECTION START /////
  68. //instantialize an instance of 'tap' for the 'ENT' tap dance.
  69. static tap ENTtap_state = {
  70. .is_press_action = true,
  71. .state = 0
  72. };
  73. void ENT_finished (qk_tap_dance_state_t *state, void *user_data) {
  74. ENTtap_state.state = cur_dance(state);
  75. switch (ENTtap_state.state) {
  76. case SINGLE_TAP: register_code(KC_SPC); break;
  77. case SINGLE_HOLD: register_code(KC_LSFT); break;
  78. case DOUBLE_TAP: register_code(KC_ENT); break;
  79. case DOUBLE_HOLD: register_code(KC_NO); break; // setting double hold to do nothing (change this if you want)
  80. case DOUBLE_SINGLE_TAP: register_code(KC_SPC); unregister_code(KC_SPC); register_code(KC_SPC);
  81. //Last case is for fast typing. Assuming your key is `f`:
  82. //For example, when typing the word `buffer`, and you want to make sure that you send `ff` and not `Esc`.
  83. //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.
  84. }
  85. }
  86. void ENT_reset (qk_tap_dance_state_t *state, void *user_data) {
  87. switch (ENTtap_state.state) {
  88. case SINGLE_TAP: unregister_code(KC_SPC); break;
  89. case SINGLE_HOLD: unregister_code(KC_LSFT); break;
  90. case DOUBLE_TAP: unregister_code(KC_ENT); break;
  91. case DOUBLE_HOLD: unregister_code(KC_NO);
  92. case DOUBLE_SINGLE_TAP: unregister_code(KC_SPC);
  93. }
  94. ENTtap_state.state = 0;
  95. }
  96. //instanalize an instance of 'tap' for the 'DEL' tap dance.
  97. static tap DELtap_state = {
  98. .is_press_action = true,
  99. .state = 0
  100. };
  101. void DEL_finished (qk_tap_dance_state_t *state, void *user_data) {
  102. DELtap_state.state = cur_dance(state);
  103. switch (DELtap_state.state) {
  104. case SINGLE_TAP: register_code(KC_BSPC); break;
  105. case SINGLE_HOLD: register_code(KC_LCTL); break;
  106. case DOUBLE_TAP: register_code(KC_DEL); break;
  107. case DOUBLE_HOLD: register_code(KC_NO); break;
  108. case DOUBLE_SINGLE_TAP: register_code(KC_BSPC); unregister_code(KC_BSPC); register_code(KC_BSPC);
  109. }
  110. }
  111. void DEL_reset (qk_tap_dance_state_t *state, void *user_data) {
  112. switch (DELtap_state.state) {
  113. case SINGLE_TAP: unregister_code(KC_BSPC); break;
  114. case SINGLE_HOLD: unregister_code(KC_LCTL); break;
  115. case DOUBLE_TAP: unregister_code(KC_DEL); break;
  116. case DOUBLE_HOLD: unregister_code(KC_NO);
  117. case DOUBLE_SINGLE_TAP: unregister_code(KC_BSPC);
  118. }
  119. DELtap_state.state = 0;
  120. }
  121. ///// QUAD FUNCTION TAP DANCE PERSONALIZATION SECTION END /////
  122. //Tap Dance Definitions
  123. //THIS SECTION HAS TO BE AT THE END OF THE TAP DANCE SECTION
  124. qk_tap_dance_action_t tap_dance_actions[] = {
  125. [TD_SFT_CAPS] = ACTION_TAP_DANCE_DOUBLE(KC_LSFT, KC_CAPS)
  126. // Other declarations would go here, separated by commas, if you have them
  127. ,[TD_Q_ESC] = ACTION_TAP_DANCE_DOUBLE(KC_Q, KC_ESC)
  128. ,[ENT_TAP_DANCE] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, ENT_finished, ENT_reset)
  129. ,[DEL_TAP_DANCE] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, DEL_finished, DEL_reset)
  130. };
  131. //In Layer declaration, add tap dance item in place of a key code
  132. //TD(TD_SFT_CAPS)
  133. ///////////// TAP DANCE SECTION END ///////////////
  134. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  135. /* Qwerty
  136. * .-----------------------------------------------------------------------------------------.
  137. * | Q//ESC | W | E | R | T | Y | U | I | O | P |
  138. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  139. * | A | S | D | F | G | H | J | K | L | SPACE |
  140. * | | | | | | | | | |SFThold |
  141. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  142. * | Z | X | C | V/NUM | B/ETC | N | M/DIR | ,/GUI | ./ALT | BKSC |
  143. * | SFThold| | | | | | | | |CTRLhold|
  144. * '-----------------------------------------------------------------------------------------'
  145. */
  146. [_QW] = LAYOUT_ortho_3x10( /* Qwerty*/
  147. TD(TD_Q_ESC), KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P,
  148. KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, SFT_T(KC_SPC),
  149. SFT_T(KC_Z), KC_X, KC_C, LT(NUM, KC_V), LT(ETC, KC_B), KC_N, LT(DIR, KC_M), GUI_T(KC_COMM), ALT_T(KC_DOT), CTL_T(KC_BSPC)
  150. ),
  151. /*
  152. * Directional Modifiers
  153. * .-----------------------------------------------------------------------------------------.
  154. * | TAB | up | | INS | CTRL | SHIFT | PgUp | HOME | - | = |
  155. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  156. * | left | down | right | PrScr | SHIFT | CTRL | PgDn | END | [ | ] |
  157. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  158. * | P-Brk | | | | | | | RGUI | ALT | / |
  159. * '-----------------------------------------------------------------------------------------'
  160. */
  161. [DIR] = LAYOUT_ortho_3x10( /* Directional Modifiers */
  162. KC_TAB, KC_UP, _______, KC_INS, KC_LCTL, KC_RSFT, KC_PGUP, KC_HOME, KC_MINS, KC_EQL,
  163. KC_LEFT, KC_DOWN, KC_RGHT, KC_PSCR, KC_LSFT, KC_RCTL, KC_PGDN, KC_END, KC_LBRC, KC_RBRC,
  164. KC_PAUS, _______, _______, _______, _______, _______, _______, KC_RGUI, KC_LALT, KC_SLSH
  165. ),
  166. /*
  167. * Numbers
  168. * .-----------------------------------------------------------------------------------------.
  169. * | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 |
  170. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  171. * | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 |
  172. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  173. * | F11 | F12 | | | | ENTER | SHIFT | GUI | ./ALT | BKSC |
  174. * | | | | | | | | | |CTRLhold|
  175. * '-----------------------------------------------------------------------------------------'
  176. */
  177. [NUM] = LAYOUT_ortho_3x10 ( /* Numbers */
  178. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10,
  179. KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0,
  180. KC_F11, KC_F12, _______, _______, _______, KC_ENT, KC_RSFT, KC_RGUI, ALT_T(KC_DOT), CTL_T(KC_BSPC)
  181. ),
  182. /*
  183. * ETC
  184. * .-----------------------------------------------------------------------------------------.
  185. * | ` | mUP | | | RESET | SHIFT | mUp | mDown | | \ |
  186. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  187. * | mLeft | mDown | mRight | | SHIFT | mBtn3 | mBtn1 | mBtn2 | ; | ' |
  188. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  189. * | Sft//Cp| | | | | C-A-D | | | ALT | DEL |
  190. * '-----------------------------------------------------------------------------------------'
  191. */
  192. [ETC] = LAYOUT_ortho_3x10( /* ETC */
  193. KC_GRV, KC_MS_U, _______, _______, RESET, KC_RSFT, KC_WH_U, KC_WH_D, _______, KC_BSLS,
  194. KC_MS_L, KC_MS_D, KC_MS_R, _______, KC_LSFT, KC_BTN3, KC_BTN1, KC_BTN2, KC_SCLN, KC_QUOT,
  195. TD(TD_SFT_CAPS), _______, _______, _______, _______, LALT(LCTL(KC_DEL)), _______, _______, KC_LALT, KC_DEL
  196. ),
  197. };