From d3b610476d0a9eedc19b2b798c8ad35edc7c8e65 Mon Sep 17 00:00:00 2001 From: PolyMeilex Date: Thu, 7 Mar 2024 22:04:45 +0100 Subject: [PATCH] Remove delegate macros --- wayland-client/CHANGELOG.md | 1 + wayland-client/src/event_queue.rs | 154 +----------------- wayland-server/CHANGELOG.md | 1 + wayland-server/src/dispatch.rs | 77 --------- wayland-server/src/global.rs | 147 ----------------- wayland-tests/tests/attach_to_surface.rs | 30 ++-- wayland-tests/tests/client_bad_requests.rs | 33 ++-- wayland-tests/tests/client_connect_to_env.rs | 12 +- .../tests/client_connect_to_socket.rs | 16 +- wayland-tests/tests/client_proxies.rs | 46 ++---- wayland-tests/tests/destructors.rs | 44 ++--- wayland-tests/tests/globals.rs | 75 +++++---- wayland-tests/tests/helpers/globals.rs | 36 ++-- wayland-tests/tests/protocol_errors.rs | 16 +- wayland-tests/tests/server_clients.rs | 23 +-- wayland-tests/tests/server_created_object.rs | 57 +++---- wayland-tests/tests/server_global_filter.rs | 29 ++-- .../tests/server_global_post_error.rs | 22 +-- wayland-tests/tests/server_resources.rs | 78 ++------- wayland-tests/tests/xdg_shell_ping.rs | 22 +-- 20 files changed, 184 insertions(+), 735 deletions(-) diff --git a/wayland-client/CHANGELOG.md b/wayland-client/CHANGELOG.md index 67bb330a895..bb408e76f85 100644 --- a/wayland-client/CHANGELOG.md +++ b/wayland-client/CHANGELOG.md @@ -6,6 +6,7 @@ - `QueueHandle::make_data` now accepts additional `DelegateTo` generic, therefore allowing users to dispatch events to types different than main `State` +- `delegate_dispatch` Removed in favour of `DelegateTo` generic on `QueueHandle::make_data` ## 0.31.7 -- 2024-10-23 diff --git a/wayland-client/src/event_queue.rs b/wayland-client/src/event_queue.rs index d8be7d886c1..b499b39c2e4 100644 --- a/wayland-client/src/event_queue.rs +++ b/wayland-client/src/event_queue.rs @@ -727,156 +727,4 @@ impl std::fmt::Debug fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("QueueProxyData").field("udata", &self.udata).finish() } -} - -/* - * Dispatch delegation helpers - */ - -/// A helper macro which delegates a set of [`Dispatch`] implementations for proxies to some other type which -/// provides a generic [`Dispatch`] implementation. -/// -/// This macro allows more easily delegating smaller parts of the protocol an application may wish to handle -/// in a modular fashion. -/// -/// # Usage -/// -/// For example, say you want to delegate events for [`WlRegistry`][crate::protocol::wl_registry::WlRegistry] -/// to the struct `DelegateToMe` for the [`Dispatch`] documentatione example. -/// -/// ``` -/// use wayland_client::{delegate_dispatch, protocol::wl_registry}; -/// # -/// # use wayland_client::Dispatch; -/// # -/// # struct DelegateToMe; -/// # struct MyUserData; -/// # -/// # impl 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::(); -/// ``` -#[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) - } - - 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) - } - } - }; -} - -/// 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!(); - } - } - }; - - ($(@< $( $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, - ) { - } - } - }; -} +} \ No newline at end of file diff --git a/wayland-server/CHANGELOG.md b/wayland-server/CHANGELOG.md index 13fe4ccfef9..6687158ac03 100644 --- a/wayland-server/CHANGELOG.md +++ b/wayland-server/CHANGELOG.md @@ -4,6 +4,7 @@ #### Breaking changes - Added `Resource::delegated_data<_, DelegatedTo>` for accessing user data of delegated objects +- `delegate_dispatch` and `delegate_global_dispatch` Removed in favour of `DataInit::init_delegated` and `DisplayHandle::create_delegated_global` #### Additions - Added a way to create delegated objects, globals and resources (a way to dispatch events to types different than the main `State`) diff --git a/wayland-server/src/dispatch.rs b/wayland-server/src/dispatch.rs index 15438184be2..d2dd14e75bc 100644 --- a/wayland-server/src/dispatch.rs +++ b/wayland-server/src/dispatch.rs @@ -415,80 +415,3 @@ pub(crate) fn on_destroyed( >::destroyed(data, client_id, &resource, udata) } - -/// 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/global.rs b/wayland-server/src/global.rs index 0e52152195b..2f9d3670590 100644 --- a/wayland-server/src/global.rs +++ b/wayland-server/src/global.rs @@ -124,150 +124,3 @@ pub trait GlobalDispatch: Sized { 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::{ - delegate_dispatch, protocol::wl_output, Client, DataInit, Dispatch, DisplayHandle, - GlobalDispatch, New, - }; - - 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>, - ) { - } - } - - 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::{ - delegate_dispatch, protocol::wl_output, Client, DataInit, Dispatch, DisplayHandle, - GlobalDispatch, New, - }; - - 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>, - ) { - } - } - - 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-tests/tests/attach_to_surface.rs b/wayland-tests/tests/attach_to_surface.rs index 664f5c52c5c..5ab9e2deaf3 100644 --- a/wayland-tests/tests/attach_to_surface.rs +++ b/wayland-tests/tests/attach_to_surface.rs @@ -7,7 +7,7 @@ use std::os::unix::io::{AsFd, OwnedFd}; #[macro_use] mod helpers; -use helpers::{globals, roundtrip, wayc, ways, TestServer}; +use helpers::{globals, roundtrip, wayc, ways, TestClient, TestServer}; use wayc::protocol::wl_shm::Format; @@ -27,9 +27,7 @@ fn attach_null() { // Client setup // 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 mut client_ddata = ClientHandler::new(&client); // Initial sync roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -38,7 +36,6 @@ fn attach_null() { .globals .bind::( &client.event_queue.handle(), - ®istry, 1..2, (), ) @@ -66,21 +63,14 @@ fn attach_buffer() { // Client setup // 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 mut client_ddata = ClientHandler::new(&client); // Initial sync roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); let shm = client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 1..2, - (), - ) + .bind::(&client.event_queue.handle(), 1..2, ()) .unwrap(); let mut file = tempfile::tempfile().unwrap(); @@ -93,7 +83,6 @@ fn attach_buffer() { .globals .bind::( &client.event_queue.handle(), - ®istry, 1..2, (), ) @@ -218,16 +207,19 @@ struct ClientHandler { globals: globals::GlobalList, } +impl ClientHandler { + fn new(client: &TestClient) -> ClientHandler { + let globals = globals::GlobalList::new(&client.display, &client.event_queue.handle()); + ClientHandler { globals } + } +} + impl AsMut for ClientHandler { fn as_mut(&mut self) -> &mut globals::GlobalList { &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, diff --git a/wayland-tests/tests/client_bad_requests.rs b/wayland-tests/tests/client_bad_requests.rs index e16f4bbb77b..ec94b0f4980 100644 --- a/wayland-tests/tests/client_bad_requests.rs +++ b/wayland-tests/tests/client_bad_requests.rs @@ -13,20 +13,13 @@ fn constructor_dead() { .create_global::(1, ()); 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 mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); let seat = client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 1..2, - (), - ) + .bind::(&client.event_queue.handle(), 1..2, ()) .unwrap(); seat.release(); @@ -43,20 +36,13 @@ fn send_constructor_wrong_type() { .create_global::(1, ()); 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 mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); let seat = client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 1..2, - (), - ) + .bind::(&client.event_queue.handle(), 1..2, ()) .unwrap(); let id = client @@ -85,16 +71,19 @@ struct ClientHandler { globals: globals::GlobalList, } +impl ClientHandler { + fn new(client: &TestClient) -> ClientHandler { + let globals = globals::GlobalList::new(&client.display, &client.event_queue.handle()); + ClientHandler { globals } + } +} + impl AsMut for ClientHandler { fn as_mut(&mut self) -> &mut globals::GlobalList { &mut self.globals } } -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, diff --git a/wayland-tests/tests/client_connect_to_env.rs b/wayland-tests/tests/client_connect_to_env.rs index c2c8dff4fc3..55f3c01495a 100644 --- a/wayland-tests/tests/client_connect_to_env.rs +++ b/wayland-tests/tests/client_connect_to_env.rs @@ -22,8 +22,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(), ()); + let mut client_data = ClientHandler::new(&client); // setup server-side let client_stream = listening.accept().unwrap().unwrap(); @@ -52,8 +51,9 @@ struct ClientHandler { } impl ClientHandler { - fn new() -> ClientHandler { - ClientHandler { globals: Default::default() } + fn new(client: &TestClient) -> ClientHandler { + let globals = globals::GlobalList::new(&client.display, &client.event_queue.handle()); + ClientHandler { globals } } } @@ -62,7 +62,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 6b298b664cd..caf4a142aeb 100644 --- a/wayland-tests/tests/client_connect_to_socket.rs +++ b/wayland-tests/tests/client_connect_to_socket.rs @@ -1,7 +1,7 @@ #[macro_use] mod helpers; -use helpers::{globals, roundtrip, wayc, ways, DumbClientData, TestClient, TestServer}; +use helpers::{globals, roundtrip, ways, DumbClientData, TestClient, TestServer}; use ways::protocol::wl_output::WlOutput as ServerOutput; @@ -20,10 +20,7 @@ fn main() { ::std::env::set_var("WAYLAND_SOCKET", format!("{}", fd2)); let mut client = TestClient::new_from_env(); - - let mut client_data = ClientHandler::new(); - - client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_data = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_data, &mut ServerData).unwrap(); // check that we connected to the right compositor @@ -56,8 +53,9 @@ struct ClientHandler { } impl ClientHandler { - fn new() -> ClientHandler { - ClientHandler { globals: Default::default() } + fn new(client: &TestClient) -> ClientHandler { + let globals = globals::GlobalList::new(&client.display, &client.event_queue.handle()); + ClientHandler { globals } } } @@ -66,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_proxies.rs b/wayland-tests/tests/client_proxies.rs index 24ad421aa07..34bee64fda1 100644 --- a/wayland-tests/tests/client_proxies.rs +++ b/wayland-tests/tests/client_proxies.rs @@ -1,7 +1,7 @@ #[macro_use] mod helpers; -use helpers::{globals, roundtrip, wayc, ways, TestServer}; +use helpers::{globals, roundtrip, wayc, ways, TestClient, TestServer}; use ways::Resource; @@ -17,9 +17,7 @@ fn proxy_equals() { let mut server_ddata = ServerHandler { output: None }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -27,7 +25,6 @@ fn proxy_equals() { .globals .bind::( &client.event_queue.handle(), - ®istry, 1..2, 0, ) @@ -37,7 +34,6 @@ fn proxy_equals() { .globals .bind::( &client.event_queue.handle(), - ®istry, 1..2, 0, ) @@ -61,9 +57,7 @@ fn proxy_user_data() { let mut server_ddata = ServerHandler { output: None }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -71,7 +65,6 @@ fn proxy_user_data() { .globals .bind::( &client.event_queue.handle(), - ®istry, 1..2, 0xDEADBEEFusize, ) @@ -81,7 +74,6 @@ fn proxy_user_data() { .globals .bind::( &client.event_queue.handle(), - ®istry, 1..2, 0xBADC0FFEusize, ) @@ -106,20 +98,13 @@ fn dead_proxies() { let mut server_ddata = ServerHandler { output: None }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); let output = client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 3..4, - (), - ) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -154,26 +139,18 @@ fn dead_object_argument() { let mut server_ddata = ServerHandler { output: None }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); let output = client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 3..4, - (), - ) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); let compositor = client_ddata .globals .bind::( &client.event_queue.handle(), - ®istry, 1..2, 0, ) @@ -239,8 +216,9 @@ struct ClientHandler { } impl ClientHandler { - fn new() -> ClientHandler { - ClientHandler { globals: Default::default(), entered: false } + fn new(client: &TestClient) -> ClientHandler { + let globals = globals::GlobalList::new(&client.display, &client.event_queue.handle()); + ClientHandler { globals, entered: false } } } @@ -250,10 +228,6 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - impl wayc::Dispatch for ClientHandler { fn event( _: &mut Self, diff --git a/wayland-tests/tests/destructors.rs b/wayland-tests/tests/destructors.rs index ecac0f4142f..78a4f256e2e 100644 --- a/wayland-tests/tests/destructors.rs +++ b/wayland-tests/tests/destructors.rs @@ -1,7 +1,7 @@ #[macro_use] mod helpers; -use helpers::{globals, roundtrip, wayc, ways, TestServer}; +use helpers::{globals, roundtrip, wayc, ways, TestClient, TestServer}; use std::sync::{ atomic::{AtomicBool, Ordering}, @@ -18,20 +18,13 @@ fn resource_destructor_request() { let mut server_ddata = ServerHandler { destructor_called: Arc::new(AtomicBool::new(false)) }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); let output = client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 3..4, - (), - ) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -53,20 +46,13 @@ fn resource_destructor_cleanup() { let mut server_ddata = ServerHandler { destructor_called: Arc::new(AtomicBool::new(false)) }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 3..4, - (), - ) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -91,20 +77,13 @@ fn client_destructor_cleanup() { let (_, mut client) = 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 mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 3..4, - (), - ) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -176,8 +155,9 @@ struct ClientHandler { } impl ClientHandler { - fn new() -> ClientHandler { - ClientHandler { globals: Default::default() } + fn new(client: &TestClient) -> ClientHandler { + let globals = globals::GlobalList::new(&client.display, &client.event_queue.handle()); + ClientHandler { globals } } } @@ -187,10 +167,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 ]); diff --git a/wayland-tests/tests/globals.rs b/wayland-tests/tests/globals.rs index 176dc24cd95..bd6a340050c 100644 --- a/wayland-tests/tests/globals.rs +++ b/wayland-tests/tests/globals.rs @@ -1,7 +1,7 @@ #[macro_use] mod helpers; -use helpers::{globals, roundtrip, wayc, ways, TestServer}; +use helpers::{globals, roundtrip, wayc, ways, TestClient, TestServer}; use ways::protocol::wl_compositor::WlCompositor as ServerCompositor; use ways::protocol::wl_output::WlOutput as ServerOutput; @@ -13,9 +13,7 @@ fn simple_global() { server.display.handle().create_global::(1, ()); let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - - client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); @@ -35,9 +33,7 @@ fn multi_versions() { server.display.handle().create_global::(1, ()); let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - - client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); @@ -57,9 +53,7 @@ fn dynamic_global() { server.display.handle().create_global::(1, ()); let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler { globals: globals::GlobalList::new() }; - - client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); assert!(client_ddata.globals.list().len() == 1); @@ -95,14 +89,12 @@ fn wrong_global() { server.display.handle().create_global::(4, ()); 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 mut client_ddata = ClientHandler::new(&client); // 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(), ()); + client_ddata.globals.registry().bind::(1, 1, &client.event_queue.handle(), ()); assert!(roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).is_err()); } @@ -115,13 +107,16 @@ fn wrong_global_version() { server.display.handle().create_global::(1, ()); 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 mut client_ddata = ClientHandler::new(&client); // instantiate a global with wrong version, this should kill the client - registry.bind::(1, 2, &client.event_queue.handle(), ()); + client_ddata.globals.registry().bind::( + 1, + 2, + &client.event_queue.handle(), + (), + ); assert!(roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).is_err()); } @@ -134,13 +129,16 @@ fn invalid_global_version() { server.display.handle().create_global::(1, ()); 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 mut client_ddata = ClientHandler::new(&client); // instantiate a global with version 0, which is invalid this should kill the client - registry.bind::(1, 0, &client.event_queue.handle(), ()); + client_ddata.globals.registry().bind::( + 1, + 0, + &client.event_queue.handle(), + (), + ); assert!(roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).is_err()); } @@ -153,13 +151,16 @@ fn wrong_global_id() { server.display.handle().create_global::(1, ()); 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 mut client_ddata = ClientHandler::new(&client); // instantiate a global with version 0, which is invalid this should kill the client - registry.bind::(3, 1, &client.event_queue.handle(), ()); + client_ddata.globals.registry().bind::( + 3, + 1, + &client.event_queue.handle(), + (), + ); assert!(roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).is_err()); } @@ -172,9 +173,7 @@ fn two_step_binding() { server.display.handle().create_global::(1, ()); 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 mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); @@ -185,13 +184,10 @@ fn two_step_binding() { client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 1..2, ()) + .bind::(&client.event_queue.handle(), 1..2, ()) .unwrap(); - client_ddata - .globals - .bind::(&client.event_queue.handle(), ®istry, 1..2, ()) - .unwrap(); + client_ddata.globals.bind::(&client.event_queue.handle(), 1..2, ()).unwrap(); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); } @@ -205,16 +201,19 @@ struct ClientHandler { globals: globals::GlobalList, } +impl ClientHandler { + fn new(client: &TestClient) -> ClientHandler { + let globals = globals::GlobalList::new(&client.display, &client.event_queue.handle()); + ClientHandler { globals } + } +} + impl AsMut for ClientHandler { fn as_mut(&mut self) -> &mut globals::GlobalList { &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, diff --git a/wayland-tests/tests/helpers/globals.rs b/wayland-tests/tests/helpers/globals.rs index 4caec8b3451..c98f4f007dc 100644 --- a/wayland-tests/tests/helpers/globals.rs +++ b/wayland-tests/tests/helpers/globals.rs @@ -2,7 +2,13 @@ use std::ops::Range; -use wayland_client::{protocol::wl_registry, Connection, Dispatch, Proxy, QueueHandle}; +use wayland_client::{ + protocol::{ + wl_display::{self, WlDisplay}, + wl_registry::{self, WlRegistry}, + }, + Connection, Dispatch, Proxy, QueueHandle, +}; /// Description of an advertized global #[derive(Debug)] @@ -24,11 +30,12 @@ pub struct GlobalDescription { #[derive(Debug)] pub struct GlobalList { globals: Vec, + registry: WlRegistry, } impl Dispatch for GlobalList where - D: Dispatch + AsMut, + D: AsMut, { fn event( handle: &mut D, @@ -59,16 +66,22 @@ impl AsMut for GlobalList { } } -impl Default for GlobalList { - fn default() -> Self { - Self::new() - } -} - impl GlobalList { /// Create a new `GlobalList` - pub fn new() -> Self { - Self { globals: Vec::new() } + pub fn new(display: &WlDisplay, qh: &QueueHandle) -> Self + where + D: AsMut + 'static, + { + let data = qh.make_data::(()); + let registry = display + .send_constructor::(wl_display::Request::GetRegistry {}, data) + .unwrap(); + + Self { globals: Vec::new(), registry } + } + + pub fn registry(&self) -> WlRegistry { + self.registry.clone() } /// Access the list of currently advertized globals @@ -83,7 +96,6 @@ impl GlobalList { pub fn bind + 'static>( &self, qh: &QueueHandle, - registry: &wl_registry::WlRegistry, version: Range, user_data: U, ) -> Result { @@ -93,7 +105,7 @@ impl GlobalList { } if version.contains(&desc.version) { - return Ok(registry.bind::(desc.name, desc.version, qh, user_data)); + return Ok(self.registry.bind::(desc.name, desc.version, qh, user_data)); } else { return Err(BindError::WrongVersion { interface: I::interface().name, diff --git a/wayland-tests/tests/protocol_errors.rs b/wayland-tests/tests/protocol_errors.rs index c95fd06c840..e8a8fdc4414 100644 --- a/wayland-tests/tests/protocol_errors.rs +++ b/wayland-tests/tests/protocol_errors.rs @@ -1,7 +1,7 @@ #[macro_use] mod helpers; -use helpers::{globals, roundtrip, wayc, ways, TestServer}; +use helpers::{globals, roundtrip, wayc, ways, TestClient, TestServer}; use ways::Resource; #[test] @@ -14,9 +14,7 @@ fn client_receive_generic_error() { let (s_client, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut ServerHandler).unwrap(); @@ -25,7 +23,6 @@ fn client_receive_generic_error() { .globals .bind::( &client.event_queue.handle(), - ®istry, 1..2, (), ) @@ -62,8 +59,9 @@ struct ClientHandler { } impl ClientHandler { - fn new() -> ClientHandler { - ClientHandler { globals: Default::default() } + fn new(client: &TestClient) -> ClientHandler { + let globals = globals::GlobalList::new(&client.display, &client.event_queue.handle()); + ClientHandler { globals } } } @@ -73,10 +71,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 ]); diff --git a/wayland-tests/tests/server_clients.rs b/wayland-tests/tests/server_clients.rs index 6811cb9849f..11e80f4da5c 100644 --- a/wayland-tests/tests/server_clients.rs +++ b/wayland-tests/tests/server_clients.rs @@ -1,7 +1,7 @@ #[macro_use] mod helpers; -use helpers::{globals, roundtrip, wayc, ways, TestServer}; +use helpers::{globals, roundtrip, wayc, ways, TestClient, TestServer}; use std::sync::{ atomic::{AtomicBool, Ordering}, @@ -25,21 +25,14 @@ fn client_user_data() { has_compositor: AtomicBool::new(false), has_output: AtomicBool::new(false), })); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); // Instantiate the globals client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 1..2, - (), - ) + .bind::(&client.event_queue.handle(), 1..2, ()) .unwrap(); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -54,7 +47,6 @@ fn client_user_data() { .globals .bind::( &client.event_queue.handle(), - ®istry, 1..2, (), ) @@ -103,8 +95,9 @@ struct ClientHandler { } impl ClientHandler { - fn new() -> ClientHandler { - ClientHandler { globals: Default::default() } + fn new(client: &TestClient) -> ClientHandler { + let globals = globals::GlobalList::new(&client.display, &client.event_queue.handle()); + ClientHandler { globals } } } @@ -114,10 +107,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 diff --git a/wayland-tests/tests/server_created_object.rs b/wayland-tests/tests/server_created_object.rs index d04a3702ff8..b56fec0f7da 100644 --- a/wayland-tests/tests/server_created_object.rs +++ b/wayland-tests/tests/server_created_object.rs @@ -1,7 +1,7 @@ #[macro_use] mod helpers; -use helpers::{globals, roundtrip, wayc, ways, TestServer}; +use helpers::{globals, roundtrip, wayc, ways, TestClient, TestServer}; use ways::protocol::wl_data_device::WlDataDevice as ServerDD; use ways::protocol::wl_data_device_manager::{ @@ -25,19 +25,17 @@ fn data_offer() { let mut server_ddata = ServerHandler { data_device: None }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); let seat = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 1..2, ()) + .bind::(&client.event_queue.handle(), 1..2, ()) .unwrap(); let ddmgr = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 3..4, ()) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); ddmgr.get_data_device(&seat, &client.event_queue.handle(), ()); @@ -71,19 +69,17 @@ fn server_id_reuse() { let mut server_ddata = ServerHandler { data_device: None }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); let seat = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 1..2, ()) + .bind::(&client.event_queue.handle(), 1..2, ()) .unwrap(); let ddmgr = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 3..4, ()) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); ddmgr.get_data_device(&seat, &client.event_queue.handle(), ()); @@ -126,7 +122,7 @@ fn server_id_reuse() { roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); - // Send a third data offer, server shoudl reuse id 0xFF000000 + // Send a third data offer, server should reuse id 0xFF000000 let offer = s_client .create_resource::( &server.display.handle(), @@ -152,19 +148,17 @@ fn server_created_race() { let mut server_ddata = ServerHandler { data_device: None }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); let seat = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 1..2, ()) + .bind::(&client.event_queue.handle(), 1..2, ()) .unwrap(); let ddmgr = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 3..4, ()) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); ddmgr.get_data_device(&seat, &client.event_queue.handle(), ()); @@ -215,19 +209,17 @@ fn creation_destruction_race() { let mut server_ddata = ServerHandler { data_device: None }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); let seat = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 1..2, ()) + .bind::(&client.event_queue.handle(), 1..2, ()) .unwrap(); let ddmgr = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 3..4, ()) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); // client creates two data devices @@ -286,19 +278,17 @@ fn creation_destruction_queue_dispatch_race() { let mut server_ddata = ServerHandler { data_device: None }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); let seat = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 1..2, ()) + .bind::(&client.event_queue.handle(), 1..2, ()) .unwrap(); let ddmgr = client_ddata .globals - .bind::(&client.event_queue.handle(), ®istry, 3..4, ()) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); let client_dd = ddmgr.get_data_device(&seat, &client.event_queue.handle(), ()); @@ -344,13 +334,9 @@ struct ClientHandler { } impl ClientHandler { - fn new() -> ClientHandler { - ClientHandler { - globals: Default::default(), - data_offer: None, - received: None, - received_dead: false, - } + fn new(client: &TestClient) -> ClientHandler { + let globals = globals::GlobalList::new(&client.display, &client.event_queue.handle()); + ClientHandler { globals, data_offer: None, received: None, received_dead: false } } } @@ -360,9 +346,6 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); client_ignore_impl!(ClientHandler => [ ClientSeat, ClientDDMgr diff --git a/wayland-tests/tests/server_global_filter.rs b/wayland-tests/tests/server_global_filter.rs index 7c62c3e6601..ecd4b444c47 100644 --- a/wayland-tests/tests/server_global_filter.rs +++ b/wayland-tests/tests/server_global_filter.rs @@ -1,7 +1,7 @@ #[macro_use] mod helpers; -use helpers::{globals, roundtrip, wayc, ways, TestServer}; +use helpers::{globals, roundtrip, wayc, ways, TestClient, TestServer}; use ways::protocol::{wl_compositor, wl_output, wl_shm}; @@ -24,9 +24,7 @@ fn global_filter() { let mut server_ddata = ServerHandler; 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(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -34,9 +32,7 @@ fn global_filter() { let (_, mut priv_client) = 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(), ()); + let mut priv_client_ddata = ClientHandler::new(&priv_client); roundtrip(&mut priv_client, &mut server, &mut priv_client_ddata, &mut server_ddata).unwrap(); @@ -68,17 +64,16 @@ fn global_filter_try_force() { // normal client that cannot bind the privileged global let (_, mut client) = server.add_client_with_data(Arc::new(MyClientData { privileged: false })); - let mut client_ddata = ClientHandler::new(); + let mut client_ddata = ClientHandler::new(&client); // privileged client that can let (_, mut priv_client) = server.add_client_with_data(Arc::new(MyClientData { privileged: true })); - let mut priv_client_ddata = ClientHandler::new(); + let mut priv_client_ddata = ClientHandler::new(&priv_client); // privileged client can bind it - let priv_registry = priv_client.display.get_registry(&priv_client.event_queue.handle(), ()); - priv_registry.bind::( + priv_client_ddata.globals.registry().bind::( 1, 1, &priv_client.event_queue.handle(), @@ -87,8 +82,7 @@ fn global_filter_try_force() { 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(), ()); - registry.bind::( + client_ddata.globals.registry().bind::( 1, 1, &client.event_queue.handle(), @@ -103,8 +97,9 @@ struct ClientHandler { } impl ClientHandler { - fn new() -> ClientHandler { - ClientHandler { globals: Default::default() } + fn new(client: &TestClient) -> ClientHandler { + let globals = globals::GlobalList::new(&client.display, &client.event_queue.handle()); + ClientHandler { globals } } } @@ -114,10 +109,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, wayc::protocol::wl_shm::WlShm, diff --git a/wayland-tests/tests/server_global_post_error.rs b/wayland-tests/tests/server_global_post_error.rs index 45995214266..fa86a4084ca 100644 --- a/wayland-tests/tests/server_global_post_error.rs +++ b/wayland-tests/tests/server_global_post_error.rs @@ -1,7 +1,7 @@ #[macro_use] mod helpers; -use helpers::{globals, roundtrip, wayc, ways, TestServer}; +use helpers::{globals, roundtrip, wayc, ways, TestClient, TestServer}; use wayc::{protocol::wl_output::WlOutput as ClientOutput, Proxy}; @@ -15,21 +15,14 @@ fn global_init_post_error() { let mut server_ddata = ServerHandler; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); // create an outputs let client_output = client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 3..4, - (), - ) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); let _ = roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata); @@ -49,8 +42,9 @@ struct ClientHandler { } impl ClientHandler { - fn new() -> ClientHandler { - ClientHandler { globals: Default::default() } + fn new(client: &TestClient) -> ClientHandler { + let globals = globals::GlobalList::new(&client.display, &client.event_queue.handle()); + ClientHandler { globals } } } @@ -60,10 +54,6 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - client_ignore_impl!(ClientHandler => [ClientOutput]); struct ServerHandler; diff --git a/wayland-tests/tests/server_resources.rs b/wayland-tests/tests/server_resources.rs index 047cb72b542..4cce5be80cd 100644 --- a/wayland-tests/tests/server_resources.rs +++ b/wayland-tests/tests/server_resources.rs @@ -1,7 +1,7 @@ #[macro_use] mod helpers; -use helpers::{globals, roundtrip, wayc, ways, TestServer}; +use helpers::{globals, roundtrip, wayc, ways, TestClient, TestServer}; use ways::{ protocol::{wl_compositor, wl_output}, @@ -20,30 +20,18 @@ fn resource_equals() { let mut server_ddata = ServerHandler { outputs: Vec::new() }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); // create two outputs client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 3..4, - (), - ) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 3..4, - (), - ) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -67,30 +55,18 @@ fn resource_user_data() { let mut server_ddata = ServerHandler { outputs: Vec::new() }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); // create two outputs client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 3..4, - (), - ) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 3..4, - (), - ) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -111,30 +87,18 @@ fn dead_resources() { let mut server_ddata = ServerHandler { outputs: Vec::new() }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); // create two outputs let client_output_1 = client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 3..4, - (), - ) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 3..4, - (), - ) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -163,21 +127,14 @@ fn get_resource() { let mut server_ddata = ServerHandler { outputs: Vec::new() }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); // create an outputs client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 3..4, - (), - ) + .bind::(&client.event_queue.handle(), 3..4, ()) .unwrap(); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -193,7 +150,7 @@ fn get_resource() { assert!(client .object_from_protocol_id::(&server.display.handle(), 4) .is_err()); - // but this suceeds + // but this succeeds assert!(client .object_from_protocol_id::(&server.display.handle(), 3) .is_ok()); @@ -204,8 +161,9 @@ struct ClientHandler { } impl ClientHandler { - fn new() -> ClientHandler { - ClientHandler { globals: Default::default() } + fn new(client: &TestClient) -> ClientHandler { + let globals = globals::GlobalList::new(&client.display, &client.event_queue.handle()); + ClientHandler { globals } } } @@ -215,10 +173,6 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - client_ignore_impl!(ClientHandler => [ClientOutput]); struct ServerHandler { diff --git a/wayland-tests/tests/xdg_shell_ping.rs b/wayland-tests/tests/xdg_shell_ping.rs index 7960a6a4b9e..3fd2f6f64ed 100644 --- a/wayland-tests/tests/xdg_shell_ping.rs +++ b/wayland-tests/tests/xdg_shell_ping.rs @@ -1,7 +1,7 @@ #[macro_use] mod helpers; -use helpers::{globals, roundtrip, wayc, ways, TestServer}; +use helpers::{globals, roundtrip, wayc, ways, TestClient, TestServer}; use wayland_protocols::xdg::shell::{client as xs_client, server as xs_server}; @@ -15,20 +15,13 @@ fn xdg_ping() { let mut server_ddata = ServerHandler { received_pong: false }; let (_, mut client) = server.add_client(); - let mut client_ddata = ClientHandler::new(); - - let registry = client.display.get_registry(&client.event_queue.handle(), ()); + let mut client_ddata = ClientHandler::new(&client); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); client_ddata .globals - .bind::( - &client.event_queue.handle(), - ®istry, - 1..2, - (), - ) + .bind::(&client.event_queue.handle(), 1..2, ()) .unwrap(); roundtrip(&mut client, &mut server, &mut client_ddata, &mut server_ddata).unwrap(); @@ -80,8 +73,9 @@ struct ClientHandler { } impl ClientHandler { - fn new() -> ClientHandler { - ClientHandler { globals: Default::default() } + fn new(client: &TestClient) -> ClientHandler { + let globals = globals::GlobalList::new(&client.display, &client.event_queue.handle()); + ClientHandler { globals } } } @@ -91,10 +85,6 @@ impl AsMut for ClientHandler { } } -wayc::delegate_dispatch!(ClientHandler: - [wayc::protocol::wl_registry::WlRegistry: ()] => globals::GlobalList -); - impl wayc::Dispatch for ClientHandler { fn event( _: &mut Self,