@@ -36,6 +36,7 @@
37#define LOGIN1_SERVICE QStringLiteral("org.freedesktop.login1")
37#define LOGIN1_SERVICE QStringLiteral("org.freedesktop.login1")
38#define LOGIN1_PATH QStringLiteral("/org/freedesktop/login1")
38#define LOGIN1_PATH QStringLiteral("/org/freedesktop/login1")
39+#define LOGIN1_SESSION_ROOT QStringLiteral("/org/freedesktop/login1/session/")
39#define LOGIN1_IFACE QStringLiteral("org.freedesktop.login1.Manager")
40#define LOGIN1_IFACE QStringLiteral("org.freedesktop.login1.Manager")
40#define LOGIN1_SESSION_IFACE QStringLiteral("org.freedesktop.login1.Session")
41#define LOGIN1_SESSION_IFACE QStringLiteral("org.freedesktop.login1.Session")
@@ -58,16 +59,9 @@ public:
59 void init()
60 void init()
61− // get our logind session path
62+ QString sessionID = QString::fromLocal8Bit(qgetenv("XDG_SESSION_ID"));
62− QDBusMessage msg = QDBusMessage::createMethodCall(LOGIN1_SERVICE,
63+ if (!sessionID.isEmpty()) {
65− QStringLiteral("GetSessionByPID"));
66− msg << (quint32) getpid();
68− QDBusReply<QDBusObjectPath> reply = QDBusConnection::SM_BUSNAME().call(msg);
69− if (reply.isValid()) {
70− logindSessionPath = reply.value().path();
64+ logindSessionPath = LOGIN1_SESSION_ROOT + sessionID;
72 // start watching the Active property
66 // start watching the Active property
73 QDBusConnection::SM_BUSNAME().connect(LOGIN1_SERVICE, logindSessionPath, QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("PropertiesChanged"),
67 QDBusConnection::SM_BUSNAME().connect(LOGIN1_SERVICE, logindSessionPath, QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("PropertiesChanged"),
@@ -79,7 +73,7 @@ public:
79 QDBusConnection::SM_BUSNAME().connect(LOGIN1_SERVICE, LOGIN1_PATH, LOGIN1_IFACE, QStringLiteral("PrepareForSleep"),
73 QDBusConnection::SM_BUSNAME().connect(LOGIN1_SERVICE, LOGIN1_PATH, LOGIN1_IFACE, QStringLiteral("PrepareForSleep"),
80 this, SLOT(onResuming(bool)));
74 this, SLOT(onResuming(bool)));
82− qWarning() << "Failed to get logind session path" << reply.error().message();
76+ qWarning() << "Failed to get logind session: XDG_SESSION_ID is not set";