I need to uniquely identify a display to the extent that the displays are indeed characteristically different. Thus, the same models of displays, plugged into the same physical port would not be treated as different, but basically everything else would be.
When the system GPU changes, the CGDirectDisplayID also changes, but not in a documented way. Experimentation indicates the same screen ID will differ by 2 depending on which GPU is used.
A way to overcome this has been to get an IO registry string for the display:
io_service_t servicePort = CGDisplayIOServicePort (cgDisplayID);
io_service_t root = IODisplayForFramebuffer (servicePort, kNilOptions);
NSDictionary* ioRegistryDict = nil;
NSString* displayKey = nil;
IORegistryEntryCreateCFProperties (root, (CFMutableDictionaryRef *)&ioRegistryDict, kCFAllocatorDefault, kNilOptions);
if (ioRegistryDict)
displayKey = [ioRegistryDict objectForKey:@"IODisplayPrefsKey"];
This works well, except in 10.9, CGDisplayIOServicePort is deprecated.
Given all of this, and Apple's advice not to cache NSScreens (which don't really work for this purpose anyway), what is the best way to reliably identify screens so that I can tell (for example) the difference between a screen at home and one at work?
I don't want to have to rely on screen resolution because the user changing resolution should not be considered a different display. Nor should the same screen on different GPUs be considered different.
A secondary goal is to find a way that given a CGDirectDisplayID, how can I determine what the CGDirectDisplayID would be for the same screen if a GPU switch were to occur? This would at least allow me to track displays by CGDirectDisplayID as long as I could match the two results from the two GPU controllers.