]> git.donarmstrong.com Git - qmk_firmware.git/blob - users/dhertz/dhertz.c
Add user-overridable callback for cancelling UCIS input (#5564)
[qmk_firmware.git] / users / dhertz / dhertz.c
1 #include "dhertz.h"
2
3 // Add reconfigurable functions here, for keymap customization
4 // This allows for a global, userspace functions, and continued
5 // customization of the keymap.  Use _keymap instead of _user
6 // functions in the keymaps
7 __attribute__ ((weak))
8 void matrix_init_keymap(void) {}
9
10 __attribute__ ((weak))
11 void matrix_scan_keymap(void) {}
12
13 __attribute__ ((weak))
14 bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
15   return true;
16 }
17 __attribute__ ((weak))
18 uint32_t layer_state_set_keymap (uint32_t state) {
19   return state;
20 }
21 __attribute__ ((weak))
22 void led_set_keymap(uint8_t usb_led) {}
23
24 __attribute__ ((weak))
25 void action_function_keymap(keyrecord_t *record, uint8_t id, uint8_t opt) {}
26
27 // Call user matrix init, then call the keymap's init function
28 void matrix_init_user(void) {
29   matrix_init_keymap();
30 }
31
32 // No global matrix scan code, so just run keymap's matix
33 // scan function
34 void matrix_scan_user(void) {
35   matrix_scan_keymap();
36 }
37
38 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
39     switch(keycode) {
40         case CMD_TAB_CMD:
41             mod_or_mod_with_macro(record, KC_LGUI, SS_TAP(X_TAB));
42             return false;
43         case CMD_GRV_CMD:
44             mod_or_mod_with_macro(record, KC_RGUI, SS_TAP(X_GRAVE));
45             return false;
46     }
47
48     if (record->event.pressed) {
49         switch(keycode) {
50             case HSH_TLD:
51                 if (get_mods()&(MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT))) {
52                     SEND_STRING(SS_TAP(X_NONUS_BSLASH));
53                 } else {
54                     SEND_STRING(SS_LALT("3"));
55                 }
56                 break;
57             case CTRL_A:
58                 SEND_STRING(SS_LCTRL("a"));
59                 break;
60             case CMD_ALT_C:
61                 SEND_STRING(SS_LGUI(SS_LALT("c")));
62                 break;
63             case CMD_SFT_L:
64                 SEND_STRING(SS_LGUI("L"));
65                 break;
66             case ISO_COUNTRY_CODE:
67                 SEND_STRING("country_iso_alpha2_code");
68                 break;
69             default:
70                 return process_record_keymap(keycode, record);
71         }
72         return false;
73     }
74     return process_record_keymap(keycode, record);
75 }
76
77 static uint16_t sunds_timer;
78
79 void mod_or_mod_with_macro(keyrecord_t *record, uint16_t kc_mod, char* macro) {
80     if (record->event.pressed) {
81         sunds_timer = timer_read();
82         register_code(kc_mod);
83     } else {
84         if (timer_elapsed(sunds_timer) < TAPPING_TERM) {
85             send_string(macro);
86         }
87         unregister_code(kc_mod);
88     }
89 }
90
91 // Runs state check and changes underglow color and animation
92 // on layer change, no matter where the change was initiated
93 // Then runs keymap's layer change check
94 uint32_t layer_state_set_user (uint32_t state) {
95   return layer_state_set_keymap (state);
96 }
97
98 void led_set_user(uint8_t usb_led) {
99    led_set_keymap(usb_led);
100 }
101