Files
sqlpxc b45d0c9f53 feat(input): plug the controller's gamepads into Windows and Linux hosts (#136)
* feat(input): plug the controller's gamepads into Windows and Linux hosts

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.

* feat(gamepads): ship usbip-win2 with the Windows installer, add an on-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).

* fix(gamepads): tell the host about held pads again after input is dropped

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.
2026-12-03 00:58:22 +08:00

18 lines
693 B
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
target/
node_modules/
client/dist/
client/src-tauri/gen/
# Windows 安装包带的 usbip-win2:打包前由 client/scripts/fetch-usbip-win2.mjs 下载(见 client/src-tauri/windows/usbip/README.md)
client/src-tauri/windows/usbip/usbip-win2-setup.exe*
client/src-tauri/windows/usbip/usbip-win2.nsh
*.log
web/.env
# 根目录的 .env:docker-compose.yml 的变量(如固定镜像版本的 AIRHAND_VERSION)
/.env
.DS_Store
# docker compose 挂载的 data 目录:运行时自动生成的证书、私钥、SQLite 数据库等,不要提交
# (写成 /data/ 只匹配根目录这一个;android 里有个同名的 data 包,不能用不带斜杠开头的 data/)
/data/
/web/data/