From c485d1cf2652bfb47afbb68f128a64f1bc518aa3 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Mon, 27 Mar 2023 20:08:17 +0100 Subject: Remove use of keymap.h (#20004) --- quantum/process_keycode/process_combo.c | 1 + 1 file changed, 1 insertion(+) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index 8597649c92..ce6725c402 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -14,6 +14,7 @@ * along with this program. If not, see . */ +#include "keymap_common.h" #include "print.h" #include "process_combo.h" #include "action_tapping.h" -- cgit v1.2.3 From 68efea70b268aceb28c28abb26641fad8d6acefd Mon Sep 17 00:00:00 2001 From: "Johannes H. Jensen" Date: Mon, 3 Apr 2023 05:01:07 +0200 Subject: Add direction to dynamic_macro_record_start_user (#19689) --- quantum/process_keycode/process_dynamic_macro.c | 10 +++++----- quantum/process_keycode/process_dynamic_macro.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c index c2e7e7716f..bf6af566e2 100644 --- a/quantum/process_keycode/process_dynamic_macro.c +++ b/quantum/process_keycode/process_dynamic_macro.c @@ -29,7 +29,7 @@ void dynamic_macro_led_blink(void) { /* User hooks for Dynamic Macros */ -__attribute__((weak)) void dynamic_macro_record_start_user(void) { +__attribute__((weak)) void dynamic_macro_record_start_user(int8_t direction) { dynamic_macro_led_blink(); } @@ -62,10 +62,10 @@ __attribute__((weak)) bool dynamic_macro_valid_key_user(uint16_t keycode, keyrec * @param[out] macro_pointer The new macro buffer iterator. * @param[in] macro_buffer The macro buffer used to initialize macro_pointer. */ -void dynamic_macro_record_start(keyrecord_t **macro_pointer, keyrecord_t *macro_buffer) { +void dynamic_macro_record_start(keyrecord_t **macro_pointer, keyrecord_t *macro_buffer, int8_t direction) { dprintln("dynamic macro recording: started"); - dynamic_macro_record_start_user(); + dynamic_macro_record_start_user(direction); clear_keyboard(); layer_clear(); @@ -213,11 +213,11 @@ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { if (!record->event.pressed) { switch (keycode) { case QK_DYNAMIC_MACRO_RECORD_START_1: - dynamic_macro_record_start(¯o_pointer, macro_buffer); + dynamic_macro_record_start(¯o_pointer, macro_buffer, +1); macro_id = 1; return false; case QK_DYNAMIC_MACRO_RECORD_START_2: - dynamic_macro_record_start(¯o_pointer, r_macro_buffer); + dynamic_macro_record_start(¯o_pointer, r_macro_buffer, -1); macro_id = 2; return false; case QK_DYNAMIC_MACRO_PLAY_1: diff --git a/quantum/process_keycode/process_dynamic_macro.h b/quantum/process_keycode/process_dynamic_macro.h index 39036541b8..ab70726897 100644 --- a/quantum/process_keycode/process_dynamic_macro.h +++ b/quantum/process_keycode/process_dynamic_macro.h @@ -35,7 +35,7 @@ void dynamic_macro_led_blink(void); bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record); -void dynamic_macro_record_start_user(void); +void dynamic_macro_record_start_user(int8_t direction); void dynamic_macro_play_user(int8_t direction); void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record); void dynamic_macro_record_end_user(int8_t direction); -- cgit v1.2.3 From 1899793f27c9b165b55b28b086bd989f12baf137 Mon Sep 17 00:00:00 2001 From: precondition <57645186+precondition@users.noreply.github.com> Date: Mon, 3 Apr 2023 07:32:47 +0200 Subject: Make IGNORE_MOD_TAP_INTERRUPT the default behaviour for mod-taps (#20211) --- quantum/process_keycode/process_auto_shift.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index aad1a164ae..62c347ae0c 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c @@ -400,12 +400,10 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { // If Retro Shift is disabled, possible custom actions shouldn't happen. // clang-format off # if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING) -# if defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) +# ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY const bool is_hold_on_interrupt = get_hold_on_other_key_press(keycode, record); -# elif defined(IGNORE_MOD_TAP_INTERRUPT) - const bool is_hold_on_interrupt = false; # else - const bool is_hold_on_interrupt = IS_QK_MOD_TAP(keycode); + const bool is_hold_on_interrupt = false; # endif # endif if (IS_RETRO(keycode) @@ -443,12 +441,8 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { # endif ) { // Fixes modifiers not being applied to rolls with AUTO_SHIFT_MODIFIERS set. -# if !defined(IGNORE_MOD_TAP_INTERRUPT) || defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) - if (autoshift_flags.in_progress -# ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY - && get_hold_on_other_key_press(keycode, record) -# endif - ) { +# ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY + if (autoshift_flags.in_progress && get_hold_on_other_key_press(keycode, record)) { autoshift_end(KC_NO, now, false, &autoshift_lastrecord); } # endif -- cgit v1.2.3 From fcf8b804ed95a98561bd4c1d6c85604be0f7cc7b Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Mon, 3 Apr 2023 10:33:45 +0200 Subject: [Core] Refactor `keyevent_t` for 1ms timing resolution (#15847) --- quantum/process_keycode/process_combo.c | 10 +++++----- quantum/process_keycode/process_steno.c | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index ce6725c402..b1b49d3019 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -145,7 +145,7 @@ static queued_combo_t combo_buffer[COMBO_BUFFER_LENGTH]; static inline void release_combo(uint16_t combo_index, combo_t *combo) { if (combo->keycode) { keyrecord_t record = { - .event = MAKE_KEYEVENT(KEYLOC_COMBO, KEYLOC_COMBO, false), + .event = MAKE_COMBOEVENT(false), .keycode = combo->keycode, }; #ifndef NO_ACTION_TAPPING @@ -233,7 +233,7 @@ static inline void dump_key_buffer(void) { process_record(record); #endif } - record->event.time = 0; + record->event.type = TICK_EVENT; #if defined(CAPS_WORD_ENABLE) && defined(AUTO_SHIFT_ENABLE) // Edge case: preserve the weak Left Shift mod if both Caps Word and @@ -333,8 +333,8 @@ void apply_combo(uint16_t combo_index, combo_t *combo) { KEY_STATE_DOWN(state, key_index); if (ALL_COMBO_KEYS_ARE_DOWN(state, key_count)) { // this in the end executes the combo when the key_buffer is dumped. - record->keycode = combo->keycode; - record->event.key = MAKE_KEYPOS(KEYLOC_COMBO, KEYLOC_COMBO); + record->keycode = combo->keycode; + record->event.type = COMBO_EVENT; qrecord->combo_index = combo_index; ACTIVATE_COMBO(combo); @@ -343,7 +343,7 @@ void apply_combo(uint16_t combo_index, combo_t *combo) { } else { // key was part of the combo but not the last one, "disable" it // by making it a TICK event. - record->event.time = 0; + record->event.type = TICK_EVENT; } } drop_combo_from_buffer(combo_index); diff --git a/quantum/process_keycode/process_steno.c b/quantum/process_keycode/process_steno.c index 8ba98bd4bb..d5ad61ba85 100644 --- a/quantum/process_keycode/process_steno.c +++ b/quantum/process_keycode/process_steno.c @@ -173,13 +173,13 @@ bool process_steno(uint16_t keycode, keyrecord_t *record) { switch (keycode) { #ifdef STENO_ENABLE_ALL case QK_STENO_BOLT: - if (IS_PRESSED(record->event)) { + if (record->event.pressed) { steno_set_mode(STENO_MODE_BOLT); } return false; case QK_STENO_GEMINI: - if (IS_PRESSED(record->event)) { + if (record->event.pressed) { steno_set_mode(STENO_MODE_GEMINI); } return false; @@ -193,7 +193,7 @@ bool process_steno(uint16_t keycode, keyrecord_t *record) { } #endif // STENO_COMBINEDMAP case STN__MIN ... STN__MAX: - if (IS_PRESSED(record->event)) { + if (record->event.pressed) { n_pressed_keys++; switch (mode) { #ifdef STENO_ENABLE_BOLT -- cgit v1.2.3 From ae63c0f509fae71270fb5885d504ee26cbad95ff Mon Sep 17 00:00:00 2001 From: Pascal Getreuer <50221757+getreuer@users.noreply.github.com> Date: Mon, 3 Apr 2023 16:11:26 -0700 Subject: [Core] Caps Word "Invert on shift" option: pressing Shift inverts the shift state. (#20092) Co-authored-by: Nick Brassel --- quantum/process_keycode/process_caps_word.c | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_caps_word.c b/quantum/process_keycode/process_caps_word.c index 94302b29ae..8f2ee1db8b 100644 --- a/quantum/process_keycode/process_caps_word.c +++ b/quantum/process_keycode/process_caps_word.c @@ -14,6 +14,54 @@ #include "process_caps_word.h" +#ifdef CAPS_WORD_INVERT_ON_SHIFT +static uint8_t held_mods = 0; + +static bool handle_shift(uint16_t keycode, keyrecord_t* record) { + switch (keycode) { + case OSM(MOD_LSFT): + keycode = KC_LSFT; + break; + case OSM(MOD_RSFT): + keycode = KC_RSFT; + break; + +# ifndef NO_ACTION_TAPPING + case QK_MOD_TAP ... QK_MOD_TAP_MAX: + if (record->tap.count == 0) { // Mod-tap key is held. + switch (QK_MOD_TAP_GET_MODS(keycode)) { + case MOD_LSFT: + keycode = KC_LSFT; + break; + case MOD_RSFT: + keycode = KC_RSFT; + break; + } + } +# endif // NO_ACTION_TAPPING + } + + if (keycode == KC_LSFT || keycode == KC_RSFT) { + const uint8_t mod = MOD_BIT(keycode); + + if (is_caps_word_on()) { + if (record->event.pressed) { + held_mods |= mod; + } else { + held_mods &= ~mod; + } + return false; + } else if ((held_mods & mod) != 0) { + held_mods &= ~mod; + del_mods(mod); + return record->event.pressed; + } + } + + return true; +} +#endif // CAPS_WORD_INVERT_ON_SHIFT + bool process_caps_word(uint16_t keycode, keyrecord_t* record) { if (keycode == QK_CAPS_WORD_TOGGLE) { if (record->event.pressed) { @@ -21,6 +69,11 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) { } return false; } +#ifdef CAPS_WORD_INVERT_ON_SHIFT + if (!handle_shift(keycode, record)) { + return false; + } +#endif // CAPS_WORD_INVERT_ON_SHIFT #ifndef NO_ACTION_ONESHOT const uint8_t mods = get_mods() | get_oneshot_mods(); @@ -111,12 +164,14 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) { if (record->tap.count == 0) { // Mod-tap key is held. const uint8_t mods = QK_MOD_TAP_GET_MODS(keycode); switch (mods) { +# ifndef CAPS_WORD_INVERT_ON_SHIFT case MOD_LSFT: keycode = KC_LSFT; break; case MOD_RSFT: keycode = KC_RSFT; break; +# endif // CAPS_WORD_INVERT_ON_SHIFT case MOD_RSFT | MOD_RALT: keycode = RSFT(KC_RALT); break; @@ -124,6 +179,9 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) { return true; default: caps_word_off(); +# ifdef CAPS_WORD_INVERT_ON_SHIFT + add_mods(held_mods); +# endif // CAPS_WORD_INVERT_ON_SHIFT return true; } } else { @@ -163,12 +221,20 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) { clear_weak_mods(); #endif // AUTO_SHIFT_ENABLE if (caps_word_press_user(keycode)) { +#ifdef CAPS_WORD_INVERT_ON_SHIFT + if (held_mods) { + set_weak_mods(get_weak_mods() ^ MOD_BIT(KC_LSFT)); + } +#endif // CAPS_WORD_INVERT_ON_SHIFT send_keyboard_report(); return true; } } caps_word_off(); +#ifdef CAPS_WORD_INVERT_ON_SHIFT + add_mods(held_mods); +#endif // CAPS_WORD_INVERT_ON_SHIFT return true; } -- cgit v1.2.3 From d3b8179f467da23fec98e97b28684c43e9e8ba73 Mon Sep 17 00:00:00 2001 From: Ricardo Hermida Ruiz Date: Mon, 10 Apr 2023 09:45:25 -0300 Subject: Prevent Tri-Layer keys from stopping caps words (#20398) --- quantum/process_keycode/process_caps_word.c | 1 + 1 file changed, 1 insertion(+) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_caps_word.c b/quantum/process_keycode/process_caps_word.c index 8f2ee1db8b..d4382680bf 100644 --- a/quantum/process_keycode/process_caps_word.c +++ b/quantum/process_keycode/process_caps_word.c @@ -148,6 +148,7 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) { case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX: case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX: case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX: + case QK_TRI_LAYER_LOWER ... QK_TRI_LAYER_UPPER: // Ignore AltGr. case KC_RALT: case OSM(MOD_RALT): -- cgit v1.2.3 From 8a332e6f0105d2db9239e3c3f997bae754522804 Mon Sep 17 00:00:00 2001 From: Pete Sevander Date: Wed, 10 May 2023 18:59:52 +0300 Subject: Fix Mod-Tap combo regression (#20669) * Add keyevent for combo keyrecord * Fix formatting * Update quantum/process_keycode/process_combo.c Co-authored-by: Sergey Vlasov * Add combo unit-tests and hot-fix process_record_tap_hint ...as this function tries to lookup the combo keys passed in. This will be refactored in a later pr. --------- Co-authored-by: Sergey Vlasov Co-authored-by: Stefan Kerkmann --- quantum/process_keycode/process_combo.c | 1 + 1 file changed, 1 insertion(+) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index b1b49d3019..2670ccabed 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -335,6 +335,7 @@ void apply_combo(uint16_t combo_index, combo_t *combo) { // this in the end executes the combo when the key_buffer is dumped. record->keycode = combo->keycode; record->event.type = COMBO_EVENT; + record->event.key = MAKE_KEYPOS(0, 0); qrecord->combo_index = combo_index; ACTIVATE_COMBO(combo); -- cgit v1.2.3 From 5faa23d54ca1e3ab83097f2a07922f48800616e6 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Mon, 15 May 2023 22:27:37 +1000 Subject: Keymap introspection for combos. (#19670) --- quantum/process_keycode/process_combo.c | 23 ++++++++--------------- quantum/process_keycode/process_combo.h | 2 +- 2 files changed, 9 insertions(+), 16 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index 2670ccabed..bbee560be9 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -19,14 +19,7 @@ #include "process_combo.h" #include "action_tapping.h" #include "action.h" - -#ifdef COMBO_COUNT -__attribute__((weak)) combo_t key_combos[COMBO_COUNT]; -uint16_t COMBO_LEN = COMBO_COUNT; -#else -extern combo_t key_combos[]; -extern uint16_t COMBO_LEN; -#endif +#include "keymap_introspection.h" __attribute__((weak)) void process_combo_event(uint16_t combo_index, bool pressed) {} @@ -195,8 +188,8 @@ static inline uint16_t _get_combo_term(uint16_t combo_index, combo_t *combo) { void clear_combos(void) { uint16_t index = 0; longest_term = 0; - for (index = 0; index < COMBO_LEN; ++index) { - combo_t *combo = &key_combos[index]; + for (index = 0; index < combo_count(); ++index) { + combo_t *combo = combo_get(index); if (!COMBO_ACTIVE(combo)) { RESET_COMBO_STATE(combo); } @@ -287,7 +280,7 @@ void drop_combo_from_buffer(uint16_t combo_index) { queued_combo_t *qcombo = &combo_buffer[i]; if (qcombo->combo_index == combo_index) { - combo_t *combo = &key_combos[combo_index]; + combo_t *combo = combo_get(combo_index); DISABLE_COMBO(combo); if (i == combo_buffer_read) { @@ -354,7 +347,7 @@ static inline void apply_combos(void) { // Apply all buffered normal combos. for (uint8_t i = combo_buffer_read; i != combo_buffer_write; INCREMENT_MOD(i)) { queued_combo_t *buffered_combo = &combo_buffer[i]; - combo_t * combo = &key_combos[buffered_combo->combo_index]; + combo_t * combo = combo_get(buffered_combo->combo_index); #ifdef COMBO_MUST_TAP_PER_COMBO if (get_combo_must_tap(buffered_combo->combo_index, combo)) { @@ -459,7 +452,7 @@ static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t * combo_t *drop = NULL; for (uint8_t combo_buffer_i = combo_buffer_read; combo_buffer_i != combo_buffer_write; INCREMENT_MOD(combo_buffer_i)) { queued_combo_t *qcombo = &combo_buffer[combo_buffer_i]; - combo_t * buffered_combo = &key_combos[qcombo->combo_index]; + combo_t * buffered_combo = combo_get(qcombo->combo_index); if ((drop = overlaps(buffered_combo, combo))) { DISABLE_COMBO(drop); @@ -565,8 +558,8 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { } #endif - for (uint16_t idx = 0; idx < COMBO_LEN; ++idx) { - combo_t *combo = &key_combos[idx]; + for (uint16_t idx = 0; idx < combo_count(); ++idx) { + combo_t *combo = combo_get(idx); is_combo_key |= process_single_combo(combo, keycode, record, idx); no_combo_keys_pressed = no_combo_keys_pressed && (NO_COMBO_KEYS_ARE_DOWN || COMBO_ACTIVE(combo) || COMBO_DISABLED(combo)); } diff --git a/quantum/process_keycode/process_combo.h b/quantum/process_keycode/process_combo.h index e430c4a5f7..bba5d5ee63 100644 --- a/quantum/process_keycode/process_combo.h +++ b/quantum/process_keycode/process_combo.h @@ -37,7 +37,7 @@ # define COMBO_BUFFER_LENGTH 4 #endif -typedef struct { +typedef struct combo_t { const uint16_t *keys; uint16_t keycode; #ifdef EXTRA_SHORT_COMBOS -- cgit v1.2.3 From 3993b15f054265071730cdb450f43457dcf4c64a Mon Sep 17 00:00:00 2001 From: Pascal Getreuer <50221757+getreuer@users.noreply.github.com> Date: Sat, 20 May 2023 05:35:06 -0700 Subject: [Core] Add Repeat Key ("repeat last key") as a core feature. (#19700) Co-authored-by: casuanoob <96005765+casuanoob@users.noreply.github.com> Co-authored-by: Sergey Vlasov --- quantum/process_keycode/process_repeat_key.c | 109 +++++++++++++++++++++++++++ quantum/process_keycode/process_repeat_key.h | 62 +++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 quantum/process_keycode/process_repeat_key.c create mode 100644 quantum/process_keycode/process_repeat_key.h (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_repeat_key.c b/quantum/process_keycode/process_repeat_key.c new file mode 100644 index 0000000000..f819aa226e --- /dev/null +++ b/quantum/process_keycode/process_repeat_key.c @@ -0,0 +1,109 @@ +// Copyright 2022-2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "process_repeat_key.h" + +// Default implementation of remember_last_key_user(). +__attribute__((weak)) bool remember_last_key_user(uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods) { + return true; +} + +static bool remember_last_key(uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods) { + switch (keycode) { + // Ignore MO, TO, TG, TT, and TL layer switch keys. + case QK_MOMENTARY ... QK_MOMENTARY_MAX: + case QK_TO ... QK_TO_MAX: + case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX: + case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX: + // Ignore mod keys. + case KC_LCTL ... KC_RGUI: + case KC_HYPR: + case KC_MEH: +#ifndef NO_ACTION_ONESHOT // Ignore one-shot keys. + case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX: + case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX: +#endif // NO_ACTION_ONESHOT +#ifdef TRI_LAYER_ENABLE // Ignore Tri Layer keys. + case QK_TRI_LAYER_LOWER: + case QK_TRI_LAYER_UPPER: +#endif // TRI_LAYER_ENABLE + return false; + + // Ignore hold events on tap-hold keys. +#ifndef NO_ACTION_TAPPING + case QK_MOD_TAP ... QK_MOD_TAP_MAX: +# ifndef NO_ACTION_LAYER + case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: +# endif // NO_ACTION_LAYER + if (record->tap.count == 0) { + return false; + } + break; +#endif // NO_ACTION_TAPPING + +#ifdef SWAP_HANDS_ENABLE + case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX: + if (IS_SWAP_HANDS_KEYCODE(keycode) || record->tap.count == 0) { + return false; + } + break; +#endif // SWAP_HANDS_ENABLE + + case QK_REPEAT_KEY: +#ifndef NO_ALT_REPEAT_KEY + case QK_ALT_REPEAT_KEY: +#endif // NO_ALT_REPEAT_KEY + return false; + } + + return remember_last_key_user(keycode, record, remembered_mods); +} + +bool process_last_key(uint16_t keycode, keyrecord_t* record) { + if (get_repeat_key_count()) { + return true; + } + + if (record->event.pressed) { + uint8_t remembered_mods = get_mods() | get_weak_mods(); +#ifndef NO_ACTION_ONESHOT + remembered_mods |= get_oneshot_mods(); +#endif // NO_ACTION_ONESHOT + + if (remember_last_key(keycode, record, &remembered_mods)) { + set_last_record(keycode, record); + set_last_mods(remembered_mods); + } + } + + return true; +} + +bool process_repeat_key(uint16_t keycode, keyrecord_t* record) { + if (get_repeat_key_count()) { + return true; + } + + if (keycode == QK_REPEAT_KEY) { + repeat_key_invoke(&record->event); + return false; +#ifndef NO_ALT_REPEAT_KEY + } else if (keycode == QK_ALT_REPEAT_KEY) { + alt_repeat_key_invoke(&record->event); + return false; +#endif // NO_ALT_REPEAT_KEY + } + + return true; +} diff --git a/quantum/process_keycode/process_repeat_key.h b/quantum/process_keycode/process_repeat_key.h new file mode 100644 index 0000000000..eddc50f254 --- /dev/null +++ b/quantum/process_keycode/process_repeat_key.h @@ -0,0 +1,62 @@ +// Copyright 2022-2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include "quantum.h" + +/** + * @brief Process handler for remembering the last key. + * + * @param keycode Keycode registered by matrix press, per keymap + * @param record keyrecord_t structure + * @return true Continue processing keycodes, and send to host + * @return false Stop processing keycodes, and don't send to host + */ +bool process_last_key(uint16_t keycode, keyrecord_t* record); + +/** + * @brief Optional callback defining which keys are remembered. + * + * @param keycode Keycode that was just pressed + * @param record keyrecord_t structure + * @param remembered_mods Mods that will be remembered with this key + * @return true Key is remembered + * @return false Key is ignored + * + * Modifier and layer switch keys are always ignored. For all other keys, this + * callback is called on every key press. Returning true means that the key is + * remembered, false means it is ignored. By default, all non-modifier, + * non-layer switch keys are remembered. + * + * The `remembered_mods` arg represents the mods that will be remembered with + * this key. It can be modified to forget certain mods, for instance to forget + * capitalization when repeating shifted letters: + * + * // Forget Shift on letter keys. + * if (KC_A <= keycode && keycode <= KC_Z && (*remembered_mods & ~MOD_MASK_SHIFT) == 0) { + * *remembered_mods = 0; + * } + */ +bool remember_last_key_user(uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods); + +/** + * @brief Process handler for Repeat Key feature. + * + * @param keycode Keycode registered by matrix press, per keymap + * @param record keyrecord_t structure + * @return true Continue processing keycodes, and send to host + * @return false Stop processing keycodes, and don't send to host + */ +bool process_repeat_key(uint16_t keycode, keyrecord_t* record); -- cgit v1.2.3