diff options
| author | outfoxxed <outfoxxed@outfoxxed.me> | 2023-05-01 07:10:53 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-01 15:10:53 +0100 |
| commit | 3a631e40db78f98ab82bb600d7cf9d7428bc2b02 (patch) | |
| tree | 9d43696e1fcd6ed24110513c67a600c001638558 /src/config/ConfigManager.cpp | |
| parent | dc469dc4c18732b534c3d9f46678a6e53379abd6 (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/config/ConfigManager.cpp')
| -rw-r--r-- | src/config/ConfigManager.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 4a56f27e..e274f89d 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1105,6 +1105,15 @@ void CConfigManager::handleEnv(const std::string& command, const std::string& va } } +void CConfigManager::handlePlugin(const std::string& command, const std::string& path) { + if (std::find(m_vDeclaredPlugins.begin(), m_vDeclaredPlugins.end(), path) != m_vDeclaredPlugins.end()) { + parseError = "plugin '" + path + "' declared twice"; + return; + } + + m_vDeclaredPlugins.push_back(path); +} + std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std::string& VALUE, bool dynamic) { if (dynamic) { parseError = ""; @@ -1151,6 +1160,8 @@ std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std:: handleBindWS(COMMAND, VALUE); else if (COMMAND.find("env") == 0) handleEnv(COMMAND, VALUE); + else if (COMMAND.find("plugin") == 0) + handlePlugin(COMMAND, VALUE); else { configSetValueSafe(currentCategory + (currentCategory == "" ? "" : ":") + COMMAND, VALUE); needsLayoutRecalc = 2; @@ -1303,6 +1314,7 @@ void CConfigManager::loadConfigLoadVars() { m_dBlurLSNamespaces.clear(); boundWorkspaces.clear(); setDefaultAnimationVars(); // reset anims + m_vDeclaredPlugins.clear(); // paths configPaths.clear(); @@ -1441,6 +1453,9 @@ void CConfigManager::loadConfigLoadVars() { // Reset no monitor reload m_bNoMonitorReload = false; + + // update plugins + handlePluginLoads(); } void CConfigManager::tick() { @@ -1954,6 +1969,31 @@ void CConfigManager::addExecRule(const SExecRequestedRule& rule) { execRequestedRules.push_back(rule); } +void CConfigManager::handlePluginLoads() { + if (g_pPluginSystem == nullptr) + return; + + bool pluginsChanged = false; + auto failedPlugins = g_pPluginSystem->updateConfigPlugins(m_vDeclaredPlugins, pluginsChanged); + + if (!failedPlugins.empty()) { + std::stringstream error; + error << "Failed to load the following plugins:"; + + for (auto path : failedPlugins) { + error << "\n" << path; + } + + g_pHyprError->queueCreate(error.str(), CColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); + } + + if (pluginsChanged) { + g_pHyprError->destroy(); + m_bForceReload = true; + tick(); + } +} + ICustomConfigValueData::~ICustomConfigValueData() { ; // empty } |
