From 9f599e316504943eec5d2fa854f7c99c575616b7 Mon Sep 17 00:00:00 2001 From: ItsOhen Date: Tue, 17 Mar 2026 17:43:53 +0100 Subject: window/rules: add scrolling_width (#13754) --- hyprtester/src/tests/main/scroll.cpp | 30 ++++++++++++++++++++++ .../rule/windowRule/WindowRuleApplicator.cpp | 6 +++++ .../rule/windowRule/WindowRuleApplicator.hpp | 1 + .../rule/windowRule/WindowRuleEffectContainer.cpp | 3 ++- .../rule/windowRule/WindowRuleEffectContainer.hpp | 3 ++- src/desktop/view/Window.cpp | 4 +-- .../tiled/scrolling/ScrollingAlgorithm.cpp | 13 +++++----- .../tiled/scrolling/ScrollingAlgorithm.hpp | 4 +-- 8 files changed, 52 insertions(+), 12 deletions(-) diff --git a/hyprtester/src/tests/main/scroll.cpp b/hyprtester/src/tests/main/scroll.cpp index 8bb950dd..3662f965 100644 --- a/hyprtester/src/tests/main/scroll.cpp +++ b/hyprtester/src/tests/main/scroll.cpp @@ -198,6 +198,34 @@ static void testSwapcolWrapping() { Tests::killAllWindows(); } +static bool testWindowRule() { + NLog::log("{}Testing Scrolling Width", Colors::GREEN); + + // inject a new rule. + OK(getFromSocket("/keyword windowrule[scrolling-width]:match:class kitty_scroll")); + OK(getFromSocket("/keyword windowrule[scrolling-width]:scrolling_width 0.1")); + + if (!Tests::spawnKitty("kitty_scroll")) { + NLog::log("{}Failed to spawn kitty with win class `kitty_scroll`", Colors::RED); + return false; + } + + if (!Tests::spawnKitty("kitty_scroll")) { + NLog::log("{}Failed to spawn kitty with win class `kitty_scroll`", Colors::RED); + return false; + } + + EXPECT(Tests::windowCount(), 2); + + // not the greatest test, but as long as res and gaps don't change, we good. + EXPECT_CONTAINS(getFromSocket("/activewindow"), "size: 174,1036"); + + NLog::log("{}Killing all windows", Colors::YELLOW); + Tests::killAllWindows(); + EXPECT(Tests::windowCount(), 0); + return true; +} + static bool test() { NLog::log("{}Testing Scroll layout", Colors::GREEN); @@ -217,6 +245,8 @@ static bool test() { NLog::log("{}Testing swapcol wrap", Colors::GREEN); testSwapcolWrapping(); + testWindowRule(); + // clean up NLog::log("Cleaning up", Colors::YELLOW); OK(getFromSocket("/dispatch workspace 1")); diff --git a/src/desktop/rule/windowRule/WindowRuleApplicator.cpp b/src/desktop/rule/windowRule/WindowRuleApplicator.cpp index dd0e7fb8..bb2499e7 100644 --- a/src/desktop/rule/windowRule/WindowRuleApplicator.cpp +++ b/src/desktop/rule/windowRule/WindowRuleApplicator.cpp @@ -541,6 +541,12 @@ CWindowRuleApplicator::SRuleResult CWindowRuleApplicator::applyStaticRule(const } catch (...) { Log::logger->log(Log::ERR, "CWindowRuleApplicator::applyStaticRule: invalid no close for {}", effect); } break; } + case WINDOW_RULE_EFFECT_SCROLLING_WIDTH: { + try { + static_.scrollingWidth = std::stof(effect); + } catch (...) { Log::logger->log(Log::ERR, "CWindowRuleApplicator::applyStaticRule: invalid scrolling width {}", effect); } + break; + } } } diff --git a/src/desktop/rule/windowRule/WindowRuleApplicator.hpp b/src/desktop/rule/windowRule/WindowRuleApplicator.hpp index 8bcf7008..e7cf15f9 100644 --- a/src/desktop/rule/windowRule/WindowRuleApplicator.hpp +++ b/src/desktop/rule/windowRule/WindowRuleApplicator.hpp @@ -54,6 +54,7 @@ namespace Desktop::Rule { std::optional noCloseFor; std::string size, position; + std::optional scrollingWidth; std::vector suppressEvent; } static_; diff --git a/src/desktop/rule/windowRule/WindowRuleEffectContainer.cpp b/src/desktop/rule/windowRule/WindowRuleEffectContainer.cpp index 660bf871..66867247 100644 --- a/src/desktop/rule/windowRule/WindowRuleEffectContainer.cpp +++ b/src/desktop/rule/windowRule/WindowRuleEffectContainer.cpp @@ -28,6 +28,7 @@ static const std::vector EFFECT_STRINGS = { "suppress_event", // "content", // "no_close_for", // + "scrolling_width", // "rounding", // "rounding_power", // "persistent_size", // @@ -69,7 +70,7 @@ static const std::vector EFFECT_STRINGS = { // This is here so that if we change the rules, we get reminded to update // the strings. -static_assert(WINDOW_RULE_EFFECT_LAST_STATIC == 54); +static_assert(WINDOW_RULE_EFFECT_LAST_STATIC == 55); CWindowRuleEffectContainer::CWindowRuleEffectContainer() : IEffectContainer(std::vector{EFFECT_STRINGS}) { ; diff --git a/src/desktop/rule/windowRule/WindowRuleEffectContainer.hpp b/src/desktop/rule/windowRule/WindowRuleEffectContainer.hpp index 0827d462..af861109 100644 --- a/src/desktop/rule/windowRule/WindowRuleEffectContainer.hpp +++ b/src/desktop/rule/windowRule/WindowRuleEffectContainer.hpp @@ -27,6 +27,7 @@ namespace Desktop::Rule { WINDOW_RULE_EFFECT_SUPPRESSEVENT, WINDOW_RULE_EFFECT_CONTENT, WINDOW_RULE_EFFECT_NOCLOSEFOR, + WINDOW_RULE_EFFECT_SCROLLING_WIDTH, // dynamic WINDOW_RULE_EFFECT_ROUNDING, @@ -76,4 +77,4 @@ namespace Desktop::Rule { }; SP windowEffects(); -}; \ No newline at end of file +}; diff --git a/src/desktop/view/Window.cpp b/src/desktop/view/Window.cpp index 00d32a47..2f87cc0f 100644 --- a/src/desktop/view/Window.cpp +++ b/src/desktop/view/Window.cpp @@ -1770,8 +1770,8 @@ void CWindow::mapWindow() { if (m_ruleApplicator->static_.fullscreenStateClient || m_ruleApplicator->static_.fullscreenStateInternal) { requestedFSState = Desktop::View::SFullscreenState{ - .internal = sc(m_ruleApplicator->static_.fullscreenStateInternal.value_or(0)), - .client = sc(m_ruleApplicator->static_.fullscreenStateClient.value_or(0)), + .internal = sc(m_ruleApplicator->static_.fullscreenStateInternal.value_or(0)), + .client = sc(m_ruleApplicator->static_.fullscreenStateClient.value_or(0)), }; } diff --git a/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp b/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp index 5de27b97..8a5b2d59 100644 --- a/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp +++ b/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp @@ -304,22 +304,22 @@ SScrollingData::SScrollingData(CScrollingAlgorithm* algo) : algorithm(algo) { controller = makeUnique(SCROLL_DIR_RIGHT); } -SP SScrollingData::add() { +SP SScrollingData::add(std::optional width) { auto col = columns.emplace_back(makeShared(self.lock())); col->self = col; - size_t stripIdx = controller->addStrip(algorithm->defaultColumnWidth()); + size_t stripIdx = controller->addStrip(width.value_or(algorithm->defaultColumnWidth())); controller->getStrip(stripIdx).userData = col; return col; } -SP SScrollingData::add(int after) { +SP SScrollingData::add(int after, std::optional width) { auto col = makeShared(self.lock()); col->self = col; columns.insert(columns.begin() + after + 1, col); - controller->insertStrip(after, algorithm->defaultColumnWidth()); + controller->insertStrip(after, width.value_or(algorithm->defaultColumnWidth())); controller->getStrip(after + 1).userData = col; return col; @@ -594,9 +594,10 @@ void CScrollingAlgorithm::newTarget(SP target) { SP droppingData = droppingOn ? dataFor(droppingOn->layoutTarget()) : nullptr; SP droppingColumn = droppingData ? droppingData->column.lock() : nullptr; + const auto width = target->window()->m_ruleApplicator->static_.scrollingWidth; if (!droppingColumn) { - auto col = m_scrollingData->add(); + auto col = m_scrollingData->add(width); col->add(target); m_scrollingData->fitCol(col); } else { @@ -610,7 +611,7 @@ void CScrollingAlgorithm::newTarget(SP target) { m_scrollingData->fitCol(droppingColumn); } else { auto idx = m_scrollingData->idx(droppingColumn); - auto col = idx == -1 ? m_scrollingData->add() : m_scrollingData->add(idx); + auto col = idx == -1 ? m_scrollingData->add(width) : m_scrollingData->add(idx, width); col->add(target); m_scrollingData->fitCol(col); } diff --git a/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.hpp b/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.hpp index d95b3197..1b2b1d1e 100644 --- a/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.hpp +++ b/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.hpp @@ -68,8 +68,8 @@ namespace Layout::Tiled { UP controller; - SP add(); - SP add(int after); + SP add(std::optional width = std::nullopt); + SP add(int after, std::optional width = std::nullopt); int64_t idx(SP c); void remove(SP c); double maxWidth(); -- cgit v1.2.3