void X11IdleDetector::checkIdleness() { xcb_screensaver_query_info_cookie_t cookie; cookie = xcb_screensaver_query_info(m_connection, m_screen->root); xcb_screensaver_query_info_reply_t *info; info = xcb_screensaver_query_info_reply(m_connection, cookie, NULL); //krazy:exclude=null const int idleSecs = info->ms_since_user_input / 1000; free(info); if (idleSecs >= idlenessDuration()) maybeIdle(IdlePeriod(QDateTime::currentDateTime().addSecs(-idleSecs), QDateTime::currentDateTime())); if (m_heartbeat.secsTo(QDateTime::currentDateTime()) > idlenessDuration()) maybeIdle(IdlePeriod(m_heartbeat, QDateTime::currentDateTime())); m_heartbeat = QDateTime::currentDateTime(); }
void X11IdleDetector::checkIdleness() { #if QT_VERSION < QT_VERSION_CHECK(5,0,0) XScreenSaverInfo* _mit_info = XScreenSaverAllocInfo(); if (!_mit_info) return; XScreenSaverQueryInfo(QX11Info::display(), QX11Info::appRootWindow(), _mit_info); const int idleSecs = _mit_info->idle / 1000; XFree(_mit_info); if (idleSecs >= idlenessDuration()) maybeIdle( IdlePeriod(QDateTime::currentDateTime().addSecs( -idleSecs ), QDateTime::currentDateTime() ) ); if ( m_heartbeat.secsTo( QDateTime::currentDateTime() ) > idlenessDuration() ) maybeIdle( IdlePeriod( m_heartbeat, QDateTime::currentDateTime() ) ); #endif m_heartbeat = QDateTime::currentDateTime(); }
void WindowsIdleDetector::timeout() { LASTINPUTINFO lif; lif.cbSize = sizeof( lif ); const bool ret = GetLastInputInfo( &lif ); if ( !ret ) { qWarning() << "Idle detection: GetLastInputInfo failed."; return; } const qint64 dwTime = static_cast<qint64>( lif.dwTime ); const qint64 ctk = static_cast<qint64>( GetTickCount() ); const int idleSecs = ( ctk - dwTime ) / 1000; if ( idleSecs >= idlenessDuration() ) maybeIdle( IdlePeriod(QDateTime::currentDateTime().addSecs( -idleSecs ), QDateTime::currentDateTime() ) ); }