From bb7b1226e65f533e21145b03047bfef604232323 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Thu, 2 Jul 2020 23:36:19 +0100 Subject: [PATCH] [libkworkspace] Port from deprecated GetSessionByPID This method calls doesn't seem to work anymore having been replaced by the more intuitve virtual paths on the logind over a year ago. Arguably that's still a bug upstream that GetSessionByPID no longer works correctly, but we may as well port to the simpler path that avoids so many layers of indirection. Use of "/auto" does not exist on old distros so the legacy path is kept. The paths used in this class were always wrong, which went unnoticed as this is the first usage of them. BUG: 423526 --- components/tests/sessions.qml | 15 ++++++++++++++ libkworkspace/kdisplaymanager.cpp | 34 +++++++++++++++++++------------ 2 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 components/tests/sessions.qml diff --git a/components/tests/sessions.qml b/components/tests/sessions.qml new file mode 100644 index 000000000..fe8cdd48a --- /dev/null +++ b/components/tests/sessions.qml @@ -0,0 +1,15 @@ +import QtQuick 2.15 +import org.kde.plasma.private.sessions 2.0 + +ListView +{ + width: 500 + height: 500 + + model: SessionsModel{} + + delegate: Text { + text: model.name + " " + model.session + " " + model.displayNumber + " VT" +model.vtNumber + } + +} diff --git a/libkworkspace/kdisplaymanager.cpp b/libkworkspace/kdisplaymanager.cpp index dbe00f442..e7de7fd07 100644 --- a/libkworkspace/kdisplaymanager.cpp +++ b/libkworkspace/kdisplaymanager.cpp @@ -55,9 +55,9 @@ #define _SYSTEMD_SERVICE "org.freedesktop.login1" #define _SYSTEMD_BASE_PATH "/org/freedesktop/login1" #define _SYSTEMD_MANAGER_IFACE _SYSTEMD_SERVICE ".Manager" -#define _SYSTEMD_SESSION_BASE_PATH _SYSTEMD_BASE_PATH "/Session" +#define _SYSTEMD_SESSION_BASE_PATH _SYSTEMD_BASE_PATH "/session" #define _SYSTEMD_SEAT_IFACE _SYSTEMD_SERVICE ".Seat" -#define _SYSTEMD_SEAT_BASE_PATH _SYSTEMD_BASE_PATH "/Seat" +#define _SYSTEMD_SEAT_BASE_PATH _SYSTEMD_BASE_PATH "/seat" #define _SYSTEMD_SESSION_IFACE _SYSTEMD_SERVICE ".Session" #define _SYSTEMD_USER_PROPERTY "User" #define _SYSTEMD_SEAT_PROPERTY "Seat" @@ -429,18 +429,25 @@ KDisplayManager::exec(const char *cmd, QByteArray &buf) static bool getCurrentSeat(QDBusObjectPath *currentSession, QDBusObjectPath *currentSeat) { SystemdManager man; - QDBusReply r = man.call(QStringLiteral("GetSessionByPID"), (uint) QCoreApplication::applicationPid()); - if (r.isValid()) { - SystemdSession sess(r.value()); - if (sess.isValid()) { - NamedDBusObjectPath namedPath = sess.getSeat(); - if (currentSession) - *currentSession = r.value(); - *currentSeat = namedPath.path; + if (man.isValid()) { + *currentSeat = QDBusObjectPath(_SYSTEMD_SEAT_BASE_PATH "/auto"); + SystemdSeat seat(*currentSeat); + if (seat.isValid()) { return true; } - } - else { + + // auto is newer and may not exist on all platforms, fallback to GetSessionByPID if the above failed + + QDBusReply r = man.call(QStringLiteral("GetSessionByPID"), (uint) QCoreApplication::applicationPid()); + if (r.isValid()) { + SystemdSession sess(r.value()); + if (sess.isValid()) { + NamedDBusObjectPath namedPath = sess.getSeat(); + *currentSeat = namedPath.path; + return true; + } + } + } else { CKManager man; QDBusReply r = man.call(QStringLiteral("GetCurrentSession")); if (r.isValid()) { @@ -699,7 +706,8 @@ KDisplayManager::localSessions(SessList &list) * doesn't seem exactly... right to me --mbriza */ se.session = QStringLiteral(""); - se.self = sp == currentSession; + + se.self = lsess.property("Id").toString() == qgetenv("XDG_SESSION_ID"); se.tty = !lsess.property("TTY").toString().isEmpty(); } list.append(se);