diff options
| author | MithicSpirit <rpc01234@gmail.com> | 2025-10-19 07:54:27 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-19 13:54:27 +0200 |
| commit | 59ff7b2f891d06f4097128faf7027a3863542167 (patch) | |
| tree | 9fe373158653b7588ee0efa036059c3bb21f592c /src/protocols/IdleNotify.cpp | |
| parent | ba077d8ff09e38a5b20c5d06d71daab52bbcc36d (diff) | |
dispatchers: add forceidle (#11922)
The forceidle dispatcher resets all ext-idle-notify timers as if the
user had been idle for the specified number of seconds. If a
notification has already fired, but would now be set with a nonzero
delay, then it is reset. Conversely, if a timer has not yet fired, but
would now be set to a nonpositive delay, then it is immediately fired.
This process ignores any existing inhibitors, but timers are otherwise
reset as normal if any new inhibitors are created or destroyed.
Diffstat (limited to 'src/protocols/IdleNotify.cpp')
| -rw-r--r-- | src/protocols/IdleNotify.cpp | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/src/protocols/IdleNotify.cpp b/src/protocols/IdleNotify.cpp index 0ebe24e3..4122bf24 100644 --- a/src/protocols/IdleNotify.cpp +++ b/src/protocols/IdleNotify.cpp @@ -21,7 +21,7 @@ CExtIdleNotification::CExtIdleNotification(SP<CExtIdleNotificationV1> resource_, m_timer = makeShared<CEventLoopTimer>(std::nullopt, onTimer, this); g_pEventLoopManager->addTimer(m_timer); - updateTimer(); + update(); LOGM(LOG, "Registered idle-notification for {}ms", timeoutMs_); } @@ -35,24 +35,39 @@ bool CExtIdleNotification::good() { return m_resource->resource(); } -void CExtIdleNotification::updateTimer() { - if (PROTO::idle->isInhibited && m_obeyInhibitors) - m_timer->updateTimeout(std::nullopt); - else - m_timer->updateTimeout(std::chrono::milliseconds(m_timeoutMs)); +void CExtIdleNotification::update(uint32_t elapsedMs) { + m_timer->updateTimeout(std::nullopt); + + if (elapsedMs == 0 && PROTO::idle->isInhibited && m_obeyInhibitors) { + reset(); + return; + } + + if (m_timeoutMs > elapsedMs) { + reset(); + m_timer->updateTimeout(std::chrono::milliseconds(m_timeoutMs - elapsedMs)); + } else + onTimerFired(); +} + +void CExtIdleNotification::update() { + update(0); } void CExtIdleNotification::onTimerFired() { + if (m_idled) + return; + m_resource->sendIdled(); m_idled = true; } -void CExtIdleNotification::onActivity() { - if (m_idled) - m_resource->sendResumed(); +void CExtIdleNotification::reset() { + if (!m_idled) + return; + m_resource->sendResumed(); m_idled = false; - updateTimer(); } bool CExtIdleNotification::inhibitorsAreObeyed() const { @@ -96,7 +111,7 @@ void CIdleNotifyProtocol::onGetNotification(CExtIdleNotifierV1* pMgr, uint32_t i void CIdleNotifyProtocol::onActivity() { for (auto const& n : m_notifications) { - n->onActivity(); + n->update(); } } @@ -104,6 +119,12 @@ void CIdleNotifyProtocol::setInhibit(bool inhibited) { isInhibited = inhibited; for (auto const& n : m_notifications) { if (n->inhibitorsAreObeyed()) - n->onActivity(); + n->update(); + } +} + +void CIdleNotifyProtocol::setTimers(uint32_t elapsedMs) { + for (auto const& n : m_notifications) { + n->update(elapsedMs); } } |
