diff --git a/daemon/powerdevilcore.cpp b/daemon/powerdevilcore.cpp --- a/daemon/powerdevilcore.cpp +++ b/daemon/powerdevilcore.cpp @@ -139,6 +139,21 @@ KIdleTime::instance()->simulateUserActivity(); }); + // Bug 354250: Simulate user activity when session becomes inactive, + // this keeps us from sending the computer to sleep when switching to an idle session. + // (this is just being lazy as it will result in us clearing everything + connect(PowerDevil::PolicyAgent::instance(), &PowerDevil::PolicyAgent::sessionActiveChanged, this, [this](bool active) { + if (active) { + // force reload profile so all actions re-register their idle timeouts + loadProfile(true /*force*/); + } else { + // Bug 354250: Keep us from sending the computer to sleep when switching + // to an idle session by removing all idle timeouts + KIdleTime::instance()->removeAllIdleTimeouts(); + m_registeredActionTimeouts.clear(); + } + }); + // Initialize the action pool, which will also load the needed startup actions. PowerDevil::ActionPool::instance()->init(this); diff --git a/daemon/powerdevilpolicyagent.h b/daemon/powerdevilpolicyagent.h --- a/daemon/powerdevilpolicyagent.h +++ b/daemon/powerdevilpolicyagent.h @@ -95,6 +95,7 @@ void InhibitionsChanged(const QList &added, const QStringList &removed); void unavailablePoliciesChanged(PowerDevil::PolicyAgent::RequiredPolicies newpolicies); + void sessionActiveChanged(bool active); private Q_SLOTS: void onServiceUnregistered(const QString & serviceName); diff --git a/daemon/powerdevilpolicyagent.cpp b/daemon/powerdevilpolicyagent.cpp --- a/daemon/powerdevilpolicyagent.cpp +++ b/daemon/powerdevilpolicyagent.cpp @@ -365,13 +365,16 @@ } else if ((!m_sdSessionInterface.isNull() && activeSession == m_sdSessionInterface.data()->path()) || (!m_ckSessionInterface.isNull() && activeSession == m_ckSessionInterface.data()->path())) { qCDebug(POWERDEVIL) << "Current session is now active"; - m_wasLastActiveSession = true; - - // sessions usually don't switch themselves, prevents session from suspending when switching back to it after a while - KIdleTime::instance()->simulateUserActivity(); + if (!m_wasLastActiveSession) { + m_wasLastActiveSession = true; + Q_EMIT sessionActiveChanged(true); + } } else { qCDebug(POWERDEVIL) << "Current session is now inactive"; - m_wasLastActiveSession = false; + if (m_wasLastActiveSession) { + m_wasLastActiveSession = false; + Q_EMIT sessionActiveChanged(false); + } } }