From a3cbc8a004f6ec5b0e1df326353a2a2fc8221129 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 28 Feb 2021 15:50:15 +0000 Subject: Overhaul bootmagic logic to have single entrypoint (#8532) * Relocate bootmagic logic to have single entrypoint * Align init of layer state --- quantum/quantum.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index db99e80fa0..7345ab0d5a 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -16,6 +16,7 @@ #include #include "quantum.h" +#include "magic.h" #ifdef BLUETOOTH_ENABLE # include "outputselect.h" @@ -601,12 +602,7 @@ void tap_random_base64(void) { } void matrix_init_quantum() { -#ifdef BOOTMAGIC_LITE - bootmagic_lite(); -#endif - if (!eeconfig_is_enabled()) { - eeconfig_init(); - } + magic(); #if defined(LED_NUM_LOCK_PIN) || defined(LED_CAPS_LOCK_PIN) || defined(LED_SCROLL_LOCK_PIN) || defined(LED_COMPOSE_PIN) || defined(LED_KANA_PIN) // TODO: remove calls to led_init_ports from keyboards and remove ifdef led_init_ports(); -- cgit v1.2.3 From 0e984b6e7e216a62df0b5d53f6a8f0d4bc13dca3 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Mon, 1 Mar 2021 08:57:02 -0800 Subject: Add ability to toggle One Shot functionality (#4198) Co-authored-by: Nick Brassel Co-authored-by: Ryan --- quantum/quantum.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index ef751a2331..78601ce6bf 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -318,6 +318,17 @@ bool process_record_quantum(keyrecord_t *record) { case OUT_BT: set_output(OUTPUT_BLUETOOTH); return false; +#endif +#ifndef NO_ACTION_ONESHOT + case ONESHOT_TOGGLE: + oneshot_toggle(); + break; + case ONESHOT_ENABLE: + oneshot_enable(); + break; + case ONESHOT_DISABLE: + oneshot_disable(); + break; #endif } } -- cgit v1.2.3 From 9155b59e1a496b64f7aa576e6e4cb84fd0a9607b Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 8 Mar 2021 16:55:00 +1100 Subject: LED Matrix: decouple from Backlight (#12054) --- quantum/quantum.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index 78601ce6bf..59d95f2f54 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -234,7 +234,7 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef AUDIO_ENABLE process_audio(keycode, record) && #endif -#ifdef BACKLIGHT_ENABLE +#if defined(BACKLIGHT_ENABLE) || defined(LED_MATRIX_ENABLE) process_backlight(keycode, record) && #endif #ifdef STENO_ENABLE @@ -387,15 +387,14 @@ void matrix_init_quantum() { led_init_ports(); #endif #ifdef BACKLIGHT_ENABLE -# ifdef LED_MATRIX_ENABLE - led_matrix_init(); -# else backlight_init_ports(); -# endif #endif #ifdef AUDIO_ENABLE audio_init(); #endif +#ifdef LED_MATRIX_ENABLE + led_matrix_init(); +#endif #ifdef RGB_MATRIX_ENABLE rgb_matrix_init(); #endif -- cgit v1.2.3 From 8da8aabbe5796232c0f17f849badd455d42b0277 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sat, 3 Jul 2021 00:19:52 -0700 Subject: Improve layer mask handling (#13065) --- quantum/quantum.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index 8ccdb774bd..b4cfa28d7d 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -340,13 +340,13 @@ void set_single_persistent_default_layer(uint8_t default_layer) { #if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS) PLAY_SONG(default_layer_songs[default_layer]); #endif - eeconfig_update_default_layer(1U << default_layer); - default_layer_set(1U << default_layer); + eeconfig_update_default_layer((layer_state_t)1 << default_layer); + default_layer_set((layer_state_t)1 << default_layer); } layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3) { - layer_state_t mask12 = (1UL << layer1) | (1UL << layer2); - layer_state_t mask3 = 1UL << layer3; + layer_state_t mask12 = ((layer_state_t)1 << layer1) | ((layer_state_t)1 << layer2); + layer_state_t mask3 = (layer_state_t)1 << layer3; return (state & mask12) == mask12 ? (state | mask3) : (state & ~mask3); } -- cgit v1.2.3 From 52cfc9259b58a3a11a244fbe35c49c7dd1a9cae0 Mon Sep 17 00:00:00 2001 From: Jonas Gessner Date: Tue, 13 Jul 2021 19:13:51 +0200 Subject: [Feature] Key Overrides (#11422) --- quantum/quantum.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index b4cfa28d7d..9cfffd9317 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -58,12 +58,16 @@ float bell_song[][2] = SONG(TERMINAL_SOUND); # include "process_auto_shift.h" #endif -static void do_code16(uint16_t code, void (*f)(uint8_t)) { +#ifdef KEY_OVERRIDE_ENABLE +# include "process_key_override_private.h" +#endif + +uint8_t extract_mod_bits(uint16_t code) { switch (code) { case QK_MODS ... QK_MODS_MAX: break; default: - return; + return 0; } uint8_t mods_to_send = 0; @@ -80,9 +84,11 @@ static void do_code16(uint16_t code, void (*f)(uint8_t)) { if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LGUI); } - f(mods_to_send); + return mods_to_send; } +static void do_code16(uint16_t code, void (*f)(uint8_t)) { f(extract_mod_bits(code)); } + void register_code16(uint16_t code) { if (IS_MOD(code) || code == KC_NO) { do_code16(code, register_mods); @@ -243,6 +249,9 @@ bool process_record_quantum(keyrecord_t *record) { #if (defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE) process_music(keycode, record) && #endif +#ifdef KEY_OVERRIDE_ENABLE + process_key_override(keycode, record) && +#endif #ifdef TAP_DANCE_ENABLE process_tap_dance(keycode, record) && #endif @@ -408,6 +417,10 @@ void matrix_scan_quantum() { matrix_scan_music(); #endif +#ifdef KEY_OVERRIDE_ENABLE + matrix_scan_key_override(); +#endif + #ifdef SEQUENCER_ENABLE matrix_scan_sequencer(); #endif -- cgit v1.2.3 From 332a5aa7cb6dfa12ff9586ed43a5b50d9a5197a0 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 17 Jul 2021 02:40:20 +1000 Subject: Move `SENDSTRING_BELL` code to `send_string.h` (#13566) --- quantum/quantum.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index 9cfffd9317..56ceec5db8 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -49,9 +49,6 @@ float goodbye_song[][2] = GOODBYE_SONG; # ifdef DEFAULT_LAYER_SONGS float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS; # endif -# ifdef SENDSTRING_BELL -float bell_song[][2] = SONG(TERMINAL_SOUND); -# endif #endif #ifdef AUTO_SHIFT_ENABLE -- cgit v1.2.3 From f945c352e7db3fedb16c90f9f176b3df6e0b62ae Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Mon, 26 Jul 2021 03:14:58 +0100 Subject: Haptic: driver-> feature (#13713) --- quantum/quantum.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index 56ceec5db8..f430a521b3 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -220,10 +220,10 @@ bool process_record_quantum(keyrecord_t *record) { #endif #if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY) process_clicky(keycode, record) && -#endif // AUDIO_CLICKY +#endif #ifdef HAPTIC_ENABLE process_haptic(keycode, record) && -#endif // HAPTIC_ENABLE +#endif #if defined(VIA_ENABLE) process_record_via(keycode, record) && #endif -- cgit v1.2.3 From 03d258c2226959480fc3ead1568ca2fe8ba37c59 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 28 Jul 2021 12:01:23 +0100 Subject: matrix_scan_x -> x_task (#13748) --- quantum/quantum.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index f430a521b3..87b219428d 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -411,7 +411,7 @@ void matrix_scan_quantum() { #endif #if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE) - matrix_scan_music(); + music_task(); #endif #ifdef KEY_OVERRIDE_ENABLE @@ -419,15 +419,15 @@ void matrix_scan_quantum() { #endif #ifdef SEQUENCER_ENABLE - matrix_scan_sequencer(); + sequencer_task(); #endif #ifdef TAP_DANCE_ENABLE - matrix_scan_tap_dance(); + tap_dance_task(); #endif #ifdef COMBO_ENABLE - matrix_scan_combo(); + combo_task(); #endif #ifdef LED_MATRIX_ENABLE -- cgit v1.2.3 From 4ef8ff458d7dcf49a288bb484323ab2098a21ef9 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 28 Jul 2021 12:01:49 +0100 Subject: Minor tidy up of key overrides (#13747) * Minor tidy up of key overrides * Update quantum/quantum.c * Update quantum/quantum.c --- quantum/quantum.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index 87b219428d..f35939216c 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -55,10 +55,6 @@ float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS; # include "process_auto_shift.h" #endif -#ifdef KEY_OVERRIDE_ENABLE -# include "process_key_override_private.h" -#endif - uint8_t extract_mod_bits(uint16_t code) { switch (code) { case QK_MODS ... QK_MODS_MAX: @@ -415,7 +411,7 @@ void matrix_scan_quantum() { #endif #ifdef KEY_OVERRIDE_ENABLE - matrix_scan_key_override(); + key_override_task(); #endif #ifdef SEQUENCER_ENABLE -- cgit v1.2.3 From 3f419dc872d3ab61d129c644e114f62fd738e9d6 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Tue, 3 Aug 2021 18:34:32 +0100 Subject: Unconditionally call led_init_ports (#12116) * Unconditionally call led_init_ports * Another call to led_init_ports --- quantum/quantum.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index f35939216c..3329c1146b 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -356,10 +356,7 @@ void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { layer_st void matrix_init_quantum() { magic(); -#if defined(LED_NUM_LOCK_PIN) || defined(LED_CAPS_LOCK_PIN) || defined(LED_SCROLL_LOCK_PIN) || defined(LED_COMPOSE_PIN) || defined(LED_KANA_PIN) - // TODO: remove calls to led_init_ports from keyboards and remove ifdef led_init_ports(); -#endif #ifdef BACKLIGHT_ENABLE backlight_init_ports(); #endif -- cgit v1.2.3 From 7e983796e18e7401c062c158f23966aeb7b1405b Mon Sep 17 00:00:00 2001 From: Pete Sevander Date: Fri, 6 Aug 2021 02:44:57 +0300 Subject: Process combos earlier & overlapping combos (#8591) * Combo processing improvements. Now it is possible to use ModTap and LayerTap keys as part of combos. Overlapping combos also don't trigger all the combos, just exactly the one that you press. New settings: - COMBO_MUST_HOLD_MODS - COMBO_MOD_TERM - COMBO_TERM_PER_COMBO - COMBO_MUST_HOLD_PER_COMBO - COMBO_STRICT_TIMER - COMBO_NO_TIMER * Remove the size flags from combo_t struct boolean members. This in the end actually saves space as the members are accessed so many times. The amount of operations needed to access the bits uses more memory than setting the size saves. * Fix `process_combo_key_release` not called correctly with tap-only combos * Fix not passing a pointer when NO_ACTION_TAPPING is defined. * Docs for `COMBO_ONLY_FROM_LAYER` * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update quantum/process_keycode/process_combo.c Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Add `EXTRA_SHORT_COMBOS` option. Stuff combo's `disabled` and `active` flags into `state`. Possibly can save some space. * Add more examples and clarify things with dict management system. - Simple examples now has a combo that has modifiers included. - The slightly more advanced examples now are actually more advanced instead of just `tap_code16()`. - Added a note that `COMBO_ACTION`s are not needed anymore as you can just use custom keycodes. - Added a note that the `g/keymap_combo.h` macros use the `process_combo_event` function and that it is not usable in one's keymap afterwards. * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Change "the" combo action example to "email" example. * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Fix sneaky infinite loop with `combo_disable()` No need to call `dump_key_buffer` when disabling combos because the buffer is either being dumped if a combo-key was pressed, or the buffer is empty if a non-combo-key is pressed. * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> Co-authored-by: Drashna Jaelre --- quantum/quantum.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index 3329c1146b..d173388714 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -143,7 +143,13 @@ void reset_keyboard(void) { } /* Convert record into usable keycode via the contained event. */ -uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) { return get_event_keycode(record->event, update_layer_cache); } +uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) { +#ifdef COMBO_ENABLE + if (record->keycode) { return record->keycode; } +#endif + return get_event_keycode(record->event, update_layer_cache); +} + /* Convert event into usable keycode. Checks the layer cache to ensure that it * retains the correct keycode after a layer change, if the key is still pressed. @@ -169,6 +175,18 @@ uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache) { return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key); } +/* Get keycode, and then process pre tapping functionality */ +bool pre_process_record_quantum(keyrecord_t *record) { + if (!( +#ifdef COMBO_ENABLE + process_combo(get_record_keycode(record, true), record) && +#endif + true)) { + return false; + } + return true; // continue processing +} + /* Get keycode, and then call keyboard function */ void post_process_record_quantum(keyrecord_t *record) { uint16_t keycode = get_record_keycode(record, false); @@ -254,9 +272,6 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef LEADER_ENABLE process_leader(keycode, record) && #endif -#ifdef COMBO_ENABLE - process_combo(keycode, record) && -#endif #ifdef PRINTING_ENABLE process_printer(keycode, record) && #endif -- cgit v1.2.3 From 4e3726bfe11b02757c5724211d2a0fc62c7f66e8 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sun, 15 Aug 2021 13:51:50 -0700 Subject: Fixup Audio startup and add to documents (#13606) * Fixup Audio startup and add to documents * fix doc descriptions --- quantum/quantum.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index d173388714..e60378afe4 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -398,7 +398,7 @@ void matrix_init_quantum() { } void matrix_scan_quantum() { -#if defined(AUDIO_ENABLE) +#if defined(AUDIO_ENABLE) && defined(AUDIO_INIT_DELAY) // There are some tasks that need to be run a little bit // after keyboard startup, or else they will not work correctly // because of interaction with the USB device state, which -- cgit v1.2.3 From c4dbf4bf0118dd785802861beb247433b5b7411d Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Tue, 24 Aug 2021 14:28:37 +0100 Subject: Tidy up quantum.c now some of tmk_core has been merged (#14083) --- quantum/quantum.c | 90 ------------------------------------------------------- 1 file changed, 90 deletions(-) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index e60378afe4..00426c3973 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -51,63 +51,6 @@ float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS; # endif #endif -#ifdef AUTO_SHIFT_ENABLE -# include "process_auto_shift.h" -#endif - -uint8_t extract_mod_bits(uint16_t code) { - switch (code) { - case QK_MODS ... QK_MODS_MAX: - break; - default: - return 0; - } - - uint8_t mods_to_send = 0; - - if (code & QK_RMODS_MIN) { // Right mod flag is set - if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_RCTL); - if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_RSFT); - if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_RALT); - if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_RGUI); - } else { - if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_LCTL); - if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_LSFT); - if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_LALT); - if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LGUI); - } - - return mods_to_send; -} - -static void do_code16(uint16_t code, void (*f)(uint8_t)) { f(extract_mod_bits(code)); } - -void register_code16(uint16_t code) { - if (IS_MOD(code) || code == KC_NO) { - do_code16(code, register_mods); - } else { - do_code16(code, register_weak_mods); - } - register_code(code); -} - -void unregister_code16(uint16_t code) { - unregister_code(code); - if (IS_MOD(code) || code == KC_NO) { - do_code16(code, unregister_mods); - } else { - do_code16(code, unregister_weak_mods); - } -} - -void tap_code16(uint16_t code) { - register_code16(code); -#if TAP_CODE_DELAY > 0 - wait_ms(TAP_CODE_DELAY); -#endif - unregister_code16(code); -} - __attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; } __attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user(keycode, record); } @@ -142,39 +85,6 @@ void reset_keyboard(void) { bootloader_jump(); } -/* Convert record into usable keycode via the contained event. */ -uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) { -#ifdef COMBO_ENABLE - if (record->keycode) { return record->keycode; } -#endif - return get_event_keycode(record->event, update_layer_cache); -} - - -/* Convert event into usable keycode. Checks the layer cache to ensure that it - * retains the correct keycode after a layer change, if the key is still pressed. - * "update_layer_cache" is to ensure that it only updates the layer cache when - * appropriate, otherwise, it will update it and cause layer tap (and other keys) - * from triggering properly. - */ -uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache) { -#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) - /* TODO: Use store_or_get_action() or a similar function. */ - if (!disable_action_cache) { - uint8_t layer; - - if (event.pressed && update_layer_cache) { - layer = layer_switch_get_layer(event.key); - update_source_layers_cache(event.key, layer); - } else { - layer = read_source_layers_cache(event.key); - } - return keymap_key_to_keycode(layer, event.key); - } else -#endif - return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key); -} - /* Get keycode, and then process pre tapping functionality */ bool pre_process_record_quantum(keyrecord_t *record) { if (!( -- cgit v1.2.3 From a84de5e22be25e2059dfee732f5cca3ec0953a35 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 25 Aug 2021 01:16:59 +0100 Subject: 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. --- quantum/quantum.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'quantum/quantum.c') diff --git a/quantum/quantum.c b/quantum/quantum.c index 00426c3973..e60378afe4 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -51,6 +51,63 @@ float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS; # endif #endif +#ifdef AUTO_SHIFT_ENABLE +# include "process_auto_shift.h" +#endif + +uint8_t extract_mod_bits(uint16_t code) { + switch (code) { + case QK_MODS ... QK_MODS_MAX: + break; + default: + return 0; + } + + uint8_t mods_to_send = 0; + + if (code & QK_RMODS_MIN) { // Right mod flag is set + if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_RCTL); + if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_RSFT); + if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_RALT); + if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_RGUI); + } else { + if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_LCTL); + if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_LSFT); + if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_LALT); + if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LGUI); + } + + return mods_to_send; +} + +static void do_code16(uint16_t code, void (*f)(uint8_t)) { f(extract_mod_bits(code)); } + +void register_code16(uint16_t code) { + if (IS_MOD(code) || code == KC_NO) { + do_code16(code, register_mods); + } else { + do_code16(code, register_weak_mods); + } + register_code(code); +} + +void unregister_code16(uint16_t code) { + unregister_code(code); + if (IS_MOD(code) || code == KC_NO) { + do_code16(code, unregister_mods); + } else { + do_code16(code, unregister_weak_mods); + } +} + +void tap_code16(uint16_t code) { + register_code16(code); +#if TAP_CODE_DELAY > 0 + wait_ms(TAP_CODE_DELAY); +#endif + unregister_code16(code); +} + __attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; } __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) { bootloader_jump(); } +/* Convert record into usable keycode via the contained event. */ +uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) { +#ifdef COMBO_ENABLE + if (record->keycode) { return record->keycode; } +#endif + return get_event_keycode(record->event, update_layer_cache); +} + + +/* Convert event into usable keycode. Checks the layer cache to ensure that it + * retains the correct keycode after a layer change, if the key is still pressed. + * "update_layer_cache" is to ensure that it only updates the layer cache when + * appropriate, otherwise, it will update it and cause layer tap (and other keys) + * from triggering properly. + */ +uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache) { +#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) + /* TODO: Use store_or_get_action() or a similar function. */ + if (!disable_action_cache) { + uint8_t layer; + + if (event.pressed && update_layer_cache) { + layer = layer_switch_get_layer(event.key); + update_source_layers_cache(event.key, layer); + } else { + layer = read_source_layers_cache(event.key); + } + return keymap_key_to_keycode(layer, event.key); + } else +#endif + return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key); +} + /* Get keycode, and then process pre tapping functionality */ bool pre_process_record_quantum(keyrecord_t *record) { if (!( -- cgit v1.2.3