macOS: Mouse confined to main display when streaming a secondary monitor

Open
#134 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, macos

Research direction

Start in src/platform/macos/macos_backend.cpp at the MacosInputState::display initialization near line 384 and the coordinate clamping in post_mouse() near line 684. Reproduce with a secondary streamed display and verify that mouse coordinates cover the selected display without changing the macOS main display.

Written by the indexing model from the issue text.

Description

Describe the Bug

When streaming a secondary monitor (set in Sunshine config), keyboard input and mouse clicks work, but the cursor cannot move normally across the streamed display. It moves vertically along the left edge and appears pinned horizontally at x=0.

Switching between Moonlight’s relative and absolute mouse modes does not resolve the issue. I want to stream the secondary monitor without making it the macOS main display.

Expected Behavior

The cursor should be able to reach the entire streamed secondary display without changing which monitor is the macOS main display.

Actual behavior

Keyboard input and clicks reach the host. Mouse positioning is incorrect; in testing, the cursor becomes pinned to the streamed display’s left edge while still moving vertically.

Additional Context
Environment
  • Sunshine: 2026.906.222525
  • Commit: LizardByte/sunshine@cb72dffa3233c5815cd5ba88f09f049dd679ba75
  • Installation: Homebrew, running as a user service
  • Host: macOS Sonoma 14.8.5, Apple Silicon
  • Client: Moonlight on macOS
  • Capture: macOS screen capture
  • Encoder: VideoToolbox
Suspected cause

The bundled libvirtualhid revision with my build of Sunshine is 6fdb8bd4de3b68d96c30e5303ac2ebb333c09746.

Its macOS backend initializes MacosInputState::display using CGMainDisplayID(). In post_mouse(), it clamps both mouse coordinates to CGDisplayBounds(state_->display). Both relative and absolute motion paths use this function.

This appears to constrain injected mouse movement to the main display rather than allowing movement on the selected secondary display.

Main-display initialization
https://github.com/LizardByte/libvirtualhid/blob/6fdb8bd4de3b68d96c30e5303ac2ebb333c09746/src/platform/macos/macos_backend.cpp#L384

Mouse coordinate clamping
https://github.com/LizardByte/libvirtualhid/blob/6fdb8bd4de3b68d96c30e5303ac2ebb333c09746/src/platform/macos/macos_backend.cpp#L684

Dominant language
C++
Stars
57
Forks
15
Avg merge
11h 15m
Merged PRs (30d)
33

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from LizardByte/libvirtualhid

All issues in LizardByte/libvirtualhid

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.