mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-22 18:49:49 +01:00
make layerSurfaces into RAII
This commit is contained in:
parent
72700bf9dc
commit
1626707b7f
8 changed files with 59 additions and 40 deletions
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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*);
|
||||
|
|
Loading…
Reference in a new issue