diff --git a/README.md b/README.md index c3643b8..aee3cd0 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ declared in `cutefish-services/CMakeLists.txt`. For the Wayland session, install KWin Wayland and select `Cutefish (KWin Wayland)` from the display manager. The session entry launches KWin with Wayland enabled and starts `cutefish-session` inside the -compositor. The session starts the retained services daemon, which in turn -starts the desktop components after its D-Bus service is ready. +compositor. The session starts the retained services daemon, waits for its +D-Bus service to register, and then starts the desktop components. ## Build diff --git a/cutefish-services/application.cpp b/cutefish-services/application.cpp index 15f372c..1470c85 100644 --- a/cutefish-services/application.cpp +++ b/cutefish-services/application.cpp @@ -19,15 +19,10 @@ #include "application.h" #include "poweradaptor.h" -#include -#include -#include #include -#include #include #include #include -#include #include #include @@ -49,8 +44,7 @@ Application::Application(int &argc, char **argv) { initTrash(); - // connect to D-Bus and register as an object: - QDBusConnection::sessionBus().registerService(QStringLiteral("com.cutefish.Services")); + // Register all service objects before publishing the well-known name. new PowerAdaptor(m_powerManager); QDBusConnection::sessionBus().registerObject(QStringLiteral("/com/cutefish/Services/Power"), m_powerManager); @@ -66,18 +60,7 @@ Application::Application(int &argc, char **argv) } } - QTimer::singleShot(10, this, &Application::invokeDesktopProcess); -} - -void Application::invokeDesktopProcess() -{ - // Start desktop UI component. - QDBusInterface sessionInterface("com.cutefish.Session", "/Session", "com.cutefish.Session", - QDBusConnection::sessionBus()); - - if (sessionInterface.isValid()) { - sessionInterface.call("startDesktopProcess"); - } + QDBusConnection::sessionBus().registerService(QStringLiteral("com.cutefish.Services")); } void Application::initTrash() diff --git a/cutefish-services/application.h b/cutefish-services/application.h index 97cc829..a8553e6 100644 --- a/cutefish-services/application.h +++ b/cutefish-services/application.h @@ -30,8 +30,6 @@ #include "power/powermanager.h" #include "power/cpumanagement.h" -#include - class Application : public QApplication { Q_OBJECT @@ -39,7 +37,6 @@ class Application : public QApplication public: explicit Application(int &argc, char **argv); - void invokeDesktopProcess(); void initTrash(); private: diff --git a/session/processmanager.cpp b/session/processmanager.cpp index 4f08ee8..6f7e14f 100644 --- a/session/processmanager.cpp +++ b/session/processmanager.cpp @@ -22,17 +22,12 @@ #include #include -#include -#include #include #include #include #include -#include #include #include -#include -#include #include #include @@ -86,9 +81,33 @@ void ProcessManager::startAfterKWinReady() m_kwinWatcher = nullptr; } - // The services daemon owns the Cutefish settings D-Bus service and - // starts the desktop components after that service is ready. + // Start the desktop after the services daemon has registered its D-Bus + // service so its theme and input backends are available to the shell. + const QString serviceName = QStringLiteral("com.cutefish.Services"); + const auto servicesReady = [this]() { + if (m_servicesWatcher) { + m_servicesWatcher->deleteLater(); + m_servicesWatcher = nullptr; + } + startDesktopProcess(); + }; + + m_servicesWatcher = new QDBusServiceWatcher(serviceName, + QDBusConnection::sessionBus(), + QDBusServiceWatcher::WatchForRegistration, + this); + connect(m_servicesWatcher, &QDBusServiceWatcher::serviceRegistered, + this, [servicesReady](const QString &) { + servicesReady(); + }); + startDaemonProcess(); + + if (QDBusConnectionInterface *interface = QDBusConnection::sessionBus().interface()) { + const QDBusReply reply = interface->isServiceRegistered(serviceName); + if (reply.isValid() && reply.value()) + servicesReady(); + } } void ProcessManager::logout() @@ -133,9 +152,6 @@ void ProcessManager::startDesktopProcess() m_desktopStarted = true; - // Start the desktop after the services daemon has initialized its theme module. - // In the way, there will be no problem that desktop and launcher can't get wallpaper. - QList> list; // Desktop components // The status bar, dock, launcher, desktop and notifications are one process now. @@ -184,8 +200,7 @@ void ProcessManager::startDesktopProcess() void ProcessManager::startDaemonProcess() { QList> list; - // This daemon registers com.cutefish.Services and triggers startup of - // the desktop components once the service is available. + // This daemon provides the services used by the desktop components. list << qMakePair(QString("cutefish-services"), QStringList()); for (QPair pair : list) { diff --git a/session/processmanager.h b/session/processmanager.h index 9d671a3..b002c07 100644 --- a/session/processmanager.h +++ b/session/processmanager.h @@ -49,6 +49,7 @@ private: private: Application *m_app; QDBusServiceWatcher *m_kwinWatcher = nullptr; + QDBusServiceWatcher *m_servicesWatcher = nullptr; bool m_kwinReady = false; bool m_desktopStarted = false; QMap m_systemProcess;