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