Skip to content

Commit

Permalink
shutdown: Introduce support for KWin closing wayland windows
Browse files Browse the repository at this point in the history
After ksmserver is done, KWin will now close (or not) open wayland
windows. Since this operation can also cancel the logout, ksmserver
gains a new hook to reset its state. This also means that it cannot
quit itself anymore but needs to be managed by plasma-shutdown.
Using this opportunity the  path for shutdown can be aligned between
X11 and Wayland. In the systemd-managed case we stop graphical-session.target,
otherwise plasma-shutdown quits KWin and ksmserver.
BUG: 461176
FIXED-IN: 6.0
  • Loading branch information
Sodivad committed Nov 20, 2023
1 parent a83f079 commit 23cca93
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ksmserver/logout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ void KSMServer::completeKilling()
void KSMServer::killingCompleted()
{
Q_EMIT logoutFinished(true);
qApp->quit();
}

void KSMServer::timeoutQuit()
Expand Down Expand Up @@ -509,3 +508,8 @@ void KSMServer::signalSubSessionClosed()
qCDebug(KSMSERVER) << state;
Q_EMIT subSessionClosed();
}

void KSMServer::resetLogout()
{
state = Idle;
}
3 changes: 3 additions & 0 deletions ksmserver/org.kde.KSMServerInterface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@
<!-- Performs a logout and closes the session. Returns true if the session was closed successfully, false if cancelled by the user-->
<arg type="b" direction="out"/>
</method>
<method name="resetLogout">
<!-- Called when logout is cancelled -->
</method>
</interface>
</node>
3 changes: 3 additions & 0 deletions ksmserver/org.kde.KWin.Session.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
<!-- Shutdown kwin at the end of the session -->
<method name="quit">
</method>
<method name="closeWaylandWindows">
<arg type="b" direction="out" />
</method>
</interface>
</node>
1 change: 1 addition & 0 deletions ksmserver/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class KSMServer : public QObject, protected QDBusContext
void restoreSession();
void setRestoreSession(const QString &sessionName);
void startDefaultSession();
void resetLogout();

Q_SIGNALS:
void logoutFinished(bool sessionClosed);
Expand Down
31 changes: 31 additions & 0 deletions startkde/plasma-shutdown/shutdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,33 @@ void Shutdown::startLogout(KWorkSpace::ShutdownType shutdownType)
return;
}
if (closeSessionReply.value()) {
ksmServerComplete();
} else {
logoutCancelled();
}
});
}

void Shutdown::ksmServerComplete()
{
OrgKdeKWinSessionInterface kwinInterface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Session"), QDBusConnection::sessionBus());
kwinInterface.setTimeout(INT32_MAX);
auto reply = kwinInterface.closeWaylandWindows();
auto watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
watcher->deleteLater();
OrgKdeKSMServerInterfaceInterface ksmserverIface(QStringLiteral("org.kde.ksmserver"), QStringLiteral("/KSMServer"), QDBusConnection::sessionBus());
auto reply = QDBusReply<bool>(*watcher);
if (!reply.isValid()) {
qCWarning(PLASMA_SESSION) << "KWin failed to complete logout";
ksmserverIface.resetLogout();
logoutCancelled();
return;
}
if (reply.value()) {
logoutComplete();
} else {
ksmserverIface.resetLogout();
logoutCancelled();
}
});
Expand All @@ -78,6 +103,12 @@ void Shutdown::logoutComplete()
QDBusReply<QDBusObjectPath> reply = QDBusConnection::sessionBus().call(msg);

if (!reply.isValid()) {
auto msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.ksmserver"),
QStringLiteral("/MainApplication"),
QStringLiteral("org.qtproject.Qt.QCoreApplication"),
QStringLiteral("quit"));
QDBusConnection::sessionBus().call(msg);

OrgKdeKWinSessionInterface kwinInterface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Session"), QDBusConnection::sessionBus());
QDBusPendingReply<> reply = kwinInterface.quit();
reply.waitForFinished();
Expand Down
1 change: 1 addition & 0 deletions startkde/plasma-shutdown/shutdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Shutdown : public QObject
private Q_SLOTS:
void logoutCancelled();
void logoutComplete();
void ksmServerComplete();

private:
void startLogout(KWorkSpace::ShutdownType shutdownType);
Expand Down

0 comments on commit 23cca93

Please sign in to comment.