summaryrefslogtreecommitdiff
path: root/src/plugins
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
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')
-rw-r--r--src/plugins/PluginAPI.cpp65
-rw-r--r--src/plugins/PluginAPI.hpp43
-rw-r--r--src/plugins/PluginSystem.cpp7
-rw-r--r--src/plugins/PluginSystem.hpp8
4 files changed, 113 insertions, 10 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;
+}
diff --git a/src/plugins/PluginAPI.hpp b/src/plugins/PluginAPI.hpp
index 77bb9926..5321c8db 100644
--- a/src/plugins/PluginAPI.hpp
+++ b/src/plugins/PluginAPI.hpp
@@ -25,6 +25,7 @@ Feel like the API is missing something you'd like to use in your plugin? Open an
#include "../SharedDefs.hpp"
#include "../defines.hpp"
#include "../version.h"
+#include "../config/values/types/IValue.hpp"
#include <any>
#include <functional>
@@ -71,6 +72,9 @@ class IHyprLayout;
class IHyprWindowDecoration;
struct SConfigValue;
class Hypr_dummyClass {};
+extern "C" {
+struct lua_State;
+}
namespace Layout {
class ITiledAlgorithm;
@@ -78,6 +82,7 @@ namespace Layout {
};
using HOOK_CALLBACK_FN = Hypr_dummyClass;
+using PLUGIN_LUA_FN = int (*)(lua_State* L);
/*
These methods are for the plugin to implement
@@ -129,16 +134,20 @@ namespace HyprlandAPI {
After you have registered ALL of your config values, you may call `getConfigValue`
returns: true on success, false on fail
+
+ deprecated: please use V2
*/
- APICALL bool addConfigValue(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value);
+ APICALL [[deprecated]] bool addConfigValue(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value);
/*
Add a config keyword.
This method may only be called in "pluginInit"
returns: true on success, false on fail
+
+ deprecated: please use V2
*/
- APICALL bool addConfigKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fn, Hyprlang::SHandlerOptions opts);
+ APICALL [[deprecated]] bool addConfigKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fn, Hyprlang::SHandlerOptions opts);
/*
Get a config value.
@@ -147,8 +156,10 @@ namespace HyprlandAPI {
returns: a pointer to the config value struct, which is guaranteed to be valid for the life of this plugin, unless another `addConfigValue` is called afterwards.
nullptr on error.
+
+ Deprecated: please use V2
*/
- APICALL Hyprlang::CConfigValue* getConfigValue(HANDLE handle, const std::string& name);
+ APICALL [[deprecated]] Hyprlang::CConfigValue* getConfigValue(HANDLE handle, const std::string& name);
/*
Deprecated: doesn't do anything anymore, use Event::bus()
@@ -325,6 +336,32 @@ namespace HyprlandAPI {
returns: true on success. False otherwise.
*/
APICALL bool unregisterHyprCtlCommand(HANDLE handle, SP<SHyprCtlCommand> cmd);
+
+ /*
+ Add a new config value. Keep the pointer, you can use it for retrieving the value.
+
+ Please note this value name must start with plugin:, e.g. plugin:my_plugin:value
+
+ returns: true on success. False otherwise.
+ */
+ APICALL bool addConfigValueV2(HANDLE handle, SP<Config::Values::IValue> value);
+
+ /*
+ Register a plugin-owned Lua C callback under hl.plugin.<namespace>.<name>.
+
+ Callbacks are removed automatically on plugin unload.
+
+ returns: true on success. False otherwise.
+ */
+ APICALL bool addLuaFunction(HANDLE handle, const std::string& namespace_, const std::string& name, PLUGIN_LUA_FN fn);
+
+ /*
+ Unregister a plugin-owned Lua C callback from hl.plugin.<namespace>.<name>.
+
+ returns: true on success. False otherwise.
+ */
+ APICALL bool removeLuaFunction(HANDLE handle, const std::string& namespace_, const std::string& name);
+
};
// NOLINTBEGIN
diff --git a/src/plugins/PluginSystem.cpp b/src/plugins/PluginSystem.cpp
index 18b6adde..b39131a5 100644
--- a/src/plugins/PluginSystem.cpp
+++ b/src/plugins/PluginSystem.cpp
@@ -2,7 +2,7 @@
#include <dlfcn.h>
#include <ranges>
-#include "../config/legacy/ConfigManager.hpp"
+#include "../config/ConfigManager.hpp"
#include "../debug/HyprCtl.hpp"
#include "../managers/eventLoop/EventLoopManager.hpp"
#include "../managers/permissions/DynamicPermissionManager.hpp"
@@ -175,9 +175,8 @@ void CPluginSystem::unloadPlugin(const CPlugin* plugin, bool eject) {
HyprlandAPI::unregisterHyprCtlCommand(plugin->m_handle, sp);
}
- // FIXME: this is wrong and if I forget to fix this by the time I add another config parser
- // this will explode and I will be mad because I am a RETARD
- Config::Legacy::mgr()->removePluginConfig(plugin->m_handle);
+ if (Config::mgr())
+ Config::mgr()->onPluginUnload(plugin->m_handle);
// save these two for dlclose and a log,
// as erase_if will kill the pointer
diff --git a/src/plugins/PluginSystem.hpp b/src/plugins/PluginSystem.hpp
index 85afaefa..4921f0d6 100644
--- a/src/plugins/PluginSystem.hpp
+++ b/src/plugins/PluginSystem.hpp
@@ -3,6 +3,7 @@
#include "../defines.hpp"
#include "../helpers/defer/Promise.hpp"
#include "../helpers/time/Timer.hpp"
+#include "../config/values/types/IValue.hpp"
#include "PluginAPI.hpp"
#include "../managers/permissions/DynamicPermissionManager.hpp"
#include <csetjmp>
@@ -25,9 +26,10 @@ class CPlugin {
std::vector<IHyprWindowDecoration*> m_registeredDecorations;
//std::vector<std::pair<std::string, WP<HOOK_CALLBACK_FN>>> m_registeredCallbacks;
- std::vector<std::string> m_registeredDispatchers;
- std::vector<WP<SHyprCtlCommand>> m_registeredHyprctlCommands;
- std::vector<std::string> m_registeredAlgos;
+ std::vector<std::string> m_registeredDispatchers;
+ std::vector<WP<SHyprCtlCommand>> m_registeredHyprctlCommands;
+ std::vector<std::string> m_registeredAlgos;
+ std::vector<WP<Config::Values::IValue>> m_registeredApiValues;
};
class CPluginSystem {