From 76c6b30517c1e09485d016e15c35650aea44259f Mon Sep 17 00:00:00 2001 From: Colin Marc Date: Wed, 13 Mar 2024 10:03:55 +0100 Subject: [PATCH] fix: trigger BufferHandler::buffer_destroyed on client death Currently, the callback is called when the client makes a destroy request, but not when the client disconnects and everything is destroyed implicitly. --- src/wayland/dmabuf/dispatch.rs | 13 +++++++++---- src/wayland/shm/handlers.rs | 11 ++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/wayland/dmabuf/dispatch.rs b/src/wayland/dmabuf/dispatch.rs index 436d7dc255b8..afa9230d2c22 100644 --- a/src/wayland/dmabuf/dispatch.rs +++ b/src/wayland/dmabuf/dispatch.rs @@ -4,7 +4,8 @@ use wayland_protocols::wp::linux_dmabuf::zv1::server::{ zwp_linux_buffer_params_v1, zwp_linux_dmabuf_feedback_v1, zwp_linux_dmabuf_v1, }; use wayland_server::{ - protocol::wl_buffer, Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, + backend::ClientId, protocol::wl_buffer, Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, + Resource, }; use crate::{ @@ -22,9 +23,9 @@ where D: Dispatch + BufferHandler, { fn request( - data: &mut D, + _data: &mut D, _client: &Client, - buffer: &wl_buffer::WlBuffer, + _buffer: &wl_buffer::WlBuffer, request: wl_buffer::Request, _udata: &Dmabuf, _dh: &DisplayHandle, @@ -32,12 +33,16 @@ where ) { match request { wl_buffer::Request::Destroy => { - data.buffer_destroyed(buffer); + // Handled in the destroyed callback. } _ => unreachable!(), } } + + fn destroyed(data: &mut D, _client: ClientId, buffer: &wl_buffer::WlBuffer, _udata: &Dmabuf) { + data.buffer_destroyed(buffer); + } } impl Dispatch for DmabufState diff --git a/src/wayland/shm/handlers.rs b/src/wayland/shm/handlers.rs index f29a3e100b02..fbdb38cc49e4 100644 --- a/src/wayland/shm/handlers.rs +++ b/src/wayland/shm/handlers.rs @@ -10,6 +10,7 @@ use super::{ use std::{num::NonZeroUsize, os::unix::io::AsRawFd, sync::Arc}; use wayland_server::{ + backend::ClientId, protocol::{ wl_buffer, wl_shm::{self, WlShm}, @@ -214,9 +215,9 @@ where D: Dispatch + BufferHandler, { fn request( - data: &mut D, + _data: &mut D, _client: &wayland_server::Client, - buffer: &wl_buffer::WlBuffer, + _buffer: &wl_buffer::WlBuffer, request: wl_buffer::Request, _udata: &ShmBufferUserData, _dh: &DisplayHandle, @@ -224,10 +225,14 @@ where ) { match request { wl_buffer::Request::Destroy => { - data.buffer_destroyed(buffer); + // Handled in the destroyed callback. } _ => unreachable!(), } } + + fn destroyed(data: &mut D, _client: ClientId, buffer: &wl_buffer::WlBuffer, _udata: &ShmBufferUserData) { + data.buffer_destroyed(buffer); + } }