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.

110 lines
3.1 KiB

  1. // Copyright 2022 Dan Hertz (@dhertz)
  2. // SPDX-License-Identifier: GPL-3.0
  3. #include "dhertz.h"
  4. // Add reconfigurable functions here, for keymap customization
  5. // This allows for a global, userspace functions, and continued
  6. // customization of the keymap. Use _keymap instead of _user
  7. // functions in the keymaps
  8. __attribute__ ((weak))
  9. void matrix_init_keymap(void) {}
  10. __attribute__ ((weak))
  11. void matrix_scan_keymap(void) {}
  12. __attribute__ ((weak))
  13. bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  14. return true;
  15. }
  16. __attribute__ ((weak))
  17. uint32_t layer_state_set_keymap (uint32_t state) {
  18. return state;
  19. }
  20. __attribute__ ((weak))
  21. void led_set_keymap(uint8_t usb_led) {}
  22. __attribute__ ((weak))
  23. void action_function_keymap(keyrecord_t *record, uint8_t id, uint8_t opt) {}
  24. // Call user matrix init, then call the keymap's init function
  25. void matrix_init_user(void) {
  26. matrix_init_keymap();
  27. }
  28. // No global matrix scan code, so just run keymap's matix
  29. // scan function
  30. void matrix_scan_user(void) {
  31. matrix_scan_keymap();
  32. }
  33. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  34. switch(keycode) {
  35. case CMD_TAB_CMD:
  36. mod_or_mod_with_macro(record, KC_LGUI, SS_TAP(X_TAB));
  37. return false;
  38. case CMD_GRV_CMD:
  39. mod_or_mod_with_macro(record, KC_RGUI, SS_TAP(X_GRAVE));
  40. return false;
  41. }
  42. if (record->event.pressed) {
  43. switch(keycode) {
  44. case HSH_TLD:
  45. if (get_mods()&(MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT))) {
  46. SEND_STRING(SS_TAP(X_NONUS_BSLASH));
  47. } else {
  48. SEND_STRING(SS_LALT("3"));
  49. }
  50. break;
  51. case CTRL_A:
  52. SEND_STRING(SS_LCTRL("a"));
  53. break;
  54. case CMD_ALT_C:
  55. SEND_STRING(SS_LGUI(SS_LALT("c")));
  56. break;
  57. case CMD_SFT_L:
  58. SEND_STRING(SS_LGUI("L"));
  59. break;
  60. case CMD_SFT_A:
  61. SEND_STRING(SS_LGUI("A"));
  62. break;
  63. case CMD_SFT_ALT_A:
  64. SEND_STRING(SS_LGUI(SS_LALT("A")));
  65. break;
  66. case ISO_COUNTRY_CODE:
  67. SEND_STRING("country_iso_alpha2_code");
  68. break;
  69. default:
  70. return process_record_keymap(keycode, record);
  71. }
  72. return false;
  73. }
  74. return process_record_keymap(keycode, record);
  75. }
  76. static uint16_t sunds_timer;
  77. void mod_or_mod_with_macro(keyrecord_t *record, uint16_t kc_mod, char* macro) {
  78. if (record->event.pressed) {
  79. sunds_timer = timer_read();
  80. register_code(kc_mod);
  81. } else {
  82. if (timer_elapsed(sunds_timer) < TAPPING_TERM) {
  83. send_string(macro);
  84. }
  85. unregister_code(kc_mod);
  86. }
  87. }
  88. // Runs state check and changes underglow color and animation
  89. // on layer change, no matter where the change was initiated
  90. // Then runs keymap's layer change check
  91. layer_state_t layer_state_set_user (layer_state_t state) {
  92. return layer_state_set_keymap (state);
  93. }
  94. void led_set_user(uint8_t usb_led) {
  95. led_set_keymap(usb_led);
  96. }