Skip to content

Commit

Permalink
retrieve login1 session object from manager (#3339)
Browse files Browse the repository at this point in the history
  • Loading branch information
afflux authored and droidmonkey committed Jan 25, 2020
1 parent 796b5ce commit 6ff3e88
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
38 changes: 32 additions & 6 deletions src/core/ScreenLockListenerDBus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusMessage>
#include <QDBusReply>
#include <QDebug>
#include <QProcessEnvironment>

ScreenLockListenerDBus::ScreenLockListenerDBus(QWidget* parent)
Expand Down Expand Up @@ -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<QVariant> args = {sessionId};
loginManager.callWithCallback("GetSession", args, this, SLOT(login1SessionObjectReceived(QDBusMessage)));
}

sessionBus.connect("com.canonical.Unity", // service
"/com/canonical/Unity/Session", // path
Expand All @@ -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<QDBusObjectPath>()) {
qDebug() << "org.freedesktop.login1.Manager.GetSession did not return a QDBusObjectPath";
return;
}
QDBusObjectPath path = arg0.value<QDBusObjectPath>();
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) {
Expand Down
2 changes: 2 additions & 0 deletions src/core/ScreenLockListenerDBus.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef SCREENLOCKLISTENERDBUS_H
#define SCREENLOCKLISTENERDBUS_H
#include "ScreenLockListenerPrivate.h"
#include <QDBusMessage>
#include <QObject>
#include <QWidget>

Expand All @@ -32,6 +33,7 @@ private slots:
void logindPrepareForSleep(bool beforeSleep);
void unityLocked();
void freedesktopScreenSaver(bool status);
void login1SessionObjectReceived(QDBusMessage);
};

#endif // SCREENLOCKLISTENERDBUS_H

0 comments on commit 6ff3e88

Please sign in to comment.