Skip to content

fix(mac): CGDisplayStream fallback when SCShareableContent misses virtual display#143

Open
hmachine1999 wants to merge 1 commit into
peetzweg:mainfrom
hmachine1999:fix/scshareable-cgdisplaystream-fallback
Open

fix(mac): CGDisplayStream fallback when SCShareableContent misses virtual display#143
hmachine1999 wants to merge 1 commit into
peetzweg:mainfrom
hmachine1999:fix/scshareable-cgdisplaystream-fallback

Conversation

@hmachine1999

Copy link
Copy Markdown

Summary

Fixes the hard failure path reported in #142:

virtual display never appeared in SCShareableContent (MacSender Code=3)

On affected machines (reproduced: Mac mini M2 + single external 4K display + macOS 15.7.x):

  1. Wi‑Fi connect + phone hello succeed
  2. CGVirtualDisplay is created and returns an id
  3. SCShareableContent never lists that id → capture never starts
  4. No purple recording indicator; iPad stays on the OpenDisplay UI

This is not a network failure — enumeration fails after a successful handshake.

Changes

File Change
Mac/VirtualDisplay.swift waitUntilReady() — poll online/NSScreen after applySettings (async)
Mac/MacSender.swift Richer findSCDisplay (explicit SCK API, size match, diagnostic logs)
Mac/MacSender.swift CGDisplayStream fallback when SCK times out, using the known CGDirectDisplayID
Mac/MacSender.swift Tear down displayStream in stop() / reconfigure()

ScreenCaptureKit remains the preferred path. CGDisplayStream is deprecated and used only as a last resort so users are not stuck with Code=3 when the virtual display id is already known.

Test plan

  • Local Debug build succeeds (OpenSidecarMac)
  • On a machine that previously hit Code=3 every session with stock builds: Extend over Wi‑Fi streams after this change (fallback path)
  • Maintainer: Extend on a normal multi-display Mac still uses SCK (no fallback log line)
  • Maintainer: Mirror mode unchanged
  • Maintainer: Disconnect / reconnect / rotate still tear down capture cleanly
  • Maintainer: /tmp/opensidecar-mac.log shows either normal capture started: or capture started (CGDisplayStream fallback):

Notes / non-goals

Closes #142

On some Mac mini + external-display-only setups, CGVirtualDisplay creates
successfully but the display never appears in SCShareableContent (MacSender
Code=3). Connection and hello succeed, yet capture never starts — no purple
indicator and the receiver stays on the OpenDisplay UI.

- Wait briefly for the virtual display to attach after applySettings
- Improve findSCDisplay diagnostics and size-based matching
- If SCK still cannot enumerate the display, capture via CGDisplayStream
  using the known CGDirectDisplayID (deprecated API, fallback only)

Fixes the user-visible dead-end for peetzweg#142.
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.

Mac: virtual display created but never appears in SCShareableContent (Code=3) — no capture / purple indicator; CGDisplayStream fallback works

1 participant