[plasma/union] src: Move input plugin registry from StyleRegistry to InputPlugin

Arjen Hiemstra <[email protected]> Wed, 5 Aug 2026 10:33:23 +0000 (UTC)
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 7ffa2ba4d053103503381b0c702971d0161fcb5f by Arjen Hiemstra.
Committed on 05/08/2026 at 10:24.
Pushed by ahiemstra into branch 'master'.

Move input plugin registry from StyleRegistry to InputPlugin

This seems like a better place and allows some things to avoid depending
on StyleRegistry.

M  +37   -0    src/InputPlugin.cpp
M  +10   -0    src/InputPlugin.h
M  +2    -5    src/StyleRegistry.cpp

https://invent.kde.org/plasma/union/-/commit/7ffa2ba4d053103503381b0c702971d0161fcb5f

diff --git a/src/InputPlugin.cpp b/src/InputPlugin.cpp
index 9c625c6b..0c533e52 100644
--- a/src/InputPlugin.cpp
+++ b/src/InputPlugin.cpp
@@ -3,11 +3,48 @@
 
 #include "InputPlugin.h"
 
+#include "PluginRegistry.h"
+
 using namespace Union;
+using namespace Qt::StringLiterals;
+
+static QHash<QString, std::shared_ptr<InputPlugin>> s_inputPlugins;
+static std::shared_ptr<PluginRegistry<InputPlugin>> s_inputRegistry;
 
 InputPlugin::InputPlugin(QObject *parent)
     : Plugin(parent)
 {
 }
 
+std::shared_ptr<InputPlugin> Union::InputPlugin::inputPlugin(const QString &typeName)
+{
+    auto inputPlugin = s_inputPlugins.value(typeName);
+
+    static const auto disableInputPlugins = qEnvironmentVariableIsSet("UNION_DISABLE_INPUT_PLUGINS");
+    if (!inputPlugin && !disableInputPlugins) {
+        if (!s_inputRegistry) {
+            s_inputRegistry = std::make_shared<PluginRegistry<InputPlugin>>(u"input"_s);
+        }
+
+        inputPlugin = std::shared_ptr<InputPlugin>(s_inputRegistry->pluginObject(typeName));
+        if (inputPlugin) {
+            s_inputPlugins.insert(typeName, inputPlugin);
+        } else {
+            return nullptr;
+        }
+    }
+
+    return inputPlugin;
+}
+
+void InputPlugin::addInputType(const QString &typeName, const std::shared_ptr<InputPlugin> &plugin)
+{
+    if (s_inputPlugins.contains(typeName)) {
+        qCWarning(UNION_GENERAL) << "Input type" << typeName << "already exits";
+        return;
+    }
+
+    s_inputPlugins.insert(typeName, plugin);
+}
+
 #include "moc_InputPlugin.cpp"
diff --git a/src/InputPlugin.h b/src/InputPlugin.h
index 5bebfa5c..91ecf7cd 100644
--- a/src/InputPlugin.h
+++ b/src/InputPlugin.h
@@ -36,6 +36,16 @@ public:
      * Style using an appropriate StyleLoader and other input specific data.
      */
     virtual std::shared_ptr<Style> createStyle(const QString &styleName) const = 0;
+
+    /*!
+     * Returns an input plugin by type name.
+     */
+    static std::shared_ptr<InputPlugin> inputPlugin(const QString &typeName);
+
+    /*!
+     * Add an input type manually.
+     */
+    static void addInputType(const QString &typeName, const std::shared_ptr<InputPlugin> &plugin);
 };
 
 }
diff --git a/src/StyleRegistry.cpp b/src/StyleRegistry.cpp
index 348e53f9..3ff634e8 100644
--- a/src/StyleRegistry.cpp
+++ b/src/StyleRegistry.cpp
@@ -34,8 +34,7 @@ class Union::StyleRegistryPrivate
 {
 public:
     StyleRegistryPrivate()
-        : inputRegistry{std::make_shared<PluginRegistry<InputPlugin>>(u"input"_s)}
-        , platformRegistry{std::make_shared<PluginRegistry<PlatformPlugin>>(u"platform"_s)}
+        : platformRegistry{std::make_shared<PluginRegistry<PlatformPlugin>>(u"platform"_s)}
     {
     }
 
@@ -65,7 +64,7 @@ public:
             return nullptr;
         }
 
-        auto plugin = inputRegistry->pluginObject(pluginName);
+        auto plugin = InputPlugin::inputPlugin(pluginName);
         if (!plugin) {
             qCWarning(UNION_GENERAL) << "Requested style" << styleName << "from plugin" << pluginName << "but the plugin could not be found!";
             return nullptr;
@@ -136,7 +135,6 @@ public:
 
     std::unique_ptr<StyleCache> styleCache;
 
-    std::shared_ptr<PluginRegistry<InputPlugin>> inputRegistry;
     QHash<StyleCache::StyleId, std::shared_ptr<Style>> styles;
 
     std::shared_ptr<PluginRegistry<PlatformPlugin>> platformRegistry;
@@ -247,7 +245,6 @@ void StyleRegistry::cleanup()
     instance->save();
 
     instance->d->styles.clear();
-    instance->d->inputRegistry.reset();
 
     instance->d->platform.reset();
     instance->d->platformRegistry.reset();