Skip to content

Input: trigger rumble through Windows.Gaming.Input - #2095

Open
fylzzz wants to merge 1 commit into
Marvisak:mainfrom
fylzzz:input/trigger-rumble
Open

fylzzz wants to merge 1 commit into
Marvisak:mainfrom
fylzzz:input/trigger-rumble

Conversation

@fylzzz

@fylzzz fylzzz commented Nov 25, 2026

Copy link
Copy Markdown

The title sends four motor levels to the device's rumble slot (0x50); the last two, the trigger motors, were dropped because XInput has none. This drives all four through Windows.Gaming.Input (the windows crate's Gaming_Input feature) when exactly one pad is connected, and falls back to XInput otherwise, since the two APIs share no pad identity. A pad that stops being driven this way has its vibration cleared.

Windows.Gaming.Input ignores the process while none of its windows is in front, so in the background the body motors stop too (XInput used to keep them going).

Tested on Windows 11 with an Xbox One pad over USB: all four motors respond with our window in front. I checked this with a hand-run test I've left out of this PR and can add if you want it.

The title sends four motor levels to slot 0x50 (low and high frequency,
left and right trigger); XInput has no trigger motors, so the last two
were dropped. The `windows` crate is already a dependency, so its
`Gaming_Input` feature gives the WinRT `Gamepad.Vibration` outside
diagnostics builds.

When one XInput slot is connected and Windows.Gaming.Input lists one
pad, all four motors go to that pad; otherwise the body motors go
through XInput as before. The two APIs share no pad identity, so with
several pads the triggers stay still (a shortcut, noted). A pad that
stops being driven this way has its vibration cleared first.
Windows.Gaming.Input ignores the process while none of its windows is
in front, so in the background the body motors stop too.

Levels are clamped to 0..1 with NaN as off, and `Source::rumble` takes
all four as `Motors`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-hle --lib gameinput:: — 9 passed, 0 failed
  • cargo clippy -p victory-hle --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean trigger rumble support via Windows.Gaming.Input with fallback to XInput and updated README.md. Looks good.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review only: victory-hle is Windows-only — nothing compiles or runs on macOS; source review of the diff.

Rumble via Windows.Gaming.Input instead of XInput — newer input path; note the crate is still Windows-only so this stays static on macOS.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

gameinput.rs set_rumble (slot 0x50) now passes all four motor levels. When exactly one XInput slot and one Windows.Gaming.Input pad are connected, host::Host::rumble drives them through Gamepad::SetVibration; otherwise it falls back to XInput for the body motors as before, and it clears a pad it stops driving. The only build change is the Gaming_Input feature of the windows crate victory-hle already uses. This replaces the shortcut comment in main. The test covers clamping and NaN. CI passes, and the author reports testing with an Xbox One pad.

Worth a maintainer's look: the disclosed trade-off that Windows.Gaming.Input stops all rumble while the window is in the background, which XInput did not. Gamepad::Gamepads() is also queried on every rumble call.


Generated by Claude Code

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Code review and Windows 11 verification at head 266f49ea9d08 merged cleanly onto main (63bcca43c6a0):

  • Code review (crates/victory-hle/src/modules/gameinput.rs:328-329, 1314-1340):
    • set_rumble filters NaN, negatives, and > 1.0 cleanly via if level > 0.0 { level.min(1.0) } else { 0.0 }.
    • Host::rumble .take()s self.driven[slot] first and zeros vibration (GamepadVibration::default()) on the previous Gamepad whenever the device disconnects or switches before falling back to XInputSetState, avoiding stuck trigger rumble.
    • Two minor non-blocking notes (both fall back safely to XInput): (1) if the calling thread hasn't initialized COM/WinRT, Gamepad::Gamepads() returns CO_E_NOTINITIALIZED and falls back to XInput without trigger motors; (2) on the very first call before an initial pad() poll populates empty_until, connected(s) reports true for all 4 slots so the first rumble falls back to XInput.
  • Verified (Windows 11, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy -p victory-hle --all-targets -- -D warnings: 0 warnings
    • victory-hle --lib -- input: 10/10 passed (full lib skipping unrelated concurrent test a_page_list_filled_after_its_request_starts which passes solo: 151/151 passed).

LGTM.

@kilolimaVI

Copy link
Copy Markdown

Comparison of the four open trigger-rumble PRs (README: "Trigger rumble"), each merged onto current main 63bcca4. Windows 11, toolchain 1.98.1; no pad here, so unit tests and CI's clippy checks only.

PR merge onto main cargo test -p victory-hle --lib -- gameinput clippy -D warnings (default / --all-features)
#1357 conflict in gameinput.rs - -
#1761 conflict in gameinput.rs - -
#1958 clean 18 passed (8 new) clean / clean
#2095 clean 10 passed (no new tests) clean / clean

#1958 and #2095 are separate implementations of the same Windows.Gaming.Input trigger path. #1958 also carries three input changes besides rumble (device methods answering as devices, a manual-dispatch dispatcher, QueryInterface by interface id) and tests for them; #2095 is rumble only, smaller, without tests. Taking one should close the other three. Both add "Gaming_Input" to victory-hle's windows features, so whichever goes second will need a one-line rebase there.

AI-assisted (Claude).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants