desktop/reserved: do not crash on invalid box init (#13880)

ref #13879
This commit is contained in:
Vaxry
2026-03-28 21:38:10 +00:00
committed by GitHub
parent eb10ecf738
commit 83d3babd4e
4 changed files with 24 additions and 2 deletions
+14 -2
View File
@@ -1,5 +1,6 @@
#include "ReservedArea.hpp"
#include "../../macros.hpp"
#include "../../debug/log/Logger.hpp"
using namespace Desktop;
@@ -19,8 +20,15 @@ CReservedArea::CReservedArea(const CBox& parent, const CBox& child) {
if (parent.empty() || child.empty())
return; // empty reserved area
ASSERT(parent.containsPoint(child.pos() + Vector2D{0.0001, 0.0001}));
ASSERT(parent.containsPoint(child.pos() + child.size() - Vector2D{0.0001, 0.0001}));
if (!parent.containsPoint(child.pos() + Vector2D{0.0001, 0.0001}) //
|| !parent.containsPoint(child.pos() + child.size() - Vector2D{0.0001, 0.0001})) {
Log::logger->log(Log::ERR, "CReservedArea: attempted to create a reserved area from parent [{}, {}] and child [{}, {}] which is invalid", parent.pos(), parent.size(),
child.pos(), child.size());
m_ok = false;
return;
}
m_initialTopLeft = child.pos() - parent.pos();
m_initialBottomRight = (parent.pos() + parent.size()) - (child.pos() + child.size());
@@ -28,6 +36,10 @@ CReservedArea::CReservedArea(const CBox& parent, const CBox& child) {
calculate();
}
bool CReservedArea::ok() const {
return m_ok;
}
void CReservedArea::calculate() {
m_bottomRight = m_initialBottomRight;
m_topLeft = m_initialTopLeft;
+4
View File
@@ -31,6 +31,8 @@ namespace Desktop {
double top() const;
double bottom() const;
bool ok() const;
bool operator==(const CReservedArea& other) const;
private:
@@ -39,6 +41,8 @@ namespace Desktop {
Vector2D m_topLeft, m_bottomRight;
Vector2D m_initialTopLeft, m_initialBottomRight;
bool m_ok = true;
struct SDynamicData {
Vector2D topLeft, bottomRight;
};
+3
View File
@@ -285,6 +285,9 @@ CBox CWindow::getWindowIdealBoundingBoxIgnoreReserved() {
const auto WORKAREA = m_workspace->m_space->workArea();
const auto& RESERVED = CReservedArea(PMONITOR->logicalBox(), WORKAREA);
if (!RESERVED.ok())
return CBox{POS, SIZE};
if (DELTALESSTHAN(POS.x, WORKAREA.x, 1)) {
POS.x -= RESERVED.left();
SIZE.x += RESERVED.left();
+3
View File
@@ -49,4 +49,7 @@ TEST(Desktop, reservedArea) {
EXPECT_EQ(d.top(), 0);
EXPECT_EQ(d.right(), 0);
EXPECT_EQ(d.bottom(), 0);
Desktop::CReservedArea e{CBox{20, 30, 900, 900}, CBox{0, 0, 100, 100}};
EXPECT_EQ(e.ok(), false);
}