Commit 72b1e92e authored by David Edmundson's avatar David Edmundson
Browse files

Update logind's SetLockedHint

SetLockedHint exists so that an external system can determine if a
session is locked or not without having to access the user's session
bus.

We support logind's requesting us to lock/unlock so it makes sense to
support this also.

CCBUG: 422591
parent f53b9b32
......@@ -318,6 +318,7 @@ void KSldApp::initialize()
connect(this, &KSldApp::locked, this,
[this]() {
m_logind->uninhibit();
m_logind->setLocked(true);
if (m_lockGrace > 0 && m_inGraceTime) {
m_graceTimer->start(m_lockGrace);
}
......@@ -325,6 +326,7 @@ void KSldApp::initialize()
);
connect(this, &KSldApp::unlocked, this,
[this]() {
m_logind->setLocked(false);
if (KScreenSaverSettings::lockOnResume()) {
m_logind->inhibit();
}
......
......@@ -56,6 +56,7 @@ LogindIntegration::LogindIntegration(const QDBusConnection &connection, QObject
connect(m_logindServiceWatcher, &QDBusServiceWatcher::serviceUnregistered, this,
[this]() {
m_connected = false;
m_sessionPath = QString();
emit connectedChanged();
}
);
......@@ -149,19 +150,19 @@ void LogindIntegration::commonServiceRegistered(QDBusPendingCallWatcher *watcher
<< reply.error().message();
return;
}
const QString sessionPath = reply.value().path();
qCDebug(KSCREENLOCKER) << "Session path:" << sessionPath;
m_sessionPath = reply.value().path();
qCDebug(KSCREENLOCKER) << "Session path:" << m_sessionPath;
// connections need to be done this way as the object exposes both method and signal
// with name "Lock"/"Unlock". Qt is not able to automatically handle this.
m_bus.connect(*m_service,
sessionPath,
m_sessionPath,
*m_sessionInterface,
QStringLiteral("Lock"),
this,
SIGNAL(requestLock()));
m_bus.connect(*m_service,
sessionPath,
m_sessionPath,
*m_sessionInterface,
QStringLiteral("Unlock"),
this,
......@@ -225,3 +226,18 @@ bool LogindIntegration::isInhibited() const
{
return m_inhibitFileDescriptor.isValid();
}
void LogindIntegration::setLocked(bool locked)
{
if (!m_connected || m_sessionPath.isEmpty()) {
return;
}
QDBusMessage message = QDBusMessage::createMethodCall(*m_service,
m_sessionPath,
*m_sessionInterface,
QStringLiteral("SetLockedHint"));
message.setArguments({locked});
m_bus.call(message, QDBus::NoBlock);
}
......@@ -43,7 +43,15 @@ public:
bool isInhibited() const;
/**
* Notify logind of our current state
*/
void setLocked(bool locked);
Q_SIGNALS:
/**
* signalled when logind asks us to lock
*/
void requestLock();
void requestUnlock();
void connectedChanged();
......@@ -68,6 +76,7 @@ private:
QDBusUnixFileDescriptor m_inhibitFileDescriptor;
const QString *m_service;
const QString *m_path;
QString m_sessionPath;
const QString *m_managerInterface;
const QString *m_sessionInterface;
};
......
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