core: Move to hyprutils for Math

Moves CRegion, CBox and Vector2D over to hyprutils.

Requires hyprutils>=0.1.4
This commit is contained in:
Vaxry 2024-06-19 16:20:06 +02:00
parent 6e5804b53d
commit fb15b7aa2a
76 changed files with 509 additions and 1004 deletions

View file

@ -26,16 +26,16 @@ class CHyprBorderDecoration : public IHyprWindowDecoration {
virtual std::string getDisplayName();
private:
SWindowDecorationExtents m_seExtents;
SWindowDecorationExtents m_seReportedExtents;
SBoxExtents m_seExtents;
SBoxExtents m_seReportedExtents;
PHLWINDOWREF m_pWindow;
PHLWINDOWREF m_pWindow;
Vector2D m_vLastWindowPos;
Vector2D m_vLastWindowSize;
Vector2D m_vLastWindowPos;
Vector2D m_vLastWindowSize;
CBox m_bAssignedGeometry = {0};
CBox m_bAssignedGeometry = {0};
CBox assignedBoxGlobal();
bool doesntWantBorders();
CBox assignedBoxGlobal();
bool doesntWantBorders();
};

View file

@ -130,7 +130,7 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a) {
const float SHADOWSCALE = std::clamp(*PSHADOWSCALE, 0.f, 1.f);
// scale the box in relation to the center of the box
fullBox.scaleFromCenter(SHADOWSCALE).translate(*PSHADOWOFFSET);
fullBox.scaleFromCenter(SHADOWSCALE).translate({(*PSHADOWOFFSET).x, (*PSHADOWOFFSET).y});
updateWindow(PWINDOW);
m_vLastWindowPos += WORKSPACEOFFSET;

View file

@ -26,14 +26,14 @@ class CHyprDropShadowDecoration : public IHyprWindowDecoration {
virtual std::string getDisplayName();
private:
SWindowDecorationExtents m_seExtents;
SWindowDecorationExtents m_seReportedExtents;
SBoxExtents m_seExtents;
SBoxExtents m_seReportedExtents;
PHLWINDOWREF m_pWindow;
PHLWINDOWREF m_pWindow;
Vector2D m_vLastWindowPos;
Vector2D m_vLastWindowSize;
Vector2D m_vLastWindowPos;
Vector2D m_vLastWindowSize;
CBox m_bLastWindowBox = {0};
CBox m_bLastWindowBoxWithDecos = {0};
CBox m_bLastWindowBox = {0};
CBox m_bLastWindowBoxWithDecos = {0};
};

View file

@ -48,7 +48,7 @@ class CHyprGroupBarDecoration : public IHyprWindowDecoration {
virtual std::string getDisplayName();
private:
SWindowDecorationExtents m_seExtents;
SBoxExtents m_seExtents;
CBox m_bAssignedBox = {0};

View file

@ -33,11 +33,11 @@ Vector2D CDecorationPositioner::getEdgeDefinedPoint(uint32_t edges, PHLWINDOW pW
if (EDGESNO == 1) {
if (TOP)
return wb.pos() + Vector2D{wb.size().x / 2.0, 0};
return wb.pos() + Vector2D{wb.size().x / 2.0, 0.0};
else if (BOTTOM)
return wb.pos() + Vector2D{wb.size().x / 2.0, wb.size().y};
else if (LEFT)
return wb.pos() + Vector2D{0, wb.size().y / 2.0};
return wb.pos() + Vector2D{0.0, wb.size().y / 2.0};
else if (RIGHT)
return wb.pos() + Vector2D{wb.size().x, wb.size().y / 2.0};
UNREACHABLE();
@ -45,11 +45,11 @@ Vector2D CDecorationPositioner::getEdgeDefinedPoint(uint32_t edges, PHLWINDOW pW
if (TOP && LEFT)
return wb.pos();
if (TOP && RIGHT)
return wb.pos() + Vector2D{wb.size().x, 0};
return wb.pos() + Vector2D{wb.size().x, 0.0};
if (BOTTOM && RIGHT)
return wb.pos() + wb.size();
if (BOTTOM && LEFT)
return wb.pos() + Vector2D{0, wb.size().y};
return wb.pos() + Vector2D{0.0, wb.size().y};
UNREACHABLE();
}
UNREACHABLE();
@ -234,26 +234,26 @@ void CDecorationPositioner::onWindowUpdate(PHLWINDOW pWindow) {
} else if (LEFT) {
pos = wb.pos() - EDGEPOINT - Vector2D{stickyOffsetXL, -stickyOffsetYT};
pos.x -= desiredSize;
size = {desiredSize, wb.size().y + stickyOffsetYB + stickyOffsetYT};
size = {(double)desiredSize, wb.size().y + stickyOffsetYB + stickyOffsetYT};
if (SOLID)
stickyOffsetXL += desiredSize;
} else if (RIGHT) {
pos = wb.pos() + Vector2D{wb.size().x, 0} - EDGEPOINT + Vector2D{stickyOffsetXR, -stickyOffsetYT};
size = {desiredSize, wb.size().y + stickyOffsetYB + stickyOffsetYT};
pos = wb.pos() + Vector2D{wb.size().x, 0.0} - EDGEPOINT + Vector2D{stickyOffsetXR, -stickyOffsetYT};
size = {(double)desiredSize, wb.size().y + stickyOffsetYB + stickyOffsetYT};
if (SOLID)
stickyOffsetXR += desiredSize;
} else if (TOP) {
pos = wb.pos() - EDGEPOINT - Vector2D{stickyOffsetXL, stickyOffsetYT};
pos.y -= desiredSize;
size = {wb.size().x + stickyOffsetXL + stickyOffsetXR, desiredSize};
size = {wb.size().x + stickyOffsetXL + stickyOffsetXR, (double)desiredSize};
if (SOLID)
stickyOffsetYT += desiredSize;
} else {
pos = wb.pos() + Vector2D{0, wb.size().y} - EDGEPOINT - Vector2D{stickyOffsetXL, stickyOffsetYB};
size = {wb.size().x + stickyOffsetXL + stickyOffsetXR, desiredSize};
pos = wb.pos() + Vector2D{0.0, wb.size().y} - EDGEPOINT - Vector2D{stickyOffsetXL, stickyOffsetYB};
size = {wb.size().x + stickyOffsetXL + stickyOffsetXR, (double)desiredSize};
if (SOLID)
stickyOffsetYB += desiredSize;
@ -271,7 +271,7 @@ void CDecorationPositioner::onWindowUpdate(PHLWINDOW pWindow) {
}
}
if (WINDOWDATA->extents != SWindowDecorationExtents{{stickyOffsetXL + reservedXL, stickyOffsetYT + reservedYT}, {stickyOffsetXR + reservedXR, stickyOffsetYB + reservedYB}}) {
if (WINDOWDATA->extents != SBoxExtents{{stickyOffsetXL + reservedXL, stickyOffsetYT + reservedYT}, {stickyOffsetXR + reservedXR, stickyOffsetYB + reservedYB}}) {
WINDOWDATA->extents = {{stickyOffsetXL + reservedXL, stickyOffsetYT + reservedYT}, {stickyOffsetXR + reservedXR, stickyOffsetYB + reservedYB}};
g_pLayoutManager->getCurrentLayout()->recalculateWindow(pWindow);
}
@ -286,14 +286,14 @@ void CDecorationPositioner::onWindowMap(PHLWINDOW pWindow) {
m_mWindowDatas[pWindow] = {};
}
SWindowDecorationExtents CDecorationPositioner::getWindowDecorationReserved(PHLWINDOW pWindow) {
SBoxExtents CDecorationPositioner::getWindowDecorationReserved(PHLWINDOW pWindow) {
try {
const auto E = m_mWindowDatas.at(pWindow);
return E.reserved;
} catch (std::out_of_range& e) { return {}; }
}
SWindowDecorationExtents CDecorationPositioner::getWindowDecorationExtents(PHLWINDOW pWindow, bool inputOnly) {
SBoxExtents CDecorationPositioner::getWindowDecorationExtents(PHLWINDOW pWindow, bool inputOnly) {
CBox accum = pWindow->getWindowMainSurfaceBox();
for (auto& data : m_vWindowPositioningDatas) {
@ -317,7 +317,7 @@ SWindowDecorationExtents CDecorationPositioner::getWindowDecorationExtents(PHLWI
decoBox.translate(EDGEPOINT);
}
SWindowDecorationExtents extentsToAdd;
SBoxExtents extentsToAdd;
if (decoBox.x < accum.x)
extentsToAdd.topLeft.x = accum.x - decoBox.x;
@ -355,7 +355,7 @@ CBox CDecorationPositioner::getBoxWithIncludedDecos(PHLWINDOW pWindow) {
decoBox.translate(EDGEPOINT);
}
SWindowDecorationExtents extentsToAdd;
SBoxExtents extentsToAdd;
if (decoBox.x < accum.x)
extentsToAdd.topLeft.x = accum.x - decoBox.x;

View file

@ -3,7 +3,7 @@
#include <cstdint>
#include <vector>
#include <map>
#include "../../helpers/Box.hpp"
#include "../../helpers/math/Math.hpp"
#include "../../desktop/DesktopTypes.hpp"
class CWindow;
@ -37,7 +37,7 @@ struct SDecorationPositioningInfo {
eDecorationPositioningPolicy policy = DECORATION_POSITION_ABSOLUTE;
uint32_t edges = 0; // enum eDecorationEdges
uint32_t priority = 10; // priority, decos will be evaluated high -> low
SWindowDecorationExtents desiredExtents;
SBoxExtents desiredExtents;
bool reserved = false; // if true, geometry will use reserved area
};
@ -62,14 +62,14 @@ class CDecorationPositioner {
Vector2D getEdgeDefinedPoint(uint32_t edges, PHLWINDOW pWindow);
// called on resize, or insert/removal of a new deco
void onWindowUpdate(PHLWINDOW pWindow);
void uncacheDecoration(IHyprWindowDecoration* deco);
SWindowDecorationExtents getWindowDecorationReserved(PHLWINDOW pWindow);
SWindowDecorationExtents getWindowDecorationExtents(PHLWINDOW pWindow, bool inputOnly = false);
CBox getBoxWithIncludedDecos(PHLWINDOW pWindow);
void repositionDeco(IHyprWindowDecoration* deco);
CBox getWindowDecorationBox(IHyprWindowDecoration* deco);
void forceRecalcFor(PHLWINDOW pWindow);
void onWindowUpdate(PHLWINDOW pWindow);
void uncacheDecoration(IHyprWindowDecoration* deco);
SBoxExtents getWindowDecorationReserved(PHLWINDOW pWindow);
SBoxExtents getWindowDecorationExtents(PHLWINDOW pWindow, bool inputOnly = false);
CBox getBoxWithIncludedDecos(PHLWINDOW pWindow);
void repositionDeco(IHyprWindowDecoration* deco);
CBox getWindowDecorationBox(IHyprWindowDecoration* deco);
void forceRecalcFor(PHLWINDOW pWindow);
private:
struct SWindowPositioningData {
@ -81,10 +81,10 @@ class CDecorationPositioner {
};
struct SWindowData {
Vector2D lastWindowSize = {};
SWindowDecorationExtents reserved = {};
SWindowDecorationExtents extents = {};
bool needsRecalc = false;
Vector2D lastWindowSize = {};
SBoxExtents reserved = {};
SBoxExtents extents = {};
bool needsRecalc = false;
};
std::map<PHLWINDOWREF, SWindowData> m_mWindowDatas;

View file

@ -2,7 +2,7 @@
#include <any>
#include "../../defines.hpp"
#include "../../helpers/Region.hpp"
#include "../../helpers/math/Math.hpp"
#include "DecorationPositioner.hpp"
enum eDecorationType {