Restore following XDG_SESSION_ID env if set

BUG: 435468

Testing done:
Ran on a VT with an XDG_SESSION_ID from another terminal, ensured it
switched
This commit is contained in:
David Edmundson 2021-04-07 17:37:59 +01:00
parent c103eb8f5c
commit 799db61381

View file

@ -61,11 +61,19 @@ static const QString s_managerPath = QStringLiteral("/org/freedesktop/login1");
static QString findProcessSessionPath()
{
QDBusMessage message = QDBusMessage::createMethodCall(s_serviceName, s_managerPath,
s_managerInterface,
QStringLiteral("GetSessionByPID"));
message.setArguments({ uint32_t(QCoreApplication::applicationPid()) });
const QString sessionId = qEnvironmentVariable("XDG_SESSION_ID");
QDBusMessage message;
if (sessionId.isEmpty()) {
message = QDBusMessage::createMethodCall(s_serviceName, s_managerPath,
s_managerInterface,
QStringLiteral("GetSessionByPID"));
message.setArguments({uint32_t(QCoreApplication::applicationPid())});
} else {
message = QDBusMessage::createMethodCall(s_serviceName, s_managerPath,
s_managerInterface,
QStringLiteral("GetSession"));
message.setArguments({sessionId});
}
const QDBusMessage reply = QDBusConnection::systemBus().call(message);
if (reply.type() == QDBusMessage::ErrorMessage) {
return QString();