From e67322034037fef22079c8e480be38c1d04b5a4a Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 29 Jul 2024 19:02:58 +0200 Subject: [PATCH] core/surface: fixup a few pointer handling edge cases --- src/managers/PointerManager.cpp | 4 ++++ src/protocols/core/Compositor.cpp | 10 ++++++++-- src/protocols/core/Compositor.hpp | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp index a09992a2..a405e2eb 100644 --- a/src/managers/PointerManager.cpp +++ b/src/managers/PointerManager.cpp @@ -151,6 +151,8 @@ void CPointerManager::setCursorSurface(SP surf, const Vector2D& hots currentCursorImage.surface = surf; currentCursorImage.scale = surf->resource()->current.scale; + surf->resource()->map(); + currentCursorImage.destroySurface = surf->events.destroy.registerListener([this](std::any data) { resetCursorImage(); }); currentCursorImage.commitSurface = surf->resource()->events.commit.registerListener([this](std::any data) { damageIfSoftware(); @@ -222,6 +224,8 @@ void CPointerManager::resetCursorImage(bool apply) { currentCursorImage.surface->resource()->leave(m); } + currentCursorImage.surface->resource()->unmap(); + currentCursorImage.destroySurface.reset(); currentCursorImage.commitSurface.reset(); currentCursorImage.surface.reset(); diff --git a/src/protocols/core/Compositor.cpp b/src/protocols/core/Compositor.cpp index 6352b7e6..43d3059b 100644 --- a/src/protocols/core/Compositor.cpp +++ b/src/protocols/core/Compositor.cpp @@ -156,6 +156,7 @@ void CWLSurfaceResource::destroy() { unmap(); } events.destroy.emit(); + releaseBuffers(false); PROTO::compositor->destroyResource(this); } @@ -338,13 +339,18 @@ void CWLSurfaceResource::unmap() { // release the buffers. // this is necessary for XWayland to function correctly, // as it does not unmap via the traditional commit(null buffer) method, but via the X11 protocol. + releaseBuffers(); +} + +void CWLSurfaceResource::releaseBuffers(bool onlyCurrent) { if (current.buffer && !current.buffer->resource->released) current.buffer->sendRelease(); - if (pending.buffer && !pending.buffer->resource->released) + if (pending.buffer && !pending.buffer->resource->released && !onlyCurrent) pending.buffer->sendRelease(); pending.buffer.reset(); - current.buffer.reset(); + if (!onlyCurrent) + current.buffer.reset(); } void CWLSurfaceResource::error(int code, const std::string& str) { diff --git a/src/protocols/core/Compositor.hpp b/src/protocols/core/Compositor.hpp index 1fa6926a..79cd1de6 100644 --- a/src/protocols/core/Compositor.hpp +++ b/src/protocols/core/Compositor.hpp @@ -137,6 +137,7 @@ class CWLSurfaceResource { int stateLocks = 0; void destroy(); + void releaseBuffers(bool onlyCurrent = true); void commitPendingState(); void bfHelper(std::vector> nodes, std::function, const Vector2D&, void*)> fn, void* data); };