Repository navigation
feat(input): plug the controller's gamepads into Windows and Linux hosts - #136
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
/dev/uinput; Steam's rules grant it, docs have a udev rule)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::Gamepadcarries the wholeXINPUT_GAMEPADstate of one pad,GamepadRemovedunplugs 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 lateGamepadRemoved. 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).tests/v10.rs; JSON samples inprotocol.json(checked by Rust, TypeScript, Kotlin and Swift).Controllers
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 throughvibrationActuator.Tests
cargo test(root),cargo clippy --all-targets -D warnings,client/src-tauricargo test --lib+ clippy (Windows),npm test+npm run build,./gradlew testDebugUnitTest.plugs_a_virtual_gamepadpasses through vhci-hcd (root) and uinput (non-root).cargo test --lib plugs_a_virtual_gamepad -- --ignored --nocapture), and a full Linux desktop build (WSL lacked libpipewire dev headers).