views:

94

answers:

1
+3  A: 

You will need to use a private CoreGraphics routine to get the list of all displays including inactive ones, and then request a rescan of the bus. Try it like this:

#include <IOKit/IOKitLib.h>
#include <IOKit/IOTypes.h>

CGDisplayErr CGSGetDisplayList(CGDisplayCount maxDisplays,
                                    CGDirectDisplayID * onlineDspys,
                                    CGDisplayCount * dspyCnt);
static void DetectDisplays()
{
 CGDirectDisplayID    displays[8];
    CGDisplayCount  dspCount = 0;

 if (CGSGetDisplayList(8, displays, &dspCount) == noErr)
 {
  for(int i = 0; i < dspCount; i++)
  {
   io_service_t service = CGDisplayIOServicePort(displays[i]);
   if (service)
    IOServiceRequestProbe(service, kIOFBUserRequestProbe);
  }
 }
}

And link to ApplicationServices and IOKit.

Ken Aspeslagh
Sorry it took me so long to respond, I had to get to where I could test this out. It worked, but I recommend a couple of changes. First, add the line `#include <ApplicationServices/ApplicationServices.h>`, which lets you change `CGSGetDisplayList` (removing its declaration) to `CGGetOnlineDisplayList` and get code completion in Xcode.
Jeff Kelley
Okay, great. I didn't have any external displays to test with and wasn't sure if you could use CGGetOnlineDisplayList instead of CGSGetDisplayList. I know CGSGetDisplayList returns all displays whether they're online or not (It was returning 4 displays on my MacBook Pro) whereas CGGetOnlineDisplayList was only returning one.If it works with CGGetOnlineDisplayList, then that's better to avoid the private API ;)
Ken Aspeslagh