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