views:

50

answers:

1

I'm trying to use CGDisplayRegisterReconfigurationCallback to get display reconfiguration events in Quartz on Mac OS X. Here's the super-simple code:

void CB(CGDirectDisplayID display,
     CGDisplayChangeSummaryFlags flags,
     void *userInfo) {
    std::cout << "In callback!" << std::endl;
}

int main (int argc, char * const argv[]) {
    std::cout << CGDisplayRegisterReconfigurationCallback(CB, NULL) << std::endl;
    std::cout << "Registered callback, sleeping..." << std::endl;
    sleep(10000000);
    return 0;
}

However, the callback isn't getting called when I plug/unplug monitors, etc. CGDisplayRegisterReconfigurationCallback returns success.

'new to os x development' would be an overstatement of my background knowledge here. Do I need to instantiate something like a quartz event loop to get callbacks to work?

A: 

You need some kind of a run loop. A standard Cocoa or Carbon app has this as part of the normal event processing. I guess the most bare-bones way would use CFRunLoopRun.

JWWalker