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.

144 lines
3.5 KiB

  1. /* Copyright 2019-2021 Konstantin Đorđević <vomindoraan@gmail.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 "konstantin.h"
  17. __attribute__((weak))
  18. void keyboard_pre_init_keymap(void) {}
  19. void keyboard_pre_init_user(void) {
  20. keyboard_pre_init_keymap();
  21. }
  22. __attribute__((weak))
  23. void eeconfig_init_keymap(void) {}
  24. void eeconfig_init_user(void) {
  25. eeconfig_init_keymap();
  26. }
  27. __attribute__((weak))
  28. void keyboard_post_init_keymap(void) {}
  29. void keyboard_post_init_user(void) {
  30. keyboard_post_init_keymap();
  31. }
  32. __attribute__((weak))
  33. layer_state_t layer_state_set_keymap(layer_state_t state) {
  34. return state;
  35. }
  36. layer_state_t layer_state_set_user(layer_state_t state) {
  37. state = layer_state_set_keymap(state);
  38. #ifdef LAYER_NUMPAD
  39. bool numpad = IS_LAYER_ON_STATE(state, L_NUMPAD);
  40. bool num_lock = IS_HOST_LED_ON(USB_LED_NUM_LOCK);
  41. if (numpad != num_lock) {
  42. tap_code(KC_NLCK); // Toggle Num Lock to match Numpad layer state
  43. }
  44. #endif
  45. return state;
  46. }
  47. __attribute__((weak))
  48. void led_set_keymap(uint8_t usb_led) {}
  49. void led_set_user(uint8_t usb_led) {
  50. led_set_keymap(usb_led);
  51. }
  52. __attribute__((weak))
  53. bool led_update_keymap(led_t led_state) {
  54. return true;
  55. }
  56. bool led_update_user(led_t led_state) {
  57. return led_update_keymap(led_state);
  58. }
  59. __attribute__((weak))
  60. bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  61. return true;
  62. }
  63. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  64. if (!process_record_keymap(keycode, record)) {
  65. return false;
  66. }
  67. switch (keycode) {
  68. uint16_t kc;
  69. #ifdef LAYER_FN
  70. static bool fn_lock = false;
  71. case FNLK:
  72. if (record->event.pressed) {
  73. fn_lock = !IS_LAYER_ON(L_FN); // Fn layer will be toggled after this
  74. }
  75. break;
  76. case FN_FNLK:
  77. if (record->event.pressed && record->tap.count == TAPPING_TOGGLE) {
  78. fn_lock = !IS_LAYER_ON(L_FN);
  79. }
  80. break;
  81. #endif
  82. case KC_ESC:
  83. if (record->event.pressed) {
  84. #ifdef LAYER_NUMPAD // Disable Numpad layer before Fn layer
  85. if (IS_LAYER_ON(L_NUMPAD)) {
  86. layer_off(L_NUMPAD);
  87. return false;
  88. }
  89. #endif
  90. #ifdef LAYER_FN
  91. if (IS_LAYER_ON(L_FN) && fn_lock) {
  92. layer_off(L_FN);
  93. return fn_lock = false;
  94. }
  95. #endif
  96. }
  97. break;
  98. case CLEAR:
  99. if (record->event.pressed) {
  100. CLEAN_MODS(
  101. SEND_STRING(SS_LCTL("a") SS_TAP(X_DELETE));
  102. )
  103. }
  104. break;
  105. case DST_P_R:
  106. kc = (get_mods() & DST_MOD_MASK) ? DST_REM : DST_PRV;
  107. CLEAN_MODS(
  108. (record->event.pressed ? register_code16 : unregister_code16)(kc);
  109. )
  110. break;
  111. case DST_N_A:
  112. kc = (get_mods() & DST_MOD_MASK) ? DST_ADD : DST_NXT;
  113. CLEAN_MODS(
  114. (record->event.pressed ? register_code16 : unregister_code16)(kc);
  115. )
  116. break;
  117. }
  118. return true;
  119. }