summaryrefslogtreecommitdiff
path: root/src/desktop
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2025-12-05 14:16:22 +0000
committerGitHub <noreply@github.com>2025-12-05 14:16:22 +0000
commit9264436f35e2c4e94adfdf2a8ea23a346ace3a65 (patch)
tree9fe48ff4728060445e655d8a3b528999fd124ff8 /src/desktop
parentd5c52ef58e57b371a9df8fd4404c5d55a1b26f34 (diff)
desktop: rewrite reserved area handling + improve tests (#12383)
Diffstat (limited to 'src/desktop')
-rw-r--r--src/desktop/Window.cpp16
-rw-r--r--src/desktop/reserved/ReservedArea.cpp89
-rw-r--r--src/desktop/reserved/ReservedArea.hpp48
3 files changed, 145 insertions, 8 deletions
diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp
index 8a0e37a6..75dc7215 100644
--- a/src/desktop/Window.cpp
+++ b/src/desktop/Window.cpp
@@ -229,19 +229,19 @@ CBox CWindow::getWindowIdealBoundingBoxIgnoreReserved() {
return CBox{sc<int>(POS.x), sc<int>(POS.y), sc<int>(SIZE.x), sc<int>(SIZE.y)};
}
- if (DELTALESSTHAN(POS.y - PMONITOR->m_position.y, PMONITOR->m_reservedTopLeft.y, 1)) {
+ if (DELTALESSTHAN(POS.y - PMONITOR->m_position.y, PMONITOR->m_reservedArea.top(), 1)) {
POS.y = PMONITOR->m_position.y;
- SIZE.y += PMONITOR->m_reservedTopLeft.y;
+ SIZE.y += PMONITOR->m_reservedArea.top();
}
- if (DELTALESSTHAN(POS.x - PMONITOR->m_position.x, PMONITOR->m_reservedTopLeft.x, 1)) {
+ if (DELTALESSTHAN(POS.x - PMONITOR->m_position.x, PMONITOR->m_reservedArea.left(), 1)) {
POS.x = PMONITOR->m_position.x;
- SIZE.x += PMONITOR->m_reservedTopLeft.x;
+ SIZE.x += PMONITOR->m_reservedArea.left();
}
- if (DELTALESSTHAN(POS.x + SIZE.x - PMONITOR->m_position.x, PMONITOR->m_size.x - PMONITOR->m_reservedBottomRight.x, 1)) {
- SIZE.x += PMONITOR->m_reservedBottomRight.x;
+ if (DELTALESSTHAN(POS.x + SIZE.x - PMONITOR->m_position.x, PMONITOR->m_size.x - PMONITOR->m_reservedArea.right(), 1)) {
+ SIZE.x += PMONITOR->m_reservedArea.right();
}
- if (DELTALESSTHAN(POS.y + SIZE.y - PMONITOR->m_position.y, PMONITOR->m_size.y - PMONITOR->m_reservedBottomRight.y, 1)) {
- SIZE.y += PMONITOR->m_reservedBottomRight.y;
+ if (DELTALESSTHAN(POS.y + SIZE.y - PMONITOR->m_position.y, PMONITOR->m_size.y - PMONITOR->m_reservedArea.bottom(), 1)) {
+ SIZE.y += PMONITOR->m_reservedArea.bottom();
}
return CBox{sc<int>(POS.x), sc<int>(POS.y), sc<int>(SIZE.x), sc<int>(SIZE.y)};
diff --git a/src/desktop/reserved/ReservedArea.cpp b/src/desktop/reserved/ReservedArea.cpp
new file mode 100644
index 00000000..b67524ce
--- /dev/null
+++ b/src/desktop/reserved/ReservedArea.cpp
@@ -0,0 +1,89 @@
+#include "ReservedArea.hpp"
+#include "../../macros.hpp"
+
+using namespace Desktop;
+
+// fuck me. Writing this at 11pm, and I have an in-class test tomorrow.
+// I am failing that bitch
+
+CReservedArea::CReservedArea(const Vector2D& tl, const Vector2D& br) : m_initialTopLeft(tl), m_initialBottomRight(br) {
+ calculate();
+}
+
+CReservedArea::CReservedArea(double top, double right, double bottom, double left) : m_initialTopLeft(left, top), m_initialBottomRight(right, bottom) {
+ calculate();
+}
+
+CReservedArea::CReservedArea(const CBox& parent, const CBox& child) {
+ ASSERT(!parent.empty() && !child.empty());
+
+ ASSERT(parent.containsPoint(child.pos() + Vector2D{0.0001, 0.0001}));
+ ASSERT(parent.containsPoint(child.pos() + child.size() - Vector2D{0.0001, 0.0001}));
+
+ m_initialTopLeft = child.pos() - parent.pos();
+ m_initialBottomRight = (parent.pos() + parent.size()) - (child.pos() + child.size());
+
+ calculate();
+}
+
+void CReservedArea::calculate() {
+ m_bottomRight = m_initialBottomRight;
+ m_topLeft = m_initialTopLeft;
+
+ for (const auto& e : m_dynamicReserved) {
+ m_bottomRight += e.bottomRight;
+ m_topLeft += e.topLeft;
+ }
+}
+
+CBox CReservedArea::apply(const CBox& other) const {
+ auto c = other.copy();
+ c.x += m_topLeft.x;
+ c.y += m_topLeft.y;
+ c.w -= m_topLeft.x + m_bottomRight.x;
+ c.h -= m_topLeft.y + m_bottomRight.y;
+ return c;
+}
+
+void CReservedArea::applyip(CBox& other) const {
+ other.x += m_topLeft.x;
+ other.y += m_topLeft.y;
+ other.w -= m_topLeft.x + m_bottomRight.x;
+ other.h -= m_topLeft.y + m_bottomRight.y;
+}
+
+bool CReservedArea::operator==(const CReservedArea& other) const {
+ return other.m_bottomRight == m_bottomRight && other.m_topLeft == m_topLeft;
+}
+
+double CReservedArea::left() const {
+ return m_topLeft.x;
+}
+
+double CReservedArea::right() const {
+ return m_bottomRight.x;
+}
+
+double CReservedArea::top() const {
+ return m_topLeft.y;
+}
+
+double CReservedArea::bottom() const {
+ return m_bottomRight.y;
+}
+
+void CReservedArea::resetType(eReservedDynamicType t) {
+ m_dynamicReserved[t] = {};
+ calculate();
+}
+
+void CReservedArea::addType(eReservedDynamicType t, const Vector2D& topLeft, const Vector2D& bottomRight) {
+ auto& ref = m_dynamicReserved[t];
+ ref.topLeft += topLeft;
+ ref.bottomRight += bottomRight;
+ calculate();
+}
+
+void CReservedArea::addType(eReservedDynamicType t, const CReservedArea& area) {
+ addType(t, {area.left(), area.top()}, {area.right(), area.bottom()});
+}
diff --git a/src/desktop/reserved/ReservedArea.hpp b/src/desktop/reserved/ReservedArea.hpp
new file mode 100644
index 00000000..2aca595d
--- /dev/null
+++ b/src/desktop/reserved/ReservedArea.hpp
@@ -0,0 +1,48 @@
+#pragma once
+
+#include "../../helpers/math/Math.hpp"
+#include <array>
+
+namespace Desktop {
+ enum eReservedDynamicType : uint8_t {
+ RESERVED_DYNAMIC_TYPE_LS = 0,
+ RESERVED_DYNAMIC_TYPE_ERROR_BAR,
+
+ RESERVED_DYNAMIC_TYPE_END,
+ };
+
+ class CReservedArea {
+ public:
+ CReservedArea() = default;
+ CReservedArea(const Vector2D& tl, const Vector2D& br);
+ CReservedArea(double top, double right, double bottom, double left);
+ CReservedArea(const CBox& parent, const CBox& child);
+ ~CReservedArea() = default;
+
+ CBox apply(const CBox& other) const;
+ void applyip(CBox& other) const;
+
+ void resetType(eReservedDynamicType);
+ void addType(eReservedDynamicType, const Vector2D& topLeft, const Vector2D& bottomRight);
+ void addType(eReservedDynamicType, const CReservedArea& area);
+
+ double left() const;
+ double right() const;
+ double top() const;
+ double bottom() const;
+
+ bool operator==(const CReservedArea& other) const;
+
+ private:
+ void calculate();
+
+ Vector2D m_topLeft, m_bottomRight;
+ Vector2D m_initialTopLeft, m_initialBottomRight;
+
+ struct SDynamicData {
+ Vector2D topLeft, bottomRight;
+ };
+
+ std::array<SDynamicData, RESERVED_DYNAMIC_TYPE_END> m_dynamicReserved;
+ };
+}; \ No newline at end of file