summaryrefslogtreecommitdiffstats
path: root/quantum
diff options
context:
space:
mode:
authorSergey Vlasov <sigprof@gmail.com>2022-10-03 12:48:16 +0300
committerGitHub <noreply@github.com>2022-10-03 20:48:16 +1100
commitca0c12847a97a62f887fd4625673395104a7257b (patch)
tree5948722aba72b72e549232950f38a35500638262 /quantum
parent0e6f1914367c59ced83c45ff4212fcc489918936 (diff)
Fix layer switching from tap dances by redoing the keymap lookup (#17935)
Diffstat (limited to 'quantum')
-rw-r--r--quantum/process_keycode/process_tap_dance.c12
-rw-r--r--quantum/process_keycode/process_tap_dance.h2
-rw-r--r--quantum/quantum.c6
3 files changed, 15 insertions, 5 deletions
diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c
index 3270a1b000..6e8e596673 100644
--- a/quantum/process_keycode/process_tap_dance.c
+++ b/quantum/process_keycode/process_tap_dance.c
@@ -115,12 +115,12 @@ static inline void process_tap_dance_action_on_dance_finished(qk_tap_dance_actio
}
}
-void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) {
+bool preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) {
qk_tap_dance_action_t *action;
- if (!record->event.pressed) return;
+ if (!record->event.pressed) return false;
- if (!active_td || keycode == active_td) return;
+ if (!active_td || keycode == active_td) return false;
action = &tap_dance_actions[TD_INDEX(active_td)];
action->state.interrupted = true;
@@ -130,6 +130,12 @@ void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) {
// Tap dance actions can leave some weak mods active (e.g., if the tap dance is mapped to a keycode with
// modifiers), but these weak mods should not affect the keypress which interrupted the tap dance.
clear_weak_mods();
+
+ // Signal that a tap dance has been finished due to being interrupted,
+ // therefore the keymap lookup for the currently processed event needs to
+ // be repeated with the current layer state that might have been updated by
+ // the finished tap dance.
+ return true;
}
bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h
index d97900d96b..d6d6c136dc 100644
--- a/quantum/process_keycode/process_tap_dance.h
+++ b/quantum/process_keycode/process_tap_dance.h
@@ -81,7 +81,7 @@ void reset_tap_dance(qk_tap_dance_state_t *state);
/* To be used internally */
-void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record);
+bool preprocess_tap_dance(uint16_t keycode, keyrecord_t *record);
bool process_tap_dance(uint16_t keycode, keyrecord_t *record);
void tap_dance_task(void);
diff --git a/quantum/quantum.c b/quantum/quantum.c
index ff36e14775..5b5364c8f1 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -251,7 +251,11 @@ bool process_record_quantum(keyrecord_t *record) {
#endif
#ifdef TAP_DANCE_ENABLE
- preprocess_tap_dance(keycode, record);
+ if (preprocess_tap_dance(keycode, record)) {
+ // The tap dance might have updated the layer state, therefore the
+ // result of the keycode lookup might change.
+ keycode = get_record_keycode(record, true);
+ }
#endif
if (!(