From 779765e5991e8f0bfbfe13221451c1c266fe2249 Mon Sep 17 00:00:00 2001 From: Reion Wong Date: Tue, 1 Sep 2026 04:35:06 -0400 Subject: [PATCH] fix(session): wait for KWin before starting GUI processes --- session/cutefish-wayland-session | 2 +- session/cutefish-wayland.desktop | 2 +- session/processmanager.cpp | 44 ++++++++++++++++++++++++++++++++ session/processmanager.h | 5 ++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/session/cutefish-wayland-session b/session/cutefish-wayland-session index 5d7f7af..d549e9a 100755 --- a/session/cutefish-wayland-session +++ b/session/cutefish-wayland-session @@ -18,4 +18,4 @@ export DESKTOP_SESSION=Cutefish # spice-vdagent. The agent uses X11 selections and cannot connect to the # native Wayland display directly; KWin bridges the Xwayland clipboard into # the Wayland session. -exec /usr/bin/kwin_wayland --xwayland --exit-with-session /usr/bin/cutefish-kwin-wayland-session "$@" +exec /usr/bin/kwin_wayland_wrapper --xwayland --exit-with-session /usr/bin/cutefish-kwin-wayland-session "$@" diff --git a/session/cutefish-wayland.desktop b/session/cutefish-wayland.desktop index 46b635d..985008d 100644 --- a/session/cutefish-wayland.desktop +++ b/session/cutefish-wayland.desktop @@ -2,7 +2,7 @@ Name=Cutefish (KWin Wayland) Comment=Cutefish desktop session on KWin Wayland Exec=/usr/bin/cutefish-wayland-session -TryExec=/usr/bin/kwin_wayland +TryExec=/usr/bin/kwin_wayland_wrapper Type=Application DesktopNames=Cutefish;KDE; X-GDM-SessionRegisters=true diff --git a/session/processmanager.cpp b/session/processmanager.cpp index 70529b0..d56bd05 100644 --- a/session/processmanager.cpp +++ b/session/processmanager.cpp @@ -30,8 +30,11 @@ #include #include #include +#include #include #include +#include +#include ProcessManager::ProcessManager(Application *app, QObject *parent) : QObject(parent) @@ -52,6 +55,37 @@ ProcessManager::~ProcessManager() void ProcessManager::start() { + if (m_kwinReady) + return; + + const QString serviceName = QStringLiteral("org.kde.KWinWrapper"); + m_kwinWatcher = new QDBusServiceWatcher(serviceName, + QDBusConnection::sessionBus(), + QDBusServiceWatcher::WatchForRegistration, + this); + connect(m_kwinWatcher, &QDBusServiceWatcher::serviceRegistered, + this, [this](const QString &) { + startAfterKWinReady(); + }); + + if (QDBusConnectionInterface *interface = QDBusConnection::sessionBus().interface()) { + const QDBusReply reply = interface->isServiceRegistered(serviceName); + if (reply.isValid() && reply.value()) + startAfterKWinReady(); + } +} + +void ProcessManager::startAfterKWinReady() +{ + if (m_kwinReady) + return; + + m_kwinReady = true; + if (m_kwinWatcher) { + m_kwinWatcher->deleteLater(); + m_kwinWatcher = nullptr; + } + // The settings daemon owns the Cutefish settings D-Bus service and // starts the desktop components after that service is ready. startDaemonProcess(); @@ -89,6 +123,16 @@ void ProcessManager::stopProcesses(QMap &processes) void ProcessManager::startDesktopProcess() { + if (!m_kwinReady) { + qWarning() << "Ignoring desktop startup before KWin is ready"; + return; + } + + if (m_desktopStarted) + return; + + m_desktopStarted = true; + // When the cutefish-settings-daemon theme module is loaded, start the desktop. // In the way, there will be no problem that desktop and launcher can't get wallpaper. diff --git a/session/processmanager.h b/session/processmanager.h index 03de2a5..9d671a3 100644 --- a/session/processmanager.h +++ b/session/processmanager.h @@ -26,6 +26,7 @@ #include class Application; +class QDBusServiceWatcher; class ProcessManager : public QObject { Q_OBJECT @@ -42,10 +43,14 @@ public: void loadAutoStartProcess(); private: + void startAfterKWinReady(); void stopProcesses(QMap &processes); private: Application *m_app; + QDBusServiceWatcher *m_kwinWatcher = nullptr; + bool m_kwinReady = false; + bool m_desktopStarted = false; QMap m_systemProcess; QMap m_autoStartProcess;