Commit 40fb202a authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

Make IdleDetector not emit resumed signal when it's inhibited

At the moment, when an IdleDetector is inhibited, it can emit the
resumed signal. It makes sense on one hand, but also it doesn't.
Inhibited != resumed.

According to the idle-inhibit-v1 protocol specification, we don't
need to emit the resumed signal:

> Likewise, the inhibitor isn't honored if the system was already idled at
> the time the inhibitor was established, although if the system later
> de-idles and re-idles the inhibitor will take effect.
parent a71146c9
Pipeline #200335 passed with stage
in 26 minutes and 1 second
......@@ -16,7 +16,7 @@ IdleDetector::IdleDetector(std::chrono::milliseconds timeout, QObject *parent)
{
m_timer->setSingleShot(true);
m_timer->setInterval(timeout);
connect(m_timer, &QTimer::timeout, this, &IdleDetector::idle);
connect(m_timer, &QTimer::timeout, this, &IdleDetector::markAsIdle);
m_timer->start();
input()->addIdleDetector(this);
......@@ -40,11 +40,7 @@ void IdleDetector::setInhibited(bool inhibited)
return;
}
m_isInhibited = inhibited;
if (inhibited) {
if (!m_timer->isActive()) {
Q_EMIT resumed();
}
m_timer->stop();
} else {
m_timer->start();
......@@ -54,10 +50,24 @@ void IdleDetector::setInhibited(bool inhibited)
void IdleDetector::activity()
{
if (!m_isInhibited) {
if (!m_timer->isActive()) {
Q_EMIT resumed();
}
m_timer->start();
markAsResumed();
}
}
void IdleDetector::markAsIdle()
{
if (!m_isIdle) {
m_isIdle = true;
Q_EMIT idle();
}
}
void IdleDetector::markAsResumed()
{
if (m_isIdle) {
m_isIdle = false;
Q_EMIT resumed();
}
}
......
......@@ -31,7 +31,11 @@ Q_SIGNALS:
void resumed();
private:
void markAsIdle();
void markAsResumed();
QTimer *m_timer;
bool m_isIdle = false;
bool m_isInhibited = false;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment