diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 905cfb63..adb91d72 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1169,11 +1169,23 @@ std::unordered_map CConfigManager::getAni return animationConfig; } -void CConfigManager::addPluginConfigVar(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value) {} +void onPluginLoadUnload(const std::string& name, bool load) { + // +} -void CConfigManager::addPluginKeyword(HANDLE handle, const std::string& name, std::function fn) { +void CConfigManager::addPluginConfigVar(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value) { + if (!name.starts_with("plugin:")) + return; + + std::string field = name.substr(7); + + m_pConfig->addSpecialConfigValue("plugin:", field.c_str(), value); + pluginVariables.push_back({handle, field}); +} + +void CConfigManager::addPluginKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fn, Hyprlang::SHandlerOptions opts) { pluginKeywords.emplace_back(SPluginKeyword{handle, name, fn}); - // HYPRLANG_TODO: + m_pConfig->registerHandler(fn, name.c_str(), opts); } void CConfigManager::removePluginConfig(HANDLE handle) { @@ -1185,6 +1197,13 @@ void CConfigManager::removePluginConfig(HANDLE handle) { } std::erase_if(pluginKeywords, [&](const auto& other) { return other.handle == handle; }); + for (auto& [h, n] : pluginVariables) { + if (h != handle) + continue; + + m_pConfig->removeSpecialConfigValue("plugin:", n.c_str()); + } + std::erase_if(pluginVariables, [handle](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 6c8d21e6..5f258bc3 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -66,9 +66,14 @@ struct SAnimationPropertyConfig { }; struct SPluginKeyword { - HANDLE handle = 0; - std::string name = ""; - std::function fn; + HANDLE handle = 0; + std::string name = ""; + Hyprlang::PCONFIGHANDLERFUNC fn = nullptr; +}; + +struct SPluginVariable { + HANDLE handle = 0; + std::string name = ""; }; struct SExecRequestedRule { @@ -93,6 +98,7 @@ class CConfigManager { void* const* getConfigValuePtr(const std::string&); Hyprlang::CConfigValue* getHyprlangConfigValuePtr(const std::string&); + void onPluginLoadUnload(const std::string& name, bool load); static std::string getConfigDir(); static std::string getMainConfigPath(); @@ -112,7 +118,7 @@ class CConfigManager { std::unordered_map getAnimationConfig(); void addPluginConfigVar(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value); - void addPluginKeyword(HANDLE handle, const std::string& name, std::function fun); + void addPluginKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fun, Hyprlang::SHandlerOptions opts = {}); void removePluginConfig(HANDLE handle); // no-op when done. @@ -171,6 +177,7 @@ class CConfigManager { std::vector m_vDeclaredPlugins; std::vector pluginKeywords; + std::vector pluginVariables; bool isFirstLaunch = true; // For exec-once diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index f115f766..107a7115 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -163,7 +163,7 @@ 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) { +APICALL bool HyprlandAPI::addConfigKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fn, Hyprlang::SHandlerOptions opts) { auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); if (!g_pPluginSystem->m_bAllowConfigVars) @@ -172,7 +172,7 @@ APICALL bool HyprlandAPI::addConfigKeyword(HANDLE handle, const std::string& nam if (!PLUGIN) return false; - g_pConfigManager->addPluginKeyword(handle, name, fn); + g_pConfigManager->addPluginKeyword(handle, name, fn, opts); return true; } diff --git a/src/plugins/PluginAPI.hpp b/src/plugins/PluginAPI.hpp index 4832a582..c58d982e 100644 --- a/src/plugins/PluginAPI.hpp +++ b/src/plugins/PluginAPI.hpp @@ -120,7 +120,7 @@ namespace HyprlandAPI { returns: true on success, false on fail */ - APICALL bool addConfigKeyword(HANDLE handle, const std::string& name, std::function fn); + APICALL bool addConfigKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fn, Hyprlang::SHandlerOptions opts); /* Get a config value.