Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not leak weak mods from tap dance to the interrupting keypress #12471

Merged
merged 1 commit into from
Apr 25, 2021

Conversation

sigprof
Copy link
Contributor

@sigprof sigprof commented Apr 3, 2021

Description

Tap dance callbacks may register weak mods; one case when it happens is when a tap dance registers a key with modifiers. When the tap dance is interrupted by pressing another key, these weak mods could affect the interrupting key (normally any stale weak mods are cleared at the start of action_exec() when handling a keypress event, but the tap dance interrupt check code is called later, and the weak mods left by that code were not cleared). Add another clear_weak_mods() call to preprocess_tap_dance() to make sure that the interrupting keypress is not affected by unrelated weak mods from the previous tap dance.

One example of a tap dance which exhibits the problem and can be used with the US QWERTY layout (unlike the example from #12445, which assumes the US International layout):

    [TD_LBRC] = ACTION_TAP_DANCE_DOUBLE(KC_LPRN, KC_LBRC),

Before the fix, pressing that tap dance key and then immediately pressing another key without releasing the tap dance key would result in the Shift modifier from KC_LPRN (which is actually S(KC_9)) getting applied to the second key.

This use case was broken by PR #9941, but just reverting that PR is not the correct solution, because it fixed another set of problems with weak mods. In particular, a reset before preprocess_tap_dance() is also required, so that any stale weak mods won't affect the keys which are registered by the tap dance itself.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Tap dance callbacks may register weak mods; one case when it happens
is when a tap dance registers a key with modifiers.  When the tap
dance is interrupted by pressing another key, these weak mods could
affect the interrupting key (normally any stale weak mods are cleared
at the start of action_exec() when handling a keypress event, but the
tap dance interrupt check code is called later, and the weak mods left
by that code were not cleared).  Add another clear_weak_mods() call to
preprocess_tap_dance() to make sure that the interrupting keypress is
not affected by unrelated weak mods from the previous tap dance.

Fixes qmk#12445.
@github-actions github-actions bot added the core label Apr 3, 2021
@spidey3 spidey3 requested a review from a team April 18, 2021 23:04
@drashna drashna requested a review from a team April 18, 2021 23:22
@tzarc tzarc merged commit da6e888 into qmk:master Apr 25, 2021
makenova pushed a commit to makenova/qmk_firmware that referenced this pull request Apr 26, 2021
…k#12471)

Tap dance callbacks may register weak mods; one case when it happens
is when a tap dance registers a key with modifiers.  When the tap
dance is interrupted by pressing another key, these weak mods could
affect the interrupting key (normally any stale weak mods are cleared
at the start of action_exec() when handling a keypress event, but the
tap dance interrupt check code is called later, and the weak mods left
by that code were not cleared).  Add another clear_weak_mods() call to
preprocess_tap_dance() to make sure that the interrupting keypress is
not affected by unrelated weak mods from the previous tap dance.

Fixes qmk#12445.
rizo pushed a commit to rizo/qmk_firmware that referenced this pull request May 10, 2021
…k#12471)

Tap dance callbacks may register weak mods; one case when it happens
is when a tap dance registers a key with modifiers.  When the tap
dance is interrupted by pressing another key, these weak mods could
affect the interrupting key (normally any stale weak mods are cleared
at the start of action_exec() when handling a keypress event, but the
tap dance interrupt check code is called later, and the weak mods left
by that code were not cleared).  Add another clear_weak_mods() call to
preprocess_tap_dance() to make sure that the interrupting keypress is
not affected by unrelated weak mods from the previous tap dance.

Fixes qmk#12445.
toddyamakawa pushed a commit to toddyamakawa/qmk_firmware that referenced this pull request May 19, 2021
…k#12471)

Tap dance callbacks may register weak mods; one case when it happens
is when a tap dance registers a key with modifiers.  When the tap
dance is interrupted by pressing another key, these weak mods could
affect the interrupting key (normally any stale weak mods are cleared
at the start of action_exec() when handling a keypress event, but the
tap dance interrupt check code is called later, and the weak mods left
by that code were not cleared).  Add another clear_weak_mods() call to
preprocess_tap_dance() to make sure that the interrupting keypress is
not affected by unrelated weak mods from the previous tap dance.

Fixes qmk#12445.
HokieGeek pushed a commit to HokieGeek/qmk_firmware that referenced this pull request Jul 11, 2021
…k#12471)

Tap dance callbacks may register weak mods; one case when it happens
is when a tap dance registers a key with modifiers.  When the tap
dance is interrupted by pressing another key, these weak mods could
affect the interrupting key (normally any stale weak mods are cleared
at the start of action_exec() when handling a keypress event, but the
tap dance interrupt check code is called later, and the weak mods left
by that code were not cleared).  Add another clear_weak_mods() call to
preprocess_tap_dance() to make sure that the interrupting keypress is
not affected by unrelated weak mods from the previous tap dance.

Fixes qmk#12445.
BorisTestov pushed a commit to BorisTestov/qmk_firmware that referenced this pull request May 23, 2024
…k#12471)

Tap dance callbacks may register weak mods; one case when it happens
is when a tap dance registers a key with modifiers.  When the tap
dance is interrupted by pressing another key, these weak mods could
affect the interrupting key (normally any stale weak mods are cleared
at the start of action_exec() when handling a keypress event, but the
tap dance interrupt check code is called later, and the weak mods left
by that code were not cleared).  Add another clear_weak_mods() call to
preprocess_tap_dance() to make sure that the interrupting keypress is
not affected by unrelated weak mods from the previous tap dance.

Fixes qmk#12445.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants