From f41e3c220366c4432cbef04c7d7a3f28a5d702b4 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 1 Mar 2026 10:15:22 +0000 Subject: [PATCH] scroll: clamp column widths properly ref https://github.com/hyprwm/Hyprland/discussions/13458 --- .../tiled/scrolling/ScrollingAlgorithm.cpp | 21 +++++++++++-------- .../tiled/scrolling/ScrollingAlgorithm.hpp | 2 ++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp b/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp index 8206a796..d9382c72 100644 --- a/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp +++ b/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp @@ -296,23 +296,21 @@ SScrollingData::SScrollingData(CScrollingAlgorithm* algo) : algorithm(algo) { } SP SScrollingData::add() { - static const auto PCOLWIDTH = CConfigValue("scrolling:column_width"); - auto col = columns.emplace_back(makeShared(self.lock())); - col->self = col; + auto col = columns.emplace_back(makeShared(self.lock())); + col->self = col; - size_t stripIdx = controller->addStrip(*PCOLWIDTH); + size_t stripIdx = controller->addStrip(algorithm->defaultColumnWidth()); controller->getStrip(stripIdx).userData = col; return col; } SP SScrollingData::add(int after) { - static const auto PCOLWIDTH = CConfigValue("scrolling:column_width"); - auto col = makeShared(self.lock()); - col->self = col; + auto col = makeShared(self.lock()); + col->self = col; columns.insert(columns.begin() + after + 1, col); - controller->insertStrip(after, *PCOLWIDTH); + controller->insertStrip(after, algorithm->defaultColumnWidth()); controller->getStrip(after + 1).userData = col; return col; @@ -486,7 +484,7 @@ CScrollingAlgorithm::CScrollingAlgorithm() { CConstVarList widths(*PCONFWIDTHS, 0, ','); for (auto& w : widths) { try { - m_config.configuredWidths.emplace_back(std::stof(std::string{w})); + m_config.configuredWidths.emplace_back(std::clamp(std::stof(std::string{w}), MIN_COLUMN_WIDTH, MAX_COLUMN_WIDTH)); } catch (...) { Log::logger->log(Log::ERR, "scrolling: Failed to parse width {} as float", w); } } if (m_config.configuredWidths.empty()) @@ -1424,3 +1422,8 @@ CBox CScrollingAlgorithm::usableArea() { box.translate(-m_parent->space()->workspace()->m_monitor->m_position); return box; } + +float CScrollingAlgorithm::defaultColumnWidth() { + static const auto PCOLWIDTH = CConfigValue("scrolling:column_width"); + return std::clamp(*PCOLWIDTH, MIN_COLUMN_WIDTH, MAX_COLUMN_WIDTH); +} diff --git a/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.hpp b/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.hpp index 20db6efe..a414a22f 100644 --- a/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.hpp +++ b/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.hpp @@ -138,6 +138,8 @@ namespace Layout::Tiled { void moveTargetTo(SP t, Math::eDirection dir, bool silent); void focusOnInput(SP target, eInputMode input); + float defaultColumnWidth(); + friend struct SScrollingData; }; };