Skip to main content

smithay_client_toolkit/
dispatch2.rs

1use std::sync::Arc;
2use wayland_client::backend::ObjectData;
3use wayland_client::{Connection, Proxy, QueueHandle};
4
5pub trait Dispatch2<I: Proxy, State> {
6    fn event(
7        &self,
8        _: &mut State,
9        _: &I,
10        _: <I as Proxy>::Event,
11        _: &Connection,
12        _: &QueueHandle<State>,
13    );
14
15    fn event_created_child(opcode: u16, _qh: &QueueHandle<State>) -> Arc<dyn ObjectData> {
16        panic!(
17            "Missing event_created_child specialization for event opcode {} of {}",
18            opcode,
19            I::interface().name
20        );
21    }
22}
23
24#[macro_export]
25macro_rules! delegate_dispatch2 {
26    ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {
27        impl<$( $( $lt $( : $clt $(+ $dlt )* )? ),+, )? I, UserData> $crate::reexports::client::Dispatch<I, UserData> for $ty
28        where
29            I: $crate::reexports::client::Proxy,
30            UserData: $crate::dispatch2::Dispatch2<I, $ty> {
31            fn event(
32                state: &mut $ty,
33                proxy: &I,
34                event: <I as $crate::reexports::client::Proxy>::Event,
35                data: &UserData,
36                conn: &$crate::reexports::client::Connection,
37                qh: &$crate::reexports::client::QueueHandle<$ty>,
38            ) {
39                data.event(state, proxy, event, conn, qh);
40            }
41
42            fn event_created_child(opcode: u16, qh: &$crate::reexports::client::QueueHandle<$ty>) -> ::std::sync::Arc<dyn $crate::reexports::client::backend::ObjectData> {
43                UserData::event_created_child(opcode, qh)
44            }
45        }
46    };
47}