diff options
author | Vaxry <[email protected]> | 2023-11-04 17:03:05 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2023-11-04 17:03:05 +0000 |
commit | 55b4f84fea33adee3ec4b0a69c2bca6e7a1f5754 (patch) | |
tree | be7db4f841b4ac049527daae01e683701bf92b92 | |
parent | 73e78f05ad5cafa20ac5bf177c94ac9ecca37097 (diff) | |
download | Hyprland-55b4f84fea33adee3ec4b0a69c2bca6e7a1f5754.tar.gz Hyprland-55b4f84fea33adee3ec4b0a69c2bca6e7a1f5754.zip |
Internal: Hyprland box implementation (#3755)
* box impl
* remove unused operators
* missed applyfromwlr
47 files changed, 520 insertions, 352 deletions
diff --git a/example/examplePlugin/customDecoration.cpp b/example/examplePlugin/customDecoration.cpp index 52b8b715..e2b5d136 100644 --- a/example/examplePlugin/customDecoration.cpp +++ b/example/examplePlugin/customDecoration.cpp @@ -33,8 +33,8 @@ void CCustomDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& offset (m_pWindow->m_sAdditionalConfigData.rounding.toUnderlying() == -1 ? *PROUNDING : m_pWindow->m_sAdditionalConfigData.rounding.toUnderlying()); // draw the border - wlr_box fullBox = {(int)(m_vLastWindowPos.x - *PBORDERSIZE), (int)(m_vLastWindowPos.y - *PBORDERSIZE), (int)(m_vLastWindowSize.x + 2.0 * *PBORDERSIZE), - (int)(m_vLastWindowSize.y + 2.0 * *PBORDERSIZE)}; + CBox fullBox = {(int)(m_vLastWindowPos.x - *PBORDERSIZE), (int)(m_vLastWindowPos.y - *PBORDERSIZE), (int)(m_vLastWindowSize.x + 2.0 * *PBORDERSIZE), + (int)(m_vLastWindowSize.y + 2.0 * *PBORDERSIZE)}; fullBox.x -= pMonitor->vecPosition.x; fullBox.y -= pMonitor->vecPosition.y; @@ -49,9 +49,9 @@ void CCustomDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& offset if (fullBox.width < 1 || fullBox.height < 1) return; // don't draw invisible shadows - g_pHyprOpenGL->scissor((wlr_box*)nullptr); + g_pHyprOpenGL->scissor((CBox*)nullptr); - scaleBox(&fullBox, pMonitor->scale); + fullBox.scale(pMonitor->scale); g_pHyprOpenGL->renderBorder(&fullBox, CColor(*PCOLOR), *PROUNDING * pMonitor->scale + *PBORDERSIZE * 2, a); } @@ -68,7 +68,7 @@ void CCustomDecoration::updateWindow(CWindow* pWindow) { } void CCustomDecoration::damageEntire() { - wlr_box dm = {(int)(m_vLastWindowPos.x - m_seExtents.topLeft.x), (int)(m_vLastWindowPos.y - m_seExtents.topLeft.y), - (int)(m_vLastWindowSize.x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x), (int)m_seExtents.topLeft.y}; + CBox dm = {(int)(m_vLastWindowPos.x - m_seExtents.topLeft.x), (int)(m_vLastWindowPos.y - m_seExtents.topLeft.y), + (int)(m_vLastWindowSize.x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x), (int)m_seExtents.topLeft.y}; g_pHyprRenderer->damageBox(&dm); }
\ No newline at end of file diff --git a/src/Compositor.cpp b/src/Compositor.cpp index f8d61501..53cd2e83 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -631,38 +631,35 @@ CWindow* CCompositor::vectorToWindow(const Vector2D& pos) { if (PMONITOR->specialWorkspaceID) { for (auto& w : m_vWindows | std::views::reverse) { - wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (w->m_bIsFloating && w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && w->m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && !w->isHidden() && - !w->m_bNoFocus) + auto box = w->getWindowMainSurfaceBox(); + if (w->m_bIsFloating && w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && w->m_bIsMapped && box.containsPoint(pos) && !w->isHidden() && !w->m_bNoFocus) return w.get(); } for (auto& w : m_vWindows) { - wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && wlr_box_contains_point(&box, pos.x, pos.y) && w->m_bIsMapped && !w->m_bIsFloating && !w->isHidden() && - !w->m_bNoFocus) + auto box = w->getWindowMainSurfaceBox(); + if (w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && box.containsPoint(pos) && w->m_bIsMapped && !w->m_bIsFloating && !w->isHidden() && !w->m_bNoFocus) return w.get(); } } // pinned for (auto& w : m_vWindows | std::views::reverse) { - wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (wlr_box_contains_point(&box, pos.x, pos.y) && w->m_bIsMapped && w->m_bIsFloating && !w->isHidden() && w->m_bPinned && !w->m_bNoFocus) + auto box = w->getWindowMainSurfaceBox(); + if (box.containsPoint(pos) && w->m_bIsMapped && w->m_bIsFloating && !w->isHidden() && w->m_bPinned && !w->m_bNoFocus) return w.get(); } // first loop over floating cuz they're above, m_vWindows should be sorted bottom->top, for tiled it doesn't matter. for (auto& w : m_vWindows | std::views::reverse) { - wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (wlr_box_contains_point(&box, pos.x, pos.y) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID) && !w->isHidden() && !w->m_bPinned && - !w->m_bNoFocus) + auto box = w->getWindowMainSurfaceBox(); + if (box.containsPoint(pos) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID) && !w->isHidden() && !w->m_bPinned && !w->m_bNoFocus) return w.get(); } for (auto& w : m_vWindows) { - wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (wlr_box_contains_point(&box, pos.x, pos.y) && w->m_bIsMapped && !w->m_bIsFloating && PMONITOR->activeWorkspace == w->m_iWorkspaceID && !w->isHidden() && !w->m_bNoFocus) + auto box = w->getWindowMainSurfaceBox(); + if (box.containsPoint(pos) && w->m_bIsMapped && !w->m_bIsFloating && PMONITOR->activeWorkspace == w->m_iWorkspaceID && !w->isHidden() && !w->m_bNoFocus) return w.get(); } @@ -674,15 +671,15 @@ CWindow* CCompositor::vectorToWindowTiled(const Vector2D& pos) { if (PMONITOR->specialWorkspaceID) { for (auto& w : m_vWindows) { - wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; - if (w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && wlr_box_contains_point(&box, pos.x, pos.y) && !w->m_bIsFloating && !w->isHidden() && !w->m_bNoFocus) + CBox box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; + if (w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && box.containsPoint(pos) && !w->m_bIsFloating && !w->isHidden() && !w->m_bNoFocus) return w.get(); } } for (auto& w : m_vWindows) { - wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; - if (w->m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && w->m_iWorkspaceID == PMONITOR->activeWorkspace && !w->m_bIsFloating && !w->isHidden() && !w->m_bNoFocus) + CBox box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; + if (w->m_bIsMapped && box.containsPoint(pos) && w->m_iWorkspaceID == PMONITOR->activeWorkspace && !w->m_bIsFloating && !w->isHidden() && !w->m_bNoFocus) return w.get(); } @@ -700,16 +697,16 @@ CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos) { if (PMONITOR->specialWorkspaceID) { for (auto& w : m_vWindows | std::views::reverse) { const auto BB = w->getWindowInputBox(); - wlr_box box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA}; - if (w->m_bIsFloating && w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && w->m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && !w->isHidden() && - !w->m_bX11ShouldntFocus && !w->m_bNoFocus) + CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA}; + if (w->m_bIsFloating && w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && w->m_bIsMapped && box.containsPoint(pos) && !w->isHidden() && !w->m_bX11ShouldntFocus && + !w->m_bNoFocus) return w.get(); } for (auto& w : m_vWindows) { - wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; - if (!w->m_bIsFloating && w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && w->m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && !w->isHidden() && - !w->m_bX11ShouldntFocus && !w->m_bNoFocus) + CBox box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; + if (!w->m_bIsFloating && w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && w->m_bIsMapped && box.containsPoint(pos) && !w->isHidden() && !w->m_bX11ShouldntFocus && + !w->m_bNoFocus) return w.get(); } } @@ -717,9 +714,9 @@ CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos) { // pinned windows on top of floating regardless for (auto& w : m_vWindows | std::views::reverse) { const auto BB = w->getWindowInputBox(); - wlr_box box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA}; + CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA}; if (w->m_bIsFloating && w->m_bIsMapped && !w->isHidden() && !w->m_bX11ShouldntFocus && w->m_bPinned && !w->m_bNoFocus) { - if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y)) + if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y})) return w.get(); if (!w->m_bIsX11) { @@ -732,13 +729,13 @@ CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos) { // first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter. for (auto& w : m_vWindows | std::views::reverse) { const auto BB = w->getWindowInputBox(); - wlr_box box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA}; + CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA}; if (w->m_bIsFloating && w->m_bIsMapped && isWorkspaceVisible(w->m_iWorkspaceID) && !w->isHidden() && !w->m_bPinned && !w->m_bNoFocus) { // OR windows should add focus to parent if (w->m_bX11ShouldntFocus && w->m_iX11Type != 2) continue; - if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y)) { + if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y})) { if (w->m_bIsX11 && w->m_iX11Type == 2 && !wlr_xwayland_or_surface_wants_focus(w->m_uSurface.xwayland)) { // Override Redirect @@ -764,9 +761,9 @@ CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos) { } } for (auto& w : m_vWindows) { - wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; - if (!w->m_bIsFloating && w->m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && w->m_iWorkspaceID == PMONITOR->activeWorkspace && !w->isHidden() && - !w->m_bX11ShouldntFocus && !w->m_bNoFocus) + CBox box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; + if (!w->m_bIsFloating && w->m_bIsMapped && box.containsPoint(pos) && w->m_iWorkspaceID == PMONITOR->activeWorkspace && !w->isHidden() && !w->m_bX11ShouldntFocus && + !w->m_bNoFocus) return w.get(); } @@ -778,37 +775,36 @@ CWindow* CCompositor::windowFromCursor() { if (PMONITOR->specialWorkspaceID) { for (auto& w : m_vWindows | std::views::reverse) { - wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (w->m_bIsFloating && w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && w->m_bIsMapped && wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && + CBox box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; + if (w->m_bIsFloating && w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && w->m_bIsMapped && box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && !w->isHidden() && !w->m_bNoFocus) return w.get(); } for (auto& w : m_vWindows) { - wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; - if (w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w->m_bIsMapped && !w->m_bNoFocus) + CBox box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; + if (w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && !w->m_bNoFocus) return w.get(); } } // pinned for (auto& w : m_vWindows | std::views::reverse) { - wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w->m_bIsMapped && w->m_bIsFloating && w->m_bPinned && !w->m_bNoFocus) + CBox box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; + if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && w->m_bIsFloating && w->m_bPinned && !w->m_bNoFocus) return w.get(); } // first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter. for (auto& w : m_vWindows | std::views::reverse) { - wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID) && !w->m_bPinned && - !w->m_bNoFocus) + CBox box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; + if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID) && !w->m_bPinned && !w->m_bNoFocus) return w.get(); } for (auto& w : m_vWindows) { - wlr_box box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; - if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w->m_bIsMapped && w->m_iWorkspaceID == PMONITOR->activeWorkspace && !w->m_bNoFocus) + CBox box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; + if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && w->m_iWorkspaceID == PMONITOR->activeWorkspace && !w->m_bNoFocus) return w.get(); } @@ -817,14 +813,14 @@ CWindow* CCompositor::windowFromCursor() { CWindow* CCompositor::windowFloatingFromCursor() { for (auto& w : m_vWindows | std::views::reverse) { - wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w->m_bIsMapped && w->m_bIsFloating && !w->isHidden() && w->m_bPinned && !w->m_bNoFocus) + CBox box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; + if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && w->m_bIsFloating && !w->isHidden() && w->m_bPinned && !w->m_bNoFocus) return w.get(); } for (auto& w : m_vWindows | std::views::reverse) { - wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID) && !w->isHidden() && + CBox box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; + if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID) && !w->isHidden() && !w->m_bPinned && !w->m_bNoFocus) return w.get(); } @@ -844,8 +840,9 @@ wlr_surface* CCompositor::vectorWindowToSurface(const Vector2D& pos, CWindow* pW double subx, suby; // calc for oversized windows... fucking bullshit, again. - wlr_box geom; - wlr_xdg_surface_get_geometry(pWindow->m_uSurface.xdg, &geom); + CBox geom; + wlr_xdg_surface_get_geometry(pWindow->m_uSurface.xdg, geom.pWlr()); + geom.applyFromWlr(); const auto PFOUND = wlr_xdg_surface_surface_at(PSURFACE, pos.x - pWindow->m_vRealPosition.vec().x + geom.x, pos.y - pWindow->m_vRealPosition.vec().y + geom.y, &subx, &suby); @@ -886,8 +883,9 @@ Vector2D CCompositor::vectorToSurfaceLocal(const Vector2D& vec, CWindow* pWindow }, &iterData); - wlr_box geom = {0}; - wlr_xdg_surface_get_geometry(PSURFACE, &geom); + CBox geom = {}; + wlr_xdg_surface_get_geometry(PSURFACE, geom.pWlr()); + geom.applyFromWlr(); if (std::get<1>(iterData) == -1337 && std::get<2>(iterData) == -1337) return vec - pWindow->m_vRealPosition.goalv(); diff --git a/src/SharedDefs.hpp b/src/SharedDefs.hpp index 068d61f6..c060ac26 100644 --- a/src/SharedDefs.hpp +++ b/src/SharedDefs.hpp @@ -26,4 +26,18 @@ enum eRenderStage struct SCallbackInfo { bool cancelled = false; /* on cancellable events, will cancel the event. */ +}; + +struct SWindowDecorationExtents { + Vector2D topLeft; + Vector2D bottomRight; + + // + SWindowDecorationExtents operator*(const double& scale) const { + return SWindowDecorationExtents{topLeft * scale, bottomRight * scale}; + } + + SWindowDecorationExtents floor() { + return {topLeft.floor(), bottomRight.floor()}; + } };
\ No newline at end of file diff --git a/src/Window.cpp b/src/Window.cpp index f66a3139..7994b6cb 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -55,12 +55,12 @@ SWindowDecorationExtents CWindow::getFullWindowExtents() { } if (m_pWLSurface.exists() && !m_bIsX11) { - wlr_box surfaceExtents = {0, 0, 0, 0}; + CBox surfaceExtents = {0, 0, 0, 0}; // TODO: this could be better, perhaps make a getFullWindowRegion? wlr_xdg_surface_for_each_popup_surface( m_uSurface.xdg, [](wlr_surface* surf, int sx, int sy, void* data) { - wlr_box* pSurfaceExtents = (wlr_box*)data; + CBox* pSurfaceExtents = (CBox*)data; if (sx < pSurfaceExtents->x) pSurfaceExtents->x = sx; if (sy < pSurfaceExtents->y) @@ -88,21 +88,21 @@ SWindowDecorationExtents CWindow::getFullWindowExtents() { return maxExtents; } -wlr_box CWindow::getFullWindowBoundingBox() { +CBox CWindow::getFullWindowBoundingBox() { if (m_sAdditionalConfigData.dimAround) { const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID); return {PMONITOR->vecPosition.x, PMONITOR->vecPosition.y, PMONITOR->vecSize.x, PMONITOR->vecSize.y}; } - auto maxExtents = getFullWindowExtents(); + auto maxExtents = getFullWindowExtents(); - wlr_box finalBox = {m_vRealPosition.vec().x - maxExtents.topLeft.x, m_vRealPosition.vec().y - maxExtents.topLeft.y, - m_vRealSize.vec().x + maxExtents.topLeft.x + maxExtents.bottomRight.x, m_vRealSize.vec().y + maxExtents.topLeft.y + maxExtents.bottomRight.y}; + CBox finalBox = {m_vRealPosition.vec().x - maxExtents.topLeft.x, m_vRealPosition.vec().y - maxExtents.topLeft.y, + m_vRealSize.vec().x + maxExtents.topLeft.x + maxExtents.bottomRight.x, m_vRealSize.vec().y + maxExtents.topLeft.y + maxExtents.bottomRight.y}; return finalBox; } -wlr_box CWindow::getWindowIdealBoundingBoxIgnoreReserved() { +CBox CWindow::getWindowIdealBoundingBoxIgnoreReserved() { const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID); @@ -113,7 +113,7 @@ wlr_box CWindow::getWindowIdealBoundingBoxIgnoreReserved() { POS = PMONITOR->vecPosition; SIZE = PMONITOR->vecSize; - return wlr_box{(int)POS.x, (int)POS.y, (int)SIZE.x, (int)SIZE.y}; + return CBox{(int)POS.x, (int)POS.y, (int)SIZE.x, (int)SIZE.y}; } if (DELTALESSTHAN(POS.y - PMONITOR->vecPosition.y, PMONITOR->vecReservedTopLeft.y, 1)) { @@ -131,10 +131,10 @@ wlr_box CWindow::getWindowIdealBoundingBoxIgnoreReserved() { SIZE.y += PMONITOR->vecReservedBottomRight.y; } - return wlr_box{(int)POS.x, (int)POS.y, (int)SIZE.x, (int)SIZE.y}; + return CBox{(int)POS.x, (int)POS.y, (int)SIZE.x, (int)SIZE.y}; } -wlr_box CWindow::getWindowInputBox() { +CBox CWindow::getWindowInputBox() { const int BORDERSIZE = getRealBorderSize(); if (m_sAdditionalConfigData.dimAround) { @@ -165,13 +165,13 @@ wlr_box CWindow::getWindowInputBox() { } // Add extents to the real base BB and return - wlr_box finalBox = {m_vRealPosition.vec().x - maxExtents.topLeft.x, m_vRealPosition.vec().y - maxExtents.topLeft.y, - m_vRealSize.vec().x + maxExtents.topLeft.x + maxExtents.bottomRight.x, m_vRealSize.vec().y + maxExtents.topLeft.y + maxExtents.bottomRight.y}; + CBox finalBox = {m_vRealPosition.vec().x - maxExtents.topLeft.x, m_vRealPosition.vec().y - maxExtents.topLeft.y, + m_vRealSize.vec().x + maxExtents.topLeft.x + maxExtents.bottomRight.x, m_vRealSize.vec().y + maxExtents.topLeft.y + maxExtents.bottomRight.y}; return finalBox; } -wlr_box CWindow::getWindowMainSurfaceBox() { +CBox CWindow::getWindowMainSurfaceBox() { return {m_vRealPosition.vec().x, m_vRealPosition.vec().y, m_vRealSize.vec().x, m_vRealSize.vec().y}; } @@ -657,9 +657,9 @@ bool CWindow::isInCurvedCorner(double x, double y) { void findExtensionForVector2D(wlr_surface* surface, int x, int y, void* data) { const auto DATA = (SExtensionFindingData*)data; - wlr_box box = {DATA->origin.x + x, DATA->origin.y + y, surface->current.width, surface->current.height}; + CBox box = {DATA->origin.x + x, DATA->origin.y + y, surface->current.width, surface->current.height}; - if (wlr_box_contains_point(&box, DATA->vec.x, DATA->vec.y)) + if (box.containsPoint(DATA->vec)) *DATA->found = surface; } diff --git a/src/Window.hpp b/src/Window.hpp index 624d3325..dbfa2e04 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -11,14 +11,16 @@ #include "macros.hpp" #include "managers/XWaylandManager.hpp" -enum eIdleInhibitMode { +enum eIdleInhibitMode +{ IDLEINHIBIT_NONE = 0, IDLEINHIBIT_ALWAYS, IDLEINHIBIT_FULLSCREEN, IDLEINHIBIT_FOCUS }; -enum eGroupRules { +enum eGroupRules +{ // effective only during first map, except for _ALWAYS variant GROUP_NONE = 0, GROUP_SET = 1 << 0, // Open as new group or add to focused group @@ -334,11 +336,11 @@ class CWindow { } // methods - wlr_box getFullWindowBoundingBox(); + CBox getFullWindowBoundingBox(); SWindowDecorationExtents getFullWindowExtents(); - wlr_box getWindowInputBox(); - wlr_box getWindowMainSurfaceBox(); - wlr_box getWindowIdealBoundingBoxIgnoreReserved(); + CBox getWindowInputBox(); + CBox getWindowMainSurfaceBox(); + CBox getWindowIdealBoundingBoxIgnoreReserved(); void updateWindowDecos(); pid_t getPID(); IHyprWindowDecoration* getDecorationByType(eDecorationType); diff --git a/src/debug/HyprDebugOverlay.cpp b/src/debug/HyprDebugOverlay.cpp index 741f6e18..b5f7e1f2 100644 --- a/src/debug/HyprDebugOverlay.cpp +++ b/src/debug/HyprDebugOverlay.cpp @@ -233,6 +233,6 @@ void CHyprDebugOverlay::draw() { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, DATA); - wlr_box pMonBox = {0, 0, PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y}; + CBox pMonBox = {0, 0, PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y}; g_pHyprOpenGL->renderTexture(m_tTexture, &pMonBox, 1.f); } diff --git a/src/debug/HyprDebugOverlay.hpp b/src/debug/HyprDebugOverlay.hpp index 03027018..f3beab45 100644 --- a/src/debug/HyprDebugOverlay.hpp +++ b/src/debug/HyprDebugOverlay.hpp @@ -24,7 +24,7 @@ class CHyprMonitorDebugOverlay { std::deque<float> m_dLastAnimationTicks; std::chrono::high_resolution_clock::time_point m_tpLastFrame; CMonitor* m_pMonitor = nullptr; - wlr_box m_wbLastDrawnBox; + CBox m_wbLastDrawnBox; friend class CHyprRenderer; }; diff --git a/src/debug/HyprNotificationOverlay.cpp b/src/debug/HyprNotificationOverlay.cpp index f82ca9bb..12f7a575 100644 --- a/src/debug/HyprNotificationOverlay.cpp +++ b/src/debug/HyprNotificationOverlay.cpp @@ -50,7 +50,7 @@ void CHyprNotificationOverlay::addNotification(const std::string& text, const CC } } -wlr_box CHyprNotificationOverlay::drawNotifications(CMonitor* pMonitor) { +CBox CHyprNotificationOverlay::drawNotifications(CMonitor* pMonitor) { static constexpr auto ANIM_DURATION_MS = 600.0; static constexpr auto ANIM_LAG_MS = 100.0; static constexpr auto NOTIF_LEFTBAR_SIZE = 5.0; @@ -170,7 +170,7 @@ wlr_box CHyprNotificationOverlay::drawNotifications(CMonitor* pMonitor) { // cleanup notifs std::erase_if(m_dNotifications, [](const auto& notif) { return notif->started.getMillis() > notif->timeMs; }); - return wlr_box{(int)(pMonitor->vecPosition.x + pMonitor->vecSize.x - maxWidth - 20), (int)pMonitor->vecPosition.y, (int)maxWidth + 20, (int)offsetY + 10}; + return CBox{(int)(pMonitor->vecPosition.x + pMonitor->vecSize.x - maxWidth - 20), (int)pMonitor->vecPosition.y, (int)maxWidth + 20, (int)offsetY + 10}; } void CHyprNotificationOverlay::draw(CMonitor* pMonitor) { @@ -201,7 +201,7 @@ void CHyprNotificationOverlay::draw(CMonitor* pMonitor) { cairo_surface_flush(m_pCairoSurface); - wlr_box damage = drawNotifications(pMonitor); + CBox damage = drawNotifications(pMonitor); g_pHyprRenderer->damageBox(&damage); g_pHyprRenderer->damageBox(&m_bLastDamage); @@ -224,6 +224,6 @@ void CHyprNotificationOverlay::draw(CMonitor* pMonitor) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pMonitor->vecPixelSize.x, pMonitor->vecPixelSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, DATA); - wlr_box pMonBox = {0, 0, pMonitor->vecPixelSize.x, pMonitor->vecPixelSize.y}; + CBox pMonBox = {0, 0, pMonitor->vecPixelSize.x, pMonitor->vecPixelSize.y}; g_pHyprOpenGL->renderTexture(m_tTexture, &pMonBox, 1.f); }
\ No newline at end of file diff --git a/src/debug/HyprNotificationOverlay.hpp b/src/debug/HyprNotificationOverlay.hpp index 462bbde1..46a9a3d0 100644 --- a/src/debug/HyprNotificationOverlay.hpp +++ b/src/debug/HyprNotificationOverlay.hpp @@ -44,8 +44,8 @@ class CHyprNotificationOverlay { void addNotification(const std::string& text, const CColor& color, const float timeMs, const eIcons icon = ICON_NONE); private: - wlr_box drawNotifications(CMonitor* pMonitor); - wlr_box m_bLastDamage; + CBox drawNotifications(CMonitor* pMonitor); + CBox m_bLastDamage; std::deque<std::unique_ptr<SNotification>> m_dNotifications; diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index 5762e21a..5f295408 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -95,8 +95,8 @@ void Events::listener_destroyLayerSurface(void* owner, void* data) { PMONITOR->scheduledRecalc = true; // and damage - wlr_box geomFixed = {layersurface->geometry.x + PMONITOR->vecPosition.x, layersurface->geometry.y + PMONITOR->vecPosition.y, layersurface->geometry.width, - layersurface->geometry.height}; + CBox geomFixed = {layersurface->geometry.x + PMONITOR->vecPosition.x, layersurface->geometry.y + PMONITOR->vecPosition.y, layersurface->geometry.width, + layersurface->geometry.height}; g_pHyprRenderer->damageBox(&geomFixed); } @@ -157,8 +157,8 @@ void Events::listener_mapLayerSurface(void* owner, void* data) { layersurface->position = Vector2D(layersurface->geometry.x, layersurface->geometry.y); - wlr_box geomFixed = {layersurface->geometry.x + PMONITOR->vecPosition.x, layersurface->geometry.y + PMONITOR->vecPosition.y, layersurface->geometry.width, - layersurface->geometry.height}; + CBox geomFixed = {layersurface->geometry.x + PMONITOR->vecPosition.x, layersurface->geometry.y + PMONITOR->vecPosition.y, layersurface->geometry.width, + layersurface->geometry.height}; g_pHyprRenderer->damageBox(&geomFixed); const auto WORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); const bool FULLSCREEN = WORKSPACE->m_bHasFullscreenWindow && WORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL; @@ -247,8 +247,8 @@ void Events::listener_unmapLayerSurface(void* owner, void* data) { } } - wlr_box geomFixed = {layersurface->geometry.x + PMONITOR->vecPosition.x, layersurface->geometry.y + PMONITOR->vecPosition.y, layersurface->geometry.width, - layersurface->geometry.height}; + CBox geomFixed = {layersurface->geometry.x + PMONITOR->vecPosition.x, layersurface->geometry.y + PMONITOR->vecPosition.y, layersurface->geometry.width, + layersurface->geometry.height}; g_pHyprRenderer->damageBox(&geomFixed); geomFixed = {layersurface->geometry.x + (int)PMONITOR->vecPosition.x, layersurface->geometry.y + (int)PMONITOR->vecPosition.y, @@ -270,7 +270,7 @@ void Events::listener_commitLayerSurface(void* owner, void* data) { if (layersurface->layer == ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND || layersurface->layer == ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM) g_pHyprOpenGL->markBlurDirtyForMonitor(PMONITOR); // so that blur is recalc'd - wlr_box geomFixed = {layersurface->geometry.x, layersurface->geometry.y, layersurface->geometry.width, layersurface->geometry.height}; + CBox geomFixed = {layersurface->geometry.x, layersurface->geometry.y, layersurface->geometry.width, layersurface->geometry.height}; g_pHyprRenderer->damageBox(&geomFixed); // fix if it changed its mon diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp index f6375edd..9155fe87 100644 --- a/src/events/Monitors.cpp +++ b/src/events/Monitors.cpp @@ -28,8 +28,9 @@ void Events::listener_change(wl_listener* listener, void* data) { const auto CONFIGHEAD = wlr_output_configuration_head_v1_create(CONFIG, m->output); - wlr_box BOX; - wlr_output_layout_get_box(g_pCompositor->m_sWLROutputLayout, m->output, &BOX); + CBox BOX; + wlr_output_layout_get_box(g_pCompositor->m_sWLROutputLayout, m->output, BOX.pWlr()); + BOX.applyFromWlr(); //m->vecSize.x = BOX.width; // m->vecSize.y = BOX.height; diff --git a/src/events/Popups.cpp b/src/events/Popups.cpp index 559c8410..c8898c3b 100644 --- a/src/events/Popups.cpp +++ b/src/events/Popups.cpp @@ -64,9 +64,9 @@ void createNewPopup(wlr_xdg_popup* popup, SXDGPopup* pHyprPopup) { const auto PMONITOR = g_pCompositor->m_pLastMonitor; - wlr_box box = {.x = PMONITOR->vecPosition.x - pHyprPopup->lx, .y = PMONITOR->vecPosition.y - pHyprPopup->ly, .width = PMONITOR->vecSize.x, .height = PMONITOR->vecSize.y}; + CBox box = {PMONITOR->vecPosition.x - pHyprPopup->lx, PMONITOR->vecPosition.y - pHyprPopup->ly, PMONITOR->vecSize.x, PMONITOR->vecSize.y}; - wlr_xdg_popup_unconstrain_from_box(popup, &box); + wlr_xdg_popup_unconstrain_from_box(popup, box.pWlr()); pHyprPopup->monitor = PMONITOR; @@ -159,8 +159,9 @@ void Events::listener_mapPopupXDG(void* owner, void* data) { int lx = 0, ly = 0; addPopupGlobalCoords(PPOPUP, &lx, &ly); - wlr_box extents; - wlr_surface_get_extends(PPOPUP->popup->base->surface, &extents); + CBox extents; + wlr_surface_get_extends(PPOPUP->popup->base->surface, extents.pWlr()); + extents.applyFromWlr(); g_pHyprRenderer->damageBox(lx - extents.x, ly - extents.y, extents.width + 2, extents.height + 2); @@ -180,17 +181,18 @@ void Events::listener_repositionPopupXDG(void* owner, void* data) { int lx = 0, ly = 0; addPopupGlobalCoords(PPOPUP, &lx, &ly); - wlr_box extents; - wlr_surface_get_extends(PPOPUP->popup->base->surface, &extents); + CBox extents; + wlr_surface_get_extends(PPOPUP->popup->base->surface, extents.pWlr()); + extents.applyFromWlr(); PPOPUP->lastPos = {lx - extents.x, ly - extents.y}; PPOPUP->repositionRequested = true; const auto PMONITOR = g_pCompositor->m_pLastMonitor; - wlr_box box = {PMONITOR->vecPosition.x - lx + PPOPUP->popup->current.geometry.x, PMONITOR->vecPosition.y - ly + PPOPUP->popup->current.geometry.y, PMONITOR->vecSize.x, - PMONITOR->vecSize.y}; - wlr_xdg_popup_unconstrain_from_box(PPOPUP->popup, &box); + CBox box = {PMONITOR->vecPosition.x - lx + PPOPUP->popup->current.geometry.x, PMONITOR->vecPosition.y - ly + PPOPUP->popup->current.geometry.y, PMONITOR->vecSize.x, + PMONITOR->vecSize.y}; + wlr_xdg_popup_unconstrain_from_box(PPOPUP->popup, box.pWlr()); } void Events::listener_unmapPopupXDG(void* owner, void* data) { @@ -207,8 +209,9 @@ void Events::listener_unmapPopupXDG(void* owner, void* data) { int lx = 0, ly = 0; addPopupGlobalCoords(PPOPUP, &lx, &ly); - wlr_box extents; - wlr_surface_get_extends(PPOPUP->popup->base->surface, &extents); + CBox extents; + wlr_surface_get_extends(PPOPUP->popup->base->surface, extents.pWlr()); + extents.applyFromWlr(); g_pHyprRenderer->damageBox(lx - extents.x, ly - extents.y, extents.width + 2, extents.height + 2); @@ -233,8 +236,9 @@ void Events::listener_commitPopupXDG(void* owner, void* data) { int lx = 0, ly = 0; addPopupGlobalCoords(PPOPUP, &lx, &ly); - wlr_box extents; - wlr_surface_get_extends(PPOPUP->popup->base->surface, &extents); + CBox extents; + wlr_surface_get_extends(PPOPUP->popup->base->surface, extents.pWlr()); + extents.applyFromWlr(); if (PPOPUP->repositionRequested) g_pHyprRenderer->damageBox(PPOPUP->lastPos.x, PPOPUP->lastPos.y, extents.width + 2, extents.height + 2); diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 59bd5fef..23559773 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -96,7 +96,7 @@ void Events::listener_mapWindow(void* owner, void* data) { if (PWORKSPACE->m_bDefaultPseudo) { PWINDOW->m_bIsPseudotiled = true; - wlr_box desiredGeometry = {0}; + CBox desiredGeometry = {0}; g_pXWaylandManager->getGeometryForWindow(PWINDOW, &desiredGeometry); PWINDOW->m_vPseudoSize = Vector2D(desiredGeometry.width, desiredGeometry.height); } diff --git a/src/helpers/Box.cpp b/src/helpers/Box.cpp new file mode 100644 index 00000000..450871cb --- /dev/null +++ b/src/helpers/Box.cpp @@ -0,0 +1,104 @@ +#include "Box.hpp" +wlr_box CBox::wlr() { + CBox rounded = roundInternal(); + m_bWlrBox = wlr_box{(int)rounded.x, (int)rounded.y, (int)rounded.w, (int)rounded.h}; + return m_bWlrBox; +} + +wlr_box* CBox::pWlr() { + CBox rounded = roundInternal(); + m_bWlrBox = wlr_box{(int)rounded.x, (int)rounded.y, (int)rounded.w, (int)rounded.h}; + return &m_bWlrBox; +} + +CBox& CBox::scale(double scale) { + x *= scale; + y *= scale; + w *= scale; + h *= scale; + + return *this; +} + +CBox& CBox::scale(const Vector2D& scale) { + x *= scale.x; + y *= scale.y; + w *= scale.x; + h *= scale.y; + + return *this; +} + +CBox& CBox::translate(const Vector2D& vec) { + x += vec.x; + y += vec.y; + + return *this; +} + +Vector2D CBox::middle() const { + return Vector2D{x + w / 2.0, y + h / 2.0}; +} + +bool CBox::containsPoint(const Vector2D& vec) const { + return VECINRECT(vec, x, y, x + w, y + h); +} + +bool CBox::empty() const { + return w == 0 || h == 0; +} + +CBox& CBox::applyFromWlr() { + x = m_bWlrBox.x; + y = m_bWlrBox.y; + w = m_bWlrBox.width; + h = m_bWlrBox.height; + + return *this; +} + +CBox& CBox::round() { + float newW = x + w - std::floor(x); + float newH = y + h - std::floor(y); + x = std::floor(x); + y = std::floor(y); + w = std::floor(newW); + h = std::floor(newH); + + return *this; +} + +CBox& CBox::transform(const wl_output_transform t, double w, double h) { + wlr_box_transform(&m_bWlrBox, pWlr(), t, w, h); + applyFromWlr(); + + return *this; +} + +CBox& CBox::addExtents(const SWindowDecorationExtents& e) { + x -= e.topLeft.x; + y -= e.topLeft.y; + w += e.topLeft.x + e.bottomRight.x; + h += e.topLeft.y + e.bottomRight.y; + + return *this; +} + +CBox& CBox::scaleFromCenter(double scale) { + double oldW = w, oldH = h; + + w *= scale; + h *= scale; + + x -= (w - oldW) / 2.0; + y -= (h - oldH) / 2.0; + + return *this; +} + +CBox CBox::roundInternal() { + float newW = x + w - std::floor(x); + float newH = y + h - std::floor(y); + + return CBox{std::floor(x), std::floor(y), std::floor(newW), std::floor(newH)}; +}
\ No newline at end of file diff --git a/src/helpers/Box.hpp b/src/helpers/Box.hpp new file mode 100644 index 00000000..7a8aa939 --- /dev/null +++ b/src/helpers/Box.hpp @@ -0,0 +1,66 @@ +#pragma once + +#include <wlr/util/box.h> +#include "Vector2D.hpp" +#include "../SharedDefs.hpp" + +class CBox { + public: + CBox(double x_, double y_, double w_, double h_) { + x = x_; + y = y_; + w = w_; + h = h_; + } + + CBox() { + w = 0; + h = 0; + } + + CBox(const wlr_box& box) { + x = box.x; + y = box.y; + w = box.width; + h = box.height; + } + + CBox(const double d) { + x = d; + y = d; + w = d; + h = d; + } + + wlr_box wlr(); + wlr_box* pWlr(); + + CBox& applyFromWlr(); + CBox& scale(double scale); + CBox& scaleFromCenter(double scale); + CBox& scale(const Vector2D& scale); + CBox& translate(const Vector2D& vec); + CBox& round(); + CBox& transform(const wl_output_transform t, double w, double h); + CBox& addExtents(const SWindowDecorationExtents& e); + + Vector2D middle() const; + + bool containsPoint(const Vector2D& vec) const; + bool empty() const; + + double x = 0, y = 0; + union { + double w; + double width; + }; + union { + double h; + double height; + }; + + private: + CBox roundInternal(); + + wlr_box m_bWlrBox; +};
\ No newline at end of file diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index b65f4a87..b3a8ade7 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -185,13 +185,6 @@ std::string escapeJSONStrings(const std::string& str) { return oss.str(); } -void scaleBox(wlr_box* box, float scale) { - box->width = std::round(box->width * scale); - box->height = std::round(box->height * scale); - box->x = std::round(box->x * scale); - box->y = std::round(box->y * scale); -} - std::string removeBeginEndSpacesTabs(std::string str) { if (str.empty()) return str; diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index 499aa90f..3bb07f79 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -16,7 +16,6 @@ struct SCallstackFrameInfo { std::string absolutePath(const std::string&, const std::string&); void addWLSignal(wl_signal*, wl_listener*, void* pOwner, const std::string& ownerString); std::string escapeJSONStrings(const std::string& str); -void scaleBox(wlr_box*, float); std::string removeBeginEndSpacesTabs(std::string); bool isNumber(const std::string&, bool allowfloat = false); bool isDirection(const std::string&); diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 6d6b40e0..9dbd2a3e 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -317,14 +317,14 @@ void CMonitor::addDamage(const CRegion* rg) { addDamage(const_cast<CRegion*>(rg)->pixman()); } -void CMonitor::addDamage(const wlr_box* box) { +void CMonitor::addDamage(const CBox* box) { static auto* const PZOOMFACTOR = &g_pConfigManager->getConfigValuePtr("misc:cursor_zoom_factor")->floatValue; if (*PZOOMFACTOR != 1.f && g_pCompositor->getMonitorFromCursor() == this) { wlr_damage_ring_add_whole(&damage); g_pCompositor->scheduleFrameForMonitor(this); } - if (wlr_damage_ring_add_box(&damage, box)) + if (wlr_damage_ring_add_box(&damage, const_cast<CBox*>(box)->pWlr())) g_pCompositor->scheduleFrameForMonitor(this); } diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp index 5e861b50..10790b5e 100644 --- a/src/helpers/Monitor.hpp +++ b/src/helpers/Monitor.hpp @@ -113,7 +113,7 @@ class CMonitor { void onDisconnect(); void addDamage(const pixman_region32_t* rg); void addDamage(const CRegion* rg); - void addDamage(const wlr_box* box); + void addDamage(const CBox* box); void setMirror(const std::string&); bool isMirror(); float getDefaultScale(); diff --git a/src/helpers/Region.cpp b/src/helpers/Region.cpp index 5515e71e..fdf8a242 100644 --- a/src/helpers/Region.cpp +++ b/src/helpers/Region.cpp @@ -21,6 +21,10 @@ CRegion::CRegion(wlr_box* box) { pixman_region32_init_rect(&m_rRegion, box->x, box->y, box->width, box->height); } +CRegion::CRegion(CBox* box) { + pixman_region32_init_rect(&m_rRegion, box->x, box->y, box->w, box->h); +} + CRegion::CRegion(pixman_box32_t* box) { pixman_region32_init_rect(&m_rRegion, box->x1, box->y1, box->x2 - box->x1, box->y2 - box->y1); } @@ -100,7 +104,7 @@ std::vector<pixman_box32_t> CRegion::getRects() const { return result; } -wlr_box CRegion::getExtents() { +CBox CRegion::getExtents() { pixman_box32_t* box = pixman_region32_extents(&m_rRegion); return {box->x1, box->y1, box->x2 - box->x1, box->y2 - box->y1}; } diff --git a/src/helpers/Region.hpp b/src/helpers/Region.hpp index cc745f9e..94b639c9 100644 --- a/src/helpers/Region.hpp +++ b/src/helpers/Region.hpp @@ -15,6 +15,8 @@ class CRegion { CRegion(double x, double y, double w, double h); /* Create from a wlr_box */ CRegion(wlr_box* box); + /* Create from a CBox */ + CRegion(CBox* box); /* Create from a pixman_box32_t */ CRegion(pixman_box32_t* box); @@ -43,7 +45,7 @@ class CRegion { CRegion& translate(const Vector2D& vec); CRegion& invert(pixman_box32_t* box); CRegion& scale(float scale); - wlr_box getExtents(); + CBox getExtents(); bool containsPoint(const Vector2D& vec) const; bool empty() const; Vector2D closestPoint(const Vector2D& vec) const; @@ -51,7 +53,7 @@ class CRegion { std::vector<pixman_box32_t> getRects() const; pixman_region32_t* pixman() { - return &m_rRegion; + return &m_rRegion; } private: diff --git a/src/helpers/SubsurfaceTree.cpp b/src/helpers/SubsurfaceTree.cpp index c3716100..84ba5cbb 100644 --- a/src/helpers/SubsurfaceTree.cpp +++ b/src/helpers/SubsurfaceTree.cpp @@ -98,8 +98,9 @@ void SubsurfaceTree::destroySurfaceTree(SSurfaceTreeNode* pNode) { // damage if (pNode->pSurface && pNode->pSurface->exists()) { - wlr_box extents = {}; - wlr_surface_get_extends(pNode->pSurface->wlr(), &extents); + CBox extents = {}; + wlr_surface_get_extends(pNode->pSurface->wlr(), extents.pWlr()); + extents.applyFromWlr(); int lx = 0, ly = 0; addSurfaceGlobalOffset(pNode, &lx, &ly); @@ -198,7 +199,7 @@ void Events::listener_unmapSubsurface(void* owner, void* data) { int lx = 0, ly = 0; addSurfaceGlobalOffset(PNODE, &lx, &ly); - wlr_box extents = {lx, ly, 0, 0}; + CBox extents = {lx, ly, 0, 0}; extents.width = PNODE->pSurface->wlr()->current.width; extents.height = PNODE->pSurface->wlr()->current.height; diff --git a/src/helpers/Vector2D.hpp b/src/helpers/Vector2D.hpp index 3c5d4a2c..6112b8e4 100644 --- a/src/helpers/Vector2D.hpp +++ b/src/helpers/Vector2D.hpp @@ -22,6 +22,9 @@ class Vector2D { Vector2D operator-(const Vector2D& a) const { return Vector2D(this->x - a.x, this->y - a.y); } + Vector2D operator-() const { + return Vector2D(-this->x, -this->y); + } Vector2D operator*(const float& a) const { return Vector2D(this->x * a, this->y * a); } diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index e8647426..f7efbe98 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -33,7 +33,7 @@ struct SLayerSurface { DYNLISTENER(commitLayerSurface); DYNLISTENER(newPopup); - wlr_box geometry = {0, 0, 0, 0}; + CBox geometry = {0, 0, 0, 0}; Vector2D position; zwlr_layer_shell_v1_layer layer; @@ -65,12 +65,12 @@ class CMonitor; struct SRenderData { CMonitor* pMonitor; timespec* when; - int x, y; + double x, y; // for iters void* data = nullptr; wlr_surface* surface = nullptr; - int w, h; + double w, h; // for rounding bool dontRound = true; diff --git a/src/hyprerror/HyprError.cpp b/src/hyprerror/HyprError.cpp index 4f916139..6a91ba87 100644 --- a/src/hyprerror/HyprError.cpp +++ b/src/hyprerror/HyprError.cpp @@ -154,7 +154,7 @@ void CHyprError::draw() { const auto PMONITOR = g_pHyprOpenGL->m_RenderData.pMonitor; - wlr_box monbox = {0, 0, PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y}; + CBox monbox = {0, 0, PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y}; m_bDamageBox.x = (int)PMONITOR->vecPosition.x; m_bDamageBox.y = (int)PMONITOR->vecPosition.y; diff --git a/src/hyprerror/HyprError.hpp b/src/hyprerror/HyprError.hpp index ff4e8577..cee648e2 100644 --- a/src/hyprerror/HyprError.hpp +++ b/src/hyprerror/HyprError.hpp @@ -23,7 +23,7 @@ class CHyprError { bool m_bIsCreated = false; CTexture m_tTexture; CAnimatedVariable m_fFadeOpacity; - wlr_box m_bDamageBox = {0, 0, 0, 0}; + CBox m_bDamageBox = {0, 0, 0, 0}; bool m_bMonitorChanged = false; }; diff --git a/src/includes.hpp b/src/includes.hpp index a70815dc..2ffb7710 100644 --- a/src/includes.hpp +++ b/src/includes.hpp @@ -145,3 +145,4 @@ extern "C" { #endif #include "helpers/Vector2D.hpp" +#include "helpers/Box.hpp" diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 2bbda858..f9f8ab59 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -6,7 +6,7 @@ void IHyprLayout::onWindowCreated(CWindow* pWindow, eDirection direction) { if (pWindow->m_bIsFloating) { onWindowCreatedFloating(pWindow); } else { - wlr_box desiredGeometry = {0}; + CBox desiredGeometry = {}; g_pXWaylandManager->getGeometryForWindow(pWindow, &desiredGeometry); if (desiredGeometry.width <= 5 || desiredGeometry.height <= 5) { @@ -75,7 +75,7 @@ void IHyprLayout::onWindowRemovedFloating(CWindow* pWindow) { void IHyprLayout::onWindowCreatedFloating(CWindow* pWindow) { - wlr_box desiredGeometry = {0}; + CBox desiredGeometry = {0}; g_pXWaylandManager->getGeometryForWindow(pWindow, &desiredGeometry); const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 0fbb2391..e3b7b7ab 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -141,8 +141,8 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc for (auto it = m_lMasterNodesData.begin(); it != m_lMasterNodesData.end(); ++it) { if (it->workspaceID != pWindow->m_iWorkspaceID) continue; - const wlr_box box = it->pWindow->getWindowIdealBoundingBoxIgnoreReserved(); - if (wlr_box_contains_point(&box, MOUSECOORDS.x, MOUSECOORDS.y)) { + const CBox box = it->pWindow->getWindowIdealBoundingBoxIgnoreReserved(); + if (box.containsPoint(MOUSECOORDS)) { switch (orientation) { case ORIENTATION_LEFT: case ORIENTATION_RIGHT: diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index a7d05030..1dc8e2c6 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -81,7 +81,7 @@ void CAnimationManager::tick() { CMonitor* PMONITOR = nullptr; bool animationsDisabled = animGlobalDisabled; - wlr_box WLRBOXPREV = {0, 0, 0, 0}; + CBox WLRBOXPREV = {0, 0, 0, 0}; if (PWINDOW) { WLRBOXPREV = PWINDOW->getFullWindowBoundingBox(); PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); @@ -236,7 +236,7 @@ void CAnimationManager::tick() { BORDERSIZE + ROUNDINGSIZE); // bottom // damage for new box - const wlr_box WLRBOXNEW = {PWINDOW->m_vRealPosition.vec().x, PWINDOW->m_vRealPosition.vec().y, PWINDOW->m_vRealSize.vec().x, PWINDOW->m_vRealSize.vec().y}; + const CBox WLRBOXNEW = {PWINDOW->m_vRealPosition.vec().x, PWINDOW->m_vRealPosition.vec().y, PWINDOW->m_vRealSize.vec().x, PWINDOW->m_vRealSize.vec().y}; g_pHyprRenderer->damageBox(WLRBOXNEW.x - BORDERSIZE, WLRBOXNEW.y - BORDERSIZE, WLRBOXNEW.width + 2 * BORDERSIZE, BORDERSIZE + ROUNDINGSIZE); // top g_pHyprRenderer->damageBox(WLRBOXNEW.x - BORDERSIZE, WLRBOXNEW.y - BORDERSIZE, BORDERSIZE + ROUNDINGSIZE, WLRBOXNEW.height + 2 * BORDERSIZE); // left g_pHyprRenderer->damageBox(WLRBOXNEW.x + WLRBOXNEW.width - ROUNDINGSIZE, WLRBOXNEW.y - BORDERSIZE, BORDERSIZE + ROUNDINGSIZE, @@ -255,9 +255,8 @@ void CAnimationManager::tick() { if (PDECO) { const auto EXTENTS = PDECO->getWindowDecorationExtents(); - wlr_box dmg = {PWINDOW->m_vRealPosition.vec().x - EXTENTS.topLeft.x, PWINDOW->m_vRealPosition.vec().y - EXTENTS.topLeft.y, - PWINDOW->m_vRealSize.vec().x + EXTENTS.topLeft.x + EXTENTS.bottomRight.x, - PWINDOW->m_vRealSize.vec().y + EXTENTS.topLeft.y + EXTENTS.bottomRight.y}; + CBox dmg = {PWINDOW->m_vRealPosition.vec().x - EXTENTS.topLeft.x, PWINDOW->m_vRealPosition.vec().y - EXTENTS.topLeft.y, + PWINDOW->m_vRealSize.vec().x + EXTENTS.topLeft.x + EXTENTS.bottomRight.x, PWINDOW->m_vRealSize.vec().y + EXTENTS.topLeft.y + EXTENTS.bottomRight.y}; if (!*PSHADOWIGNOREWINDOW) { // easy, damage the entire box diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index a40647fa..04fbaf21 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -74,7 +74,7 @@ void CHyprXWaylandManager::activateWindow(CWindow* pWindow, bool activate) { g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID)->m_pLastFocusedWindow = pWindow; } -void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, wlr_box* pbox) { +void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, CBox* pbox) { if (pWindow->m_bIsX11) { const auto SIZEHINTS = pWindow->m_uSurface.xwayland->size_hints; @@ -89,8 +89,10 @@ void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, wlr_box* pbox) pbox->width = pWindow->m_uSurface.xwayland->width; pbox->height = pWindow->m_uSurface.xwayland->height; } - } else - wlr_xdg_surface_get_geometry(pWindow->m_uSurface.xdg, pbox); + } else { + wlr_xdg_surface_get_geometry(pWindow->m_uSurface.xdg, pbox->pWlr()); + pbox->applyFromWlr(); + } } std::string CHyprXWaylandManager::getTitle(CWindow* pWindow) { diff --git a/src/managers/XWaylandManager.hpp b/src/managers/XWaylandManager.hpp index 807f0593..e41313e0 100644 --- a/src/managers/XWaylandManager.hpp +++ b/src/managers/XWaylandManager.hpp @@ -15,7 +15,7 @@ class CHyprXWaylandManager { wlr_surface* getWindowSurface(CWindow*); void activateSurface(wlr_surface*, bool); void activateWindow(CWindow*, bool); - void getGeometryForWindow(CWindow*, wlr_box*); + void getGeometryForWindow(CWindow*, CBox*); std::string getTitle(CWindow*); std::string getAppIDClass(CWindow*); void sendCloseWindow(CWindow*); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index dcbf4e3c..d7733e96 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -599,8 +599,8 @@ void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) { // TODO detect click on LS properly if (*PRESIZEONBORDER && !m_bLastFocusOnLS) { if (w && !w->m_bIsFullscreen) { - const wlr_box real = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if ((!wlr_box_contains_point(&real, mouseCoords.x, mouseCoords.y) || w->isInCurvedCorner(mouseCoords.x, mouseCoords.y)) && !w->hasPopupAt(mouseCoords)) { + const CBox real = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; + if ((!real.containsPoint(mouseCoords) || w->isInCurvedCorner(mouseCoords.x, mouseCoords.y)) && !w->hasPopupAt(mouseCoords)) { g_pKeybindManager->resizeWithBorder(e); return; } @@ -675,8 +675,8 @@ void CInputManager::onMouseWheel(wlr_pointer_axis_event* e) { const auto pWindow = g_pCompositor->vectorToWindowIdeal(MOUSECOORDS); if (*PGROUPBARSCROLLING && pWindow && !pWindow->m_bIsFullscreen && !pWindow->hasPopupAt(MOUSECOORDS) && pWindow->m_sGroupData.pNextWindow) { - const wlr_box box = pWindow->getDecorationByType(DECORATION_GROUPBAR)->getWindowDecorationRegion().getExtents(); - if (wlr_box_contains_point(&box, MOUSECOORDS.x, MOUSECOORDS.y)) { + const CBox box = pWindow->getDecorationByType(DECORATION_GROUPBAR)->getWindowDecorationRegion().getExtents(); + if (box.containsPoint(MOUSECOORDS)) { if (e->delta > 0) pWindow->setGroupCurrent(pWindow->m_sGroupData.pNextWindow); else @@ -1207,7 +1207,7 @@ void CInputManager::updateDragIcon() { switch (m_sDrag.dragIcon->drag->grab_type) { case WLR_DRAG_GRAB_KEYBOARD: break; case WLR_DRAG_GRAB_KEYBOARD_POINTER: { - wlr_box box = {m_sDrag.pos.x - 2, m_sDrag.pos.y - 2, m_sDrag.dragIcon->surface->current.width + 4, m_sDrag.dragIcon->surface->current.height + 4}; + CBox box = {m_sDrag.pos.x - 2, m_sDrag.pos.y - 2, m_sDrag.dragIcon->surface->current.width + 4, m_sDrag.dragIcon->surface->current.height + 4}; g_pHyprRenderer->damageBox(&box); m_sDrag.pos = getMouseCoordsInternal(); break; @@ -1474,9 +1474,9 @@ void CInputManager::setTabletConfigs() { const auto REGION_POS = g_pConfigManager->getDeviceVec(t.name, "region_position", "input:tablet:region_position"); const auto REGION_SIZE = g_pConfigManager->getDeviceVec(t.name, "region_size", "input:tablet:region_size"); - const auto REGION = wlr_box{REGION_POS.x, REGION_POS.y, REGION_SIZE.x, REGION_SIZE.y}; - if (!wlr_box_empty(®ION)) - wlr_cursor_map_input_to_region(g_pCompositor->m_sWLRCursor, t.wlrDevice, ®ION); + auto regionBox = CBox{REGION_POS.x, REGION_POS.y, REGION_SIZE.x, REGION_SIZE.y}; + if (!regionBox.empty()) + wlr_cursor_map_input_to_region(g_pCompositor->m_sWLRCursor, t.wlrDevice, regionBox.pWlr()); } } } @@ -1621,14 +1621,14 @@ void CInputManager::setCursorIconOnBorder(CWindow* w) { // give a small leeway (10 px) for corner icon const auto CORNER = *PROUNDING + BORDERSIZE + 10; const auto mouseCoords = getMouseCoordsInternal(); - wlr_box box = w->getWindowMainSurfaceBox(); + CBox box = w->getWindowMainSurfaceBox(); eBorderIconDirection direction = BORDERICON_NONE; - wlr_box boxFullGrabInput = {box.x - *PEXTENDBORDERGRAB - BORDERSIZE, box.y - *PEXTENDBORDERGRAB - BORDERSIZE, box.width + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE), - box.height + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE)}; + CBox boxFullGrabInput = {box.x - *PEXTENDBORDERGRAB - BORDERSIZE, box.y - *PEXTENDBORDERGRAB - BORDERSIZE, box.width + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE), + box.height + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE)}; if (w->hasPopupAt(mouseCoords)) direction = BORDERICON_NONE; - else if (!wlr_box_contains_point(&boxFullGrabInput, mouseCoords.x, mouseCoords.y) || (!m_lCurrentlyHeldButtons.empty() && !currentlyDraggedWindow)) + else if (!boxFullGrabInput.containsPoint(mouseCoords) || (!m_lCurrentlyHeldButtons.empty() && !currentlyDraggedWindow)) direction = BORDERICON_NONE; else { @@ -1647,7 +1647,7 @@ void CInputManager::setCursorIconOnBorder(CWindow* w) { if (onDeco) direction = BORDERICON_NONE; else { - if (wlr_box_contains_point(&box, mouseCoords.x, mouseCoords.y)) { + if (box.containsPoint(mouseCoords)) { if (!w->isInCurvedCorner(mouseCoords.x, mouseCoords.y)) { direction = BORDERICON_NONE; } else { diff --git a/src/managers/input/InputMethodRelay.cpp b/src/managers/input/InputMethodRelay.cpp index 4af17096..5b6df08d 100644 --- a/src/managers/input/InputMethodRelay.cpp +++ b/src/managers/input/InputMethodRelay.cpp @@ -178,7 +178,7 @@ void CInputMethodRelay::updateInputPopup(SIMEPopup* pPopup) { bool cursorRect = PFOCUSEDTI->pWlrInput ? PFOCUSEDTI->pWlrInput->current.features & WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE : true; const auto PFOCUSEDSURFACE = focusedSurface(PFOCUSEDTI); - auto cursorBox = PFOCUSEDTI->pWlrInput ? PFOCUSEDTI->pWlrInput->current.cursor_rectangle : PFOCUSEDTI->pV1Input->cursorRectangle; + CBox cursorBox = PFOCUSEDTI->pWlrInput ? PFOCUSEDTI->pWlrInput->current.cursor_rectangle : PFOCUSEDTI->pV1Input->cursorRectangle; CMonitor* pMonitor = nullptr; Vector2D parentPos; @@ -209,7 +209,7 @@ void CInputMethodRelay::updateInputPopup(SIMEPopup* pPopup) { if (!pMonitor) return; - wlr_box finalBox = cursorBox; + CBox finalBox = cursorBox; if (cursorBox.y + parentPos.y + pPopup->pSurface->surface->current.height + finalBox.height > pMonitor->vecPosition.y + pMonitor->vecSize.y) finalBox.y -= pPopup->pSurface->surface->current.height + finalBox.height; @@ -225,7 +225,7 @@ void CInputMethodRelay::updateInputPopup(SIMEPopup* pPopup) { pPopup->lastSize = Vector2D(pPopup->pSurface->surface->current.width, pPopup->pSurface->surface->current.height); - wlr_input_popup_surface_v2_send_text_input_rectangle(pPopup->pSurface, &finalBox); + wlr_input_popup_surface_v2_send_text_input_rectangle(pPopup->pSurface, finalBox.pWlr()); damagePopup(pPopup); } diff --git a/src/protocols/Screencopy.cpp b/src/protocols/Screencopy.cpp index aaec0fab..63ba8832 100644 --- a/src/protocols/Screencopy.cpp +++ b/src/protocols/Screencopy.cpp @@ -183,7 +183,7 @@ void CScreencopyProtocolManager::removeFrame(SScreencopyFrame* frame, bool force m_lFrames.remove(*frame); } -void CScreencopyProtocolManager::captureOutput(wl_client* client, wl_resource* resource, uint32_t frame, int32_t overlay_cursor, wl_resource* output, wlr_box box) { +void CScreencopyProtocolManager::captureOutput(wl_client* client, wl_resource* resource, uint32_t frame, int32_t overlay_cursor, wl_resource* output, CBox box) { const auto PCLIENT = clientFromResource(resource); const auto PFRAME = &m_lFrames.emplace_back(); @@ -239,8 +239,7 @@ void CScreencopyProtocolManager::captureOutput(wl_client* client, wl_resource* r } int ow, oh; wlr_output_effective_resolution(PFRAME->pMonitor->output, &ow, &oh); - wlr_box_transform(&PFRAME->box, &PFRAME->box, PFRAME->pMonitor->transform, ow, oh); - scaleBox(&PFRAME->box, PFRAME->pMonitor->scale); + PFRAME->box.transform(PFRAME->pMonitor->transform, ow, oh).scale(PFRAME->pMonitor->scale); PFRAME->shmStride = (PSHMINFO->bpp / 8) * PFRAME->box.width; diff --git a/src/protocols/Screencopy.hpp b/src/protocols/Screencopy.hpp index 3af75544..e3d1e22a 100644 --- a/src/protocols/Screencopy.hpp +++ b/src/protocols/Screencopy.hpp @@ -46,7 +46,7 @@ struct SScreencopyFrame { uint32_t shmFormat = 0; uint32_t dmabufFormat = 0; - wlr_box box = {0}; + CBox box = {}; int shmStride = 0; bool overlayCursor = false; @@ -73,7 +73,7 @@ class CScreencopyProtocolManager { void removeFrame(SScreencopyFrame* frame, bool force = false); void displayDestroy(); - void captureOutput(wl_client* client, wl_resource* resource, uint32_t frame, int32_t overlay_cursor, wl_resource* output, wlr_box box = {0, 0, 0, 0}); + void captureOutput(wl_client* client, wl_resource* resource, uint32_t frame, int32_t overlay_cursor, wl_resource* output, CBox box = {0, 0, 0, 0}); void copyFrame(wl_client* client, wl_resource* resource, wl_resource* buffer); diff --git a/src/protocols/TextInputV1.cpp b/src/protocols/TextInputV1.cpp index 9156da12..d69a79ca 100644 --- a/src/protocols/TextInputV1.cpp +++ b/src/protocols/TextInputV1.cpp @@ -200,7 +200,7 @@ void CTextInputV1ProtocolManager::handleSetContentType(wl_client* client, wl_res void CTextInputV1ProtocolManager::handleSetCursorRectangle(wl_client* client, wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height) { const auto PTI = tiFromResource(resource); - PTI->cursorRectangle = wlr_box{x, y, width, height}; + PTI->cursorRectangle = CBox{x, y, width, height}; } void CTextInputV1ProtocolManager::handleSetPreferredLanguage(wl_client* client, wl_resource* resource, const char* language) { diff --git a/src/protocols/TextInputV1.hpp b/src/protocols/TextInputV1.hpp index f714b24c..b279763d 100644 --- a/src/protocols/TextInputV1.hpp +++ b/src/protocols/TextInputV1.hpp @@ -39,9 +39,9 @@ struct STextInputV1 { uint32_t purpose = 0; } pendingContentType; - wlr_box cursorRectangle = {0, 0, 0, 0}; + CBox cursorRectangle = {0, 0, 0, 0}; - bool operator==(const STextInputV1& other) { + bool operator==(const STextInputV1& other) { return other.client == client && other.resourceCaller == resourceCaller && other.resourceImpl == resourceImpl; } }; diff --git a/src/protocols/ToplevelExport.cpp b/src/protocols/ToplevelExport.cpp index 3515d652..11287660 100644 --- a/src/protocols/ToplevelExport.cpp +++ b/src/protocols/ToplevelExport.cpp @@ -201,7 +201,7 @@ void CToplevelExportProtocolManager::captureToplevel(wl_client* client, wl_resou PFRAME->box = {0, 0, (int)(PFRAME->pWindow->m_vRealSize.vec().x * PMONITOR->scale), (int)(PFRAME->pWindow->m_vRealSize.vec().y * PMONITOR->scale)}; int ow, oh; wlr_output_effective_resolution(PMONITOR->output, &ow, &oh); - wlr_box_transform(&PFRAME->box, &PFRAME->box, PMONITOR->transform, ow, oh); + PFRAME->box.transform(PMONITOR->transform, ow, oh); PFRAME->shmStride = (PSHMINFO->bpp / 8) * PFRAME->box.width; @@ -301,9 +301,9 @@ void CToplevelExportProtocolManager::onOutputCommit(CMonitor* pMonitor, wlr_outp if (PMONITOR != g_pCompositor->getMonitorFromID(f->pWindow->m_iMonitorID)) continue; - wlr_box geometry = {f->pWindow->m_vRealPosition.vec().x, f->pWindow->m_vRealPosition.vec().y, f->pWindow->m_vRealSize.vec().x, f->pWindow->m_vRealSize.vec().y}; + CBox geometry = {f->pWindow->m_vRealPosition.vec().x, f->pWindow->m_vRealPosition.vec().y, f->pWindow->m_vRealSize.vec().x, f->pWindow->m_vRealSize.vec().y}; - if (!wlr_output_layout_intersects(g_pCompositor->m_sWLROutputLayout, pMonitor->output, &geometry)) + if (!wlr_output_layout_intersects(g_pCompositor->m_sWLROutputLayout, pMonitor->output, geometry.pWlr())) continue; shareFrame(f); @@ -448,7 +448,7 @@ bool CToplevelExportProtocolManager::copyFrameDmabuf(SScreencopyFrame* frame, ti g_pHyprOpenGL->bindWlrOutputFb(); - wlr_box monbox = {0, 0, PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y}; + CBox monbox = {0, 0, PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y}; g_pHyprOpenGL->renderTexture(g_pHyprOpenGL->m_RenderData.pCurrentMonData->primaryFB.m_cTex, &monbox, 1.f); g_pHyprOpenGL->end(); diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index d8637a53..0011e636 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -172,17 +172,14 @@ void CHyprOpenGLImpl::end() { saveBufferForMirror(); // save with original damage region glBindFramebuffer(GL_FRAMEBUFFER, m_iWLROutputFb); - wlr_box monbox = {0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; + CBox monbox = {0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; if (m_RenderData.mouseZoomFactor != 1.f) { const auto ZOOMCENTER = m_RenderData.mouseZoomUseMouse ? (g_pInputManager->getMouseCoordsInternal() - m_RenderData.pMonitor->vecPosition) * m_RenderData.pMonitor->scale : m_RenderData.pMonitor->vecTransformedSize / 2.f; - monbox.x -= ZOOMCENTER.x; - monbox.y -= ZOOMCENTER.y; - scaleBox(&monbox, m_RenderData.mouseZoomFactor); - monbox.x += *PZOOMRIGID ? m_RenderData.pMonitor->vecTransformedSize.x / 2 : ZOOMCENTER.x; - monbox.y += *PZOOMRIGID ? m_RenderData.pMonitor->vecTransformedSize.y / 2 : ZOOMCENTER.y; + + monbox.translate(-ZOOMCENTER).scale(m_RenderData.mouseZoomFactor).translate(*PZOOMRIGID ? m_RenderData.pMonitor->vecTransformedSize / 2.0 : ZOOMCENTER); if (monbox.x > 0) monbox.x = 0; @@ -418,7 +415,7 @@ void CHyprOpenGLImpl::clear(const CColor& color) { } } - scissor((wlr_box*)nullptr); + scissor((CBox*)nullptr); } void CHyprOpenGLImpl::blend(bool enabled) { @@ -431,7 +428,7 @@ void CHyprOpenGLImpl::blend(bool enabled) { m_bBlend = enabled; } -void CHyprOpenGLImpl::scissor(const wlr_box* pBox, bool transform) { +void CHyprOpenGLImpl::scissor(const CBox* pBox, bool transform) { RASSERT(m_RenderData.pMonitor, "Tried to scissor without begin()!"); if (!pBox) { @@ -439,14 +436,14 @@ void CHyprOpenGLImpl::scissor(const wlr_box* pBox, bool transform) { return; } - wlr_box newBox = *pBox; + CBox newBox = *pBox; if (transform) { int w, h; wlr_output_transformed_resolution(m_RenderData.pMonitor->output, &w, &h); const auto TR = wlr_output_transform_invert(m_RenderData.pMonitor->transform); - wlr_box_transform(&newBox, &newBox, TR, w, h); + newBox.transform(TR, w, h); } glScissor(newBox.x, newBox.y, newBox.width, newBox.height); @@ -461,22 +458,22 @@ void CHyprOpenGLImpl::scissor(const pixman_box32* pBox, bool transform) { return; } - wlr_box newBox = {pBox->x1, pBox->y1, pBox->x2 - pBox->x1, pBox->y2 - pBox->y1}; + CBox newBox = {pBox->x1, pBox->y1, pBox->x2 - pBox->x1, pBox->y2 - pBox->y1}; scissor(&newBox, transform); } void CHyprOpenGLImpl::scissor(const int x, const int y, const int w, const int h, bool transform) { - wlr_box box = {x, y, w, h}; + CBox box = {x, y, w, h}; scissor(&box, transform); } -void CHyprOpenGLImpl::renderRect(wlr_box* box, const CColor& col, int round) { +void CHyprOpenGLImpl::renderRect(CBox* box, const CColor& col, int round) { if (!m_RenderData.damage.empty()) renderRectWithDamage(box, col, &m_RenderData.damage, round); } -void CHyprOpenGLImpl::renderRectWithBlur(wlr_box* box, const CColor& col, int round, float blurA) { +void CHyprOpenGLImpl::renderRectWithBlur(CBox* box, const CColor& col, int round, float blurA) { if (m_RenderData.damage.empty()) return; @@ -489,7 +486,7 @@ void CHyprOpenGLImpl::renderRectWithBlur(wlr_box* box, const CColor& col, int ro m_RenderData.pCurrentMonData->primaryFB.bind(); // make a stencil for rounded corners to work with blur - scissor((wlr_box*)nullptr); // allow the entire window and stencil to render + scissor((CBox*)nullptr); // allow the entire window and stencil to render glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT); @@ -506,7 +503,7 @@ void CHyprOpenGLImpl::renderRectWithBlur(wlr_box* box, const CColor& col, int ro glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); scissor(box); - wlr_box MONITORBOX = {0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; + CBox MONITORBOX = {0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; m_bEndFrame = true; // fix transformed const auto SAVEDRENDERMODIF = m_RenderData.renderModif; m_RenderData.renderModif = {}; // fix shit @@ -519,26 +516,24 @@ void CHyprOpenGLImpl::renderRectWithBlur(wlr_box* box, const CColor& col, int ro glDisable(GL_STENCIL_TEST); glStencilMask(-1); glStencilFunc(GL_ALWAYS, 1, 0xFF); - scissor((wlr_box*)nullptr); + scissor((CBox*)nullptr); renderRectWithDamage(box, col, &m_RenderData.damage, round); } -void CHyprOpenGLImpl::renderRectWithDamage(wlr_box* box, const CColor& col, CRegion* damage, int round) { +void CHyprOpenGLImpl::renderRectWithDamage(CBox* box, const CColor& col, CRegion* damage, int round) { RASSERT((box->width > 0 && box->height > 0), "Tried to render rect with width/height < 0!"); RASSERT(m_RenderData.pMonitor, "Tried to render rect without begin()!"); TRACY_GPU_ZONE("RenderRectWithDamage"); - wlr_box newBox = *box; - scaleBox(&newBox, m_RenderData.renderModif.scale); - newBox.x += m_RenderData.renderModif.translate.x; - newBox.y += m_RenderData.renderModif.translate.y; + CBox newBox = *box; + newBox.scale(m_RenderData.renderModif.scale).translate(m_RenderData.renderModif.translate); box = &newBox; float matrix[9]; - wlr_matrix_project_box(matrix, box, wlr_output_transform_invert(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform), 0, + wlr_matrix_project_box(matrix, box->pWlr(), wlr_output_transform_invert(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform), 0, m_RenderData.pMonitor->output->transform_matrix); // TODO: write own, don't use WLR here float glMatrix[9]; @@ -556,9 +551,9 @@ void CHyprOpenGLImpl::renderRectWithDamage(wlr_box* box, const CColor& col, CReg // premultiply the color as well as we don't work with straight alpha glUniform4f(m_RenderData.pCurrentMonData->m_shQUAD.color, col.r * col.a, col.g * col.a, col.b * col.a, col.a); - wlr_box transformedBox; - wlr_box_transform(&transformedBox, box, wlr_output_transform_invert(m_RenderData.pMonitor->transform), m_RenderData.pMonitor->vecTransformedSize.x, - m_RenderData.pMonitor->vecTransformedSize.y); + CBox transformedBox = *box; + transformedBox.transform(wlr_output_transform_invert(m_RenderData.pMonitor->transform), m_RenderData.pMonitor->vecTransformedSize.x, + m_RenderData.pMonitor->vecTransformedSize.y); const auto TOPLEFT = Vector2D(transformedBox.x, transformedBox.y); const auto FULLSIZE = Vector2D(transformedBox.width, transformedBox.height); @@ -592,22 +587,22 @@ void CHyprOpenGLImpl::renderRectWithDamage(wlr_box* box, const CColor& col, CReg glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shQUAD.posAttrib); } -void CHyprOpenGLImpl::renderTexture(wlr_texture* tex, wlr_box* pBox, float alpha, int round, bool allowCustomUV) { +void CHyprOpenGLImpl::renderTexture(wlr_texture* tex, CBox* pBox, float alpha, int round, bool allowCustomUV) { RASSERT(m_RenderData.pMonitor, "Tried to render texture without begin()!"); renderTexture(CTexture(tex), pBox, alpha, round, false, allowCustomUV); } -void CHyprOpenGLImpl::renderTexture(const CTexture& tex, wlr_box* pBox, float alpha, int round, bool discardActive, bool allowCustomUV) { +void CHyprOpenGLImpl::renderTexture(const CTexture& tex, CBox* pBox, float alpha, int round, bool discardActive, bool allowCustomUV) { RASSERT(m_RenderData.pMonitor, "Tried to render texture without begin()!"); renderTextureInternalWithDamage(tex, pBox, alpha, &m_RenderData.damage, round, discardActive, false, allowCustomUV, true); - scissor((wlr_box*)nullptr); + scissor((CBox*)nullptr); } -void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, wlr_box* pBox, float alpha, CRegion* damage, int round, bool discardActive, bool noAA, - bool allowCustomUV, bool allowDim) { +void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, CBox* pBox, float alpha, CRegion* damage, int round, bool discardActive, bool noAA, bool allowCustomUV, + bool allowDim) { RASSERT(m_RenderData.pMonitor, "Tried to render texture without begin()!"); RASSERT((tex.m_iTexID > 0), "Attempted to draw NULL texture!"); @@ -618,17 +613,15 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, wlr_b if (m_RenderData.damage.empty()) return; - wlr_box newBox = *pBox; - scaleBox(&newBox, m_RenderData.renderModif.scale); - newBox.x += m_RenderData.renderModif.translate.x; - newBox.y += m_RenderData.renderModif.translate.y; + CBox newBox = *pBox; + newBox.scale(m_RenderData.renderModif.scale).translate(m_RenderData.renderModif.translate); static auto* const PDIMINACTIVE = &g_pConfigManager->getConfigValuePtr("decoration:dim_inactive")->intValue; // get transform const auto TRANSFORM = wlr_output_transform_invert(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform); float matrix[9]; - wlr_matrix_project_box(matrix, &newBox, TRANSFORM, 0, m_RenderData.pMonitor->output->transform_matrix); + wlr_matrix_project_box(matrix, newBox.pWlr(), TRANSFORM, 0, m_RenderData.pMonitor->output->transform_matrix); float glMatrix[9]; wlr_matrix_multiply(glMatrix, m_RenderData.projection, matrix); @@ -711,9 +704,9 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, wlr_b } } - wlr_box transformedBox; - wlr_box_transform(&transformedBox, &newBox, wlr_output_transform_invert(m_RenderData.pMonitor->transform), m_RenderData.pMonitor->vecTransformedSize.x, - m_RenderData.pMonitor->vecTransformedSize.y); + CBox transformedBox = newBox; + transformedBox.transform(wlr_output_transform_invert(m_RenderData.pMonitor->transform), m_RenderData.pMonitor->vecTransformedSize.x, + m_RenderData.pMonitor->vecTransformedSize.y); const auto TOPLEFT = Vector2D(transformedBox.x, transformedBox.y); const auto FULLSIZE = Vector2D(transformedBox.width, transformedBox.height); @@ -774,7 +767,7 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, wlr_b glBindTexture(tex.m_iTarget, 0); } -void CHyprOpenGLImpl::renderTexturePrimitive(const CTexture& tex, wlr_box* pBox) { +void CHyprOpenGLImpl::renderTexturePrimitive(const CTexture& tex, CBox* pBox) { RASSERT(m_RenderData.pMonitor, "Tried to render texture without begin()!"); RASSERT((tex.m_iTexID > 0), "Attempted to draw NULL texture!"); @@ -783,15 +776,13 @@ void CHyprOpenGLImpl::renderTexturePrimitive(const CTexture& tex, wlr_box* pBox) if (m_RenderData.damage.empty()) return; - wlr_box newBox = *pBox; - scaleBox(&newBox, m_RenderData.renderModif.scale); - newBox.x += m_RenderData.renderModif.translate.x; - newBox.y += m_RenderData.renderModif.translate.y; + CBox newBox = *pBox; + newBox.scale(m_RenderData.renderModif.scale).translate(m_RenderData.renderModif.translate); // get transform const auto TRANSFORM = wlr_output_transform_invert(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform); float matrix[9]; - wlr_matrix_project_box(matrix, &newBox, TRANSFORM, 0, m_RenderData.pMonitor->output->transform_matrix); + wlr_matrix_project_box(matrix, newBox.pWlr(), TRANSFORM, 0, m_RenderData.pMonitor->output->transform_matrix); float glMatrix[9]; wlr_matrix_multiply(glMatrix, m_RenderData.projection, matrix); @@ -822,7 +813,7 @@ void CHyprOpenGLImpl::renderTexturePrimitive(const CTexture& tex, wlr_box* pBox) glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } - scissor((wlr_box*)nullptr); + scissor((CBox*)nullptr); glDisableVertexAttribArray(shader->posAttrib); glDisableVertexAttribArray(shader->texAttrib); @@ -845,8 +836,8 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, CRegion* o // get transforms for the full monitor const auto TRANSFORM = wlr_output_transform_invert(m_RenderData.pMonitor->transform); float matrix[9]; - wlr_box MONITORBOX = {0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; - wlr_matrix_project_box(matrix, &MONITORBOX, TRANSFORM, 0, m_RenderData.pMonitor->output->transform_matrix); + CBox MONITORBOX = {0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; + wlr_matrix_project_box(matrix, MONITORBOX.pWlr(), TRANSFORM, 0, m_RenderData.pMonitor->output->transform_matrix); float glMatrix[9]; wlr_matrix_multiply(glMatrix, m_RenderData.projection, matrix); @@ -1138,7 +1129,7 @@ void CHyprOpenGLImpl::preBlurForCurrentMonitor() { // make the fake dmg CRegion fakeDamage{0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; - wlr_box wholeMonitor = {0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; + CBox wholeMonitor = {0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; const auto POUTFB = blurMainFramebufferWithDamage(1, &fakeDamage); // render onto blurFB @@ -1197,7 +1188,7 @@ bool CHyprOpenGLImpl::shouldUseNewBlurOptimizations(SLayerSurface* pLayer, CWind return false; } -void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, wlr_box* pBox, float a, wlr_surface* pSurface, int round, bool blockBlurOptimization, float blurA) { +void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, CBox* pBox, float a, wlr_surface* pSurface, int round, bool blockBlurOptimization, float blurA) { RASSERT(m_RenderData.pMonitor, "Tried to render texture with blur without begin()!"); static auto* const PBLURENABLED = &g_pConfigManager->getConfigValuePtr("decoration:blur:enabled")->intValue; @@ -1251,7 +1242,7 @@ void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, wlr_box* pBox, m_RenderData.pCurrentMonData->primaryFB.bind(); // make a stencil for rounded corners to work with blur - scissor((wlr_box*)nullptr); // allow the entire window and stencil to render + scissor((CBox*)nullptr); // allow the entire window and stencil to render glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT); @@ -1271,7 +1262,7 @@ void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, wlr_box* pBox, glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); // stencil done. Render everything. - wlr_box MONITORBOX = {0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; + CBox MONITORBOX = {0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; // render our great blurred FB static auto* const PBLURIGNOREOPACITY = &g_pConfigManager->getConfigValuePtr("decoration:blur:ignore_opacity")->intValue; m_bEndFrame = true; // fix transformed @@ -1291,17 +1282,17 @@ void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, wlr_box* pBox, glStencilMask(-1); glStencilFunc(GL_ALWAYS, 1, 0xFF); - scissor((wlr_box*)nullptr); + scissor((CBox*)nullptr); } -void pushVert2D(float x, float y, float* arr, int& counter, wlr_box* box) { +void pushVert2D(float x, float y, float* arr, int& counter, CBox* box) { // 0-1 space god damnit arr[counter * 2 + 0] = x / box->width; arr[counter * 2 + 1] = y / box->height; counter++; } -void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CGradientValueData& grad, int round, int borderSize, float a, int outerRound) { +void CHyprOpenGLImpl::renderBorder(CBox* box, const CGradientValueData& grad, int round, int borderSize, float a, int outerRound) { RASSERT((box->width > 0 && box->height > 0), "Tried to render rect with width/height < 0!"); RASSERT(m_RenderData.pMonitor, "Tried to render rect without begin()!"); @@ -1310,10 +1301,8 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CGradientValueData& grad, if (m_RenderData.damage.empty() || (m_pCurrentWindow && m_pCurrentWindow->m_sAdditionalConfigData.forceNoBorder)) return; - wlr_box newBox = *box; - scaleBox(&newBox, m_RenderData.renderModif.scale); - newBox.x += m_RenderData.renderModif.translate.x; - newBox.y += m_RenderData.renderModif.translate.y; + CBox newBox = *box; + newBox.scale(m_RenderData.renderModif.scale).translate(m_RenderData.renderModif.translate); box = &newBox; @@ -1331,7 +1320,7 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CGradientValueData& grad, round += round == 0 ? 0 : scaledBorderSize; float matrix[9]; - wlr_matrix_project_box(matrix, box, wlr_output_transform_invert(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform), 0, + wlr_matrix_project_box(matrix, box->pWlr(), wlr_output_transform_invert(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform), 0, m_RenderData.pMonitor->output->transform_matrix); // TODO: write own, don't use WLR here float glMatrix[9]; @@ -1356,9 +1345,9 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CGradientValueData& grad, glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.angle, (int)(grad.m_fAngle / (PI / 180.0)) % 360 * (PI / 180.0)); glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.alpha, a); - wlr_box transformedBox; - wlr_box_transform(&transformedBox, box, wlr_output_transform_invert(m_RenderData.pMonitor->transform), m_RenderData.pMonitor->vecTransformedSize.x, - m_RenderData.pMonitor->vecTransformedSize.y); + CBox transformedBox = *box; + transformedBox.transform(wlr_output_transform_invert(m_RenderData.pMonitor->transform), m_RenderData.pMonitor->vecTransformedSize.x, + m_RenderData.pMonitor->vecTransformedSize.y); const auto TOPLEFT = Vector2D(transformedBox.x, transformedBox.y); const auto FULLSIZE = Vector2D(transformedBox.width, transformedBox.height); @@ -1587,7 +1576,7 @@ void CHyprOpenGLImpl::renderSnapshot(CWindow** pWindow) { const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); - wlr_box windowBox; + CBox windowBox; // some mafs to figure out the correct box // the originalClosedPos is relative to the monitor's pos Vector2D scaleXY = Vector2D((PMONITOR->scale * PWINDOW->m_vRealSize.vec().x / (PWINDOW->m_vOriginalClosedSize.x * PMONITOR->scale)), @@ -1601,7 +1590,7 @@ void CHyprOpenGLImpl::renderSnapshot(CWindow** pWindow) { CRegion fakeDamage{0, 0, PMONITOR->vecTransformedSize.x, PMONITOR->vecTransformedSize.y}; if (*PDIMAROUND && (*pWindow)->m_sAdditionalConfigData.dimAround) { - wlr_box monbox = {0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.y}; + CBox monbox = {0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.y}; g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, *PDIMAROUND * PWINDOW->m_fAlpha.fl())); g_pHyprRenderer->damageMonitor(PMONITOR); } @@ -1629,7 +1618,7 @@ void CHyprOpenGLImpl::renderSnapshot(SLayerSurface** pLayer) { const auto PMONITOR = g_pCompositor->getMonitorFromID(PLAYER->monitorID); - wlr_box monbox = {0, 0, PMONITOR->vecTransformedSize.x, PMONITOR->vecTransformedSize.y}; + CBox monbox = {0, 0, PMONITOR->vecTransformedSize.x, PMONITOR->vecTransformedSize.y}; CRegion fakeDamage{0, 0, PMONITOR->vecTransformedSize.x, PMONITOR->vecTransformedSize.y}; @@ -1640,7 +1629,7 @@ void CHyprOpenGLImpl::renderSnapshot(SLayerSurface** pLayer) { m_bEndFrame = false; } -void CHyprOpenGLImpl::renderRoundedShadow(wlr_box* box, int round, int range, float a, CFramebuffer* matte) { +void CHyprOpenGLImpl::renderRoundedShadow(CBox* box, int round, int range, float a, CFramebuffer* matte) { RASSERT(m_RenderData.pMonitor, "Tried to render shadow without begin()!"); RASSERT((box->width > 0 && box->height > 0), "Tried to render shadow with width/height < 0!"); RASSERT(m_pCurrentWindow, "Tried to render shadow without a window!"); @@ -1650,10 +1639,8 @@ void CHyprOpenGLImpl::renderRoundedShadow(wlr_box* box, int round, int range, fl TRACY_GPU_ZONE("RenderShadow"); - wlr_box newBox = *box; - scaleBox(&newBox, m_RenderData.renderModif.scale); - newBox.x += m_RenderData.renderModif.translate.x; - newBox.y += m_RenderData.renderModif.translate.y; + CBox newBox = *box; + newBox.scale(m_RenderData.renderModif.scale).translate(m_RenderData.renderModif.translate); box = &newBox; @@ -1665,7 +1652,7 @@ void CHyprOpenGLImpl::renderRoundedShadow(wlr_box* box, int round, int range, fl const auto col = m_pCurrentWindow->m_cRealShadowColor.col(); float matrix[9]; - wlr_matrix_project_box(matrix, box, wlr_output_transform_invert(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform), 0, + wlr_matrix_project_box(matrix, box->pWlr(), wlr_output_transform_invert(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform), 0, m_RenderData.pMonitor->output->transform_matrix); // TODO: write own, don't use WLR here float glMatrix[9]; @@ -1752,7 +1739,7 @@ void CHyprOpenGLImpl::saveBufferForMirror() { m_RenderData.pCurrentMonData->monitorMirrorFB.bind(); - wlr_box monbox = {0, 0, m_RenderData.pMonitor->vecPixelSize.x, m_RenderData.pMonitor->vecPixelSize.y}; + CBox monbox = {0, 0, m_RenderData.pMonitor->vecPixelSize.x, m_RenderData.pMonitor->vecPixelSize.y}; blend(false); @@ -1764,7 +1751,7 @@ void CHyprOpenGLImpl::saveBufferForMirror() { } void CHyprOpenGLImpl::renderMirrored() { - wlr_box monbox = {0, 0, m_RenderData.pMonitor->vecPixelSize.x, m_RenderData.pMonitor->vecPixelSize.y}; + CBox monbox = {0, 0, m_RenderData.pMonitor->vecPixelSize.x, m_RenderData.pMonitor->vecPixelSize.y}; const auto PFB = &m_mMonitorRenderResources[m_RenderData.pMonitor->pMirrorOf].monitorMirrorFB; @@ -1867,7 +1854,7 @@ void CHyprOpenGLImpl::createBGTextureForMonitor(CMonitor* pMonitor) { origin.x = (m_RenderData.pMonitor->vecTransformedSize.x - PTEX->m_vSize.x * scale) / 2.0; } - wlr_box box = {origin.x, origin.y, PTEX->m_vSize.x * scale, PTEX->m_vSize.y * scale}; + CBox box = {origin.x, origin.y, PTEX->m_vSize.x * scale, PTEX->m_vSize.y * scale}; m_mMonitorRenderResources[pMonitor].backgroundTexBox = box; @@ -1954,7 +1941,7 @@ void CHyprOpenGLImpl::bindOffMain() { } void CHyprOpenGLImpl::renderOffToMain(CFramebuffer* off) { - wlr_box monbox = {0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; + CBox monbox = {0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; renderTexturePrimitive(off->m_cTex, &monbox); } diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index ab3eb7cf..93dccbf4 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -52,7 +52,7 @@ struct SMonitorRenderData { bool blurFBDirty = true; bool blurFBShouldRender = false; - wlr_box backgroundTexBox; + CBox backgroundTexBox; // Shaders bool m_bShadersInitialized = false; @@ -89,7 +89,7 @@ struct SCurrentRenderData { Vector2D primarySurfaceUVTopLeft = Vector2D(-1, -1); Vector2D primarySurfaceUVBottomRight = Vector2D(-1, -1); - wlr_box clipBox = {}; + CBox clipBox = {}; uint32_t discardMode = DISCARD_OPAQUE; float discardOpacity = 0.f; @@ -105,14 +105,14 @@ class CHyprOpenGLImpl { void end(); void bindWlrOutputFb(); - void renderRect(wlr_box*, const CColor&, int round = 0); - void renderRectWithBlur(wlr_box*, const CColor&, int round = 0, float blurA = 1.f); - void renderRectWithDamage(wlr_box*, const CColor&, CRegion* damage, int round = 0); - void renderTexture(wlr_texture*, wlr_box*, float a, int round = 0, bool allowCustomUV = false); - void renderTexture(const CTexture&, wlr_box*, float a, int round = 0, bool discardActive = false, bool allowCustomUV = false); - void renderTextureWithBlur(const CTexture&, wlr_box*, float a, wlr_surface* pSurface, int round = 0, bool blockBlurOptimization = false, float blurA = 1.f); - void renderRoundedShadow(wlr_box*, int round, int range, float a = 1.0, CFramebuffer* matte = nullptr); - void renderBorder(wlr_box*, const CGradientValueData&, int round, int borderSize, float a = 1.0, int outerRound = -1 /* use round */); + void renderRect(CBox*, const CColor&, int round = 0); + void renderRectWithBlur(CBox*, const CColor&, int round = 0, float blurA = 1.f); + void renderRectWithDamage(CBox*, const CColor&, CRegion* damage, int round = 0); + void renderTexture(wlr_texture*, CBox*, float a, int round = 0, bool allowCustomUV = false); + void renderTexture(const CTexture&, CBox*, float a, int round = 0, bool discardActive = false, bool allowCustomUV = false); + void renderTextureWithBlur(const CTexture&, CBox*, float a, wlr_surface* pSurface, int round = 0, bool blockBlurOptimization = false, float blurA = 1.f); + void renderRoundedShadow(CBox*, int round, int range, float a = 1.0, CFramebuffer* matte = nullptr); + void renderBorder(CBox*, const CGradientValueData&, int round, int borderSize, float a = 1.0, int outerRound = -1 /* use round */); void saveMatrix(); void setMatrixScaleTranslate(const Vector2D& translate, const float& scale); @@ -128,7 +128,7 @@ class CHyprOpenGLImpl { void clear(const CColor&); void clearWithTex(); - void scissor(const wlr_box*, bool transform = true); + void scissor(const CBox*, bool transform = true); void scissor(const pixman_box32*, bool transform = true); void scissor(const int x, const int y, const int w, const int h, bool transform = true); @@ -187,9 +187,9 @@ class CHyprOpenGLImpl { // returns the out FB, can be either Mirror or MirrorSwap CFramebuffer* blurMainFramebufferWithDamage(float a, CRegion* damage); - void renderTextureInternalWithDamage(const CTexture&, wlr_box* pBox, float a, CRegion* damage, int round = 0, bool discardOpaque = false, bool noAA = false, + void renderTextureInternalWithDamage(const CTexture&, CBox* pBox, float a, CRegion* damage, int round = 0, bool discardOpaque = false, bool noAA = false, bool allowCustomUV = false, bool allowDim = false); - void renderTexturePrimitive(const CTexture& tex, wlr_box* pBox); + void renderTexturePrimitive(const CTexture& tex, CBox* pBox); void renderSplash(cairo_t* const, cairo_surface_t* const, double); void preBlurForCurrentMonitor(); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 82175b99..a43d6a2d 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -22,7 +22,7 @@ void renderSurface(struct wlr_surface* surface, int x, int y, void* data) { double outputX = 0, outputY = 0; wlr_output_layout_output_coords(g_pCompositor->m_sWLROutputLayout, RDATA->pMonitor->output, &outputX, &outputY); - wlr_box windowBox; + CBox windowBox; if (RDATA->surface && surface == RDATA->surface) { windowBox = {(int)outputX + RDATA->x + x, (int)outputY + RDATA->y + y, RDATA->w, RDATA->h}; @@ -67,7 +67,8 @@ void renderSurface(struct wlr_surface* surface, int x, int y, void* data) { g_pHyprRenderer->calculateUVForSurface(RDATA->pWindow, surface, RDATA->squishOversized); - scaleBox(&windowBox, RDATA->pMonitor->scale); + windowBox.scale(RDATA->pMonitor->scale); + windowBox.round(); float rounding = RDATA->rounding; @@ -110,9 +111,9 @@ void renderSurface(struct wlr_surface* surface, int x, int y, void* data) { } bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor, CWorkspace* pWorkspace) { - wlr_box geometry = pWindow->getFullWindowBoundingBox(); + CBox geometry = pWindow->getFullWindowBoundingBox(); - if (!wlr_output_layout_intersects(g_pCompositor->m_sWLROutputLayout, pMonitor->output, &geometry)) + if (!wlr_output_layout_intersects(g_pCompositor->m_sWLROutputLayout, pMonitor->output, geometry.pWlr())) return false; if (pWindow->m_iWorkspaceID == -1) @@ -343,7 +344,14 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* static auto* const PBORDERSIZE = &g_pConfigManager->getConfigValuePtr("general:border_size")->intValue; static auto* const PBLUR = &g_pConfigManager->getConfigValuePtr("decoration:blur:enabled")->intValue; - SRenderData renderdata = {pMonitor, time, REALPOS.x, REALPOS.y}; + SRenderData renderdata = {pMonitor, time}; + CBox textureBox = {REALPOS.x, REALPOS.y, std::max(pWindow->m_vRealSize.vec().x, 5.0), std::max(pWindow->m_vRealSize.vec().y, 5.0)}; + + renderdata.x = textureBox.x; + renderdata.y = textureBox.y; + renderdata.w = textureBox.w; + renderdata.h = textureBox.h; + if (ignorePosition) { renderdata.x = pMonitor->vecPosition.x; renderdata.y = pMonitor->vecPosition.y; @@ -353,8 +361,6 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* decorate = false; renderdata.surface = pWindow->m_pWLSurface.wlr(); - renderdata.w = std::max(pWindow->m_vRealSize.vec().x, 5.0); // clamp the size to min 5, - renderdata.h = std::max(pWindow->m_vRealSize.vec().y, 5.0); // otherwise we'll have issues later with invalid boxes renderdata.dontRound = (pWindow->m_bIsFullscreen && PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL) || (!pWindow->m_sSpecialRenderData.rounding); renderdata.fadeAlpha = pWindow->m_fAlpha.fl() * (pWindow->m_bPinned ? 1.f : PWORKSPACE->m_fAlpha.fl()); renderdata.alpha = pWindow->m_fActiveInactiveAlpha.fl(); @@ -377,7 +383,7 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* EMIT_HOOK_EVENT("render", RENDER_PRE_WINDOW); if (*PDIMAROUND && pWindow->m_sAdditionalConfigData.dimAround && !m_bRenderingSnapshot && mode != RENDER_PASS_POPUP) { - wlr_box monbox = {0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecTransformedSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecTransformedSize.y}; + CBox monbox = {0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecTransformedSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecTransformedSize.y}; g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, *PDIMAROUND * renderdata.alpha * renderdata.fadeAlpha)); } @@ -446,8 +452,8 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* g_pHyprOpenGL->m_RenderData.useNearestNeighbor = true; if (pWindow->m_pWLSurface.small() && !pWindow->m_pWLSurface.m_bFillIgnoreSmall && renderdata.blur && *PBLUR) { - wlr_box wb = {renderdata.x - pMonitor->vecPosition.x, renderdata.y - pMonitor->vecPosition.y, renderdata.w, renderdata.h}; - scaleBox(&wb, pMonitor->scale); + CBox wb = {renderdata.x - pMonitor->vecPosition.x, renderdata.y - pMonitor->vecPosition.y, renderdata.w, renderdata.h}; + wb.scale(pMonitor->scale).round(); g_pHyprOpenGL->renderRectWithBlur(&wb, CColor(0, 0, 0, 0), renderdata.dontRound ? 0 : renderdata.rounding - 1, renderdata.fadeAlpha); renderdata.blur = false; } @@ -466,9 +472,9 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* grad.m_fAngle = normalizeAngleRad(grad.m_fAngle); } - wlr_box windowBox = {renderdata.x - pMonitor->vecPosition.x, renderdata.y - pMonitor->vecPosition.y, renderdata.w, renderdata.h}; + CBox windowBox = {renderdata.x - pMonitor->vecPosition.x, renderdata.y - pMonitor->vecPosition.y, renderdata.w, renderdata.h}; - scaleBox(&windowBox, pMonitor->scale); + windowBox.scale(pMonitor->scale).round(); int borderSize = pWindow->m_sSpecialRenderData.borderSize.toUnderlying() == -1 ? *PBORDERSIZE : pWindow->m_sSpecialRenderData.borderSize.toUnderlying(); if (pWindow->m_sAdditionalConfigData.borderSize.toUnderlying() != -1) @@ -503,8 +509,9 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* if (mode == RENDER_PASS_ALL || mode == RENDER_PASS_POPUP) { if (!pWindow->m_bIsX11) { - wlr_box geom; - wlr_xdg_surface_get_geometry(pWindow->m_uSurface.xdg, &geom); + CBox geom; + wlr_xdg_surface_get_geometry(pWindow->m_uSurface.xdg, geom.pWlr()); + geom.applyFromWlr(); renderdata.x -= geom.x; renderdata.y -= geom.y; @@ -604,7 +611,7 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* if (!g_pCompositor->m_sSeat.exclusiveClient && g_pSessionLockManager->isSessionLocked()) { // locked with no exclusive, draw only red - wlr_box boxe = {0, 0, INT16_MAX, INT16_MAX}; + CBox boxe = {0, 0, INT16_MAX, INT16_MAX}; g_pHyprOpenGL->renderRect(&boxe, CColor(1.0, 0.2, 0.2, 1.0)); return; } @@ -654,12 +661,12 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* const bool ANIMOUT = !pMonitor->specialWorkspaceID; if (*PDIMSPECIAL != 0.f) { - wlr_box monbox = {translate.x, translate.y, pMonitor->vecTransformedSize.x * scale, pMonitor->vecTransformedSize.y * scale}; + CBox monbox = {translate.x, translate.y, pMonitor->vecTransformedSize.x * scale, pMonitor->vecTransformedSize.y * scale}; g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, *PDIMSPECIAL * (ANIMOUT ? (1.0 - SPECIALANIMPROGRS) : SPECIALANIMPROGRS))); } if (*PBLURSPECIAL && *PBLUR) { - wlr_box monbox = {translate.x, translate.y, pMonitor->vecTransformedSize.x * scale, pMonitor->vecTransformedSize.y * scale}; + CBox monbox = {translate.x, translate.y, pMonitor->vecTransformedSize.x * scale, pMonitor->vecTransformedSize.y * scale}; g_pHyprOpenGL->renderRectWithBlur(&monbox, CColor(0, 0, 0, 0), 0, (ANIMOUT ? (1.0 - SPECIALANIMPROGRS) : SPECIALANIMPROGRS)); } @@ -711,7 +718,7 @@ void CHyprRenderer::renderLockscreen(CMonitor* pMonitor, timespec* now) { if (!PSLS) { // locked with no surface, fill with red - wlr_box boxe = {0, 0, INT16_MAX, INT16_MAX}; + CBox boxe = {0, 0, INT16_MAX, INT16_MAX}; g_pHyprOpenGL->renderRect(&boxe, CColor(1.0, 0.2, 0.2, 1.0)); } else { renderSessionLockSurface(PSLS, pMonitor, now); @@ -753,8 +760,9 @@ void CHyprRenderer::calculateUVForSurface(CWindow* pWindow, wlr_surface* pSurfac if (!main || !pWindow) return; - wlr_box geom; - wlr_xdg_surface_get_geometry(pWindow->m_uSurface.xdg, &geom); + CBox geom; + wlr_xdg_surface_get_geometry(pWindow->m_uSurface.xdg, geom.pWlr()); + geom.applyFromWlr(); // ignore X and Y, adjust uv if (geom.x != 0 || geom.y != 0 || geom.width > pWindow->m_vRealSize.vec().x || geom.height > pWindow->m_vRealSize.vec().y) { @@ -1073,7 +1081,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { } g_pHyprOpenGL->blend(true); - wlr_box renderBox = {0, 0, (int)pMonitor->vecPixelSize.x, (int)pMonitor->vecPixelSize.y}; + CBox renderBox = {0, 0, (int)pMonitor->vecPixelSize.x, (int)pMonitor->vecPixelSize.y}; renderWorkspace(pMonitor, g_pCompositor->getWorkspaceByID(pMonitor->activeWorkspace), &now, renderBox); renderLockscreen(pMonitor, &now); @@ -1091,7 +1099,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { } if (*PDAMAGEBLINK && damageBlinkCleanup == 0) { - wlr_box monrect = {0, 0, pMonitor->vecTransformedSize.x, pMonitor->vecTransformedSize.y}; + CBox monrect = {0, 0, pMonitor->vecTransformedSize.x, pMonitor->vecTransformedSize.y}; g_pHyprOpenGL->renderRect(&monrect, CColor(1.0, 0.0, 1.0, 100.0 / 255.0), 0); damageBlinkCleanup = 1; } else if (*PDAMAGEBLINK) { @@ -1193,7 +1201,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { } } -void CHyprRenderer::renderWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const wlr_box& geometry) { +void CHyprRenderer::renderWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const CBox& geometry) { Vector2D translate = {geometry.x, geometry.y}; float scale = (float)geometry.width / pMonitor->vecPixelSize.x; @@ -1350,8 +1358,8 @@ void apply_exclusive(struct wlr_box* usable_area, uint32_t anchor, int32_t exclu } } -void CHyprRenderer::arrangeLayerArray(CMonitor* pMonitor, const std::vector<std::unique_ptr<SLayerSurface>>& layerSurfaces, bool exclusiveZone, wlr_box* usableArea) { - wlr_box full_area = {pMonitor->vecPosition.x, pMonitor->vecPosition.y, pMonitor->vecSize.x, pMonitor->vecSize.y}; +void CHyprRenderer::arrangeLayerArray(CMonitor* pMonitor, const std::vector<std::unique_ptr<SLayerSurface>>& layerSurfaces, bool exclusiveZone, CBox* usableArea) { + CBox full_area = {pMonitor->vecPosition.x, pMonitor->vecPosition.y, pMonitor->vecSize.x, pMonitor->vecSize.y}; for (auto& ls : layerSurfaces) { if (ls->fadingOut || ls->readyToDelete || !ls->layerSurface || ls->noProcess) @@ -1362,7 +1370,7 @@ void CHyprRenderer::arrangeLayerArray(CMonitor* pMonitor, const std::vector<std: if (exclusiveZone != (PSTATE->exclusive_zone > 0)) continue; - wlr_box bounds; + CBox bounds; if (PSTATE->exclusive_zone == -1) bounds = full_area; else @@ -1370,7 +1378,7 @@ void CHyprRenderer::arrangeLayerArray(CMonitor* pMonitor, const std::vector<std: const Vector2D OLDSIZE = {ls->geometry.width, ls->geometry.height}; - wlr_box box = {.width = PSTATE->desired_width, .height = PSTATE->desired_height}; + CBox box = {0, 0, PSTATE->desired_width, PSTATE->desired_height}; // Horizontal axis const uint32_t both_horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; if (box.width == 0) { @@ -1425,7 +1433,9 @@ void CHyprRenderer::arrangeLayerArray(CMonitor* pMonitor, const std::vector<std: // Apply ls->geometry = box; - apply_exclusive(usableArea, PSTATE->anchor, PSTATE->exclusive_zone, PSTATE->margin.top, PSTATE->margin.right, PSTATE->margin.bottom, PSTATE->margin.left); + apply_exclusive(usableArea->pWlr(), PSTATE->anchor, PSTATE->exclusive_zone, PSTATE->margin.top, PSTATE->margin.right, PSTATE->margin.bottom, PSTATE->margin.left); + + usableArea->applyFromWlr(); if (Vector2D{box.width, box.height} != OLDSIZE) wlr_layer_surface_v1_configure(ls->layerSurface, box.width, box.height); @@ -1445,7 +1455,7 @@ void CHyprRenderer::arrangeLayersForMonitor(const int& monitor) { PMONITOR->vecReservedBottomRight = Vector2D(); PMONITOR->vecReservedTopLeft = Vector2D(); - wlr_box usableArea = {PMONITOR->vecPosition.x, PMONITOR->vecPosition.y, PMONITOR->vecSize.x, PMONITOR->vecSize.y}; + CBox usableArea = {PMONITOR->vecPosition.x, PMONITOR->vecPosition.y, PMONITOR->vecSize.x, PMONITOR->vecSize.y}; for (auto& la : PMONITOR->m_aLayerSurfaceLayers) arrangeLayerArray(PMONITOR, la, true, &usableArea); @@ -1529,10 +1539,10 @@ void CHyprRenderer::damageWindow(CWindow* pWindow) { if (g_pCompositor->m_bUnsafeState) return; - wlr_box damageBox = pWindow->getFullWindowBoundingBox(); + CBox damageBox = pWindow->getFullWindowBoundingBox(); for (auto& m : g_pCompositor->m_vMonitors) { - wlr_box fixedDamageBox = {damageBox.x - m->vecPosition.x, damageBox.y - m->vecPosition.y, damageBox.width, damageBox.height}; - scaleBox(&fixedDamageBox, m->scale); + CBox fixedDamageBox = {damageBox.x - m->vecPosition.x, damageBox.y - m->vecPosition.y, damageBox.width, damageBox.height}; + fixedDamageBox.scale(m->scale); m->addDamage(&fixedDamageBox); } @@ -1549,7 +1559,7 @@ void CHyprRenderer::damageMonitor(CMonitor* pMonitor) { if (g_pCompositor->m_bUnsafeState || pMonitor->isMirror()) return; - wlr_box damageBox = {0, 0, INT16_MAX, INT16_MAX}; + CBox damageBox = {0, 0, INT16_MAX, INT16_MAX}; pMonitor->addDamage(&damageBox); static auto* const PLOGDAMAGE = &g_pConfigManager->getConfigValuePtr("debug:log_damage")->intValue; @@ -1558,7 +1568,7 @@ void CHyprRenderer::damageMonitor(CMonitor* pMonitor) { Debug::log(LOG, "Damage: Monitor {}", pMonitor->szName); } -void CHyprRenderer::damageBox(wlr_box* pBox) { +void CHyprRenderer::damageBox(CBox* pBox) { if (g_pCompositor->m_bUnsafeState) return; @@ -1566,8 +1576,8 @@ void CHyprRenderer::damageBox(wlr_box* pBox) { if (m->isMirror()) continue; // don't damage mirrors traditionally - wlr_box damageBox = {pBox->x - m->vecPosition.x, pBox->y - m->vecPosition.y, pBox->width, pBox->height}; - scaleBox(&damageBox, m->scale); + CBox damageBox = {pBox->x - m->vecPosition.x, pBox->y - m->vecPosition.y, pBox->width, pBox->height}; + damageBox.scale(m->scale); m->addDamage(&damageBox); } @@ -1578,7 +1588,7 @@ void CHyprRenderer::damageBox(wlr_box* pBox) { } void CHyprRenderer::damageBox(const int& x, const int& y, const int& w, const int& h) { - wlr_box box = {x, y, w, h}; + CBox box = {x, y, w, h}; damageBox(&box); } @@ -1611,8 +1621,8 @@ void CHyprRenderer::renderDragIcon(CMonitor* pMonitor, timespec* time) { wlr_surface_for_each_surface(g_pInputManager->m_sDrag.dragIcon->surface, renderSurface, &renderdata); - wlr_box box = {g_pInputManager->m_sDrag.pos.x - 2, g_pInputManager->m_sDrag.pos.y - 2, g_pInputManager->m_sDrag.dragIcon->surface->current.width + 4, - g_pInputManager->m_sDrag.dragIcon->surface->current.height + 4}; + CBox box = {g_pInputManager->m_sDrag.pos.x - 2, g_pInputManager->m_sDrag.pos.y - 2, g_pInputManager->m_sDrag.dragIcon->surface->current.width + 4, + g_pInputManager->m_sDrag.dragIcon->surface->current.height + 4}; g_pHyprRenderer->damageBox(&box); } @@ -1934,9 +1944,8 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR pMonitor->vecTransformedSize = Vector2D(x, y); if (pMonitor->createdByUser) { - wlr_box transformedBox = {0, 0, (int)pMonitor->vecTransformedSize.x, (int)pMonitor->vecTransformedSize.y}; - wlr_box_transform(&transformedBox, &transformedBox, wlr_output_transform_invert(pMonitor->output->transform), (int)pMonitor->vecTransformedSize.x, - (int)pMonitor->vecTransformedSize.y); + CBox transformedBox = {0, 0, pMonitor->vecTransformedSize.x, pMonitor->vecTransformedSize.y}; + transformedBox.transform(wlr_output_transform_invert(pMonitor->output->transform), pMonitor->vecTransformedSize.x, pMonitor->vecTransformedSize.y); pMonitor->vecPixelSize = Vector2D(transformedBox.width, transformedBox.height); } @@ -2092,9 +2101,9 @@ void CHyprRenderer::setOccludedForBackLayers(CRegion& region, CWorkspace* pWorks const Vector2D POS = w->m_vRealPosition.vec() + Vector2D{ROUNDING, ROUNDING} - PMONITOR->vecPosition + (w->m_bPinned ? Vector2D{} : pWorkspace->m_vRenderOffset.vec()); const Vector2D SIZE = w->m_vRealSize.vec() - Vector2D{ROUNDING * 2, ROUNDING * 2}; - wlr_box box = {POS.x, POS.y, SIZE.x, SIZE.y}; + CBox box = {POS.x, POS.y, SIZE.x, SIZE.y}; - scaleBox(&box, PMONITOR->scale); + box.scale(PMONITOR->scale); rg.add(&box); } diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index 0281d33f..f28600b4 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -40,7 +40,7 @@ class CHyprRenderer { void arrangeLayersForMonitor(const int&); void damageSurface(wlr_surface*, double, double, double scale = 1.0); void damageWindow(CWindow*); - void damageBox(wlr_box*); + void damageBox(CBox*); void damageBox(const int& x, const int& y, const int& w, const int& h); void damageRegion(const CRegion&); void damageMonitor(CMonitor*); @@ -89,7 +89,7 @@ class CHyprRenderer { } m_sLastCursorData; private: - void arrangeLayerArray(CMonitor*, const std::vector<std::unique_ptr<SLayerSurface>>&, bool, wlr_box*); + void arrangeLayerArray(CMonitor*, const std::vector<std::unique_ptr<SLayerSurface>>&, bool, CBox*); void renderWorkspaceWindowsFullscreen(CMonitor*, CWorkspace*, timespec*); // renders workspace windows (fullscreen) (tiled, floating, pinned, but no special) void renderWorkspaceWindows(CMonitor*, CWorkspace*, timespec*); // renders workspace windows (no fullscreen) (tiled, floating, pinned, but no special) void renderWindow(CWindow*, CMonitor*, timespec*, bool, eRenderPassMode, bool ignorePosition = false, bool ignoreAllGeometry = false); @@ -97,7 +97,7 @@ class CHyprRenderer { void renderSessionLockSurface(SSessionLockSurface*, CMonitor*, timespec*); void renderDragIcon(CMonitor*, timespec*); void renderIMEPopup(SIMEPopup*, CMonitor*, timespec*); - void renderWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const wlr_box& geometry); + void renderWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const CBox& geometry); void renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const Vector2D& translate = {0, 0}, const float& scale = 1.f); bool m_bHasARenderedCursor = true; diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index c2edb9ce..422cd9b3 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -29,8 +29,8 @@ void CHyprDropShadowDecoration::damageEntire() { if (*PSHADOWS != 1) return; // disabled - wlr_box dm = {m_vLastWindowPos.x - m_seExtents.topLeft.x, m_vLastWindowPos.y - m_seExtents.topLeft.y, m_vLastWindowSize.x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x, - m_vLastWindowSize.y + m_seExtents.topLeft.y + m_seExtents.bottomRight.y}; + CBox dm = {m_vLastWindowPos.x - m_seExtents.topLeft.x, m_vLastWindowPos.y - m_seExtents.topLeft.y, m_vLastWindowSize.x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x, + m_vLastWindowSize.y + m_seExtents.topLeft.y + m_seExtents.bottomRight.y}; g_pHyprRenderer->damageBox(&dm); } @@ -68,9 +68,8 @@ void CHyprDropShadowDecoration::updateWindow(CWindow* pWindow) { maxExtents.bottomRight.y = EXTENTS.bottomRight.y; } - m_bLastWindowBox = {(int)(m_vLastWindowPos.x - maxExtents.topLeft.x - BORDER), (int)(m_vLastWindowPos.y - maxExtents.topLeft.y - BORDER), - (int)(m_vLastWindowSize.x + maxExtents.topLeft.x + maxExtents.bottomRight.x + 2 * BORDER), - (int)(m_vLastWindowSize.y + maxExtents.topLeft.y + maxExtents.bottomRight.y + 2 * BORDER)}; + m_bLastWindowBox = {m_vLastWindowPos.x, m_vLastWindowPos.y, m_vLastWindowSize.x, m_vLastWindowSize.y}; + m_eLastExtents = {{maxExtents.topLeft + Vector2D{BORDER, BORDER}}, {maxExtents.bottomRight + Vector2D{BORDER, BORDER}}}; } } @@ -103,55 +102,40 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D const auto ROUNDING = m_pWindow->rounding() + m_pWindow->getRealBorderSize(); // draw the shadow - wlr_box fullBox = {m_bLastWindowBox.x - *PSHADOWSIZE, m_bLastWindowBox.y - *PSHADOWSIZE, m_bLastWindowBox.width + 2.0 * *PSHADOWSIZE, - m_bLastWindowBox.height + 2.0 * *PSHADOWSIZE}; - - fullBox.x -= pMonitor->vecPosition.x; - fullBox.y -= pMonitor->vecPosition.y; + CBox fullBox = {m_bLastWindowBox.x, m_bLastWindowBox.y, m_bLastWindowBox.width, m_bLastWindowBox.height}; + fullBox.addExtents(m_eLastExtents).translate(-pMonitor->vecPosition); + fullBox.x -= *PSHADOWSIZE; + fullBox.y -= *PSHADOWSIZE; + fullBox.w += 2 * *PSHADOWSIZE; + fullBox.h += 2 * *PSHADOWSIZE; const float SHADOWSCALE = std::clamp(*PSHADOWSCALE, 0.f, 1.f); // scale the box in relation to the center of the box - const Vector2D NEWSIZE = Vector2D{fullBox.width, fullBox.height} * SHADOWSCALE; - fullBox.width = NEWSIZE.x; - fullBox.height = NEWSIZE.y; - - if (PSHADOWOFFSET->x < 0) { - fullBox.x += PSHADOWOFFSET->x; - } else if (PSHADOWOFFSET->x > 0) { - fullBox.x = m_bLastWindowBox.x + m_bLastWindowBox.width - fullBox.width + (SHADOWSCALE * *PSHADOWSIZE) + PSHADOWOFFSET->x - pMonitor->vecPosition.x; - } else { - fullBox.x += ((m_bLastWindowBox.width + 2.0 * *PSHADOWSIZE) - NEWSIZE.x) / 2.0; - } - - if (PSHADOWOFFSET->y < 0) { - fullBox.y += PSHADOWOFFSET->y; - } else if (PSHADOWOFFSET->y > 0) { - fullBox.y = m_bLastWindowBox.y + m_bLastWindowBox.height - fullBox.height + (SHADOWSCALE * *PSHADOWSIZE) + PSHADOWOFFSET->y - pMonitor->vecPosition.y; - } else { - fullBox.y += ((m_bLastWindowBox.height + 2.0 * *PSHADOWSIZE) - NEWSIZE.y) / 2.0; - } + fullBox.scaleFromCenter(SHADOWSCALE).translate(*PSHADOWOFFSET); m_seExtents = {{m_vLastWindowPos.x - fullBox.x - pMonitor->vecPosition.x + 2, m_vLastWindowPos.y - fullBox.y - pMonitor->vecPosition.y + 2}, {fullBox.x + fullBox.width + pMonitor->vecPosition.x - m_vLastWindowPos.x - m_vLastWindowSize.x + 2, fullBox.y + fullBox.height + pMonitor->vecPosition.y - m_vLastWindowPos.y - m_vLastWindowSize.y + 2}}; - fullBox.x += offset.x; - fullBox.y += offset.y; + fullBox.translate(offset); if (fullBox.width < 1 || fullBox.height < 1) return; // don't draw invisible shadows - g_pHyprOpenGL->scissor((wlr_box*)nullptr); + g_pHyprOpenGL->scissor((CBox*)nullptr); // we'll take the liberty of using this as it should not be used rn CFramebuffer& alphaFB = g_pHyprOpenGL->m_RenderData.pCurrentMonData->mirrorFB; auto* LASTFB = g_pHyprOpenGL->m_RenderData.currentFB; if (*PSHADOWIGNOREWINDOW) { - wlr_box windowBox = {m_bLastWindowBox.x - pMonitor->vecPosition.x, m_bLastWindowBox.y - pMonitor->vecPosition.y, m_bLastWindowBox.width, m_bLastWindowBox.height}; + CBox windowBox = m_bLastWindowBox; + + windowBox.translate(-pMonitor->vecPosition).scale(pMonitor->scale); + windowBox.round(); - scaleBox(&windowBox, pMonitor->scale); + windowBox.addExtents(SWindowDecorationExtents{m_eLastExtents * pMonitor->scale}.floor()).round(); if (windowBox.width < 1 || windowBox.height < 1) { return; // prevent assert failed @@ -165,7 +149,7 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D LASTFB->bind(); } - scaleBox(&fullBox, pMonitor->scale); + fullBox.scale(pMonitor->scale).round(); g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, a, &alphaFB); } diff --git a/src/render/decorations/CHyprDropShadowDecoration.hpp b/src/render/decorations/CHyprDropShadowDecoration.hpp index 7fadf851..d7ec043e 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.hpp +++ b/src/render/decorations/CHyprDropShadowDecoration.hpp @@ -27,5 +27,6 @@ class CHyprDropShadowDecoration : public IHyprWindowDecoration { Vector2D m_vLastWindowPos; Vector2D m_vLastWindowSize; - wlr_box m_bLastWindowBox = {0}; + CBox m_bLastWindowBox = {0}; + SWindowDecorationExtents m_eLastExtents = {}; };
\ No newline at end of file diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index a34a47b7..df269bce 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -76,8 +76,8 @@ void CHyprGroupBarDecoration::updateWindow(CWindow* pWindow) { } void CHyprGroupBarDecoration::damageEntire() { - wlr_box dm = {m_vLastWindowPos.x - m_seExtents.topLeft.x, m_vLastWindowPos.y - m_seExtents.topLeft.y, m_vLastWindowSize.x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x, - m_seExtents.topLeft.y}; + CBox dm = {m_vLastWindowPos.x - m_seExtents.topLeft.x, m_vLastWindowPos.y - m_seExtents.topLeft.y, m_vLastWindowSize.x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x, + m_seExtents.topLeft.y}; g_pHyprRenderer->damageBox(&dm); } @@ -99,13 +99,13 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& int xoff = 0; for (int i = 0; i < barsToDraw; ++i) { - wlr_box rect = {m_vLastWindowPos.x + xoff - pMonitor->vecPosition.x + offset.x, - m_vLastWindowPos.y - BAR_PADDING_OUTER_VERT - BORDERSIZE - BAR_INDICATOR_HEIGHT - pMonitor->vecPosition.y + offset.y, m_fBarWidth, BAR_INDICATOR_HEIGHT}; + CBox rect = {m_vLastWindowPos.x + xoff - pMonitor->vecPosition.x + offset.x, + m_vLastWindowPos.y - BAR_PADDING_OUTER_VERT - BORDERSIZE - BAR_INDICATOR_HEIGHT - pMonitor->vecPosition.y + offset.y, m_fBarWidth, BAR_INDICATOR_HEIGHT}; if (rect.width <= 0 || rect.height <= 0) break; - scaleBox(&rect, pMonitor->scale); + rect.scale(pMonitor->scale); static auto* const PGROUPCOLACTIVE = &g_pConfigManager->getConfigValuePtr("group:groupbar:col.active")->data; static auto* const PGROUPCOLINACTIVE = &g_pConfigManager->getConfigValuePtr("group:groupbar:col.inactive")->data; diff --git a/src/render/decorations/IHyprWindowDecoration.hpp b/src/render/decorations/IHyprWindowDecoration.hpp index 29d50595..47945b38 100644 --- a/src/render/decorations/IHyprWindowDecoration.hpp +++ b/src/render/decorations/IHyprWindowDecoration.hpp @@ -11,11 +11,6 @@ enum eDecorationType DECORATION_CUSTOM }; -struct SWindowDecorationExtents { - Vector2D topLeft; - Vector2D bottomRight; -}; - enum eDecorationLayer { DECORATION_LAYER_BOTTOM = 0, /* lowest. */ |