From 94b90a2cb0b4a0e13018cd5ebbf09394abf3b96b Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Tue, 28 Apr 2026 18:10:25 +0100 Subject: config/lua: add ExpressionVec2, allow using a table for vec2 rules (#14197) --- src/config/lua/bindings/LuaBindingsInternal.cpp | 44 ++++++++++++++----------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'src/config/lua/bindings/LuaBindingsInternal.cpp') diff --git a/src/config/lua/bindings/LuaBindingsInternal.cpp b/src/config/lua/bindings/LuaBindingsInternal.cpp index e5a65bf7..a6af42f8 100644 --- a/src/config/lua/bindings/LuaBindingsInternal.cpp +++ b/src/config/lua/bindings/LuaBindingsInternal.cpp @@ -1,5 +1,7 @@ #include "LuaBindingsInternal.hpp" +#include "../../../desktop/rule/windowRule/WindowRule.hpp" + using namespace Config; using namespace Config::Lua; using namespace Config::Lua::Bindings; @@ -489,6 +491,24 @@ std::expected Internal::ruleValueToString(lua_State* L return std::unexpected("value must be a string, bool, or number"); } +std::expected Internal::addWindowRuleEffectFromLua(lua_State* L, const SWindowRuleEffectDesc& desc, const SP& rule) { + auto val = UP(desc.factory()); + auto err = val->parse(L); + + if (err.errorCode != PARSE_ERROR_OK) { + const bool allowLegacyString = desc.effect == WE::WINDOW_RULE_EFFECT_BORDER_COLOR && lua_isstring(L, -1); + if (!allowLegacyString) + return std::unexpected(err.message); + + return rule->addEffect(desc.effect, lua_tostring(L, -1)); + } + + if (const auto expr = dc(val.get()); expr) + return rule->addEffect(desc.effect, expr->parsed()); + + return rule->addEffect(desc.effect, val->toString()); +} + std::expected, int> Internal::buildRuleFromTable(lua_State* L, int idx) { SP rule; @@ -538,26 +558,10 @@ std::expected, int> Internal::buildRuleFromTable( continue; } - auto val = UP(desc->factory()); - auto err = val->parse(L); - if (err.errorCode != PARSE_ERROR_OK) { - const bool allowLegacyString = (key == "max_size" || key == "min_size" || key == "border_color") && lua_isstring(L, -1); - if (allowLegacyString) { - auto res = rule->addEffect(desc->effect, lua_tostring(L, -1)); - if (!res) { - lua_pop(L, 1); - return std::unexpected(Internal::configError(L, "buildRuleFromTable: effect '{}': {}", key, res.error())); - } - } else { - lua_pop(L, 1); - return std::unexpected(Internal::configError(L, "buildRuleFromTable: effect '{}': {}", key, err.message)); - } - } else { - auto res = rule->addEffect(desc->effect, val->toString()); - if (!res) { - lua_pop(L, 1); - return std::unexpected(Internal::configError(L, "buildRuleFromTable: effect '{}': {}", key, res.error())); - } + auto res = Internal::addWindowRuleEffectFromLua(L, *desc, rule); + if (!res) { + lua_pop(L, 1); + return std::unexpected(Internal::configError(L, "buildRuleFromTable: effect '{}': {}", key, res.error())); } hasRuleEffects = true; -- cgit v1.2.3