summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-07-23 15:48:08 +0200
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-07-23 15:48:08 +0200
commit1626707b7f4fd3d2b313e78cb3a41783f072f73b (patch)
treed03ac32a9c898f38216f191949b8c5b2ff89044e /src
parent72700bf9dc17d1d145130bd53b436a80e1c971d2 (diff)
make layerSurfaces into RAII
Diffstat (limited to 'src')
-rw-r--r--src/Compositor.cpp18
-rw-r--r--src/Compositor.hpp2
-rw-r--r--src/debug/HyprCtl.cpp4
-rw-r--r--src/events/Layers.cpp33
-rw-r--r--src/events/Monitors.cpp19
-rw-r--r--src/helpers/Monitor.hpp5
-rw-r--r--src/render/Renderer.cpp16
-rw-r--r--src/render/Renderer.hpp2
8 files changed, 59 insertions, 40 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp
index 99a46dfa..d8c39e30 100644
--- a/src/Compositor.cpp
+++ b/src/Compositor.cpp
@@ -716,7 +716,7 @@ CWindow* CCompositor::getWindowForPopup(wlr_xdg_popup* popup) {
return nullptr;
}
-wlr_surface* CCompositor::vectorToLayerSurface(const Vector2D& pos, std::list<SLayerSurface*>* layerSurfaces, Vector2D* sCoords, SLayerSurface** ppLayerSurfaceFound) {
+wlr_surface* CCompositor::vectorToLayerSurface(const Vector2D& pos, std::vector<std::unique_ptr<SLayerSurface>>* layerSurfaces, Vector2D* sCoords, SLayerSurface** ppLayerSurfaceFound) {
for (auto it = layerSurfaces->rbegin(); it != layerSurfaces->rend(); it++) {
if ((*it)->fadingOut || !(*it)->layerSurface || ((*it)->layerSurface && !(*it)->layerSurface->mapped))
continue;
@@ -724,7 +724,7 @@ wlr_surface* CCompositor::vectorToLayerSurface(const Vector2D& pos, std::list<SL
const auto SURFACEAT = wlr_layer_surface_v1_surface_at((*it)->layerSurface, pos.x - (*it)->geometry.x, pos.y - (*it)->geometry.y, &sCoords->x, &sCoords->y);
if (SURFACEAT) {
- *ppLayerSurfaceFound = *it;
+ *ppLayerSurfaceFound = it->get();
return SURFACEAT;
}
}
@@ -900,18 +900,18 @@ void CCompositor::cleanupFadingOut(const int& monid) {
continue;
if (ls->fadingOut && ls->readyToDelete && !ls->alpha.isBeingAnimated()) {
- for (auto& m : m_vMonitors) {
- for (auto& lsl : m->m_aLayerSurfaceLists) {
- lsl.remove(ls);
- }
- }
-
g_pHyprOpenGL->m_mLayerFramebuffers[ls].release();
g_pHyprOpenGL->m_mLayerFramebuffers.erase(ls);
- delete ls;
m_vSurfacesFadingOut.erase(std::remove(m_vSurfacesFadingOut.begin(), m_vSurfacesFadingOut.end(), ls));
+ for (auto& m : m_vMonitors) {
+ for (auto& lsl : m->m_aLayerSurfaceLists) {
+ if (!lsl.empty() && std::find_if(lsl.begin(), lsl.end(), [&](std::unique_ptr<SLayerSurface>& other) { return other.get() == ls; }) != lsl.end())
+ lsl.erase(std::remove_if(lsl.begin(), lsl.end(), [&](std::unique_ptr<SLayerSurface>& other) { return other.get() == ls; }));
+ }
+ }
+
Debug::log(LOG, "Cleanup: destroyed a layersurface");
glFlush(); // to free mem NOW.
diff --git a/src/Compositor.hpp b/src/Compositor.hpp
index 0500387c..9b80357f 100644
--- a/src/Compositor.hpp
+++ b/src/Compositor.hpp
@@ -107,7 +107,7 @@ public:
CWindow* vectorToWindow(const Vector2D&);
CWindow* vectorToWindowIdeal(const Vector2D&); // used only for finding a window to focus on, basically a "findFocusableWindow"
CWindow* vectorToWindowTiled(const Vector2D&);
- wlr_surface* vectorToLayerSurface(const Vector2D&, std::list<SLayerSurface*>*, Vector2D*, SLayerSurface**);
+ wlr_surface* vectorToLayerSurface(const Vector2D&, std::vector<std::unique_ptr<SLayerSurface>>*, Vector2D*, SLayerSurface**);
wlr_surface* vectorWindowToSurface(const Vector2D&, CWindow*, Vector2D& sl);
CWindow* windowFromCursor();
CWindow* windowFloatingFromCursor();
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp
index 9832a22d..f87b6711 100644
--- a/src/debug/HyprCtl.cpp
+++ b/src/debug/HyprCtl.cpp
@@ -220,7 +220,7 @@ R"#( {
"h": %i,
"namespace": "%s"
},)#",
- layer,
+ layer.get(),
layer->geometry.x,
layer->geometry.y,
layer->geometry.width,
@@ -259,7 +259,7 @@ R"#( {
result += getFormat("\tLayer level %i:\n", layerLevel);
for (auto& layer : level) {
- result += getFormat("\t\tLayer %x: xywh: %i %i %i %i, namespace: %s\n", layer, layer->geometry.x, layer->geometry.y, layer->geometry.width, layer->geometry.height, layer->szNamespace.c_str());
+ result += getFormat("\t\tLayer %x: xywh: %i %i %i %i, namespace: %s\n", layer.get(), layer->geometry.x, layer->geometry.y, layer->geometry.width, layer->geometry.height, layer->szNamespace.c_str());
}
layerLevel++;
diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp
index 431ebef1..f69b9127 100644
--- a/src/events/Layers.cpp
+++ b/src/events/Layers.cpp
@@ -32,7 +32,7 @@ void Events::listener_newLayerSurface(wl_listener* listener, void* data) {
}
const auto PMONITOR = (SMonitor*)g_pCompositor->getMonitorFromOutput(WLRLAYERSURFACE->output);
- SLayerSurface* layerSurface = PMONITOR->m_aLayerSurfaceLists[WLRLAYERSURFACE->pending.layer].emplace_back(new SLayerSurface());
+ SLayerSurface* layerSurface = PMONITOR->m_aLayerSurfaceLists[WLRLAYERSURFACE->pending.layer].emplace_back(std::make_unique<SLayerSurface>()).get();
layerSurface->szNamespace = WLRLAYERSURFACE->_namespace;
@@ -109,8 +109,13 @@ void Events::listener_mapLayerSurface(void* owner, void* data) {
if ((uint64_t)layersurface->monitorID != PMONITOR->ID) {
const auto POLDMON = g_pCompositor->getMonitorFromID(layersurface->monitorID);
- POLDMON->m_aLayerSurfaceLists[layersurface->layer].remove(layersurface);
- PMONITOR->m_aLayerSurfaceLists[layersurface->layer].push_back(layersurface);
+ for (auto it = POLDMON->m_aLayerSurfaceLists[layersurface->layer].begin(); it != POLDMON->m_aLayerSurfaceLists[layersurface->layer].end(); it++) {
+ if (it->get() == layersurface) {
+ PMONITOR->m_aLayerSurfaceLists[layersurface->layer].emplace_back(std::move(*it));
+ POLDMON->m_aLayerSurfaceLists[layersurface->layer].erase(it);
+ break;
+ }
+ }
layersurface->monitorID = PMONITOR->ID;
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(POLDMON->ID);
g_pHyprRenderer->arrangeLayersForMonitor(POLDMON->ID);
@@ -197,8 +202,15 @@ void Events::listener_commitLayerSurface(void* owner, void* data) {
// fix if it changed its mon
if ((uint64_t)layersurface->monitorID != PMONITOR->ID) {
const auto POLDMON = g_pCompositor->getMonitorFromID(layersurface->monitorID);
- POLDMON->m_aLayerSurfaceLists[layersurface->layer].remove(layersurface);
- PMONITOR->m_aLayerSurfaceLists[layersurface->layer].push_back(layersurface);
+
+ for (auto it = POLDMON->m_aLayerSurfaceLists[layersurface->layer].begin(); it != POLDMON->m_aLayerSurfaceLists[layersurface->layer].end(); it++) {
+ if (it->get() == layersurface) {
+ PMONITOR->m_aLayerSurfaceLists[layersurface->layer].emplace_back(std::move(*it));
+ POLDMON->m_aLayerSurfaceLists[layersurface->layer].erase(it);
+ break;
+ }
+ }
+
layersurface->monitorID = PMONITOR->ID;
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(POLDMON->ID);
g_pHyprRenderer->arrangeLayersForMonitor(POLDMON->ID);
@@ -208,8 +220,15 @@ void Events::listener_commitLayerSurface(void* owner, void* data) {
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);
+
+ for (auto it = PMONITOR->m_aLayerSurfaceLists[layersurface->layer].begin(); it != PMONITOR->m_aLayerSurfaceLists[layersurface->layer].end(); it++) {
+ if (it->get() == layersurface) {
+ PMONITOR->m_aLayerSurfaceLists[layersurface->layerSurface->current.layer].emplace_back(std::move(*it));
+ PMONITOR->m_aLayerSurfaceLists[layersurface->layer].erase(it);
+ break;
+ }
+ }
+
layersurface->layer = layersurface->layerSurface->current.layer;
}
diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp
index 9604dc69..57da68fc 100644
--- a/src/events/Monitors.cpp
+++ b/src/events/Monitors.cpp
@@ -72,10 +72,11 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
return;
}
- SMonitor newMonitor;
- newMonitor.output = OUTPUT;
- newMonitor.ID = g_pCompositor->getNextAvailableMonitorID();
- newMonitor.szName = OUTPUT->name;
+ const auto PNEWMONITOR = g_pCompositor->m_vMonitors.emplace_back(std::make_unique<SMonitor>()).get();
+
+ PNEWMONITOR->output = OUTPUT;
+ PNEWMONITOR->ID = g_pCompositor->getNextAvailableMonitorID();
+ PNEWMONITOR->szName = OUTPUT->name;
wlr_output_init_render(OUTPUT, g_pCompositor->m_sWLRAllocator, g_pCompositor->m_sWLRRenderer);
@@ -86,11 +87,9 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
wlr_output_enable_adaptive_sync(OUTPUT, 1);
// create it in the arr
- newMonitor.vecPosition = monitorRule.offset;
- newMonitor.vecSize = monitorRule.resolution;
- newMonitor.refreshRate = monitorRule.refreshRate;
-
- const auto PNEWMONITOR = g_pCompositor->m_vMonitors.emplace_back(std::make_unique<SMonitor>(newMonitor)).get();
+ PNEWMONITOR->vecPosition = monitorRule.offset;
+ PNEWMONITOR->vecSize = monitorRule.resolution;
+ PNEWMONITOR->refreshRate = monitorRule.refreshRate;
PNEWMONITOR->hyprListener_monitorFrame.initCallback(&OUTPUT->events.frame, &Events::listener_monitorFrame, PNEWMONITOR);
PNEWMONITOR->hyprListener_monitorDestroy.initCallback(&OUTPUT->events.destroy, &Events::listener_monitorDestroy, PNEWMONITOR);
@@ -134,7 +133,7 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(PNEWMONITOR->ID);
PNEWWORKSPACE->startAnim(true,true,true);
} else {
- PNEWWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(std::make_unique<CWorkspace>(newMonitor.ID, newDefaultWorkspaceName)).get();
+ PNEWWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(std::make_unique<CWorkspace>(PNEWMONITOR->ID, newDefaultWorkspaceName)).get();
// We are required to set the name here immediately
wlr_ext_workspace_handle_v1_set_name(PNEWWORKSPACE->m_pWlrHandle, newDefaultWorkspaceName.c_str());
diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp
index 24e555f9..93736614 100644
--- a/src/helpers/Monitor.hpp
+++ b/src/helpers/Monitor.hpp
@@ -3,8 +3,9 @@
#include "../defines.hpp"
#include <deque>
#include "WLClasses.hpp"
-#include <list>
+#include <vector>
#include <array>
+#include <memory>
struct SMonitor {
Vector2D vecPosition = Vector2D(0,0);
@@ -38,7 +39,7 @@ struct SMonitor {
// Double-linked list because we need to have constant mem addresses for signals
// We have to store pointers and use raw new/delete because they might be moved between them
// and I am lazy
- std::array<std::list<SLayerSurface*>, 4> m_aLayerSurfaceLists;
+ std::array<std::vector<std::unique_ptr<SLayerSurface>>, 4> m_aLayerSurfaceLists;
DYNLISTENER(monitorFrame);
DYNLISTENER(monitorDestroy);
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index 79b3a8b5..a00d6f11 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -147,12 +147,12 @@ void CHyprRenderer::renderWorkspaceWithFullscreenWindow(SMonitor* pMonitor, CWor
if (pWorkspace->m_efFullscreenMode != FULLSCREEN_FULL) {
// on non-full we draw the bar and shit
for (auto& ls : pMonitor->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) {
- renderLayer(ls, pMonitor, time);
+ renderLayer(ls.get(), pMonitor, time);
}
}
for (auto& ls : pMonitor->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]) {
- renderLayer(ls, pMonitor, time);
+ renderLayer(ls.get(), pMonitor, time);
}
renderDragIcon(pMonitor, time);
@@ -290,10 +290,10 @@ void CHyprRenderer::renderAllClientsForMonitor(const int& ID, timespec* time) {
// Render layer surfaces below windows for monitor
for (auto& ls : PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]) {
- renderLayer(ls, PMONITOR, time);
+ renderLayer(ls.get(), PMONITOR, time);
}
for (auto& ls : PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]) {
- renderLayer(ls, PMONITOR, time);
+ renderLayer(ls.get(), PMONITOR, time);
}
// if there is a fullscreen window, render it and then do not render anymore.
@@ -376,10 +376,10 @@ void CHyprRenderer::renderAllClientsForMonitor(const int& ID, timespec* time) {
// Render surfaces above windows for monitor
for (auto& ls : PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) {
- renderLayer(ls, PMONITOR, time);
+ renderLayer(ls.get(), PMONITOR, time);
}
for (auto& ls : PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]) {
- renderLayer(ls, PMONITOR, time);
+ renderLayer(ls.get(), PMONITOR, time);
}
renderDragIcon(PMONITOR, time);
@@ -504,7 +504,7 @@ void apply_exclusive(struct wlr_box* usable_area, uint32_t anchor, int32_t exclu
}
}
-void CHyprRenderer::arrangeLayerArray(SMonitor* pMonitor, const std::list<SLayerSurface*>& layerSurfaces, bool exclusiveZone, wlr_box* usableArea) {
+void CHyprRenderer::arrangeLayerArray(SMonitor* 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};
for (auto& ls : layerSurfaces) {
@@ -577,7 +577,7 @@ void CHyprRenderer::arrangeLayerArray(SMonitor* pMonitor, const std::list<SLayer
box.y -= PSTATE->margin.bottom;
}
if (box.width <= 0 || box.height <= 0) {
- Debug::log(ERR, "LayerSurface %x has a negative/zero w/h???", ls);
+ Debug::log(ERR, "LayerSurface %x has a negative/zero w/h???", ls.get());
continue;
}
// Apply
diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp
index 97a0dc70..3c9b18bd 100644
--- a/src/render/Renderer.hpp
+++ b/src/render/Renderer.hpp
@@ -46,7 +46,7 @@ public:
DAMAGETRACKINGMODES damageTrackingModeFromStr(const std::string&);
private:
- void arrangeLayerArray(SMonitor*, const std::list<SLayerSurface*>&, bool, wlr_box*);
+ void arrangeLayerArray(SMonitor*, const std::vector<std::unique_ptr<SLayerSurface>>&, bool, wlr_box*);
void renderWorkspaceWithFullscreenWindow(SMonitor*, CWorkspace*, timespec*);
void renderWindow(CWindow*, SMonitor*, timespec*, bool, eRenderPassMode);
void renderLayer(SLayerSurface*, SMonitor*, timespec*);