From 6ff3e8801d8efbc5fca7b9f4bf2e3785ea4ee6ef Mon Sep 17 00:00:00 2001 From: Kjell Braden Date: Tue, 21 Jan 2020 11:32:47 +0100 Subject: [PATCH] retrieve login1 session object from manager (#3339) --- src/core/ScreenLockListenerDBus.cpp | 38 ++++++++++++++++++++++++----- src/core/ScreenLockListenerDBus.h | 2 ++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/core/ScreenLockListenerDBus.cpp b/src/core/ScreenLockListenerDBus.cpp index 5c57861bd..66970aee3 100644 --- a/src/core/ScreenLockListenerDBus.cpp +++ b/src/core/ScreenLockListenerDBus.cpp @@ -19,7 +19,9 @@ #include #include +#include #include +#include #include ScreenLockListenerDBus::ScreenLockListenerDBus(QWidget* parent) @@ -57,12 +59,14 @@ ScreenLockListenerDBus::ScreenLockListenerDBus(QWidget* parent) SLOT(logindPrepareForSleep(bool))); QString sessionId = QProcessEnvironment::systemEnvironment().value("XDG_SESSION_ID"); - systemBus.connect("", // service - QString("/org/freedesktop/login1/session/") + sessionId, // path - "org.freedesktop.login1.Session", // interface - "Lock", // signal name - this, // receiver - SLOT(unityLocked())); + QDBusInterface loginManager("org.freedesktop.login1", // service + "/org/freedesktop/login1", // path + "org.freedesktop.login1.Manager", // interface + systemBus); + if (loginManager.isValid()) { + QList args = {sessionId}; + loginManager.callWithCallback("GetSession", args, this, SLOT(login1SessionObjectReceived(QDBusMessage))); + } sessionBus.connect("com.canonical.Unity", // service "/com/canonical/Unity/Session", // path @@ -72,6 +76,28 @@ ScreenLockListenerDBus::ScreenLockListenerDBus(QWidget* parent) SLOT(unityLocked())); } +void ScreenLockListenerDBus::login1SessionObjectReceived(QDBusMessage response) +{ + if (response.arguments().isEmpty()) { + qDebug() << "org.freedesktop.login1.Manager.GetSession did not return results"; + return; + } + QVariant arg0 = response.arguments().at(0); + if (!arg0.canConvert()) { + qDebug() << "org.freedesktop.login1.Manager.GetSession did not return a QDBusObjectPath"; + return; + } + QDBusObjectPath path = arg0.value(); + QDBusConnection systemBus = QDBusConnection::systemBus(); + + systemBus.connect("", // service + path.path(), // path + "org.freedesktop.login1.Session", // interface + "Lock", // signal name + this, // receiver + SLOT(unityLocked())); +} + void ScreenLockListenerDBus::gnomeSessionStatusChanged(uint status) { if (status != 0) { diff --git a/src/core/ScreenLockListenerDBus.h b/src/core/ScreenLockListenerDBus.h index ab73a8cf3..59120eed3 100644 --- a/src/core/ScreenLockListenerDBus.h +++ b/src/core/ScreenLockListenerDBus.h @@ -18,6 +18,7 @@ #ifndef SCREENLOCKLISTENERDBUS_H #define SCREENLOCKLISTENERDBUS_H #include "ScreenLockListenerPrivate.h" +#include #include #include @@ -32,6 +33,7 @@ private slots: void logindPrepareForSleep(bool beforeSleep); void unityLocked(); void freedesktopScreenSaver(bool status); + void login1SessionObjectReceived(QDBusMessage); }; #endif // SCREENLOCKLISTENERDBUS_H