> What do you need the IOServicePort for?

This GitHub comment provides the
> outline of a solution for getting
information about individual displays, which
> would seem to be more
verbose but safer than granting client apps access to
> the window
server's mach
> ports:
https://github.com/glfw/glfw/issues/165#issuecomment-30515700

On machines with dual GPUs and auto-switching (or even manual switching),
when the GPU changes, the CGDisplayID changes too, and not in a documented
way (although in pratice they seem to differ by 2)

The following code will obtain a string from a CGDisplayID that does not
change when the GPU changes, yet is different for each screen.


-(NSString *)ioDisplayKeyForCGDisplayID:(CGDirectDisplayID)cgDisplayID
{
  io_service_t    servicePort = CGDisplayIOServicePort (cgDisplayID);
  io_service_t    root = IODisplayForFramebuffer (servicePort, kNilOptions);
  NSDictionary*   ioRegistryDict = nil;
  NSString*       prefsKey = nil;
      
  IORegistryEntryCreateCFProperties (root, (CFMutableDictionaryRef*)
  &ioRegistryDict, kCFAllocatorDefault, kNilOptions);

  if (ioRegistryDict)
     prefsKey = [ioRegistryDict objectForKey:@"IODisplayPrefsKey"];
  

  return (prefsKey);
}

Ultimately, I am trying to identify a screen in a way that will not be
affected by the system changing GPUs, nor by the user rearranging the
screens.

Trygve






_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to