process_records.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
  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 "drashna.h"
  17. uint16_t copy_paste_timer;
  18. __attribute__((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { return true; }
  19. __attribute__((weak)) bool process_record_secrets(uint16_t keycode, keyrecord_t *record) { return true; }
  20. // Defines actions tor my global custom keycodes. Defined in drashna.h file
  21. // Then runs the _keymap's record handier if not processed here
  22. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  23. // If console is enabled, it will print the matrix position and status of each key pressed
  24. #ifdef KEYLOGGER_ENABLE
  25. # if defined(KEYBOARD_ergodox_ez) || defined(KEYBOARD_keebio_iris_rev2)
  26. xprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.row, record->event.key.col, record->event.pressed);
  27. # else
  28. xprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed);
  29. # endif
  30. #endif // KEYLOGGER_ENABLE
  31. #ifdef OLED_DRIVER_ENABLE
  32. process_record_user_oled(keycode, record);
  33. #endif // OLED
  34. if (!(process_record_keymap(keycode, record) && process_record_secrets(keycode, record)
  35. #ifdef RGB_MATRIX_ENABLE
  36. && process_record_user_rgb_matrix(keycode, record)
  37. #endif
  38. #ifdef RGBLIGHT_ENABLE
  39. && process_record_user_rgb_light(keycode, record)
  40. #endif
  41. && true)) {
  42. return false;
  43. }
  44. switch (keycode) {
  45. case KC_QWERTY ... KC_WORKMAN:
  46. if (record->event.pressed) {
  47. uint8_t mods = mod_config(get_mods() | get_oneshot_mods());
  48. if (!mods) {
  49. set_single_persistent_default_layer(keycode - KC_QWERTY);
  50. } else if (mods & MOD_MASK_SHIFT) {
  51. set_single_persistent_default_layer(keycode - KC_QWERTY + 4);
  52. } else if (mods & MOD_MASK_CTRL) {
  53. set_single_persistent_default_layer(keycode - KC_QWERTY + 8);
  54. }
  55. }
  56. break;
  57. case KC_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader
  58. if (!record->event.pressed) {
  59. #ifndef MAKE_BOOTLOADER
  60. uint8_t temp_mod = mod_config(get_mods());
  61. uint8_t temp_osm = mod_config(get_oneshot_mods());
  62. clear_mods();
  63. clear_oneshot_mods();
  64. #endif
  65. send_string_with_delay_P(PSTR("qmk"), TAP_CODE_DELAY);
  66. #ifndef MAKE_BOOTLOADER
  67. if ((temp_mod | temp_osm) & MOD_MASK_SHIFT)
  68. #endif
  69. {
  70. send_string_with_delay_P(PSTR(" flash "), TAP_CODE_DELAY);
  71. #ifndef MAKE_BOOTLOADER
  72. } else {
  73. send_string_with_delay_P(PSTR(" compile "), TAP_CODE_DELAY);
  74. #endif
  75. }
  76. send_string_with_delay_P(PSTR("-kb " QMK_KEYBOARD " -km " QMK_KEYMAP), TAP_CODE_DELAY);
  77. #ifdef RGB_MATRIX_SPLIT_RIGHT
  78. send_string_with_delay_P(PSTR(" RGB_MATRIX_SPLIT_RIGHT=yes"), TAP_CODE_DELAY);
  79. # ifndef OLED_DRIVER_ENABLE
  80. send_string_with_delay_P(PSTR(" OLED_DRIVER_ENABLE=no"), TAP_CODE_DELAY);
  81. # endif
  82. #endif
  83. send_string_with_delay_P(PSTR(SS_TAP(X_ENTER)), TAP_CODE_DELAY);
  84. }
  85. break;
  86. case VRSN: // Prints firmware version
  87. if (record->event.pressed) {
  88. send_string_with_delay_P(PSTR(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE), TAP_CODE_DELAY);
  89. }
  90. break;
  91. case KC_DIABLO_CLEAR: // reset all Diablo timers, disabling them
  92. #ifdef TAP_DANCE_ENABLE
  93. if (record->event.pressed) {
  94. for (uint8_t index = 0; index < 4; index++) {
  95. diablo_timer[index].key_interval = 0;
  96. }
  97. }
  98. #endif // TAP_DANCE_ENABLE
  99. break;
  100. case KC_CCCV: // One key copy/paste
  101. if (record->event.pressed) {
  102. copy_paste_timer = timer_read();
  103. } else {
  104. if (timer_elapsed(copy_paste_timer) > TAPPING_TERM) { // Hold, copy
  105. tap_code16(LCTL(KC_C));
  106. } else { // Tap, paste
  107. tap_code16(LCTL(KC_V));
  108. }
  109. }
  110. break;
  111. #ifdef UNICODE_ENABLE
  112. case UC_FLIP: // (ノಠ痊ಠ)ノ彡┻━┻
  113. if (record->event.pressed) {
  114. send_unicode_string("(ノಠ痊ಠ)ノ彡┻━┻");
  115. }
  116. break;
  117. case UC_TABL: // ┬─┬ノ( º _ ºノ)
  118. if (record->event.pressed) {
  119. send_unicode_string("┬─┬ノ( º _ ºノ)");
  120. }
  121. break;
  122. case UC_SHRG: // ¯\_(ツ)_/¯
  123. if (record->event.pressed) {
  124. send_unicode_string("¯\\_(ツ)_/¯");
  125. }
  126. break;
  127. case UC_DISA: // ಠ_ಠ
  128. if (record->event.pressed) {
  129. send_unicode_string("ಠ_ಠ");
  130. }
  131. break;
  132. #endif
  133. case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal
  134. #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
  135. if (record->event.pressed) {
  136. userspace_config.rgb_layer_change ^= 1;
  137. dprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change);
  138. eeconfig_update_user(userspace_config.raw);
  139. if (userspace_config.rgb_layer_change) {
  140. # if defined(RGBLIGHT_ENABLE) && defined(RGB_MATRIX_ENABLE)
  141. rgblight_enable_noeeprom();
  142. # endif
  143. layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better)
  144. # if defined(RGBLIGHT_ENABLE) && defined(RGB_MATRIX_ENABLE)
  145. } else {
  146. rgblight_disable_noeeprom();
  147. # endif
  148. }
  149. }
  150. #endif // RGBLIGHT_ENABLE
  151. break;
  152. #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
  153. case RGB_TOG:
  154. // Split keyboards need to trigger on key-up for edge-case issue
  155. # ifndef SPLIT_KEYBOARD
  156. if (record->event.pressed) {
  157. # else
  158. if (!record->event.pressed) {
  159. # endif
  160. # if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
  161. rgblight_toggle();
  162. # endif
  163. # if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
  164. rgb_matrix_toggle();
  165. # endif
  166. }
  167. return false;
  168. break;
  169. case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions
  170. if (record->event.pressed) {
  171. bool is_eeprom_updated;
  172. # if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
  173. // This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
  174. if (userspace_config.rgb_layer_change) {
  175. userspace_config.rgb_layer_change = false;
  176. dprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change);
  177. is_eeprom_updated = true;
  178. }
  179. # endif
  180. # if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
  181. if (userspace_config.rgb_matrix_idle_anim) {
  182. userspace_config.rgb_matrix_idle_anim = false;
  183. dprintf("RGB Matrix Idle Animation [EEPROM]: %u\n", userspace_config.rgb_matrix_idle_anim);
  184. is_eeprom_updated = true;
  185. }
  186. # endif
  187. if (is_eeprom_updated) {
  188. eeconfig_update_user(userspace_config.raw);
  189. }
  190. }
  191. #endif
  192. }
  193. return true;
  194. }