diff --git a/wayland-client/src/event_queue.rs b/wayland-client/src/event_queue.rs index 94674bd3747..8837107f766 100644 --- a/wayland-client/src/event_queue.rs +++ b/wayland-client/src/event_queue.rs @@ -831,6 +831,21 @@ macro_rules! delegate_dispatch { /// /// // This interface should not emit events: /// delegate_noop!(ExampleApp: wl_subcompositor::WlSubcompositor); +/// +/// // Also you can do it with generic type, for example +/// struct ExampleAppGeneric; +/// delegate_noop!(@ ExampleAppGeneric: ignore wl_data_offer::WlDataOffer); +/// delegate_noop!(@ ExampleAppGeneric: wl_subcompositor::WlSubcompositor); +/// +/// // @ is to start with generic, and for base generic type is also ok +/// trait E { +/// // add code here +/// } +/// struct ExampleAppGeneric2 { +/// a: T +/// } +/// delegate_noop!(@ Name2: ignore wl_data_offer::WlDataOffer); +/// delegate_noop!(@ Name2: ignore wl_subcompositor::WlSubcompositor); /// ``` /// /// This last example will execute `unreachable!()` if the interface emits any events. @@ -851,6 +866,22 @@ macro_rules! delegate_noop { } }; + // delegate_noop!(@ ExampleApp: wl_subcompositor::WlSubcompositor); + ($(@< $( const $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from: ty : $interface: ty) => { + impl$(< $(const $lt $( : $clt $(+ $dlt )* )? ),+ >)? $crate::Dispatch<$interface, ()> for $dispatch_from { + fn event( + _: &mut Self, + _: &$interface, + _: <$interface as $crate::Proxy>::Event, + _: &(), + _: &$crate::Connection, + _: &$crate::QueueHandle, + ) { + unreachable!(); + } + } + }; + ($(@< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from: ty : ignore $interface: ty) => { impl$(< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $crate::Dispatch<$interface, ()> for $dispatch_from { fn event( @@ -864,4 +895,19 @@ macro_rules! delegate_noop { } } }; + + // delegate_noop!(@ ExampleApp: ignore wl_subcompositor::WlSubcompositor); + ($(@< $( const $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from: ty : ignore $interface: ty) => { + impl$(< $( const $lt $( : $clt $(+ $dlt )* )? ),+ >)? $crate::Dispatch<$interface, ()> for $dispatch_from { + fn event( + _: &mut Self, + _: &$interface, + _: <$interface as $crate::Proxy>::Event, + _: &(), + _: &$crate::Connection, + _: &$crate::QueueHandle, + ) { + } + } + }; } diff --git a/wayland-server/src/dispatch.rs b/wayland-server/src/dispatch.rs index f68fc5b84dd..5b05dd871d8 100644 --- a/wayland-server/src/dispatch.rs +++ b/wayland-server/src/dispatch.rs @@ -347,6 +347,11 @@ impl + 'stati /// } /// } /// ``` +/// This macro_rules also support to be used with generic type, it will be similiar with client one +/// like +/// ```rust, no_run +/// delegate_dispatch!(@ ExampleApp: [wl_output::WlOutput: MyUserData] => DelegateToMe); +/// ``` #[macro_export] macro_rules! delegate_dispatch { ($(@< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from:ty : [$interface: ty: $udata: ty] => $dispatch_to: ty) => { @@ -363,6 +368,25 @@ macro_rules! delegate_dispatch { <$dispatch_to as $crate::Dispatch<$interface, $udata, Self>>::request(state, client, resource, request, data, dhandle, data_init) } + fn destroyed(state: &mut Self, client: $crate::backend::ClientId, resource: &$interface, data: &$udata) { + <$dispatch_to as $crate::Dispatch<$interface, $udata, Self>>::destroyed(state, client, resource, data) + } + } + }; + ($(@< $( const $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from:ty : [$interface: ty: $udata: ty] => $dispatch_to: ty) => { + impl$(< $( const $lt $( : $clt $(+ $dlt )* )? ),+ >)? $crate::Dispatch<$interface, $udata> for $dispatch_from { + fn request( + state: &mut Self, + client: &$crate::Client, + resource: &$interface, + request: <$interface as $crate::Resource>::Request, + data: &$udata, + dhandle: &$crate::DisplayHandle, + data_init: &mut $crate::DataInit<'_, Self>, + ) { + <$dispatch_to as $crate::Dispatch<$interface, $udata, Self>>::request(state, client, resource, request, data, dhandle, data_init) + } + fn destroyed(state: &mut Self, client: $crate::backend::ClientId, resource: &$interface, data: &$udata) { <$dispatch_to as $crate::Dispatch<$interface, $udata, Self>>::destroyed(state, client, resource, data) }