GameInput: XCL_INPUT_LOCK=1 gives the title the scripted presses only #3739

Open
vasanex wants to merge 1 commit from upstream-pr/3739 into main
vasanex commented 2026-12-02 23:04:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by vasanex on 2026-12-02T23:04:19Z.


A scripted run (XCL_PRESS_AT / XCL_PRESS_A_AT) also gets whatever is pressed at the PC: the title's window takes the focus when it opens, and XCL reads the keyboard while it has it. In two unattended world runs for the title run: line of #3041, keys pressed at the PC during the run (Tab, and Shift or Ctrl) arrived in the title as View and a stick click. XCL_INPUT_LOCK=1 makes the title see the scripted presses only. Without the variable nothing changes.

What is in it

  • crates/xcl/src/hle/gameinput.rs: input_locked(); poll reads no controller, keyboard or mouse under the lock (host_pad), the scripted presses still arrive. log_input_lock() logs the lock at startup with the number of scripted presses, and warns when there are none (the title then gets no input at all). press_script() is the press list scripted() already parsed, moved out so the startup line can count it.
  • crates/xcl/src/hle/kbm.rs: under the lock the window does not take the mouse and the keyboard (attach): no raw mouse input, no held cursor, and no "keyboard and mouse play as the gamepad" line next to the lock's.
  • crates/xcl/src/hle/mod.rs: calls log_input_lock() where the registry is built, next to the offline switch.
  • crates/xcl/src/hle/d3d12x/present.rs: the window's title says | User input locked after the frame rate and before the compile counts (title_text).
  • README.md: one bullet under Controls.
  • Tests: a_locked_input_reads_no_controller_and_keeps_the_scripted_presses (gameinput), a_locked_input_leaves_the_mouse_and_the_keyboard_to_the_pc (kbm), and the title cases in the_title_counts_dxc_compiles_and_driver_builds.

Tested

  • RTX 3080 10 GB (driver 621.40), AMD Ryzen 9 7950X, Windows 11 26200, Rust 1.100.0, debug for the suite, release for the title runs.
  • cargo test --workspace -- --test-threads=4 on the head: 3007 passed, 0 failed, 52 ignored; 25 SKIPPED lines (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache), the same tests as on main.
  • The regression runs below: 60 s of the retail title, release, default settings plus XCL_NETWORK=0 on both sides.
  • Two 60 s runs of the retail title with XCL_INPUT_LOCK=1, on the release build of the head before the kbm.rs part (67ea7859), not repeated on this one:
    • without scripted presses: the log has the lock line with "(0 scripted)" and the warning; the window titles sampled once a second read XCL – <name> | N FPS | User input locked and XCL – <name> | N FPS | User input locked | compiling shaders: DXC … (1698 frames, no device removal, no crash).
    • with XCL_PRESS_A_AT=20,24: the lock line with "(2 scripted)", no warning, and A arrives in the title ("gamepad buttons 0x4 pressed for the first time" at 20.0 s; 1411 frames, no device removal, no crash).
  • The window's first title, before the first frame-rate update, is the bare name without the lock part.

Regression run

main 5ad98adb:

xcl-smoke v1
commit: 5ad98adbc360225ac8a57ad9661e16fe8df9d8dd
gpu: NVIDIA GeForce RTX 3080
title: aaa95fa3
seconds: 60
exit: 0x0
frames shown: 1696 (PresentX 1696)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 18206 MB

this PR's head:

xcl-smoke v1
commit: 1cea7ef3d441b99a82a35702ea2e35c6ba4f1f50
gpu: NVIDIA GeForce RTX 3080
title: aaa95fa3
seconds: 60
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17998 MB

Not tested

  • AMD and Intel GPUs (the change is input and window text only); a PlayStation controller; titles other than the retail one.
  • The kbm.rs part in a title run: that the cursor stays free and the gamepad line is gone under the lock is read from the code and covered by the unit test of the condition only.
  • Real input under the lock: nobody pressed a key or a controller button during the two lock runs, so that such input stays out is covered by the unit test only.
  • Overlaps: #893 (scripted stick) touches the same lines of gameinput.rs and will need a rebase after whichever merges first; #2984 documents XCL_PRESS_AT in the README at another place.

