diff --git a/wayland-client/CHANGELOG.md b/wayland-client/CHANGELOG.md index 10b9d3607ba..0ead35e7322 100644 --- a/wayland-client/CHANGELOG.md +++ b/wayland-client/CHANGELOG.md @@ -2,6 +2,13 @@ ## Unreleased +#### Breaking changes +- Define `Dispatch` to be implemented on udata type +- Remove `delegate_dispatch!` in favor of implementation that is generic over + `D` for a particular user data type +- Replace `delegate_noop!` with `Noop` and `NoopIgnore` types providing generic + dispatch implementations + ## 0.31.14-- 2026-03-30 - Updated Wayland core protocol to 1.25 diff --git a/wayland-client/examples/list_globals.rs b/wayland-client/examples/list_globals.rs index abb88e92bc7..bd453174a73 100644 --- a/wayland-client/examples/list_globals.rs +++ b/wayland-client/examples/list_globals.rs @@ -14,12 +14,12 @@ struct AppData; // // In this example, we just use () as we don't have any value to associate. See // the `Dispatch` documentation for more details about this. -impl Dispatch for AppData { +impl Dispatch for () { fn event( - _: &mut Self, + &self, + _: &mut AppData, _: &wl_registry::WlRegistry, event: wl_registry::Event, - _: &(), _: &Connection, _: &QueueHandle, ) { diff --git a/wayland-client/examples/simple_window.rs b/wayland-client/examples/simple_window.rs index ce684e7928b..762b9e01209 100644 --- a/wayland-client/examples/simple_window.rs +++ b/wayland-client/examples/simple_window.rs @@ -1,15 +1,14 @@ use std::{fs::File, os::unix::io::AsFd}; use wayland_client::{ - Connection, Dispatch, QueueHandle, WEnum, delegate_noop, - protocol::{ - wl_buffer, wl_compositor, wl_keyboard, wl_registry, wl_seat, wl_shm, wl_shm_pool, - wl_surface, - }, + Connection, Dispatch, NoopIgnore, QueueHandle, WEnum, + protocol::{wl_buffer, wl_compositor, wl_keyboard, wl_registry, wl_seat, wl_shm, wl_surface}, }; use wayland_protocols::xdg::shell::client::{xdg_surface, xdg_toplevel, xdg_wm_base}; +struct GlobalData; + fn main() { let conn = Connection::connect_to_env().unwrap(); @@ -17,7 +16,7 @@ fn main() { let qhandle = event_queue.handle(); let display = conn.display(); - display.get_registry(&qhandle, ()); + display.get_registry(&qhandle, GlobalData); let mut state = State { running: true, @@ -44,21 +43,21 @@ struct State { configured: bool, } -impl Dispatch for State { +impl Dispatch for GlobalData { fn event( - state: &mut Self, + &self, + state: &mut State, registry: &wl_registry::WlRegistry, event: wl_registry::Event, - _: &(), _: &Connection, - qh: &QueueHandle, + qh: &QueueHandle, ) { if let wl_registry::Event::Global { name, interface, .. } = event { match &interface[..] { "wl_compositor" => { let compositor = - registry.bind::(name, 1, qh, ()); - let surface = compositor.create_surface(qh, ()); + registry.bind::(name, 1, qh, NoopIgnore); + let surface = compositor.create_surface(qh, NoopIgnore); state.base_surface = Some(surface); if state.wm_base.is_some() && state.xdg_surface.is_none() { @@ -66,13 +65,14 @@ impl Dispatch for State { } } "wl_shm" => { - let shm = registry.bind::(name, 1, qh, ()); + let shm = registry.bind::(name, 1, qh, NoopIgnore); let (init_w, init_h) = (320, 240); let mut file = tempfile::tempfile().unwrap(); draw(&mut file, (init_w, init_h)); - let pool = shm.create_pool(file.as_fd(), (init_w * init_h * 4) as i32, qh, ()); + let pool = + shm.create_pool(file.as_fd(), (init_w * init_h * 4) as i32, qh, NoopIgnore); let buffer = pool.create_buffer( 0, init_w as i32, @@ -80,7 +80,7 @@ impl Dispatch for State { (init_w * 4) as i32, wl_shm::Format::Argb8888, qh, - (), + NoopIgnore, ); state.buffer = Some(buffer.clone()); @@ -91,10 +91,11 @@ impl Dispatch for State { } } "wl_seat" => { - registry.bind::(name, 1, qh, ()); + registry.bind::(name, 1, qh, GlobalData); } "xdg_wm_base" => { - let wm_base = registry.bind::(name, 1, qh, ()); + let wm_base = + registry.bind::(name, 1, qh, GlobalData); state.wm_base = Some(wm_base); if state.base_surface.is_some() && state.xdg_surface.is_none() { @@ -107,13 +108,6 @@ impl Dispatch for State { } } -// Ignore events from these object types in this example. -delegate_noop!(State: ignore wl_compositor::WlCompositor); -delegate_noop!(State: ignore wl_surface::WlSurface); -delegate_noop!(State: ignore wl_shm::WlShm); -delegate_noop!(State: ignore wl_shm_pool::WlShmPool); -delegate_noop!(State: ignore wl_buffer::WlBuffer); - fn draw(tmp: &mut File, (buf_x, buf_y): (u32, u32)) { use std::{cmp::min, io::Write}; let mut buf = std::io::BufWriter::new(tmp); @@ -134,8 +128,8 @@ impl State { let wm_base = self.wm_base.as_ref().unwrap(); let base_surface = self.base_surface.as_ref().unwrap(); - let xdg_surface = wm_base.get_xdg_surface(base_surface, qh, ()); - let toplevel = xdg_surface.get_toplevel(qh, ()); + let xdg_surface = wm_base.get_xdg_surface(base_surface, qh, GlobalData); + let toplevel = xdg_surface.get_toplevel(qh, GlobalData); toplevel.set_title("A fantastic window!".into()); base_surface.commit(); @@ -144,14 +138,14 @@ impl State { } } -impl Dispatch for State { +impl Dispatch for GlobalData { fn event( - _: &mut Self, + &self, + _: &mut State, wm_base: &xdg_wm_base::XdgWmBase, event: xdg_wm_base::Event, - _: &(), _: &Connection, - _: &QueueHandle, + _: &QueueHandle, ) { if let xdg_wm_base::Event::Ping { serial } = event { wm_base.pong(serial); @@ -159,14 +153,14 @@ impl Dispatch for State { } } -impl Dispatch for State { +impl Dispatch for GlobalData { fn event( - state: &mut Self, + &self, + state: &mut State, xdg_surface: &xdg_surface::XdgSurface, event: xdg_surface::Event, - _: &(), _: &Connection, - _: &QueueHandle, + _: &QueueHandle, ) { if let xdg_surface::Event::Configure { serial, .. } = event { xdg_surface.ack_configure(serial); @@ -180,14 +174,14 @@ impl Dispatch for State { } } -impl Dispatch for State { +impl Dispatch for GlobalData { fn event( - state: &mut Self, + &self, + state: &mut State, _: &xdg_toplevel::XdgToplevel, event: xdg_toplevel::Event, - _: &(), _: &Connection, - _: &QueueHandle, + _: &QueueHandle, ) { if let xdg_toplevel::Event::Close = event { state.running = false; @@ -195,31 +189,31 @@ impl Dispatch for State { } } -impl Dispatch for State { +impl Dispatch for GlobalData { fn event( - _: &mut Self, + &self, + _: &mut State, seat: &wl_seat::WlSeat, event: wl_seat::Event, - _: &(), _: &Connection, - qh: &QueueHandle, + qh: &QueueHandle, ) { if let wl_seat::Event::Capabilities { capabilities: WEnum::Value(capabilities) } = event { if capabilities.contains(wl_seat::Capability::Keyboard) { - seat.get_keyboard(qh, ()); + seat.get_keyboard(qh, GlobalData); } } } } -impl Dispatch for State { +impl Dispatch for GlobalData { fn event( - state: &mut Self, + &self, + state: &mut State, _: &wl_keyboard::WlKeyboard, event: wl_keyboard::Event, - _: &(), _: &Connection, - _: &QueueHandle, + _: &QueueHandle, ) { if let wl_keyboard::Event::Key { key, .. } = event { if key == 1 { diff --git a/wayland-client/src/event_queue.rs b/wayland-client/src/event_queue.rs index 11836a0e2e0..55234426fc3 100644 --- a/wayland-client/src/event_queue.rs +++ b/wayland-client/src/event_queue.rs @@ -38,17 +38,13 @@ use crate::{Connection, DispatchError, Proxy, conn::SyncData}; /// ## Modularity /// /// To provide generic handlers for downstream usage, it is possible to make an implementation of the trait -/// that is generic over the last type argument, as illustrated below. Users will then be able to -/// automatically delegate their implementation to yours using the [`delegate_dispatch!()`] macro. -/// -/// [`delegate_dispatch!()`]: crate::delegate_dispatch!() +/// that is generic over the last type argument, as illustrated below. /// /// As a result, when your implementation is instantiated, the last type parameter `State` will be the state /// struct of the app using your generic implementation. You can put additional trait constraints on it to /// specify an interface between your module and downstream code, as illustrated in this example: /// /// ``` -/// # // Maintainers: If this example changes, please make sure you also carry those changes over to the delegate_dispatch macro. /// use wayland_client::{protocol::wl_registry, Dispatch}; /// /// /// The type we want to delegate to @@ -61,7 +57,7 @@ use crate::{Connection, DispatchError, Proxy, conn::SyncData}; /// /// // Now a generic implementation of Dispatch, we are generic over the last type argument instead of using /// // the default State=Self. -/// impl Dispatch for DelegateToMe +/// impl Dispatch for MyUserData /// where /// // State is the type which has delegated to this type, so it needs to have an impl of Dispatch itself /// State: Dispatch, @@ -71,10 +67,10 @@ use crate::{Connection, DispatchError, Proxy, conn::SyncData}; /// State: AsMut, /// { /// fn event( +/// &self, /// state: &mut State, /// _proxy: &wl_registry::WlRegistry, /// _event: wl_registry::Event, -/// _udata: &MyUserData, /// _conn: &wayland_client::Connection, /// _qhandle: &wayland_client::QueueHandle, /// ) { @@ -92,11 +88,9 @@ use crate::{Connection, DispatchError, Proxy, conn::SyncData}; /// implementation of [`Dispatch`] cannot be used directly as the dispatching state, as rustc /// currently fails to understand that it also provides `Dispatch` (assuming all other /// trait bounds are respected as well). -pub trait Dispatch +pub trait Dispatch where - Self: Sized, I: Proxy, - State: Dispatch, { /// Called when an event from the server is processed /// @@ -110,10 +104,10 @@ where /// - a reference to a [`QueueHandle`] associated with the [`EventQueue`] currently processing events, in /// case you need to create new objects that you want associated to the same [`EventQueue`]. fn event( + &self, state: &mut State, proxy: &I, event: I::Event, - data: &UserData, conn: &Connection, qhandle: &QueueHandle, ); @@ -333,9 +327,8 @@ impl EventQueueInner { msg: Message, odata: Arc, ) where - State: Dispatch + 'static, - U: Send + Sync + 'static, - I: Proxy + 'static, + U: Dispatch + Send + Sync + 'static, + I: Proxy, { let func = queue_callback::; self.queue.push_back(QueueEvent(func, msg, odata)); @@ -608,12 +601,9 @@ impl QueueHandle { /// This creates an implementation of [`ObjectData`] fitting for direct use with `wayland-backend` APIs /// that forwards all events to the event queue associated with this token, integrating the object into /// the [`Dispatch`]-based logic of `wayland-client`. - pub fn make_data( - &self, - user_data: U, - ) -> Arc + pub fn make_data(&self, user_data: U) -> Arc where - State: Dispatch, + U: Dispatch + Send + Sync + 'static, { Arc::new(QueueProxyData:: { handle: self.clone(), @@ -644,11 +634,7 @@ impl Drop for QueueFreezeGuard<'_, State> { } } -fn queue_callback< - I: Proxy + 'static, - U: Send + Sync + 'static, - State: Dispatch + 'static, ->( +fn queue_callback + Send + Sync + 'static, State>( handle: &Connection, msg: Message, data: &mut State, @@ -656,8 +642,8 @@ fn queue_callback< qhandle: &QueueHandle, ) -> Result<(), DispatchError> { let (proxy, event) = I::parse_event(handle, msg)?; - let udata = odata.data_as_any().downcast_ref().expect("Wrong user_data value for object"); - >::event(data, &proxy, event, udata, handle, qhandle); + let udata: &U = odata.data_as_any().downcast_ref().expect("Wrong user_data value for object"); + udata.event(data, &proxy, event, handle, qhandle); Ok(()) } @@ -669,9 +655,9 @@ pub struct QueueProxyData { _phantom: PhantomData, } -impl ObjectData for QueueProxyData +impl ObjectData for QueueProxyData where - State: Dispatch + 'static, + U: Dispatch + Send + Sync + 'static, { fn event( self: Arc, @@ -682,7 +668,7 @@ where .args .iter() .any(|arg| matches!(arg, Argument::NewId(id) if !id.is_null())) - .then(|| State::event_created_child(msg.opcode, &self.handle)); + .then(|| U::event_created_child(msg.opcode, &self.handle)); self.handle.inner.lock().unwrap().enqueue_event::(msg, self.clone()); @@ -703,174 +689,20 @@ impl std::fmt::Debug for QueueProxyData Dispatch for DelegateToMe -/// # where -/// # State: Dispatch + AsMut, -/// # { -/// # fn event( -/// # _state: &mut State, -/// # _proxy: &wl_registry::WlRegistry, -/// # _event: wl_registry::Event, -/// # _udata: &MyUserData, -/// # _conn: &wayland_client::Connection, -/// # _qhandle: &wayland_client::QueueHandle, -/// # ) { -/// # } -/// # } -/// -/// // ExampleApp is the type events will be dispatched to. -/// -/// /// The application state -/// struct ExampleApp { -/// /// The delegate for handling wl_registry events. -/// delegate: DelegateToMe, -/// } -/// -/// // Use delegate_dispatch to implement Dispatch for ExampleApp -/// delegate_dispatch!(ExampleApp: [wl_registry::WlRegistry: MyUserData] => DelegateToMe); -/// -/// // DelegateToMe requires that ExampleApp implements AsMut, so we provide the -/// // trait implementation. -/// impl AsMut for ExampleApp { -/// fn as_mut(&mut self) -> &mut DelegateToMe { -/// &mut self.delegate -/// } -/// } -/// -/// // To explain the macro above, you may read it as the following: -/// // -/// // For ExampleApp, delegate WlRegistry to DelegateToMe. -/// -/// // Assert ExampleApp can Dispatch events for wl_registry -/// fn assert_is_registry_delegate() -/// where -/// T: Dispatch, -/// { -/// } -/// -/// assert_is_registry_delegate::(); -/// -/// // This macro can also be applied to a generic type using the `@<>` syntax: -/// -/// /// The application state -/// struct GenericApp { -/// /// The delegate for handling wl_registry events. -/// delegate: DelegateToMe, -/// app_data: T, -/// } -/// -/// delegate_dispatch!(@ GenericApp: [wl_registry::WlRegistry: MyUserData] => DelegateToMe); -/// -/// impl AsMut for GenericApp { -/// fn as_mut(&mut self) -> &mut DelegateToMe { -/// &mut self.delegate -/// } -/// } -/// -/// // Assert that the above setup applies to a concrete GenericApp type -/// assert_is_registry_delegate::>(); -/// ``` -#[macro_export] -macro_rules! delegate_dispatch { - ($(@< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from:ty : [$interface: ty: $udata: ty] => $dispatch_to: ty) => { - impl$(< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $crate::Dispatch<$interface, $udata> for $dispatch_from { - fn event( - state: &mut Self, - proxy: &$interface, - event: <$interface as $crate::Proxy>::Event, - data: &$udata, - conn: &$crate::Connection, - qhandle: &$crate::QueueHandle, - ) { - <$dispatch_to as $crate::Dispatch<$interface, $udata, Self>>::event(state, proxy, event, data, conn, qhandle) - } +/// A type that implements [`Dispatch`] for all interfaces, panicking on any event. +#[derive(Debug)] +pub struct Noop; - fn event_created_child( - opcode: u16, - qhandle: &$crate::QueueHandle - ) -> ::std::sync::Arc { - <$dispatch_to as $crate::Dispatch<$interface, $udata, Self>>::event_created_child(opcode, qhandle) - } - } - }; +impl Dispatch for Noop { + fn event(&self, _: &mut State, _: &I, _: I::Event, _: &Connection, _: &QueueHandle) { + unreachable!() + } } -/// A helper macro which delegates a set of [`Dispatch`] implementations for proxies to a static handler. -/// -/// # Usage -/// -/// This macro is useful to implement [`Dispatch`] for interfaces where events are unimportant to -/// the current application and can be ignored. -/// -/// # Example -/// -/// ``` -/// use wayland_client::{delegate_noop, protocol::{wl_data_offer, wl_subcompositor}}; -/// -/// /// The application state -/// struct ExampleApp { -/// // ... -/// } -/// -/// // Ignore all events for this interface: -/// delegate_noop!(ExampleApp: ignore wl_data_offer::WlDataOffer); -/// -/// // This interface should not emit events: -/// delegate_noop!(ExampleApp: wl_subcompositor::WlSubcompositor); -/// ``` -/// -/// This last example will execute `unreachable!()` if the interface emits any events. -#[macro_export] -macro_rules! delegate_noop { - ($(@< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from: ty : $interface: ty) => { - impl$(< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $crate::Dispatch<$interface, ()> for $dispatch_from { - fn event( - _: &mut Self, - _: &$interface, - _: <$interface as $crate::Proxy>::Event, - _: &(), - _: &$crate::Connection, - _: &$crate::QueueHandle, - ) { - unreachable!(); - } - } - }; +/// A type that implements [`Dispatch`] for all interfaces, ignoring any event. +#[derive(Debug)] +pub struct NoopIgnore; - ($(@< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from: ty : ignore $interface: ty) => { - impl$(< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $crate::Dispatch<$interface, ()> for $dispatch_from { - fn event( - _: &mut Self, - _: &$interface, - _: <$interface as $crate::Proxy>::Event, - _: &(), - _: &$crate::Connection, - _: &$crate::QueueHandle, - ) { - } - } - }; +impl Dispatch for NoopIgnore { + fn event(&self, _: &mut State, _: &I, _: I::Event, _: &Connection, _: &QueueHandle) {} } diff --git a/wayland-client/src/globals.rs b/wayland-client/src/globals.rs index e857c418c1a..149b9d62503 100644 --- a/wayland-client/src/globals.rs +++ b/wayland-client/src/globals.rs @@ -20,14 +20,14 @@ //! # struct State; //! //! // You need to provide a Dispatch impl for your app -//! impl wayland_client::Dispatch for State { +//! impl wayland_client::Dispatch for GlobalListContents { //! fn event( +//! // This mutex contains an up-to-date list of the currently known globals +//! // including the one that was just added or destroyed +//! &self, //! state: &mut State, //! proxy: &wl_registry::WlRegistry, //! event: wl_registry::Event, -//! // This mutex contains an up-to-date list of the currently known globals -//! // including the one that was just added or destroyed -//! data: &GlobalListContents, //! conn: &Connection, //! qhandle: &QueueHandle, //! ) { @@ -38,12 +38,12 @@ //! let conn = Connection::connect_to_env().unwrap(); //! let (globals, queue) = registry_queue_init::(&conn).unwrap(); //! -//! # impl wayland_client::Dispatch for State { +//! # impl wayland_client::Dispatch for () { //! # fn event( +//! # &self, //! # state: &mut State, //! # proxy: &wl_compositor::WlCompositor, //! # event: wl_compositor::Event, -//! # data: &(), //! # conn: &Connection, //! # qhandle: &QueueHandle, //! # ) {} @@ -79,7 +79,8 @@ pub fn registry_queue_init( conn: &Connection, ) -> Result<(GlobalList, EventQueue), GlobalError> where - State: Dispatch + 'static, + State: 'static, + GlobalListContents: Dispatch + 'static, { let event_queue = conn.new_event_queue(); let display = conn.display(); @@ -156,8 +157,8 @@ impl GlobalList { ) -> Result where I: Proxy + 'static, - State: Dispatch + 'static, - U: Send + Sync + 'static, + State: 'static, + U: Dispatch + Send + Sync + 'static, { let version_start = *version.start(); let version_end = *version.end(); @@ -339,7 +340,7 @@ struct RegistryState { impl ObjectData for RegistryState where - State: Dispatch, + GlobalListContents: Dispatch, { fn event( self: Arc, diff --git a/wayland-client/src/lib.rs b/wayland-client/src/lib.rs index 0a0ceeac963..cdf8b6700e9 100644 --- a/wayland-client/src/lib.rs +++ b/wayland-client/src/lib.rs @@ -41,10 +41,9 @@ //! managing the newly created object. //! //! However, implementing all those traits on your own is a lot of (often uninteresting) work. To make this -//! easier a composition mechanism is provided using the [`delegate_dispatch!`] macro. This way, another -//! library (such as Smithay's Client Toolkit) can provide generic [`Dispatch`] implementations that you -//! can reuse in your own app by delegating those objects to that provided implementation. See the -//! documentation of those traits and macro for details. +//! easier another library (such as Smithay's Client Toolkit) can provide generic [`Dispatch`] implementations +//! for a user-data type it defines, that you can reuse in your own appSee the documentation of those traits +//! for details. //! //! ## Getting started example //! @@ -67,12 +66,12 @@ //! // //! // In this example, we just use () as we don't have any value to associate. See //! // the `Dispatch` documentation for more details about this. -//! impl Dispatch for AppData { +//! impl Dispatch for () { //! fn event( -//! _state: &mut Self, +//! &self, +//! _state: &mut AppData, //! _: &wl_registry::WlRegistry, //! event: wl_registry::Event, -//! _: &(), //! _: &Connection, //! _: &QueueHandle, //! ) { @@ -195,7 +194,9 @@ pub mod backend { pub use wayland_backend::protocol::WEnum; pub use conn::{ConnectError, Connection}; -pub use event_queue::{Dispatch, EventQueue, QueueFreezeGuard, QueueHandle, QueueProxyData}; +pub use event_queue::{ + Dispatch, EventQueue, Noop, NoopIgnore, QueueFreezeGuard, QueueHandle, QueueProxyData, +}; // internal imports for dispatching logging depending on the `log` feature #[cfg(feature = "log")] diff --git a/wayland-scanner/src/client_gen.rs b/wayland-scanner/src/client_gen.rs index 678d819732c..5626dfc5795 100644 --- a/wayland-scanner/src/client_gen.rs +++ b/wayland-scanner/src/client_gen.rs @@ -246,7 +246,10 @@ fn gen_methods(interface: &Interface) -> TokenStream { quote! { #doc_attr #[allow(clippy::too_many_arguments)] - pub fn #method_name + 'static>(&self, #(#fn_args,)* qh: &QueueHandle, udata: U) -> super::#created_iface_mod::#created_iface_type { + pub fn #method_name(&self, #(#fn_args,)* qh: &QueueHandle, udata: U) -> super::#created_iface_mod::#created_iface_type + where + U: Dispatch + Send + Sync + 'static + { self.send_constructor( Request::#enum_variant { #(#enum_args),* @@ -261,7 +264,10 @@ fn gen_methods(interface: &Interface) -> TokenStream { quote! { #doc_attr #[allow(clippy::too_many_arguments)] - pub fn #method_name + 'static>(&self, #(#fn_args,)* qh: &QueueHandle, udata: U) -> I { + pub fn #method_name(&self, #(#fn_args,)* qh: &QueueHandle, udata: U) -> I + where + U: Dispatch + Send + Sync + 'static + { self.send_constructor( Request::#enum_variant { #(#enum_args),* diff --git a/wayland-scanner/tests/scanner_assets/test-client-code.rs b/wayland-scanner/tests/scanner_assets/test-client-code.rs index f77c21acef5..3b1c4331145 100644 --- a/wayland-scanner/tests/scanner_assets/test-client-code.rs +++ b/wayland-scanner/tests/scanner_assets/test-client-code.rs @@ -264,14 +264,14 @@ pub mod wl_display { impl WlDisplay { #[doc = "asynchronous roundtrip\n\nThe sync request asks the server to emit the 'done' event\non the returned wl_callback object. Since requests are\nhandled in-order and events are delivered in-order, this can\nbe used as a barrier to ensure all previous requests and the\nresulting events have been handled.\n\nThe object returned by this request will be destroyed by the\ncompositor after the callback is fired and as such the client must not\nattempt to use it after that point.\n\nThe callback_data passed in the callback is the event serial."] #[allow(clippy::too_many_arguments)] - pub fn sync< - U: Send + Sync + 'static, - D: Dispatch + 'static, - >( + pub fn sync( &self, qh: &QueueHandle, udata: U, - ) -> super::wl_callback::WlCallback { + ) -> super::wl_callback::WlCallback + where + U: Dispatch + Send + Sync + 'static, + { self.send_constructor( Request::Sync {}, qh.make_data::(udata), @@ -280,14 +280,14 @@ pub mod wl_display { } #[doc = "get global registry object\n\nThis request creates a registry object that allows the client\nto list and bind the global objects available from the\ncompositor.\n\nIt should be noted that the server side resources consumed in\nresponse to a get_registry request can only be released when the\nclient disconnects, not when the client side proxy is destroyed.\nTherefore, clients should invoke get_registry as infrequently as\npossible to avoid wasting memory."] #[allow(clippy::too_many_arguments)] - pub fn get_registry< - U: Send + Sync + 'static, - D: Dispatch + 'static, - >( + pub fn get_registry( &self, qh: &QueueHandle, udata: U, - ) -> super::wl_registry::WlRegistry { + ) -> super::wl_registry::WlRegistry + where + U: Dispatch + Send + Sync + 'static, + { self.send_constructor( Request::GetRegistry {}, qh.make_data::(udata), @@ -519,13 +519,16 @@ pub mod wl_registry { impl WlRegistry { #[doc = "bind an object to the display\n\nBinds a new, client-created object to the server using the\nspecified name as the identifier."] #[allow(clippy::too_many_arguments)] - pub fn bind + 'static>( + pub fn bind( &self, name: u32, version: u32, qh: &QueueHandle, udata: U, - ) -> I { + ) -> I + where + U: Dispatch + Send + Sync + 'static, + { self.send_constructor( Request::Bind { name, id: (I::interface(), version) }, qh.make_data::(udata), @@ -1162,14 +1165,14 @@ pub mod test_global { ); } #[allow(clippy::too_many_arguments)] - pub fn get_secondary< - U: Send + Sync + 'static, - D: Dispatch + 'static, - >( + pub fn get_secondary( &self, qh: &QueueHandle, udata: U, - ) -> super::secondary::Secondary { + ) -> super::secondary::Secondary + where + U: Dispatch + Send + Sync + 'static, + { self.send_constructor( Request::GetSecondary {}, qh.make_data::(udata), @@ -1177,14 +1180,14 @@ pub mod test_global { .unwrap_or_else(|_| Proxy::inert(self.backend.clone())) } #[allow(clippy::too_many_arguments)] - pub fn get_tertiary< - U: Send + Sync + 'static, - D: Dispatch + 'static, - >( + pub fn get_tertiary( &self, qh: &QueueHandle, udata: U, - ) -> super::tertiary::Tertiary { + ) -> super::tertiary::Tertiary + where + U: Dispatch + Send + Sync + 'static, + { self.send_constructor( Request::GetTertiary {}, qh.make_data::(udata), @@ -1239,16 +1242,16 @@ pub mod test_global { } #[doc = "a newid request that also takes allow null arg"] #[allow(clippy::too_many_arguments)] - pub fn newid_and_allow_null< - U: Send + Sync + 'static, - D: Dispatch + 'static, - >( + pub fn newid_and_allow_null( &self, sec: Option<&super::secondary::Secondary>, ter: &super::tertiary::Tertiary, qh: &QueueHandle, udata: U, - ) -> super::quad::Quad { + ) -> super::quad::Quad + where + U: Dispatch + Send + Sync + 'static, + { self.send_constructor( Request::NewidAndAllowNull { sec: sec.cloned(), ter: ter.clone() }, qh.make_data::(udata), diff --git a/wayland-server/CHANGELOG.md b/wayland-server/CHANGELOG.md index b91116c6526..00e74235680 100644 --- a/wayland-server/CHANGELOG.md +++ b/wayland-server/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +#### Breaking changes +- Define `Dispatch` and `GlobalDispatch` to be implemented on udata type +- Remove `delegate_dispatch!` and `delegate_global_dispatch!` in favor of + implementation that is generic over `D` for a particular user data type + ## 0.31.13-- 2026-03-30 - Updated Wayland core protocol to 1.25 diff --git a/wayland-server/src/client.rs b/wayland-server/src/client.rs index 91b4bffac73..b28e556d17a 100644 --- a/wayland-server/src/client.rs +++ b/wayland-server/src/client.rs @@ -51,16 +51,17 @@ impl Client { /// The newly created resource should be immediately sent to the client through an associated event with /// a `new_id` argument. Not doing so risks corrupting the protocol state and causing protocol errors at /// a later time. - pub fn create_resource< - I: Resource + 'static, - U: Send + Sync + 'static, - D: Dispatch + 'static, - >( + pub fn create_resource( &self, handle: &DisplayHandle, version: u32, user_data: U, - ) -> Result { + ) -> Result + where + I: Resource + 'static, + U: Dispatch + Send + Sync + 'static, + D: 'static, + { let id = handle.handle.create_object::( self.id.clone(), I::interface(), diff --git a/wayland-server/src/dispatch.rs b/wayland-server/src/dispatch.rs index 65bb478805d..9cd5eb1fc46 100644 --- a/wayland-server/src/dispatch.rs +++ b/wayland-server/src/dispatch.rs @@ -30,18 +30,13 @@ use crate::{Client, DisplayHandle, Resource}; /// ## Modularity /// /// To provide generic handlers for downstream usage, it is possible to make an implementation of the trait -/// that is generic over the last type argument, as illustrated below. Users will then be able to -/// automatically delegate their implementation to yours using the [`delegate_dispatch!()`] macro. -/// -/// [`delegate_dispatch!()`]: crate::delegate_dispatch!() +/// that is generic over the last type argument, as illustrated below. /// /// As a result, when your implementation is instanciated, the last type parameter `State` will be the state /// struct of the app using your generic implementation. You can put additional trait constraints on it to /// specify an interface between your module and downstream code, as illustrated in this example: /// /// ``` -/// # // Maintainers: If this example changes, please make sure you also carry those changes over to the -/// # // delegate_dispatch macro. /// use wayland_server::{protocol::wl_output, Dispatch}; /// /// /// The type we want to delegate to @@ -54,21 +49,21 @@ use crate::{Client, DisplayHandle, Resource}; /// /// // Now a generic implementation of Dispatch, we are generic over the last type argument instead of using /// // the default State=Self. -/// impl Dispatch for DelegateToMe +/// impl Dispatch for MyUserData /// where /// // State is the type which has delegated to this type, so it needs to have an impl of Dispatch itself -/// State: Dispatch, +/// MyUserData: Dispatch, /// // If your delegate type has some internal state, it'll need to access it, and you can /// // require it by adding custom trait bounds. /// // In this example, we just require an AsMut implementation /// State: AsMut, /// { /// fn request( +/// &self, /// state: &mut State, /// _client: &wayland_server::Client, /// _resource: &wl_output::WlOutput, /// _request: wl_output::Request, -/// _udata: &MyUserData, /// _dhandle: &wayland_server::DisplayHandle, /// _data_init: &mut wayland_server::DataInit<'_, State>, /// ) { @@ -86,18 +81,18 @@ use crate::{Client, DisplayHandle, Resource}; /// implementation of [`Dispatch`] cannot be used directly as the dispatching state, as rustc /// currently fails to understand that it also provides `Dispatch` (assuming all other /// trait bounds are respected as well). -pub trait Dispatch: Sized { +pub trait Dispatch { /// Called when a request from a client is processed. /// /// The implementation of this function will vary depending on what protocol is being implemented. Typically /// the server may respond to clients by sending events to the resource, or some other resource stored in /// the user data. fn request( + &self, state: &mut State, client: &Client, resource: &I, request: I::Request, - data: &UserData, dhandle: &DisplayHandle, data_init: &mut DataInit<'_, State>, ); @@ -114,10 +109,10 @@ pub trait Dispatch: Sized { /// /// By default this method does nothing. fn destroyed( + &self, _state: &mut State, _client: wayland_backend::server::ClientId, _resource: &I, - _data: &UserData, ) { } } @@ -160,13 +155,9 @@ pub struct DataInit<'a, D: 'static> { impl DataInit<'_, D> { /// Initialize an object by assigning it its user-data - pub fn init( - &mut self, - resource: New, - data: U, - ) -> I + pub fn init(&mut self, resource: New, data: U) -> I where - D: Dispatch + 'static, + U: Dispatch + Send + Sync + 'static, { let arc = Arc::new(ResourceData::::new(data)); *self.store = Some(arc.clone() as Arc<_>); @@ -219,7 +210,7 @@ impl ResourceData { } } -impl + 'static> ObjectData +impl + Send + Sync + 'static> ObjectData for ResourceData { fn request( @@ -262,12 +253,11 @@ impl + 'stati let mut new_data = None; - >::request( + udata.request( data, &client, &resource, request, - udata, &dhandle, // The error is None since the creating object posts an error. &mut DataInit { store: &mut new_data, error: &mut None }, @@ -290,83 +280,6 @@ impl + 'stati // therefore manually initialize the data associated with protocol object wrapper. resource.__set_object_data(self.clone()); - >::destroyed(data, client_id, &resource, &self.udata) + self.udata.destroyed(data, client_id, &resource) } } - -/// A helper macro which delegates a set of [`Dispatch`] implementations for a resource to some other type which -/// provides a generic [`Dispatch`] implementation. -/// -/// This macro allows more easily delegating smaller parts of the protocol a compositor may wish to handle -/// in a modular fashion. -/// -/// # Usage -/// -/// For example, say you want to delegate events for [`WlOutput`][crate::protocol::wl_output::WlOutput] -/// to the `DelegateToMe` type from the [`Dispatch`] documentation. -/// -/// ``` -/// use wayland_server::{delegate_dispatch, protocol::wl_output}; -/// # -/// # use wayland_server::Dispatch; -/// # -/// # struct DelegateToMe; -/// # -/// # impl Dispatch for DelegateToMe -/// # where -/// # D: Dispatch + AsMut, -/// # { -/// # fn request( -/// # _state: &mut D, -/// # _client: &wayland_server::Client, -/// # _resource: &wl_output::WlOutput, -/// # _request: wl_output::Request, -/// # _data: &(), -/// # _dhandle: &wayland_server::DisplayHandle, -/// # _data_init: &mut wayland_server::DataInit<'_, D>, -/// # ) { -/// # } -/// # } -/// # -/// # type MyUserData = (); -/// -/// // ExampleApp is the type events will be dispatched to. -/// -/// /// The application state -/// struct ExampleApp { -/// /// The delegate for handling wl_registry events. -/// delegate: DelegateToMe, -/// } -/// -/// // Use delegate_dispatch to implement Dispatch for ExampleApp. -/// delegate_dispatch!(ExampleApp: [wl_output::WlOutput: MyUserData] => DelegateToMe); -/// -/// // DelegateToMe requires that ExampleApp implements AsMut, so we provide the trait implementation. -/// impl AsMut for ExampleApp { -/// fn as_mut(&mut self) -> &mut DelegateToMe { -/// &mut self.delegate -/// } -/// } -/// ``` -#[macro_export] -macro_rules! delegate_dispatch { - ($(@< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from:ty : [$interface: ty: $udata: ty] => $dispatch_to: ty) => { - impl$(< $( $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) - } - } - }; -} diff --git a/wayland-server/src/display.rs b/wayland-server/src/display.rs index 0b28166beb0..a6ddb004559 100644 --- a/wayland-server/src/display.rs +++ b/wayland-server/src/display.rs @@ -123,13 +123,10 @@ impl DisplayHandle { /// defined by your [`GlobalDispatch`] implementation for the given interface. Whenever a client /// binds this global, the associated [`GlobalDispatch::bind()`] method will be invoked on your /// `State`. - pub fn create_global( - &self, - version: u32, - data: U, - ) -> GlobalId + pub fn create_global(&self, version: u32, data: U) -> GlobalId where - State: GlobalDispatch + 'static, + State: 'static, + U: GlobalDispatch + Send + Sync + 'static, { self.handle.create_global::( I::interface(), diff --git a/wayland-server/src/global.rs b/wayland-server/src/global.rs index c6868a9e77b..5916de1d41d 100644 --- a/wayland-server/src/global.rs +++ b/wayland-server/src/global.rs @@ -15,12 +15,12 @@ pub(crate) struct GlobalData { unsafe impl Send for GlobalData {} unsafe impl Sync for GlobalData {} -impl + 'static> +impl + Send + Sync + 'static> GlobalHandler for GlobalData { fn can_view(&self, id: ClientId, data: &Arc, _: GlobalId) -> bool { let client = Client { id, data: data.clone() }; - >::can_view(client, &self.data) + self.data.can_view(&client) } fn bind( @@ -39,12 +39,11 @@ impl + let mut new_data = None; let mut protocol_error = None; - >::bind( + self.data.bind( data, &handle, &client, New::wrap(resource.clone()), - &self.data, &mut DataInit { store: &mut new_data, error: &mut protocol_error }, ); @@ -92,17 +91,17 @@ impl ObjectData for ProtocolErrorData { /// of associated user data. /// /// Its behavior is similar to the [`Dispatch`][crate::Dispatch] trait. -pub trait GlobalDispatch: Sized { +pub trait GlobalDispatch { /// Called when a client has bound this global. /// /// The return value of this function should contain user data to associate the object created by the /// client. fn bind( + &self, state: &mut State, handle: &DisplayHandle, client: &Client, resource: New, - global_data: &GlobalData, data_init: &mut DataInit<'_, State>, ); @@ -116,158 +115,7 @@ pub trait GlobalDispatch: Sized { /// which must only be used by XWayland. /// /// The default implementation allows all clients to see the global. - fn can_view(_client: Client, _global_data: &GlobalData) -> bool { + fn can_view(&self, _client: &Client) -> bool { true } } - -/* - * Dispatch delegation helpers - */ - -/// A helper macro which delegates a set of [`GlobalDispatch`] implementations for a resource to some other type which -/// provdes a generic [`GlobalDispatch`] implementation. -/// -/// Its usage is similar to the [`delegate_dispatch!()`] macro. -/// -/// [`delegate_dispatch!()`]: crate::delegate_dispatch!() -#[macro_export] -macro_rules! delegate_global_dispatch { - ($(@< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from:ty : [$interface: ty: $udata: ty] => $dispatch_to: ty) => { - impl$(< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $crate::GlobalDispatch<$interface, $udata> for $dispatch_from { - fn bind( - state: &mut Self, - dhandle: &$crate::DisplayHandle, - client: &$crate::Client, - resource: $crate::New<$interface>, - global_data: &$udata, - data_init: &mut $crate::DataInit<'_, Self>, - ) { - <$dispatch_to as $crate::GlobalDispatch<$interface, $udata, Self>>::bind(state, dhandle, client, resource, global_data, data_init) - } - - fn can_view(client: $crate::Client, global_data: &$udata) -> bool { - <$dispatch_to as $crate::GlobalDispatch<$interface, $udata, Self>>::can_view(client, global_data) - } - } - }; -} - -#[cfg(test)] -mod tests { - #[test] - fn smoke_test_dispatch_global_dispatch() { - use crate::{ - Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, delegate_dispatch, - protocol::wl_output, - }; - - #[allow(dead_code)] - struct DelegateToMe; - - impl Dispatch for DelegateToMe - where - D: Dispatch + AsMut, - { - fn request( - _state: &mut D, - _client: &Client, - _resource: &wl_output::WlOutput, - _request: wl_output::Request, - _data: &(), - _dhandle: &DisplayHandle, - _data_init: &mut DataInit<'_, D>, - ) { - } - } - impl GlobalDispatch for DelegateToMe - where - D: GlobalDispatch, - D: Dispatch, - D: AsMut, - { - fn bind( - _state: &mut D, - _handle: &DisplayHandle, - _client: &Client, - _resource: New, - _global_data: &(), - _data_init: &mut DataInit<'_, D>, - ) { - } - } - - #[allow(dead_code)] - struct ExampleApp { - delegate: DelegateToMe, - } - - delegate_dispatch!(ExampleApp: [wl_output::WlOutput: ()] => DelegateToMe); - delegate_global_dispatch!(ExampleApp: [wl_output::WlOutput: ()] => DelegateToMe); - - impl AsMut for ExampleApp { - fn as_mut(&mut self) -> &mut DelegateToMe { - &mut self.delegate - } - } - } - - #[test] - fn smoke_test_dispatch_global_dispatch_generics() { - use crate::{ - Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, delegate_dispatch, - protocol::wl_output, - }; - - #[allow(dead_code)] - struct DelegateToMe(A); - - impl Dispatch for DelegateToMe - where - A: 'static, - D: Dispatch + AsMut>, - { - fn request( - _state: &mut D, - _client: &Client, - _resource: &wl_output::WlOutput, - _request: wl_output::Request, - _data: &(), - _dhandle: &DisplayHandle, - _data_init: &mut DataInit<'_, D>, - ) { - } - } - impl GlobalDispatch for DelegateToMe - where - A: 'static, - D: GlobalDispatch, - D: Dispatch, - D: AsMut>, - { - fn bind( - _state: &mut D, - _handle: &DisplayHandle, - _client: &Client, - _resource: New, - _global_data: &(), - _data_init: &mut DataInit<'_, D>, - ) { - } - } - - #[allow(dead_code)] - struct ExampleApp { - delegate: DelegateToMe, - } - - delegate_dispatch!(@ ExampleApp: [wl_output::WlOutput: ()] => DelegateToMe); - delegate_global_dispatch!(@ ExampleApp: [wl_output::WlOutput: ()] => DelegateToMe); - - impl AsMut> for ExampleApp { - fn as_mut(&mut self) -> &mut DelegateToMe { - &mut self.delegate - } - } - } -} diff --git a/wayland-server/src/lib.rs b/wayland-server/src/lib.rs index 4cdd9bdb462..8445c576b63 100644 --- a/wayland-server/src/lib.rs +++ b/wayland-server/src/lib.rs @@ -24,10 +24,9 @@ //! `Dispatch` for every Wayland object `O` it needs to process events for. //! //! However, implementing all those traits on your own is a lot of (often uninteresting) work. To make this -//! easier a composition mechanism is provided using the [`delegate_dispatch!()`] macro. This way, another -//! library (such as Smithay) can provide generic [`Dispatch`] implementations that you can reuse on your -//! own app by delegating those objects to that provided implementation. See the documentation of those -//! traits and macro for details. +//! easier a another library (such as Smithay) can provide generic [`Dispatch`] implementations that you +//! for a user-data type it defines, so can reuse on your own app. See the documentation of those traits +//! for details. //! //! ## Globals //! diff --git a/wayland-tests/src/globals.rs b/wayland-tests/src/globals.rs index 773ff3da304..3d982131739 100644 --- a/wayland-tests/src/globals.rs +++ b/wayland-tests/src/globals.rs @@ -26,15 +26,18 @@ pub struct GlobalList { globals: Vec, } -impl Dispatch for GlobalList +#[derive(Debug)] +pub struct GlobalListData; + +impl Dispatch for GlobalListData where - D: Dispatch + AsMut, + D: AsMut, { fn event( + &self, handle: &mut D, _: &wl_registry::WlRegistry, event: wl_registry::Event, - _: &(), _: &Connection, _: &QueueHandle, ) { @@ -80,13 +83,18 @@ impl GlobalList { /// /// You can specify the requested interface as type parameter, and the version range. You /// also need to provide the user data value that will be set for the newly created object. - pub fn bind + 'static>( + pub fn bind( &self, qh: &QueueHandle, registry: &wl_registry::WlRegistry, version: RangeInclusive, user_data: U, - ) -> Result { + ) -> Result + where + I: Proxy + 'static, + U: Dispatch + Send + Sync + 'static, + D: 'static, + { for desc in &self.globals { if desc.interface != I::interface().name { continue; diff --git a/wayland-tests/src/lib.rs b/wayland-tests/src/lib.rs index c84ba4f9537..e748f0d711b 100644 --- a/wayland-tests/src/lib.rs +++ b/wayland-tests/src/lib.rs @@ -131,28 +131,19 @@ impl ways::backend::ClientData for DumbClientData { fn disconnected(&self, _: ways::backend::ClientId, _: ways::backend::DisconnectReason) {} } -#[macro_export] -macro_rules! client_ignore_impl { - ($handler:ty => [$($iface:ty),*]) => { - $( - $crate::wayc::delegate_noop!($handler: ignore $iface); - )* - } -} - #[macro_export] macro_rules! server_ignore_impl { ($handler:ty => [$($iface:ty),*]) => { $( - impl $crate::ways::Dispatch<$iface, ()> for $handler { + impl $crate::ways::Dispatch<$iface, $handler> for () { fn request( - _: &mut Self, + &self, + _: &mut $handler, _: &$crate::ways::Client, _: &$iface, _: <$iface as $crate::ways::Resource>::Request, - _: &(), _: &$crate::ways::DisplayHandle, - _: &mut $crate::ways::DataInit<'_, Self>, + _: &mut $crate::ways::DataInit<'_, $handler>, ) { } } @@ -164,15 +155,15 @@ macro_rules! server_ignore_impl { macro_rules! server_ignore_global_impl { ($handler:ty => [$($iface:ty),*]) => { $( - impl $crate::ways::GlobalDispatch<$iface, ()> for $handler { + impl $crate::ways::GlobalDispatch<$iface, $handler> for () { fn bind( - _: &mut Self, + &self, + _: &mut $handler, _: &$crate::ways::DisplayHandle, _: &$crate::ways::Client, new_id: $crate::ways::New<$iface>, - _: &(), - data_init: &mut $crate::ways::DataInit<'_, Self>, + data_init: &mut $crate::ways::DataInit<'_, $handler>, ) { data_init.init(new_id, ()); } diff --git a/wayland-tests/tests/attach_to_surface.rs b/wayland-tests/tests/attach_to_surface.rs index a7919d2efe7..b1775bc236c 100644 --- a/wayland-tests/tests/attach_to_surface.rs +++ b/wayland-tests/tests/attach_to_surface.rs @@ -3,8 +3,7 @@ use std::io::{Read, Seek, Write}; use std::os::unix::io::{AsFd, OwnedFd}; use wayland_tests::{ - TestServer, client_ignore_impl, globals, roundtrip, server_ignore_global_impl, - server_ignore_impl, wayc, ways, + TestServer, globals, roundtrip, server_ignore_global_impl, server_ignore_impl, wayc, ways, }; use wayc::protocol::wl_shm::Format; @@ -27,7 +26,8 @@ fn attach_null() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); // Initial sync roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -38,10 +38,10 @@ fn attach_null() { &client.event_queue.handle(), ®istry, 1..=1, - (), + wayc::NoopIgnore, ) .unwrap(); - let surface = compositor.create_surface(&client.event_queue.handle(), ()); + let surface = compositor.create_surface(&client.event_queue.handle(), wayc::NoopIgnore); surface.attach(None, 0, 0); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -66,7 +66,8 @@ fn attach_buffer() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); // Initial sync roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -77,15 +78,23 @@ fn attach_buffer() { &client.event_queue.handle(), ®istry, 1..=1, - (), + wayc::NoopIgnore, ) .unwrap(); let mut file = tempfile::tempfile().unwrap(); write!(file, "I like trains!").unwrap(); file.flush().unwrap(); - let pool = shm.create_pool(file.as_fd(), 42, &client.event_queue.handle(), ()); - let buffer = pool.create_buffer(0, 0, 0, 0, Format::Argb8888, &client.event_queue.handle(), ()); + let pool = shm.create_pool(file.as_fd(), 42, &client.event_queue.handle(), wayc::NoopIgnore); + let buffer = pool.create_buffer( + 0, + 0, + 0, + 0, + Format::Argb8888, + &client.event_queue.handle(), + wayc::NoopIgnore, + ); let compositor = client_ddata .globals @@ -93,10 +102,10 @@ fn attach_buffer() { &client.event_queue.handle(), ®istry, 1..=1, - (), + wayc::NoopIgnore, ) .unwrap(); - let surface = compositor.create_surface(&client.event_queue.handle(), ()); + let surface = compositor.create_surface(&client.event_queue.handle(), wayc::NoopIgnore); surface.attach(Some(&buffer), 0, 0); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -122,15 +131,15 @@ struct ServerHandler { fd_found: Option<(OwnedFd, Option)>, } -impl ways::Dispatch for ServerHandler { +impl ways::Dispatch for () { fn request( - _: &mut Self, + &self, + _: &mut ServerHandler, _: &ways::Client, _: &ways::protocol::wl_compositor::WlCompositor, request: ways::protocol::wl_compositor::Request, - _: &(), _: &ways::DisplayHandle, - init: &mut ways::DataInit<'_, Self>, + init: &mut ways::DataInit<'_, ServerHandler>, ) { if let ways::protocol::wl_compositor::Request::CreateSurface { id } = request { init.init(id, ()); @@ -140,15 +149,15 @@ impl ways::Dispatch for ServerH } } -impl ways::Dispatch for ServerHandler { +impl ways::Dispatch for () { fn request( - state: &mut Self, + &self, + state: &mut ServerHandler, _: &ways::Client, _: &ways::protocol::wl_surface::WlSurface, request: ways::protocol::wl_surface::Request, - _: &(), _: &ways::DisplayHandle, - _: &mut ways::DataInit<'_, Self>, + _: &mut ways::DataInit<'_, ServerHandler>, ) { if let ways::protocol::wl_surface::Request::Attach { buffer, x, y } = request { assert_eq!(x, 0); @@ -161,15 +170,15 @@ impl ways::Dispatch for ServerHandler } } -impl ways::Dispatch for ServerHandler { +impl ways::Dispatch for () { fn request( - state: &mut Self, + &self, + state: &mut ServerHandler, _: &ways::Client, _: &ways::protocol::wl_shm::WlShm, request: ways::protocol::wl_shm::Request, - _: &(), _: &ways::DisplayHandle, - init: &mut ways::DataInit<'_, Self>, + init: &mut ways::DataInit<'_, ServerHandler>, ) { if let ways::protocol::wl_shm::Request::CreatePool { fd, size, id } = request { assert_eq!(size, 42); @@ -182,15 +191,15 @@ impl ways::Dispatch for ServerHandler { } } -impl ways::Dispatch for ServerHandler { +impl ways::Dispatch for () { fn request( - state: &mut Self, + &self, + state: &mut ServerHandler, _: &ways::Client, _: &ways::protocol::wl_shm_pool::WlShmPool, request: ways::protocol::wl_shm_pool::Request, - _: &(), _: &ways::DisplayHandle, - init: &mut ways::DataInit<'_, Self>, + init: &mut ways::DataInit<'_, ServerHandler>, ) { if let ways::protocol::wl_shm_pool::Request::CreateBuffer { id, .. } = request { let fd_found = state.fd_found.as_mut().unwrap(); @@ -221,15 +230,3 @@ impl AsMut for ClientHandler { &mut self.globals } } - -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - -client_ignore_impl!(ClientHandler => [ - wayc::protocol::wl_compositor::WlCompositor, - wayc::protocol::wl_surface::WlSurface, - wayc::protocol::wl_shm::WlShm, - wayc::protocol::wl_shm_pool::WlShmPool, - wayc::protocol::wl_buffer::WlBuffer -]); diff --git a/wayland-tests/tests/backend_socket_out_limits.rs b/wayland-tests/tests/backend_socket_out_limits.rs index 347e43963d9..7e6c933b71c 100644 --- a/wayland-tests/tests/backend_socket_out_limits.rs +++ b/wayland-tests/tests/backend_socket_out_limits.rs @@ -6,8 +6,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use wayland_client::backend::ObjectData; use wayland_tests::{ - TestClient, TestServer, client_ignore_impl, globals, server_ignore_global_impl, - server_ignore_impl, wayc, ways, + TestClient, TestServer, globals, server_ignore_global_impl, server_ignore_impl, wayc, ways, }; // This test checks the behavior for @@ -44,7 +43,8 @@ fn backend_socket_out_limits() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new(), syncs_done: 0 }; - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); // Initial sync roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -55,7 +55,7 @@ fn backend_socket_out_limits() { &client.event_queue.handle(), ®istry, 1..=1, - (), + wayc::NoopIgnore, ) .unwrap(); @@ -64,7 +64,7 @@ fn backend_socket_out_limits() { let mut pools = Vec::new(); for _ in 0..TEST_FD_COUNT { let file = tempfile::tempfile().unwrap(); - let pool = shm.create_pool(file.as_fd(), 8, &client.event_queue.handle(), ()); + let pool = shm.create_pool(file.as_fd(), 8, &client.event_queue.handle(), wayc::NoopIgnore); files.push(file); pools.push(pool); } @@ -83,15 +83,15 @@ struct ServerHandler { received_fds: Vec, } -impl ways::Dispatch for ServerHandler { +impl ways::Dispatch for () { fn request( - state: &mut Self, + &self, + state: &mut ServerHandler, _: &ways::Client, _: &ways::protocol::wl_shm::WlShm, request: ways::protocol::wl_shm::Request, - _: &(), _: &ways::DisplayHandle, - init: &mut ways::DataInit<'_, Self>, + init: &mut ways::DataInit<'_, ServerHandler>, ) { if let ways::protocol::wl_shm::Request::CreatePool { fd, id, .. } = request { state.received_fds.push(fd); @@ -123,29 +123,19 @@ impl AsMut for ClientHandler { } } -impl wayc::Dispatch for ClientHandler { +impl wayc::Dispatch for () { fn event( - state: &mut Self, + &self, + state: &mut ClientHandler, _: &wayc::protocol::wl_callback::WlCallback, _: ::Event, - _: &(), _: &wayland_client::Connection, - _: &wayland_client::QueueHandle, + _: &wayland_client::QueueHandle, ) { state.syncs_done += 1; } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - -client_ignore_impl!(ClientHandler => [ - wayc::protocol::wl_compositor::WlCompositor, - wayc::protocol::wl_shm::WlShm, - wayc::protocol::wl_shm_pool::WlShmPool -]); - // Use a modified version of helpers::roundtrip here // which gracefully handles ErrorKind::WouldBlock from socket reads and flushes // to enable testing with the large amount of Wayland messages this test requires diff --git a/wayland-tests/tests/buffer_size.rs b/wayland-tests/tests/buffer_size.rs index ba546505a51..18b04595d10 100644 --- a/wayland-tests/tests/buffer_size.rs +++ b/wayland-tests/tests/buffer_size.rs @@ -13,7 +13,8 @@ fn buffer_size() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); let mut server_handler = ServerHandler::default(); @@ -25,11 +26,11 @@ fn buffer_size() { &client.event_queue.handle(), ®istry, 1..=1, - (), + wayc::NoopIgnore, ) .unwrap(); - let _pointer = seat.get_pointer(&client.event_queue.handle(), ()); + let _pointer = seat.get_pointer(&client.event_queue.handle(), wayc::NoopIgnore); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_handler).unwrap(); @@ -62,7 +63,8 @@ fn buffer_size_client() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); let mut server_handler = ServerHandler::default(); @@ -74,11 +76,11 @@ fn buffer_size_client() { &client.event_queue.handle(), ®istry, 1..=1, - (), + wayc::NoopIgnore, ) .unwrap(); - let pointer = seat.get_pointer(&client.event_queue.handle(), ()); + let pointer = seat.get_pointer(&client.event_queue.handle(), wayc::NoopIgnore); // Send too many Wayland events to buffer for default server buffer for _ in 0..10_000 { @@ -112,7 +114,8 @@ fn buffer_size_increase() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); let mut server_handler = ServerHandler::default(); @@ -124,11 +127,11 @@ fn buffer_size_increase() { &client.event_queue.handle(), ®istry, 1..=1, - (), + wayc::NoopIgnore, ) .unwrap(); - let _pointer = seat.get_pointer(&client.event_queue.handle(), ()); + let _pointer = seat.get_pointer(&client.event_queue.handle(), wayc::NoopIgnore); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_handler).unwrap(); @@ -155,16 +158,6 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - -client_ignore_impl!(ClientHandler => [ - wayc::protocol::wl_seat::WlSeat, - wayc::protocol::wl_pointer::WlPointer, - wayc::protocol::wl_keyboard::WlKeyboard -]); - /* * Server handler */ @@ -178,13 +171,13 @@ server_ignore_impl!(ServerHandler => [ways::protocol::wl_pointer::WlPointer]); server_ignore_global_impl!(ServerHandler => [ways::protocol::wl_seat::WlSeat]); -impl ways::Dispatch for ServerHandler { +impl ways::Dispatch for () { fn request( + &self, server_handler: &mut ServerHandler, _: &ways::Client, _: &ways::protocol::wl_seat::WlSeat, request: ways::protocol::wl_seat::Request, - _: &(), _: &ways::DisplayHandle, data_init: &mut ways::DataInit<'_, ServerHandler>, ) { diff --git a/wayland-tests/tests/client_bad_requests.rs b/wayland-tests/tests/client_bad_requests.rs index f3272c71bd6..a93fd797745 100644 --- a/wayland-tests/tests/client_bad_requests.rs +++ b/wayland-tests/tests/client_bad_requests.rs @@ -12,7 +12,8 @@ fn constructor_dead() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); @@ -22,13 +23,13 @@ fn constructor_dead() { &client.event_queue.handle(), ®istry, 1..=1, - (), + wayc::NoopIgnore, ) .unwrap(); seat.release(); - assert!(seat.get_pointer(&client.event_queue.handle(), ()).id().is_null()); + assert!(seat.get_pointer(&client.event_queue.handle(), wayc::NoopIgnore).id().is_null()); } #[test] @@ -42,7 +43,8 @@ fn send_constructor_wrong_type() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); @@ -52,7 +54,7 @@ fn send_constructor_wrong_type() { &client.event_queue.handle(), ®istry, 1..=1, - (), + wayc::NoopIgnore, ) .unwrap(); @@ -65,7 +67,7 @@ fn send_constructor_wrong_type() { client .event_queue .handle() - .make_data::(()), + .make_data::(wayc::NoopIgnore), ), ) .unwrap(); @@ -88,16 +90,6 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - -client_ignore_impl!(ClientHandler => [ - wayc::protocol::wl_seat::WlSeat, - wayc::protocol::wl_pointer::WlPointer, - wayc::protocol::wl_keyboard::WlKeyboard -]); - /* * Server handler */ diff --git a/wayland-tests/tests/client_connect_to_env.rs b/wayland-tests/tests/client_connect_to_env.rs index 5ed2444f80a..571b44da7ed 100644 --- a/wayland-tests/tests/client_connect_to_env.rs +++ b/wayland-tests/tests/client_connect_to_env.rs @@ -25,7 +25,7 @@ fn main() { // connect the client let mut client = TestClient::new_from_env(); let mut client_data = ClientHandler::new(); - client.display.get_registry(&client.event_queue.handle(), ()); + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); // setup server-side let client_stream = listening.accept().unwrap().unwrap(); @@ -64,7 +64,3 @@ impl AsMut for ClientHandler { &mut self.globals } } - -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); diff --git a/wayland-tests/tests/client_connect_to_socket.rs b/wayland-tests/tests/client_connect_to_socket.rs index 91bcae4f7b7..438f6b4c4c5 100644 --- a/wayland-tests/tests/client_connect_to_socket.rs +++ b/wayland-tests/tests/client_connect_to_socket.rs @@ -1,6 +1,6 @@ use wayland_tests::{ DumbClientData, TestClient, TestServer, globals, roundtrip, server_ignore_global_impl, - server_ignore_impl, wayc, ways, + server_ignore_impl, ways, }; use ways::protocol::wl_output::WlOutput as ServerOutput; @@ -24,7 +24,7 @@ fn main() { let mut client_data = ClientHandler::new(); - client.display.get_registry(&client.event_queue.handle(), ()); + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_data, &mut ServerData).unwrap(); // check that we connected to the right compositor @@ -67,7 +67,3 @@ impl AsMut for ClientHandler { &mut self.globals } } - -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); diff --git a/wayland-tests/tests/client_globals_helpers.rs b/wayland-tests/tests/client_globals_helpers.rs index 29673514ecf..573844f97ee 100644 --- a/wayland-tests/tests/client_globals_helpers.rs +++ b/wayland-tests/tests/client_globals_helpers.rs @@ -4,9 +4,7 @@ use std::sync::{ mpsc::sync_channel, }; -use wayland_tests::{ - TestServer, client_ignore_impl, server_ignore_global_impl, server_ignore_impl, wayc, ways, -}; +use wayland_tests::{TestServer, server_ignore_global_impl, server_ignore_impl, wayc, ways}; use ways::protocol::wl_compositor::WlCompositor as ServerCompositor; use ways::protocol::wl_output::WlOutput as ServerOutput; @@ -51,15 +49,27 @@ fn client_global_helpers_init() { // ensure bind works as expected // Too high version fails - assert!(globals.bind::(&queue.handle(), 5..=5, ()).is_err()); + assert!( + globals + .bind::(&queue.handle(), 5..=5, wayc::NoopIgnore) + .is_err() + ); // Missing global fails assert!( globals - .bind::(&queue.handle(), 1..=1, ()) + .bind::( + &queue.handle(), + 1..=1, + wayc::NoopIgnore + ) .is_err() ); // Compatible spec succeeds - assert!(globals.bind::(&queue.handle(), 1..=5, ()).is_ok()); + assert!( + globals + .bind::(&queue.handle(), 1..=5, wayc::NoopIgnore) + .is_ok() + ); // cleanup kill_switch.store(true, Ordering::Release); @@ -182,7 +192,7 @@ fn too_high_global_version() { let _ = globals.bind::( &queue.handle(), 1..=max_compositor_version + 1, - (), + wayc::NoopIgnore, ); } @@ -193,14 +203,14 @@ server_ignore_global_impl!(ServerHandler => [ServerCompositor, ServerShell, Serv struct ClientHandler(bool); -impl wayc::Dispatch for ClientHandler { +impl wayc::Dispatch for GlobalListContents { fn event( - state: &mut Self, + &self, + state: &mut ClientHandler, _: &wl_registry::WlRegistry, event: wl_registry::Event, - _: &GlobalListContents, _: &wayc::Connection, - _: &wayc::QueueHandle, + _: &wayc::QueueHandle, ) { if let wl_registry::Event::Global { name, interface, version } = event { assert_eq!(name, 3); @@ -215,8 +225,3 @@ impl wayc::Dispatch for ClientHandl } } } - -client_ignore_impl!(ClientHandler => [ - wl_compositor::WlCompositor, - wl_subcompositor::WlSubcompositor -]); diff --git a/wayland-tests/tests/client_proxies.rs b/wayland-tests/tests/client_proxies.rs index b28cef36a3e..6fd2efdd320 100644 --- a/wayland-tests/tests/client_proxies.rs +++ b/wayland-tests/tests/client_proxies.rs @@ -1,6 +1,5 @@ use wayland_tests::{ - TestServer, client_ignore_impl, globals, roundtrip, server_ignore_global_impl, - server_ignore_impl, wayc, ways, + TestServer, globals, roundtrip, server_ignore_global_impl, server_ignore_impl, wayc, ways, }; use ways::Resource; @@ -19,7 +18,8 @@ fn proxy_equals() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -63,7 +63,8 @@ fn proxy_user_data() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -108,7 +109,8 @@ fn dead_proxies() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -118,7 +120,7 @@ fn dead_proxies() { &client.event_queue.handle(), ®istry, 3..=3, - (), + wayc::NoopIgnore, ) .unwrap(); @@ -156,7 +158,8 @@ fn dead_object_argument() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -166,7 +169,7 @@ fn dead_object_argument() { &client.event_queue.handle(), ®istry, 3..=3, - (), + wayc::NoopIgnore, ) .unwrap(); let compositor = client_ddata @@ -191,29 +194,29 @@ struct ServerHandler { output: Option, } -impl ways::GlobalDispatch for ServerHandler { +impl ways::GlobalDispatch for () { fn bind( - state: &mut Self, + &self, + state: &mut ServerHandler, _: &ways::DisplayHandle, _: &ways::Client, output: ways::New, - _: &(), - data_init: &mut ways::DataInit<'_, Self>, + data_init: &mut ways::DataInit<'_, ServerHandler>, ) { let output = data_init.init(output, ()); state.output = Some(output); } } -impl ways::Dispatch for ServerHandler { +impl ways::Dispatch for () { fn request( - state: &mut Self, + &self, + state: &mut ServerHandler, _: &ways::Client, _: &ways::protocol::wl_compositor::WlCompositor, request: ways::protocol::wl_compositor::Request, - _: &(), dhandle: &ways::DisplayHandle, - data_init: &mut ways::DataInit<'_, Self>, + data_init: &mut ways::DataInit<'_, ServerHandler>, ) { if let ways::protocol::wl_compositor::Request::CreateSurface { id } = request { let surface = data_init.init(id, ()); @@ -250,30 +253,26 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - -impl wayc::Dispatch for ClientHandler { +impl wayc::Dispatch for usize { fn event( - _: &mut Self, + &self, + _: &mut ClientHandler, _: &wayc::protocol::wl_compositor::WlCompositor, _: wayc::protocol::wl_compositor::Event, - _: &usize, _: &wayc::Connection, - _: &wayc::QueueHandle, + _: &wayc::QueueHandle, ) { } } -impl wayc::Dispatch for ClientHandler { +impl wayc::Dispatch for () { fn event( - state: &mut Self, + &self, + state: &mut ClientHandler, _: &wayc::protocol::wl_surface::WlSurface, event: wayc::protocol::wl_surface::Event, - _: &(), conn: &wayc::Connection, - _: &wayc::QueueHandle, + _: &wayc::QueueHandle, ) { if let wayc::protocol::wl_surface::Event::Enter { output } = event { assert!(conn.get_object_data(output.id()).is_err()); @@ -283,7 +282,3 @@ impl wayc::Dispatch for ClientHandler } } } - -client_ignore_impl!(ClientHandler => [ - wayc::protocol::wl_output::WlOutput -]); diff --git a/wayland-tests/tests/destroyed_object.rs b/wayland-tests/tests/destroyed_object.rs index f7d071bd5a2..8c2d8ea0879 100644 --- a/wayland-tests/tests/destroyed_object.rs +++ b/wayland-tests/tests/destroyed_object.rs @@ -12,17 +12,23 @@ fn destroyed_object_in_arg() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::default(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); let qh = client.event_queue.handle(); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); let compositor = client_ddata .globals - .bind::(&qh, ®istry, 1..=1, ()) + .bind::( + &qh, + ®istry, + 1..=1, + wayc::Noop, + ) .unwrap(); - let surface = compositor.create_surface(&qh, ()); - let region = compositor.create_region(&qh, ()); + let surface = compositor.create_surface(&qh, wayc::NoopIgnore); + let region = compositor.create_region(&qh, wayc::NoopIgnore); region.destroy(); surface.set_input_region(Some(®ion)); @@ -31,15 +37,15 @@ fn destroyed_object_in_arg() { struct ServerHandler; -impl ways::Dispatch for ServerHandler { +impl ways::Dispatch for () { fn request( - _state: &mut Self, + &self, + _state: &mut ServerHandler, _: &ways::Client, _: &ways::protocol::wl_compositor::WlCompositor, request: ways::protocol::wl_compositor::Request, - _: &(), _: &ways::DisplayHandle, - data_init: &mut ways::DataInit<'_, Self>, + data_init: &mut ways::DataInit<'_, ServerHandler>, ) { match request { ways::protocol::wl_compositor::Request::CreateSurface { id } => { @@ -74,10 +80,3 @@ impl AsMut for ClientHandler { &mut self.globals } } - -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); -wayc::delegate_noop!(ClientHandler: wayc::protocol::wl_compositor::WlCompositor); -wayc::delegate_noop!(ClientHandler: ignore wayc::protocol::wl_surface::WlSurface); -wayc::delegate_noop!(ClientHandler: wayc::protocol::wl_region::WlRegion); diff --git a/wayland-tests/tests/destructors.rs b/wayland-tests/tests/destructors.rs index af0b9ddfb56..21d93943930 100644 --- a/wayland-tests/tests/destructors.rs +++ b/wayland-tests/tests/destructors.rs @@ -1,4 +1,4 @@ -use wayland_tests::{TestServer, client_ignore_impl, globals, roundtrip, wayc, ways}; +use wayland_tests::{TestServer, globals, roundtrip, wayc, ways}; use std::sync::{ Arc, @@ -17,7 +17,8 @@ fn resource_destructor_request() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -27,7 +28,7 @@ fn resource_destructor_request() { &client.event_queue.handle(), ®istry, 3..=3, - (), + wayc::NoopIgnore, ) .unwrap(); @@ -52,7 +53,8 @@ fn resource_destructor_cleanup() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -62,7 +64,7 @@ fn resource_destructor_cleanup() { &client.event_queue.handle(), ®istry, 3..=3, - (), + wayc::NoopIgnore, ) .unwrap(); @@ -90,7 +92,8 @@ fn client_destructor_cleanup() { server.add_client_with_data(Arc::new(DestructorClientData(destructor_called.clone()))); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -100,7 +103,7 @@ fn client_destructor_cleanup() { &client.event_queue.handle(), ®istry, 3..=3, - (), + wayc::NoopIgnore, ) .unwrap(); @@ -129,38 +132,38 @@ struct ServerHandler { struct ServerUData(Arc); -impl ways::GlobalDispatch for ServerHandler { +impl ways::GlobalDispatch for () { fn bind( - state: &mut Self, + &self, + state: &mut ServerHandler, _: &ways::DisplayHandle, _: &ways::Client, output: ways::New, - _: &(), - data_init: &mut ways::DataInit<'_, Self>, + data_init: &mut ways::DataInit<'_, ServerHandler>, ) { data_init.init(output, ServerUData(state.destructor_called.clone())); } } -impl ways::Dispatch for ServerHandler { +impl ways::Dispatch for ServerUData { fn request( - _: &mut Self, + &self, + _: &mut ServerHandler, _: &ways::Client, _: &ways::protocol::wl_output::WlOutput, _: ways::protocol::wl_output::Request, - _: &ServerUData, _: &ways::DisplayHandle, - _: &mut ways::DataInit<'_, Self>, + _: &mut ways::DataInit<'_, ServerHandler>, ) { } fn destroyed( - _: &mut Self, + &self, + _: &mut ServerHandler, _: ways::backend::ClientId, _resource: &ways::protocol::wl_output::WlOutput, - data: &ServerUData, ) { - data.0.store(true, Ordering::Release); + self.0.store(true, Ordering::Release); } } @@ -179,11 +182,3 @@ impl AsMut for ClientHandler { &mut self.globals } } - -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - -client_ignore_impl!(ClientHandler => [ - wayc::protocol::wl_output::WlOutput -]); diff --git a/wayland-tests/tests/display_ptr.rs b/wayland-tests/tests/display_ptr.rs index 9b3220dd394..fe2d230adb9 100644 --- a/wayland-tests/tests/display_ptr.rs +++ b/wayland-tests/tests/display_ptr.rs @@ -9,7 +9,8 @@ fn client_objectid_display_ptr() { let (_s_client, client) = server.add_client::(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); registry.id().display_ptr().unwrap(); } @@ -24,8 +25,4 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - struct ServerHandler; diff --git a/wayland-tests/tests/globals.rs b/wayland-tests/tests/globals.rs index ed6f84141d1..870344e1c5b 100644 --- a/wayland-tests/tests/globals.rs +++ b/wayland-tests/tests/globals.rs @@ -1,6 +1,5 @@ use wayland_tests::{ - TestServer, client_ignore_impl, globals, roundtrip, server_ignore_global_impl, - server_ignore_impl, wayc, ways, + TestServer, globals, roundtrip, server_ignore_global_impl, server_ignore_impl, wayc, ways, }; use ways::protocol::wl_compositor::WlCompositor as ServerCompositor; @@ -15,7 +14,7 @@ fn simple_global() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - client.display.get_registry(&client.event_queue.handle(), ()); + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); @@ -37,7 +36,7 @@ fn multi_versions() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - client.display.get_registry(&client.event_queue.handle(), ()); + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); @@ -59,7 +58,7 @@ fn dynamic_global() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - client.display.get_registry(&client.event_queue.handle(), ()); + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); assert!(client_ddata.globals.list().len() == 1); @@ -97,12 +96,13 @@ fn wrong_global() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); // instantiate a wrong global, this should kill the client // but currently does not fail on native_lib - registry.bind::(1, 1, &client.event_queue.handle(), ()); + registry.bind::(1, 1, &client.event_queue.handle(), wayc::NoopIgnore); assert!(roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).is_err()); } @@ -117,11 +117,12 @@ fn wrong_global_version() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); // instantiate a global with wrong version, this should kill the client - registry.bind::(1, 2, &client.event_queue.handle(), ()); + registry.bind::(1, 2, &client.event_queue.handle(), wayc::NoopIgnore); assert!(roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).is_err()); } @@ -136,11 +137,12 @@ fn invalid_global_version() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); // instantiate a global with version 0, which is invalid this should kill the client - registry.bind::(1, 0, &client.event_queue.handle(), ()); + registry.bind::(1, 0, &client.event_queue.handle(), wayc::NoopIgnore); assert!(roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).is_err()); } @@ -155,11 +157,12 @@ fn wrong_global_id() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); // instantiate a global with version 0, which is invalid this should kill the client - registry.bind::(3, 1, &client.event_queue.handle(), ()); + registry.bind::(3, 1, &client.event_queue.handle(), wayc::NoopIgnore); assert!(roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).is_err()); } @@ -174,7 +177,8 @@ fn two_step_binding() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); @@ -185,12 +189,17 @@ fn two_step_binding() { client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 1..=1, ()) + .bind::( + &client.event_queue.handle(), + ®istry, + 1..=1, + wayc::NoopIgnore, + ) .unwrap(); client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 1..=1, ()) + .bind::(&client.event_queue.handle(), ®istry, 1..=1, wayc::NoopIgnore) .unwrap(); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); @@ -210,13 +219,3 @@ impl AsMut for ClientHandler { &mut self.globals } } - -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - -client_ignore_impl!(ClientHandler => [ - wayc::protocol::wl_compositor::WlCompositor, - wayc::protocol::wl_shell::WlShell, - wayc::protocol::wl_output::WlOutput -]); diff --git a/wayland-tests/tests/protocol_errors.rs b/wayland-tests/tests/protocol_errors.rs index ab126cdff81..23cb6da90df 100644 --- a/wayland-tests/tests/protocol_errors.rs +++ b/wayland-tests/tests/protocol_errors.rs @@ -2,8 +2,7 @@ #![cfg(not(feature = "libwayland_client_1_23"))] use wayland_tests::{ - TestServer, client_ignore_impl, globals, roundtrip, server_ignore_global_impl, - server_ignore_impl, wayc, ways, + TestServer, globals, roundtrip, server_ignore_global_impl, server_ignore_impl, wayc, ways, }; use ways::Resource; @@ -19,7 +18,8 @@ fn client_receive_generic_error() { let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); @@ -30,7 +30,7 @@ fn client_receive_generic_error() { &client.event_queue.handle(), ®istry, 1..=1, - (), + wayc::NoopIgnore, ) .unwrap(); @@ -76,14 +76,6 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - -client_ignore_impl!(ClientHandler => [ - wayc::protocol::wl_compositor::WlCompositor -]); - struct ServerHandler; server_ignore_impl!(ServerHandler => [ diff --git a/wayland-tests/tests/server_clients.rs b/wayland-tests/tests/server_clients.rs index 700b87d1a12..09312bf4ab0 100644 --- a/wayland-tests/tests/server_clients.rs +++ b/wayland-tests/tests/server_clients.rs @@ -1,6 +1,4 @@ -use wayland_tests::{ - TestServer, client_ignore_impl, globals, roundtrip, server_ignore_impl, wayc, ways, -}; +use wayland_tests::{TestServer, globals, roundtrip, server_ignore_impl, wayc, ways}; use std::sync::{ Arc, @@ -26,7 +24,8 @@ fn client_user_data() { })); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -37,7 +36,7 @@ fn client_user_data() { &client.event_queue.handle(), ®istry, 1..=1, - (), + wayc::NoopIgnore, ) .unwrap(); @@ -55,7 +54,7 @@ fn client_user_data() { &client.event_queue.handle(), ®istry, 1..=1, - (), + wayc::NoopIgnore, ) .unwrap(); @@ -113,15 +112,6 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - -client_ignore_impl!(ClientHandler => [ - wayc::protocol::wl_output::WlOutput, - wayc::protocol::wl_compositor::WlCompositor -]); - struct ServerHandler; struct MyClientData { @@ -139,28 +129,28 @@ server_ignore_impl!(ServerHandler => [ ways::protocol::wl_compositor::WlCompositor ]); -impl ways::GlobalDispatch for ServerHandler { +impl ways::GlobalDispatch for () { fn bind( - _: &mut Self, + &self, + _: &mut ServerHandler, _: &ways::DisplayHandle, client: &ways::Client, resource: ways::New, - _: &(), - data_init: &mut ways::DataInit<'_, Self>, + data_init: &mut ways::DataInit<'_, ServerHandler>, ) { data_init.init(resource, ()); client.get_data::().unwrap().has_output.store(true, Ordering::SeqCst); } } -impl ways::GlobalDispatch for ServerHandler { +impl ways::GlobalDispatch for () { fn bind( - _: &mut Self, + &self, + _: &mut ServerHandler, _: &ways::DisplayHandle, client: &ways::Client, resource: ways::New, - _: &(), - data_init: &mut ways::DataInit<'_, Self>, + data_init: &mut ways::DataInit<'_, ServerHandler>, ) { data_init.init(resource, ()); client.get_data::().unwrap().has_compositor.store(true, Ordering::SeqCst) diff --git a/wayland-tests/tests/server_created_object.rs b/wayland-tests/tests/server_created_object.rs index 74cb3576d4c..036f7381e85 100644 --- a/wayland-tests/tests/server_created_object.rs +++ b/wayland-tests/tests/server_created_object.rs @@ -1,6 +1,5 @@ use wayland_tests::{ - TestServer, client_ignore_impl, globals, roundtrip, server_ignore_global_impl, - server_ignore_impl, wayc, ways, + TestServer, globals, roundtrip, server_ignore_global_impl, server_ignore_impl, wayc, ways, }; use ways::Resource; @@ -27,17 +26,18 @@ fn data_offer() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); let seat = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 1..=1, ()) + .bind::(&client.event_queue.handle(), ®istry, 1..=1, wayc::NoopIgnore) .unwrap(); let ddmgr = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 3..=3, ()) + .bind::(&client.event_queue.handle(), ®istry, 3..=3, wayc::NoopIgnore) .unwrap(); ddmgr.get_data_device(&seat, &client.event_queue.handle(), ()); @@ -73,17 +73,18 @@ fn server_id_reuse() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); let seat = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 1..=1, ()) + .bind::(&client.event_queue.handle(), ®istry, 1..=1, wayc::NoopIgnore) .unwrap(); let ddmgr = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 3..=3, ()) + .bind::(&client.event_queue.handle(), ®istry, 3..=3, wayc::NoopIgnore) .unwrap(); ddmgr.get_data_device(&seat, &client.event_queue.handle(), ()); @@ -154,17 +155,18 @@ fn server_created_race() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); let seat = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 1..=1, ()) + .bind::(&client.event_queue.handle(), ®istry, 1..=1, wayc::NoopIgnore) .unwrap(); let ddmgr = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 3..=3, ()) + .bind::(&client.event_queue.handle(), ®istry, 3..=3, wayc::NoopIgnore) .unwrap(); ddmgr.get_data_device(&seat, &client.event_queue.handle(), ()); @@ -217,17 +219,18 @@ fn creation_destruction_race() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); let seat = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 1..=1, ()) + .bind::(&client.event_queue.handle(), ®istry, 1..=1, wayc::NoopIgnore) .unwrap(); let ddmgr = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 3..=3, ()) + .bind::(&client.event_queue.handle(), ®istry, 3..=3, wayc::NoopIgnore) .unwrap(); // client creates two data devices @@ -288,17 +291,18 @@ fn creation_destruction_queue_dispatch_race() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); let seat = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 1..=1, ()) + .bind::(&client.event_queue.handle(), ®istry, 1..=1, wayc::NoopIgnore) .unwrap(); let ddmgr = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 3..=3, ()) + .bind::(&client.event_queue.handle(), ®istry, 3..=3, wayc::NoopIgnore) .unwrap(); let client_dd = ddmgr.get_data_device(&seat, &client.event_queue.handle(), ()); @@ -360,22 +364,14 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); -client_ignore_impl!(ClientHandler => [ - ClientSeat, - ClientDDMgr -]); - -impl wayc::Dispatch for ClientHandler { +impl wayc::Dispatch for () { fn event( - state: &mut Self, + &self, + state: &mut ClientHandler, data_device: &wayc::protocol::wl_data_device::WlDataDevice, event: wayc::protocol::wl_data_device::Event, - _: &(), conn: &wayc::Connection, - _: &wayc::QueueHandle, + _: &wayc::QueueHandle, ) { if conn.object_info(data_device.id()).is_err() { state.received_dead = true; @@ -393,14 +389,14 @@ impl wayc::Dispatch for Client ]); } -impl wayc::Dispatch for ClientHandler { +impl wayc::Dispatch for () { fn event( - state: &mut Self, + &self, + state: &mut ClientHandler, _: &ClientDO, event: wayc::protocol::wl_data_offer::Event, - _: &(), _: &wayc::Connection, - _: &wayc::QueueHandle, + _: &wayc::QueueHandle, ) { match event { wayc::protocol::wl_data_offer::Event::Offer { mime_type } => { @@ -426,15 +422,15 @@ server_ignore_global_impl!(ServerHandler => [ ServerDDMgr ]); -impl ways::Dispatch for ServerHandler { +impl ways::Dispatch for () { fn request( - state: &mut Self, + &self, + state: &mut ServerHandler, _: &ways::Client, _: &ServerDDMgr, request: SDDMReq, - _: &(), _: &ways::DisplayHandle, - data_init: &mut ways::DataInit<'_, Self>, + data_init: &mut ways::DataInit<'_, ServerHandler>, ) { match request { SDDMReq::GetDataDevice { id, .. } => { diff --git a/wayland-tests/tests/server_global_filter.rs b/wayland-tests/tests/server_global_filter.rs index cf26cb389be..a6fed559c63 100644 --- a/wayland-tests/tests/server_global_filter.rs +++ b/wayland-tests/tests/server_global_filter.rs @@ -1,6 +1,4 @@ -use wayland_tests::{ - TestServer, client_ignore_impl, globals, roundtrip, server_ignore_impl, wayc, ways, -}; +use wayland_tests::{TestServer, globals, roundtrip, server_ignore_impl, wayc, ways}; use ways::protocol::{wl_compositor, wl_output, wl_shm}; @@ -25,7 +23,7 @@ fn global_filter() { let (_, mut client) = server.add_client_with_data(Arc::new(MyClientData { privileged: false })); let mut client_ddata = ClientHandler::new(); - client.display.get_registry(&client.event_queue.handle(), ()); + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -35,7 +33,7 @@ fn global_filter() { server.add_client_with_data(Arc::new(MyClientData { privileged: true })); let mut priv_client_ddata = ClientHandler::new(); - priv_client.display.get_registry(&priv_client.event_queue.handle(), ()); + priv_client.display.get_registry(&priv_client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut priv_client, &mut server, &mut priv_client_ddata, &mut server_ddata).unwrap(); @@ -76,22 +74,25 @@ fn global_filter_try_force() { // privileged client can bind it - let priv_registry = priv_client.display.get_registry(&priv_client.event_queue.handle(), ()); + let priv_registry = priv_client + .display + .get_registry(&priv_client.event_queue.handle(), globals::GlobalListData); priv_registry.bind::( 1, 1, &priv_client.event_queue.handle(), - (), + wayc::NoopIgnore, ); roundtrip(&mut priv_client, &mut server, &mut priv_client_ddata, &mut server_ddata).unwrap(); // unprivileged client cannot - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); registry.bind::( 1, 1, &client.event_queue.handle(), - (), + wayc::NoopIgnore, ); assert!(roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).is_err()); @@ -113,65 +114,47 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - -client_ignore_impl!(ClientHandler => [ - wayc::protocol::wl_compositor::WlCompositor, - wayc::protocol::wl_shm::WlShm, - wayc::protocol::wl_output::WlOutput -]); - struct ServerHandler; -impl ways::GlobalDispatch for ServerHandler { +impl ways::GlobalDispatch for () { fn bind( - _: &mut Self, + &self, + _: &mut ServerHandler, _: &ways::DisplayHandle, _: &ways::Client, resource: ways::New, - _: &(), - data_init: &mut ways::DataInit<'_, Self>, + data_init: &mut ways::DataInit<'_, ServerHandler>, ) { data_init.init(resource, ()); } - - fn can_view(_: ways::Client, _: &()) -> bool { - true - } } -impl ways::GlobalDispatch for ServerHandler { +impl ways::GlobalDispatch for () { fn bind( - _: &mut Self, + &self, + _: &mut ServerHandler, _: &ways::DisplayHandle, _: &ways::Client, resource: ways::New, - _: &(), - data_init: &mut ways::DataInit<'_, Self>, + data_init: &mut ways::DataInit<'_, ServerHandler>, ) { data_init.init(resource, ()); } - - fn can_view(_: ways::Client, _: &()) -> bool { - true - } } -impl ways::GlobalDispatch for ServerHandler { +impl ways::GlobalDispatch for () { fn bind( - _: &mut Self, + &self, + _: &mut ServerHandler, _: &ways::DisplayHandle, _: &ways::Client, resource: ways::New, - _: &(), - data_init: &mut ways::DataInit<'_, Self>, + data_init: &mut ways::DataInit<'_, ServerHandler>, ) { data_init.init(resource, ()); } - fn can_view(client: ways::Client, _: &()) -> bool { + fn can_view(&self, client: &ways::Client) -> bool { client.get_data::().unwrap().privileged } } diff --git a/wayland-tests/tests/server_global_post_error.rs b/wayland-tests/tests/server_global_post_error.rs index 0be48ddf98a..7eaa7fb207a 100644 --- a/wayland-tests/tests/server_global_post_error.rs +++ b/wayland-tests/tests/server_global_post_error.rs @@ -1,6 +1,6 @@ -use wayland_tests::{TestServer, client_ignore_impl, globals, roundtrip, wayc, ways}; +use wayland_tests::{TestServer, globals, roundtrip, wayc, ways}; -use wayc::{Proxy, protocol::wl_output::WlOutput as ClientOutput}; +use wayc::Proxy; #[test] fn global_init_post_error() { @@ -14,7 +14,8 @@ fn global_init_post_error() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -25,7 +26,7 @@ fn global_init_post_error() { &client.event_queue.handle(), ®istry, 3..=3, - (), + wayc::NoopIgnore, ) .unwrap(); @@ -57,36 +58,30 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - -client_ignore_impl!(ClientHandler => [ClientOutput]); - struct ServerHandler; -impl ways::GlobalDispatch for ServerHandler { +impl ways::GlobalDispatch for () { fn bind( - _state: &mut Self, + &self, + _state: &mut ServerHandler, _handle: &ways::DisplayHandle, _client: &ways::Client, resource: ways::New, - _global_data: &(), - data_init: &mut ways::DataInit<'_, Self>, + data_init: &mut ways::DataInit<'_, ServerHandler>, ) { data_init.post_error(resource, 11u32, "Server posts error when global is created"); } } -impl ways::Dispatch for ServerHandler { +impl ways::Dispatch for () { fn request( - _state: &mut Self, + &self, + _state: &mut ServerHandler, _client: &ways::Client, _resource: &ways::protocol::wl_output::WlOutput, _request: ::Request, - _data: &(), _dhandle: &ways::DisplayHandle, - _data_init: &mut ways::DataInit<'_, Self>, + _data_init: &mut ways::DataInit<'_, ServerHandler>, ) { unreachable!() } diff --git a/wayland-tests/tests/server_resources.rs b/wayland-tests/tests/server_resources.rs index 5c0d09777d5..655caedac12 100644 --- a/wayland-tests/tests/server_resources.rs +++ b/wayland-tests/tests/server_resources.rs @@ -1,12 +1,10 @@ -use wayland_tests::{TestServer, client_ignore_impl, globals, roundtrip, wayc, ways}; +use wayland_tests::{TestServer, globals, roundtrip, wayc, ways}; use ways::{ Resource, protocol::{wl_compositor, wl_output}, }; -use wayc::protocol::wl_output::WlOutput as ClientOutput; - #[test] fn resource_equals() { let mut server = TestServer::new(); @@ -19,7 +17,8 @@ fn resource_equals() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -30,7 +29,7 @@ fn resource_equals() { &client.event_queue.handle(), ®istry, 3..=3, - (), + wayc::NoopIgnore, ) .unwrap(); client_ddata @@ -39,7 +38,7 @@ fn resource_equals() { &client.event_queue.handle(), ®istry, 3..=3, - (), + wayc::NoopIgnore, ) .unwrap(); @@ -66,7 +65,8 @@ fn resource_user_data() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -77,7 +77,7 @@ fn resource_user_data() { &client.event_queue.handle(), ®istry, 3..=3, - (), + wayc::NoopIgnore, ) .unwrap(); client_ddata @@ -86,7 +86,7 @@ fn resource_user_data() { &client.event_queue.handle(), ®istry, 3..=3, - (), + wayc::NoopIgnore, ) .unwrap(); @@ -110,7 +110,8 @@ fn dead_resources() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -121,7 +122,7 @@ fn dead_resources() { &client.event_queue.handle(), ®istry, 3..=3, - (), + wayc::NoopIgnore, ) .unwrap(); client_ddata @@ -130,7 +131,7 @@ fn dead_resources() { &client.event_queue.handle(), ®istry, 3..=3, - (), + wayc::NoopIgnore, ) .unwrap(); @@ -162,7 +163,8 @@ fn get_resource() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -173,7 +175,7 @@ fn get_resource() { &client.event_queue.handle(), ®istry, 3..=3, - (), + wayc::NoopIgnore, ) .unwrap(); @@ -214,24 +216,18 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - -client_ignore_impl!(ClientHandler => [ClientOutput]); - struct ServerHandler { outputs: Vec, } -impl ways::GlobalDispatch for ServerHandler { +impl ways::GlobalDispatch for () { fn bind( - state: &mut Self, + &self, + state: &mut ServerHandler, _: &ways::DisplayHandle, _: &ways::Client, output: ways::New, - _: &(), - data_init: &mut ways::DataInit<'_, Self>, + data_init: &mut ways::DataInit<'_, ServerHandler>, ) { let output = data_init.init(output, UData(1000 + state.outputs.len())); state.outputs.push(output); @@ -240,15 +236,15 @@ impl ways::GlobalDispatch for ServerHandler { struct UData(usize); -impl ways::Dispatch for ServerHandler { +impl ways::Dispatch for UData { fn request( - _: &mut Self, + &self, + _: &mut ServerHandler, _: &ways::Client, _: &wl_output::WlOutput, _: wl_output::Request, - _: &UData, _: &ways::DisplayHandle, - _: &mut ways::DataInit<'_, Self>, + _: &mut ways::DataInit<'_, ServerHandler>, ) { } } diff --git a/wayland-tests/tests/xdg_shell_ping.rs b/wayland-tests/tests/xdg_shell_ping.rs index 2c7f91a0bee..e3e4f9e5a2c 100644 --- a/wayland-tests/tests/xdg_shell_ping.rs +++ b/wayland-tests/tests/xdg_shell_ping.rs @@ -14,7 +14,8 @@ fn xdg_ping() { let (_, mut client) = server.add_client(); let mut client_ddata = ClientHandler::new(); - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let registry = + client.display.get_registry(&client.event_queue.handle(), globals::GlobalListData); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -38,29 +39,29 @@ struct ServerHandler { received_pong: bool, } -impl ways::GlobalDispatch for ServerHandler { +impl ways::GlobalDispatch for () { fn bind( - _: &mut Self, + &self, + _: &mut ServerHandler, _: &ways::DisplayHandle, _: &ways::Client, resource: ways::New, - _: &(), - data_init: &mut ways::DataInit<'_, Self>, + data_init: &mut ways::DataInit<'_, ServerHandler>, ) { let wm_base = data_init.init(resource, ()); wm_base.ping(42); } } -impl ways::Dispatch for ServerHandler { +impl ways::Dispatch for () { fn request( - state: &mut Self, + &self, + state: &mut ServerHandler, _: &ways::Client, _: &xs_server::xdg_wm_base::XdgWmBase, request: xs_server::xdg_wm_base::Request, - _: &(), _: &ways::DisplayHandle, - _: &mut ways::DataInit<'_, Self>, + _: &mut ways::DataInit<'_, ServerHandler>, ) { match request { xs_server::xdg_wm_base::Request::Pong { serial } => { @@ -88,18 +89,14 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - -impl wayc::Dispatch for ClientHandler { +impl wayc::Dispatch for () { fn event( - _: &mut Self, + &self, + _: &mut ClientHandler, wm_base: &xs_client::xdg_wm_base::XdgWmBase, event: xs_client::xdg_wm_base::Event, - _: &(), _: &wayc::Connection, - _: &wayc::QueueHandle, + _: &wayc::QueueHandle, ) { match event { xs_client::xdg_wm_base::Event::Ping { serial } => wm_base.pong(serial),