summaryrefslogtreecommitdiff
path: root/src/protocols/XDGShell.cpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-06-08 12:03:47 +0200
committerVaxry <vaxry@vaxry.net>2024-06-08 12:03:47 +0200
commit211353dc34b8f0fa17fc1e4d1d5f04d6fe1910e5 (patch)
treed0665d48481c62450c0c97da3bfaea95670885f4 /src/protocols/XDGShell.cpp
parent10e02076b183f508ef72198366d53902fe0d9098 (diff)
core: verify surface roles on creation of objects
Diffstat (limited to 'src/protocols/XDGShell.cpp')
-rw-r--r--src/protocols/XDGShell.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/protocols/XDGShell.cpp b/src/protocols/XDGShell.cpp
index 191a1124..dcbc6162 100644
--- a/src/protocols/XDGShell.cpp
+++ b/src/protocols/XDGShell.cpp
@@ -419,6 +419,12 @@ CXDGSurfaceResource::~CXDGSurfaceResource() {
events.destroy.emit();
if (configureSource)
wl_event_source_remove(configureSource);
+ if (surface)
+ surface->resetRole();
+}
+
+eSurfaceRole CXDGSurfaceResource::role() {
+ return SURFACE_ROLE_XDG_SHELL;
}
bool CXDGSurfaceResource::good() {
@@ -646,8 +652,19 @@ CXDGWMBase::CXDGWMBase(SP<CXdgWmBase> resource_) : resource(resource_) {
});
resource->setGetXdgSurface([this](CXdgWmBase* r, uint32_t id, wl_resource* surf) {
- const auto RESOURCE = PROTO::xdgShell->m_vSurfaces.emplace_back(
- makeShared<CXDGSurfaceResource>(makeShared<CXdgSurface>(r->client(), r->version(), id), self.lock(), CWLSurfaceResource::fromResource(surf)));
+ auto SURF = CWLSurfaceResource::fromResource(surf);
+
+ if (!SURF) {
+ r->error(-1, "Invalid surface passed");
+ return;
+ }
+
+ if (SURF->role->role() != SURFACE_ROLE_UNASSIGNED) {
+ r->error(-1, "Surface already has a different role");
+ return;
+ }
+
+ const auto RESOURCE = PROTO::xdgShell->m_vSurfaces.emplace_back(makeShared<CXDGSurfaceResource>(makeShared<CXdgSurface>(r->client(), r->version(), id), self.lock(), SURF));
if (!RESOURCE->good()) {
r->noMemory();
@@ -656,6 +673,7 @@ CXDGWMBase::CXDGWMBase(SP<CXdgWmBase> resource_) : resource(resource_) {
}
RESOURCE->self = RESOURCE;
+ SURF->role = RESOURCE;
surfaces.emplace_back(RESOURCE);