diff --git a/include/wx/osx/evtloop.h b/include/wx/osx/evtloop.h index 4e45db718c..00a5258fce 100644 --- a/include/wx/osx/evtloop.h +++ b/include/wx/osx/evtloop.h @@ -53,9 +53,14 @@ public: AddSourceForFD(int fd, wxEventLoopSourceHandler *handler, int flags); #endif // wxUSE_EVENTLOOP_SOURCE - void ObserverCallBack(CFRunLoopObserverRef observer, int activity); protected: + void CommonModeObserverCallBack(CFRunLoopObserverRef observer, int activity); + void DefaultModeObserverCallBack(CFRunLoopObserverRef observer, int activity); + + static void OSXCommonModeObserverCallBack(CFRunLoopObserverRef observer, int activity, void *info); + static void OSXDefaultModeObserverCallBack(CFRunLoopObserverRef observer, int activity, void *info); + // get the currently executing CFRunLoop virtual CFRunLoopRef CFGetCurrentRunLoop() const; @@ -74,8 +79,11 @@ protected: // cfrunloop CFRunLoopRef m_runLoop; - // runloop observer - CFRunLoopObserverRef m_runLoopObserver; + // common modes runloop observer + CFRunLoopObserverRef m_commonModeRunLoopObserver; + + // default mode runloop observer + CFRunLoopObserverRef m_defaultModeRunLoopObserver; private: // process all already pending events and dispatch a new one (blocking diff --git a/src/osx/core/evtloop_cf.cpp b/src/osx/core/evtloop_cf.cpp index f151cb5684..f83729f1c9 100644 --- a/src/osx/core/evtloop_cf.cpp +++ b/src/osx/core/evtloop_cf.cpp @@ -147,14 +147,21 @@ wxCFEventLoop::AddSourceForFD(int WXUNUSED(fd), #endif // wxUSE_EVENTLOOP_SOURCE -extern "C" void wxObserverCallBack(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info) +void wxCFEventLoop::OSXCommonModeObserverCallBack(CFRunLoopObserverRef observer, int activity, void *info) { wxCFEventLoop * eventloop = static_cast(info); if ( eventloop ) - eventloop->ObserverCallBack(observer, activity); + eventloop->CommonModeObserverCallBack(observer, activity); } -void wxCFEventLoop::ObserverCallBack(CFRunLoopObserverRef WXUNUSED(observer), int activity) +void wxCFEventLoop::OSXDefaultModeObserverCallBack(CFRunLoopObserverRef observer, int activity, void *info) +{ + wxCFEventLoop * eventloop = static_cast(info); + if ( eventloop ) + eventloop->DefaultModeObserverCallBack(observer, activity); +} + +void wxCFEventLoop::CommonModeObserverCallBack(CFRunLoopObserverRef WXUNUSED(observer), int activity) { if ( activity & kCFRunLoopBeforeTimers ) { @@ -170,21 +177,30 @@ void wxCFEventLoop::ObserverCallBack(CFRunLoopObserverRef WXUNUSED(observer), in wxTheApp->ProcessPendingEvents(); } + if ( activity & kCFRunLoopBeforeWaiting ) + { +#if wxUSE_THREADS + wxMutexGuiLeaveOrEnter(); +#endif + } +} + +void wxCFEventLoop::DefaultModeObserverCallBack(CFRunLoopObserverRef WXUNUSED(observer), int activity) +{ + if ( activity & kCFRunLoopBeforeTimers ) + { + } + if ( activity & kCFRunLoopBeforeWaiting ) { if ( ProcessIdle() ) { WakeUp(); } - else - { -#if wxUSE_THREADS - wxMutexGuiLeaveOrEnter(); -#endif - } } } + wxCFEventLoop::wxCFEventLoop() { m_shouldExit = false; @@ -194,15 +210,21 @@ wxCFEventLoop::wxCFEventLoop() CFRunLoopObserverContext ctxt; bzero( &ctxt, sizeof(ctxt) ); ctxt.info = this; - m_runLoopObserver = CFRunLoopObserverCreate( kCFAllocatorDefault, kCFRunLoopBeforeTimers | kCFRunLoopBeforeWaiting , true /* repeats */, 0, - wxObserverCallBack, &ctxt ); - CFRunLoopAddObserver(m_runLoop, m_runLoopObserver, kCFRunLoopCommonModes); - CFRelease(m_runLoopObserver); + m_commonModeRunLoopObserver = CFRunLoopObserverCreate( kCFAllocatorDefault, kCFRunLoopBeforeTimers | kCFRunLoopBeforeWaiting , true /* repeats */, 0, + (CFRunLoopObserverCallBack) wxCFEventLoop::OSXCommonModeObserverCallBack, &ctxt ); + CFRunLoopAddObserver(m_runLoop, m_commonModeRunLoopObserver, kCFRunLoopCommonModes); + CFRelease(m_commonModeRunLoopObserver); + + m_defaultModeRunLoopObserver = CFRunLoopObserverCreate( kCFAllocatorDefault, kCFRunLoopBeforeTimers | kCFRunLoopBeforeWaiting , true /* repeats */, 0, + (CFRunLoopObserverCallBack) wxCFEventLoop::OSXDefaultModeObserverCallBack, &ctxt ); + CFRunLoopAddObserver(m_runLoop, m_defaultModeRunLoopObserver, kCFRunLoopDefaultMode); + CFRelease(m_defaultModeRunLoopObserver); } wxCFEventLoop::~wxCFEventLoop() { - CFRunLoopRemoveObserver(m_runLoop, m_runLoopObserver, kCFRunLoopCommonModes); + CFRunLoopRemoveObserver(m_runLoop, m_commonModeRunLoopObserver, kCFRunLoopCommonModes); + CFRunLoopRemoveObserver(m_runLoop, m_defaultModeRunLoopObserver, kCFRunLoopDefaultMode); }