From 5ba33f846129f3e6c0505b19f94634b24505e828 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sun, 26 Apr 2026 15:16:36 +0100 Subject: config/lua: init lua config manager, use lua if available (#13817) Adds a new lua config manager, which will automatically be used if there is a lua config present. --- src/plugins/PluginAPI.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'src/plugins/PluginAPI.cpp') diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index 4722924d..c49fa0a0 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -4,6 +4,7 @@ #include "../plugins/PluginSystem.hpp" #include "../managers/eventLoop/EventLoopManager.hpp" #include "../config/legacy/ConfigManager.hpp" +#include "../config/lua/ConfigManager.hpp" #include "../notification/NotificationOverlay.hpp" #include "../layout/target/Target.hpp" #include "../layout/supplementary/WorkspaceAlgoMatcher.hpp" @@ -175,6 +176,9 @@ APICALL bool HyprlandAPI::removeWindowDecoration(HANDLE handle, IHyprWindowDecor APICALL bool HyprlandAPI::addConfigValue(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value) { auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); + if (Config::mgr()->type() != Config::CONFIG_LEGACY) + return false; + if (!g_pPluginSystem->m_allowConfigVars) return false; @@ -191,6 +195,9 @@ APICALL bool HyprlandAPI::addConfigValue(HANDLE handle, const std::string& name, APICALL bool HyprlandAPI::addConfigKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fn, Hyprlang::SHandlerOptions opts) { auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); + if (Config::mgr()->type() != Config::CONFIG_LEGACY) + return false; + if (!g_pPluginSystem->m_allowConfigVars) return false; @@ -204,6 +211,9 @@ APICALL bool HyprlandAPI::addConfigKeyword(HANDLE handle, const std::string& nam APICALL Hyprlang::CConfigValue* HyprlandAPI::getConfigValue(HANDLE handle, const std::string& name) { auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); + if (Config::mgr()->type() != Config::CONFIG_LEGACY) + return nullptr; + if (!PLUGIN) return nullptr; @@ -431,3 +441,58 @@ APICALL bool HyprlandAPI::unregisterHyprCtlCommand(HANDLE handle, SP value) { + auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); + + if (!PLUGIN) + return false; + + PLUGIN->m_registeredApiValues.emplace_back(value); + + auto ret = Config::mgr()->registerPluginValue(handle, value); + if (!ret) { + Log::logger->log(Log::ERR, "failed to register plugin value \"{}\": {}", value->name(), ret.error()); + return false; + } + + value->commence(); + + return true; +} + +APICALL bool HyprlandAPI::addLuaFunction(HANDLE handle, const std::string& namespace_, const std::string& name, PLUGIN_LUA_FN fn) { + auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); + + if (!PLUGIN) + return false; + + if (!Config::mgr() || Config::mgr()->type() != Config::CONFIG_LUA) + return false; + + auto ret = dynamicPointerCast(WP(Config::mgr()))->registerPluginLuaFunction(handle, namespace_, name, fn); + if (!ret) { + Log::logger->log(Log::ERR, "failed to register lua plugin function {}.{}: {}", namespace_, name, ret.error()); + return false; + } + + return true; +} + +APICALL bool HyprlandAPI::removeLuaFunction(HANDLE handle, const std::string& namespace_, const std::string& name) { + auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); + + if (!PLUGIN) + return false; + + if (!Config::mgr() || Config::mgr()->type() != Config::CONFIG_LUA) + return false; + + auto ret = dynamicPointerCast(WP(Config::mgr()))->unregisterPluginLuaFunction(handle, namespace_, name); + if (!ret) { + Log::logger->log(Log::ERR, "failed to unregister lua plugin function {}.{}: {}", namespace_, name, ret.error()); + return false; + } + + return true; +} -- cgit v1.2.3