Skip to content

Gamepads: hide Moonlight controllers from the host until they're assigned to their session - #94

Merged
mlopezsegura merged 1 commit into
masterfrom
fix/stream-pad-early-hide
Nov 24, 2026
Merged

mlopezsegura merged 1 commit into
masterfrom
fix/stream-pad-early-hide

Conversation

@mlopezsegura

Copy link
Copy Markdown
Collaborator

Why

The remote player's controller could also reach the host PC. Sunshine creates Moonlight controllers in ViGEmBus, and OpenStreamMS only learns which session owns one from Sunshine's log, so it hid the controller after it appeared. In that moment the host (Steam, a game's XInput) had already opened it, and HidHide doesn't revoke open handles. The HID child was restarted to close them, but the Xbox 360 node itself — the one XInput reads — never was, because it has children. Controllers that OpenStreamMS plugs in for seats were already hidden before appearing (ClaimNextViGEmPad); Moonlight ones weren't.

What changes

  • While any stream session is running, the next 4 free ViGEmBus serials are kept in HidHide's jail for both Xbox 360 (USB\VID_045E&PID_028E\NN) and DS4 (USB\VID_054C&PID_05C4\NN), with a session that doesn't exist. A new controller is hidden from every session from the moment it appears.
  • When it's assigned, its nodes get the owning session's jail and the controller is restarted as a whole (it can be now: nobody else has it open), so the owning session detects it. If the restart is refused, the previous per-node logic runs.
  • Seat claims keep precedence over reservations. A controller that can't be assigned goes back to visible everywhere, as before. Reservations are cleared when no stream runs and when the service stops; leftovers are removed at startup.

Testing

  • dotnet test: 171/171.
  • Deployed on a test PC. Not yet confirmed with a real Moonlight client and Steam open on the host.

🤖 Generated with Claude Code

… assigned

Sunshine creates Moonlight controllers in ViGEmBus, and the owning session is
only known once it shows up in Sunshine's log, so the controller was hidden
after it appeared. By then the host (Steam, a game's XInput) had already opened
it, and the Xbox 360 node itself (the one XInput uses) was never restarted
because it has children: the remote player's controller also reached the PC.

While streams are running, the next free ViGEmBus serials (Xbox 360 and DS4) are
now kept in HidHide's jail with a session that doesn't exist, so a new
controller is hidden from everyone from the start. Once assigned it's made
visible only in its session and restarted as a whole so that session picks it
up. Seat claims keep precedence, an unassigned controller goes back to visible
everywhere as before, and reservations are removed when the service stops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mlopezsegura
mlopezsegura merged commit 4ffa0fa into master Nov 24, 2026
2 checks passed
@mlopezsegura
mlopezsegura deleted the fix/stream-pad-early-hide branch November 24, 2026 22:48
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