Port IdleDetector to QBasicTimer
QBasicTimer is lighter and it properly handles timeout values bigger than INT32_MAX. CCBUG: 482077
This commit is contained in:
parent
18e414443e
commit
e2cbed7060
2 changed files with 20 additions and 10 deletions
|
@ -14,13 +14,10 @@ namespace KWin
|
||||||
|
|
||||||
IdleDetector::IdleDetector(std::chrono::milliseconds timeout, QObject *parent)
|
IdleDetector::IdleDetector(std::chrono::milliseconds timeout, QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_timer(new QTimer(this))
|
, m_timeout(timeout)
|
||||||
{
|
{
|
||||||
Q_ASSERT(timeout >= 0ms);
|
Q_ASSERT(timeout >= 0ms);
|
||||||
m_timer->setSingleShot(true);
|
m_timer.start(timeout, this);
|
||||||
m_timer->setInterval(timeout);
|
|
||||||
connect(m_timer, &QTimer::timeout, this, &IdleDetector::markAsIdle);
|
|
||||||
m_timer->start();
|
|
||||||
|
|
||||||
input()->addIdleDetector(this);
|
input()->addIdleDetector(this);
|
||||||
}
|
}
|
||||||
|
@ -32,6 +29,14 @@ IdleDetector::~IdleDetector()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IdleDetector::timerEvent(QTimerEvent *event)
|
||||||
|
{
|
||||||
|
if (event->timerId() == m_timer.timerId()) {
|
||||||
|
m_timer.stop();
|
||||||
|
markAsIdle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool IdleDetector::isInhibited() const
|
bool IdleDetector::isInhibited() const
|
||||||
{
|
{
|
||||||
return m_isInhibited;
|
return m_isInhibited;
|
||||||
|
@ -44,16 +49,16 @@ void IdleDetector::setInhibited(bool inhibited)
|
||||||
}
|
}
|
||||||
m_isInhibited = inhibited;
|
m_isInhibited = inhibited;
|
||||||
if (inhibited) {
|
if (inhibited) {
|
||||||
m_timer->stop();
|
m_timer.stop();
|
||||||
} else {
|
} else {
|
||||||
m_timer->start();
|
m_timer.start(m_timeout, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IdleDetector::activity()
|
void IdleDetector::activity()
|
||||||
{
|
{
|
||||||
if (!m_isInhibited) {
|
if (!m_isInhibited) {
|
||||||
m_timer->start();
|
m_timer.start(m_timeout, this);
|
||||||
markAsResumed();
|
markAsResumed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
|
|
||||||
#include <kwin_export.h>
|
#include <kwin_export.h>
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QBasicTimer>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
@ -30,11 +31,15 @@ Q_SIGNALS:
|
||||||
void idle();
|
void idle();
|
||||||
void resumed();
|
void resumed();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void timerEvent(QTimerEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void markAsIdle();
|
void markAsIdle();
|
||||||
void markAsResumed();
|
void markAsResumed();
|
||||||
|
|
||||||
QTimer *m_timer;
|
QBasicTimer m_timer;
|
||||||
|
std::chrono::milliseconds m_timeout;
|
||||||
bool m_isIdle = false;
|
bool m_isIdle = false;
|
||||||
bool m_isInhibited = false;
|
bool m_isInhibited = false;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue