summaryrefslogtreecommitdiff
path: root/src/config/lua/bindings
diff options
context:
space:
mode:
Diffstat (limited to 'src/config/lua/bindings')
-rw-r--r--src/config/lua/bindings/LuaBindingsConfigRules.cpp18
-rw-r--r--src/config/lua/bindings/LuaBindingsInternal.cpp44
-rw-r--r--src/config/lua/bindings/LuaBindingsInternal.hpp14
3 files changed, 37 insertions, 39 deletions
diff --git a/src/config/lua/bindings/LuaBindingsConfigRules.cpp b/src/config/lua/bindings/LuaBindingsConfigRules.cpp
index 88761f05..52ecaf69 100644
--- a/src/config/lua/bindings/LuaBindingsConfigRules.cpp
+++ b/src/config/lua/bindings/LuaBindingsConfigRules.cpp
@@ -1076,21 +1076,9 @@ static int hlWindowRule(lua_State* L) {
continue;
}
- auto val = UP<ILuaConfigValue>(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)
- self->addError(std::format("{}: hl.window_rule: field '{}': {}", sourceInfo, key, res.error()));
- } else
- self->addError(std::format("{}: hl.window_rule: field '{}': {}", sourceInfo, key, err.message));
- } else {
- auto res = rule->addEffect(desc->effect, val->toString());
- if (!res)
- self->addError(std::format("{}: hl.window_rule: field '{}': {}", sourceInfo, key, res.error()));
- }
+ auto res = Internal::addWindowRuleEffectFromLua(L, *desc, rule);
+ if (!res)
+ self->addError(std::format("{}: hl.window_rule: field '{}': {}", sourceInfo, key, res.error()));
lua_pop(L, 1);
}
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<std::string, std::string> Internal::ruleValueToString(lua_State* L
return std::unexpected("value must be a string, bool, or number");
}
+std::expected<void, std::string> Internal::addWindowRuleEffectFromLua(lua_State* L, const SWindowRuleEffectDesc& desc, const SP<Desktop::Rule::CWindowRule>& rule) {
+ auto val = UP<ILuaConfigValue>(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<CLuaConfigExpressionVec2*>(val.get()); expr)
+ return rule->addEffect(desc.effect, expr->parsed());
+
+ return rule->addEffect(desc.effect, val->toString());
+}
+
std::expected<SP<Desktop::Rule::CWindowRule>, int> Internal::buildRuleFromTable(lua_State* L, int idx) {
SP<Desktop::Rule::CWindowRule> rule;
@@ -538,26 +558,10 @@ std::expected<SP<Desktop::Rule::CWindowRule>, int> Internal::buildRuleFromTable(
continue;
}
- auto val = UP<ILuaConfigValue>(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;
diff --git a/src/config/lua/bindings/LuaBindingsInternal.hpp b/src/config/lua/bindings/LuaBindingsInternal.hpp
index fc07515f..5d4a8d87 100644
--- a/src/config/lua/bindings/LuaBindingsInternal.hpp
+++ b/src/config/lua/bindings/LuaBindingsInternal.hpp
@@ -10,6 +10,7 @@
#include "../types/LuaConfigInt.hpp"
#include "../types/LuaConfigString.hpp"
#include "../types/LuaConfigVec2.hpp"
+#include "../types/LuaConfigExpressionVec2.hpp"
#include "../../../Compositor.hpp"
#include "../../../helpers/MiscFunctions.hpp"
@@ -31,6 +32,10 @@ extern "C" {
#include <lauxlib.h>
}
+namespace Desktop::Rule {
+ class CWindowRule;
+}
+
namespace Config::Lua::Bindings::Internal {
struct SWindowRuleEffectDesc {
@@ -51,8 +56,8 @@ namespace Config::Lua::Bindings::Internal {
{"no_initial_focus", []() -> ILuaConfigValue* { return new CLuaConfigBool(false); }, WE::WINDOW_RULE_EFFECT_NOINITIALFOCUS},
{"pin", []() -> ILuaConfigValue* { return new CLuaConfigBool(false); }, WE::WINDOW_RULE_EFFECT_PIN},
{"fullscreen_state", []() -> ILuaConfigValue* { return new CLuaConfigString(STRVAL_EMPTY); }, WE::WINDOW_RULE_EFFECT_FULLSCREENSTATE},
- {"move", []() -> ILuaConfigValue* { return new CLuaConfigString(STRVAL_EMPTY); }, WE::WINDOW_RULE_EFFECT_MOVE},
- {"size", []() -> ILuaConfigValue* { return new CLuaConfigString(STRVAL_EMPTY); }, WE::WINDOW_RULE_EFFECT_SIZE},
+ {"move", []() -> ILuaConfigValue* { return new CLuaConfigExpressionVec2(); }, WE::WINDOW_RULE_EFFECT_MOVE},
+ {"size", []() -> ILuaConfigValue* { return new CLuaConfigExpressionVec2(); }, WE::WINDOW_RULE_EFFECT_SIZE},
{"monitor", []() -> ILuaConfigValue* { return new CLuaConfigString(STRVAL_EMPTY); }, WE::WINDOW_RULE_EFFECT_MONITOR},
{"workspace", []() -> ILuaConfigValue* { return new CLuaConfigString(STRVAL_EMPTY); }, WE::WINDOW_RULE_EFFECT_WORKSPACE},
{"group", []() -> ILuaConfigValue* { return new CLuaConfigString(STRVAL_EMPTY); }, WE::WINDOW_RULE_EFFECT_GROUP},
@@ -69,8 +74,8 @@ namespace Config::Lua::Bindings::Internal {
{"idle_inhibit", []() -> ILuaConfigValue* { return new CLuaConfigString(STRVAL_EMPTY); }, WE::WINDOW_RULE_EFFECT_IDLE_INHIBIT},
{"opacity", []() -> ILuaConfigValue* { return new CLuaConfigString(STRVAL_EMPTY); }, WE::WINDOW_RULE_EFFECT_OPACITY},
{"tag", []() -> ILuaConfigValue* { return new CLuaConfigString(STRVAL_EMPTY); }, WE::WINDOW_RULE_EFFECT_TAG},
- {"max_size", []() -> ILuaConfigValue* { return new CLuaConfigVec2({0, 0}); }, WE::WINDOW_RULE_EFFECT_MAX_SIZE},
- {"min_size", []() -> ILuaConfigValue* { return new CLuaConfigVec2({0, 0}); }, WE::WINDOW_RULE_EFFECT_MIN_SIZE},
+ {"max_size", []() -> ILuaConfigValue* { return new CLuaConfigExpressionVec2(); }, WE::WINDOW_RULE_EFFECT_MAX_SIZE},
+ {"min_size", []() -> ILuaConfigValue* { return new CLuaConfigExpressionVec2(); }, WE::WINDOW_RULE_EFFECT_MIN_SIZE},
{"border_color", []() -> ILuaConfigValue* { return new CLuaConfigGradient(CHyprColor(0xFF000000)); }, WE::WINDOW_RULE_EFFECT_BORDER_COLOR},
{"persistent_size", []() -> ILuaConfigValue* { return new CLuaConfigBool(false); }, WE::WINDOW_RULE_EFFECT_PERSISTENT_SIZE},
{"allows_input", []() -> ILuaConfigValue* { return new CLuaConfigBool(false); }, WE::WINDOW_RULE_EFFECT_ALLOWS_INPUT},
@@ -140,6 +145,7 @@ namespace Config::Lua::Bindings::Internal {
Config::Actions::eTogglableAction tableToggleAction(lua_State* L, int idx, const char* field = "action");
std::expected<std::string, std::string> ruleValueToString(lua_State* L);
+ std::expected<void, std::string> addWindowRuleEffectFromLua(lua_State* L, const SWindowRuleEffectDesc& desc, const SP<Desktop::Rule::CWindowRule>& rule);
std::expected<SP<Desktop::Rule::CWindowRule>, int> buildRuleFromTable(lua_State* L, int idx);
int configError(lua_State* L, std::string s, Config::Actions::eActionErrorLevel level = Config::Actions::eActionErrorLevel::ERROR,