CoreGraphics reports two displays connections during system wakeup

Hello,

The application I'm working on must report new hardware connections. To retrieve connected displays information and monitor new connections, I'm using the "Core Graphics" framework (see recommendation https://developer.apple.com/forums/thread/779945).
The monitoring logic relies on a callback function which invokes when the local display configuration changes(kCGDisplayAddFlag/kCGDisplayRemoveFlag).

#import <Cocoa/Cocoa.h>

static void displayChanged(CGDirectDisplayID displayID, CGDisplayChangeSummaryFlags flags, void *userInfo)
{
   uint32_t vendor = CGDisplayVendorNumber(displayID);

   if (flags & kCGDisplayAddFlag)
   {
       if (vendor == kDisplayVendorIDUnknown)
       {
           NSLog(@"I/O Kit cannot identify the monitor. kDisplayVendorIDUnknown. displayId = %u", displayID);

           return;
       }

       NSLog(@"%u connected. vendor(%u)", displayID, vendor);
   }

   if (flags & kCGDisplayRemoveFlag)
   {
        NSLog(@"%u disconnected", displayID);
   }
}

int main(int argc, const char * argv[])
{
    @autoreleasepool
    {
        CGDisplayRegisterReconfigurationCallback(displayChanged, NULL);

        NSApplicationLoad();
        CFRunLoopRun();
    }

    return 0;
}

The test environment is a Mac mini with an external display connected via HDMI. Everything works correctly until the system enters sleep mode. Upon wakeup, the app reports two displays: the first with vendor ID kDisplayVendorIDUnknown and the second with the expected vendor ID.

Why does Core Graphics report two connections during wakeup? Is there any way to avoid this?

Thank you in advance.

Answered by DTS Engineer in 851230022

the first with vendor ID kDisplayVendorIDUnknown

More specifically, I suspect this is the "placeholder" display described in this post.

Why does Core Graphics report two connections during wakeup?

Basically, the "placeholder" display ensures that the system always has some kind of display target, regardless of whatever other activity is happening. In the case of wakeup, the placeholder is used until the physical display has finished waking up (or being discovered, depending on the connection type).

Is there any way to avoid this?

You can't avoid/prevent the behavior itself, but in most cases you should just be ignoring that particular display entirely.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Accepted Answer

the first with vendor ID kDisplayVendorIDUnknown

More specifically, I suspect this is the "placeholder" display described in this post.

Why does Core Graphics report two connections during wakeup?

Basically, the "placeholder" display ensures that the system always has some kind of display target, regardless of whatever other activity is happening. In the case of wakeup, the placeholder is used until the physical display has finished waking up (or being discovered, depending on the connection type).

Is there any way to avoid this?

You can't avoid/prevent the behavior itself, but in most cases you should just be ignoring that particular display entirely.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Thank you a lot for the help!

CoreGraphics reports two displays connections during system wakeup
 
 
Q