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.

255 lines
7.5 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 "caps_word.h"
  16. #include "g/keymap_combo.h"
  17. __attribute__((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { return true; }
  18. __attribute__((weak)) bool process_record_secrets(uint16_t keycode, keyrecord_t *record) { return true; }
  19. uint16_t tap_taplong_timer;
  20. inline void tap_taplong(uint16_t kc1, uint16_t kc2, keyrecord_t *record) {
  21. if (record->event.pressed) {
  22. tap_taplong_timer = timer_read();
  23. } else {
  24. if (timer_elapsed(tap_taplong_timer) > TAPPING_TERM) {
  25. tap_code16(kc2);
  26. } else {
  27. tap_code16(kc1);
  28. }
  29. }
  30. }
  31. /* for (){}[]""''<>``. tap for open. Hold for open and close, ending inbetween. */
  32. /* Assumes a one character length. */
  33. inline void open_openclose(uint16_t kc1, uint16_t kc2, keyrecord_t *record) {
  34. if (record->event.pressed) {
  35. tap_taplong_timer = timer_read();
  36. }else{
  37. if (timer_elapsed(tap_taplong_timer) > TAPPING_TERM) {
  38. tap_code16(kc1);
  39. tap_code16(kc2);
  40. tap_code16(KC_LEFT);
  41. } else {
  42. tap_code16(kc1);
  43. }
  44. }
  45. }
  46. // Defines actions for my global custom keycodes. Defined in ericgebhart.h file
  47. // Then runs the _keymap's record handier if not processed here
  48. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  49. // If console is enabled, it will print the matrix position and status of each key pressed
  50. #ifdef OLED_ENABLE
  51. process_record_user_oled(keycode, record);
  52. #endif // OLED
  53. if (!process_caps_word(keycode, record)) { return false; }
  54. if (process_record_keymap(keycode, record) && process_record_secrets(keycode, record)) {
  55. switch (keycode) {
  56. // Handle the key translations for Dvorak on bepo. It's best if these are the first
  57. // enums after SAFE_RANGE.
  58. case DB_1 ... BB_QUOT:
  59. if(record->event.pressed)
  60. send_keycode(keycode);
  61. unregister_code(keycode);
  62. break;
  63. // Set the default layer. eeprom if shifted.
  64. case KC_DVORAK ... KC_BEPO:
  65. if (record->event.pressed) {
  66. uint8_t mods = mod_config(get_mods() | get_oneshot_mods());
  67. if (!mods) {
  68. default_layer_set(1UL << (keycode - KC_DVORAK));
  69. } else if (mods & MOD_MASK_SHIFT) {
  70. set_single_persistent_default_layer(1UL << (keycode - KC_DVORAK));
  71. }
  72. }
  73. break;
  74. case KC_RESET: // Custom RESET code
  75. if (!record->event.pressed) {
  76. reset_keyboard();
  77. }
  78. return false;
  79. break;
  80. case KC_SPACETEST: // test something.
  81. // default_layer_set(1UL << _BEAKL);
  82. // tap_code16(LSFT(KC_SPACE));
  83. break;
  84. // tap or long tap for different key.
  85. case KC_CCCV: // One key copy/paste
  86. tap_taplong(LCTL(KC_C), LCTL(KC_V), record);
  87. break;
  88. case BP_CCCV: // One key copy/paste
  89. tap_taplong(LCTL(BP_C), LCTL(BP_V), record);
  90. break;
  91. case KC_CTCN: // New TaB/Window
  92. tap_taplong(LCTL(KC_T), LCTL(KC_N), record);
  93. break;
  94. case BP_CTCN: // New TaB/Window
  95. tap_taplong(LCTL(BP_T), LCTL(BP_N), record);
  96. break;
  97. case KC_CWCQ: // Close Tab-window/Quit
  98. tap_taplong(LCTL(KC_W), LCTL(KC_Q), record);
  99. break;
  100. case BP_CWCQ: // Close Tab-window/Quit
  101. tap_taplong(LCTL(BP_W), LCTL(BP_Q), record);
  102. break;
  103. case KC_XM_PORD: // Xmonad scratch pads or desktop
  104. tap_taplong(LGUI(KC_E), LGUI(KC_T), record);
  105. break;
  106. case BP_XM_PORD: // Xmonad scratch pads or desktop
  107. tap_taplong(LGUI(BP_E), LGUI(BP_T), record);
  108. break;
  109. // Open on tap and Open with close and back arrow on hold.
  110. case KC_OCPRN:
  111. open_openclose(KC_LPRN, KC_RPRN, record);
  112. break;
  113. case BP_OCPRN:
  114. open_openclose(DB_LPRN, DB_RPRN, record);
  115. break;
  116. case KC_OCBRC:
  117. open_openclose(KC_LBRC, KC_RBRC, record);
  118. break;
  119. case BP_OCBRC:
  120. open_openclose(KC_RBRC, KC_LBRC, record);
  121. break;
  122. case KC_OCCBR:
  123. open_openclose(KC_LCBR, KC_RCBR, record);
  124. break;
  125. case BP_OCCBR:
  126. open_openclose(BP_LCBR, BP_RCBR, record);
  127. break;
  128. case KC_OCDQUO:
  129. open_openclose(KC_DQUO, KC_DQUO, record);
  130. break;
  131. case BP_OCDQUO:
  132. open_openclose(BP_DQUO, BP_DQUO, record);
  133. break;
  134. case KC_OCQUOT:
  135. open_openclose(KC_QUOT, KC_QUOT, record);
  136. break;
  137. case BP_OCQUOT:
  138. open_openclose(BP_QUOT, BP_QUOT, record);
  139. break;
  140. case KC_OCGRV:
  141. open_openclose(KC_GRAVE, KC_GRAVE, record);
  142. break;
  143. case BP_OCGRV:
  144. open_openclose(BP_GRV, BP_GRV, record);
  145. break;
  146. case KC_OCLTGT:
  147. open_openclose(KC_LT, KC_GT, record);
  148. break;
  149. case BP_OCLTGT:
  150. open_openclose(BP_LDAQ, BP_RDAQ, record);
  151. break;
  152. //Turn shift backspace into delete.
  153. /* case KC_BSPC: */
  154. /* { */
  155. /* // Initialize a boolean variable that keeps track */
  156. /* // of the delete key status: registered or not? */
  157. /* static bool delkey_registered; */
  158. /* if (record->event.pressed) { */
  159. /* uint8_t mod_state = get_mods(); */
  160. /* // Detect the activation of either shift keys */
  161. /* if (mod_state & MOD_MASK_SHIFT) { */
  162. /* // First temporarily canceling both shifts so that */
  163. /* // shift isn't applied to the KC_DEL keycode */
  164. /* del_mods(MOD_MASK_SHIFT); */
  165. /* register_code(KC_DEL); */
  166. /* // Update the boolean variable to reflect the status of KC_DEL */
  167. /* delkey_registered = true; */
  168. /* // Reapplying modifier state so that the held shift key(s) */
  169. /* // still work even after having tapped the Backspace/Delete key. */
  170. /* set_mods(mod_state); */
  171. /* return false; */
  172. /* } */
  173. /* } else { // on release of KC_BSPC */
  174. /* // In case KC_DEL is still being sent even after the release of KC_BSPC */
  175. /* if (delkey_registered) { */
  176. /* unregister_code(KC_DEL); */
  177. /* delkey_registered = false; */
  178. /* return false; */
  179. /* } */
  180. /* } */
  181. /* // Let QMK process the KC_BSPC keycode as usual outside of shift */
  182. /* return true; */
  183. /* } */
  184. #ifdef UNICODE_ENABLE
  185. case UC_FLIP: // (ノಠ痊ಠ)ノ彡┻━┻
  186. if (record->event.pressed) {
  187. send_unicode_string("(ノಠ痊ಠ)ノ彡┻━┻");
  188. }
  189. break;
  190. case UC_TABL: // ┬─┬ノ( º _ ºノ)
  191. if (record->event.pressed) {
  192. send_unicode_string("┬─┬ノ( º _ ºノ)");
  193. }
  194. break;
  195. case UC_SHRG: // ¯\_(ツ)_/¯
  196. if (record->event.pressed) {
  197. send_unicode_string("¯\\_(ツ)_/¯");
  198. }
  199. break;
  200. case UC_DISA: // ಠ_ಠ
  201. if (record->event.pressed) {
  202. send_unicode_string("ಠ_ಠ");
  203. }
  204. break;
  205. #endif
  206. }
  207. }
  208. return true;
  209. }