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/config/lua/objects/LuaWindowRule.cpp | 80 ++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/config/lua/objects/LuaWindowRule.cpp (limited to 'src/config/lua/objects/LuaWindowRule.cpp') diff --git a/src/config/lua/objects/LuaWindowRule.cpp b/src/config/lua/objects/LuaWindowRule.cpp new file mode 100644 index 00000000..63fd1a2c --- /dev/null +++ b/src/config/lua/objects/LuaWindowRule.cpp @@ -0,0 +1,80 @@ +#include "LuaWindowRule.hpp" + +#include "../../../desktop/rule/Engine.hpp" + +#include + +using namespace Config::Lua; + +static constexpr const char* MT = "HL.WindowRule"; + +// +static int windowRuleEq(lua_State* L) { + const auto* lhs = sc*>(luaL_checkudata(L, 1, MT)); + const auto* rhs = sc*>(luaL_checkudata(L, 2, MT)); + + lua_pushboolean(L, lhs->lock() == rhs->lock()); + return 1; +} + +static int windowRuleToString(lua_State* L) { + const auto* ref = sc*>(luaL_checkudata(L, 1, MT)); + const auto rule = ref->lock(); + + if (!rule) + lua_pushstring(L, "HL.WindowRule(expired)"); + else + lua_pushfstring(L, "HL.WindowRule(%p)", rule.get()); + + return 1; +} + +static int windowRuleSetEnabled(lua_State* L) { + auto* ref = sc*>(luaL_checkudata(L, 1, MT)); + luaL_checktype(L, 2, LUA_TBOOLEAN); + + const auto rule = ref->lock(); + if (!rule) + return 0; + + rule->setEnabled(lua_toboolean(L, 2)); + Desktop::Rule::ruleEngine()->updateAllRules(); + return 0; +} + +static int windowRuleIsEnabled(lua_State* L) { + auto* ref = sc*>(luaL_checkudata(L, 1, MT)); + + const auto rule = ref->lock(); + if (!rule) { + lua_pushnil(L); + return 1; + } + + lua_pushboolean(L, rule->isEnabled()); + return 1; +} + +static int windowRuleIndex(lua_State* L) { + luaL_checkudata(L, 1, MT); + const std::string_view key = luaL_checkstring(L, 2); + + if (key == "set_enabled") + lua_pushcfunction(L, windowRuleSetEnabled); + else if (key == "is_enabled") + lua_pushcfunction(L, windowRuleIsEnabled); + else + lua_pushnil(L); + + return 1; +} + +void Objects::CLuaWindowRule::setup(lua_State* L) { + registerMetatable(L, MT, windowRuleIndex, gcRef>, windowRuleEq, windowRuleToString); +} + +void Objects::CLuaWindowRule::push(lua_State* L, const SP& rule) { + new (lua_newuserdata(L, sizeof(WP))) WP(rule); + luaL_getmetatable(L, MT); + lua_setmetatable(L, -2); +} -- cgit v1.2.3