Make it possible to restart kwin_wayland from a command line argument

A recent patch made it possible to restart KWin when it crashes, this
opens the possibility to do it for development purposes. So far it could
be done using `killall -9 kwin_wayland`. This patch embraces this
functionality under --replace so it's a bit more documented and under
its own semantics.
It is done by returning the process with 133 exit code and picking that
code specifically as a wish to restart.
icc-effect-5.26.4
Aleix Pol 2021-01-30 01:37:13 +01:00 committed by Aleix Pol Gonzalez
parent e7dc64028c
commit 66f87138b1
5 changed files with 26 additions and 3 deletions

View File

@ -181,6 +181,11 @@ void DBusInterface::showDebugConsole()
console->show();
}
void DBusInterface::replace()
{
QCoreApplication::exit(133);
}
namespace {
QVariantMap clientToVariantMap(const AbstractClient *c)
{

View File

@ -58,6 +58,7 @@ public Q_SLOTS: // METHODS
QString supportInformation();
Q_NOREPLY void unclutterDesktop();
Q_NOREPLY void showDebugConsole();
Q_NOREPLY void replace();
QVariantMap queryWindowInfo();
QVariantMap getWindowInfo(const QString &uuid);

View File

@ -101,16 +101,21 @@ int main(int argc, char **argv)
waitpid(pid, &status, 0); /* wait for child */
crashCount++;
if (WIFEXITED(status)) {
int exit_status = WEXITSTATUS(status);
fprintf(stderr, "Kwin exited with code %d\n", exit_status);
break;
if (exit_status == 133) {
crashCount = 0;
fprintf(stderr, "Compositor restarted, respawning\n");
} else {
fprintf(stderr, "KWin exited with code %d\n", exit_status);
break;
}
} else if (WIFSIGNALED(status)) {
// we crashed! Let's go again!
pid = 0;
fprintf(stderr, "Compositor crashed, respawning\n");
}
crashCount++;
}
wl_socket_destroy(socket);

View File

@ -40,6 +40,7 @@
#include <QStyle>
#include <QDebug>
#include <QWindow>
#include <QDBusInterface>
// system
#if HAVE_SYS_PRCTL_H
@ -562,11 +563,15 @@ int main(int argc, char * argv[])
i18n("Wayland socket to use for incoming connections."),
QStringLiteral("wayland_fd"));
QCommandLineOption replaceOption(QStringLiteral("replace"),
i18n("Exits this instance so it can be restarted by kwin_wayland_wrapper."));
QCommandLineParser parser;
a.setupCommandLine(&parser);
parser.addOption(xwaylandOption);
parser.addOption(waylandSocketOption);
parser.addOption(waylandSocketFdOption);
parser.addOption(replaceOption);
if (hasX11Option) {
parser.addOption(x11DisplayOption);
@ -636,6 +641,12 @@ int main(int argc, char * argv[])
a.setUseKActivities(false);
#endif
if (parser.isSet(replaceOption)) {
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.KWin"), QStringLiteral("/KWin"),
QStringLiteral("org.kde.KWin"), QStringLiteral("replace"));
QDBusConnection::sessionBus().call(msg, QDBus::NoBlock);
return 0;
}
if (parser.isSet(listBackendsOption)) {
for (const auto &plugin: availablePlugins) {
std::cout << std::setw(40) << std::left << qPrintable(plugin.name()) << qPrintable(plugin.description()) << std::endl;

View File

@ -36,6 +36,7 @@
<arg type="s" direction="out"/>
</method>
<method name="showDebugConsole"/>
<method name="replace"/>
<method name="queryWindowInfo">
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
<arg type="a{sv}" direction="out"/>