summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authoroutfoxxed <outfoxxed@outfoxxed.me>2023-05-01 07:10:53 -0700
committerGitHub <noreply@github.com>2023-05-01 15:10:53 +0100
commit3a631e40db78f98ab82bb600d7cf9d7428bc2b02 (patch)
tree9d43696e1fcd6ed24110513c67a600c001638558 /src/plugins
parentdc469dc4c18732b534c3d9f46678a6e53379abd6 (diff)
Declarative plugin management (#2180)
* Declarative plugin management Allow declaring `plugin` entries in the hyprland configuration. Plugins will be loaded if an entry is added and unloaded if that entry is removed. * Replace pointers with copying in updateconfigPlugins * Include which plugin was declared twice in error
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/PluginSystem.cpp29
-rw-r--r--src/plugins/PluginSystem.hpp17
2 files changed, 39 insertions, 7 deletions
diff --git a/src/plugins/PluginSystem.cpp b/src/plugins/PluginSystem.cpp
index 73de9bf5..040cfcf1 100644
--- a/src/plugins/PluginSystem.cpp
+++ b/src/plugins/PluginSystem.cpp
@@ -119,6 +119,35 @@ void CPluginSystem::unloadAllPlugins() {
unloadPlugin(p.get(), false); // Unload remaining plugins gracefully
}
+std::vector<std::string> CPluginSystem::updateConfigPlugins(const std::vector<std::string>& plugins, bool& changed) {
+ std::vector<std::string> failures;
+
+ // unload all plugins that are no longer present
+ for (auto& p : m_vLoadedPlugins | std::views::reverse) {
+ if (p->m_bLoadedWithConfig && std::find(plugins.begin(), plugins.end(), p->path) == plugins.end()) {
+ Debug::log(LOG, "Unloading plugin %s which is no longer present in config", p->path.c_str());
+ unloadPlugin(p.get(), false);
+ changed = true;
+ }
+ }
+
+ // load all new plugins
+ for (auto& path : plugins) {
+ if (std::find_if(m_vLoadedPlugins.begin(), m_vLoadedPlugins.end(), [&](const auto& other) { return other->path == path; }) == m_vLoadedPlugins.end()) {
+ Debug::log(LOG, "Loading plugin %s which is now present in config", path.c_str());
+ const auto plugin = loadPlugin(path);
+
+ if (plugin) {
+ plugin->m_bLoadedWithConfig = true;
+ changed = true;
+ } else
+ failures.push_back(path);
+ }
+ }
+
+ return failures;
+}
+
CPlugin* CPluginSystem::getPluginByPath(const std::string& path) {
for (auto& p : m_vLoadedPlugins) {
if (p->path == path)
diff --git a/src/plugins/PluginSystem.hpp b/src/plugins/PluginSystem.hpp
index 5d1a1532..0ef30bab 100644
--- a/src/plugins/PluginSystem.hpp
+++ b/src/plugins/PluginSystem.hpp
@@ -15,6 +15,8 @@ class CPlugin {
std::string path = "";
+ bool m_bLoadedWithConfig = false;
+
HANDLE m_pHandle = nullptr;
std::vector<IHyprLayout*> registeredLayouts;
@@ -27,14 +29,15 @@ class CPluginSystem {
public:
CPluginSystem();
- CPlugin* loadPlugin(const std::string& path);
- void unloadPlugin(const CPlugin* plugin, bool eject = false);
- void unloadAllPlugins();
- CPlugin* getPluginByPath(const std::string& path);
- CPlugin* getPluginByHandle(HANDLE handle);
- std::vector<CPlugin*> getAllPlugins();
+ CPlugin* loadPlugin(const std::string& path);
+ void unloadPlugin(const CPlugin* plugin, bool eject = false);
+ void unloadAllPlugins();
+ std::vector<std::string> updateConfigPlugins(const std::vector<std::string>& plugins, bool& changed);
+ CPlugin* getPluginByPath(const std::string& path);
+ CPlugin* getPluginByHandle(HANDLE handle);
+ std::vector<CPlugin*> getAllPlugins();
- bool m_bAllowConfigVars = false;
+ bool m_bAllowConfigVars = false;
private:
std::vector<std::unique_ptr<CPlugin>> m_vLoadedPlugins;