summaryrefslogtreecommitdiff
path: root/src/layout/algorithm
diff options
context:
space:
mode:
authorNathan Ollerenshaw <chrome@stupendous.net>2026-03-15 08:06:10 -0700
committerGitHub <noreply@github.com>2026-03-15 10:06:10 -0500
commitdf55752241c81fe4faa73aa77b775eb12b3e3fa4 (patch)
tree4b4b9b338a5a30e70f3105c8eca54e443d0f128a /src/layout/algorithm
parent9bf8fe7a5278b5f366384d73d87844a165c16b7a (diff)
algo/scroll: fix std::clamp assertion crash on resume from suspend (#13737)
Diffstat (limited to 'src/layout/algorithm')
-rw-r--r--src/layout/algorithm/tiled/scrolling/ScrollTapeController.cpp12
-rw-r--r--src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp11
2 files changed, 22 insertions, 1 deletions
diff --git a/src/layout/algorithm/tiled/scrolling/ScrollTapeController.cpp b/src/layout/algorithm/tiled/scrolling/ScrollTapeController.cpp
index 93a7dac1..6cd7da9c 100644
--- a/src/layout/algorithm/tiled/scrolling/ScrollTapeController.cpp
+++ b/src/layout/algorithm/tiled/scrolling/ScrollTapeController.cpp
@@ -240,7 +240,17 @@ void CScrollTapeController::fitStrip(size_t stripIndex, const CBox& usableArea,
const double stripStart = calculateStripStart(stripIndex, usableArea, fullscreenOnOne);
const double stripSize = calculateStripSize(stripIndex, usableArea, fullscreenOnOne);
- m_offset = std::clamp(m_offset, stripStart - usablePrimary + stripSize, stripStart);
+ const double lo = stripStart - usablePrimary + stripSize;
+ const double hi = stripStart;
+
+ if (lo > hi) {
+ // strip is wider than viewport (e.g. during monitor reconnection after suspend),
+ // center the strip instead of hitting the std::clamp assertion
+ m_offset = stripStart - (usablePrimary - stripSize) / 2.0;
+ return;
+ }
+
+ m_offset = std::clamp(m_offset, lo, hi);
}
bool CScrollTapeController::isStripVisible(size_t stripIndex, const CBox& usableArea, bool fullscreenOnOne, bool full) const {
diff --git a/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp b/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp
index a64edb3a..5de27b97 100644
--- a/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp
+++ b/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp
@@ -795,6 +795,11 @@ void CScrollingAlgorithm::resizeTarget(const Vector2D& delta, SP<ITarget> target
}
void CScrollingAlgorithm::recalculate() {
+ // guard against recalculation during transitional monitor states
+ // (e.g. monitor reconnecting after suspend where workspace/monitor may not be ready)
+ if (!m_parent || !m_parent->space() || !m_parent->space()->workspace() || !m_parent->space()->workspace()->m_monitor)
+ return;
+
if (Desktop::focusState()->window()) {
const auto TARGET = Desktop::focusState()->window()->layoutTarget();
@@ -1516,6 +1521,12 @@ CBox CScrollingAlgorithm::usableArea() {
return box;
box.translate(-m_parent->space()->workspace()->m_monitor->m_position);
+
+ // ensure dimensions are never zero or negative, which can happen during
+ // monitor transitions (e.g. reconnection after suspend with stale reserved areas)
+ box.w = std::max(box.w, 1.0);
+ box.h = std::max(box.h, 1.0);
+
return box;
}