From 341e04a36ce5254315a40c563ea7f5d891b289e8 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 2 Feb 2024 15:04:04 +0000 Subject: [PATCH] dwindle: avoid sending negative sizes to wlr fixes #4591 --- src/helpers/Box.cpp | 7 +++++++ src/helpers/Box.hpp | 1 + src/layout/DwindleLayout.cpp | 8 ++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/helpers/Box.cpp b/src/helpers/Box.cpp index 3d57bc79..d3f5d36c 100644 --- a/src/helpers/Box.cpp +++ b/src/helpers/Box.cpp @@ -105,6 +105,13 @@ CBox& CBox::expand(const double& value) { return *this; } +CBox& CBox::noNegativeSize() { + std::clamp(w, 0.0, std::numeric_limits::infinity()); + std::clamp(h, 0.0, std::numeric_limits::infinity()); + + return *this; +} + CBox CBox::roundInternal() { float newW = x + w - std::floor(x); float newH = y + h - std::floor(y); diff --git a/src/helpers/Box.hpp b/src/helpers/Box.hpp index a1ed83be..fd31a7b7 100644 --- a/src/helpers/Box.hpp +++ b/src/helpers/Box.hpp @@ -51,6 +51,7 @@ class CBox { CBox& transform(const wl_output_transform t, double w, double h); CBox& addExtents(const SWindowDecorationExtents& e); CBox& expand(const double& value); + CBox& noNegativeSize(); CBox copy() const; diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 85111fcd..4058121f 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -22,13 +22,13 @@ void SDwindleNodeData::recalcSizePosRecursive(bool force, bool horizontalOverrid if (SPLITSIDE) { // split left/right const float FIRSTSIZE = box.w / 2.0 * splitRatio; - children[0]->box = CBox{box.x, box.y, FIRSTSIZE, box.h}; - children[1]->box = CBox{box.x + FIRSTSIZE, box.y, box.w - FIRSTSIZE, box.h}; + children[0]->box = CBox{box.x, box.y, FIRSTSIZE, box.h}.noNegativeSize(); + children[1]->box = CBox{box.x + FIRSTSIZE, box.y, box.w - FIRSTSIZE, box.h}.noNegativeSize(); } else { // split top/bottom const float FIRSTSIZE = box.h / 2.0 * splitRatio; - children[0]->box = CBox{box.x, box.y, box.w, FIRSTSIZE}; - children[1]->box = CBox{box.x, box.y + FIRSTSIZE, box.w, box.h - FIRSTSIZE}; + children[0]->box = CBox{box.x, box.y, box.w, FIRSTSIZE}.noNegativeSize(); + children[1]->box = CBox{box.x, box.y + FIRSTSIZE, box.w, box.h - FIRSTSIZE}.noNegativeSize(); } children[0]->recalcSizePosRecursive(force);