summaryrefslogtreecommitdiff
path: root/src/plugins/PluginAPI.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2026-04-26 15:16:36 +0100
committerGitHub <noreply@github.com>2026-04-26 15:16:36 +0100
commit5ba33f846129f3e6c0505b19f94634b24505e828 (patch)
treeaaacabe678006040c342935481a86607c66607fd /src/plugins/PluginAPI.cpp
parent329b2b356dd92ac07f4e2aa69cbce82ee9ba9d19 (diff)
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.
Diffstat (limited to 'src/plugins/PluginAPI.cpp')
-rw-r--r--src/plugins/PluginAPI.cpp65
1 files changed, 65 insertions, 0 deletions
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<SHyprCtlCom
return true;
}
+
+APICALL bool HyprlandAPI::addConfigValueV2(HANDLE handle, SP<Config::Values::IValue> 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<Config::Lua::CConfigManager>(WP<Config::IConfigManager>(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<Config::Lua::CConfigManager>(WP<Config::IConfigManager>(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;
+}