Repository navigation
Conversation
On Apple Silicon there are no IODisplayConnect services, so displays without an EDID (most of them, and every virtual display) get a macos-cg-* id. Its hash included the CGDirectDisplayID and unit number, which macOS reassigns when a display reconnects or a virtual display is recreated, so the device id changed with them. Leave both out when the display reports a nonzero serial; vendor, model and serial identify it.
|
I’d hold this revision until the CoreGraphics fallback handles ambiguous serials. Could you treat both This leaves zero-serial reconnects unchanged, so I wouldn’t consider it a replacement for Sunshine #6023 without a zero-serial virtual-display reconnect test. Review completed by Codex | Model: unavailable | Thinking: unavailable |
Treat 0xFFFFFFFF, which Apple documents as an exception value, like 0: neither identifies a display. When another online display reports the same vendor, model and serial, keep the display id and unit number in the identity as before, so both displays are still enumerated and each id resolves to its own display. Only a display with a usable, unique serial gets the stable id.
|
Thanks, both are right. Pushed 9ebc7d9:
On upgrades, I printed Agreed on #6023. Zero-serial displays still change id on reconnect, so this complements it rather than replacing it. |
|
Thanks, Dave. In Sunshine, the unresolved ID maps to an empty selector, so it can capture a different display without warning. Before updating Sunshine’s pin, could we test saving A in both configurations, then plugging or unplugging B while A stays connected? The selection should either keep resolving to A or be reported as unresolved; a serial-only ID should not be assigned arbitrarily to one of two matches. At minimum Sunshine should warn before falling back from an explicit selection. I’d keep Sunshine #6023 separate for the zero-serial UUID test. Review completed by Codex | Model: unavailable | Thinking: unavailable |
…lugged Whether a macos-cg-* id includes the display id and unit number depends on whether another online display reports the same vendor, model and serial, so a display that stays connected switches between the two forms when such a display is plugged in or unplugged, and an id saved under the other form stopped resolving. getDisplayId() still matches the current id first. If nothing matches, it compares against each online display's other form (getDeviceIdAlias()) and accepts it only if exactly one online display has it. A serial-only id saved before an identical display was plugged in matches both, so it is logged and left unresolved rather than handed to one of them. Verified with CGVirtualDisplay hotplug on macOS 27.2.1: an id saved while a twin was online now resolves after the twin is unplugged, an id saved alone is unresolved (with a warning) once a twin is plugged in, and an id is never resolved to the other display.
|
Thanks, you're right. The description already said a remaining twin "moves to the stable id once the twin is gone," and I didn't follow that through to what it does to a saved id. I reproduced both transitions with real
New tests: Agreed on warning in Sunshine before falling back from an explicit |
|




Description
On Apple Silicon,
MacApiLayer::getDeviceId()falls through to themacos-cg-*id for most displays: there are noIODisplayConnectservices, so neither the EDID nor the IOKit metadata path matches, and every virtual display ends up there too. That id hashes theCGDirectDisplayIDand unit number along with vendor, model and serial (mac_api_layer.cpp#L591-L597). macOS hands out a new display id when a display reconnects and every time a virtual display is created, so the device id changes with it and a saved id stops matching. With aCGVirtualDisplayrecreated per stream I saw display ids 9, 10, ... 30 over one day, each with a different device id.The display id and unit number are now left out of the hash only when vendor, model and serial identify the display on their own:
0and0xFFFFFFFF(which Apple documents as an exception value) both count as no serial, andOtherwise the identity is the same as on master, so identical panels sharing a serial are still both enumerated and each id resolves to its own display. The rule lives in
mac_utils::makeCgDeviceIdentity()so it can be tested without real displays.Because the form depends on what else is online, a display that stays connected switches forms when a twin is plugged in or unplugged. Lookup handles that:
getDisplayId()matches the current id first, then the display's other form (getDeviceIdAlias()), but only if exactly one online display has it. So an id saved while a twin was online still resolves after the twin is unplugged, and a serial-only id saved before a twin was plugged in matches both and is left unresolved (with a warning) rather than handed to one of them.Upgrade note: a saved
macos-cg-*id for a display with a usable, unique serial changes once. The old id no longer resolves; in Sunshine,map_output_name()then returns an empty name and capture falls back to the main display without a warning, so the display has to be picked again from Sunshine's display list. Numericoutput_namevalues (what Sunshine's docs tell macOS users to set) don't go through this and aren't affected. Displays without a usable serial keep their ids.SunshineStream/Sunshine#6023 works around the same instability by accepting display UUIDs in
output_name. This complements it rather than replacing it: zero-serial displays (some virtual display tools create those) still get a new id on every reconnect.Screenshot
N/A
Issues Fixed or Closed
Roadmap Issues
Testing
MacApiUtils.IsUsableCgSerial:0and0xFFFFFFFFare rejected.MacApiUtils.MakeCgDeviceIdentity: a unique serial gives the same identity across display id / unit changes; no usable serial, or a second online display with the same vendor / model / serial, keeps the display id and unit; once the twin is gone the stable identity comes back.MacDisplayDeviceMocked.EnumAvailableDevices_IdenticalSerialsStayDistinct: two displays with identical serials go throughenumAvailableDevices()andgetDisplayName(); both are listed and each id resolves to its own display. With the duplicate check removed, this test andMakeCgDeviceIdentityfail (one device listed).MacApiUtils.MakeCgDeviceIdentityAlias: after a twin is plugged in, both displays have the old serial-only identity as their alias; after it's unplugged, the remaining display's alias is the identity it had while the twin was online, and only it has it.MacDisplayDeviceMocked.GetDisplayName_ResolvesUniqueAlias/GetDisplayName_AmbiguousAliasUnresolved, andSetDisplayModes_InactiveDisplaynow also covers an alias belonging to an inactive display. All three fail with the previousgetDisplayId().test_libdisplaydevice: all 185 tests pass (macOS 27.2.1, M3 Pro).Hotplug with real
CGVirtualDisplays: A's id saved fromenumAvailableDevices(), then resolved withgetDisplayName()after the change. WindowServer won't create a second virtual display with the same vendor / product / serial, so B is created with serial + 1 and the test reports it as A's serial to the library; hotplug, display ids and unit numbers are real.9ebc7d9A kept its display id and unit number when B was unplugged, which is why the second row resolves.
Real displays,
getDeviceId()printed from master and from this branch on the same Mac (all three have nonzero, unique serials):macos-cg-8bc5173d321a7649macos-cg-ef298961686314eemacos-cg-f6d2a85c90531058macos-cg-818c4426e52a57ebCGVirtualDisplay(display id 24)macos-cg-414eb810b4214452macos-cg-8362b26f6b4599bdThe virtual display's id on this branch is the same one it had at display ids 9 - 30 earlier.
I don't have two identical panels, so the duplicate-serial case is covered by the mocked tests and the virtual-display test above.
Formatted with clang-format 23.1.0 (the version pinned in
lizardbyte-common).Type of Change
Checklist
AI Usage
See our AI usage policy.