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

Open
github-bot wants to merge 1 commit from github-bot/gh-955 into main AGit
Owner

@⁠UwUCammie on GitHub · 2026-11-24 15:41 UTC · original
UwUCammie:pr/gameinput-wine-hotplug → main · +100 −1 · 2 files · 1 commits · open

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)
**@⁠UwUCammie** on GitHub · 2026-11-24 15:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/955) `UwUCammie:pr/gameinput-wine-hotplug` → `main` · +100 −1 · 2 files · 1 commits · open 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)
SDL's Windows backends rescan for pads only on a Windows device notification
(CM_Register_Notification for XInput/DirectInput, WM_DEVICECHANGE for HIDAPI).
Wine does not deliver one for a pad plugged in after start, so such a pad never
appeared, while an unplugged one did go (as a failed read). The poll thread now
compares the XInput slots in use and the HID joysticks/gamepads in the raw-input
device list (which Wine refreshes itself) once a second, and restarts SDL's
gamepad subsystem when they change; open pads come back as reconnections.
LEONIDA_GAMEINPUT_HOTPLUG=0 turns it off.

The retail title's terms screen scrolls its text on the right stick and accepts
the boxes only once each text has been scrolled to its end. IJKL push the
keyboard pad's right stick to its edge (K is down), over the mouse, so the
screen can be passed without a pad or a mouse.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:30:19 +00:00
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 21:58 UTC · original

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

**@⁠PierreEbele** on GitHub · 2026-11-25 21:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/955#issuecomment-7175768529) 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
This pull request has changes conflicting with the target branch.
  • runtime/shims/gameinput.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/955/head:github-bot/gh-955'
git switch 'github-bot/gh-955'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-955'
git switch 'github-bot/gh-955'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-955'
git switch 'github-bot/gh-955'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-955'
git switch 'main'
git merge --squash 'github-bot/gh-955'
git switch 'main'
git merge --ff-only 'github-bot/gh-955'
git switch 'main'
git merge 'github-bot/gh-955'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.