Skip to content

fix(input): track and release the X2 mouse button - #6232

Open
diEBirne wants to merge 1 commit into
SunshineStream:masterfrom
diEBirne:fix/track-mouse-x2-button
Open

diEBirne wants to merge 1 commit into
SunshineStream:masterfrom
diEBirne:fix/track-mouse-x2-button

Conversation

@diEBirne

@diEBirne diEBirne commented Dec 5, 2026

Copy link
Copy Markdown

Description

mouse_press tracks which mouse buttons are held so that reset_mouse_buttons() can release them when the
client disconnects. It is indexed by the Moonlight button ID, but those IDs run from BUTTON_LEFT (1) to
BUTTON_X2 (5), while the array only had 5 slots (0-4). The bounds check in the mouse button passthrough
(button < mouse_press.size()) therefore skipped BUTTON_X2 entirely: the press was still forwarded to the
platform, but never recorded, so a disconnect never released it.

In practice this leaves the host's "forward" mouse button stuck down. It is easy to hit with Moonlight's gamepad
mouse emulation, which maps RB to BUTTON_X2: the quit combo (Select + Start + LB + RB) ends the stream while RB is
still held. Afterwards clicks and text selection on the host no longer work until the button state is reset
(e.g. Ctrl+Alt+Del). BUTTON_X1 (LB) was released correctly, only BUTTON_X2 stayed down.

The fix sizes the array as BUTTON_X2 + 1 so every Moonlight button ID has a slot. Two small test helpers
(send_mouse_button_packet(), release_held_mouse_buttons()) mirror the existing keyboard helpers and are used by
a regression test that presses each button and checks that a disconnect-style reset releases it.

Screenshot

Issues Fixed or Closed

Possibly related: moonlight-stream/moonlight-qt#2035 (a comment there reports stuck input with gamepad mouse mode and
a Windows host).

Roadmap Issues

Testing

Added InputGamepadSessionTest.ReleasesEveryHeldMouseButtonOnDisconnect in tests/unit/test_input.cpp. It uses the
existing fake libvirtualhid backend, presses each Moonlight mouse button (BUTTON_LEFT through BUTTON_X2) and checks
that release_held_mouse_buttons() (the same reset_mouse_buttons() a disconnect runs) submits exactly one release
for that button.

Validated in a debian:trixie container (deps from scripts/linux_build.sh --step=deps, CUDA and docs off), based on
13ca613:

  • Without the fix (array size reverted to 5): the new test fails for BUTTON_X2 only; the fake backend logs
    button 4 pressed with no matching release.
  • With the fix: the new test passes.
  • With the fix: InputGamepadSessionTest.*:InputPacketValidationTest.*:*Keyboard*:*Mouse* under xvfb-run,
    51 tests passed.
  • clang-format --dry-run --Werror (19.1.7) on the changed files: no findings.

Manual: reproduced the stuck button on a Windows host (Apollo, which shares this code) with the Moonlight gamepad
mouse emulation quit combo. I did not build or run the full test suite, or test on Windows or macOS.

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

@sonarqubecloud

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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.

1 participant