diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 0d9cc288..3d4d265a 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1389,8 +1389,15 @@ std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std:: else if (COMMAND.starts_with("plugin")) handlePlugin(COMMAND, VALUE); else { - configSetValueSafe(currentCategory + (currentCategory == "" ? "" : ":") + COMMAND, VALUE); - needsLayoutRecalc = 2; + // try config + const auto IT = std::find_if(pluginKeywords.begin(), pluginKeywords.end(), [&](const auto& other) { return other.name == COMMAND; }); + + if (IT != pluginKeywords.end()) { + IT->fn(COMMAND, VALUE); + } else { + configSetValueSafe(currentCategory + (currentCategory == "" ? "" : ":") + COMMAND, VALUE); + needsLayoutRecalc = 2; + } } if (dynamic) { @@ -1524,6 +1531,8 @@ void CConfigManager::parseLine(std::string& line) { } void CConfigManager::loadConfigLoadVars() { + EMIT_HOOK_EVENT("preConfigReload", nullptr); + Debug::log(LOG, "Reloading the config!"); parseError = ""; // reset the error currentCategory = ""; // reset the category @@ -2312,8 +2321,13 @@ void CConfigManager::addPluginConfigVar(HANDLE handle, const std::string& name, } } +void CConfigManager::addPluginKeyword(HANDLE handle, const std::string& name, std::function fn) { + pluginKeywords.emplace_back(SPluginKeyword{handle, name, fn}); +} + void CConfigManager::removePluginConfig(HANDLE handle) { std::erase_if(pluginConfigs, [&](const auto& other) { return other.first == handle; }); + std::erase_if(pluginKeywords, [&](const auto& other) { return other.handle == handle; }); } std::string CConfigManager::getDefaultWorkspaceFor(const std::string& name) { diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index c6c726bf..f89ae72c 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "../Window.hpp" #include "../helpers/WLClasses.hpp" @@ -71,6 +72,12 @@ struct SAnimationPropertyConfig { SAnimationPropertyConfig* pParentAnimation = nullptr; }; +struct SPluginKeyword { + HANDLE handle = 0; + std::string name = ""; + std::function fn; +}; + struct SExecRequestedRule { std::string szRule = ""; uint64_t iPid = 0; @@ -120,7 +127,8 @@ class CConfigManager { std::unordered_map getAnimationConfig(); void addPluginConfigVar(HANDLE handle, const std::string& name, const SConfigValue& value); - void removePluginConfig(HANDLE handle); + void addPluginKeyword(HANDLE handle, const std::string& name, std::function fun); + void removePluginConfig(HANDLE handle); // no-op when done. void dispatchExecOnce(); @@ -163,6 +171,7 @@ class CConfigManager { std::vector m_vDeclaredPlugins; std::unordered_map>> pluginConfigs; // stores plugin configs + std::vector pluginKeywords; bool isFirstLaunch = true; // For exec-once diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index 8d2f6627..a873644e 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -160,6 +160,19 @@ APICALL bool HyprlandAPI::addConfigValue(HANDLE handle, const std::string& name, return true; } +APICALL bool HyprlandAPI::addConfigKeyword(HANDLE handle, const std::string& name, std::function fn) { + auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); + + if (!g_pPluginSystem->m_bAllowConfigVars) + return false; + + if (!PLUGIN) + return false; + + g_pConfigManager->addPluginKeyword(handle, name, fn); + return true; +} + APICALL SConfigValue* HyprlandAPI::getConfigValue(HANDLE handle, const std::string& name) { auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); diff --git a/src/plugins/PluginAPI.hpp b/src/plugins/PluginAPI.hpp index 36cdbe63..30c6b4c7 100644 --- a/src/plugins/PluginAPI.hpp +++ b/src/plugins/PluginAPI.hpp @@ -114,6 +114,14 @@ namespace HyprlandAPI { */ APICALL bool addConfigValue(HANDLE handle, const std::string& name, const SConfigValue& value); + /* + Add a config keyword. + This method may only be called in "pluginInit" + + returns: true on success, false on fail + */ + APICALL bool addConfigKeyword(HANDLE handle, const std::string& name, std::function fn); + /* Get a config value.