diff --git a/src/core/ScreenLockListenerDBus.cpp b/src/core/ScreenLockListenerDBus.cpp index 5c57861bda..66970aee39 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 ab73a8cf3d..59120eed33 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