Skip to content

fix(linux): prevent stuck keys from uinput repeat races - #198

Merged
ReenigneArcher merged 1 commit into
masterfrom
codex/fix-linux-keyboard-repeat-race
Oct 20, 2026
Merged

ReenigneArcher merged 1 commit into
masterfrom
codex/fix-linux-keyboard-repeat-race

Conversation

@ReenigneArcher

Copy link
Copy Markdown
Member

Description

The uinput keyboard repeat thread can replay a stale key press after a release, leaving the key held in the kernel while the library tracks it as released. Remove the repeat thread and its pressed-key cache so only caller-submitted transitions reach the device. Key repeat remains with the compositor or X server.

Document that the uinput backend ignores auto_repeat_interval_ms, and add event-capture and real-uinput regression coverage.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Testing

  • The event-capture regression fails against the original backend with 38 events instead of the four submitted press/release events. It passes with the fix for repeat intervals of 0, 1, and the default 50 milliseconds.
  • Reproduced the stuck key with the original backend on a grabbed uinput device in an isolated QEMU VM running Linux 7.0.0-38-generic: EVIOCGKEY reported KEY_F still down after release. With the fix, both native tests pass: libinput keyboard transitions and two seconds of rapid press/release cycles with kernel-state checks and a delayed check for a late press.
  • Linux: built test_libvirtualhid and gamepad_adapter; all 146 device-independent tests passed.
  • MSYS2/UCRT64: built the library, test_libvirtualhid, and gamepad_adapter; all 52 selected core API, report, adapter, and lifecycle tests passed.
  • clang-format 23.1.0, git diff --check, and Doxygen passed with no documentation warnings.
  • Sunshine/Moonlight streaming and Hyprland end-to-end behavior were not tested.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Tests have been added or updated for new or modified functionality, including regression tests for bug fixes

AI Usage

See our AI usage policy.

  • AI tools were used while preparing this PR

Generated by Codex using gpt-6.1-sol with xhigh thinking.

@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.74%. Comparing base (dfff3ea) to head (5bab58e).
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #198      +/-   ##
==========================================
+ Coverage   73.73%   73.74%   +0.01%     
==========================================
  Files          43       43              
  Lines       10704    10670      -34     
  Branches     3696     3677      -19     
==========================================
- Hits         7893     7869      -24     
+ Misses       2447     2442       -5     
+ Partials      364      359       -5     
Flag Coverage Δ
FreeBSD 53.99% <50.00%> (+0.14%) ⬆️
Linux-Clang 68.43% <100.00%> (+0.02%) ⬆️
Linux-GCC 80.96% <100.00%> (+0.05%) ⬆️
PowerShell 75.60% <ø> (ø)
Windows-MSVC 74.15% <ø> (-0.02%) ⬇️
Windows-MinGW-UCRT64 66.19% <ø> (+0.11%) ⬆️
macOS 50.96% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/include/libvirtualhid/types.hpp 97.43% <ø> (ø)
src/platform/linux/uhid_backend.cpp 81.46% <100.00%> (+0.08%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dfff3ea...5bab58e. Read the comment docs.

@ReenigneArcher
ReenigneArcher merged commit 1aea6e3 into master Oct 20, 2026
34 checks passed
@ReenigneArcher
ReenigneArcher deleted the codex/fix-linux-keyboard-repeat-race branch October 20, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linux: uinput keyboard repeat thread can re-press a just-released key, leaving it stuck down

1 participant