From 45d46779737b63a4ad4a77e8ebfdb4d82f06544e Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 20 Jul 2022 11:52:22 +0200 Subject: [PATCH] move PluginManager singleton to Application --- src/main.cpp | 9 +++++++-- src/main.h | 5 +++++ src/pluginmanager.cpp | 10 ++-------- src/pluginmanager.h | 2 +- src/workspace.cpp | 4 ++-- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d1e1f5c0fb..cfeda13a8c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -266,7 +266,7 @@ void Application::createOptions() void Application::createPlugins() { - PluginManager::create(this); + m_pluginManager = std::make_unique(); } void Application::createColorManager() @@ -306,7 +306,7 @@ void Application::destroyCompositor() void Application::destroyPlugins() { - delete PluginManager::self(); + m_pluginManager.reset(); } void Application::destroyColorManager() @@ -562,4 +562,9 @@ void Application::initPlatform(const KPluginMetaData &plugin) } } +PluginManager *Application::pluginManager() const +{ + return m_pluginManager.get(); +} + } // namespace diff --git a/src/main.h b/src/main.h index 900ec2705c..c68246f2e6 100644 --- a/src/main.h +++ b/src/main.h @@ -15,6 +15,7 @@ #include #include +#include // Qt #include #include @@ -28,6 +29,7 @@ namespace KWin class Platform; class X11EventFilter; +class PluginManager; class XcbEventFilter : public QAbstractNativeEventFilter { @@ -238,6 +240,8 @@ public: static void setupMalloc(); static void setupLocalizedString(); + PluginManager *pluginManager() const; + Q_SIGNALS: void x11ConnectionChanged(); void x11ConnectionAboutToBeDestroyed(); @@ -293,6 +297,7 @@ private: bool m_terminating = false; qreal m_xwaylandScale = 1; QProcessEnvironment m_processEnvironment; + std::unique_ptr m_pluginManager; }; inline static Application *kwinApp() diff --git a/src/pluginmanager.cpp b/src/pluginmanager.cpp index fc42e5ffdb..48ad69002c 100644 --- a/src/pluginmanager.cpp +++ b/src/pluginmanager.cpp @@ -17,8 +17,6 @@ namespace KWin { -KWIN_SINGLETON_FACTORY(PluginManager) - static const QString s_pluginDirectory = QStringLiteral("kwin/plugins"); static QJsonValue readPluginInfo(const QJsonObject &metadata, const QString &key) @@ -26,8 +24,7 @@ static QJsonValue readPluginInfo(const QJsonObject &metadata, const QString &key return metadata.value(QLatin1String("KPlugin")).toObject().value(key); } -PluginManager::PluginManager(QObject *parent) - : QObject(parent) +PluginManager::PluginManager() { const KConfigGroup config(kwinApp()->config(), QStringLiteral("Plugins")); @@ -77,10 +74,7 @@ PluginManager::PluginManager(QObject *parent) new PluginManagerDBusInterface(this); } -PluginManager::~PluginManager() -{ - s_self = nullptr; -} +PluginManager::~PluginManager() = default; QStringList PluginManager::loadedPlugins() const { diff --git a/src/pluginmanager.h b/src/pluginmanager.h index 9657a8df39..555d04caf3 100644 --- a/src/pluginmanager.h +++ b/src/pluginmanager.h @@ -28,6 +28,7 @@ class KWIN_EXPORT PluginManager : public QObject Q_OBJECT public: + PluginManager(); ~PluginManager() override; QStringList loadedPlugins() const; @@ -45,7 +46,6 @@ private: std::map> m_plugins; QHash m_staticPlugins; - KWIN_SINGLETON(PluginManager) }; } // namespace KWin diff --git a/src/workspace.cpp b/src/workspace.cpp index 44cc34e3c8..31005b69ba 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -1724,14 +1724,14 @@ QString Workspace::supportInformation() const } support.append(QLatin1String("\nLoaded Plugins:\n")); support.append(QLatin1String("---------------\n")); - QStringList loadedPlugins = PluginManager::self()->loadedPlugins(); + QStringList loadedPlugins = kwinApp()->pluginManager()->loadedPlugins(); loadedPlugins.sort(); for (const QString &plugin : qAsConst(loadedPlugins)) { support.append(plugin + QLatin1Char('\n')); } support.append(QLatin1String("\nAvailable Plugins:\n")); support.append(QLatin1String("------------------\n")); - QStringList availablePlugins = PluginManager::self()->availablePlugins(); + QStringList availablePlugins = kwinApp()->pluginManager()->availablePlugins(); availablePlugins.sort(); for (const QString &plugin : qAsConst(availablePlugins)) { support.append(plugin + QLatin1Char('\n'));