除了注册,还需要什么来获取Quartz回调? [英] Is anything required to get a Quartz callback besides registering for it?
问题描述
我正在尝试使用CGDisplayRegisterReconfigurationCallback
在Mac OS X上的Quartz中获取显示重新配置事件.这是超简单的代码:
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;
}
但是,当我插入/拔下监视器等时,回调不会被调用.CGDisplayRegisterReconfigurationCallback
返回成功.
However, the callback isn't getting called when I plug/unplug monitors, etc. CGDisplayRegisterReconfigurationCallback
returns success.
"OS X开发的新手"将在这里夸大我的背景知识.我需要实例化诸如石英事件循环之类的方法来使回调起作用吗?
'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?
推荐答案
您需要某种运行循环.标准的Cocoa或Carbon应用程序将此作为正常事件处理的一部分.我猜最简单的方法是使用CFRunLoopRun.
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.
这篇关于除了注册,还需要什么来获取Quartz回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!