konstantin.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "konstantin.h"
  2. #ifdef LAYER_NUMPAD
  3. static void toggle_numpad(void) {
  4. layer_invert(L_NUMPAD);
  5. bool numpad_on = IS_LAYER_ON(L_NUMPAD);
  6. bool num_lock_on = IS_HOST_LED_ON(USB_LED_NUM_LOCK);
  7. if (num_lock_on != numpad_on) {
  8. tap_code(KC_NLCK); // Toggle Num Lock to match layer state
  9. }
  10. }
  11. #endif
  12. __attribute__((weak))
  13. bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  14. return true;
  15. }
  16. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  17. if (!process_record_keymap(keycode, record)) {
  18. return false;
  19. }
  20. switch (keycode) {
  21. case CLEAR:
  22. if (record->event.pressed) {
  23. SEND_STRING(SS_LCTRL("a") SS_TAP(X_DELETE));
  24. }
  25. return false;
  26. #ifdef LAYER_FN
  27. static bool fn_lock;
  28. case FN_FNLK:
  29. if (record->event.pressed && record->tap.count == TAPPING_TOGGLE) {
  30. fn_lock = !IS_LAYER_ON(L_FN); // Fn layer will be toggled after this
  31. }
  32. return true;
  33. #endif
  34. #ifdef LAYER_NUMPAD
  35. case NUMPAD:
  36. if (record->event.pressed) {
  37. toggle_numpad();
  38. }
  39. return false;
  40. #endif
  41. case KC_ESC:
  42. if (record->event.pressed) {
  43. #ifdef LAYER_NUMPAD
  44. if (IS_LAYER_ON(L_NUMPAD)) {
  45. toggle_numpad();
  46. return false;
  47. }
  48. #endif
  49. #ifdef LAYER_FN
  50. if (IS_LAYER_ON(L_FN) && fn_lock) {
  51. layer_off(L_FN);
  52. return fn_lock = false;
  53. }
  54. #endif
  55. }
  56. return true;
  57. default:
  58. return true;
  59. }
  60. }
  61. __attribute__((weak))
  62. uint32_t layer_state_set_keymap(uint32_t state) {
  63. return state;
  64. }
  65. uint32_t layer_state_set_user(uint32_t state) {
  66. return layer_state_set_keymap(state);
  67. }