konstantin.c 1.5 KB

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