process_records.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "drashna.h"
  4. #include "version.h"
  5. uint16_t copy_paste_timer;
  6. bool host_driver_disabled = false;
  7. // Defines actions tor my global custom keycodes. Defined in drashna.h file
  8. // Then runs the _keymap's record handier if not processed here
  9. /**
  10. * @brief Keycode handler for keymaps
  11. *
  12. * This handles the keycodes at the keymap level, useful for keyboard specific customization
  13. */
  14. __attribute__((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  15. return true;
  16. }
  17. __attribute__((weak)) bool process_record_secrets(uint16_t keycode, keyrecord_t *record) {
  18. return true;
  19. }
  20. /**
  21. * @brief Main user keycode handler
  22. *
  23. * This handles all of the keycodes for the user, including calling feature handlers.
  24. *
  25. * @param keycode Keycode from matrix
  26. * @param record keyrecord_t data structure
  27. * @return true Continue processing keycode and send to host
  28. * @return false Stop process keycode and do not send to host
  29. */
  30. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  31. #ifdef ENCODER_ENABLE // some debouncing for weird issues
  32. if (IS_ENCODEREVENT(record->event)) {
  33. static bool ignore_first = true;
  34. if (ignore_first) {
  35. ignore_first = false;
  36. return false;
  37. }
  38. }
  39. #endif
  40. // If console is enabled, it will print the matrix position and status of each key pressed
  41. #ifdef KEYLOGGER_ENABLE
  42. uprintf("KL: kc: 0x%04X, col: %2u, row: %2u, pressed: %1d, time: %5u, int: %1d, count: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed, record->event.time, record->tap.interrupted, record->tap.count);
  43. #endif // KEYLOGGER_ENABLE
  44. #if defined(OLED_ENABLE) && defined(CUSTOM_OLED_DRIVER)
  45. process_record_user_oled(keycode, record);
  46. #endif // OLED
  47. if (!(process_record_keymap(keycode, record) && process_record_secrets(keycode, record)
  48. #ifdef CUSTOM_RGB_MATRIX
  49. && process_record_user_rgb_matrix(keycode, record)
  50. #endif
  51. #ifdef CUSTOM_RGBLIGHT
  52. && process_record_user_rgb_light(keycode, record)
  53. #endif
  54. #ifdef CUSTOM_UNICODE_ENABLE
  55. && process_record_unicode(keycode, record)
  56. #endif
  57. #if defined(CUSTOM_POINTING_DEVICE)
  58. && process_record_pointing(keycode, record)
  59. #endif
  60. && true)) {
  61. return false;
  62. }
  63. switch (keycode) {
  64. case FIRST_DEFAULT_LAYER_KEYCODE ... LAST_DEFAULT_LAYER_KEYCODE:
  65. if (record->event.pressed) {
  66. uint8_t mods = mod_config(get_mods() | get_oneshot_mods());
  67. if (!mods) {
  68. set_single_persistent_default_layer(keycode - FIRST_DEFAULT_LAYER_KEYCODE);
  69. #if LAST_DEFAULT_LAYER_KEYCODE > (FIRST_DEFAULT_LAYER_KEYCODE + 3)
  70. } else if (mods & MOD_MASK_SHIFT) {
  71. set_single_persistent_default_layer(keycode - FIRST_DEFAULT_LAYER_KEYCODE + 4);
  72. # if LAST_DEFAULT_LAYER_KEYCODE > (FIRST_DEFAULT_LAYER_KEYCODE + 7)
  73. } else if (mods & MOD_MASK_CTRL) {
  74. set_single_persistent_default_layer(keycode - FIRST_DEFAULT_LAYER_KEYCODE + 8);
  75. # endif
  76. #endif
  77. }
  78. }
  79. break;
  80. case VRSN: // Prints firmware version
  81. if (record->event.pressed) {
  82. send_string_with_delay_P(PSTR(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE), TAP_CODE_DELAY);
  83. }
  84. break;
  85. case KC_DIABLO_CLEAR: // reset all Diablo timers, disabling them
  86. #ifdef TAP_DANCE_ENABLE
  87. if (record->event.pressed) {
  88. for (uint8_t index = 0; index < 4; index++) {
  89. diablo_timer[index].key_interval = 0;
  90. }
  91. }
  92. #endif // TAP_DANCE_ENABLE
  93. break;
  94. case KC_CCCV: // One key copy/paste
  95. if (record->event.pressed) {
  96. copy_paste_timer = timer_read();
  97. } else {
  98. if (timer_elapsed(copy_paste_timer) > TAPPING_TERM) { // Hold, copy
  99. tap_code16(LCTL(KC_C));
  100. } else { // Tap, paste
  101. tap_code16(LCTL(KC_V));
  102. }
  103. }
  104. break;
  105. case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal
  106. #if defined(CUSTOM_RGBLIGHT) || defined(CUSTOM_RGB_MATRIX)
  107. if (record->event.pressed) {
  108. userspace_config.rgb_layer_change ^= 1;
  109. dprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change);
  110. eeconfig_update_user(userspace_config.raw);
  111. if (userspace_config.rgb_layer_change) {
  112. # if defined(CUSTOM_RGB_MATRIX)
  113. rgb_matrix_set_flags(LED_FLAG_UNDERGLOW | LED_FLAG_KEYLIGHT | LED_FLAG_INDICATOR);
  114. # if defined(CUSTOM_RGBLIGHT)
  115. rgblight_enable_noeeprom();
  116. # endif
  117. # endif
  118. layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better)
  119. # if defined(CUSTOM_RGB_MATRIX)
  120. } else {
  121. rgb_matrix_set_flags(LED_FLAG_ALL);
  122. # if defined(CUSTOM_RGBLIGHT)
  123. rgblight_disable_noeeprom();
  124. # endif
  125. # endif
  126. }
  127. }
  128. #endif // CUSTOM_RGBLIGHT
  129. break;
  130. #if defined(CUSTOM_RGBLIGHT) || defined(CUSTOM_RGB_MATRIX)
  131. case RGB_TOG:
  132. // Split keyboards need to trigger on key-up for edge-case issue
  133. # ifndef SPLIT_KEYBOARD
  134. if (record->event.pressed) {
  135. # else
  136. if (!record->event.pressed) {
  137. # endif
  138. # if defined(CUSTOM_RGBLIGHT) && !defined(RGBLIGHT_DISABLE_KEYCODES)
  139. rgblight_toggle();
  140. # endif
  141. # if defined(CUSTOM_RGB_MATRIX) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
  142. rgb_matrix_toggle();
  143. # endif
  144. }
  145. return false;
  146. break;
  147. case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions
  148. if (record->event.pressed) {
  149. bool is_eeprom_updated;
  150. # if defined(CUSTOM_RGBLIGHT) && !defined(RGBLIGHT_DISABLE_KEYCODES)
  151. // This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
  152. if (userspace_config.rgb_layer_change) {
  153. userspace_config.rgb_layer_change = false;
  154. dprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change);
  155. is_eeprom_updated = true;
  156. }
  157. # endif
  158. # if defined(CUSTOM_RGB_MATRIX) && defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
  159. if (userspace_config.rgb_matrix_idle_anim) {
  160. userspace_config.rgb_matrix_idle_anim = false;
  161. dprintf("RGB Matrix Idle Animation [EEPROM]: %u\n", userspace_config.rgb_matrix_idle_anim);
  162. is_eeprom_updated = true;
  163. }
  164. # endif
  165. if (is_eeprom_updated) {
  166. eeconfig_update_user(userspace_config.raw);
  167. }
  168. }
  169. break;
  170. #endif
  171. case KEYLOCK: {
  172. static host_driver_t *host_driver = 0;
  173. if (record->event.pressed) {
  174. if (host_get_driver()) {
  175. host_driver = host_get_driver();
  176. clear_keyboard();
  177. host_set_driver(0);
  178. host_driver_disabled = true;
  179. } else {
  180. host_set_driver(host_driver);
  181. host_driver_disabled = false;
  182. }
  183. }
  184. break;
  185. }
  186. }
  187. return true;
  188. }
  189. __attribute__((weak)) void post_process_record_keymap(uint16_t keycode, keyrecord_t *record) {}
  190. void post_process_record_user(uint16_t keycode, keyrecord_t *record) {
  191. post_process_record_keymap(keycode, record);
  192. }