Get the logind session to take over through env variable instead of own PID

Summary:
So far KWin resolved the logind session to take over by  using its own
PID with the method GetSessionByPID. This doesn't work if KWin itself
is not part of the session or if KWin is supposed to take over a
different session.

The session to take over is now derived from XDG_SESSION_ID. If it is
not set the variant through getSessionByPID is used.

This allows to e.g. run kwin on vt1, but have the graphical output
on vt2. Thus it's possible to see the debug output. Also it should allow
to run kwin_wayland through an ssh session, so that gdb can be used.

If we take over another session on a different vt, we need to make sure
that it's the current virtual terminal. Otherwise assumptions in the
startup code would break. So let's ensure the session we integrate with
is active.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1445
This commit is contained in:
Martin Gräßlin 2016-04-19 10:30:39 +02:00
parent 64f7de4024
commit 537cc148df

View file

@ -126,12 +126,22 @@ LogindIntegration::~LogindIntegration()
void LogindIntegration::logindServiceRegistered() void LogindIntegration::logindServiceRegistered()
{ {
const QByteArray sessionId = qgetenv("XDG_SESSION_ID");
QString methodName;
QVariantList args;
if (sessionId.isEmpty()) {
methodName = QStringLiteral("GetSessionByPID");
args << (quint32) QCoreApplication::applicationPid();
} else {
methodName = QStringLiteral("GetSession");
args << QString::fromLocal8Bit(sessionId);
}
// get the current session // get the current session
QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service,
s_login1Path, s_login1Path,
s_login1ManagerInterface, s_login1ManagerInterface,
QStringLiteral("GetSessionByPID")); methodName);
message.setArguments(QVariantList() << (quint32) QCoreApplication::applicationPid()); message.setArguments(args);
QDBusPendingReply<QDBusObjectPath> session = m_bus.asyncCall(message); QDBusPendingReply<QDBusObjectPath> session = m_bus.asyncCall(message);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(session, this); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(session, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, connect(watcher, &QDBusPendingCallWatcher::finished, this,
@ -149,6 +159,13 @@ void LogindIntegration::logindServiceRegistered()
qCDebug(KWIN_CORE) << "Session path:" << m_sessionPath; qCDebug(KWIN_CORE) << "Session path:" << m_sessionPath;
m_connected = true; m_connected = true;
connectSessionPropertiesChanged(); connectSessionPropertiesChanged();
// activate the session, in case we are not on it
QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service,
m_sessionPath,
s_login1SessionInterface,
QStringLiteral("Activate"));
// blocking on purpose
m_bus.call(message);
getSeat(); getSeat();
getSessionActive(); getSessionActive();
getVirtualTerminal(); getVirtualTerminal();