diff --git a/Cargo.lock b/Cargo.lock index 2512ea50..09c64541 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3485,7 +3485,7 @@ checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" [[package]] name = "smithay" version = "0.7.0" -source = "git+https://github.com/Smithay/smithay.git?rev=ff5fa7df392cecfba049ffed55cdaa4e98a8e7ef#ff5fa7df392cecfba049ffed55cdaa4e98a8e7ef" +source = "git+https://github.com/Smithay/smithay.git?rev=0d14cd655f6e905ad5110ff0384400da223f2cab#0d14cd655f6e905ad5110ff0384400da223f2cab" dependencies = [ "aliasable", "appendlist", @@ -3560,7 +3560,7 @@ dependencies = [ [[package]] name = "smithay-drm-extras" version = "0.1.0" -source = "git+https://github.com/Smithay/smithay.git?rev=ff5fa7df392cecfba049ffed55cdaa4e98a8e7ef#ff5fa7df392cecfba049ffed55cdaa4e98a8e7ef" +source = "git+https://github.com/Smithay/smithay.git?rev=0d14cd655f6e905ad5110ff0384400da223f2cab#0d14cd655f6e905ad5110ff0384400da223f2cab" dependencies = [ "drm", "libdisplay-info", diff --git a/Cargo.toml b/Cargo.toml index f27f81d5..bc6d099f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,13 +28,13 @@ tracy-client = { version = "0.18.4", default-features = false } [workspace.dependencies.smithay] # version = "0.4.1" git = "https://github.com/Smithay/smithay.git" -rev = "ff5fa7df392cecfba049ffed55cdaa4e98a8e7ef" +rev = "0d14cd655f6e905ad5110ff0384400da223f2cab" default-features = false [workspace.dependencies.smithay-drm-extras] # version = "0.1.0" git = "https://github.com/Smithay/smithay.git" -rev = "ff5fa7df392cecfba049ffed55cdaa4e98a8e7ef" +rev = "0d14cd655f6e905ad5110ff0384400da223f2cab" # path = "../smithay/smithay-drm-extras" [package] diff --git a/src/handlers/background_effect.rs b/src/handlers/background_effect.rs index 967a0370..36299000 100644 --- a/src/handlers/background_effect.rs +++ b/src/handlers/background_effect.rs @@ -1,6 +1,5 @@ use std::sync::{Arc, Mutex}; -use smithay::delegate_background_effect; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::utils::{Logical, Rectangle}; use smithay::wayland::background_effect::{ @@ -120,4 +119,3 @@ impl ExtBackgroundEffectHandler for State { mark_blur_region_pending_dirty(&wl_surface); } } -delegate_background_effect!(State); diff --git a/src/handlers/compositor.rs b/src/handlers/compositor.rs index f38b2934..f9bd5af9 100644 --- a/src/handlers/compositor.rs +++ b/src/handlers/compositor.rs @@ -16,7 +16,6 @@ use smithay::wayland::compositor::{ use smithay::wayland::dmabuf::get_dmabuf; use smithay::wayland::shell::xdg::ToplevelCachedState; use smithay::wayland::shm::{ShmHandler, ShmState}; -use smithay::{delegate_compositor, delegate_shm}; use super::xdg_shell::add_mapped_toplevel_pre_commit_hook; use crate::handlers::XDG_ACTIVATION_TOKEN_TIMEOUT; @@ -523,9 +522,6 @@ impl ShmHandler for State { } } -delegate_compositor!(State); -delegate_shm!(State); - impl State { pub fn add_default_dmabuf_pre_commit_hook(&mut self, surface: &WlSurface) { if !surface.is_alive() { diff --git a/src/handlers/layer_shell.rs b/src/handlers/layer_shell.rs index 0c5c1cd0..de0af99e 100644 --- a/src/handlers/layer_shell.rs +++ b/src/handlers/layer_shell.rs @@ -1,4 +1,3 @@ -use smithay::delegate_layer_shell; use smithay::desktop::{layer_map_for_output, LayerSurface, PopupKind, WindowSurfaceType}; use smithay::reexports::wayland_server::protocol::wl_output::WlOutput; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; @@ -73,7 +72,6 @@ impl WlrLayerShellHandler for State { self.unconstrain_popup(&PopupKind::Xdg(popup)); } } -delegate_layer_shell!(State); impl State { pub fn layer_shell_handle_commit(&mut self, surface: &WlSurface) -> bool { diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 3532078b..e0dfd2f3 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -61,16 +61,6 @@ use smithay::wayland::tablet_manager::TabletSeatHandler; use smithay::wayland::xdg_activation::{ XdgActivationHandler, XdgActivationState, XdgActivationToken, XdgActivationTokenData, }; -use smithay::{ - delegate_cursor_shape, delegate_data_control, delegate_data_device, delegate_dmabuf, - delegate_drm_lease, delegate_ext_data_control, delegate_fractional_scale, - delegate_idle_inhibit, delegate_idle_notify, delegate_input_method_manager, - delegate_keyboard_shortcuts_inhibit, delegate_output, delegate_pointer_constraints, - delegate_pointer_gestures, delegate_presentation, delegate_primary_selection, - delegate_relative_pointer, delegate_seat, delegate_security_context, delegate_session_lock, - delegate_single_pixel_buffer, delegate_tablet_manager, delegate_text_input_manager, - delegate_viewporter, delegate_virtual_keyboard_manager, delegate_xdg_activation, -}; pub use crate::handlers::xdg_shell::KdeDecorationsModeState; use crate::layout::workspace::WorkspaceId; @@ -90,11 +80,6 @@ use crate::protocols::virtual_pointer::{ VirtualPointerMotionEvent, }; use crate::utils::{output_size, send_scale_transform}; -use crate::{ - delegate_ext_workspace, delegate_foreign_toplevel, delegate_gamma_control, - delegate_mutter_x11_interop, delegate_output_management, delegate_screencopy, - delegate_virtual_pointer, -}; pub const XDG_ACTIVATION_TOKEN_TIMEOUT: Duration = Duration::from_secs(10); @@ -138,11 +123,6 @@ impl SeatHandler for State { } } } -delegate_seat!(State); -delegate_cursor_shape!(State); -delegate_pointer_gestures!(State); -delegate_relative_pointer!(State); -delegate_text_input_manager!(State); impl TabletSeatHandler for State { fn tablet_tool_image(&mut self, _tool: &TabletToolDescriptor, image: CursorImageStatus) { @@ -152,7 +132,6 @@ impl TabletSeatHandler for State { self.niri.queue_redraw_all(); } } -delegate_tablet_manager!(State); impl PointerConstraintsHandler for State { fn new_constraint(&mut self, _surface: &WlSurface, _pointer: &PointerHandle) { @@ -217,7 +196,6 @@ impl PointerConstraintsHandler for State { } } } -delegate_pointer_constraints!(State); impl InputMethodHandler for State { fn new_popup(&mut self, surface: PopupSurface) { @@ -278,10 +256,6 @@ impl KeyboardShortcutsInhibitHandler for State { } } -delegate_input_method_manager!(State); -delegate_keyboard_shortcuts_inhibit!(State); -delegate_virtual_keyboard_manager!(State); - impl SelectionHandler for State { type SelectionUserData = Arc<[u8]>; @@ -401,14 +375,11 @@ impl crate::niri::Niri { } } -delegate_data_device!(State); - impl PrimarySelectionHandler for State { fn primary_selection_state(&mut self) -> &mut PrimarySelectionState { &mut self.niri.primary_selection_state } } -delegate_primary_selection!(State); impl WlrDataControlHandler for State { fn data_control_state(&mut self) -> &mut WlrDataControlState { @@ -416,25 +387,18 @@ impl WlrDataControlHandler for State { } } -delegate_data_control!(State); - impl ExtDataControlHandler for State { fn data_control_state(&mut self) -> &mut ExtDataControlState { &mut self.niri.ext_data_control_state } } -delegate_ext_data_control!(State); - impl OutputHandler for State { fn output_bound(&mut self, output: Output, wl_output: WlOutput) { foreign_toplevel::on_output_bound(self, &output, &wl_output); ext_workspace::on_output_bound(self, &output, &wl_output); } } -delegate_output!(State); - -delegate_presentation!(State); impl DmabufHandler for State { fn dmabuf_state(&mut self) -> &mut DmabufState { @@ -454,7 +418,6 @@ impl DmabufHandler for State { } } } -delegate_dmabuf!(State); impl SessionLockHandler for State { fn lock_state(&mut self) -> &mut SessionLockManagerState { @@ -481,7 +444,6 @@ impl SessionLockHandler for State { self.niri.new_lock_surface(surface, &output); } } -delegate_session_lock!(State); pub fn configure_lock_surface(surface: &LockSurface, output: &Output) { surface.with_pending_state(|states| { @@ -512,14 +474,12 @@ impl SecurityContextHandler for State { .unwrap(); } } -delegate_security_context!(State); impl IdleNotifierHandler for State { fn idle_notifier_state(&mut self) -> &mut IdleNotifierState { &mut self.niri.idle_notifier_state } } -delegate_idle_notify!(State); impl IdleInhibitHandler for State { fn inhibit(&mut self, surface: WlSurface) { @@ -530,7 +490,6 @@ impl IdleInhibitHandler for State { self.niri.idle_inhibiting_surfaces.remove(&surface); } } -delegate_idle_inhibit!(State); impl ForeignToplevelHandler for State { fn foreign_toplevel_manager_state(&mut self) -> &mut ForeignToplevelManagerState { @@ -595,7 +554,6 @@ impl ForeignToplevelHandler for State { } } } -delegate_foreign_toplevel!(State); impl ExtWorkspaceHandler for State { fn ext_workspace_manager_state(&mut self) -> &mut ExtWorkspaceManagerState { @@ -631,7 +589,6 @@ impl ExtWorkspaceHandler for State { } } } -delegate_ext_workspace!(State); impl ScreencopyHandler for State { fn frame(&mut self, manager: &ZwlrScreencopyManagerV1, screencopy: Screencopy) { @@ -661,7 +618,6 @@ impl ScreencopyHandler for State { &mut self.niri.screencopy_state } } -delegate_screencopy!(State); impl VirtualPointerHandler for State { fn virtual_pointer_manager_state(&mut self) -> &mut VirtualPointerManagerState { @@ -686,7 +642,6 @@ impl VirtualPointerHandler for State { self.process_input_event(InputEvent::::PointerAxis { event }); } } -delegate_virtual_pointer!(State); impl DrmLeaseHandler for State { fn drm_lease_state(&mut self, node: DrmNode) -> &mut DrmLeaseState { @@ -733,9 +688,6 @@ impl DrmLeaseHandler for State { .remove_lease(lease_id); } } -delegate_drm_lease!(State); - -delegate_viewporter!(State); impl GammaControlHandler for State { fn gamma_control_manager_state(&mut self) -> &mut GammaControlManagerState { @@ -766,7 +718,6 @@ impl GammaControlHandler for State { } } } -delegate_gamma_control!(State); struct UrgentOnlyMarker; @@ -840,10 +791,8 @@ impl XdgActivationHandler for State { self.niri.activation_state.remove_token(&token); } } -delegate_xdg_activation!(State); impl FractionalScaleHandler for State {} -delegate_fractional_scale!(State); impl OutputManagementHandler for State { fn output_management_state(&mut self) -> &mut OutputManagementManagerState { @@ -855,9 +804,5 @@ impl OutputManagementHandler for State { self.reload_output_config(); } } -delegate_output_management!(State); impl MutterX11InteropHandler for State {} -delegate_mutter_x11_interop!(State); - -delegate_single_pixel_buffer!(State); diff --git a/src/handlers/xdg_shell.rs b/src/handlers/xdg_shell.rs index 38440c90..19b60133 100644 --- a/src/handlers/xdg_shell.rs +++ b/src/handlers/xdg_shell.rs @@ -32,9 +32,6 @@ use smithay::wayland::shell::xdg::{ XdgToplevelSurfaceData, }; use smithay::wayland::xdg_foreign::{XdgForeignHandler, XdgForeignState}; -use smithay::{ - delegate_kde_decoration, delegate_xdg_decoration, delegate_xdg_foreign, delegate_xdg_shell, -}; use tracing::field::Empty; use crate::input::move_grab::MoveGrab; @@ -918,8 +915,6 @@ impl XdgShellHandler for State { } } -delegate_xdg_shell!(State); - impl XdgDecorationHandler for State { fn new_decoration(&mut self, toplevel: ToplevelSurface) { // If we want CSD, we hide this global altogether. @@ -973,7 +968,6 @@ impl XdgDecorationHandler for State { } } } -delegate_xdg_decoration!(State); /// Whether KDE server decorations are in use. #[derive(Default, Clone)] @@ -1014,14 +1008,12 @@ impl KdeDecorationHandler for State { }); } } -delegate_kde_decoration!(State); impl XdgForeignHandler for State { fn xdg_foreign_state(&mut self) -> &mut XdgForeignState { &mut self.niri.xdg_foreign_state } } -delegate_xdg_foreign!(State); impl State { pub fn send_initial_configure(&mut self, toplevel: &ToplevelSurface) { diff --git a/src/niri.rs b/src/niri.rs index 17110d69..beb64869 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -418,6 +418,8 @@ pub struct Niri { pub casting: Screencasting, } +smithay::delegate_dispatch2!(State); + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum PointerVisibility { /// The pointer is visible. diff --git a/src/protocols/ext_workspace.rs b/src/protocols/ext_workspace.rs index 3c0429eb..fae308ac 100644 --- a/src/protocols/ext_workspace.rs +++ b/src/protocols/ext_workspace.rs @@ -26,11 +26,13 @@ use smithay::reexports::wayland_server::protocol::wl_output::WlOutput; use smithay::reexports::wayland_server::{ Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, }; +use smithay::wayland::{Dispatch2, GlobalDispatch2}; use wayland_backend::server::ClientId; use crate::layout::monitor::Monitor; use crate::layout::workspace::{Workspace, WorkspaceId}; use crate::niri::State; +use crate::protocols::EmptyData; use crate::window::Mapped; const VERSION: u32 = 1; @@ -67,6 +69,10 @@ struct ExtWorkspaceGroupData { instances: Vec, } +// Wrapper struct for trait coherence. +#[derive(PartialEq, Eq)] +struct WrappedManager(ExtWorkspaceManagerV1); + struct ExtWorkspaceData { // id cannot change once set. id: Option, @@ -113,7 +119,7 @@ pub fn refresh(state: &mut State) { for group in &data.instances { // Send workspace_leave for all workspaces in this group with matching manager. - let manager: &ExtWorkspaceManagerV1 = group.data().unwrap(); + let manager: &WrappedManager = group.data().unwrap(); for ws in protocol_state.workspaces.values() { if ws.output.as_ref() == Some(output) { for workspace in &ws.instances { @@ -199,7 +205,7 @@ fn refresh_workspace_group(protocol_state: &mut ExtWorkspaceManagerState, output // Send workspace_enter for all existing workspaces on this output. for group in &data.instances { - let manager: &ExtWorkspaceManagerV1 = group.data().unwrap(); + let manager: &WrappedManager = group.data().unwrap(); for ws in protocol_state.workspaces.values() { if ws.output.as_ref() != Some(output) { continue; @@ -224,7 +230,7 @@ fn send_workspace_enter_leave( if let Some(output) = &data.output { if let Some(group_data) = workspace_groups.get(output) { for group in &group_data.instances { - let manager: &ExtWorkspaceManagerV1 = group.data().unwrap(); + let manager: &WrappedManager = group.data().unwrap(); for workspace in &data.instances { if workspace.data() == Some(manager) { if enter { @@ -407,14 +413,14 @@ impl ExtWorkspaceGroupData { output: &Output, ) -> &ExtWorkspaceGroupHandleV1 where - D: Dispatch, + D: Dispatch, D: 'static, { let group = client .create_resource::( handle, manager.version(), - manager.clone(), + WrappedManager(manager.clone()), ) .unwrap(); manager.workspace_group(&group); @@ -438,14 +444,14 @@ impl ExtWorkspaceData { manager: &ExtWorkspaceManagerV1, ) -> &ExtWorkspaceHandleV1 where - D: Dispatch, + D: Dispatch, D: 'static, { let workspace = client .create_resource::( handle, manager.version(), - manager.clone(), + WrappedManager(manager.clone()), ) .unwrap(); manager.workspace(&workspace); @@ -476,7 +482,6 @@ impl ExtWorkspaceManagerState { pub fn new(display: &DisplayHandle, filter: F) -> Self where D: GlobalDispatch, - D: Dispatch, D: 'static, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, { @@ -493,23 +498,21 @@ impl ExtWorkspaceManagerState { } } -impl GlobalDispatch - for ExtWorkspaceManagerState +impl GlobalDispatch2 for ExtWorkspaceGlobalData where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, + D: Dispatch, + D: Dispatch, D: ExtWorkspaceHandler, { fn bind( + &self, state: &mut D, handle: &DisplayHandle, client: &Client, resource: New, - _global_data: &ExtWorkspaceGlobalData, data_init: &mut DataInit<'_, D>, ) { - let manager = data_init.init(resource, ()); + let manager = data_init.init(resource, EmptyData); let state = state.ext_workspace_manager_state(); @@ -537,22 +540,21 @@ where state.instances.insert(manager, Vec::new()); } - fn can_view(client: Client, global_data: &ExtWorkspaceGlobalData) -> bool { - (global_data.filter)(&client) + fn can_view(&self, client: &Client) -> bool { + (self.filter)(client) } } -impl Dispatch for ExtWorkspaceManagerState +impl Dispatch2 for EmptyData where - D: Dispatch, D: ExtWorkspaceHandler, { fn request( + &self, state: &mut D, _client: &Client, resource: &ExtWorkspaceManagerV1, request: ::Request, - _data: &(), _dhandle: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { @@ -581,37 +583,38 @@ where let state = state.ext_workspace_manager_state(); state.instances.retain(|x, _| x != resource); + let manager = WrappedManager(resource.clone()); + for data in state.workspace_groups.values_mut() { data.instances - .retain(|instance| instance.data() != Some(resource)); + .retain(|instance| instance.data() != Some(&manager)); } for data in state.workspaces.values_mut() { data.instances - .retain(|instance| instance.data() != Some(resource)); + .retain(|instance| instance.data() != Some(&manager)); } } _ => unreachable!(), } } - fn destroyed(state: &mut D, _client: ClientId, resource: &ExtWorkspaceManagerV1, _data: &()) { + fn destroyed(&self, state: &mut D, _client: ClientId, resource: &ExtWorkspaceManagerV1) { let state = state.ext_workspace_manager_state(); state.instances.retain(|x, _| x != resource); } } -impl Dispatch for ExtWorkspaceManagerState +impl Dispatch2 for WrappedManager where - D: Dispatch, D: ExtWorkspaceHandler, { fn request( + &self, state: &mut D, _client: &Client, resource: &ExtWorkspaceHandleV1, request: ::Request, - data: &ExtWorkspaceManagerV1, _dhandle: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { @@ -628,7 +631,7 @@ where match request { ext_workspace_handle_v1::Request::Activate => { - let actions = protocol_state.instances.get_mut(data).unwrap(); + let actions = protocol_state.instances.get_mut(&self.0).unwrap(); actions.push(Action::Activate(workspace)); } ext_workspace_handle_v1::Request::Deactivate => (), @@ -639,7 +642,7 @@ where .find(|(_, data)| data.instances.contains(&workspace_group)) .map(|(output, _)| output.clone()) { - let actions = protocol_state.instances.get_mut(data).unwrap(); + let actions = protocol_state.instances.get_mut(&self.0).unwrap(); actions.push(Action::Assign(workspace, output.downgrade())); } } @@ -649,12 +652,7 @@ where } } - fn destroyed( - state: &mut D, - _client: ClientId, - resource: &ExtWorkspaceHandleV1, - _data: &ExtWorkspaceManagerV1, - ) { + fn destroyed(&self, state: &mut D, _client: ClientId, resource: &ExtWorkspaceHandleV1) { let state = state.ext_workspace_manager_state(); for data in state.workspaces.values_mut() { data.instances.retain(|instance| instance != resource); @@ -662,17 +660,16 @@ where } } -impl Dispatch for ExtWorkspaceManagerState +impl Dispatch2 for WrappedManager where - D: Dispatch, D: ExtWorkspaceHandler, { fn request( + &self, _state: &mut D, _client: &Client, _resource: &ExtWorkspaceGroupHandleV1, request: ::Request, - _data: &ExtWorkspaceManagerV1, _dhandle: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { @@ -683,33 +680,10 @@ where } } - fn destroyed( - state: &mut D, - _client: ClientId, - resource: &ExtWorkspaceGroupHandleV1, - _data: &ExtWorkspaceManagerV1, - ) { + fn destroyed(&self, state: &mut D, _client: ClientId, resource: &ExtWorkspaceGroupHandleV1) { let state = state.ext_workspace_manager_state(); for data in state.workspace_groups.values_mut() { data.instances.retain(|instance| instance != resource); } } } - -#[macro_export] -macro_rules! delegate_ext_workspace { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols::ext::workspace::v1::server::ext_workspace_manager_v1::ExtWorkspaceManagerV1: $crate::protocols::ext_workspace::ExtWorkspaceGlobalData - ] => $crate::protocols::ext_workspace::ExtWorkspaceManagerState); - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols::ext::workspace::v1::server::ext_workspace_manager_v1::ExtWorkspaceManagerV1: () - ] => $crate::protocols::ext_workspace::ExtWorkspaceManagerState); - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols::ext::workspace::v1::server::ext_workspace_handle_v1::ExtWorkspaceHandleV1: smithay::reexports::wayland_protocols::ext::workspace::v1::server::ext_workspace_manager_v1::ExtWorkspaceManagerV1 - ] => $crate::protocols::ext_workspace::ExtWorkspaceManagerState); - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols::ext::workspace::v1::server::ext_workspace_group_handle_v1::ExtWorkspaceGroupHandleV1: smithay::reexports::wayland_protocols::ext::workspace::v1::server::ext_workspace_manager_v1::ExtWorkspaceManagerV1 - ] => $crate::protocols::ext_workspace::ExtWorkspaceManagerState); - }; -} diff --git a/src/protocols/foreign_toplevel.rs b/src/protocols/foreign_toplevel.rs index 11379169..f16e5ac9 100644 --- a/src/protocols/foreign_toplevel.rs +++ b/src/protocols/foreign_toplevel.rs @@ -17,11 +17,13 @@ use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::reexports::wayland_server::{ Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, }; +use smithay::wayland::{Dispatch2, GlobalDispatch2}; use smithay::wayland::shell::xdg::{ ToplevelState, ToplevelStateSet, XdgToplevelSurfaceRoleAttributes }; use crate::niri::State; +use crate::protocols::EmptyData; use crate::window::mapped::MappedId; use crate::utils::with_toplevel_role_and_current; @@ -67,8 +69,6 @@ impl ForeignToplevelManagerState { where D: GlobalDispatch, D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: 'static, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, { @@ -323,11 +323,15 @@ impl ToplevelData { client: &Client, manager: &ExtForeignToplevelListV1, ) where - D: Dispatch, + D: Dispatch, D: 'static, { let toplevel = client - .create_resource::(handle, manager.version(), ()) + .create_resource::( + handle, + manager.version(), + EmptyData, + ) .unwrap(); manager.toplevel(&toplevel); @@ -351,11 +355,15 @@ impl ToplevelData { client: &Client, manager: &ZwlrForeignToplevelManagerV1, ) where - D: Dispatch, + D: Dispatch, D: 'static, { let toplevel = client - .create_resource::(handle, manager.version(), ()) + .create_resource::( + handle, + manager.version(), + EmptyData, + ) .unwrap(); manager.toplevel(&toplevel); @@ -382,23 +390,21 @@ impl ToplevelData { } } -impl GlobalDispatch - for ForeignToplevelManagerState +impl GlobalDispatch2 for ForeignToplevelGlobalData where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, + D: Dispatch, + D: Dispatch, D: ForeignToplevelHandler, { fn bind( + &self, state: &mut D, handle: &DisplayHandle, client: &Client, resource: New, - _global_data: &ForeignToplevelGlobalData, data_init: &mut DataInit<'_, D>, ) { - let manager = data_init.init(resource, ()); + let manager = data_init.init(resource, EmptyData); let state = state.foreign_toplevel_manager_state(); @@ -409,22 +415,21 @@ where state.ext_list_instances.insert(manager); } - fn can_view(client: Client, global_data: &ForeignToplevelGlobalData) -> bool { - (global_data.filter)(&client) + fn can_view(&self, client: &Client) -> bool { + (self.filter)(client) } } -impl Dispatch for ForeignToplevelManagerState +impl Dispatch2 for EmptyData where - D: Dispatch, D: ForeignToplevelHandler, { fn request( + &self, state: &mut D, _client: &Client, resource: &ExtForeignToplevelListV1, request: ::Request, - _data: &(), _dhandle: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { @@ -441,29 +446,23 @@ where } } - fn destroyed( - state: &mut D, - _client: ClientId, - resource: &ExtForeignToplevelListV1, - _data: &(), - ) { + fn destroyed(&self, state: &mut D, _client: ClientId, resource: &ExtForeignToplevelListV1) { // also remove the instance here, in case `stop` was never sent, e.g. sudden disconnect. let state = state.foreign_toplevel_manager_state(); state.ext_list_instances.remove(resource); } } -impl Dispatch for ForeignToplevelManagerState +impl Dispatch2 for EmptyData where - D: Dispatch, D: ForeignToplevelHandler, { fn request( + &self, _state: &mut D, _client: &Client, _resource: &ExtForeignToplevelHandleV1, request: ::Request, - _data: &(), _dhandle: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { @@ -473,12 +472,7 @@ where } } - fn destroyed( - state: &mut D, - _client: ClientId, - resource: &ExtForeignToplevelHandleV1, - _data: &(), - ) { + fn destroyed(&self, state: &mut D, _client: ClientId, resource: &ExtForeignToplevelHandleV1) { let state = state.foreign_toplevel_manager_state(); for data in state.toplevels.values_mut() { data.ext_list_instances.remove(resource); @@ -486,23 +480,21 @@ where } } -impl GlobalDispatch - for ForeignToplevelManagerState +impl GlobalDispatch2 for ForeignToplevelGlobalData where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, + D: Dispatch, + D: Dispatch, D: ForeignToplevelHandler, { fn bind( + &self, state: &mut D, handle: &DisplayHandle, client: &Client, resource: New, - _global_data: &ForeignToplevelGlobalData, data_init: &mut DataInit<'_, D>, ) { - let manager = data_init.init(resource, ()); + let manager = data_init.init(resource, EmptyData); let state = state.foreign_toplevel_manager_state(); @@ -513,22 +505,21 @@ where state.wlr_management_instances.insert(manager); } - fn can_view(client: Client, global_data: &ForeignToplevelGlobalData) -> bool { - (global_data.filter)(&client) + fn can_view(&self, client: &Client) -> bool { + (self.filter)(client) } } -impl Dispatch for ForeignToplevelManagerState +impl Dispatch2 for EmptyData where - D: Dispatch, D: ForeignToplevelHandler, { fn request( + &self, state: &mut D, _client: &Client, resource: &ZwlrForeignToplevelManagerV1, request: ::Request, - _data: &(), _dhandle: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { @@ -544,29 +535,23 @@ where } } - fn destroyed( - state: &mut D, - _client: ClientId, - resource: &ZwlrForeignToplevelManagerV1, - _data: &(), - ) { + fn destroyed(&self, state: &mut D, _client: ClientId, resource: &ZwlrForeignToplevelManagerV1) { // also remove the instance here, in case `stop` was never sent, e.g. sudden disconnect. let state = state.foreign_toplevel_manager_state(); state.wlr_management_instances.remove(resource); } } -impl Dispatch for ForeignToplevelManagerState +impl Dispatch2 for EmptyData where - D: Dispatch, D: ForeignToplevelHandler, { fn request( + &self, state: &mut D, _client: &Client, resource: &ZwlrForeignToplevelHandleV1, request: ::Request, - _data: &(), _dhandle: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { @@ -606,12 +591,7 @@ where } } - fn destroyed( - state: &mut D, - _client: ClientId, - resource: &ZwlrForeignToplevelHandleV1, - _data: &(), - ) { + fn destroyed(&self, state: &mut D, _client: ClientId, resource: &ZwlrForeignToplevelHandleV1) { let state = state.foreign_toplevel_manager_state(); for data in state.toplevels.values_mut() { data.wlr_management_instances.remove(resource); @@ -642,28 +622,3 @@ fn to_state_vec(states: &ToplevelStateSet, has_focus: bool) -> ArrayVec rv } - -#[macro_export] -macro_rules! delegate_foreign_toplevel { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols::ext::foreign_toplevel_list::v1::server::ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1: $crate::protocols::foreign_toplevel::ForeignToplevelGlobalData - ] => $crate::protocols::foreign_toplevel::ForeignToplevelManagerState); - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols::ext::foreign_toplevel_list::v1::server::ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1: () - ] => $crate::protocols::foreign_toplevel::ForeignToplevelManagerState); - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols::ext::foreign_toplevel_list::v1::server::ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1: () - ] => $crate::protocols::foreign_toplevel::ForeignToplevelManagerState); - - smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::foreign_toplevel::v1::server::zwlr_foreign_toplevel_manager_v1::ZwlrForeignToplevelManagerV1: $crate::protocols::foreign_toplevel::ForeignToplevelGlobalData - ] => $crate::protocols::foreign_toplevel::ForeignToplevelManagerState); - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::foreign_toplevel::v1::server::zwlr_foreign_toplevel_manager_v1::ZwlrForeignToplevelManagerV1: () - ] => $crate::protocols::foreign_toplevel::ForeignToplevelManagerState); - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::foreign_toplevel::v1::server::zwlr_foreign_toplevel_handle_v1::ZwlrForeignToplevelHandleV1: () - ] => $crate::protocols::foreign_toplevel::ForeignToplevelManagerState); - }; -} diff --git a/src/protocols/gamma_control.rs b/src/protocols/gamma_control.rs index d0c99572..9c397709 100644 --- a/src/protocols/gamma_control.rs +++ b/src/protocols/gamma_control.rs @@ -8,12 +8,15 @@ use smithay::reexports::wayland_server::backend::ClientId; use smithay::reexports::wayland_server::{ Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, }; +use smithay::wayland::{Dispatch2, GlobalDispatch2}; use wayland_protocols_wlr::gamma_control::v1::server::{ zwlr_gamma_control_manager_v1, zwlr_gamma_control_v1, }; use zwlr_gamma_control_manager_v1::ZwlrGammaControlManagerV1; use zwlr_gamma_control_v1::ZwlrGammaControlV1; +use crate::protocols::EmptyData; + const VERSION: u32 = 1; pub struct GammaControlManagerState { @@ -39,8 +42,6 @@ impl GammaControlManagerState { pub fn new(display: &DisplayHandle, filter: F) -> Self where D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: GammaControlHandler, D: 'static, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, @@ -62,44 +63,40 @@ impl GammaControlManagerState { } } -impl GlobalDispatch - for GammaControlManagerState +impl GlobalDispatch2 for GammaControlManagerGlobalData where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, + D: Dispatch, D: GammaControlHandler, D: 'static, { fn bind( + &self, _state: &mut D, _handle: &DisplayHandle, _client: &Client, manager: New, - _manager_state: &GammaControlManagerGlobalData, data_init: &mut DataInit<'_, D>, ) { - data_init.init(manager, ()); + data_init.init(manager, EmptyData); } - fn can_view(client: Client, global_data: &GammaControlManagerGlobalData) -> bool { - (global_data.filter)(&client) + fn can_view(&self, client: &Client) -> bool { + (self.filter)(client) } } -impl Dispatch for GammaControlManagerState +impl Dispatch2 for EmptyData where - D: Dispatch, D: Dispatch, D: GammaControlHandler, D: 'static, { fn request( + &self, state: &mut D, _client: &Client, _resource: &ZwlrGammaControlManagerV1, request: ::Request, - _data: &(), _dhandle: &DisplayHandle, data_init: &mut DataInit<'_, D>, ) { @@ -136,18 +133,17 @@ where } } -impl Dispatch for GammaControlManagerState +impl Dispatch2 for GammaControlState where - D: Dispatch, D: GammaControlHandler, D: 'static, { fn request( + &self, state: &mut D, _client: &Client, resource: &ZwlrGammaControlV1, request: ::Request, - data: &GammaControlState, _dhandle: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { @@ -162,7 +158,7 @@ where trace!("setting gamma for output {}", output.name()); // Start with a u16 slice so it's aligned correctly. - let mut gamma = vec![0u16; data.gamma_size as usize * 3]; + let mut gamma = vec![0u16; self.gamma_size as usize * 3]; let buf = bytemuck::cast_slice_mut(&mut gamma); let mut file = File::from(fd); { @@ -210,12 +206,7 @@ where } } - fn destroyed( - state: &mut D, - _client: ClientId, - resource: &ZwlrGammaControlV1, - _data: &GammaControlState, - ) { + fn destroyed(&self, state: &mut D, _client: ClientId, resource: &ZwlrGammaControlV1) { let gamma_controls = &mut state.gamma_control_manager_state().gamma_controls; let Some((output, _)) = gamma_controls.iter().find(|(_, x)| *x == resource) else { return; @@ -226,20 +217,3 @@ where let _ = state.set_gamma(&output, None); } } - -#[macro_export] -macro_rules! delegate_gamma_control { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::gamma_control::v1::server::zwlr_gamma_control_manager_v1::ZwlrGammaControlManagerV1: $crate::protocols::gamma_control::GammaControlManagerGlobalData - ] => $crate::protocols::gamma_control::GammaControlManagerState); - - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::gamma_control::v1::server::zwlr_gamma_control_manager_v1::ZwlrGammaControlManagerV1: () - ] => $crate::protocols::gamma_control::GammaControlManagerState); - - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::gamma_control::v1::server::zwlr_gamma_control_v1::ZwlrGammaControlV1: $crate::protocols::gamma_control::GammaControlState - ] => $crate::protocols::gamma_control::GammaControlManagerState); - }; -} diff --git a/src/protocols/mod.rs b/src/protocols/mod.rs index b150cb7f..9a6b25a7 100644 --- a/src/protocols/mod.rs +++ b/src/protocols/mod.rs @@ -7,3 +7,9 @@ pub mod screencopy; pub mod virtual_pointer; pub mod raw; + +/// Empty user-data for protocol impls. +/// +/// Same as Smithay's `GlobalData` which we can't use due to coherence. +#[derive(Debug)] +pub struct EmptyData; diff --git a/src/protocols/mutter_x11_interop.rs b/src/protocols/mutter_x11_interop.rs index cce41f15..5919f22b 100644 --- a/src/protocols/mutter_x11_interop.rs +++ b/src/protocols/mutter_x11_interop.rs @@ -2,6 +2,7 @@ use mutter_x11_interop::MutterX11Interop; use smithay::reexports::wayland_server::{ Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, }; +use smithay::wayland::{Dispatch2, GlobalData, GlobalDispatch2}; use super::raw::mutter_x11_interop::v1::server::mutter_x11_interop; @@ -19,7 +20,6 @@ impl MutterX11InteropManagerState { pub fn new(display: &DisplayHandle, filter: F) -> Self where D: GlobalDispatch, - D: Dispatch, D: MutterX11InteropHandler, D: 'static, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, @@ -33,42 +33,37 @@ impl MutterX11InteropManagerState { } } -impl GlobalDispatch - for MutterX11InteropManagerState +impl GlobalDispatch2 for MutterX11InteropManagerGlobalData where - D: GlobalDispatch, - D: Dispatch, + D: Dispatch, D: MutterX11InteropHandler, - D: 'static, { fn bind( + &self, _state: &mut D, _handle: &DisplayHandle, _client: &Client, manager: New, - _manager_state: &MutterX11InteropManagerGlobalData, data_init: &mut DataInit<'_, D>, ) { - data_init.init(manager, ()); + data_init.init(manager, GlobalData); } - fn can_view(client: Client, global_data: &MutterX11InteropManagerGlobalData) -> bool { - (global_data.filter)(&client) + fn can_view(&self, client: &Client) -> bool { + (self.filter)(client) } } -impl Dispatch for MutterX11InteropManagerState +impl Dispatch2 for GlobalData where - D: Dispatch, D: MutterX11InteropHandler, - D: 'static, { fn request( + &self, _state: &mut D, _client: &Client, _resource: &MutterX11Interop, request: ::Request, - _data: &(), _dhandle: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { @@ -78,16 +73,3 @@ where } } } - -#[macro_export] -macro_rules! delegate_mutter_x11_interop { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::protocols::raw::mutter_x11_interop::v1::server::mutter_x11_interop::MutterX11Interop: $crate::protocols::mutter_x11_interop::MutterX11InteropManagerGlobalData - ] => $crate::protocols::mutter_x11_interop::MutterX11InteropManagerState); - - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::protocols::raw::mutter_x11_interop::v1::server::mutter_x11_interop::MutterX11Interop: () - ] => $crate::protocols::mutter_x11_interop::MutterX11InteropManagerState); - }; -} diff --git a/src/protocols/output_management.rs b/src/protocols/output_management.rs index 75d822ae..c26b276d 100644 --- a/src/protocols/output_management.rs +++ b/src/protocols/output_management.rs @@ -14,6 +14,7 @@ use smithay::reexports::wayland_server::protocol::wl_output::Transform as WlTran use smithay::reexports::wayland_server::{ Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, WEnum, }; +use smithay::wayland::{Dispatch2, GlobalDispatch2}; use zwlr_output_configuration_head_v1::ZwlrOutputConfigurationHeadV1; use zwlr_output_configuration_v1::ZwlrOutputConfigurationV1; use zwlr_output_head_v1::{AdaptiveSyncState, ZwlrOutputHeadV1}; @@ -22,6 +23,7 @@ use zwlr_output_mode_v1::ZwlrOutputModeV1; use crate::backend::OutputId; use crate::niri::State; +use crate::protocols::EmptyData; use crate::utils::ipc_transform_to_smithay; const VERSION: u32 = 4; @@ -50,6 +52,10 @@ pub trait OutputManagementHandler { fn apply_output_config(&mut self, config: niri_config::Outputs); } +struct OutputConfigurationData { + serial: u32, +} + #[derive(Debug)] enum OutputConfigurationState { Ongoing(HashMap), @@ -65,11 +71,6 @@ impl OutputManagementManagerState { pub fn new(display: &DisplayHandle, filter: F) -> Self where D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, D: OutputManagementHandler, D: 'static, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, @@ -136,7 +137,7 @@ impl OutputManagementManagerState { .create_resource::( &self.display, head.version(), - (), + EmptyData, ) .unwrap(); head.mode(&new_mode); @@ -269,27 +270,23 @@ impl OutputManagementManagerState { } } -impl GlobalDispatch - for OutputManagementManagerState +impl GlobalDispatch2 for OutputManagementManagerGlobalData where - D: GlobalDispatch, - D: Dispatch, + D: Dispatch, + D: Dispatch, D: Dispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, D: OutputManagementHandler, D: 'static, { fn bind( + &self, state: &mut D, display: &DisplayHandle, client: &Client, manager: New, - _manager_state: &OutputManagementManagerGlobalData, data_init: &mut DataInit<'_, D>, ) { - let manager = data_init.init(manager, ()); + let manager = data_init.init(manager, EmptyData); let g_state = state.output_management_state(); let mut client_data = ClientData { heads: HashMap::new(), @@ -303,35 +300,30 @@ where manager.done(g_state.serial); } - fn can_view(client: Client, global_data: &OutputManagementManagerGlobalData) -> bool { - (global_data.filter)(&client) + fn can_view(&self, client: &Client) -> bool { + (self.filter)(client) } } -impl Dispatch for OutputManagementManagerState +impl Dispatch2 for EmptyData where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, + D: Dispatch, D: OutputManagementHandler, D: 'static, { fn request( + &self, state: &mut D, client: &Client, _manager: &ZwlrOutputManagerV1, request: zwlr_output_manager_v1::Request, - _data: &(), _display: &DisplayHandle, data_init: &mut DataInit<'_, D>, ) { match request { zwlr_output_manager_v1::Request::CreateConfiguration { id, serial } => { let g_state = state.output_management_state(); - let conf = data_init.init(id, serial); + let conf = data_init.init(id, OutputConfigurationData { serial }); if let Some(client_data) = g_state.clients.get_mut(&client.id()) { if serial != g_state.serial { conf.cancelled(); @@ -350,33 +342,28 @@ where _ => unreachable!(), } } - fn destroyed(state: &mut D, client: ClientId, _resource: &ZwlrOutputManagerV1, _data: &()) { + fn destroyed(&self, state: &mut D, client: ClientId, _resource: &ZwlrOutputManagerV1) { state.output_management_state().clients.remove(&client); } } -impl Dispatch for OutputManagementManagerState +impl Dispatch2 for OutputConfigurationData where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, D: Dispatch, - D: Dispatch, D: OutputManagementHandler, D: 'static, { fn request( + &self, state: &mut D, client: &Client, conf: &ZwlrOutputConfigurationV1, request: zwlr_output_configuration_v1::Request, - serial: &u32, _display: &DisplayHandle, data_init: &mut DataInit<'_, D>, ) { let g_state = state.output_management_state(); - let outdated = *serial != g_state.serial; + let outdated = self.serial != g_state.serial; if outdated { debug!("OutputConfiguration: request from an outdated configuration"); } @@ -565,24 +552,17 @@ where } } -impl Dispatch - for OutputManagementManagerState +impl Dispatch2 for OutputConfigurationHeadState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, D: OutputManagementHandler, D: 'static, { fn request( + &self, state: &mut D, client: &Client, conf_head: &ZwlrOutputConfigurationHeadV1, request: zwlr_output_configuration_head_v1::Request, - data: &OutputConfigurationHeadState, _display: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { @@ -591,11 +571,12 @@ where error!("ConfigurationHead: missing client data"); return; }; - let OutputConfigurationHeadState::Ok(output_id, conf) = data else { + let OutputConfigurationHeadState::Ok(output_id, conf) = self else { warn!("ConfigurationHead: request sent to a cancelled head"); return; }; - let Some(serial) = conf.data::() else { + let Some(OutputConfigurationData { serial }) = conf.data::() + else { error!("ConfigurationHead: missing serial"); return; }; @@ -740,23 +721,17 @@ where } } -impl Dispatch for OutputManagementManagerState +impl Dispatch2 for OutputId where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, D: OutputManagementHandler, D: 'static, { fn request( + &self, _state: &mut D, _client: &Client, _output_head: &ZwlrOutputHeadV1, request: zwlr_output_head_v1::Request, - _data: &OutputId, _display: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { @@ -765,30 +740,24 @@ where _ => unreachable!(), } } - fn destroyed(state: &mut D, client: ClientId, _resource: &ZwlrOutputHeadV1, data: &OutputId) { + fn destroyed(&self, state: &mut D, client: ClientId, _resource: &ZwlrOutputHeadV1) { if let Some(c) = state.output_management_state().clients.get_mut(&client) { - c.heads.remove(data); + c.heads.remove(self); } } } -impl Dispatch for OutputManagementManagerState +impl Dispatch2 for EmptyData where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, D: OutputManagementHandler, D: 'static, { fn request( + &self, _state: &mut D, _client: &Client, _mode: &ZwlrOutputModeV1, request: zwlr_output_mode_v1::Request, - _data: &(), _display: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { @@ -799,30 +768,6 @@ where } } -#[macro_export] -macro_rules! delegate_output_management{ - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::output_management::v1::server::zwlr_output_manager_v1::ZwlrOutputManagerV1: $crate::protocols::output_management::OutputManagementManagerGlobalData - ] => $crate::protocols::output_management::OutputManagementManagerState); - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::output_management::v1::server::zwlr_output_manager_v1::ZwlrOutputManagerV1: () - ] => $crate::protocols::output_management::OutputManagementManagerState); - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::output_management::v1::server::zwlr_output_configuration_v1::ZwlrOutputConfigurationV1: u32 - ] => $crate::protocols::output_management::OutputManagementManagerState); - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::output_management::v1::server::zwlr_output_head_v1::ZwlrOutputHeadV1: $crate::backend::OutputId - ] => $crate::protocols::output_management::OutputManagementManagerState); - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::output_management::v1::server::zwlr_output_mode_v1::ZwlrOutputModeV1: () - ] => $crate::protocols::output_management::OutputManagementManagerState); - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::output_management::v1::server::zwlr_output_configuration_head_v1::ZwlrOutputConfigurationHeadV1: $crate::protocols::output_management::OutputConfigurationHeadState - ] => $crate::protocols::output_management::OutputManagementManagerState); - }; -} - fn notify_removed_head(clients: &mut HashMap, head: &OutputId) { for data in clients.values_mut() { if let Some((head, mods)) = data.heads.remove(head) { @@ -853,15 +798,9 @@ fn send_new_head( output: OutputId, conf: &niri_ipc::Output, ) where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, - D: OutputManagementHandler, - D: 'static, + D: Dispatch, D: Dispatch, - D: Dispatch, + D: OutputManagementHandler, D: 'static, { let new_head = client @@ -879,7 +818,7 @@ fn send_new_head( let mut new_modes = Vec::with_capacity(conf.modes.len()); for (index, mode) in conf.modes.iter().enumerate() { let new_mode = client - .create_resource::(display, new_head.version(), ()) + .create_resource::(display, new_head.version(), EmptyData) .unwrap(); new_head.mode(&new_mode); new_mode.size(i32::from(mode.width), i32::from(mode.height)); diff --git a/src/protocols/screencopy.rs b/src/protocols/screencopy.rs index c7600433..c6e61ce5 100644 --- a/src/protocols/screencopy.rs +++ b/src/protocols/screencopy.rs @@ -19,11 +19,12 @@ use smithay::reexports::wayland_server::{ Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, }; use smithay::utils::{Physical, Point, Rectangle, Size, Transform}; -use smithay::wayland::{dmabuf, shm}; +use smithay::wayland::{dmabuf, shm, Dispatch2, GlobalDispatch2}; use wayland_backend::server::Credentials; use zwlr_screencopy_frame_v1::{Flags, ZwlrScreencopyFrameV1}; use zwlr_screencopy_manager_v1::ZwlrScreencopyManagerV1; +use crate::protocols::EmptyData; use crate::utils::{get_credentials_for_client, get_monotonic_time, CastSessionId, CastStreamId}; const VERSION: u32 = 3; @@ -211,8 +212,6 @@ impl ScreencopyManagerState { pub fn new(display: &DisplayHandle, filter: F) -> Self where D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: ScreencopyHandler, D: 'static, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, @@ -278,24 +277,21 @@ impl ScreencopyManagerState { } } -impl GlobalDispatch - for ScreencopyManagerState +impl GlobalDispatch2 for ScreencopyManagerGlobalData where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, + D: Dispatch, D: ScreencopyHandler, D: 'static, { fn bind( + &self, state: &mut D, dh: &DisplayHandle, client: &Client, manager: New, - _manager_state: &ScreencopyManagerGlobalData, data_init: &mut DataInit<'_, D>, ) { - let manager = data_init.init(manager, ()); + let manager = data_init.init(manager, EmptyData); let state = state.screencopy_state(); let credentials = get_credentials_for_client(dh, client); @@ -303,25 +299,23 @@ where state.queues.insert(manager.clone(), queue); } - fn can_view(client: Client, global_data: &ScreencopyManagerGlobalData) -> bool { - (global_data.filter)(&client) + fn can_view(&self, client: &Client) -> bool { + (self.filter)(client) } } -impl Dispatch for ScreencopyManagerState +impl Dispatch2 for EmptyData where - D: GlobalDispatch, - D: Dispatch, D: Dispatch, D: ScreencopyHandler, D: 'static, { fn request( + &self, state: &mut D, _client: &Client, manager: &ZwlrScreencopyManagerV1, request: zwlr_screencopy_manager_v1::Request, - _data: &(), _display: &DisplayHandle, data_init: &mut DataInit<'_, D>, ) { @@ -443,10 +437,10 @@ where } fn destroyed( + &self, state: &mut D, _client: wayland_backend::server::ClientId, manager: &ZwlrScreencopyManagerV1, - _data: &(), ) { let state = state.screencopy_state(); @@ -483,24 +477,6 @@ pub trait ScreencopyHandler { fn screencopy_state(&mut self) -> &mut ScreencopyManagerState; } -#[allow(missing_docs)] -#[macro_export] -macro_rules! delegate_screencopy { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::screencopy::v1::server::zwlr_screencopy_manager_v1::ZwlrScreencopyManagerV1: $crate::protocols::screencopy::ScreencopyManagerGlobalData - ] => $crate::protocols::screencopy::ScreencopyManagerState); - - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::screencopy::v1::server::zwlr_screencopy_manager_v1::ZwlrScreencopyManagerV1: () - ] => $crate::protocols::screencopy::ScreencopyManagerState); - - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::screencopy::v1::server::zwlr_screencopy_frame_v1::ZwlrScreencopyFrameV1: $crate::protocols::screencopy::ScreencopyFrameState - ] => $crate::protocols::screencopy::ScreencopyManagerState); - }; -} - #[derive(Clone)] pub struct ScreencopyFrameInfo { output: Output, @@ -518,18 +494,17 @@ pub enum ScreencopyFrameState { }, } -impl Dispatch for ScreencopyManagerState +impl Dispatch2 for ScreencopyFrameState where - D: Dispatch, D: ScreencopyHandler, D: 'static, { fn request( + &self, state: &mut D, _client: &Client, frame: &ZwlrScreencopyFrameV1, request: zwlr_screencopy_frame_v1::Request, - data: &ScreencopyFrameState, _display: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { @@ -541,7 +516,7 @@ where manager, info, copied, - } = data + } = self else { return; }; @@ -617,12 +592,12 @@ where } fn destroyed( + &self, state: &mut D, _client: wayland_backend::server::ClientId, frame: &ZwlrScreencopyFrameV1, - data: &ScreencopyFrameState, ) { - let ScreencopyFrameState::Pending { manager, .. } = data else { + let ScreencopyFrameState::Pending { manager, .. } = self else { return; }; diff --git a/src/protocols/virtual_pointer.rs b/src/protocols/virtual_pointer.rs index 4ecc85ab..c2b01e1c 100644 --- a/src/protocols/virtual_pointer.rs +++ b/src/protocols/virtual_pointer.rs @@ -14,6 +14,7 @@ use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat; use smithay::reexports::wayland_server::{ Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, }; +use smithay::wayland::{Dispatch2, GlobalDispatch2}; use wayland_backend::protocol::WEnum; use wayland_protocols_wlr::virtual_pointer::v1::server::{ zwlr_virtual_pointer_manager_v1, zwlr_virtual_pointer_v1, @@ -21,6 +22,8 @@ use wayland_protocols_wlr::virtual_pointer::v1::server::{ use zwlr_virtual_pointer_manager_v1::ZwlrVirtualPointerManagerV1; use zwlr_virtual_pointer_v1::ZwlrVirtualPointerV1; +use crate::protocols::EmptyData; + const VERSION: u32 = 2; pub struct VirtualPointerManagerState { @@ -289,8 +292,6 @@ impl VirtualPointerManagerState { pub fn new(display: &DisplayHandle, filter: F) -> Self where D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: VirtualPointerHandler, D: 'static, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, @@ -306,44 +307,39 @@ impl VirtualPointerManagerState { } } -impl GlobalDispatch - for VirtualPointerManagerState +impl GlobalDispatch2 for VirtualPointerManagerGlobalData where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: VirtualPointerHandler, + D: Dispatch, D: 'static, { fn bind( + &self, _state: &mut D, _handle: &DisplayHandle, _client: &Client, manager: New, - _manager_state: &VirtualPointerManagerGlobalData, data_init: &mut DataInit<'_, D>, ) { - data_init.init(manager, ()); + data_init.init(manager, EmptyData); } - fn can_view(client: Client, global_data: &VirtualPointerManagerGlobalData) -> bool { - (global_data.filter)(&client) + fn can_view(&self, client: &Client) -> bool { + (self.filter)(client) } } -impl Dispatch for VirtualPointerManagerState +impl Dispatch2 for EmptyData where - D: Dispatch, D: Dispatch, D: VirtualPointerHandler, D: 'static, { fn request( + &self, state: &mut D, _client: &Client, _resource: &ZwlrVirtualPointerManagerV1, request: ::Request, - _data: &(), _dhandle: &DisplayHandle, data_init: &mut DataInit<'_, D>, ) { @@ -377,18 +373,17 @@ where } } -impl Dispatch for VirtualPointerManagerState +impl Dispatch2 for VirtualPointerUserData where - D: Dispatch, D: VirtualPointerHandler, D: 'static, { fn request( + &self, handler: &mut D, _client: &Client, resource: &ZwlrVirtualPointerV1, request: ::Request, - _data: &VirtualPointerUserData, _dhandle: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { @@ -528,10 +523,10 @@ where } fn destroyed( + &self, handler: &mut D, _client: wayland_backend::server::ClientId, resource: &ZwlrVirtualPointerV1, - _data: &VirtualPointerUserData, ) { let pointer = VirtualPointer { pointer: resource.clone(), @@ -544,20 +539,3 @@ where .remove(resource); } } - -#[macro_export] -macro_rules! delegate_virtual_pointer { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::virtual_pointer::v1::server::zwlr_virtual_pointer_manager_v1::ZwlrVirtualPointerManagerV1: $crate::protocols::virtual_pointer::VirtualPointerManagerGlobalData - ] => $crate::protocols::virtual_pointer::VirtualPointerManagerState); - - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::virtual_pointer::v1::server::zwlr_virtual_pointer_manager_v1::ZwlrVirtualPointerManagerV1: () - ] => $crate::protocols::virtual_pointer::VirtualPointerManagerState); - - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols_wlr::virtual_pointer::v1::server::zwlr_virtual_pointer_v1::ZwlrVirtualPointerV1: $crate::protocols::virtual_pointer::VirtualPointerUserData - ] => $crate::protocols::virtual_pointer::VirtualPointerManagerState); - }; -}