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.hpp | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'src/plugins/PluginAPI.hpp') 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 #include @@ -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 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 value); + + /* + Register a plugin-owned Lua C callback under hl.plugin... + + 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... + + returns: true on success. False otherwise. + */ + APICALL bool removeLuaFunction(HANDLE handle, const std::string& namespace_, const std::string& name); + }; // NOLINTBEGIN -- cgit v1.2.3