mirror of
https://github.com/hyprwm/Hyprland
synced 2026-05-05 12:37:59 +02:00
algo/scroll: fix std::clamp assertion crash on resume from suspend (#13737)
This commit is contained in:
parent
9bf8fe7a52
commit
df55752241
2 changed files with 22 additions and 1 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue