gameinput: pads plugged in after start under Wine, and IJKL on the keyboard pad's right stick (RT-GAMEINPUT-WINE-HOTPLUG) #955

Closed
UwUCammie wants to merge 1 commit from upstream-pr/955 into main
UwUCammie commented 2026-11-24 15:41:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by UwUCammie on 2026-11-24T15:41:41Z.


Claimed in the coordination issue as: RT-GAMEINPUT-WINE-HOTPLUG

What and why

Under Wine a controller plugged in after the game has started never reaches the title. SDL's Windows backends only rescan when Windows reports a device change: the XInput and DirectInput drivers through CM_Register_Notification, HIDAPI through WM_DEVICECHANGE on its message window. Wine delivers neither for a pad that arrives later. Measured on Wine 11.22: a run started with no pad never showed one after it was connected. A pad that is unplugged does go away, because its reads fail.

The poll thread now builds a small signature once a second, without touching SDL internals:

  • which XInput slots answer XInputGetCapabilities;
  • the HID devices in GetRawInputDeviceList with usage page 1 and usage joystick, gamepad or multi-axis.

Wine refreshes both lists itself. When the signature changes, SDL's gamepad subsystem is restarted (SDL_QuitSubSystem / SDL_InitSubSystem(SDL_INIT_GAMEPAD)), the one public way to make every backend scan again. Open pads are closed first through the normal close_pad path, so the title sees a disconnect and a reconnect, and only when the hardware changed. LEONIDA_GAMEINPUT_HOTPLUG=0 turns it off.

The keyboard pad also gets I/J/K/L as the right stick at full deflection, over the mouse. The retail title's legal terms screen scrolls each policy text on the right stick, and its checkboxes only count once a text has been scrolled to the end. Without a pad or a working mouse path (headless runs), that screen could not be passed. docs/gameinput.md lists both.

Tested

  • gameinput_test.exe on this branch (clang-cl + xwin cross build, run under Wine 11.22): 364 checks, 0 failures.
  • The same change on a local integration branch, retail 1.0.2.1 under Wine with an 8BitDo pad (XInput, 2dc8:301d). At start SDL listed the one pad three times (as an Xbox 360, an Xbox One S and an XInput controller). After the first signature change (Wine finishing its device list) the restart left exactly one pad plus the keyboard pad, and input kept working. With K held, the terms screen scrolled to the end of each text and its Confirm button enabled.
  • Not tested: physically plugging a pad in mid-run on this machine (I ran remotely). The restart path is the same one the first signature change exercised.

GPUs tested: n/a (input only; the machine is an AMD Radeon RX 7900 XT, RADV, Mesa 26.3.1, CachyOS, Wine 11.22)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5475394807 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/955). Originally posted by [UwUCammie](https://github.com/UwUCammie) on 2026-11-24T15:41:41Z. --- Claimed in the coordination issue as: RT-GAMEINPUT-WINE-HOTPLUG ### What and why Under Wine a controller plugged in after the game has started never reaches the title. SDL's Windows backends only rescan when Windows reports a device change: the XInput and DirectInput drivers through `CM_Register_Notification`, HIDAPI through `WM_DEVICECHANGE` on its message window. Wine delivers neither for a pad that arrives later. Measured on Wine 11.22: a run started with no pad never showed one after it was connected. A pad that is unplugged does go away, because its reads fail. The poll thread now builds a small signature once a second, without touching SDL internals: - which XInput slots answer `XInputGetCapabilities`; - the HID devices in `GetRawInputDeviceList` with usage page 1 and usage joystick, gamepad or multi-axis. Wine refreshes both lists itself. When the signature changes, SDL's gamepad subsystem is restarted (`SDL_QuitSubSystem` / `SDL_InitSubSystem(SDL_INIT_GAMEPAD)`), the one public way to make every backend scan again. Open pads are closed first through the normal `close_pad` path, so the title sees a disconnect and a reconnect, and only when the hardware changed. `LEONIDA_GAMEINPUT_HOTPLUG=0` turns it off. The keyboard pad also gets I/J/K/L as the right stick at full deflection, over the mouse. The retail title's legal terms screen scrolls each policy text on the right stick, and its checkboxes only count once a text has been scrolled to the end. Without a pad or a working mouse path (headless runs), that screen could not be passed. `docs/gameinput.md` lists both. ### Tested - `gameinput_test.exe` on this branch (clang-cl + xwin cross build, run under Wine 11.22): `364 checks, 0 failures`. - The same change on a local integration branch, retail 1.0.2.1 under Wine with an 8BitDo pad (XInput, `2dc8:301d`). At start SDL listed the one pad three times (as an Xbox 360, an Xbox One S and an XInput controller). After the first signature change (Wine finishing its device list) the restart left exactly one pad plus the keyboard pad, and input kept working. With K held, the terms screen scrolled to the end of each text and its Confirm button enabled. - Not tested: physically plugging a pad in mid-run on this machine (I ran remotely). The restart path is the same one the first signature change exercised. GPUs tested: n/a (input only; the machine is an AMD Radeon RX 7900 XT, RADV, Mesa 26.3.1, CachyOS, Wine 11.22) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change)
PierreEbele commented 2026-11-25 21:58:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T21:58:06Z.


Reviewed 3f59ed6: docs tests pass on the PR tree (test_docs_env_vars, test_docs_table_rows); the shim itself cannot build here (MSVC/Windows + SDL3), so the Wine hotplug path was only reviewed statically — keyboard-pad reattach after the SDL restart, the failed-restart state and the poll-mu serialization all check out, and LEONIDA_GAMEINPUT_HOTPLUG is documented. One load-bearing assumption to keep in mind: the controller signature uses raw-input hDevice handles, so it relies on Wine keeping them stable across its list refreshes (measured by the author; recommend a Wine + pad sanity run before relying on it). No findings.
AI-assisted review.

Recommendation: Merge

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7175768529 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/955#issuecomment-7175768529). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T21:58:06Z. --- Reviewed 3f59ed6: docs tests pass on the PR tree (test_docs_env_vars, test_docs_table_rows); the shim itself cannot build here (MSVC/Windows + SDL3), so the Wine hotplug path was only reviewed statically — keyboard-pad reattach after the SDL restart, the failed-restart state and the poll-mu serialization all check out, and `LEONIDA_GAMEINPUT_HOTPLUG` is documented. One load-bearing assumption to keep in mind: the controller signature uses raw-input `hDevice` handles, so it relies on Wine keeping them stable across its list refreshes (measured by the author; recommend a Wine + pad sanity run before relying on it). No findings. AI-assisted review. **Recommendation:** Merge
MoonEyes commented 2026-11-27 23:20:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T23:20:30Z.


Hi @UwUCammie, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/shims/gameinput.cpp), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7230065147 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/955#issuecomment-7230065147). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T23:20:30Z. --- Hi @UwUCammie, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/shims/gameinput.cpp`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
UwUCammie commented 2026-11-27 23:59:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by UwUCammie on 2026-11-27T23:59:43Z.


Rebased on current main (the branch is now at 0207820dc), it merges cleanly again.

Two things changed with the rebase:

  • detach_keyboard_pad() is gone on main, so the restart now switches the keyboard pad off through g_keyboard.update(false, backend) and the next poll attaches it again.
  • gameinput_test sets LEONIDA_GAMEINPUT_HOTPLUG=0. Under Wine a real controller on the test machine is reported a few seconds after a fresh prefix starts, the watch then restarts SDL's gamepad subsystem under the virtual pads and the history checks fail. That was about 1 run in 10 here (8 failures, with controllers changed (1 -> 2 devices); rescanning in the output); with the variable set it passed 25 runs of 25.

Built gameinput_test with clang-cl against the xwin SDK and ran it under Wine 11.22: 364 checks, 0 failures. Still not tested: plugging a pad in by hand mid-run.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7230561744 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/955#issuecomment-7230561744). Originally posted by [UwUCammie](https://github.com/UwUCammie) on 2026-11-27T23:59:43Z. --- Rebased on current `main` (the branch is now at 0207820dc), it merges cleanly again. Two things changed with the rebase: - `detach_keyboard_pad()` is gone on `main`, so the restart now switches the keyboard pad off through `g_keyboard.update(false, backend)` and the next poll attaches it again. - `gameinput_test` sets `LEONIDA_GAMEINPUT_HOTPLUG=0`. Under Wine a real controller on the test machine is reported a few seconds after a fresh prefix starts, the watch then restarts SDL's gamepad subsystem under the virtual pads and the history checks fail. That was about 1 run in 10 here (8 failures, with `controllers changed (1 -> 2 devices); rescanning` in the output); with the variable set it passed 25 runs of 25. Built `gameinput_test` with clang-cl against the xwin SDK and ran it under Wine 11.22: 364 checks, 0 failures. Still not tested: plugging a pad in by hand mid-run.
OreoFR commented 2026-11-28 21:45:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:45:33Z.


Verified by OreoFR

  • Base: main c1ecf04ed + PR head 0207820dc
  • Test: ctest -R ^(gameinput|gameinput_script)$
  • Red on main: OK (first run: 1 flaky haptics failure "both motors resume for the second pulse", passes on rerun; the test only sets LEONIDA_GAMEINPUT_HOTPLUG=0)
  • Green with the PR: OK
  • Verdict: NO RED (hot-plug under Wine, not exercised here)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246250465 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/955#issuecomment-7246250465). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:45:33Z. --- **Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `0207820dc` - Test: `ctest -R ^(gameinput|gameinput_script)$` - Red on main: OK (first run: 1 flaky haptics failure "both motors resume for the second pulse", passes on rerun; the test only sets LEONIDA_GAMEINPUT_HOTPLUG=0) - Green with the PR: OK - Verdict: NO RED (hot-plug under Wine, not exercised here) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
merzleckeier commented 2026-11-28 22:20:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-28T22:20:23Z.


Independent Wine 11.22 check on CachyOS. I built Windows x64 Release with clang-cl/xwin and SDL 3.4.20, comparing current main c7753ed98 with PR head 0207820dc merged on top. Both passed gameinput_test (389/389) and gameinput_test --input-script (12/12).

I also ran gameinput_probe with a Linux uinput Xbox 360 controller and logged the XInput capability mask in the same process. Both builds enumerate the device when it is already present at startup. When the probe started with no device, two attach/detach cycles left the XInput mask at zero on the PR build and there was no GameInput connect callback or rescan. With a device present at startup, the mask stayed at one during detach/re-attach. This fixture did not produce the Windows-side signature change this PR watches, so hotplug remains unverified in this setup.

Synthetic input only. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246666154 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/955#issuecomment-7246666154). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-28T22:20:23Z. --- Independent Wine 11.22 check on CachyOS. I built Windows x64 Release with clang-cl/xwin and SDL 3.4.20, comparing current main `c7753ed98` with PR head `0207820dc` merged on top. Both passed `gameinput_test` (389/389) and `gameinput_test --input-script` (12/12). I also ran `gameinput_probe` with a Linux uinput Xbox 360 controller and logged the XInput capability mask in the same process. Both builds enumerate the device when it is already present at startup. When the probe started with no device, two attach/detach cycles left the XInput mask at zero on the PR build and there was no GameInput connect callback or rescan. With a device present at startup, the mask stayed at one during detach/re-attach. This fixture did not produce the Windows-side signature change this PR watches, so hotplug remains unverified in this setup. Synthetic input only. AI-assisted.
zmasi commented 2026-11-29 01:00:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-29T01:00:05Z.


Windows 11 + MSVC 19.44 + SDL3 Verification — PASS (0207820dc7)

Verified 0207820dc7 (RT-GAMEINPUT-WINE-HOTPLUG) merged onto origin/main (e66c65b950 / 16f5053047, 0 conflicts, plus a 5-way combined merge alongside #1146, #988, #2544, and #1738) on native Windows 11 (10.0.26200.9974) with MSVC 19.44.35228 and static SDL3 (3.4.20).

Checks Run

  • gameinput_test.exe full suite (/std:c++20 /O2 /MD /EHsc /W4 /permissive- /utf-8):
    • Compiled cleanly (0 warnings in gameinput.cpp / gameinput_test.cpp) and passed 389 checks, 0 failures (rc=0).
  • Red -> Green IJKL right-stick probe:
    • Exercised I (up +1.0), K (down -1.0), J (left -1.0), L (right +1.0), I+L (+0.7071, +0.7071), and K+J (-0.7071, -0.7071) through fake_key_down + rt::gameinput::poll(): Red (rc=1, right stick remained 0 on origin/main) -> Green (rc=0 on #955 + origin/main).
  • Documentation & environment-variable gates:
    • tests/test_docs_env_vars.py, tests/test_docs_table_rows.py, and tests/test_docs_encoding.py all passed (rc=0).

Non-Blocking Notes

  1. Mouse-decay tail & opposite-key cancellation on IJKL (runtime/shims/gameinput.cpp): Because IJKL assigns directly into g_keyboard.right_x / g_keyboard.right_y (the mouse delta integrator), releasing I/J/K/L (or pressing opposite keys such as I+K after holding I, where rx == 0 && ry == 0 skips the if (rx || ry) branch) lets the stick decay back to 0 over several polls via kMouseDecayNum / kMouseDecayDen rather than centering on the very next poll like WASD, and gameinput_test.cpp does not yet include dedicated IJKL assertions.
  2. Transient ERROR_INSUFFICIENT_BUFFER in controller_signature() (runtime/shims/gameinput.cpp): If any raw-input device arrives between the sizing GetRawInputDeviceList(nullptr, &count, ...) call and GetRawInputDeviceList(list.data(), &count, ...), got == UINT(-1) skips all HID entries for that tick (sig == {slots}), which can trigger a spurious sig != last gamepad subsystem restart on the failed tick and a second restart 1 s later when GetRawInputDeviceList succeeds.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248492531 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/955#issuecomment-7248492531). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-29T01:00:05Z. --- ## Windows 11 + MSVC `19.44` + SDL3 Verification — PASS (`0207820dc7`) Verified `0207820dc7` (`RT-GAMEINPUT-WINE-HOTPLUG`) merged onto `origin/main` (`e66c65b950` / `16f5053047`, `0` conflicts, plus a 5-way combined merge alongside `#1146`, `#988`, `#2544`, and `#1738`) on native Windows 11 (`10.0.26200.9974`) with MSVC `19.44.35228` and static `SDL3` (`3.4.20`). ### Checks Run - **`gameinput_test.exe` full suite** (`/std:c++20 /O2 /MD /EHsc /W4 /permissive- /utf-8`): - Compiled cleanly (`0` warnings in `gameinput.cpp` / `gameinput_test.cpp`) and passed **`389 checks, 0 failures`** (`rc=0`). - **Red -> Green IJKL right-stick probe**: - Exercised `I` (up `+1.0`), `K` (down `-1.0`), `J` (left `-1.0`), `L` (right `+1.0`), `I+L` (`+0.7071, +0.7071`), and `K+J` (`-0.7071, -0.7071`) through `fake_key_down` + `rt::gameinput::poll()`: **Red** (`rc=1`, right stick remained `0` on `origin/main`) -> **Green** (`rc=0` on `#955 + origin/main`). - **Documentation & environment-variable gates**: - `tests/test_docs_env_vars.py`, `tests/test_docs_table_rows.py`, and `tests/test_docs_encoding.py` all passed (`rc=0`). ### Non-Blocking Notes 1. **Mouse-decay tail & opposite-key cancellation on IJKL (`runtime/shims/gameinput.cpp`)**: Because IJKL assigns directly into `g_keyboard.right_x` / `g_keyboard.right_y` (the mouse delta integrator), releasing `I`/`J`/`K`/`L` (or pressing opposite keys such as `I+K` after holding `I`, where `rx == 0 && ry == 0` skips the `if (rx || ry)` branch) lets the stick decay back to `0` over several polls via `kMouseDecayNum / kMouseDecayDen` rather than centering on the very next poll like `WASD`, and `gameinput_test.cpp` does not yet include dedicated IJKL assertions. 2. **Transient `ERROR_INSUFFICIENT_BUFFER` in `controller_signature()` (`runtime/shims/gameinput.cpp`)**: If any raw-input device arrives between the sizing `GetRawInputDeviceList(nullptr, &count, ...)` call and `GetRawInputDeviceList(list.data(), &count, ...)`, `got == UINT(-1)` skips all HID entries for that tick (`sig == {slots}`), which can trigger a spurious `sig != last` gamepad subsystem restart on the failed tick and a second restart 1 s later when `GetRawInputDeviceList` succeeds. AI-assisted.
aslan2142 commented 2026-12-01 17:21:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T17:21:43Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7319176436 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/955#issuecomment-7319176436). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T17:21:43Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

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
ProjectLeonida/mandy!955
No description provided.