core/surface: fixup a few pointer handling edge cases

This commit is contained in:
Vaxry 2024-07-29 19:02:58 +02:00
parent 9c38b0fdbe
commit e673220340
3 changed files with 13 additions and 2 deletions

View file

@ -151,6 +151,8 @@ void CPointerManager::setCursorSurface(SP<CWLSurface> surf, const Vector2D& hots
currentCursorImage.surface = surf; currentCursorImage.surface = surf;
currentCursorImage.scale = surf->resource()->current.scale; currentCursorImage.scale = surf->resource()->current.scale;
surf->resource()->map();
currentCursorImage.destroySurface = surf->events.destroy.registerListener([this](std::any data) { resetCursorImage(); }); currentCursorImage.destroySurface = surf->events.destroy.registerListener([this](std::any data) { resetCursorImage(); });
currentCursorImage.commitSurface = surf->resource()->events.commit.registerListener([this](std::any data) { currentCursorImage.commitSurface = surf->resource()->events.commit.registerListener([this](std::any data) {
damageIfSoftware(); damageIfSoftware();
@ -222,6 +224,8 @@ void CPointerManager::resetCursorImage(bool apply) {
currentCursorImage.surface->resource()->leave(m); currentCursorImage.surface->resource()->leave(m);
} }
currentCursorImage.surface->resource()->unmap();
currentCursorImage.destroySurface.reset(); currentCursorImage.destroySurface.reset();
currentCursorImage.commitSurface.reset(); currentCursorImage.commitSurface.reset();
currentCursorImage.surface.reset(); currentCursorImage.surface.reset();

View file

@ -156,6 +156,7 @@ void CWLSurfaceResource::destroy() {
unmap(); unmap();
} }
events.destroy.emit(); events.destroy.emit();
releaseBuffers(false);
PROTO::compositor->destroyResource(this); PROTO::compositor->destroyResource(this);
} }
@ -338,12 +339,17 @@ void CWLSurfaceResource::unmap() {
// release the buffers. // release the buffers.
// this is necessary for XWayland to function correctly, // 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. // 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) if (current.buffer && !current.buffer->resource->released)
current.buffer->sendRelease(); current.buffer->sendRelease();
if (pending.buffer && !pending.buffer->resource->released) if (pending.buffer && !pending.buffer->resource->released && !onlyCurrent)
pending.buffer->sendRelease(); pending.buffer->sendRelease();
pending.buffer.reset(); pending.buffer.reset();
if (!onlyCurrent)
current.buffer.reset(); current.buffer.reset();
} }

View file

@ -137,6 +137,7 @@ class CWLSurfaceResource {
int stateLocks = 0; int stateLocks = 0;
void destroy(); void destroy();
void releaseBuffers(bool onlyCurrent = true);
void commitPendingState(); void commitPendingState();
void bfHelper(std::vector<SP<CWLSurfaceResource>> nodes, std::function<void(SP<CWLSurfaceResource>, const Vector2D&, void*)> fn, void* data); void bfHelper(std::vector<SP<CWLSurfaceResource>> nodes, std::function<void(SP<CWLSurfaceResource>, const Vector2D&, void*)> fn, void* data);
}; };