Skip to content

feat(input): plug the controller's gamepads into Windows and Linux hosts - #136

Merged
sqlpxc merged 3 commits into
mainfrom
feat/gamepads
Dec 2, 2026
Merged

sqlpxc merged 3 commits into
mainfrom
feat/gamepads

Conversation

@sqlpxc

@sqlpxc sqlpxc commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Gamepads connected to the controller are plugged into the host as wired Xbox 360 controllers through airhand-dock 0.2.0, so games see a real USB gamepad (XInput, DirectInput, Windows.Gaming.Input, SDL, Steam, evdev), and their rumble comes back to the controller's gamepad.

Hosts

Host How
Windows usbip-win2 (installed once, no admin rights afterwards; works in the system service and on the lock screen)
Linux vhci-hcd as root, otherwise uinput (needs access to /dev/uinput; Steam's rules grant it, docs have a udev rule)
macOS, Android, iOS not supported; macOS says so, phones say nothing
  • Pads belong to the controller (its end-to-end handshake identity), not to a session: a reconnect within 30 s keeps them, so games don't see the pad disconnect; a normal disconnect unplugs them at once.
  • Plugging and unplugging run on one worker thread (client/src-tauri/src/host/gamepad.rs); the host tells each controller whether it can take gamepads and why not (HostMsg::Gamepad), re-checking while a driver or permission is missing (installing usbip-win2 needs no restart).

Protocol (no version bump: older peers skip the new events and messages)

  • InputEvent::Gamepad carries the whole XINPUT_GAMEPAD state of one pad, GamepadRemoved unplugs it; both ride the control lane with the other input. Adjacent states of one pad with the same buttons coalesce (protocol, controller queue, console, Android, iOS), never across a button change. Stale input becomes "release all", which also puts every remote pad back to rest. A pad held still sends nothing new, so the controller service resends every pad that isn't at rest every 500 ms, and when it drops queued input itself, its "release all" carries the current state of every pad (and the removals it dropped); the host still carries out a late GamepadRemoved. A UI puts a session's pads back to rest before it stops handing it the gamepads (Android also when its window loses focus).
  • HostMsg::Gamepad { state, detail }, HostMsg::Rumble { pad, large, small } (latest value per pad on the host's outbox).
  • Golden bytes in tests/v10.rs; JSON samples in protocol.json (checked by Rust, TypeScript, Kotlin and Swift).

Controllers

  • Console (desktop and web): one Gamepad API hub for the page (client/src/lib/gamepad.ts) hands the pads to the session you're viewing; toolbar gamepad menu with the switch, the reason when the host can't, and the pads; rumble through vibrationActuator.
  • Android: phones (menu → Keyboard & input → Gamepads) and TVs (Select + Start opens the menu); rumble through the input device's vibrators.
  • iOS: GameController capture, CoreHaptics rumble on the pad's handles, menu → Gamepads.

Tests

  • cargo test (root), cargo clippy --all-targets -D warnings, client/src-tauri cargo test --lib + clippy (Windows), npm test + npm run build, ./gradlew testDebugUnitTest.
  • Host module on Linux (WSL2): plugs_a_virtual_gamepad passes through vhci-hcd (root) and uinput (non-root).
  • Not run here: the iOS build (no Xcode on this machine), a Windows host with usbip-win2 installed (cargo test --lib plugs_a_virtual_gamepad -- --ignored --nocapture), and a full Linux desktop build (WSL lacked libpipewire dev headers).

Gamepads connected to the controller are plugged into the host as wired
Xbox 360 controllers through airhand-dock 0.2.0 (usbip-win2 on Windows;
vhci-hcd as root or uinput otherwise on Linux), so every game sees a real
gamepad, and the game's rumble comes back to the controller's gamepad.

- proto: InputEvent::Gamepad (the whole XINPUT_GAMEPAD state of one pad) and
  GamepadRemoved; HostMsg::Gamepad (whether the host can take gamepads, and
  why not) and HostMsg::Rumble. Adjacent states of one pad with the same
  buttons coalesce, never across a button change.
- link: rumble keeps the latest value per pad on the host's outbox; the
  controller queue coalesces gamepad states; SessionEvent::Gamepad / Rumble.
- desktop host: virtual pads belong to the controller (its handshake
  identity), survive a reconnect within 30 s and are unplugged at once on a
  normal disconnect; plugging runs on one worker thread; status is probed at
  session start and while a driver or permission is missing.
- console (desktop and web): Gamepad API hub, toolbar menu, rumble through
  vibrationActuator, a notice when the host can't take gamepads.
- Android (phones and TVs) and iOS: gamepad capture, rumble, menu entries.
- docs, protocol fixtures and tests on every side.
…-screen gamepad to game keys

The Windows installer now carries usbip-win2, so hosts don't have to download
the gamepad driver themselves, and phone game keys can be an on-screen Xbox 360
controller that is plugged into the computer like a connected gamepad.

- installer: before bundling, `tauri build` runs scripts/fetch-usbip-win2.mjs
  (beforeBundleCommand in tauri.windows.conf.json), which downloads the pinned
  USBip-0.9.8.1-x64.exe and checks its SHA-256 (CI fails without it, local
  builds only warn and bundle without it). hooks.nsh asks once per interactive
  install when usbip-win2 isn't installed (x64 Windows 10 1903+, both install
  modes; UAC when installed just for you) and runs it very silently with
  /COMPONENTS=main,client /NORESTART. Silent and passive installs (updates)
  don't ask; /USBIP installs it without asking. An existing installation is
  left alone and uninstalling Airhand keeps it; its BSD license goes into
  usbip\. The "needs usbip-win2" hints point to the Airhand installer.
- Android: gamepad buttons (pad:a ... pad:right) for keys, the D-pad and the
  left / right analog stick for sticks, a Gamepad (Xbox) template, a Gamepad
  group in the key picker, Xbox colors for A B X Y. GameControls puts the pad
  state together; Gamepads gives the on-screen pad a slot on first press,
  unplugs it when the layout has no gamepad controls left (hiding only puts it
  at rest), vibrates the phone on rumble (unless "vibrate on press" is off) and
  says why when the Gamepads switch is off or the host is too old.
- iOS: the same (GameModel, GameLayer, GameEditor, Gamepads with CoreHaptics on
  the iPhone itself, SessionController wiring) and GameTests.
- docs: usage, android, ios, building, limitations, architecture, READMEs and
  windows/usbip/README.md (how to update the pinned version).
…pped

Gamepad states are only sent when they change. After a network stall the
controller drops its queued input or the host drops late input, both
replaced by "release all", so a trigger or button held still stayed
released on the host until it moved.

- link: the controller queue remembers what the UI last said about each
  pad, recorded as messages are queued so it always matches the queue
  order. When it drops queued input, its "release all" carries the
  current state of every pad and the removals it dropped; pads that
  aren't at rest are resent every 500 ms, which covers input the host
  dropped. Reading that state and queueing the resend happen under one
  lock, so a resend never lands after a newer release.
- host: a late GamepadRemoved is still carried out (removing late does no
  harm; dropping it left a phantom pad plugged in).
- console and iOS: before a session stops getting the gamepads, its held
  pads are put back to rest, so the resend of a session not in use never
  pulls back pads another session of the same controller is using.
- Android: the same when gamepads stop going to the host (in the
  background, window focus lost, TV menu open), and the keys and axes
  gathered so far are cleared: their releases never arrive, and the next
  resync pressed them again.
- docs: the gamepad notes in the protocol and the architecture.
@sqlpxc
sqlpxc merged commit b45d0c9 into main Dec 2, 2026
1 check passed
@sqlpxc
sqlpxc deleted the feat/gamepads branch December 2, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant