Repository navigation
fix: stale captured events leaking across interactions - #4
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
balancedflavor, it was possible to get spurious keycodes emitted atthe start of a subsequent interaction. For example, with
&ok_ltmonYand&kp TABonT(on the app-switch layer), typing normally could occasionallyproduce one or more
Tkeycodes followed by the intendedYoutput.Root cause: a race between the tapping-term timer and the interrupt key.
With
balancedflavor, a hold is resolved when an interrupt key is both pressedand released. However, if the tapping-term timer fires while the interrupt key
is still held down,
do_hold()is called from the work handler — which setsundecided_olm = NULL. The interrupt key's release event then arrives afterundecided_olmisNULL, so the position listener lets it bubble freely insteadof capturing it. The result: the interrupt key-down is in the capture buffer but
its key-up is not, and
captured_events_countis never reset.On the next interaction, if a tap resolves,
release_captured_events()replaysthe stale key-down from the previous interaction — emitting an unexpected keycode
before the intended output.
Fix
Two changes to
behavior_os_layer_mod.c:os_layer_mod_work_handler: callrelease_captured_events()immediatelyafter
do_hold()when the timer fires. This mirrors exactly what theinterrupt-driven path already does in the event listener, and ensures the
buffer is always cleared when a hold is decided.
on_os_layer_mod_binding_released(HOLD path): resetcaptured_events_count = 0as a defensive safety net for any edge case where an event entered the buffer
without being replayed.
Tests
Added
tests/os-layer-mod/balanced-timer-fires-while-interrupt-held: pressesthe
ok_ltmkey, presses an interrupt key, then waits pasttapping-term-mswhile the interrupt key is still held. Verifies the interrupt key is replayed
under the active layer (producing
TwhileLALTis held), with no leakageinto subsequent interactions.
Fixed
run-teststo run all test suites undertests/when invoked withno arguments, rather than only the
oskey/suite. Theos-layer-modsuite waspreviously silently skipped.