Alex Broadwin
Alex Broadwin

Reputation: 1338

Uniquely identifying an NSScreen

I'm working on a project which has settings for each display. I want my application to support a display being removed and later re-added, possibly with another display used in between, with the original settings for each display being applied when the display is seen again.

As far as I can tell there is no way, through NSScreen, to uniquely identify one outside of the context of the current display configuration. I can't just use screen dimensions/properties as the user could have multiple displays of the same model in different locations; this problem applies to all persistent properties of a screen as far as I can tell.

Is there a good, known way to do this?

Thanks for your time. Any help is greatly appreciated.

Upvotes: 5

Views: 1011

Answers (1)

ashcatch
ashcatch

Reputation: 2357

The documentation to -[NSScreen deviceDescription] talks about getting the CGDirectDisplayID and the documentation about the CGDirectDisplayID says:

When a monitor is attached, Quartz assigns a unique display identifier (ID). A display ID can persist across processes and system reboot, and typically remains constant as long as certain display parameters do not change.

When assigning a display ID, Quartz considers the following parameters:

  • Vendor
  • Model
  • Serial number
  • Position in the I/O Kit registry

This sounds pretty close to what you are looking for.

Upvotes: 7

Related Questions