AI use

  • Claude Code with Claude Fable 5.2 wrote the change, the tests and this description, and ran the tests and title runs.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5616294342 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3739). Originally posted by [vasanex](https://github.com/vasanex) on 2026-12-02T23:04:19Z. --- A scripted run (`XCL_PRESS_AT` / `XCL_PRESS_A_AT`) also gets whatever is pressed at the PC: the title's window takes the focus when it opens, and XCL reads the keyboard while it has it. In two unattended world runs for the `title run:` line of #3041, keys pressed at the PC during the run (Tab, and Shift or Ctrl) arrived in the title as View and a stick click. `XCL_INPUT_LOCK=1` makes the title see the scripted presses only. Without the variable nothing changes. **What is in it** - `crates/xcl/src/hle/gameinput.rs`: `input_locked()`; `poll` reads no controller, keyboard or mouse under the lock (`host_pad`), the scripted presses still arrive. `log_input_lock()` logs the lock at startup with the number of scripted presses, and warns when there are none (the title then gets no input at all). `press_script()` is the press list `scripted()` already parsed, moved out so the startup line can count it. - `crates/xcl/src/hle/kbm.rs`: under the lock the window does not take the mouse and the keyboard (`attach`): no raw mouse input, no held cursor, and no "keyboard and mouse play as the gamepad" line next to the lock's. - `crates/xcl/src/hle/mod.rs`: calls `log_input_lock()` where the registry is built, next to the offline switch. - `crates/xcl/src/hle/d3d12x/present.rs`: the window's title says `| User input locked` after the frame rate and before the compile counts (`title_text`). - `README.md`: one bullet under Controls. - Tests: `a_locked_input_reads_no_controller_and_keeps_the_scripted_presses` (gameinput), `a_locked_input_leaves_the_mouse_and_the_keyboard_to_the_pc` (kbm), and the title cases in `the_title_counts_dxc_compiles_and_driver_builds`. **Tested** - RTX 3080 10 GB (driver 621.40), AMD Ryzen 9 7950X, Windows 11 26200, Rust 1.100.0, debug for the suite, release for the title runs. - `cargo test --workspace -- --test-threads=4` on the head: 3007 passed, 0 failed, 52 ignored; 25 `SKIPPED` lines (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache), the same tests as on `main`. - The regression runs below: 60 s of the retail title, release, default settings plus `XCL_NETWORK=0` on both sides. - Two 60 s runs of the retail title with `XCL_INPUT_LOCK=1`, on the release build of the head before the `kbm.rs` part (`67ea7859`), not repeated on this one: - without scripted presses: the log has the lock line with "(0 scripted)" and the warning; the window titles sampled once a second read `XCL – <name> | N FPS | User input locked` and `XCL – <name> | N FPS | User input locked | compiling shaders: DXC …` (1698 frames, no device removal, no crash). - with `XCL_PRESS_A_AT=20,24`: the lock line with "(2 scripted)", no warning, and A arrives in the title ("gamepad buttons 0x4 pressed for the first time" at 20.0 s; 1411 frames, no device removal, no crash). - The window's first title, before the first frame-rate update, is the bare name without the lock part. **Regression run** main `5ad98adb`: ``` xcl-smoke v1 commit: 5ad98adbc360225ac8a57ad9661e16fe8df9d8dd gpu: NVIDIA GeForce RTX 3080 title: aaa95fa3 seconds: 60 exit: 0x0 frames shown: 1696 (PresentX 1696) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 18206 MB ``` this PR's head: ``` xcl-smoke v1 commit: 1cea7ef3d441b99a82a35702ea2e35c6ba4f1f50 gpu: NVIDIA GeForce RTX 3080 title: aaa95fa3 seconds: 60 exit: 0x0 frames shown: 1695 (PresentX 1695) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17998 MB ``` **Not tested** - AMD and Intel GPUs (the change is input and window text only); a PlayStation controller; titles other than the retail one. - The `kbm.rs` part in a title run: that the cursor stays free and the gamepad line is gone under the lock is read from the code and covered by the unit test of the condition only. - Real input under the lock: nobody pressed a key or a controller button during the two lock runs, so that such input stays out is covered by the unit test only. - Overlaps: #893 (scripted stick) touches the same lines of `gameinput.rs` and will need a rebase after whichever merges first; #2984 documents `XCL_PRESS_AT` in the README at another place. **AI use** - Claude Code with Claude Fable 5.2 wrote the change, the tests and this description, and ran the tests and title runs. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Foniass commented 2026-12-02 23:15:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T23:15:50Z.


Review of 67ea7859 (code reading only, not a merge-check) · 1 medium

In short: The PR adds XCL_INPUT_LOCK=1, which stops poll from reading the PC's controller, keyboard and mouse, so a scripted run gets only the XCL_PRESS_AT / XCL_PRESS_A_AT presses. It also logs the lock at startup and marks it in the window title. The input gate is right and opt-in, and nothing blocks the PR. One medium point: under the lock, the keyboard/mouse window hook is still attached.

Medium

  1. The lock still attaches keyboard and mouse to the window.

    • poll skips kbm::apply, but kbm::attach still runs when the window opens and after preparation (present.rs ~887, present/preparation.rs ~145). It has no lock check (kbm.rs ~496).
    • So it registers raw mouse input and logs "keyboard and mouse play as the gamepad (…)" next to the new "not read" line.
    • kbm::on_message then hides the cursor and clips it to the window centre each time the window is activated or clicked.
    • Nothing reaches the title, but the log contradicts itself, and someone using the PC loses the mouse while the run has focus, which is the case the lock is for.

    Fix: return early from kbm::attach when gameinput::input_locked() is set.

Checked and fine
  • Without the variable, input_locked() is false, host_pad(false, …) gives the same xinput_pad().or_else(playstation::pad).unwrap_or_default() as before, and !locked && kbm::enabled() reduces to the old gate.
  • Under the lock, the XInput, PlayStation, keyboard and kbm::apply reads are all skipped. scripted() is still merged into s.buttons, and the first-press log still sees scripted buttons.
  • press_script() is the same OnceLock parse, moved out unchanged.
  • log_input_lock() logs nothing unless the lock is on, and build runs it once.
  • With the lock off, title_text gives exactly the old string.
  • The test checks the controller closure is never called under the lock, that scripted presses survive, and both startup lines.
  • 83+/7-, README updated. #893 and #2449 touch the press script but add no lock.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7361770628 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3739#issuecomment-7361770628). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T23:15:50Z. --- **Review** of `67ea7859` (code reading only, not a merge-check) · 1 medium **In short:** The PR adds `XCL_INPUT_LOCK=1`, which stops `poll` from reading the PC's controller, keyboard and mouse, so a scripted run gets only the `XCL_PRESS_AT` / `XCL_PRESS_A_AT` presses. It also logs the lock at startup and marks it in the window title. The input gate is right and opt-in, and nothing blocks the PR. One medium point: under the lock, the keyboard/mouse window hook is still attached. #### Medium 1. **The lock still attaches keyboard and mouse to the window.** - `poll` skips `kbm::apply`, but `kbm::attach` still runs when the window opens and after preparation (`present.rs` ~887, `present/preparation.rs` ~145). It has no lock check (`kbm.rs` ~496). - So it registers raw mouse input and logs "keyboard and mouse play as the gamepad (…)" next to the new "not read" line. - `kbm::on_message` then hides the cursor and clips it to the window centre each time the window is activated or clicked. - Nothing reaches the title, but the log contradicts itself, and someone using the PC loses the mouse while the run has focus, which is the case the lock is for. Fix: return early from `kbm::attach` when `gameinput::input_locked()` is set. <details><summary>Checked and fine</summary> - Without the variable, `input_locked()` is false, `host_pad(false, …)` gives the same `xinput_pad().or_else(playstation::pad).unwrap_or_default()` as before, and `!locked && kbm::enabled()` reduces to the old gate. - Under the lock, the XInput, PlayStation, keyboard and `kbm::apply` reads are all skipped. `scripted()` is still merged into `s.buttons`, and the first-press log still sees scripted buttons. - `press_script()` is the same `OnceLock` parse, moved out unchanged. - `log_input_lock()` logs nothing unless the lock is on, and `build` runs it once. - With the lock off, `title_text` gives exactly the old string. - The test checks the controller closure is never called under the lock, that scripted presses survive, and both startup lines. - 83+/7-, README updated. #893 and #2449 touch the press script but add no lock. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
vasanex commented 2026-12-02 23:45:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by vasanex on 2026-12-02T23:45:17Z.


@Foniass thanks, right: kbm::attach had no lock check, and keyboard and mouse are on by default, so under the lock the window still registered raw mouse input, logged the gamepad line next to "not read", and held the cursor on activation.

Fixed in 1cea7ef3: attach returns under the lock, so the window is never recorded for kbm and on_message leaves the cursor alone. New test a_locked_input_leaves_the_mouse_and_the_keyboard_to_the_pc covers the condition.

Suite on 1cea7ef3: 3007 passed, 0 failed, 52 ignored, 25 SKIPPED (the same as on main); smoke in the description.

Not tested: the cursor in a title run under the lock (the two lock runs in the description are from the head before this part), and AMD.

Claude Code with Claude Fable 5.2 made the change, ran the tests and wrote this comment.

<!-- greyfinch-sync:ivall/xcl:comment:7362384271 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3739#issuecomment-7362384271). Originally posted by [vasanex](https://github.com/vasanex) on 2026-12-02T23:45:17Z. --- @Foniass thanks, right: `kbm::attach` had no lock check, and keyboard and mouse are on by default, so under the lock the window still registered raw mouse input, logged the gamepad line next to "not read", and held the cursor on activation. Fixed in `1cea7ef3`: `attach` returns under the lock, so the window is never recorded for `kbm` and `on_message` leaves the cursor alone. New test `a_locked_input_leaves_the_mouse_and_the_keyboard_to_the_pc` covers the condition. Suite on `1cea7ef3`: 3007 passed, 0 failed, 52 ignored, 25 SKIPPED (the same as on main); smoke in the description. Not tested: the cursor in a title run under the lock (the two lock runs in the description are from the head before this part), and AMD. Claude Code with Claude Fable 5.2 made the change, ran the tests and wrote this comment.
Foniass commented 2026-12-02 23:45:59 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T23:45:59Z.


Follow-up review of 1cea7ef3, since 67ea7859 (code reading only, not a merge-check) · no new findings

In short: This push fixes the point from my last review. kbm::attach now returns early under XCL_INPUT_LOCK=1, so the window registers no raw mouse input, logs no "keyboard and mouse play" line, and never holds the cursor. A test covers the decision. Nothing blocks it.

Checked and fine
  • Earlier finding fixed: the lock still attached keyboard and mouse to the window. attach checks attaches(enabled(), gameinput::input_locked()) before it stores WINDOW. on_message returns at once when WINDOW is not this window (kbm.rs ~569), so the cursor-hold path on activate and click never runs.
  • a_locked_input_leaves_the_mouse_and_the_keyboard_to_the_pc covers all four combinations of enabled and locked.
  • Without the lock, attaches(enabled, false) is enabled, as before. The commit message says so.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7362399026 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3739#issuecomment-7362399026). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T23:45:59Z. --- **Follow-up review** of `1cea7ef3`, since `67ea7859` (code reading only, not a merge-check) · no new findings **In short:** This push fixes the point from my last review. `kbm::attach` now returns early under `XCL_INPUT_LOCK=1`, so the window registers no raw mouse input, logs no "keyboard and mouse play" line, and never holds the cursor. A test covers the decision. Nothing blocks it. <details><summary>Checked and fine</summary> - Earlier finding fixed: the lock still attached keyboard and mouse to the window. `attach` checks `attaches(enabled(), gameinput::input_locked())` before it stores `WINDOW`. `on_message` returns at once when `WINDOW` is not this window (`kbm.rs` ~569), so the cursor-hold path on activate and click never runs. - `a_locked_input_leaves_the_mouse_and_the_keyboard_to_the_pc` covers all four combinations of enabled and locked. - Without the lock, `attaches(enabled, false)` is `enabled`, as before. The commit message says so. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3739:upstream-pr/3739'
git switch 'upstream-pr/3739'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3739'
git switch 'upstream-pr/3739'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3739'
git switch 'upstream-pr/3739'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3739'
git switch 'main'
git merge --squash 'upstream-pr/3739'
git switch 'main'
git merge --ff-only 'upstream-pr/3739'
git switch 'main'
git merge 'upstream-pr/3739'
git push origin 'main'
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
xcl-dev/xcl!3739
No description provided.