From 211353dc34b8f0fa17fc1e4d1d5f04d6fe1910e5 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 8 Jun 2024 12:03:47 +0200 Subject: core: verify surface roles on creation of objects --- src/protocols/LayerShell.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/protocols/LayerShell.cpp') diff --git a/src/protocols/LayerShell.cpp b/src/protocols/LayerShell.cpp index 8fa6dd27..d4b105cb 100644 --- a/src/protocols/LayerShell.cpp +++ b/src/protocols/LayerShell.cpp @@ -159,6 +159,12 @@ CLayerShellResource::CLayerShellResource(SP resource_, SPresetRole(); +} + +eSurfaceRole CLayerShellResource::role() { + return SURFACE_ROLE_LAYER_SHELL; } bool CLayerShellResource::good() { @@ -207,8 +213,19 @@ void CLayerShellProtocol::destroyResource(CLayerShellResource* surf) { void CLayerShellProtocol::onGetLayerSurface(CZwlrLayerShellV1* pMgr, uint32_t id, wl_resource* surface, wl_resource* output, zwlrLayerShellV1Layer layer, std::string namespace_) { const auto CLIENT = pMgr->client(); const auto PMONITOR = output ? CWLOutputResource::fromResource(output)->monitor.get() : nullptr; - const auto RESOURCE = m_vLayers.emplace_back( - makeShared(makeShared(CLIENT, pMgr->version(), id), CWLSurfaceResource::fromResource(surface), namespace_, PMONITOR, layer)); + auto SURF = CWLSurfaceResource::fromResource(surface); + + if (!SURF) { + pMgr->error(-1, "Invalid surface"); + return; + } + + if (SURF->role->role() != SURFACE_ROLE_UNASSIGNED) { + pMgr->error(-1, "Surface already has a different role"); + return; + } + + const auto RESOURCE = m_vLayers.emplace_back(makeShared(makeShared(CLIENT, pMgr->version(), id), SURF, namespace_, PMONITOR, layer)); if (!RESOURCE->good()) { pMgr->noMemory(); @@ -216,6 +233,7 @@ void CLayerShellProtocol::onGetLayerSurface(CZwlrLayerShellV1* pMgr, uint32_t id return; } + SURF->role = RESOURCE; g_pCompositor->m_vLayers.emplace_back(CLayerSurface::create(RESOURCE)); LOGM(LOG, "New wlr_layer_surface {:x}", (uintptr_t)RESOURCE.get()); -- cgit v1.2.3