Skip to content

Commit

Permalink
fix: trigger BufferHandler::buffer_destroyed on client death
Browse files Browse the repository at this point in the history
Currently, the callback is called when the client makes a destroy request, but
not when the client disconnects and everything is destroyed implicitly.
  • Loading branch information
colinmarc authored and Drakulix committed Mar 13, 2024
1 parent e61db79 commit 76c6b30
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/wayland/dmabuf/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -22,22 +23,26 @@ where
D: Dispatch<wl_buffer::WlBuffer, Dmabuf> + 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,
_data_init: &mut DataInit<'_, D>,
) {
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<D> Dispatch<zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1, DmabufData, D> for DmabufState
Expand Down
11 changes: 8 additions & 3 deletions src/wayland/shm/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -214,20 +215,24 @@ where
D: Dispatch<wl_buffer::WlBuffer, ShmBufferUserData> + 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,
_data_init: &mut DataInit<'_, D>,
) {
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);
}
}

0 comments on commit 76c6b30

Please sign in to comment.