Is anything required to get a Quartz callback besides registering for it?

筅森魡賤 提交于 2019-12-11 04:18:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!