diff --git a/src/protocols/LayerShell.cpp b/src/protocols/LayerShell.cpp index 295ef4a9..17d3b22a 100644 --- a/src/protocols/LayerShell.cpp +++ b/src/protocols/LayerShell.cpp @@ -175,10 +175,6 @@ CLayerShellResource::~CLayerShellResource() { surface->resetRole(); } -eSurfaceRole CLayerShellResource::role() { - return SURFACE_ROLE_LAYER_SHELL; -} - bool CLayerShellResource::good() { return resource->resource(); } @@ -245,8 +241,12 @@ void CLayerShellProtocol::onGetLayerSurface(CZwlrLayerShellV1* pMgr, uint32_t id return; } - SURF->role = RESOURCE; + SURF->role = makeShared(RESOURCE); g_pCompositor->m_vLayers.emplace_back(CLayerSurface::create(RESOURCE)); LOGM(LOG, "New wlr_layer_surface {:x}", (uintptr_t)RESOURCE.get()); } + +CLayerShellRole::CLayerShellRole(SP ls) : layerSurface(ls) { + ; +} diff --git a/src/protocols/LayerShell.hpp b/src/protocols/LayerShell.hpp index ee0b7859..801bdfd6 100644 --- a/src/protocols/LayerShell.hpp +++ b/src/protocols/LayerShell.hpp @@ -12,16 +12,26 @@ class CMonitor; class CWLSurfaceResource; +class CLayerShellResource; -class CLayerShellResource : public ISurfaceRole { +class CLayerShellRole : public ISurfaceRole { + public: + CLayerShellRole(SP ls); + + virtual eSurfaceRole role() { + return SURFACE_ROLE_LAYER_SHELL; + } + + WP layerSurface; +}; +class CLayerShellResource { public: CLayerShellResource(SP resource_, SP surf_, std::string namespace_, CMonitor* pMonitor, zwlrLayerShellV1Layer layer); ~CLayerShellResource(); - bool good(); - void configure(const Vector2D& size); - void sendClosed(); - virtual eSurfaceRole role(); + bool good(); + void configure(const Vector2D& size); + void sendClosed(); enum eCommittedState { STATE_SIZE = (1 << 0), diff --git a/src/protocols/XDGShell.cpp b/src/protocols/XDGShell.cpp index 5e82b530..4aa5d373 100644 --- a/src/protocols/XDGShell.cpp +++ b/src/protocols/XDGShell.cpp @@ -443,10 +443,6 @@ CXDGSurfaceResource::~CXDGSurfaceResource() { surface->resetRole(); } -eSurfaceRole CXDGSurfaceResource::role() { - return SURFACE_ROLE_XDG_SHELL; -} - bool CXDGSurfaceResource::good() { return resource->resource(); } @@ -668,7 +664,7 @@ CXDGWMBase::CXDGWMBase(SP resource_) : resource(resource_) { RESOURCE->self = RESOURCE; RESOURCE->surface = SURF; - SURF->role = RESOURCE; + SURF->role = makeShared(RESOURCE); surfaces.emplace_back(RESOURCE); @@ -765,3 +761,7 @@ void CXDGShellProtocol::onPopupDestroy(WP popup) { if (popup->surface) grab->remove(popup->surface->surface.lock()); } + +CXDGSurfaceRole::CXDGSurfaceRole(SP xdg) : xdgSurface(xdg) { + ; +} diff --git a/src/protocols/XDGShell.hpp b/src/protocols/XDGShell.hpp index e6812c38..81d10613 100644 --- a/src/protocols/XDGShell.hpp +++ b/src/protocols/XDGShell.hpp @@ -141,15 +141,24 @@ class CXDGToplevelResource { void applyState(); }; -class CXDGSurfaceResource : public ISurfaceRole { +class CXDGSurfaceRole : public ISurfaceRole { + public: + CXDGSurfaceRole(SP xdg); + + virtual eSurfaceRole role() { + return SURFACE_ROLE_XDG_SHELL; + } + + WP xdgSurface; +}; + +class CXDGSurfaceResource { public: CXDGSurfaceResource(SP resource_, SP owner_, SP surface_); ~CXDGSurfaceResource(); static SP fromResource(wl_resource*); - virtual eSurfaceRole role(); - bool good(); WP owner; diff --git a/src/protocols/core/Compositor.cpp b/src/protocols/core/Compositor.cpp index bff52133..4a6fa40f 100644 --- a/src/protocols/core/Compositor.cpp +++ b/src/protocols/core/Compositor.cpp @@ -277,7 +277,7 @@ void CWLSurfaceResource::bfHelper(std::vector> nodes, std for (auto& n : nodes) { Vector2D offset = {}; if (n->role->role() == SURFACE_ROLE_SUBSURFACE) { - auto subsurface = (CWLSubsurfaceResource*)n->role.get(); + auto subsurface = ((CSubsurfaceRole*)n->role.get())->subsurface.lock(); offset = subsurface->posRelativeToParent(); } @@ -448,7 +448,7 @@ void CWLSurfaceResource::commitPendingState() { // TODO: we should _accumulate_ and not replace above if sync if (role->role() == SURFACE_ROLE_SUBSURFACE) { - auto subsurface = (CWLSubsurfaceResource*)role.get(); + auto subsurface = ((CSubsurfaceRole*)role.get())->subsurface.lock(); if (subsurface->sync) return; @@ -458,7 +458,7 @@ void CWLSurfaceResource::commitPendingState() { breadthfirst( [](SP surf, const Vector2D& offset, void* data) { if (surf->role->role() == SURFACE_ROLE_SUBSURFACE) { - auto subsurface = (CWLSubsurfaceResource*)surf->role.get(); + auto subsurface = ((CSubsurfaceRole*)surf->role.get())->subsurface.lock(); if (!subsurface->sync) return; } diff --git a/src/protocols/core/Subcompositor.cpp b/src/protocols/core/Subcompositor.cpp index 90f89d91..2a7c06dc 100644 --- a/src/protocols/core/Subcompositor.cpp +++ b/src/protocols/core/Subcompositor.cpp @@ -119,7 +119,7 @@ Vector2D CWLSubsurfaceResource::posRelativeToParent() { while (surf->role->role() == SURFACE_ROLE_SUBSURFACE && std::find_if(surfacesVisited.begin(), surfacesVisited.end(), [surf](const auto& other) { return surf == other; }) == surfacesVisited.end()) { surfacesVisited.emplace_back(surf); - auto subsurface = (CWLSubsurfaceResource*)parent->role.get(); + auto subsurface = ((CSubsurfaceRole*)parent->role.get())->subsurface.lock(); pos += subsurface->position; surf = subsurface->parent.lock(); } @@ -130,10 +130,6 @@ bool CWLSubsurfaceResource::good() { return resource->resource(); } -eSurfaceRole CWLSubsurfaceResource::role() { - return SURFACE_ROLE_SUBSURFACE; -} - SP CWLSubsurfaceResource::t1Parent() { SP surf = parent.lock(); std::vector> surfacesVisited; @@ -141,7 +137,7 @@ SP CWLSubsurfaceResource::t1Parent() { while (surf->role->role() == SURFACE_ROLE_SUBSURFACE && std::find_if(surfacesVisited.begin(), surfacesVisited.end(), [surf](const auto& other) { return surf == other; }) == surfacesVisited.end()) { surfacesVisited.emplace_back(surf); - auto subsurface = (CWLSubsurfaceResource*)parent->role.get(); + auto subsurface = ((CSubsurfaceRole*)parent->role.get())->subsurface.lock(); surf = subsurface->parent.lock(); } return surf; @@ -171,7 +167,7 @@ CWLSubcompositorResource::CWLSubcompositorResource(SP resource SP t1Parent = nullptr; if (PARENT->role->role() == SURFACE_ROLE_SUBSURFACE) { - auto subsurface = (CWLSubsurfaceResource*)PARENT->role.get(); + auto subsurface = ((CSubsurfaceRole*)PARENT->role.get())->subsurface.lock(); t1Parent = subsurface->t1Parent(); } else t1Parent = PARENT; @@ -191,7 +187,7 @@ CWLSubcompositorResource::CWLSubcompositorResource(SP resource } RESOURCE->self = RESOURCE; - SURF->role = RESOURCE; + SURF->role = makeShared(RESOURCE); PARENT->subsurfaces.emplace_back(RESOURCE); LOGM(LOG, "New wl_subsurface with id {} at {:x}", id, (uintptr_t)RESOURCE.get()); @@ -225,3 +221,7 @@ void CWLSubcompositorProtocol::destroyResource(CWLSubcompositorResource* resourc void CWLSubcompositorProtocol::destroyResource(CWLSubsurfaceResource* resource) { std::erase_if(m_vSurfaces, [&](const auto& other) { return other.get() == resource; }); } + +CSubsurfaceRole::CSubsurfaceRole(SP sub) : subsurface(sub) { + ; +} diff --git a/src/protocols/core/Subcompositor.hpp b/src/protocols/core/Subcompositor.hpp index 824f0ffc..2e6b10bb 100644 --- a/src/protocols/core/Subcompositor.hpp +++ b/src/protocols/core/Subcompositor.hpp @@ -16,15 +16,26 @@ #include "../types/SurfaceRole.hpp" class CWLSurfaceResource; +class CWLSubsurfaceResource; -class CWLSubsurfaceResource : public ISurfaceRole { +class CSubsurfaceRole : public ISurfaceRole { + public: + CSubsurfaceRole(SP sub); + + virtual eSurfaceRole role() { + return SURFACE_ROLE_SUBSURFACE; + } + + WP subsurface; +}; + +class CWLSubsurfaceResource { public: CWLSubsurfaceResource(SP resource_, SP surface_, SP parent_); ~CWLSubsurfaceResource(); Vector2D posRelativeToParent(); bool good(); - virtual eSurfaceRole role(); SP t1Parent(); bool sync = false;