问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/958281/is-anything-required-to-get-a-quartz-callback-besides-registering-for-it