desktop/windowRule: allow expression in min_size/max_size (#12977)
This commit is contained in:
parent
e7985ca4c4
commit
22fc8136a2
4 changed files with 48 additions and 10 deletions
|
|
@ -77,6 +77,16 @@ static bool testGetprop() {
|
|||
EXPECT(getCommandStdOut("hyprctl getprop class:kitty min_size"), "100 50");
|
||||
EXPECT(getCommandStdOut("hyprctl getprop class:kitty min_size -j"), R"({"min_size": [100,50]})");
|
||||
|
||||
// expr-based min/max _size
|
||||
getFromSocket("/dispatch setfloating class:kitty"); // need to set floating for tests below
|
||||
getFromSocket("/dispatch setprop class:kitty max_size 90+10 25*2"); // set max to the same as min above, forcing window to 100*50
|
||||
EXPECT(getCommandStdOut("hyprctl getprop class:kitty max_size"), "100 50");
|
||||
EXPECT(getCommandStdOut("hyprctl getprop class:kitty max_size -j"), R"({"max_size": [100,50]})");
|
||||
getFromSocket("/dispatch setprop class:kitty min_size window_w*0.5 window_h-10");
|
||||
EXPECT(getCommandStdOut("hyprctl getprop class:kitty min_size"), "50 40");
|
||||
EXPECT(getCommandStdOut("hyprctl getprop class:kitty min_size -j"), R"({"min_size": [50,40]})");
|
||||
getFromSocket("/dispatch settiled class:kitty"); // go back to tiled for consistency
|
||||
|
||||
// opacity
|
||||
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity"), "1");
|
||||
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity -j"), R"({"opacity": 1})");
|
||||
|
|
|
|||
|
|
@ -970,7 +970,8 @@ static bool test() {
|
|||
Tests::killAllWindows();
|
||||
|
||||
// test expression rules
|
||||
OK(getFromSocket("/keyword windowrule match:class expr_kitty, float yes, size monitor_w*0.5 monitor_h*0.5, move 20+(monitor_w*0.1) monitor_h*0.5"));
|
||||
OK(getFromSocket("/keyword windowrule match:class expr_kitty, float yes, size monitor_w*0.5 monitor_h*0.5, min_size monitor_w*0.25 monitor_h*0.25, "
|
||||
"max_size monitor_w*0.75 monitor_h*0.75, move 20+(monitor_w*0.1) monitor_h*0.5"));
|
||||
|
||||
if (!spawnKitty("expr_kitty"))
|
||||
return false;
|
||||
|
|
@ -980,6 +981,14 @@ static bool test() {
|
|||
EXPECT_CONTAINS(str, "floating: 1");
|
||||
EXPECT_CONTAINS(str, "at: 212,540");
|
||||
EXPECT_CONTAINS(str, "size: 960,540");
|
||||
|
||||
auto min = getFromSocket("/getprop active min_size");
|
||||
EXPECT_CONTAINS(min, "480");
|
||||
EXPECT_CONTAINS(min, "270");
|
||||
|
||||
auto max = getFromSocket("/getprop active max_size");
|
||||
EXPECT_CONTAINS(max, "1440");
|
||||
EXPECT_CONTAINS(max, "810");
|
||||
}
|
||||
|
||||
OK(getFromSocket("/reload"));
|
||||
|
|
|
|||
|
|
@ -265,13 +265,17 @@ CWindowRuleApplicator::SRuleResult CWindowRuleApplicator::applyDynamicRule(const
|
|||
if (!m_window)
|
||||
break;
|
||||
|
||||
const auto VEC = configStringToVector2D(effect);
|
||||
if (VEC.x < 1 || VEC.y < 1) {
|
||||
const auto VEC = m_window->calculateExpression(effect);
|
||||
if (!VEC) {
|
||||
Log::logger->log(Log::ERR, "failed to parse {} as an expression", effect);
|
||||
break;
|
||||
}
|
||||
if (VEC->x < 1 || VEC->y < 1) {
|
||||
Log::logger->log(Log::ERR, "Invalid size for maxsize");
|
||||
break;
|
||||
}
|
||||
|
||||
m_maxSize.first = Types::COverridableVar(VEC, Types::PRIORITY_WINDOW_RULE);
|
||||
m_maxSize.first = Types::COverridableVar(*VEC, Types::PRIORITY_WINDOW_RULE);
|
||||
|
||||
if (*PCLAMP_TILED || m_window->m_isFloating)
|
||||
m_window->clampWindowSize(std::nullopt, m_maxSize.first.value());
|
||||
|
|
@ -286,13 +290,18 @@ CWindowRuleApplicator::SRuleResult CWindowRuleApplicator::applyDynamicRule(const
|
|||
if (!m_window)
|
||||
break;
|
||||
|
||||
const auto VEC = configStringToVector2D(effect);
|
||||
if (VEC.x < 1 || VEC.y < 1) {
|
||||
const auto VEC = m_window->calculateExpression(effect);
|
||||
if (!VEC) {
|
||||
Log::logger->log(Log::ERR, "failed to parse {} as an expression", effect);
|
||||
break;
|
||||
}
|
||||
|
||||
if (VEC->x < 1 || VEC->y < 1) {
|
||||
Log::logger->log(Log::ERR, "Invalid size for maxsize");
|
||||
break;
|
||||
}
|
||||
|
||||
m_minSize.first = Types::COverridableVar(VEC, Types::PRIORITY_WINDOW_RULE);
|
||||
m_minSize.first = Types::COverridableVar(*VEC, Types::PRIORITY_WINDOW_RULE);
|
||||
if (*PCLAMP_TILED || m_window->m_isFloating)
|
||||
m_window->clampWindowSize(m_minSize.first.value(), std::nullopt);
|
||||
} catch (std::exception& e) { Log::logger->log(Log::ERR, "minsize rule \"{}\" failed with: {}", effect, e.what()); }
|
||||
|
|
|
|||
|
|
@ -3164,12 +3164,22 @@ SDispatchResult CKeybindManager::setProp(std::string args) {
|
|||
|
||||
try {
|
||||
if (PROP == "max_size") {
|
||||
PWINDOW->m_ruleApplicator->maxSizeOverride(Desktop::Types::COverridableVar(configStringToVector2D(VAL), Desktop::Types::PRIORITY_SET_PROP));
|
||||
const auto SIZE = PWINDOW->calculateExpression(VAL);
|
||||
if (!SIZE) {
|
||||
Log::logger->log(Log::ERR, "failed to parse {} as an expression", VAL);
|
||||
throw "failed to parse expression";
|
||||
}
|
||||
PWINDOW->m_ruleApplicator->maxSizeOverride(Desktop::Types::COverridableVar(*SIZE, Desktop::Types::PRIORITY_SET_PROP));
|
||||
PWINDOW->clampWindowSize(std::nullopt, PWINDOW->m_ruleApplicator->maxSize().value());
|
||||
PWINDOW->setHidden(false);
|
||||
} else if (PROP == "min_size") {
|
||||
PWINDOW->m_ruleApplicator->minSizeOverride(Desktop::Types::COverridableVar(configStringToVector2D(VAL), Desktop::Types::PRIORITY_SET_PROP));
|
||||
PWINDOW->clampWindowSize(std::nullopt, PWINDOW->m_ruleApplicator->minSize().value());
|
||||
const auto SIZE = PWINDOW->calculateExpression(VAL);
|
||||
if (!SIZE) {
|
||||
Log::logger->log(Log::ERR, "failed to parse {} as an expression", VAL);
|
||||
throw "failed to parse expression";
|
||||
}
|
||||
PWINDOW->m_ruleApplicator->minSizeOverride(Desktop::Types::COverridableVar(*SIZE, Desktop::Types::PRIORITY_SET_PROP));
|
||||
PWINDOW->clampWindowSize(PWINDOW->m_ruleApplicator->minSize().value(), std::nullopt);
|
||||
PWINDOW->setHidden(false);
|
||||
} else if (PROP == "active_border_color" || PROP == "inactive_border_color") {
|
||||
CGradientValueData colorData = {};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue