Commit 5acbf74c authored by David Redondo's avatar David Redondo 🏎
Browse files

Lock the screen if necessary when connecting to logind

It can happen that we connect to a logind where the session should
already be locked. So lock it accordingly.
parent 29153f16
...@@ -308,11 +308,16 @@ void KSldApp::initialize() ...@@ -308,11 +308,16 @@ void KSldApp::initialize()
} }
} }
); );
connect(m_logind, &LogindIntegration::connectedChanged, this, connect(m_logind, &LogindIntegration::connectedChanged, this, [this]() {
[this]() { if (!m_logind->isConnected()) {
if (m_logind->isConnected() && m_lockState == ScreenLocker::KSldApp::Unlocked && KScreenSaverSettings::lockOnResume()) { return;
}
if (m_lockState == ScreenLocker::KSldApp::Unlocked && KScreenSaverSettings::lockOnResume()) {
m_logind->inhibit(); m_logind->inhibit();
} }
if (m_logind->isLocked()) {
lock(EstablishLock::Immediate);
}
} }
); );
connect(this, &KSldApp::locked, this, connect(this, &KSldApp::locked, this,
...@@ -347,6 +352,10 @@ void KSldApp::initialize() ...@@ -347,6 +352,10 @@ void KSldApp::initialize()
this, SLOT(solidSuspend())); this, SLOT(solidSuspend()));
configure(); configure();
if (m_logind->isLocked()) {
lock(EstablishLock::Immediate);
}
} }
void KSldApp::configure() void KSldApp::configure()
......
...@@ -37,6 +37,8 @@ const static QString s_consolekitPath = QStringLiteral("/org/freedesktop/Console ...@@ -37,6 +37,8 @@ const static QString s_consolekitPath = QStringLiteral("/org/freedesktop/Console
const static QString s_consolekitManagerInterface = QStringLiteral("org.freedesktop.ConsoleKit.Manager"); const static QString s_consolekitManagerInterface = QStringLiteral("org.freedesktop.ConsoleKit.Manager");
const static QString s_consolekitSessionInterface = QStringLiteral("org.freedesktop.ConsoleKit.Session"); const static QString s_consolekitSessionInterface = QStringLiteral("org.freedesktop.ConsoleKit.Session");
const static QString s_propertyInterface = QStringLiteral("org.freedesktop.DBus.Properties");
LogindIntegration::LogindIntegration(const QDBusConnection &connection, QObject *parent) LogindIntegration::LogindIntegration(const QDBusConnection &connection, QObject *parent)
: QObject(parent) : QObject(parent)
, m_bus(connection) , m_bus(connection)
...@@ -240,3 +242,19 @@ void LogindIntegration::setLocked(bool locked) ...@@ -240,3 +242,19 @@ void LogindIntegration::setLocked(bool locked)
m_bus.call(message, QDBus::NoBlock); m_bus.call(message, QDBus::NoBlock);
} }
bool LogindIntegration::isLocked() const
{
if (!m_connected || m_sessionPath.isEmpty()) {
return false;
}
QDBusMessage message = QDBusMessage::createMethodCall(*m_service, m_sessionPath, s_propertyInterface,
QStringLiteral("Get"));
message.setArguments({*m_sessionInterface, QStringLiteral("LockedHint")});
QDBusReply<QDBusVariant> reply = m_bus.call(message);
if (reply.isValid()) {
return reply.value().variant().toBool();
}
qCDebug(KSCREENLOCKER()) << reply.error();
return false;
}
...@@ -47,6 +47,7 @@ public: ...@@ -47,6 +47,7 @@ public:
* Notify logind of our current state * Notify logind of our current state
*/ */
void setLocked(bool locked); void setLocked(bool locked);
bool isLocked() const;
Q_SIGNALS: Q_SIGNALS:
/** /**
......
Markdown is supported
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