konstantin.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. case DST_P_R:
  27. (record->event.pressed ? register_code16 : unregister_code16)(
  28. (get_mods() & DST_MOD_MASK) ? DST_REM : DST_PRV
  29. );
  30. return false;
  31. case DST_N_A:
  32. (record->event.pressed ? register_code16 : unregister_code16)(
  33. (get_mods() & DST_MOD_MASK) ? DST_ADD : DST_NXT
  34. );
  35. return false;
  36. #ifdef LAYER_FN
  37. static bool fn_lock;
  38. case FN_FNLK:
  39. if (record->event.pressed && record->tap.count == TAPPING_TOGGLE) {
  40. fn_lock = !IS_LAYER_ON(L_FN); // Fn layer will be toggled after this
  41. }
  42. return true;
  43. #endif
  44. #ifdef LAYER_NUMPAD
  45. case NUMPAD:
  46. if (record->event.pressed) {
  47. toggle_numpad();
  48. }
  49. return false;
  50. #endif
  51. case KC_ESC:
  52. if (record->event.pressed) {
  53. #ifdef LAYER_NUMPAD
  54. if (IS_LAYER_ON(L_NUMPAD)) {
  55. toggle_numpad();
  56. return false;
  57. }
  58. #endif
  59. #ifdef LAYER_FN
  60. if (IS_LAYER_ON(L_FN) && fn_lock) {
  61. layer_off(L_FN);
  62. return fn_lock = false;
  63. }
  64. #endif
  65. }
  66. return true;
  67. default:
  68. return true;
  69. }
  70. }
  71. __attribute__((weak))
  72. uint32_t layer_state_set_keymap(uint32_t state) {
  73. return state;
  74. }
  75. uint32_t layer_state_set_user(uint32_t state) {
  76. return layer_state_set_keymap(state);
  77. }