Example #1
0
X11IdleDetector::X11IdleDetector( QObject* parent )
    : IdleDetector( parent )
{
    connect( &m_timer, SIGNAL( timeout() ), this, SLOT( checkIdleness() ) );
    m_timer.start( idlenessDuration() * 1000 / 5 );
    m_heartbeat = QDateTime::currentDateTime();
}
Example #2
0
X11IdleDetector::X11IdleDetector(QObject *parent)
    : IdleDetector(parent)
{
    connect(&m_timer, &QTimer::timeout, this, &X11IdleDetector::checkIdleness);
    m_timer.start(idlenessDuration() * 1000 / 5);
    m_heartbeat = QDateTime::currentDateTime();
}
Example #3
0
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();
}
Example #4
0
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() ) );
}
Example #6
0
void IdleDetector::maybeIdle( IdlePeriod period )
{
    if ( ! Configuration::instance().detectIdling ) {
        return;
    }

    qDebug() << "IdleDetector::maybeIdle: Checking for idleness";

    // merge overlapping idle periods
    IdlePeriods periods ( idlePeriods() );
    periods << period;
//     // TEMP (this was used to test the overlapping-idle-period compression below, leave it in
//     {
//         IdlePeriod i2( period.first.addSecs( 1 ), period.second.addSecs( 1 ) ); // should be merged
//         IdlePeriod i3( period.second.addSecs( 2 ), period.second.addSecs( 5 ) ); // should not be merged
//         periods << i2 << i3;
//     }

    qSort( periods );
    m_idlePeriods.clear();
    while ( ! periods.isEmpty() ) {
        IdlePeriod first = periods.first();
        periods.pop_front();
        while ( ! periods.isEmpty() ) {
            IdlePeriod second = periods.first();
            if ( second.first >= first.first && second.first <= first.second ) {
                first.second = qMax( first.second, second.second );
                // first.first is already the earlier time, because the container is sorted
            } else {
                break;
            }
            periods.pop_front();
        }
        if ( first.first.secsTo( first.second ) >= idlenessDuration() ) {
            // we ignore idle period of less than MinimumSeconds
            m_idlePeriods << first;
        }
    }
    // notify application
    if ( ! idlePeriods().isEmpty() ) {
        qDebug() << "IdleDetector::maybeIdle: Found idleness";
        emit maybeIdle();
    }
}
Example #7
0
void X11IdleDetector::idlenessDurationChanged()
{
    m_timer.stop();
    m_timer.start( idlenessDuration() * 1000 / 5 );
}
WindowsIdleDetector::WindowsIdleDetector( QObject* parent ) : IdleDetector( parent ) {
    connect( &m_timer, SIGNAL(timeout()), this, SLOT(timeout()) );
    m_timer.setInterval( idlenessDuration() * 1000 / 2 );
    m_timer.setSingleShot( false );
    m_timer.start();
}
void WindowsIdleDetector::idlenessDurationChanged() {
    m_timer.stop();
    m_timer.setInterval( idlenessDuration() * 1000 / 2 );
    m_timer.start();
}