diff options
| author | Vaxry <vaxry@vaxry.net> | 2026-04-28 15:42:09 +0100 |
|---|---|---|
| committer | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2026-04-28 16:52:41 +0100 |
| commit | cbefb357a57ce5f6dd161a400a5867609022ee66 (patch) | |
| tree | 446a9491200c0d495ab82562247d96b4e1af5b99 /src/config | |
| parent | 98fbbafef78057c818fb02b15c27e38ad2f5b5bc (diff) | |
desktop/windowRule: use variants for storage internally
Improves storage: less dynamic parsing, immediate config errors, faster.
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/legacy/ConfigManager.cpp | 11 | ||||
| -rw-r--r-- | src/config/lua/bindings/LuaBindingsConfigRules.cpp | 22 | ||||
| -rw-r--r-- | src/config/lua/bindings/LuaBindingsInternal.cpp | 25 | ||||
| -rw-r--r-- | src/config/supplementary/executor/Executor.cpp | 8 |
4 files changed, 48 insertions, 18 deletions
diff --git a/src/config/legacy/ConfigManager.cpp b/src/config/legacy/ConfigManager.cpp index a19993f0..5d74528d 100644 --- a/src/config/legacy/ConfigManager.cpp +++ b/src/config/legacy/ConfigManager.cpp @@ -895,8 +895,11 @@ std::optional<std::string> CConfigManager::addRuleFromConfigKey(const std::strin for (const auto& e : Desktop::Rule::windowEffects()->allEffectStrings()) { auto VAL = m_config->getSpecialConfigValuePtr("windowrule", e.c_str(), name.c_str()); - if (VAL && VAL->m_bSetByUser) - rule->addEffect(Desktop::Rule::windowEffects()->get(e).value_or(Desktop::Rule::WINDOW_RULE_EFFECT_NONE), std::any_cast<Hyprlang::STRING>(VAL->getValue())); + if (VAL && VAL->m_bSetByUser) { + auto res = rule->addEffect(Desktop::Rule::windowEffects()->get(e).value_or(Desktop::Rule::WINDOW_RULE_EFFECT_NONE), std::any_cast<Hyprlang::STRING>(VAL->getValue())); + if (!res) + return res.error(); + } } Desktop::Rule::ruleEngine()->registerRule(std::move(rule)); @@ -1981,7 +1984,9 @@ std::optional<std::string> CConfigManager::handleWindowrule(const std::string& c const auto EFFECT = Desktop::Rule::windowEffects()->get(FIRST); if (!EFFECT.has_value()) return std::format("invalid effect {}", el); - rule->addEffect(*EFFECT, std::string{el.substr(spacePos + 1)}); + auto res = rule->addEffect(*EFFECT, std::string{el.substr(spacePos + 1)}); + if (!res) + return res.error(); } else return std::format("invalid field type {}", FIRST); } diff --git a/src/config/lua/bindings/LuaBindingsConfigRules.cpp b/src/config/lua/bindings/LuaBindingsConfigRules.cpp index 2faab8c6..4f9fc861 100644 --- a/src/config/lua/bindings/LuaBindingsConfigRules.cpp +++ b/src/config/lua/bindings/LuaBindingsConfigRules.cpp @@ -1066,8 +1066,11 @@ static int hlWindowRule(lua_State* L) { auto val = Internal::ruleValueToString(L); if (!val) self->addError(std::format("{}: hl.window_rule: field '{}': {}", sourceInfo, key, val.error())); - else - rule->addEffect(*dynamicEffect, *val); + else { + auto res = rule->addEffect(*dynamicEffect, *val); + if (!res) + self->addError(std::format("{}: hl.window_rule: field '{}': {}", sourceInfo, key, res.error())); + } lua_pop(L, 1); continue; @@ -1077,12 +1080,17 @@ static int hlWindowRule(lua_State* L) { 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) - rule->addEffect(desc->effect, lua_tostring(L, -1)); - else + 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 - rule->addEffect(desc->effect, val->toString()); + } else { + auto res = rule->addEffect(desc->effect, val->toString()); + 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 02b7c060..e5a65bf7 100644 --- a/src/config/lua/bindings/LuaBindingsInternal.cpp +++ b/src/config/lua/bindings/LuaBindingsInternal.cpp @@ -527,7 +527,11 @@ std::expected<SP<Desktop::Rule::CWindowRule>, int> Internal::buildRuleFromTable( return std::unexpected(Internal::configError(L, "buildRuleFromTable: effect '{}': {}", key, val.error())); } - rule->addEffect(*dynamicEffect, *val); + auto res = rule->addEffect(*dynamicEffect, *val); + if (!res) { + lua_pop(L, 1); + return std::unexpected(Internal::configError(L, "buildRuleFromTable: effect '{}': {}", key, res.error())); + } hasRuleEffects = true; lua_pop(L, 1); @@ -538,14 +542,23 @@ std::expected<SP<Desktop::Rule::CWindowRule>, int> Internal::buildRuleFromTable( 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) - rule->addEffect(desc->effect, lua_tostring(L, -1)); - else { + 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 - rule->addEffect(desc->effect, val->toString()); + } 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())); + } + } hasRuleEffects = true; lua_pop(L, 1); diff --git a/src/config/supplementary/executor/Executor.cpp b/src/config/supplementary/executor/Executor.cpp index 70b47a69..b5d3a021 100644 --- a/src/config/supplementary/executor/Executor.cpp +++ b/src/config/supplementary/executor/Executor.cpp @@ -123,7 +123,11 @@ std::optional<uint64_t> CExecutor::spawnWithRules(std::string args, PHLWORKSPACE std::string execToken = ""; if (!RULES.empty()) { - auto rule = Desktop::Rule::CWindowRule::buildFromExecString(std::move(RULES)); + auto rule = Desktop::Rule::CWindowRule::buildFromExecString(std::move(RULES)); + if (!rule) { + Log::logger->log(Log::ERR, "Failed to parse exec rule: {}", rule.error()); + return std::nullopt; + } const auto TOKEN = g_pTokenManager->registerNewToken(nullptr, std::chrono::seconds(1)); @@ -132,7 +136,7 @@ std::optional<uint64_t> CExecutor::spawnWithRules(std::string args, PHLWORKSPACE if (!PROC) return std::nullopt; - applyRuleToProc(rule, *PROC, TOKEN); + applyRuleToProc(*rule, *PROC, TOKEN); return PROC; } |
