bool Kopete::IdlePlatform::init() { // May already be init'ed. if ( d->mTimerRef ) return true; // According to the docs, InstallEventLoopIdleTimer is new in 10.2. // According to the headers, it has been around since 10.0. // One of them is lying. We'll play it safe and weak-link the function. // Load the "Carbon.framework" bundle. CFBundleRef carbonBundle; if ( LoadFrameworkBundle( CFSTR("Carbon.framework"), &carbonBundle ) != noErr ) return false; // Load the Mach-O function pointers for the routine we will be using. InstallEventLoopIdleTimerPtr myInstallEventLoopIdleTimer = (InstallEventLoopIdleTimerPtr)CFBundleGetFunctionPointerForName( carbonBundle, CFSTR("InstallEventLoopIdleTimer") ); if ( myInstallEventLoopIdleTimer == 0 ) return false; EventLoopIdleTimerUPP timerUPP = NewEventLoopIdleTimerUPP( Private::IdleTimerAction ); if ( (*myInstallEventLoopIdleTimer)(GetMainEventLoop(), kEventDurationSecond, kEventDurationSecond, timerUPP, 0, &d->mTimerRef) ) return true; return false; }
AutoAwayPlugin::AutoAwayPlugin(unsigned base, Buffer *config) : Plugin(base), EventReceiver(HighPriority) { load_data(autoAwayData, &data, config); #ifdef WIN32 HINSTANCE hLib = GetModuleHandleA("user32"); if (hLib != NULL){ (DWORD&)_GetLastInputInfo = (DWORD)GetProcAddress(hLib,"GetLastInputInfo"); }else{ hLibUI = LoadLibraryA("idleui.dll"); if (hLibUI != NULL) (DWORD&)_IdleUIGetLastInputTime = (DWORD)GetProcAddress(hLibUI, "IdleUIGetLastInputTime"); } #elif defined(HAVE_CARBON_CARBNON_H) && !defined(HAVE_X) CFBundleRef carbonBundle; if (LoadFrameworkBundle( CFSTR("Carbon.framework"), &carbonBundle ) == noErr) { InstallEventLoopIdleTimerPtr myInstallEventLoopIdleTimer = (InstallEventLoopIdleTimerPtr)CFBundleGetFunctionPointerForName(carbonBundle, CFSTR("InstallEventLoopIdleTimer")); if (myInstallEventLoopIdleTimer){ EventLoopIdleTimerUPP timerUPP = NewEventLoopIdleTimerUPP(Private::IdleTimerAction); (*myInstallEventLoopIdleTimer)(GetMainEventLoop(), kEventDurationSecond, kEventDurationSecond, timerUPP, 0, &mTimerRef); } } #endif Event ePlugin(EventGetPluginInfo, (void*)"_core"); pluginInfo *info = (pluginInfo*)(ePlugin.process()); core = static_cast<CorePlugin*>(info->plugin); bAway = false; bNA = false; bOff = false; m_timer = new QTimer(this); connect(m_timer, SIGNAL(timeout()), this, SLOT(timeout())); m_timer->start(AUTOAWAY_TIME); }
void Shell::EventLoop(ShellIdleFunction idle_function) { OSStatus error; error = InstallApplicationEventHandler(NewEventHandlerUPP(InputMacOSX::EventHandler), GetEventTypeCount(INPUT_EVENTS), INPUT_EVENTS, NULL, NULL); if (error != noErr) DisplayError("Unable to install handler for input events, error: %d.", error); error = InstallWindowEventHandler(window, NewEventHandlerUPP(EventHandler), GetEventTypeCount(WINDOW_EVENTS), WINDOW_EVENTS, NULL, NULL); if (error != noErr) DisplayError("Unable to install handler for window events, error: %d.", error); EventLoopTimerRef timer; error = InstallEventLoopIdleTimer(GetMainEventLoop(), // inEventLoop 0, // inFireDelay 5 * kEventDurationMillisecond, // inInterval (200 Hz) NewEventLoopIdleTimerUPP(IdleTimerCallback), // inTimerProc (void*) idle_function, // inTimerData, &timer // outTimer ); if (error != noErr) DisplayError("Unable to install Carbon event loop timer, error: %d.", error); RunApplicationEventLoop(); }