diff --git a/src/events/Events.cpp b/src/events/Events.cpp index 1c40e520..24c51a07 100644 --- a/src/events/Events.cpp +++ b/src/events/Events.cpp @@ -190,6 +190,8 @@ void Events::listener_commitLayerSurface(wl_listener* listener, void* data) { if (!layersurface->layerSurface->output) return; + g_pHyprRenderer->arrangeLayersForMonitor(PMONITOR->ID); + if (layersurface->layer != layersurface->layerSurface->current.layer) { PMONITOR->m_aLayerSurfaceLists[layersurface->layer].remove(layersurface); PMONITOR->m_aLayerSurfaceLists[layersurface->layerSurface->current.layer].push_back(layersurface); diff --git a/src/helpers/Vector2D.hpp b/src/helpers/Vector2D.hpp index 166e0b92..5fe4ccd3 100644 --- a/src/helpers/Vector2D.hpp +++ b/src/helpers/Vector2D.hpp @@ -35,6 +35,5 @@ class Vector2D { return a.x != x || a.y != y; } - Vector2D floor(); }; \ No newline at end of file diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 0ad0c1ba..b335cbe0 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -139,4 +139,70 @@ void CHyprRenderer::outputMgrApplyTest(wlr_output_configuration_v1* config, bool wlr_output_configuration_v1_destroy(config); Debug::log(LOG, "OutputMgr Applied/Tested."); +} + +void CHyprRenderer::arrangeLayerArray(SMonitor* pMonitor, const std::list& layerSurfaces) { + for (auto& ls : layerSurfaces) { + + const auto STATE = &ls->layerSurface->current; + wlr_box layerBox = { .width = STATE->desired_width, .height = STATE->desired_height }; + + if (STATE->anchor & (ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) + layerBox.width = pMonitor->vecSize.x; + if (STATE->anchor & (ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) + layerBox.height = pMonitor->vecSize.y; + + if (STATE->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP) { + pMonitor->vecReservedTopLeft.y += STATE->desired_height; + layerBox.x = pMonitor->vecPosition.x + STATE->margin.left; + layerBox.y = pMonitor->vecPosition.y + STATE->margin.top; + + layerBox.width -= STATE->margin.left + STATE->margin.right; + layerBox.height -= STATE->margin.top + STATE->margin.bottom; + } + if (STATE->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM) { + pMonitor->vecReservedBottomRight.y += STATE->desired_height; + layerBox.x = pMonitor->vecPosition.x + STATE->margin.left; + layerBox.y = pMonitor->vecPosition.y + pMonitor->vecSize.y - layerBox.height - STATE->margin.bottom; + + layerBox.width -= STATE->margin.left + STATE->margin.right; + layerBox.height -= STATE->margin.top + STATE->margin.bottom; + } + if (STATE->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT) { + pMonitor->vecReservedTopLeft.x += STATE->desired_width; + layerBox.x = pMonitor->vecPosition.x + STATE->margin.left; + layerBox.y = pMonitor->vecPosition.y + STATE->margin.top; + + layerBox.width -= STATE->margin.left + STATE->margin.right; + layerBox.height -= STATE->margin.top + STATE->margin.bottom; + } + if (STATE->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT) { + pMonitor->vecReservedBottomRight.x += STATE->desired_width; + layerBox.x = pMonitor->vecPosition.x + pMonitor->vecSize.x - layerBox.width - STATE->margin.right; + layerBox.y = pMonitor->vecPosition.y + STATE->margin.top; + + layerBox.width -= STATE->margin.left + STATE->margin.right; + layerBox.height -= STATE->margin.top + STATE->margin.bottom; + } + + ls->geometry = layerBox; + + wlr_layer_surface_v1_configure(ls->layerSurface, layerBox.width, layerBox.height); + + Debug::log(LOG, "LayerSurface %x arranged: x: %i y: %i w: %i h: %i", &ls, layerBox.x, layerBox.y, layerBox.width, layerBox.height); + } +} + +void CHyprRenderer::arrangeLayersForMonitor(const int& monitor) { + const auto PMONITOR = g_pCompositor->getMonitorFromID(monitor); + + if (!PMONITOR) + return; + + // Reset the reserved + PMONITOR->vecReservedBottomRight = Vector2D(); + PMONITOR->vecReservedTopLeft = Vector2D(); + + for (auto& la : PMONITOR->m_aLayerSurfaceLists) + arrangeLayerArray(PMONITOR, la); } \ No newline at end of file diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index e1d6894f..21a32975 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -1,14 +1,18 @@ #pragma once #include "../defines.hpp" +#include +#include "../helpers/Monitor.hpp" class CHyprRenderer { public: void renderAllClientsForMonitor(const int&, timespec*); void outputMgrApplyTest(wlr_output_configuration_v1*, bool); + void arrangeLayersForMonitor(const int&); private: + void arrangeLayerArray(SMonitor*, const std::list&); }; inline std::unique_ptr g_pHyprRenderer;