[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


(cherry picked from commit bb7b1226e6)
wilder-portage-prov
David Edmundson 6 years ago
parent 92e2b2ee3a
commit 3acf8f3024
  1. 15
      components/tests/sessions.qml
  2. 34
      libkworkspace/kdisplaymanager.cpp

@ -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
}
}

@ -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<QDBusObjectPath> 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<QDBusObjectPath> 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<QDBusObjectPath> 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("<unknown>");
se.self = sp == currentSession;
se.self = lsess.property("Id").toString() == qgetenv("XDG_SESSION_ID");
se.tty = !lsess.property("TTY").toString().isEmpty();
}
list.append(se);

Loading…
Cancel
Save