aboutsummaryrefslogtreecommitdiff
path: root/quantum/quantum.c
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-08-25 01:16:59 +0100
committerGitHub <noreply@github.com>2021-08-25 01:16:59 +0100
commita84de5e22be25e2059dfee732f5cca3ec0953a35 (patch)
tree31202fc9dcf0ff56ead905b234ed0ab364ca7de7 /quantum/quantum.c
parent3855713ca0a9513c51fe70e61032d7ea89fa7e87 (diff)
downloadqmk_firmware-a84de5e22be25e2059dfee732f5cca3ec0953a35.tar.gz
qmk_firmware-a84de5e22be25e2059dfee732f5cca3ec0953a35.zip
Revert 14083 && 14144 (#14150)
* Revert "Short term bodge for firmware size bloat (#14144)" This reverts commit a8d65473461c337fb1e168d907bfb8c3ac8fdbd0. * Revert "Tidy up quantum.c now some of tmk_core has been merged (#14083)" This reverts commit c4dbf4bf0118dd785802861beb247433b5b7411d.
Diffstat (limited to 'quantum/quantum.c')
-rw-r--r--quantum/quantum.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 00426c397..e60378afe 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -51,6 +51,63 @@ float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS;
51# endif 51# endif
52#endif 52#endif
53 53
54#ifdef AUTO_SHIFT_ENABLE
55# include "process_auto_shift.h"
56#endif
57
58uint8_t extract_mod_bits(uint16_t code) {
59 switch (code) {
60 case QK_MODS ... QK_MODS_MAX:
61 break;
62 default:
63 return 0;
64 }
65
66 uint8_t mods_to_send = 0;
67
68 if (code & QK_RMODS_MIN) { // Right mod flag is set
69 if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_RCTL);
70 if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_RSFT);
71 if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_RALT);
72 if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_RGUI);
73 } else {
74 if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_LCTL);
75 if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_LSFT);
76 if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_LALT);
77 if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LGUI);
78 }
79
80 return mods_to_send;
81}
82
83static void do_code16(uint16_t code, void (*f)(uint8_t)) { f(extract_mod_bits(code)); }
84
85void register_code16(uint16_t code) {
86 if (IS_MOD(code) || code == KC_NO) {
87 do_code16(code, register_mods);
88 } else {
89 do_code16(code, register_weak_mods);
90 }
91 register_code(code);
92}
93
94void unregister_code16(uint16_t code) {
95 unregister_code(code);
96 if (IS_MOD(code) || code == KC_NO) {
97 do_code16(code, unregister_mods);
98 } else {
99 do_code16(code, unregister_weak_mods);
100 }
101}
102
103void tap_code16(uint16_t code) {
104 register_code16(code);
105#if TAP_CODE_DELAY > 0
106 wait_ms(TAP_CODE_DELAY);
107#endif
108 unregister_code16(code);
109}
110
54__attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; } 111__attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; }
55 112
56__attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user(keycode, record); } 113__attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user(keycode, record); }
@@ -85,6 +142,39 @@ void reset_keyboard(void) {
85 bootloader_jump(); 142 bootloader_jump();
86} 143}
87 144
145/* Convert record into usable keycode via the contained event. */
146uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) {
147#ifdef COMBO_ENABLE
148 if (record->keycode) { return record->keycode; }
149#endif
150 return get_event_keycode(record->event, update_layer_cache);
151}
152
153
154/* Convert event into usable keycode. Checks the layer cache to ensure that it
155 * retains the correct keycode after a layer change, if the key is still pressed.
156 * "update_layer_cache" is to ensure that it only updates the layer cache when
157 * appropriate, otherwise, it will update it and cause layer tap (and other keys)
158 * from triggering properly.
159 */
160uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache) {
161#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
162 /* TODO: Use store_or_get_action() or a similar function. */
163 if (!disable_action_cache) {
164 uint8_t layer;
165
166 if (event.pressed && update_layer_cache) {
167 layer = layer_switch_get_layer(event.key);
168 update_source_layers_cache(event.key, layer);
169 } else {
170 layer = read_source_layers_cache(event.key);
171 }
172 return keymap_key_to_keycode(layer, event.key);
173 } else
174#endif
175 return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key);
176}
177
88/* Get keycode, and then process pre tapping functionality */ 178/* Get keycode, and then process pre tapping functionality */
89bool pre_process_record_quantum(keyrecord_t *record) { 179bool pre_process_record_quantum(keyrecord_t *record) {
90 if (!( 180 if (!(