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?

4

1 回答 1

0

你需要某种运行循环。标准的 Cocoa 或 Carbon 应用程序将此作为正常事件处理的一部分。我想最简单的方法是使用 CFRunLoopRun。

于 2010-07-04T07:06:20.133 回答