Input: controller input keeps the display and the PC awake, as keyboard and mouse do (#893) #921

Merged
xiepeixuan merged 1 commit from upstream-pr/921 into main 2026-11-29 08:16:58 +00:00
xiepeixuan commented 2026-11-28 09:07:55 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by xiepeixuan on 2026-11-28T09:07:55Z.


Part of #893 (the display sleeping); the Game Bar part is not addressed.

What it changes

Windows can reach its display or system idle timeout while the player is using only a controller. Here GameInput polls XInput and reads PlayStation HID reports directly, then passes snapshots to the title; that path does not tell Windows to reset the idle timers as keyboard and mouse activity do. This fits the report that moving the mouse restores the screen while the title is still presenting.

In the Windows Host::pad refresh of the merged XInput/PlayStation snapshot, check all physical slots before adding VICTORY_KEYS buttons. A button, a trigger above the XInput threshold (30), or a stick outside its radial dead zone (7849 left, 8689 right) counts as activity. The thresholds are converted to the existing normalized PadState units; they are only used for the idle decision and never filter the values passed to the title.

Reuse the keyboard's foreground check and send a single SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED) at most once per second across the four slots. Without ES_CONTINUOUS, Windows resets the idle timers rather than holding a request. The title's own deferrals already go through display.rs, which is unchanged. This does not add a switch, change the power plan, or keep the PC awake once nobody is using the controller.

Uses audit

Checked use Effect
Host::pad from Hub::poll One check when slot zero refreshes the shared snapshot, including when slot zero is empty but another slot is active. Other slots return the same cached readings. Hub::start still does its initial poll and starts the same poll thread.
Source::pad from single-pad set_rumble Its existing enumeration can also observe physical input at slot zero. It shares the same timer and focus gate; a rumble command itself is not activity. The connected-slot test, motor levels, routing and multi-pad path are unchanged. Fake and non-Windows sources are unchanged.
host(), Host::default, and HUB The single shared Windows host starts with no previous reset. The existing source mutex protects the same snapshot and the new timestamp for both callers.
Host::pads, hid_slots, Host::xinput, convert, and playstation::{mode, slots, pads} Device polling, XInput precedence, HID slot assignment, and rumble ownership do not change. The idle check reads the merged snapshot without mutating it. convert, the HID parser, pad merging, the keyboard stand-in, reading history, and the gamepad_state ABI keep the same PadState values.
focused, scripted, and FALLBACK_BUTTONS The keyboard path calls the same helpers and keeps the same behavior. Slot zero still gets the same scripted buttons only when it has a physical pad, but only after the activity check. The stand-in keyboard pad still uses the same mapping.
pad_active, PadActivity::first_pad, last_reset, and reset_idle_timers New private uses only: the activity helper supplies the one Windows call site, and tests inject the clock, focus, script and reset callbacks.

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): No in-game run; Windows unit tests only.

  • Before: 26 passed, 0 failed on 63b902fe.

  • After: 30 passed, 0 failed on 16c09473.

  • cargo test passed for the crates it touches: Yes — cargo test -p victory-hle --lib gameinput.

  • Windows workspace check: cargo check --workspace --locked passed on 16c09473e1d588e71fd38f2360a57c5961a0289b. Fork Windows job

  • Windows GameInput tests: cargo test -p victory-hle --lib gameinput passed: 30 passed, 0 failed, versus 26 passed, 0 failed on upstream 63b902fe in the same workflow. The four new tests cover the shared one-second limit, inactive input and normalized threshold boundaries, foreground gating, and scripted buttons.

  • Full Windows CI: the fork run stops at the same two Clippy errors as upstream main (see #665), with no new diagnostics. The later all-features Clippy and workspace-test steps are skipped as on main.

    • clippy::let_and_return at crates/victory-shader/src/emit/mod.rs:2768:9
    • clippy::manual_is_multiple_of at crates/victory-gpu/src/shadow.rs:1708:32

The fork workflow was triggered separately, but both topic jobs checked out and asserted the exact PR SHA above. No workflow changes or workspace-wide formatting are included in this PR.

Checked for overlap

  • I searched the open pull requests for the same issue and for crates/victory-hle/src/modules/gameinput.rs. Related: #1098 (scripted input timing) and #839 (controller detection); neither resets Windows idle timers for physical controller activity.

AI-assisted (Codex). Not run in the game here.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5538588704 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/921). Originally posted by [xiepeixuan](https://github.com/xiepeixuan) on 2026-11-28T09:07:55Z. --- Part of #893 (the display sleeping); the Game Bar part is not addressed. ## What it changes Windows can reach its display or system idle timeout while the player is using only a controller. Here GameInput polls XInput and reads PlayStation HID reports directly, then passes snapshots to the title; that path does not tell Windows to reset the idle timers as keyboard and mouse activity do. This fits the report that moving the mouse restores the screen while the title is still presenting. In the Windows `Host::pad` refresh of the merged XInput/PlayStation snapshot, check all physical slots **before** adding `VICTORY_KEYS` buttons. A button, a trigger above the XInput threshold (30), or a stick outside its radial dead zone (7849 left, 8689 right) counts as activity. The thresholds are converted to the existing normalized `PadState` units; they are only used for the idle decision and never filter the values passed to the title. Reuse the keyboard's foreground check and send a single `SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)` at most once per second across the four slots. Without `ES_CONTINUOUS`, [Windows resets the idle timers rather than holding a request](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate). The title's own deferrals already go through `display.rs`, which is unchanged. This does not add a switch, change the power plan, or keep the PC awake once nobody is using the controller. ### Uses audit | Checked use | Effect | |---|---| | `Host::pad` from `Hub::poll` | One check when slot zero refreshes the shared snapshot, including when slot zero is empty but another slot is active. Other slots return the same cached readings. `Hub::start` still does its initial poll and starts the same poll thread. | | `Source::pad` from single-pad `set_rumble` | Its existing enumeration can also observe physical input at slot zero. It shares the same timer and focus gate; a rumble command itself is not activity. The connected-slot test, motor levels, routing and multi-pad path are unchanged. Fake and non-Windows sources are unchanged. | | `host()`, `Host::default`, and `HUB` | The single shared Windows host starts with no previous reset. The existing source mutex protects the same snapshot and the new timestamp for both callers. | | `Host::pads`, `hid_slots`, `Host::xinput`, `convert`, and `playstation::{mode, slots, pads}` | Device polling, XInput precedence, HID slot assignment, and rumble ownership do not change. The idle check reads the merged snapshot without mutating it. `convert`, the HID parser, pad merging, the keyboard stand-in, reading history, and the `gamepad_state` ABI keep the same `PadState` values. | | `focused`, `scripted`, and `FALLBACK_BUTTONS` | The keyboard path calls the same helpers and keeps the same behavior. Slot zero still gets the same scripted buttons only when it has a physical pad, but only after the activity check. The stand-in keyboard pad still uses the same mapping. | | `pad_active`, `PadActivity::first_pad`, `last_reset`, and `reset_idle_timers` | New private uses only: the activity helper supplies the one Windows call site, and tests inject the clock, focus, script and reset callbacks. | ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): No in-game run; Windows unit tests only. - Before: **26 passed, 0 failed** on `63b902fe`. - After: **30 passed, 0 failed** on `16c09473`. - `cargo test` passed for the crates it touches: Yes — `cargo test -p victory-hle --lib gameinput`. - **Windows workspace check:** `cargo check --workspace --locked` passed on `16c09473e1d588e71fd38f2360a57c5961a0289b`. [Fork Windows job](https://github.com/xiepeixuan/VIctory-NVIDIA/actions/runs/46128518265/job/140928361880) - **Windows GameInput tests:** `cargo test -p victory-hle --lib gameinput` passed: **30 passed, 0 failed**, versus **26 passed, 0 failed** on [upstream `63b902fe` in the same workflow](https://github.com/xiepeixuan/VIctory-NVIDIA/actions/runs/46128518265/job/140928361673). The four new tests cover the shared one-second limit, inactive input and normalized threshold boundaries, foreground gating, and scripted buttons. - **Full Windows CI:** the [fork run](https://github.com/xiepeixuan/VIctory-NVIDIA/actions/runs/46128518117) stops at the same two Clippy errors as [upstream main](https://github.com/trustno1-coder/VIctory-NVIDIA/actions/runs/46104876336) (see #665), with no new diagnostics. The later all-features Clippy and workspace-test steps are skipped as on main. - `clippy::let_and_return` at `crates/victory-shader/src/emit/mod.rs:2768:9` - `clippy::manual_is_multiple_of` at `crates/victory-gpu/src/shadow.rs:1708:32` The fork workflow was triggered separately, but both topic jobs checked out and asserted the exact PR SHA above. No workflow changes or workspace-wide formatting are included in this PR. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for `crates/victory-hle/src/modules/gameinput.rs`. Related: #1098 (scripted input timing) and #839 (controller detection); neither resets Windows idle timers for physical controller activity. AI-assisted (Codex). Not run in the game here.
Dukestar69 commented 2026-11-28 09:20:35 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-28T09:20:35Z.

Review: APPROVED


Tested locally merged onto main (63b902f).

  • Merge & Policy: Clean merge; cargo xtask policy passed (294 files ok).
  • Tests: cargo test -p victory-hle --lib gameinput passed (30 passed; 0 failed; 1 ignored, including all 4 new idle-reset tests: scripted_buttons_are_delivered_without_resetting_idle, a_background_pad_does_not_reset_idle_or_delay_the_first_foreground_reset, pad_idle_reset_uses_normalized_xinput_thresholds, and all_physical_pad_slots_share_one_idle_reset_per_second) with 0 compiler warnings.

Well-scoped QoL fix keeping the display awake on active foreground controller input without triggering from background or scripted inputs. LGTM.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6096940882 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/921#pullrequestreview-6096940882). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-28T09:20:35Z. **Review:** APPROVED --- Tested locally merged onto `main` (`63b902f`). - **Merge & Policy**: Clean merge; `cargo xtask policy` passed (`294 files ok`). - **Tests**: `cargo test -p victory-hle --lib gameinput` passed (`30 passed; 0 failed; 1 ignored`, including all 4 new idle-reset tests: `scripted_buttons_are_delivered_without_resetting_idle`, `a_background_pad_does_not_reset_idle_or_delay_the_first_foreground_reset`, `pad_idle_reset_uses_normalized_xinput_thresholds`, and `all_physical_pad_slots_share_one_idle_reset_per_second`) with 0 compiler warnings. Well-scoped QoL fix keeping the display awake on active foreground controller input without triggering from background or scripted inputs. LGTM. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!921
No description provided.