diff --git a/Cargo.toml b/Cargo.toml index 2764cc67ac83..03f49a546362 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,6 +69,26 @@ profiling = "1.0" smallvec = "1.11" pixman = { version = "0.1.0", features = ["drm-fourcc"], optional = true } +[patch.crates-io] +wayland-egl = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2"} +wayland-protocols = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" } +wayland-protocols-wlr = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" } +wayland-protocols-misc = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" } +wayland-server = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" } +wayland-client = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" } +wayland-sys = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" } +wayland-backend = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" } +wayland-scanner = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" } +# wayland-egl = { path = "../wayland-rs/wayland-egl/" } +# wayland-protocols = { path = "../wayland-rs/wayland-protocols/" } +# wayland-protocols-wlr = { path = "../wayland-rs/wayland-protocols-wlr/" } +# wayland-protocols-misc = { path = "../wayland-rs/wayland-protocols-misc/" } +# wayland-server = { path = "../wayland-rs/wayland-server/" } +# wayland-client = { path = "../wayland-rs/wayland-client/" } +# wayland-sys = { path = "../wayland-rs/wayland-sys/" } +# wayland-backend = { path = "../wayland-rs/wayland-backend/" } +# wayland-scanner = { path = "../wayland-rs/wayland-scanner/" } + [dev-dependencies] clap = { version = "4", features = ["derive"] } diff --git a/anvil/Cargo.toml b/anvil/Cargo.toml index 7b9713831d23..787762bf9f74 100644 --- a/anvil/Cargo.toml +++ b/anvil/Cargo.toml @@ -37,7 +37,7 @@ gl_generator = "0.14" [features] debug = ["fps_ticker", "image/png", "renderdoc"] -default = ["egl", "winit", "x11", "udev", "xwayland"] +default = ["egl", "x11", "udev", "xwayland"] egl = ["smithay/use_system_lib", "smithay/backend_egl"] test_all_features = ["default", "debug"] udev = [ diff --git a/anvil/src/state.rs b/anvil/src/state.rs index d394285a93b6..82b705b42931 100644 --- a/anvil/src/state.rs +++ b/anvil/src/state.rs @@ -10,12 +10,6 @@ use smithay::{ backend::renderer::element::{ default_primary_scanout_output_compare, utils::select_dmabuf_feedback, RenderElementStates, }, - delegate_compositor, delegate_data_control, delegate_data_device, delegate_fractional_scale, - delegate_input_method_manager, delegate_keyboard_shortcuts_inhibit, delegate_layer_shell, - delegate_output, delegate_pointer_constraints, delegate_pointer_gestures, delegate_presentation, - delegate_primary_selection, delegate_relative_pointer, delegate_seat, delegate_security_context, - delegate_shm, delegate_tablet_manager, delegate_text_input_manager, delegate_viewporter, - delegate_virtual_keyboard_manager, delegate_xdg_activation, delegate_xdg_decoration, delegate_xdg_shell, desktop::{ space::SpaceElement, utils::{ @@ -96,7 +90,6 @@ use crate::{ }; #[cfg(feature = "xwayland")] use smithay::{ - delegate_xwayland_keyboard_grab, utils::{Point, Size}, wayland::selection::{SelectionSource, SelectionTarget}, wayland::xwayland_keyboard_grab::{XWaylandKeyboardGrabHandler, XWaylandKeyboardGrabState}, @@ -173,8 +166,6 @@ pub struct AnvilState { pub show_window_preview: bool, } -delegate_compositor!(@ AnvilState); - impl DataDeviceHandler for AnvilState { fn data_device_state(&self) -> &DataDeviceState { &self.data_device_state @@ -194,10 +185,8 @@ impl ServerDndGrabHandler for AnvilState { unreachable!("Anvil doesn't do server-side grabs"); } } -delegate_data_device!(@ AnvilState); impl OutputHandler for AnvilState {} -delegate_output!(@ AnvilState); impl SelectionHandler for AnvilState { type SelectionUserData = (); @@ -233,7 +222,6 @@ impl PrimarySelectionHandler for AnvilState { &self.primary_selection_state } } -delegate_primary_selection!(@ AnvilState); impl DataControlHandler for AnvilState { fn data_control_state(&self) -> &DataControlState { @@ -241,14 +229,11 @@ impl DataControlHandler for AnvilState { } } -delegate_data_control!(@ AnvilState); - impl ShmHandler for AnvilState { fn shm_state(&self) -> &ShmState { &self.shm_state } } -delegate_shm!(@ AnvilState); impl SeatHandler for AnvilState { type KeyboardFocus = KeyboardFocusTarget; @@ -276,11 +261,6 @@ impl SeatHandler for AnvilState { self.backend_data.update_led_state(led_state) } } -delegate_seat!(@ AnvilState); - -delegate_tablet_manager!(@ AnvilState); - -delegate_text_input_manager!(@ AnvilState); impl InputMethodHandler for AnvilState { fn new_popup(&mut self, surface: PopupSurface) { @@ -303,8 +283,6 @@ impl InputMethodHandler for AnvilState { } } -delegate_input_method_manager!(@ AnvilState); - impl KeyboardShortcutsInhibitHandler for AnvilState { fn keyboard_shortcuts_inhibit_state(&mut self) -> &mut KeyboardShortcutsInhibitState { &mut self.keyboard_shortcuts_inhibit_state @@ -316,14 +294,6 @@ impl KeyboardShortcutsInhibitHandler for AnvilState AnvilState); - -delegate_virtual_keyboard_manager!(@ AnvilState); - -delegate_pointer_gestures!(@ AnvilState); - -delegate_relative_pointer!(@ AnvilState); - impl PointerConstraintsHandler for AnvilState { fn new_constraint(&mut self, surface: &WlSurface, pointer: &PointerHandle) { // XXX region @@ -334,9 +304,6 @@ impl PointerConstraintsHandler for AnvilState } } } -delegate_pointer_constraints!(@ AnvilState); - -delegate_viewporter!(@ AnvilState); impl XdgActivationHandler for AnvilState { fn activation_state(&mut self) -> &mut XdgActivationState { @@ -375,7 +342,6 @@ impl XdgActivationHandler for AnvilState { } } } -delegate_xdg_activation!(@ AnvilState); impl XdgDecorationHandler for AnvilState { fn new_decoration(&mut self, toplevel: ToplevelSurface) { @@ -427,11 +393,6 @@ impl XdgDecorationHandler for AnvilState { } } } -delegate_xdg_decoration!(@ AnvilState); - -delegate_xdg_shell!(@ AnvilState); -delegate_layer_shell!(@ AnvilState); -delegate_presentation!(@ AnvilState); impl FractionalScaleHandler for AnvilState { fn new_fractional_scale( @@ -480,7 +441,6 @@ impl FractionalScaleHandler for AnvilState { }); } } -delegate_fractional_scale!(@ AnvilState); impl SecurityContextHandler for AnvilState { fn context_created(&mut self, source: SecurityContextListenerSource, security_context: SecurityContext) { @@ -500,7 +460,6 @@ impl SecurityContextHandler for AnvilState AnvilState); #[cfg(feature = "xwayland")] impl XWaylandKeyboardGrabHandler for AnvilState { @@ -512,15 +471,12 @@ impl XWaylandKeyboardGrabHandler for AnvilState< Some(KeyboardFocusTarget::Window(elem.0.clone())) } } -#[cfg(feature = "xwayland")] -delegate_xwayland_keyboard_grab!(@ AnvilState); impl XdgForeignHandler for AnvilState { fn xdg_foreign_state(&mut self) -> &mut XdgForeignState { &mut self.xdg_foreign_state } } -smithay::delegate_xdg_foreign!(@ AnvilState); impl AnvilState { pub fn init( diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index f87702952eef..cf1b52bc77ea 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -50,7 +50,6 @@ use smithay::{ udev::{all_gpus, primary_gpu, UdevBackend, UdevEvent}, SwapBuffersError, }, - delegate_dmabuf, delegate_drm_lease, desktop::{ space::{Space, SurfaceTree}, utils::OutputPresentationFeedback, @@ -175,7 +174,6 @@ impl DmabufHandler for AnvilState { } } } -delegate_dmabuf!(AnvilState); impl Backend for UdevData { const HAS_RELATIVE_MOTION: bool = true; @@ -560,8 +558,6 @@ impl DrmLeaseHandler for AnvilState { } } -delegate_drm_lease!(AnvilState); - pub type RenderSurface = GbmBufferedSurface, Option>; pub type GbmDrmCompositor = DrmCompositor< diff --git a/anvil/src/winit.rs b/anvil/src/winit.rs index 0c2de8e37e96..44339793a53f 100644 --- a/anvil/src/winit.rs +++ b/anvil/src/winit.rs @@ -26,7 +26,6 @@ use smithay::{ winit::{self, WinitEvent, WinitGraphicsBackend}, SwapBuffersError, }, - delegate_dmabuf, input::{ keyboard::LedState, pointer::{CursorImageAttributes, CursorImageStatus}, @@ -81,7 +80,6 @@ impl DmabufHandler for AnvilState { } } } -delegate_dmabuf!(AnvilState); impl Backend for WinitData { fn seat_name(&self) -> String { diff --git a/anvil/src/x11.rs b/anvil/src/x11.rs index 24637d8e1631..d0ecbc5c7e73 100644 --- a/anvil/src/x11.rs +++ b/anvil/src/x11.rs @@ -30,7 +30,6 @@ use smithay::{ vulkan::{version::Version, Instance, PhysicalDevice}, x11::{WindowBuilder, X11Backend, X11Event, X11Surface}, }, - delegate_dmabuf, input::{ keyboard::LedState, pointer::{CursorImageAttributes, CursorImageStatus}, @@ -84,7 +83,6 @@ impl DmabufHandler for AnvilState { } } } -delegate_dmabuf!(AnvilState); impl Backend for X11Data { fn seat_name(&self) -> String { diff --git a/examples/compositor.rs b/examples/compositor.rs index 0a82929377e1..63fb539cae4f 100644 --- a/examples/compositor.rs +++ b/examples/compositor.rs @@ -1,6 +1,5 @@ use std::sync::Arc; -use smithay::delegate_compositor; use smithay::reexports::wayland_server::Display; use smithay::wayland::compositor::{CompositorClientState, CompositorHandler, CompositorState}; @@ -74,5 +73,3 @@ impl AsMut for App { &mut self.compositor_state } } - -delegate_compositor!(App); diff --git a/examples/minimal.rs b/examples/minimal.rs index 0aff829c5116..f883ef8b753d 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -15,7 +15,6 @@ use smithay::{ }, winit::{self, WinitEvent}, }, - delegate_compositor, delegate_data_device, delegate_seat, delegate_shm, delegate_xdg_shell, input::{keyboard::FilterResult, Seat, SeatHandler, SeatState}, reexports::wayland_server::{protocol::wl_seat, Display}, utils::{Rectangle, Serial, Transform}, @@ -289,10 +288,3 @@ impl ClientData for ClientState { println!("disconnected"); } } - -// Macros used to delegate protocol handling to types in the app state. -delegate_xdg_shell!(App); -delegate_compositor!(App); -delegate_shm!(App); -delegate_seat!(App); -delegate_data_device!(App); diff --git a/examples/seat.rs b/examples/seat.rs index 8b2afe24e02a..256ec3006b82 100644 --- a/examples/seat.rs +++ b/examples/seat.rs @@ -1,6 +1,5 @@ use std::sync::Arc; -use smithay::delegate_seat; use smithay::input::{keyboard::FilterResult, Seat, SeatHandler, SeatState}; use smithay::reexports::wayland_server::{ backend::{ClientData, ClientId, DisconnectReason}, @@ -84,5 +83,3 @@ impl ClientData for ClientState { println!("disconnected"); } } - -delegate_seat!(App); diff --git a/smallvil/src/handlers/compositor.rs b/smallvil/src/handlers/compositor.rs index d41a6b41abb5..bb8ece9c28ae 100644 --- a/smallvil/src/handlers/compositor.rs +++ b/smallvil/src/handlers/compositor.rs @@ -1,7 +1,6 @@ use crate::{grabs::resize_grab, state::ClientState, Smallvil}; use smithay::{ backend::renderer::utils::on_commit_buffer_handler, - delegate_compositor, delegate_shm, reexports::wayland_server::{ protocol::{wl_buffer, wl_surface::WlSurface}, Client, @@ -56,6 +55,3 @@ impl ShmHandler for Smallvil { &self.shm_state } } - -delegate_compositor!(Smallvil); -delegate_shm!(Smallvil); diff --git a/smallvil/src/handlers/mod.rs b/smallvil/src/handlers/mod.rs index 959564b55821..a41b6dd34b4e 100644 --- a/smallvil/src/handlers/mod.rs +++ b/smallvil/src/handlers/mod.rs @@ -15,7 +15,6 @@ use smithay::wayland::selection::data_device::{ set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, ServerDndGrabHandler, }; use smithay::wayland::selection::SelectionHandler; -use smithay::{delegate_data_device, delegate_output, delegate_seat}; impl SeatHandler for Smallvil { type KeyboardFocus = WlSurface; @@ -35,8 +34,6 @@ impl SeatHandler for Smallvil { } } -delegate_seat!(Smallvil); - // // Wl Data Device // @@ -54,11 +51,8 @@ impl DataDeviceHandler for Smallvil { impl ClientDndGrabHandler for Smallvil {} impl ServerDndGrabHandler for Smallvil {} -delegate_data_device!(Smallvil); - // // Wl Output & Xdg Output // impl OutputHandler for Smallvil {} -delegate_output!(Smallvil); diff --git a/smallvil/src/handlers/xdg_shell.rs b/smallvil/src/handlers/xdg_shell.rs index af4aaf32a8d6..6238cca98742 100644 --- a/smallvil/src/handlers/xdg_shell.rs +++ b/smallvil/src/handlers/xdg_shell.rs @@ -1,5 +1,4 @@ use smithay::{ - delegate_xdg_shell, desktop::{find_popup_root_surface, get_popup_toplevel_coords, PopupKind, PopupManager, Space, Window}, input::{ pointer::{Focus, GrabStartData as PointerGrabStartData}, @@ -123,9 +122,6 @@ impl XdgShellHandler for Smallvil { } } -// Xdg Shell -delegate_xdg_shell!(Smallvil); - fn check_grab( seat: &Seat, surface: &WlSurface, diff --git a/src/input/mod.rs b/src/input/mod.rs index 3eb66da73716..b781d4583947 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -142,7 +142,7 @@ pub mod pointer; pub mod touch; /// Handler trait for Seats -pub trait SeatHandler: Sized { +pub trait SeatHandler: Sized + 'static { /// Type used to represent the target currently holding the keyboard focus type KeyboardFocus: KeyboardTarget + 'static; /// Type used to represent the target currently holding the pointer focus @@ -307,7 +307,7 @@ impl SeatState { } } -impl Seat { +impl Seat { /// Access the `UserDataMap` associated with this `Seat` pub fn user_data(&self) -> &UserDataMap { &self.arc.user_data_map diff --git a/src/utils/user_data.rs b/src/utils/user_data.rs index 7efac2234c10..a68e6cb1e811 100644 --- a/src/utils/user_data.rs +++ b/src/utils/user_data.rs @@ -8,6 +8,18 @@ use std::thread::{self, ThreadId}; use self::list::AppendList; +// TODO: Perhaps make this public +#[cfg(feature = "wayland_frontend")] +pub(crate) trait UserdataGetter: wayland_server::Resource +where + U: 'static, + DelegatedTo: 'static, +{ + fn user_data(&self) -> Option<&U> { + self.delegated_data::<_, DelegatedTo>() + } +} + // `UserData.get()` is called frequently, and unfortunately // `thread::current().id()` is not very efficient to be calling every time. #[inline] diff --git a/src/wayland/compositor/handlers.rs b/src/wayland/compositor/handlers.rs index 301f8b342bbb..b4cd360063c1 100644 --- a/src/wayland/compositor/handlers.rs +++ b/src/wayland/compositor/handlers.rs @@ -17,6 +17,7 @@ use wayland_server::{ use crate::utils::{ alive_tracker::{AliveTracker, IsAlive}, + user_data::UserdataGetter, Logical, Point, }; @@ -35,12 +36,7 @@ use tracing::trace; impl GlobalDispatch for CompositorState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, D: CompositorHandler, - D: 'static, { fn bind( _state: &mut D, @@ -50,17 +46,13 @@ where _global_data: &(), data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } impl Dispatch for CompositorState where - D: Dispatch, - D: Dispatch, - D: Dispatch, D: CompositorHandler, - D: 'static, { fn request( state: &mut D, @@ -75,7 +67,7 @@ where wl_compositor::Request::CreateSurface { id } => { trace!(id = ?id, "Creating a new wl_surface"); - let surface = data_init.init( + let surface = data_init.init_delegated::<_, _, Self>( id, SurfaceUserData { inner: PrivateSurfaceData::new(), @@ -92,7 +84,7 @@ where wl_compositor::Request::CreateRegion { id } => { trace!(id = ?id, "Creating a new wl_region"); - data_init.init( + data_init.init_delegated::<_, _, Self>( id, RegionUserData { inner: Default::default(), @@ -154,12 +146,11 @@ pub struct SurfaceUserData { pub(super) user_state_type: (std::any::TypeId, &'static str), } +impl UserdataGetter for WlSurface {} + impl Dispatch for CompositorState where - D: Dispatch, - D: Dispatch, D: CompositorHandler, - D: 'static, { fn request( state: &mut D, @@ -217,7 +208,7 @@ where }); } wl_surface::Request::Frame { callback } => { - let callback = data_init.init(callback, ()); + let callback = data_init.init_delegated::<_, _, Self>(callback, ()); PrivateSurfaceData::with_states(surface, |states| { states @@ -229,7 +220,7 @@ where } wl_surface::Request::SetOpaqueRegion { region } => { let attributes = region.map(|r| { - let attributes_mutex = &r.data::().unwrap().inner; + let attributes_mutex = &r.user_data().unwrap().inner; attributes_mutex.lock().unwrap().clone() }); PrivateSurfaceData::with_states(surface, |states| { @@ -238,7 +229,7 @@ where } wl_surface::Request::SetInputRegion { region } => { let attributes = region.map(|r| { - let attributes_mutex = &r.data::().unwrap().inner; + let attributes_mutex = &r.user_data().unwrap().inner; attributes_mutex.lock().unwrap().clone() }); PrivateSurfaceData::with_states(surface, |states| { @@ -315,7 +306,7 @@ where impl IsAlive for WlSurface { fn alive(&self) -> bool { - let data: &SurfaceUserData = self.data().unwrap(); + let data: &SurfaceUserData = self.user_data().unwrap(); data.alive_tracker.alive() } } @@ -330,9 +321,10 @@ pub struct RegionUserData { pub(crate) inner: Mutex, } +impl UserdataGetter for WlRegion {} + impl Dispatch for CompositorState where - D: Dispatch, D: CompositorHandler, { fn request( @@ -368,11 +360,7 @@ where impl GlobalDispatch for CompositorState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: CompositorHandler, - D: 'static, { fn bind( _state: &mut D, @@ -382,16 +370,13 @@ where _global_data: &(), data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } impl Dispatch for CompositorState where - D: Dispatch, - D: Dispatch, D: CompositorHandler, - D: 'static, { fn request( state: &mut D, @@ -410,7 +395,7 @@ where return; } - data_init.init( + data_init.init_delegated::<_, _, Self>( id, SubsurfaceUserData { surface: surface.clone(), @@ -504,11 +489,11 @@ pub fn is_effectively_sync(surface: &wl_surface::WlSurface) -> bool { } } +impl UserdataGetter for WlSubsurface {} + impl Dispatch for CompositorState where - D: Dispatch, D: CompositorHandler, - D: 'static, { fn request( _state: &mut D, @@ -586,9 +571,7 @@ where impl Dispatch for CompositorState where - D: Dispatch, D: CompositorHandler, - D: 'static, { fn request( _state: &mut D, diff --git a/src/wayland/compositor/mod.rs b/src/wayland/compositor/mod.rs index 429bf15d9a70..1cb41a7f22af 100644 --- a/src/wayland/compositor/mod.rs +++ b/src/wayland/compositor/mod.rs @@ -30,7 +30,6 @@ //! ``` //! # extern crate wayland_server; //! # #[macro_use] extern crate smithay; -//! use smithay::delegate_compositor; //! use smithay::wayland::compositor::{CompositorState, CompositorClientState, CompositorHandler}; //! //! # struct State { compositor_state: CompositorState } @@ -60,7 +59,6 @@ //! // .. your implementation .. //! } //! } -//! delegate_compositor!(State); //! //! // You're now ready to go! //! ``` @@ -121,13 +119,14 @@ use self::transaction::TransactionQueue; pub use self::transaction::{Blocker, BlockerState}; pub use self::tree::{AlreadyHasRole, TraversalAction}; use self::tree::{PrivateSurfaceData, SuggestedSurfaceState}; +use crate::utils::user_data::UserdataGetter; use crate::utils::Transform; use crate::utils::{user_data::UserDataMap, Buffer, Logical, Point, Rectangle}; use wayland_server::backend::GlobalId; use wayland_server::protocol::wl_compositor::WlCompositor; use wayland_server::protocol::wl_subcompositor::WlSubcompositor; use wayland_server::protocol::{wl_buffer, wl_callback, wl_output, wl_region, wl_surface::WlSurface}; -use wayland_server::{Client, DisplayHandle, GlobalDispatch, Resource}; +use wayland_server::{Client, DisplayHandle, Resource}; /// The role of a subsurface surface. pub const SUBSURFACE_ROLE: &str = "subsurface"; @@ -434,7 +433,7 @@ pub fn send_surface_state(surface: &WlSurface, data: &SurfaceData, scale: i32, t /// If the region is not managed by the `CompositorGlobal` that provided this token, this /// will panic (having more than one compositor is not supported). pub fn get_region_attributes(region: &wl_region::WlRegion) -> RegionAttributes { - match region.data::() { + match region.user_data() { Some(data) => data.inner.lock().unwrap().clone(), None => panic!("Accessing the data of foreign regions is not supported."), } @@ -448,7 +447,7 @@ where F: Fn(&mut D, &DisplayHandle, &WlSurface) + Send + Sync + 'static, D: 'static, { - let (user_state_type_id, user_state_type) = surface.data::().unwrap().user_state_type; + let (user_state_type_id, user_state_type) = surface.user_data().unwrap().user_state_type; assert_eq!( std::any::TypeId::of::(), user_state_type_id, @@ -472,7 +471,7 @@ where F: Fn(&mut D, &DisplayHandle, &WlSurface) + Send + Sync + 'static, D: 'static, { - let (user_state_type_id, user_state_type) = surface.data::().unwrap().user_state_type; + let (user_state_type_id, user_state_type) = surface.user_data().unwrap().user_state_type; assert_eq!( std::any::TypeId::of::(), user_state_type_id, @@ -499,7 +498,7 @@ where F: Fn(&mut D, &WlSurface) + Send + Sync + 'static, D: 'static, { - let (user_state_type_id, user_state_type) = surface.data::().unwrap().user_state_type; + let (user_state_type_id, user_state_type) = surface.user_data().unwrap().user_state_type; assert_eq!( std::any::TypeId::of::(), user_state_type_id, @@ -544,7 +543,7 @@ pub fn add_blocker(surface: &WlSurface, blocker: impl Blocker + Send + 'static) } /// Handler trait for compositor -pub trait CompositorHandler { +pub trait CompositorHandler: 'static { /// [CompositorState] getter fn compositor_state(&mut self) -> &mut CompositorState; /// [CompositorClientState] getter @@ -633,7 +632,7 @@ impl CompositorState { /// [`wl_subcompositor`]: wayland_server::protocol::wl_subcompositor pub fn new(display: &DisplayHandle) -> Self where - D: GlobalDispatch + GlobalDispatch + 'static, + D: CompositorHandler, { Self::new_with_version::(display, 5) } @@ -647,17 +646,17 @@ impl CompositorState { /// [`wl_compositor`]: wayland_server::protocol::wl_compositor pub fn new_v6(display: &DisplayHandle) -> Self where - D: GlobalDispatch + GlobalDispatch + 'static, + D: CompositorHandler, { Self::new_with_version::(display, 6) } fn new_with_version(display: &DisplayHandle, version: u32) -> Self where - D: GlobalDispatch + GlobalDispatch + 'static, + D: CompositorHandler, { - let compositor = display.create_global::(version, ()); - let subcompositor = display.create_global::(1, ()); + let compositor = display.create_delegated_global::(version, ()); + let subcompositor = display.create_delegated_global::(1, ()); CompositorState { compositor, @@ -677,37 +676,11 @@ impl CompositorState { } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_compositor { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_compositor::WlCompositor: () - ] => $crate::wayland::compositor::CompositorState); - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_subcompositor::WlSubcompositor: () - ] => $crate::wayland::compositor::CompositorState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_compositor::WlCompositor: () - ] => $crate::wayland::compositor::CompositorState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_surface::WlSurface: $crate::wayland::compositor::SurfaceUserData - ] => $crate::wayland::compositor::CompositorState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_region::WlRegion: $crate::wayland::compositor::RegionUserData - ] => $crate::wayland::compositor::CompositorState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_callback::WlCallback: () - ] => $crate::wayland::compositor::CompositorState); - // WlSubcompositor - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_subcompositor::WlSubcompositor: () - ] => $crate::wayland::compositor::CompositorState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_subsurface::WlSubsurface: $crate::wayland::compositor::SubsurfaceUserData - ] => $crate::wayland::compositor::CompositorState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } #[cfg(test)] diff --git a/src/wayland/compositor/tree.rs b/src/wayland/compositor/tree.rs index 4ad59209c363..81166c6c481c 100644 --- a/src/wayland/compositor/tree.rs +++ b/src/wayland/compositor/tree.rs @@ -1,4 +1,7 @@ -use crate::{utils::Serial, wayland::compositor::SUBSURFACE_ROLE}; +use crate::{ + utils::{user_data::UserdataGetter, Serial}, + wayland::compositor::SUBSURFACE_ROLE, +}; use super::{ cache::MultiCache, @@ -123,13 +126,13 @@ impl PrivateSurfaceData { let mut my_data = my_data_mutex.lock().unwrap(); if let Some(old_parent) = my_data.parent.take() { // We had a parent, lets unregister ourselves from it - let old_parent_mutex = &old_parent.data::().unwrap().inner; + let old_parent_mutex = &old_parent.user_data().unwrap().inner; let mut old_parent_guard = old_parent_mutex.lock().unwrap(); old_parent_guard.children.retain(|c| c.id() != surface.id()); } // orphan all our children for child in my_data.children.drain(..) { - let child_mutex = &child.data::().unwrap().inner; + let child_mutex = &child.user_data().unwrap().inner; if std::ptr::eq(child_mutex, my_data_mutex) { // This child is ourselves, don't do anything. continue; @@ -166,7 +169,7 @@ impl PrivateSurfaceData { } pub fn lock_user_data(surface: &WlSurface) -> MutexGuard<'_, PrivateSurfaceData> { - surface.data::().unwrap().inner.lock().unwrap() + surface.user_data().unwrap().inner.lock().unwrap() } pub fn set_role(surface: &WlSurface, role: &'static str) -> Result<(), AlreadyHasRole> { diff --git a/src/wayland/content_type/dispatch.rs b/src/wayland/content_type/dispatch.rs index b8e49089bea3..32f719595af3 100644 --- a/src/wayland/content_type/dispatch.rs +++ b/src/wayland/content_type/dispatch.rs @@ -11,9 +11,6 @@ use crate::wayland::compositor; impl GlobalDispatch for ContentTypeState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: 'static, { fn bind( @@ -24,20 +21,18 @@ where _: &(), data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } impl Dispatch for ContentTypeState where - D: Dispatch, - D: Dispatch, D: 'static, { fn request( _state: &mut D, _: &Client, - manager: &wp_content_type_manager_v1::WpContentTypeManagerV1, + manager: &WpContentTypeManagerV1, request: wp_content_type_manager_v1::Request, _data: &(), _dh: &DisplayHandle, @@ -66,7 +61,7 @@ where "WlSurface already has WpSurfaceContentType attached", ) } else { - data_init.init(id, ContentTypeUserData::new(surface)); + data_init.init_delegated::<_, _, Self>(id, ContentTypeUserData::new(surface)); } } @@ -76,10 +71,7 @@ where } } -impl Dispatch for ContentTypeState -where - D: Dispatch, -{ +impl Dispatch for ContentTypeState { fn request( _state: &mut D, _: &Client, diff --git a/src/wayland/content_type/mod.rs b/src/wayland/content_type/mod.rs index 18d6a3c715f8..b37723e2948d 100644 --- a/src/wayland/content_type/mod.rs +++ b/src/wayland/content_type/mod.rs @@ -7,7 +7,6 @@ //! # //! use wayland_server::{protocol::wl_surface::WlSurface, DisplayHandle}; //! use smithay::{ -//! delegate_content_type, delegate_compositor, //! wayland::compositor::{self, CompositorState, CompositorClientState, CompositorHandler}, //! wayland::content_type::{ContentTypeSurfaceCachedState, ContentTypeState}, //! }; @@ -18,9 +17,6 @@ //! struct ClientState { compositor_state: CompositorClientState } //! impl wayland_server::backend::ClientData for ClientState {} //! -//! delegate_content_type!(State); -//! delegate_compositor!(State); -//! //! impl CompositorHandler for State { //! fn compositor_state(&mut self) -> &mut CompositorState { //! &mut self.compositor_state @@ -54,13 +50,9 @@ use std::sync::{ }; use wayland_protocols::wp::content_type::v1::server::{ - wp_content_type_manager_v1::WpContentTypeManagerV1, - wp_content_type_v1::{self, WpContentTypeV1}, -}; -use wayland_server::{ - backend::GlobalId, protocol::wl_surface::WlSurface, Dispatch, DisplayHandle, GlobalDispatch, Resource, - Weak, + wp_content_type_manager_v1::WpContentTypeManagerV1, wp_content_type_v1, }; +use wayland_server::{backend::GlobalId, protocol::wl_surface::WlSurface, DisplayHandle, Resource, Weak}; use super::compositor::Cacheable; @@ -155,12 +147,9 @@ impl ContentTypeState { /// Regiseter new [WpContentTypeManagerV1] global pub fn new(display: &DisplayHandle) -> ContentTypeState where - D: GlobalDispatch - + Dispatch - + Dispatch - + 'static, + D: 'static, { - let global = display.create_global::(1, ()); + let global = display.create_delegated_global::(1, ()); ContentTypeState { global } } @@ -172,30 +161,8 @@ impl ContentTypeState { } /// Macro to delegate implementation of the wp content type protocol +#[deprecated(note = "No longer needed, this is now NOP")] #[macro_export] macro_rules! delegate_content_type { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - type __WpContentTypeManagerV1 = - $crate::reexports::wayland_protocols::wp::content_type::v1::server::wp_content_type_manager_v1::WpContentTypeManagerV1; - type __WpContentTypeV1 = - $crate::reexports::wayland_protocols::wp::content_type::v1::server::wp_content_type_v1::WpContentTypeV1; - - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __WpContentTypeManagerV1: () - ] => $crate::wayland::content_type::ContentTypeState - ); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __WpContentTypeManagerV1: () - ] => $crate::wayland::content_type::ContentTypeState - ); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __WpContentTypeV1: $crate::wayland::content_type::ContentTypeUserData - ] => $crate::wayland::content_type::ContentTypeState - ); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/cursor_shape.rs b/src/wayland/cursor_shape.rs index d2b582831447..e6517d16f3a1 100644 --- a/src/wayland/cursor_shape.rs +++ b/src/wayland/cursor_shape.rs @@ -10,7 +10,6 @@ //! extern crate wayland_server; //! //! use smithay::wayland::cursor_shape::CursorShapeManagerState; -//! use smithay::delegate_cursor_shape; //! //! # use smithay::backend::input::KeyState; //! # use smithay::input::{ @@ -92,8 +91,6 @@ //! # } //! //! let state = CursorShapeManagerState::new::(&display.handle()); -//! -//! delegate_cursor_shape!(State); //! ``` use wayland_protocols::wp::cursor_shape::v1::server::wp_cursor_shape_device_v1::Request as ShapeRequest; @@ -110,10 +107,11 @@ use wayland_server::{backend::GlobalId, Dispatch, DisplayHandle}; use crate::input::pointer::{CursorIcon, CursorImageStatus}; use crate::input::SeatHandler; +use crate::input::SeatState; +use crate::utils::user_data::UserdataGetter; use crate::wayland::seat::WaylandFocus; use super::seat::PointerUserData; -use super::tablet_manager::TabletToolUserData; /// State of the cursor shape manager. #[derive(Debug)] @@ -125,12 +123,10 @@ impl CursorShapeManagerState { /// Register new [CursorShapeManager] global. pub fn new(display: &DisplayHandle) -> Self where - D: GlobalDispatch, - D: Dispatch, D: SeatHandler, - D: 'static, + ::PointerFocus: WaylandFocus, { - let global = display.create_global::(1, ()); + let global = display.create_delegated_global::(1, ()); Self { global } } @@ -142,10 +138,8 @@ impl CursorShapeManagerState { impl GlobalDispatch for CursorShapeManagerState where - D: GlobalDispatch, - D: Dispatch, D: SeatHandler, - D: 'static, + ::PointerFocus: WaylandFocus, { fn bind( _state: &mut D, @@ -155,16 +149,14 @@ where _global_data: &(), data_init: &mut wayland_server::DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } impl Dispatch for CursorShapeManagerState where - D: Dispatch, - D: Dispatch, D: SeatHandler, - D: 'static, + ::PointerFocus: WaylandFocus, { fn request( _state: &mut D, @@ -180,7 +172,7 @@ where cursor_shape_device, pointer, } => { - data_init.init( + data_init.init_delegated::<_, _, Self>( cursor_shape_device, CursorShapeDeviceUserData(CursorShapeDeviceUserDataInner::Pointer(pointer)), ); @@ -189,7 +181,7 @@ where cursor_shape_device, tablet_tool, } => { - data_init.init( + data_init.init_delegated::<_, _, Self>( cursor_shape_device, CursorShapeDeviceUserData(CursorShapeDeviceUserDataInner::Tablet(tablet_tool)), ); @@ -214,11 +206,8 @@ pub(crate) enum CursorShapeDeviceUserDataInner { impl Dispatch for CursorShapeManagerState where - D: Dispatch, - D: Dispatch, D: SeatHandler, ::PointerFocus: WaylandFocus, - D: 'static, { fn request( state: &mut D, @@ -236,7 +225,7 @@ where } => { match &data.0 { CursorShapeDeviceUserDataInner::Pointer(pointer) => { - let pointer_data = pointer.data::>(); + let pointer_data = pointer.delegated_data::, SeatState>(); let handle = match pointer_data.and_then(|data| data.handle.as_ref()) { Some(handle) => handle, None => return, @@ -276,7 +265,7 @@ where } } CursorShapeDeviceUserDataInner::Tablet(tablet) => { - let tablet_data = match tablet.data::() { + let tablet_data = match tablet.user_data() { Some(data) => data, None => return, }; @@ -352,18 +341,9 @@ fn shape_to_cursor_icon(shape: Shape) -> CursorIcon { } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_cursor_shape { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::cursor_shape::v1::server::wp_cursor_shape_manager_v1::WpCursorShapeManagerV1: () - ] => $crate::wayland::cursor_shape::CursorShapeManagerState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::cursor_shape::v1::server::wp_cursor_shape_manager_v1::WpCursorShapeManagerV1: () - ] => $crate::wayland::cursor_shape::CursorShapeManagerState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::cursor_shape::v1::server::wp_cursor_shape_device_v1::WpCursorShapeDeviceV1: $crate::wayland::cursor_shape::CursorShapeDeviceUserData - ] => $crate::wayland::cursor_shape::CursorShapeManagerState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/dmabuf/dispatch.rs b/src/wayland/dmabuf/dispatch.rs index 436d7dc255b8..01bce52eb4b7 100644 --- a/src/wayland/dmabuf/dispatch.rs +++ b/src/wayland/dmabuf/dispatch.rs @@ -1,15 +1,18 @@ use std::sync::{atomic::AtomicBool, Mutex}; use wayland_protocols::wp::linux_dmabuf::zv1::server::{ - zwp_linux_buffer_params_v1, zwp_linux_dmabuf_feedback_v1, zwp_linux_dmabuf_v1, + zwp_linux_buffer_params_v1::{self, ZwpLinuxBufferParamsV1}, + zwp_linux_dmabuf_feedback_v1::{self, ZwpLinuxDmabufFeedbackV1}, + zwp_linux_dmabuf_v1::{self, ZwpLinuxDmabufV1}, }; use wayland_server::{ - protocol::wl_buffer, Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, + protocol::wl_buffer::{self, WlBuffer}, + Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, }; use crate::{ backend::allocator::dmabuf::{Dmabuf, Plane, MAX_PLANES}, - wayland::{buffer::BufferHandler, compositor}, + wayland::compositor, }; use super::{ @@ -17,14 +20,14 @@ use super::{ DmabufState, Import, ImportNotifier, Modifier, SurfaceDmabufFeedbackState, }; -impl Dispatch for DmabufState +impl Dispatch for DmabufState where - D: Dispatch + BufferHandler, + D: DmabufHandler, { fn request( data: &mut D, _client: &Client, - buffer: &wl_buffer::WlBuffer, + buffer: &WlBuffer, request: wl_buffer::Request, _udata: &Dmabuf, _dh: &DisplayHandle, @@ -40,18 +43,14 @@ where } } -impl Dispatch for DmabufState +impl Dispatch for DmabufState where - D: Dispatch - + Dispatch - + Dispatch - + DmabufHandler - + 'static, + D: DmabufHandler, { fn request( state: &mut D, _client: &Client, - _resource: &zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1, + _resource: &ZwpLinuxDmabufV1, request: zwp_linux_dmabuf_v1::Request, data: &DmabufData, _dh: &DisplayHandle, @@ -61,7 +60,7 @@ where zwp_linux_dmabuf_v1::Request::Destroy => {} zwp_linux_dmabuf_v1::Request::CreateParams { params_id } => { - data_init.init( + data_init.init_delegated::<_, _, Self>( params_id, DmabufParamsData { id: data.id, @@ -74,7 +73,7 @@ where } zwp_linux_dmabuf_v1::Request::GetDefaultFeedback { id } => { - let feedback = data_init.init( + let feedback = data_init.init_delegated::<_, _, Self>( id, DmabufFeedbackData { known_default_feedbacks: data.known_default_feedbacks.clone(), @@ -96,7 +95,7 @@ where } zwp_linux_dmabuf_v1::Request::GetSurfaceFeedback { id, surface } => { - let feedback = data_init.init( + let feedback = data_init.init_delegated::<_, _, Self>( id, DmabufFeedbackData { known_default_feedbacks: data.known_default_feedbacks.clone(), @@ -126,19 +125,15 @@ where } } -impl Dispatch - for DmabufState +impl Dispatch for DmabufState where - D: Dispatch - + Dispatch - + Dispatch - + 'static, + D: DmabufHandler, { fn request( _state: &mut D, _client: &Client, - resource: &zwp_linux_dmabuf_feedback_v1::ZwpLinuxDmabufFeedbackV1, - request: ::Request, + resource: &ZwpLinuxDmabufFeedbackV1, + request: zwp_linux_dmabuf_feedback_v1::Request, data: &DmabufFeedbackData, _dhandle: &DisplayHandle, _data_init: &mut DataInit<'_, D>, @@ -163,18 +158,15 @@ where } } -impl GlobalDispatch for DmabufState +impl GlobalDispatch for DmabufState where - D: GlobalDispatch - + Dispatch - + Dispatch - + 'static, + D: DmabufHandler, { fn bind( _state: &mut D, _dh: &DisplayHandle, _client: &Client, - resource: New, + resource: New, global_data: &DmabufGlobalData, data_init: &mut DataInit<'_, D>, ) { @@ -185,7 +177,7 @@ where known_default_feedbacks: global_data.known_default_feedbacks.clone(), }; - let zwp_dmabuf = data_init.init(resource, data); + let zwp_dmabuf = data_init.init_delegated::<_, _, Self>(resource, data); // Immediately send format info to the client if we are the correct version. // @@ -214,17 +206,14 @@ where } } -impl Dispatch for DmabufState +impl Dispatch for DmabufState where - D: Dispatch - + Dispatch - + BufferHandler - + DmabufHandler, + D: DmabufHandler, { fn request( state: &mut D, _client: &Client, - params: &zwp_linux_buffer_params_v1::ZwpLinuxBufferParamsV1, + params: &ZwpLinuxBufferParamsV1, request: zwp_linux_buffer_params_v1::Request, data: &DmabufParamsData, dh: &DisplayHandle, @@ -324,7 +313,7 @@ where if let Some(dmabuf) = data.create_dmabuf(params, width, height, format, flags, None) { if state.dmabuf_state().globals.get(&data.id).is_some() { // The buffer isn't technically valid during data_init, but the client is not allowed to use the buffer until ready. - let buffer = data_init.init(buffer_id, dmabuf.clone()); + let buffer = data_init.init_delegated::<_, _, Self>(buffer_id, dmabuf.clone()); let notifier = ImportNotifier::new( params.clone(), dh.clone(), diff --git a/src/wayland/dmabuf/mod.rs b/src/wayland/dmabuf/mod.rs index feeef28c4c2a..6bd34c10eefc 100644 --- a/src/wayland/dmabuf/mod.rs +++ b/src/wayland/dmabuf/mod.rs @@ -17,7 +17,6 @@ //! //! ```no_run //! use smithay::{ -//! delegate_dmabuf, //! backend::allocator::dmabuf::{Dmabuf}, //! reexports::{ //! wayland_server::protocol::{ @@ -73,9 +72,6 @@ //! } //! } //! -//! // Delegate dmabuf handling for State to DmabufState. -//! delegate_dmabuf!(State); -//! //! # let mut display = wayland_server::Display::::new().unwrap(); //! # let display_handle = display.handle(); //! // First a DmabufState must be created. This type is used to create some "DmabufGlobal"s @@ -140,7 +136,6 @@ //! ```no_run //! # extern crate wayland_server; //! # use smithay::{ -//! # delegate_dmabuf, //! # backend::allocator::dmabuf::Dmabuf, //! # reexports::{wayland_server::protocol::wl_buffer::WlBuffer}, //! # wayland::{ @@ -161,7 +156,6 @@ //! # } //! # fn dmabuf_imported(&mut self, global: &DmabufGlobal, dmabuf: Dmabuf, notifier: ImportNotifier) {} //! # } -//! # delegate_dmabuf!(State); //! # let mut display = wayland_server::Display::::new().unwrap(); //! # let display_handle = display.handle(); //! # let mut dmabuf_state = DmabufState::new(); @@ -210,7 +204,7 @@ use wayland_server::{ wl_buffer::{self, WlBuffer}, wl_surface::WlSurface, }, - Client, Dispatch, DisplayHandle, GlobalDispatch, Resource, WEnum, + Client, DisplayHandle, Resource, WEnum, }; #[cfg(feature = "backend_drm")] @@ -595,10 +589,7 @@ impl DmabufState { /// if you want to create a version 4 global you need to call [`DmabufState::create_global_with_default_feedback`]. pub fn create_global(&mut self, display: &DisplayHandle, formats: Vec) -> DmabufGlobal where - D: GlobalDispatch - + BufferHandler - + DmabufHandler - + 'static, + D: DmabufHandler, { self.create_global_with_filter::(display, formats, |_| true) } @@ -618,10 +609,7 @@ impl DmabufState { filter: F, ) -> DmabufGlobal where - D: GlobalDispatch - + BufferHandler - + DmabufHandler - + 'static, + D: DmabufHandler, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, { self.create_global_with_filter_and_optional_default_feedback::( @@ -641,10 +629,7 @@ impl DmabufState { default_feedback: &DmabufFeedback, ) -> DmabufGlobal where - D: GlobalDispatch - + BufferHandler - + DmabufHandler - + 'static, + D: DmabufHandler, { self.create_global_with_filter_and_default_feedback::(display, default_feedback, |_| true) } @@ -663,10 +648,7 @@ impl DmabufState { filter: F, ) -> DmabufGlobal where - D: GlobalDispatch - + BufferHandler - + DmabufHandler - + 'static, + D: DmabufHandler, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, { self.create_global_with_filter_and_optional_default_feedback::( @@ -685,10 +667,7 @@ impl DmabufState { filter: F, ) -> DmabufGlobal where - D: GlobalDispatch - + BufferHandler - + DmabufHandler - + 'static, + D: DmabufHandler, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, { let id = next_global_id(); @@ -723,7 +702,8 @@ impl DmabufState { id, }; - let global = display.create_global::(version, data); + let global = display + .create_delegated_global::(version, data); self.globals.insert( id, DmabufGlobalState { @@ -873,18 +853,14 @@ impl ImportNotifier { /// This can return [`InvalidId`] if the client the buffer was imported from has died. pub fn successful(mut self) -> Result where - D: Dispatch - + Dispatch - + BufferHandler - + DmabufHandler - + 'static, + D: DmabufHandler, { let client = self.inner.client(); let result = match self.import { Import::Falliable => { if let Some(client) = client { - match client.create_resource::( + match client.create_delegated_resource::( &self.display, 1, self.dmabuf.clone(), @@ -982,7 +958,7 @@ impl Drop for ImportNotifier { } /// Handler trait for [`Dmabuf`] import from the compositor. -pub trait DmabufHandler: BufferHandler { +pub trait DmabufHandler: BufferHandler + 'static { /// Returns a mutable reference to the [`DmabufState`] delegate type. fn dmabuf_state(&mut self) -> &mut DmabufState; @@ -1020,40 +996,19 @@ pub trait DmabufHandler: BufferHandler { /// /// [`WlBuffer`]: wl_buffer::WlBuffer pub fn get_dmabuf(buffer: &wl_buffer::WlBuffer) -> Result { - buffer.data::().cloned().ok_or(UnmanagedResource) + buffer + .delegated_data::() + .cloned() + .ok_or(UnmanagedResource) } /// Macro to delegate implementation of the linux dmabuf to [`DmabufState`]. /// /// You must also implement [`DmabufHandler`] to use this. +#[deprecated(note = "No longer needed, this is now NOP")] #[macro_export] macro_rules! delegate_dmabuf { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - type __ZwpLinuxDmabufV1 = - $crate::reexports::wayland_protocols::wp::linux_dmabuf::zv1::server::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1; - type __ZwpLinuxBufferParamsV1 = - $crate::reexports::wayland_protocols::wp::linux_dmabuf::zv1::server::zwp_linux_buffer_params_v1::ZwpLinuxBufferParamsV1; - type __ZwpLinuxDmabufFeedbackv1 = - $crate::reexports::wayland_protocols::wp::linux_dmabuf::zv1::server::zwp_linux_dmabuf_feedback_v1::ZwpLinuxDmabufFeedbackV1; - - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - __ZwpLinuxDmabufV1: $crate::wayland::dmabuf::DmabufGlobalData - ] => $crate::wayland::dmabuf::DmabufState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - __ZwpLinuxDmabufV1: $crate::wayland::dmabuf::DmabufData - ] => $crate::wayland::dmabuf::DmabufState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - __ZwpLinuxBufferParamsV1: $crate::wayland::dmabuf::DmabufParamsData - ] => $crate::wayland::dmabuf::DmabufState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_buffer::WlBuffer: $crate::backend::allocator::dmabuf::Dmabuf - ] => $crate::wayland::dmabuf::DmabufState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - __ZwpLinuxDmabufFeedbackv1: $crate::wayland::dmabuf::DmabufFeedbackData - ] => $crate::wayland::dmabuf::DmabufState); - - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } impl DmabufParamsData { diff --git a/src/wayland/drm_lease/mod.rs b/src/wayland/drm_lease/mod.rs index ff5693c02b8c..2b536e6c351c 100644 --- a/src/wayland/drm_lease/mod.rs +++ b/src/wayland/drm_lease/mod.rs @@ -18,7 +18,6 @@ //! allows you to add additional needed DRM resources to the lease and accept or decline the request. //! //! ```no_run -//! # use smithay::delegate_drm_lease; //! # use smithay::wayland::drm_lease::*; //! # use smithay::backend::drm::{DrmDevice, DrmNode}; //! @@ -49,8 +48,6 @@ //! fn lease_destroyed(&mut self, node: DrmNode, lease_id: u32) { self.active_leases.retain(|l| l.id() != lease_id); } //! } //! -//! delegate_drm_lease!(State); -//! //! # let mut display = wayland_server::Display::::new().unwrap(); //! # let display_handle = display.handle(); //! # let drm_device: DrmDevice = todo!(); @@ -87,8 +84,11 @@ use std::{ use drm::control::{connector, crtc, plane, Device, RawResourceHandle}; use rustix::fs::OFlags; -use wayland_protocols::wp::drm_lease::v1::server::*; -use wayland_server::backend::GlobalId; +use wayland_protocols::wp::drm_lease::v1::server::{ + wp_drm_lease_connector_v1::WpDrmLeaseConnectorV1, wp_drm_lease_device_v1::WpDrmLeaseDeviceV1, + wp_drm_lease_request_v1::WpDrmLeaseRequestV1, wp_drm_lease_v1::WpDrmLeaseV1, *, +}; +use wayland_server::backend::{ClientId, GlobalId}; use wayland_server::{Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource}; use crate::backend::drm::{DrmDevice, DrmDeviceFd, DrmNode, NodeType}; @@ -111,14 +111,14 @@ struct DrmLeaseConnector { node: DrmNode, handle: connector::Handle, enabled: bool, - known_instances: Vec, + known_instances: Vec, } /// Data attached to wp_drm_lease_request_v1 objects #[derive(Debug)] pub struct DrmLeaseRequestData { node: DrmNode, - connectors: Mutex>, + connectors: Mutex>, } /// DRM lease request containing a set of requested connectors @@ -197,7 +197,7 @@ pub struct DrmLease { connectors: HashSet, crtcs: HashSet, lease_id: NonZeroU32, - obj: Arc>>, + obj: Arc>>, fd: Arc>>, revoked: Arc, } @@ -220,7 +220,7 @@ impl DrmLease { self.lease_id.get() } - fn set_obj(&self, obj: wp_drm_lease_v1::WpDrmLeaseV1) { + fn set_obj(&self, obj: WpDrmLeaseV1) { *self.obj.lock().unwrap() = Some(obj); } fn take_fd(&mut self) -> Option { @@ -231,7 +231,7 @@ impl DrmLease { #[derive(Debug)] struct DrmLeaseRef { drm: DrmDeviceFd, - obj: Weak>>, + obj: Weak>>, lease_id: NonZeroU32, revoked: Arc, connectors: HashSet, @@ -299,14 +299,7 @@ impl LeaseRejected { } /// Handler trait for drm leasing from the compositor. -pub trait DrmLeaseHandler: - GlobalDispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + 'static -{ +pub trait DrmLeaseHandler: 'static { /// Returns a mutable reference to the [`DrmLeaseState`] delegate type fn drm_lease_state(&mut self, node: DrmNode) -> &mut DrmLeaseState; /// A client has issued a new request. @@ -383,13 +376,7 @@ impl DrmLeaseState { /// Create a new DRM lease global for a given [`DrmNode`]. pub fn new(display: &DisplayHandle, drm_node: &DrmNode) -> Result where - D: DrmLeaseHandler - + GlobalDispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + 'static, + D: DrmLeaseHandler, { Self::new_with_filter::(display, drm_node, |_| true) } @@ -403,13 +390,7 @@ impl DrmLeaseState { filter: F, ) -> Result where - D: DrmLeaseHandler - + GlobalDispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + 'static, + D: DrmLeaseHandler, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, { let path = drm_node @@ -425,7 +406,7 @@ impl DrmLeaseState { node: *drm_node, }; - let global = display.create_global::(1, data); + let global = display.create_delegated_global::(1, data); Ok(DrmLeaseState { node: *drm_node, @@ -440,13 +421,7 @@ impl DrmLeaseState { /// Add a connector, that is free to be leased to clients. pub fn add_connector(&mut self, connector: connector::Handle, name: String, description: String) where - D: DrmLeaseHandler - + GlobalDispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + 'static, + D: DrmLeaseHandler, { if self.connectors.iter().any(|conn| conn.handle == connector) { return; @@ -456,9 +431,7 @@ impl DrmLeaseState { for instance in &self.known_lease_devices { if let Ok(client) = self.dh.get_client(instance.id()) { if let Ok(lease_connector) = client - .create_resource::( - &self.dh, 1, self.node, - ) + .create_delegated_resource::(&self.dh, 1, self.node) { instance.connector(&lease_connector); lease_connector.name(name.clone()); @@ -538,26 +511,14 @@ impl DrmLeaseState { /// Resume all connectors temporarily (e.g. upon gaining DRM master as the session becomes active) pub fn resume(&mut self) where - D: DrmLeaseHandler - + GlobalDispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + 'static, + D: DrmLeaseHandler, { self.resume_internal::(None); } fn resume_internal(&mut self, connectors: Option<&HashSet>) where - D: DrmLeaseHandler - + GlobalDispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + 'static, + D: DrmLeaseHandler, { for (instance, client) in self .known_lease_devices @@ -591,13 +552,7 @@ impl DrmLeaseState { fn remove_lease(&mut self, id: u32) -> Option where - D: DrmLeaseHandler - + GlobalDispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + 'static, + D: DrmLeaseHandler, { let lease_ref = { if let Some(pos) = self @@ -624,13 +579,7 @@ impl DrmLeaseState { /// Disable the global, it will no longer be advertised to new clients pub fn disable_global(&mut self) where - D: DrmLeaseHandler - + GlobalDispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + 'static, + D: DrmLeaseHandler, { if let Some(global) = self.global.take() { self.dh.disable_global::(global); @@ -658,22 +607,12 @@ impl Drop for DrmLeaseState { } impl DrmLeaseConnector { - fn new_instance( - &mut self, - dh: &DisplayHandle, - client: &Client, - ) -> Option + fn new_instance(&mut self, dh: &DisplayHandle, client: &Client) -> Option where - D: DrmLeaseHandler - + GlobalDispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + 'static, + D: DrmLeaseHandler, { if let Ok(lease_connector) = - client.create_resource::(dh, 1, self.node) + client.create_delegated_resource::(dh, 1, self.node) { self.known_instances.push(lease_connector.clone()); @@ -683,7 +622,7 @@ impl DrmLeaseConnector { } } - fn send_info(&self, connector: &wp_drm_lease_connector_v1::WpDrmLeaseConnectorV1) { + fn send_info(&self, connector: &WpDrmLeaseConnectorV1) { connector.name(self.name.clone()); connector.description(self.description.clone()); connector.connector_id(self.handle.into()); @@ -691,27 +630,20 @@ impl DrmLeaseConnector { } } -impl GlobalDispatch - for DrmLeaseState +impl GlobalDispatch for DrmLeaseState where - D: DrmLeaseHandler - + GlobalDispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + 'static, + D: DrmLeaseHandler, { fn bind( state: &mut D, dh: &DisplayHandle, client: &Client, - resource: New, + resource: New, global_data: &DrmLeaseDeviceGlobalData, data_init: &mut DataInit<'_, D>, ) { let drm_lease_state = state.drm_lease_state(global_data.node); - let wp_drm_lease_device = data_init.init(resource, global_data.node); + let wp_drm_lease_device = data_init.init_delegated::<_, _, Self>(resource, global_data.node); let Ok(fd) = get_non_master_fd(&global_data.path) else { // nothing we can do @@ -736,28 +668,22 @@ where } } -impl Dispatch for DrmLeaseState +impl Dispatch for DrmLeaseState where - D: DrmLeaseHandler - + GlobalDispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + 'static, + D: DrmLeaseHandler, { fn request( state: &mut D, _client: &Client, - resource: &wp_drm_lease_device_v1::WpDrmLeaseDeviceV1, - request: ::Request, + resource: &WpDrmLeaseDeviceV1, + request: wp_drm_lease_device_v1::Request, data: &DrmNode, _dhandle: &DisplayHandle, data_init: &mut DataInit<'_, D>, ) { match request { wp_drm_lease_device_v1::Request::CreateLeaseRequest { id } => { - data_init.init( + data_init.init_delegated::<_, _, Self>( id, DrmLeaseRequestData { node: *data, @@ -777,33 +703,22 @@ where } } -impl Dispatch for DrmLeaseState +impl Dispatch for DrmLeaseState where - D: DrmLeaseHandler - + GlobalDispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + 'static, + D: DrmLeaseHandler, { fn request( _state: &mut D, _client: &Client, - _resource: &wp_drm_lease_connector_v1::WpDrmLeaseConnectorV1, - _request: ::Request, + _resource: &WpDrmLeaseConnectorV1, + _request: wp_drm_lease_connector_v1::Request, _data: &DrmNode, _dhandle: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { } - fn destroyed( - state: &mut D, - _client: wayland_server::backend::ClientId, - resource: &wp_drm_lease_connector_v1::WpDrmLeaseConnectorV1, - data: &DrmNode, - ) { + fn destroyed(state: &mut D, _client: ClientId, resource: &WpDrmLeaseConnectorV1, data: &DrmNode) { let drm_lease_state = state.drm_lease_state(*data); drm_lease_state.connectors.iter_mut().for_each(|connector| { connector.known_instances.retain(|obj| obj != resource); @@ -811,21 +726,15 @@ where } } -impl Dispatch for DrmLeaseState +impl Dispatch for DrmLeaseState where - D: DrmLeaseHandler - + GlobalDispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + 'static, + D: DrmLeaseHandler, { fn request( state: &mut D, _client: &Client, - resource: &wp_drm_lease_request_v1::WpDrmLeaseRequestV1, - request: ::Request, + resource: &WpDrmLeaseRequestV1, + request: wp_drm_lease_request_v1::Request, data: &DrmLeaseRequestData, _dhandle: &DisplayHandle, data_init: &mut DataInit<'_, D>, @@ -877,7 +786,7 @@ where ) { Ok(builder) => match builder.build() { Ok(mut lease) => { - let lease_obj = data_init.init( + let lease_obj = data_init.init_delegated::<_, _, Self>( id, DrmLeaseData { id: lease.lease_id.get(), @@ -904,7 +813,7 @@ where } Err(err) => { tracing::error!(?err, "Failed to create lease"); - let lease_obj = data_init.init( + let lease_obj = data_init.init_delegated::<_, _, Self>( id, DrmLeaseData { id: 0, @@ -916,7 +825,7 @@ where }, Err(err) => { tracing::debug!(?err, "Compositor denied lease request"); - let lease_obj = data_init.init( + let lease_obj = data_init.init_delegated::<_, _, Self>( id, DrmLeaseData { id: 0, @@ -932,33 +841,22 @@ where } } -impl Dispatch for DrmLeaseState +impl Dispatch for DrmLeaseState where - D: DrmLeaseHandler - + GlobalDispatch - + Dispatch - + Dispatch - + Dispatch - + Dispatch - + 'static, + D: DrmLeaseHandler, { fn request( _state: &mut D, _client: &Client, - _resource: &wp_drm_lease_v1::WpDrmLeaseV1, - _request: ::Request, + _resource: &WpDrmLeaseV1, + _request: wp_drm_lease_v1::Request, _data: &DrmLeaseData, _dhandle: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { } - fn destroyed( - state: &mut D, - _client: wayland_server::backend::ClientId, - _resource: &wp_drm_lease_v1::WpDrmLeaseV1, - data: &DrmLeaseData, - ) { + fn destroyed(state: &mut D, _client: ClientId, _resource: &WpDrmLeaseV1, data: &DrmLeaseData) { let drm_lease_state = state.drm_lease_state(data.node); if let Some(lease_ref) = drm_lease_state.remove_lease::(data.id) { state.lease_destroyed(data.node, lease_ref.lease_id.get()); @@ -969,34 +867,8 @@ where /// Macro to delegate implementation of the drm-lease protocol to [`DrmLeaseState`]. /// /// You must also implement [`DrmLeaseHandler`] to use this. +#[deprecated(note = "No longer needed, this is now NOP")] #[macro_export] macro_rules! delegate_drm_lease { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - type __WpDrmLeaseDeviceV1 = - $crate::reexports::wayland_protocols::wp::drm_lease::v1::server::wp_drm_lease_device_v1::WpDrmLeaseDeviceV1; - type __WpDrmLeaseConnectorV1 = - $crate::reexports::wayland_protocols::wp::drm_lease::v1::server::wp_drm_lease_connector_v1::WpDrmLeaseConnectorV1; - type __WpDrmLeaseRequestV1 = - $crate::reexports::wayland_protocols::wp::drm_lease::v1::server::wp_drm_lease_request_v1::WpDrmLeaseRequestV1; - type __WpDrmLeaseV1 = - $crate::reexports::wayland_protocols::wp::drm_lease::v1::server::wp_drm_lease_v1::WpDrmLeaseV1; - - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - __WpDrmLeaseDeviceV1: $crate::wayland::drm_lease::DrmLeaseDeviceGlobalData - ] => $crate::wayland::drm_lease::DrmLeaseState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - __WpDrmLeaseConnectorV1: $crate::backend::drm::DrmNode - ] => $crate::wayland::drm_lease::DrmLeaseState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - __WpDrmLeaseDeviceV1: $crate::backend::drm::DrmNode - ] => $crate::wayland::drm_lease::DrmLeaseState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - __WpDrmLeaseRequestV1: $crate::wayland::drm_lease::DrmLeaseRequestData - ] => $crate::wayland::drm_lease::DrmLeaseState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - __WpDrmLeaseV1: $crate::wayland::drm_lease::DrmLeaseData - ] => $crate::wayland::drm_lease::DrmLeaseState); - - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/fractional_scale/mod.rs b/src/wayland/fractional_scale/mod.rs index c2cc25665fb7..3a6ae966ac44 100644 --- a/src/wayland/fractional_scale/mod.rs +++ b/src/wayland/fractional_scale/mod.rs @@ -8,7 +8,6 @@ //! and implement the [`FractionalScaleHandler`], as shown in this example: //! //! ``` -//! use smithay::delegate_fractional_scale; //! use smithay::wayland::compositor; //! use smithay::reexports::wayland_server::protocol::wl_surface; //! use smithay::wayland::fractional_scale::{ @@ -38,7 +37,6 @@ //! }) //! } //! } -//! delegate_fractional_scale!(State); //! //! // You're now ready to go! //! ``` @@ -67,10 +65,12 @@ use std::cell::RefCell; use wayland_protocols::wp::fractional_scale::v1::server::{ - wp_fractional_scale_manager_v1, wp_fractional_scale_v1, + wp_fractional_scale_manager_v1::{self, WpFractionalScaleManagerV1}, + wp_fractional_scale_v1::{self, WpFractionalScaleV1}, }; use wayland_server::{ - backend::GlobalId, protocol::wl_surface, Dispatch, DisplayHandle, GlobalDispatch, Resource, Weak, + backend::GlobalId, protocol::wl_surface::WlSurface, Dispatch, DisplayHandle, GlobalDispatch, Resource, + Weak, }; use super::compositor::{with_states, SurfaceData}; @@ -82,18 +82,13 @@ pub struct FractionalScaleManagerState { } impl FractionalScaleManagerState { - /// Create new [`wp_fraction_scale_manager`](wayland_protocols::wp::fractional_scale::v1::server::wp_fractional_scale_manager_v1) global. + /// Create new [`WpFractionalScaleManagerV1`] global. pub fn new(display: &DisplayHandle) -> FractionalScaleManagerState where - D: GlobalDispatch - + Dispatch - + Dispatch> - + 'static, D: FractionalScaleHandler, { FractionalScaleManagerState { - global: display - .create_global::(1, ()), + global: display.create_delegated_global::(1, ()), } } @@ -103,39 +98,31 @@ impl FractionalScaleManagerState { } } -impl GlobalDispatch - for FractionalScaleManagerState +impl GlobalDispatch for FractionalScaleManagerState where - D: GlobalDispatch - + Dispatch - + Dispatch>, D: FractionalScaleHandler, { fn bind( _state: &mut D, _handle: &DisplayHandle, _client: &wayland_server::Client, - resource: wayland_server::New, + resource: wayland_server::New, _global_data: &(), data_init: &mut wayland_server::DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } -impl Dispatch - for FractionalScaleManagerState +impl Dispatch for FractionalScaleManagerState where - D: GlobalDispatch - + Dispatch - + Dispatch>, D: FractionalScaleHandler, { fn request( state: &mut D, _client: &wayland_server::Client, - _resource: &wp_fractional_scale_manager_v1::WpFractionalScaleManagerV1, - request: ::Request, + _resource: &WpFractionalScaleManagerV1, + request: wp_fractional_scale_manager_v1::Request, _data: &(), _dhandle: &DisplayHandle, data_init: &mut wayland_server::DataInit<'_, D>, @@ -162,7 +149,7 @@ where } let fractional_scale: wp_fractional_scale_v1::WpFractionalScaleV1 = - data_init.init(id, surface.downgrade()); + data_init.init_delegated::<_, _, Self>(id, surface.downgrade()); with_states(&surface, |states| { if !states.data_map.insert_if_missing(|| { @@ -189,20 +176,13 @@ where } } -impl Dispatch, D> - for FractionalScaleManagerState -where - D: GlobalDispatch - + Dispatch - + Dispatch>, - D: FractionalScaleHandler, -{ +impl Dispatch, D> for FractionalScaleManagerState { fn request( _state: &mut D, _client: &wayland_server::Client, - _resource: &wp_fractional_scale_v1::WpFractionalScaleV1, - request: ::Request, - data: &Weak, + _resource: &WpFractionalScaleV1, + request: wp_fractional_scale_v1::Request, + data: &Weak, _dhandle: &DisplayHandle, _data_init: &mut wayland_server::DataInit<'_, D>, ) { @@ -223,9 +203,9 @@ where } /// Fractional scale handler type -pub trait FractionalScaleHandler { +pub trait FractionalScaleHandler: 'static { /// A new fractional scale was instantiated - fn new_fractional_scale(&mut self, surface: wl_surface::WlSurface); + fn new_fractional_scale(&mut self, surface: WlSurface); } /// Type stored in WlSurface states data_map @@ -283,19 +263,9 @@ where } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_fractional_scale { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::fractional_scale::v1::server::wp_fractional_scale_manager_v1::WpFractionalScaleManagerV1: () - ] => $crate::wayland::fractional_scale::FractionalScaleManagerState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::fractional_scale::v1::server::wp_fractional_scale_manager_v1::WpFractionalScaleManagerV1: () - ] => $crate::wayland::fractional_scale::FractionalScaleManagerState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::fractional_scale::v1::server::wp_fractional_scale_v1::WpFractionalScaleV1: $crate::reexports::wayland_server::Weak<$crate::reexports::wayland_server::protocol::wl_surface::WlSurface> - ] => $crate::wayland::fractional_scale::FractionalScaleManagerState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/idle_inhibit/inhibitor.rs b/src/wayland/idle_inhibit/inhibitor.rs index a3949f33f074..606038fe75bc 100644 --- a/src/wayland/idle_inhibit/inhibitor.rs +++ b/src/wayland/idle_inhibit/inhibitor.rs @@ -22,9 +22,7 @@ impl IdleInhibitorState { impl Dispatch for IdleInhibitManagerState where - D: Dispatch, D: IdleInhibitHandler, - D: 'static, { fn request( state: &mut D, diff --git a/src/wayland/idle_inhibit/mod.rs b/src/wayland/idle_inhibit/mod.rs index ee5d801a15c9..480138d5c915 100644 --- a/src/wayland/idle_inhibit/mod.rs +++ b/src/wayland/idle_inhibit/mod.rs @@ -8,7 +8,6 @@ //! implement the [`IdleInhibitHandler`], as shown in this example: //! //! ``` -//! use smithay::delegate_idle_inhibit; //! use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; //! use smithay::wayland::idle_inhibit::{IdleInhibitManagerState, IdleInhibitHandler}; //! @@ -27,13 +26,11 @@ //! // … //! } //! } -//! delegate_idle_inhibit!(State); //! //! // You're now ready to go! //! ``` use _idle_inhibit::zwp_idle_inhibit_manager_v1::{Request, ZwpIdleInhibitManagerV1}; -use _idle_inhibit::zwp_idle_inhibitor_v1::ZwpIdleInhibitorV1; use wayland_protocols::wp::idle_inhibit::zv1::server as _idle_inhibit; use wayland_server::backend::GlobalId; use wayland_server::protocol::wl_surface::WlSurface; @@ -55,13 +52,10 @@ impl IdleInhibitManagerState { /// Create new [`zwp_idle_inhibit_manager`](ZwpIdleInhibitManagerV1) global. pub fn new(display: &DisplayHandle) -> Self where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: IdleInhibitHandler, - D: 'static, { - let global = display.create_global::(MANAGER_VERSION, ()); + let global = + display.create_delegated_global::(MANAGER_VERSION, ()); Self { global } } @@ -74,11 +68,7 @@ impl IdleInhibitManagerState { impl GlobalDispatch for IdleInhibitManagerState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: IdleInhibitHandler, - D: 'static, { fn bind( _state: &mut D, @@ -88,17 +78,13 @@ where _manager_state: &(), data_init: &mut DataInit<'_, D>, ) { - data_init.init(manager, ()); + data_init.init_delegated::<_, _, Self>(manager, ()); } } impl Dispatch for IdleInhibitManagerState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: IdleInhibitHandler, - D: 'static, { fn request( state: &mut D, @@ -112,7 +98,7 @@ where match request { Request::CreateInhibitor { id, surface } => { state.inhibit(surface.clone()); - data_init.init(id, IdleInhibitorState::new(surface)); + data_init.init_delegated::<_, _, Self>(id, IdleInhibitorState::new(surface)); } Request::Destroy => (), _ => unreachable!(), @@ -121,7 +107,7 @@ where } /// Handler trait for idle-inhibit. -pub trait IdleInhibitHandler { +pub trait IdleInhibitHandler: 'static { /// Enable idle inhibition for the output of the provided surface. fn inhibit(&mut self, surface: WlSurface); @@ -133,20 +119,9 @@ pub trait IdleInhibitHandler { fn uninhibit(&mut self, surface: WlSurface); } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] #[macro_export] macro_rules! delegate_idle_inhibit { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols::wp::idle_inhibit::zv1::server::zwp_idle_inhibit_manager_v1::ZwpIdleInhibitManagerV1: () - ] => $crate::wayland::idle_inhibit::IdleInhibitManagerState); - - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols::wp::idle_inhibit::zv1::server::zwp_idle_inhibit_manager_v1::ZwpIdleInhibitManagerV1: () - ] => $crate::wayland::idle_inhibit::IdleInhibitManagerState); - - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - smithay::reexports::wayland_protocols::wp::idle_inhibit::zv1::server::zwp_idle_inhibitor_v1::ZwpIdleInhibitorV1: $crate::wayland::idle_inhibit::inhibitor::IdleInhibitorState - ] => $crate::wayland::idle_inhibit::IdleInhibitManagerState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/idle_notify/mod.rs b/src/wayland/idle_notify/mod.rs index f64e5fd09c86..23ef131733fa 100644 --- a/src/wayland/idle_notify/mod.rs +++ b/src/wayland/idle_notify/mod.rs @@ -3,7 +3,6 @@ //! ``` //! # extern crate wayland_server; //! # #[macro_use] extern crate smithay; -//! use smithay::delegate_idle_notify; //! use smithay::wayland::idle_notify::{IdleNotifierState, IdleNotifierHandler}; //! # use smithay::input::{Seat, SeatHandler, SeatState, pointer::CursorImageStatus}; //! # use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; @@ -33,7 +32,6 @@ //! &mut self.idle_notifier //! } //! } -//! delegate_idle_notify!(State); //! //! // On input you should notify the idle_notifier //! // state.idle_notifier.notify_activity(&seat); @@ -62,7 +60,7 @@ use wayland_server::{ use crate::input::{Seat, SeatHandler}; /// Handler trait for ext-idle-notify -pub trait IdleNotifierHandler: Sized { +pub trait IdleNotifierHandler: Sized + 'static { /// [`IdleNotifierState`] getter fn idle_notifier_state(&mut self) -> &mut IdleNotifierState; } @@ -107,13 +105,9 @@ impl IdleNotifierState { /// Create new [`ExtIdleNotifierV1`] global. pub fn new(display: &DisplayHandle, loop_handle: LoopHandle<'static, D>) -> Self where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: IdleNotifierHandler, - D: 'static, { - let global = display.create_global::(1, ()); + let global = display.create_delegated_global::(1, ()); Self { global, notifications: HashMap::new(), @@ -132,7 +126,7 @@ impl IdleNotifierState { for notification in self.notifications() { if is_inhibited { - let data = notification.data::().unwrap(); + let data = Self::notification_user_data(notification).unwrap(); if data.is_idle() { notification.resumed(); @@ -162,7 +156,7 @@ impl IdleNotifierState { }; for notification in notifications { - let data = notification.data::().unwrap(); + let data = Self::notification_user_data(notification).unwrap(); if data.is_idle() { notification.resumed(); @@ -183,7 +177,7 @@ impl IdleNotifierState { } fn reinsert_timer(&self, notification: &ExtIdleNotificationV1) { - let data = notification.data::().unwrap(); + let data = Self::notification_user_data(notification).unwrap(); if let Some(token) = data.take_timer_token() { self.loop_handle.remove(token); @@ -198,7 +192,7 @@ impl IdleNotifierState { .insert_source(calloop::timer::Timer::from_duration(data.timeout), { let idle_notification = notification.clone(); move |_, _, state| { - let data = idle_notification.data::().unwrap(); + let data = Self::notification_user_data(&idle_notification).unwrap(); if !state.idle_notifier_state().is_inhibited && !data.is_idle() { idle_notification.idled(); @@ -212,6 +206,10 @@ impl IdleNotifierState { data.set_timer_token(token.ok()); } + + fn notification_user_data(res: &ExtIdleNotificationV1) -> Option<&IdleNotificationUserData> { + res.delegated_data::<_, Self>() + } } impl IdleNotifierState { @@ -227,11 +225,7 @@ impl IdleNotifierState { impl GlobalDispatch for IdleNotifierState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: IdleNotifierHandler, - D: 'static, { fn bind( _state: &mut D, @@ -241,17 +235,13 @@ where _global_data: &(), data_init: &mut wayland_server::DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } impl Dispatch for IdleNotifierState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: IdleNotifierHandler, - D: 'static, { fn request( state: &mut D, @@ -268,7 +258,7 @@ where let idle_notifier_state = state.idle_notifier_state(); - let idle_notification = data_init.init( + let idle_notification = data_init.init_delegated::<_, _, Self>( id, IdleNotificationUserData { seat: seat.clone(), @@ -295,7 +285,6 @@ where impl Dispatch for IdleNotifierState where - D: Dispatch, D: IdleNotifierHandler, { fn request( @@ -331,30 +320,8 @@ where } /// Macro to delegate implementation of the ext idle notify protocol +#[deprecated(note = "No longer needed, this is now NOP")] #[macro_export] macro_rules! delegate_idle_notify { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - type __ExtIdleNotifierV1 = - $crate::reexports::wayland_protocols::ext::idle_notify::v1::server::ext_idle_notifier_v1::ExtIdleNotifierV1; - type __ExtIdleNotificationV1 = - $crate::reexports::wayland_protocols::ext::idle_notify::v1::server::ext_idle_notification_v1::ExtIdleNotificationV1; - - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __ExtIdleNotifierV1: () - ] => $crate::wayland::idle_notify::IdleNotifierState<$ty> - ); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __ExtIdleNotifierV1: () - ] => $crate::wayland::idle_notify::IdleNotifierState<$ty> - ); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __ExtIdleNotificationV1: $crate::wayland::idle_notify::IdleNotificationUserData - ] => $crate::wayland::idle_notify::IdleNotifierState<$ty> - ); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/input_method/input_method_handle.rs b/src/wayland/input_method/input_method_handle.rs index da0df6af4b18..d8eeef3dbd01 100644 --- a/src/wayland/input_method/input_method_handle.rs +++ b/src/wayland/input_method/input_method_handle.rs @@ -4,11 +4,7 @@ use std::{ }; use tracing::warn; -use wayland_protocols_misc::zwp_input_method_v2::server::{ - zwp_input_method_keyboard_grab_v2::ZwpInputMethodKeyboardGrabV2, - zwp_input_method_v2::{self, ZwpInputMethodV2}, - zwp_input_popup_surface_v2::ZwpInputPopupSurfaceV2, -}; +use wayland_protocols_misc::zwp_input_method_v2::server::zwp_input_method_v2::{self, ZwpInputMethodV2}; use wayland_server::{backend::ClientId, protocol::wl_surface::WlSurface}; use wayland_server::{ protocol::wl_keyboard::KeymapFormat, Client, DataInit, Dispatch, DisplayHandle, Resource, @@ -16,7 +12,7 @@ use wayland_server::{ use crate::{ input::{keyboard::KeyboardHandle, SeatHandler}, - utils::{alive_tracker::AliveTracker, Logical, Rectangle, SERIAL_COUNTER}, + utils::{alive_tracker::AliveTracker, user_data::UserdataGetter, Logical, Rectangle, SERIAL_COUNTER}, wayland::{compositor, seat::WaylandFocus, text_input::TextInputHandle}, }; @@ -114,7 +110,7 @@ impl InputMethodHandle { if let Some(instance) = im.instance.as_ref() { instance.object.activate(); if let Some(popup) = im.popup_handle.surface.as_mut() { - let data = instance.object.data::>().unwrap(); + let data: &InputMethodUserData = instance.object.user_data().unwrap(); let location = (data.popup_geometry_callback)(state, surface); // Remove old popup. (data.dismiss_popup)(state, popup.clone()); @@ -142,7 +138,7 @@ impl InputMethodHandle { instance.done(); } if let Some(popup) = im.popup_handle.surface.as_mut() { - let data = instance.object.data::>().unwrap(); + let data: &InputMethodUserData = instance.object.user_data().unwrap(); if popup.get_parent().is_some() { (data.dismiss_popup)(state, popup.clone()); } @@ -173,15 +169,12 @@ impl fmt::Debug for InputMethodUserData { } } +impl UserdataGetter, InputMethodManagerState> for ZwpInputMethodV2 {} + impl Dispatch, D> for InputMethodManagerState where - D: Dispatch>, - D: Dispatch, - D: Dispatch>, - D: SeatHandler, D: InputMethodHandler, ::KeyboardFocus: WaylandFocus, - D: 'static, { fn request( state: &mut D, @@ -249,7 +242,7 @@ where }; let mut input_method = data.handle.inner.lock().unwrap(); - let instance = data_init.init( + let instance = data_init.init_delegated::<_, _, Self>( id, InputMethodPopupSurfaceUserData { alive_tracker: AliveTracker::default(), @@ -266,7 +259,7 @@ where let input_method = data.handle.inner.lock().unwrap(); data.keyboard_handle .set_grab(input_method.keyboard_grab.clone(), SERIAL_COUNTER.next_serial()); - let instance = data_init.init( + let instance = data_init.init_delegated::<_, _, Self>( keyboard, InputMethodKeyboardUserData { handle: input_method.keyboard_grab.clone(), diff --git a/src/wayland/input_method/input_method_keyboard_grab.rs b/src/wayland/input_method/input_method_keyboard_grab.rs index 6e21fcc90df3..1c19cb953b4f 100644 --- a/src/wayland/input_method/input_method_keyboard_grab.rs +++ b/src/wayland/input_method/input_method_keyboard_grab.rs @@ -35,7 +35,7 @@ pub struct InputMethodKeyboardGrab { impl KeyboardGrab for InputMethodKeyboardGrab where - D: SeatHandler + 'static, + D: SeatHandler, { fn input( &mut self, diff --git a/src/wayland/input_method/input_method_popup_surface.rs b/src/wayland/input_method/input_method_popup_surface.rs index dc3601b0ce57..935bc21b4adf 100644 --- a/src/wayland/input_method/input_method_popup_surface.rs +++ b/src/wayland/input_method/input_method_popup_surface.rs @@ -3,10 +3,11 @@ use std::sync::{Arc, Mutex}; use wayland_protocols_misc::zwp_input_method_v2::server::zwp_input_popup_surface_v2::{ self, ZwpInputPopupSurfaceV2, }; -use wayland_server::{backend::ClientId, protocol::wl_surface::WlSurface, Dispatch, Resource}; +use wayland_server::{backend::ClientId, protocol::wl_surface::WlSurface, Dispatch}; use crate::utils::{ alive_tracker::{AliveTracker, IsAlive}, + user_data::UserdataGetter, Logical, Point, Rectangle, }; @@ -51,7 +52,7 @@ impl PopupSurface { /// Is the input method popup surface referred by this handle still alive? pub fn alive(&self) -> bool { // TODO other things to check? This may not sufice. - let role_data: &InputMethodPopupSurfaceUserData = self.surface_role.data().unwrap(); + let role_data = self.surface_role.user_data().unwrap(); self.surface.alive() && role_data.alive_tracker.alive() } @@ -110,6 +111,8 @@ pub struct InputMethodPopupSurfaceUserData { pub(super) alive_tracker: AliveTracker, } +impl UserdataGetter for ZwpInputPopupSurfaceV2 {} + impl Dispatch for InputMethodManagerState { fn request( _state: &mut D, diff --git a/src/wayland/input_method/mod.rs b/src/wayland/input_method/mod.rs index f414da75b46f..b3e27f11f73e 100644 --- a/src/wayland/input_method/mod.rs +++ b/src/wayland/input_method/mod.rs @@ -4,9 +4,6 @@ //! it must be used in conjunction with the text input module to work. //! //! ``` -//! use smithay::{ -//! delegate_seat, delegate_input_method_manager, delegate_text_input_manager, -//! }; //! use smithay::input::{Seat, SeatState, SeatHandler, pointer::CursorImageStatus}; //! use smithay::wayland::input_method::{InputMethodManagerState, InputMethodHandler, PopupSurface}; //! use smithay::wayland::text_input::TextInputManagerState; @@ -15,8 +12,6 @@ //! //! # struct State { seat_state: SeatState }; //! -//! delegate_seat!(State); -//! //! impl InputMethodHandler for State { //! fn new_popup(&mut self, surface: PopupSurface) {} //! fn dismiss_popup(&mut self, surface: PopupSurface) {} @@ -25,11 +20,6 @@ //! } //! } //! -//! // Delegate input method handling for State to InputMethodManagerState. -//! delegate_input_method_manager!(State); -//! -//! delegate_text_input_manager!(State); -//! //! # let mut display = wayland_server::Display::::new().unwrap(); //! # let display_handle = display.handle(); //! @@ -51,7 +41,6 @@ //! InputMethodManagerState::new::(&display_handle, |_client| true); //! // Add text input capabilities, needed for the input method to work //! TextInputManagerState::new::(&display_handle); -//! //! ``` use wayland_server::{ @@ -59,9 +48,8 @@ use wayland_server::{ GlobalDispatch, New, }; -use wayland_protocols_misc::zwp_input_method_v2::server::{ - zwp_input_method_manager_v2::{self, ZwpInputMethodManagerV2}, - zwp_input_method_v2::ZwpInputMethodV2, +use wayland_protocols_misc::zwp_input_method_v2::server::zwp_input_method_manager_v2::{ + self, ZwpInputMethodManagerV2, }; use crate::{ @@ -73,7 +61,7 @@ pub use input_method_handle::{InputMethodHandle, InputMethodUserData}; pub use input_method_keyboard_grab::InputMethodKeyboardUserData; pub use input_method_popup_surface::InputMethodPopupSurfaceUserData; -use super::text_input::TextInputHandle; +use super::{seat::WaylandFocus, text_input::TextInputHandle}; const MANAGER_VERSION: u32 = 1; @@ -86,7 +74,7 @@ mod input_method_popup_surface; pub use input_method_popup_surface::{PopupParent, PopupSurface}; /// Adds input method popup to compositor state -pub trait InputMethodHandler { +pub trait InputMethodHandler: SeatHandler + 'static { /// Add a popup surface to compositor state. fn new_popup(&mut self, surface: PopupSurface); @@ -127,17 +115,15 @@ impl InputMethodManagerState { /// Initialize a text input manager global. pub fn new(display: &DisplayHandle, filter: F) -> Self where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch>, - D: SeatHandler, - D: 'static, + D: InputMethodHandler, + ::KeyboardFocus: WaylandFocus, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, { let data = InputMethodManagerGlobalData { filter: Box::new(filter), }; - let global = display.create_global::(MANAGER_VERSION, data); + let global = + display.create_delegated_global::(MANAGER_VERSION, data); Self { global } } @@ -150,11 +136,8 @@ impl InputMethodManagerState { impl GlobalDispatch for InputMethodManagerState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch>, - D: SeatHandler, - D: 'static, + D: InputMethodHandler, + ::KeyboardFocus: WaylandFocus, { fn bind( _: &mut D, @@ -164,7 +147,7 @@ where _: &InputMethodManagerGlobalData, data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } fn can_view(client: Client, global_data: &InputMethodManagerGlobalData) -> bool { @@ -174,10 +157,8 @@ where impl Dispatch for InputMethodManagerState where - D: Dispatch, - D: Dispatch>, - D: SeatHandler + InputMethodHandler, - D: 'static, + D: InputMethodHandler, + ::KeyboardFocus: WaylandFocus, { fn request( _state: &mut D, @@ -201,7 +182,7 @@ where ti.enter(surface); }); let keyboard_handle = seat.get_keyboard().unwrap(); - let instance = data_init.init( + let instance = data_init.init_delegated::<_, _, Self>( input_method, InputMethodUserData { handle: handle.clone(), @@ -222,29 +203,9 @@ where } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_input_method_manager { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols_misc::zwp_input_method_v2::server::zwp_input_method_manager_v2::ZwpInputMethodManagerV2: - $crate::wayland::input_method::InputMethodManagerGlobalData - ] => $crate::wayland::input_method::InputMethodManagerState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols_misc::zwp_input_method_v2::server::zwp_input_method_manager_v2::ZwpInputMethodManagerV2: () - ] => $crate::wayland::input_method::InputMethodManagerState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols_misc::zwp_input_method_v2::server::zwp_input_method_v2::ZwpInputMethodV2: - $crate::wayland::input_method::InputMethodUserData - ] => $crate::wayland::input_method::InputMethodManagerState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols_misc::zwp_input_method_v2::server::zwp_input_method_keyboard_grab_v2::ZwpInputMethodKeyboardGrabV2: - $crate::wayland::input_method::InputMethodKeyboardUserData - ] => $crate::wayland::input_method::InputMethodManagerState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols_misc::zwp_input_method_v2::server::zwp_input_popup_surface_v2::ZwpInputPopupSurfaceV2: - $crate::wayland::input_method::InputMethodPopupSurfaceUserData - ] => $crate::wayland::input_method::InputMethodManagerState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/keyboard_shortcuts_inhibit/dispatch.rs b/src/wayland/keyboard_shortcuts_inhibit/dispatch.rs index 1f0367b39675..8097e409152a 100644 --- a/src/wayland/keyboard_shortcuts_inhibit/dispatch.rs +++ b/src/wayland/keyboard_shortcuts_inhibit/dispatch.rs @@ -13,7 +13,10 @@ use wayland_server::{ Dispatch, GlobalDispatch, Resource, }; -use crate::input::{Seat, SeatHandler}; +use crate::{ + input::{Seat, SeatHandler}, + utils::user_data::UserdataGetter, +}; use super::{KeyboardShortcutsInhibitHandler, KeyboardShortcutsInhibitState}; @@ -30,8 +33,7 @@ pub struct KeyboardShortcutsInhibitorUserData { impl GlobalDispatch for KeyboardShortcutsInhibitState where D: KeyboardShortcutsInhibitHandler, - D: Dispatch, - D: Dispatch, + D: SeatHandler, { fn bind( _state: &mut D, @@ -41,7 +43,7 @@ where _global_data: &(), data_init: &mut wayland_server::DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } @@ -49,8 +51,6 @@ impl Dispatch for KeyboardShortc where D: KeyboardShortcutsInhibitHandler, D: SeatHandler, - D: Dispatch, - D: Dispatch, { fn request( handler: &mut D, @@ -82,7 +82,7 @@ where let seat = Seat::::from_resource(&seat).unwrap(); let seat_data = super::SeatData::get(&seat); - let inhibitor = data_init.init( + let inhibitor = data_init.init_delegated::<_, _, Self>( id, KeyboardShortcutsInhibitorUserData { seat: seat_id.clone(), @@ -109,6 +109,11 @@ where } } +impl UserdataGetter + for ZwpKeyboardShortcutsInhibitorV1 +{ +} + impl Dispatch for KeyboardShortcutsInhibitState where diff --git a/src/wayland/keyboard_shortcuts_inhibit/mod.rs b/src/wayland/keyboard_shortcuts_inhibit/mod.rs index 2c7fcada9b52..13f33e61cc06 100644 --- a/src/wayland/keyboard_shortcuts_inhibit/mod.rs +++ b/src/wayland/keyboard_shortcuts_inhibit/mod.rs @@ -12,13 +12,16 @@ use wayland_protocols::wp::keyboard_shortcuts_inhibit::zv1::server::{ use wayland_server::{ backend::{GlobalId, ObjectId}, protocol::{wl_seat::WlSeat, wl_surface::WlSurface}, - Dispatch, DisplayHandle, GlobalDispatch, Resource, + DisplayHandle, Resource, }; mod dispatch; pub use dispatch::KeyboardShortcutsInhibitorUserData; -use crate::input::{Seat, SeatHandler}; +use crate::{ + input::{Seat, SeatHandler}, + utils::user_data::UserdataGetter, +}; type SeatId = ObjectId; @@ -68,12 +71,12 @@ impl KeyboardShortcutsInhibitState { /// Regiseter new [ZwpKeyboardShortcutsInhibitManagerV1] global pub fn new(display: &DisplayHandle) -> Self where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, + D: KeyboardShortcutsInhibitHandler, + D: SeatHandler, D: 'static, { - let manager_global = display.create_global::(1, ()); + let manager_global = + display.create_delegated_global::(1, ()); Self { manager_global, inhibitors: HashMap::new(), @@ -94,7 +97,7 @@ pub struct KeyboardShortcutsInhibitor { impl KeyboardShortcutsInhibitor { fn data(&self) -> &KeyboardShortcutsInhibitorUserData { - self.inhibitor.data().unwrap() + self.inhibitor.user_data().unwrap() } fn set_is_active(&self, v: bool) { @@ -239,18 +242,8 @@ pub trait KeyboardShortcutsInhibitHandler { /// Macro to delegate implementation of the keyboard shortcuts inhibit protocol /// /// You must also implement [`KeyboardShortcutsInhibitHandler`] to use this. +#[deprecated(note = "No longer needed, this is now NOP")] #[macro_export] macro_rules! delegate_keyboard_shortcuts_inhibit { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::keyboard_shortcuts_inhibit::zv1::server::zwp_keyboard_shortcuts_inhibit_manager_v1::ZwpKeyboardShortcutsInhibitManagerV1: () - ] => $crate::wayland::keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::keyboard_shortcuts_inhibit::zv1::server::zwp_keyboard_shortcuts_inhibit_manager_v1::ZwpKeyboardShortcutsInhibitManagerV1: () - ] => $crate::wayland::keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::keyboard_shortcuts_inhibit::zv1::server::zwp_keyboard_shortcuts_inhibitor_v1::ZwpKeyboardShortcutsInhibitorV1: $crate::wayland::keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitorUserData - ] => $crate::wayland::keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/output/handlers.rs b/src/wayland/output/handlers.rs index bece42ef7639..a36776e88de6 100644 --- a/src/wayland/output/handlers.rs +++ b/src/wayland/output/handlers.rs @@ -14,13 +14,7 @@ use super::{xdg::XdgOutput, Output, OutputHandler, OutputManagerState, OutputUse * Wl Output */ -impl GlobalDispatch for OutputManagerState -where - D: GlobalDispatch, - D: Dispatch, - D: OutputHandler, - D: 'static, -{ +impl GlobalDispatch for OutputManagerState { fn bind( state: &mut D, _dh: &DisplayHandle, @@ -29,7 +23,7 @@ where global_data: &WlOutputData, data_init: &mut DataInit<'_, D>, ) { - let output = data_init.init( + let output = data_init.init_delegated::<_, _, Self>( resource, OutputUserData { global_data: global_data.inner.clone(), @@ -95,10 +89,7 @@ where } } -impl Dispatch for OutputManagerState -where - D: Dispatch, -{ +impl Dispatch for OutputManagerState { fn request( _state: &mut D, _client: &Client, @@ -129,13 +120,7 @@ where * XDG Output */ -impl GlobalDispatch for OutputManagerState -where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: 'static, -{ +impl GlobalDispatch for OutputManagerState { fn bind( _state: &mut D, _handle: &DisplayHandle, @@ -144,16 +129,11 @@ where _global_data: &(), data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } -impl Dispatch for OutputManagerState -where - D: Dispatch, - D: Dispatch, - D: 'static, -{ +impl Dispatch for OutputManagerState { fn request( _state: &mut D, _client: &Client, @@ -177,7 +157,7 @@ where inner.xdg_output = Some(xdg_output.clone()); } - let id = data_init.init(id, XdgOutputUserData { xdg_output }); + let id = data_init.init_delegated::<_, _, Self>(id, XdgOutputUserData { xdg_output }); inner.xdg_output.as_ref().unwrap().add_instance(&id, &wl_output); } @@ -193,10 +173,7 @@ pub struct XdgOutputUserData { xdg_output: XdgOutput, } -impl Dispatch for OutputManagerState -where - D: Dispatch, -{ +impl Dispatch for OutputManagerState { fn request( _state: &mut D, _client: &Client, diff --git a/src/wayland/output/mod.rs b/src/wayland/output/mod.rs index 6f97db53ab93..36ef9ad1b221 100644 --- a/src/wayland/output/mod.rs +++ b/src/wayland/output/mod.rs @@ -21,7 +21,6 @@ //! ``` //! # extern crate wayland_server; //! # extern crate smithay; -//! use smithay::delegate_output; //! use smithay::output::{Output, PhysicalProperties, Scale, Mode, Subpixel}; //! use smithay::utils::Transform; //! use smithay::wayland::output::OutputHandler; @@ -57,7 +56,6 @@ //! output.add_mode(Mode { size: (1024, 768).into(), refresh: 60000 }); //! //! impl OutputHandler for State {} -//! delegate_output!(State); //! ``` mod handlers; @@ -73,7 +71,7 @@ use wayland_server::{ wl_output::{Mode as WMode, Subpixel as WlSubpixel, Transform, WlOutput}, wl_surface, }, - Client, DisplayHandle, GlobalDispatch, Resource, + Client, DisplayHandle, Resource, }; use crate::utils::{Logical, Point}; @@ -109,11 +107,9 @@ impl OutputManagerState { /// Create new output manager with xdg output support pub fn new_with_xdg_output(display: &DisplayHandle) -> Self where - D: GlobalDispatch, - D: GlobalDispatch, D: 'static, { - let xdg_output_manager = display.create_global::(3, ()); + let xdg_output_manager = display.create_delegated_global::(3, ()); Self { xdg_output_manager: Some(xdg_output_manager), @@ -171,12 +167,12 @@ impl Output { /// multiple times. pub fn create_global(&self, display: &DisplayHandle) -> GlobalId where - D: GlobalDispatch, + D: OutputHandler, D: 'static, { info!(output = self.name(), "Creating new wl_output"); self.inner.0.lock().unwrap().handle = Some(display.backend_handle().downgrade()); - display.create_global::( + display.create_delegated_global::( 4, WlOutputData { inner: self.inner.clone(), @@ -186,9 +182,11 @@ impl Output { /// Attempt to retrieve a [`Output`] from an existing resource pub fn from_resource(output: &WlOutput) -> Option { - output.data::().map(|ud| Output { - inner: ud.global_data.clone(), - }) + output + .delegated_data::() + .map(|ud| Output { + inner: ud.global_data.clone(), + }) } pub(crate) fn wl_change_current_state( @@ -315,25 +313,9 @@ impl Output { } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_output { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_output::WlOutput: $crate::wayland::output::WlOutputData - ] => $crate::wayland::output::OutputManagerState); - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::xdg::xdg_output::zv1::server::zxdg_output_manager_v1::ZxdgOutputManagerV1: () - ] => $crate::wayland::output::OutputManagerState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_output::WlOutput: $crate::wayland::output::OutputUserData - ] => $crate::wayland::output::OutputManagerState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::xdg::xdg_output::zv1::server::zxdg_output_v1::ZxdgOutputV1: $crate::wayland::output::XdgOutputUserData - ] => $crate::wayland::output::OutputManagerState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::xdg::xdg_output::zv1::server::zxdg_output_manager_v1::ZxdgOutputManagerV1: () - ] => $crate::wayland::output::OutputManagerState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/pointer_constraints.rs b/src/wayland/pointer_constraints.rs index ad52c8a06434..a10e792bda02 100644 --- a/src/wayland/pointer_constraints.rs +++ b/src/wayland/pointer_constraints.rs @@ -23,7 +23,7 @@ use wayland_server::{ use super::compositor::{self, RegionAttributes}; use crate::{ - input::{pointer::PointerHandle, SeatHandler}, + input::{pointer::PointerHandle, SeatHandler, SeatState}, utils::{Logical, Point}, wayland::seat::PointerUserData, }; @@ -104,7 +104,7 @@ impl<'a, D: SeatHandler + 'static> ops::Deref for PointerConstraintRef<'a, D> { } } -impl<'a, D: SeatHandler + 'static> PointerConstraintRef<'a, D> { +impl<'a, D: SeatHandler> PointerConstraintRef<'a, D> { /// Send `locked`/`unlocked` /// /// This is not sent automatically since compositors may have different @@ -194,14 +194,9 @@ impl PointerConstraintsState { /// Create a new pointer constraints global pub fn new(display: &DisplayHandle) -> Self where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch>, - D: Dispatch>, - D: SeatHandler, - D: 'static, + D: PointerConstraintsHandler, { - let global = display.create_global::(VERSION, ()); + let global = display.create_delegated_global::(VERSION, ()); Self { global } } @@ -313,12 +308,7 @@ fn remove_constraint(surface: &WlSurface, pointer: &Po impl Dispatch for PointerConstraintsState where - D: Dispatch, - D: Dispatch>, - D: Dispatch>, - D: SeatHandler, D: PointerConstraintsHandler, - D: 'static, { fn request( state: &mut D, @@ -338,8 +328,12 @@ where lifetime, } => { let region = region.as_ref().map(compositor::get_region_attributes); - let pointer = pointer.data::>().unwrap().handle.clone(); - let handle = data_init.init( + let pointer = pointer + .delegated_data::, SeatState>() + .unwrap() + .handle + .clone(); + let handle = data_init.init_delegated::<_, _, Self>( id, PointerConstraintUserData { surface: surface.clone(), @@ -372,8 +366,12 @@ where lifetime, } => { let region = region.as_ref().map(compositor::get_region_attributes); - let pointer = pointer.data::>().unwrap().handle.clone(); - let handle = data_init.init( + let pointer = pointer + .delegated_data::, SeatState>() + .unwrap() + .handle + .clone(); + let handle = data_init.init_delegated::<_, _, Self>( id, PointerConstraintUserData { surface: surface.clone(), @@ -404,10 +402,7 @@ where impl GlobalDispatch for PointerConstraintsState where - D: GlobalDispatch - + Dispatch - + SeatHandler - + 'static, + D: PointerConstraintsHandler, { fn bind( _state: &mut D, @@ -417,15 +412,13 @@ where _global_data: &(), data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } impl Dispatch, D> for PointerConstraintsState where - D: Dispatch>, - D: SeatHandler, - D: 'static, + D: PointerConstraintsHandler, { fn request( _state: &mut D, @@ -460,9 +453,7 @@ where impl Dispatch, D> for PointerConstraintsState where - D: Dispatch>, - D: SeatHandler, - D: 'static, + D: PointerConstraintsHandler, { fn request( _state: &mut D, @@ -500,21 +491,9 @@ where } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] #[macro_export] macro_rules! delegate_pointer_constraints { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::pointer_constraints::zv1::server::zwp_pointer_constraints_v1::ZwpPointerConstraintsV1: () - ] => $crate::wayland::pointer_constraints::PointerConstraintsState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::pointer_constraints::zv1::server::zwp_pointer_constraints_v1::ZwpPointerConstraintsV1: () - ] => $crate::wayland::pointer_constraints::PointerConstraintsState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::pointer_constraints::zv1::server::zwp_confined_pointer_v1::ZwpConfinedPointerV1: $crate::wayland::pointer_constraints::PointerConstraintUserData - ] => $crate::wayland::pointer_constraints::PointerConstraintsState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::pointer_constraints::zv1::server::zwp_locked_pointer_v1::ZwpLockedPointerV1: $crate::wayland::pointer_constraints::PointerConstraintUserData - ] => $crate::wayland::pointer_constraints::PointerConstraintsState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/pointer_gestures.rs b/src/wayland/pointer_gestures.rs index ec9402fc84cb..05c8efc51da7 100644 --- a/src/wayland/pointer_gestures.rs +++ b/src/wayland/pointer_gestures.rs @@ -20,7 +20,6 @@ //! extern crate smithay; //! //! use smithay::wayland::pointer_gestures::PointerGesturesState; -//! use smithay::delegate_pointer_gestures; //! # use smithay::backend::input::KeyState; //! # use smithay::input::{ //! # pointer::{PointerTarget, AxisFrame, MotionEvent, ButtonEvent, RelativeMotionEvent, @@ -92,8 +91,6 @@ //! # } //! # } //! let state = PointerGesturesState::new::(&display.handle()); -//! -//! delegate_pointer_gestures!(State); //! ``` use std::sync::Mutex; @@ -111,7 +108,7 @@ use wayland_server::{ }; use crate::{ - input::{pointer::PointerHandle, SeatHandler}, + input::{pointer::PointerHandle, SeatHandler, SeatState}, wayland::seat::PointerUserData, }; @@ -135,15 +132,9 @@ impl PointerGesturesState { /// Register new [ZwpPointerGesturesV1] global pub fn new(display: &DisplayHandle) -> Self where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch>, - D: Dispatch>, - D: Dispatch>, D: SeatHandler, - D: 'static, { - let global = display.create_global::(MANAGER_VERSION, ()); + let global = display.create_delegated_global::(MANAGER_VERSION, ()); Self { global } } @@ -156,12 +147,7 @@ impl PointerGesturesState { impl Dispatch for PointerGesturesState where - D: Dispatch, - D: Dispatch>, - D: Dispatch>, - D: Dispatch>, D: SeatHandler, - D: 'static, { fn request( _state: &mut D, @@ -174,34 +160,43 @@ where ) { match request { zwp_pointer_gestures_v1::Request::GetSwipeGesture { id, pointer } => { - let handle = &pointer.data::>().unwrap().handle; + let handle = &pointer + .delegated_data::, SeatState>() + .unwrap() + .handle; let user_data = PointerGestureUserData { handle: handle.clone(), in_progress_on: Mutex::new(None), }; - let gesture = data_init.init(id, user_data); + let gesture = data_init.init_delegated::<_, _, Self>(id, user_data); if let Some(handle) = handle { handle.new_swipe_gesture(gesture); } } zwp_pointer_gestures_v1::Request::GetPinchGesture { id, pointer } => { - let handle = &pointer.data::>().unwrap().handle; + let handle = &pointer + .delegated_data::, SeatState>() + .unwrap() + .handle; let user_data = PointerGestureUserData { handle: handle.clone(), in_progress_on: Mutex::new(None), }; - let gesture = data_init.init(id, user_data); + let gesture = data_init.init_delegated::<_, _, Self>(id, user_data); if let Some(handle) = handle { handle.new_pinch_gesture(gesture); } } zwp_pointer_gestures_v1::Request::GetHoldGesture { id, pointer } => { - let handle = &pointer.data::>().unwrap().handle; + let handle = &pointer + .delegated_data::, SeatState>() + .unwrap() + .handle; let user_data = PointerGestureUserData { handle: handle.clone(), in_progress_on: Mutex::new(None), }; - let gesture = data_init.init(id, user_data); + let gesture = data_init.init_delegated::<_, _, Self>(id, user_data); if let Some(handle) = handle { handle.new_hold_gesture(gesture); } @@ -214,7 +209,7 @@ where impl GlobalDispatch for PointerGesturesState where - D: GlobalDispatch + Dispatch + SeatHandler + 'static, + D: SeatHandler, { fn bind( _state: &mut D, @@ -224,15 +219,13 @@ where _global_data: &(), data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } impl Dispatch, D> for PointerGesturesState where - D: Dispatch>, D: SeatHandler, - D: 'static, { fn request( _state: &mut D, @@ -267,9 +260,7 @@ where impl Dispatch, D> for PointerGesturesState where - D: Dispatch>, D: SeatHandler, - D: 'static, { fn request( _state: &mut D, @@ -304,9 +295,7 @@ where impl Dispatch, D> for PointerGesturesState where - D: Dispatch>, D: SeatHandler, - D: 'static, { fn request( _state: &mut D, @@ -340,23 +329,8 @@ where } /// Macro to delegate implementation of the pointer gestures protocol +#[deprecated(note = "No longer needed, this is now NOP")] #[macro_export] macro_rules! delegate_pointer_gestures { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::pointer_gestures::zv1::server::zwp_pointer_gestures_v1::ZwpPointerGesturesV1: () - ] => $crate::wayland::pointer_gestures::PointerGesturesState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::pointer_gestures::zv1::server::zwp_pointer_gestures_v1::ZwpPointerGesturesV1: () - ] => $crate::wayland::pointer_gestures::PointerGesturesState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::pointer_gestures::zv1::server::zwp_pointer_gesture_swipe_v1::ZwpPointerGestureSwipeV1: $crate::wayland::pointer_gestures::PointerGestureUserData - ] => $crate::wayland::pointer_gestures::PointerGesturesState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::pointer_gestures::zv1::server::zwp_pointer_gesture_pinch_v1::ZwpPointerGesturePinchV1: $crate::wayland::pointer_gestures::PointerGestureUserData - ] => $crate::wayland::pointer_gestures::PointerGesturesState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::pointer_gestures::zv1::server::zwp_pointer_gesture_hold_v1::ZwpPointerGestureHoldV1: $crate::wayland::pointer_gestures::PointerGestureUserData - ] => $crate::wayland::pointer_gestures::PointerGesturesState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/presentation/mod.rs b/src/wayland/presentation/mod.rs index 611ae6ca390b..b4631f377ea7 100644 --- a/src/wayland/presentation/mod.rs +++ b/src/wayland/presentation/mod.rs @@ -9,7 +9,6 @@ //! //! ``` //! use smithay::wayland::presentation::PresentationState; -//! use smithay::delegate_presentation; //! //! # struct State; //! # let mut display = wayland_server::Display::::new().unwrap(); @@ -19,9 +18,6 @@ //! 1 // the id of the clock //! ); //! -//! // implement Dispatch for the Presentation types -//! delegate_presentation!(State); -//! //! // You're now ready to go! //! ``` //! @@ -72,9 +68,13 @@ use std::time::Duration; -use wayland_protocols::wp::presentation_time::server::{wp_presentation, wp_presentation_feedback}; +use wayland_protocols::wp::presentation_time::server::{ + wp_presentation::{self, WpPresentation}, + wp_presentation_feedback::{self, WpPresentationFeedback}, +}; use wayland_server::{ - backend::GlobalId, protocol::wl_surface, Dispatch, DisplayHandle, GlobalDispatch, Resource, Weak, + backend::GlobalId, protocol::wl_surface::WlSurface, Dispatch, DisplayHandle, GlobalDispatch, Resource, + Weak, }; use crate::output::Output; @@ -88,19 +88,16 @@ pub struct PresentationState { } impl PresentationState { - /// Create new [`WpPresentation`](wp_presentation::WpPresentation) global. + /// Create new [`WpPresentation`] global. /// /// It returns the presentation state, which you can drop to remove these global from /// the event loop in the future. pub fn new(display: &DisplayHandle, clk_id: u32) -> Self where - D: GlobalDispatch - + Dispatch - + Dispatch - + 'static, + D: 'static, { PresentationState { - global: display.create_global::(1, clk_id), + global: display.create_delegated_global::(1, clk_id), } } @@ -110,43 +107,33 @@ impl PresentationState { } } -impl GlobalDispatch for PresentationState -where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, -{ +impl GlobalDispatch for PresentationState { fn bind( _state: &mut D, _handle: &DisplayHandle, _client: &wayland_server::Client, - resource: wayland_server::New, + resource: wayland_server::New, global_data: &u32, data_init: &mut wayland_server::DataInit<'_, D>, ) { - let interface = data_init.init(resource, *global_data); + let interface = data_init.init_delegated::<_, _, Self>(resource, *global_data); interface.clock_id(*global_data); } } -impl Dispatch for PresentationState -where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, -{ +impl Dispatch for PresentationState { fn request( _state: &mut D, _client: &wayland_server::Client, - _resource: &wp_presentation::WpPresentation, - request: ::Request, + _resource: &WpPresentation, + request: wp_presentation::Request, data: &u32, _dhandle: &DisplayHandle, data_init: &mut wayland_server::DataInit<'_, D>, ) { match request { wp_presentation::Request::Feedback { surface, callback } => { - let callback = data_init.init(callback, ()); + let callback = data_init.init_delegated::<_, _, Self>(callback, ()); // TODO: Is there a better way to store the surface? with_states(&surface, |states| { @@ -164,17 +151,12 @@ where } } -impl Dispatch for PresentationFeedbackState -where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, -{ +impl Dispatch for PresentationState { fn request( _state: &mut D, _client: &wayland_server::Client, - _resource: &wp_presentation_feedback::WpPresentationFeedback, - _request: ::Request, + _resource: &WpPresentationFeedback, + _request: wp_presentation_feedback::Request, _data: &(), _dhandle: &DisplayHandle, _data_init: &mut wayland_server::DataInit<'_, D>, @@ -183,16 +165,12 @@ where } } -/// State for a single presentation feedback callback -#[derive(Debug)] -pub struct PresentationFeedbackState; - /// Holds a single presentation feedback #[derive(Debug)] pub struct PresentationFeedbackCallback { - surface: Weak, + surface: Weak, clk_id: u32, - callback: wp_presentation_feedback::WpPresentationFeedback, + callback: WpPresentationFeedback, } impl PresentationFeedbackCallback { @@ -261,7 +239,7 @@ pub struct PresentationFeedbackCachedState { impl PresentationFeedbackCachedState { fn add_callback( &mut self, - surface: wl_surface::WlSurface, + surface: WlSurface, clk_id: u32, callback: wp_presentation_feedback::WpPresentationFeedback, ) { @@ -299,19 +277,9 @@ impl Drop for PresentationFeedbackCachedState { } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_presentation { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation::WpPresentation: u32 - ] => $crate::wayland::presentation::PresentationState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation::WpPresentation: u32 - ] => $crate::wayland::presentation::PresentationState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation_feedback::WpPresentationFeedback: () - ] => $crate::wayland::presentation::PresentationFeedbackState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/relative_pointer.rs b/src/wayland/relative_pointer.rs index 7e67980da246..db5318e113cf 100644 --- a/src/wayland/relative_pointer.rs +++ b/src/wayland/relative_pointer.rs @@ -8,7 +8,6 @@ //! extern crate smithay; //! //! use smithay::wayland::relative_pointer::RelativePointerManagerState; -//! use smithay::delegate_relative_pointer; //! # use smithay::backend::input::KeyState; //! # use smithay::input::{ //! # pointer::{PointerTarget, AxisFrame, MotionEvent, ButtonEvent, RelativeMotionEvent, @@ -80,8 +79,6 @@ //! # } //! # } //! let state = RelativePointerManagerState::new::(&display.handle()); -//! -//! delegate_relative_pointer!(State); //! ``` use wayland_protocols::wp::relative_pointer::zv1::server::{ @@ -94,7 +91,7 @@ use wayland_server::{ }; use crate::{ - input::{pointer::PointerHandle, SeatHandler}, + input::{pointer::PointerHandle, SeatHandler, SeatState}, wayland::seat::PointerUserData, }; @@ -116,13 +113,10 @@ impl RelativePointerManagerState { /// Register new [ZwpRelativePointerV1] global pub fn new(display: &DisplayHandle) -> Self where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch>, D: SeatHandler, - D: 'static, { - let global = display.create_global::(MANAGER_VERSION, ()); + let global = + display.create_delegated_global::(MANAGER_VERSION, ()); Self { global } } @@ -135,10 +129,7 @@ impl RelativePointerManagerState { impl Dispatch for RelativePointerManagerState where - D: Dispatch, - D: Dispatch>, D: SeatHandler, - D: 'static, { fn request( _state: &mut D, @@ -151,11 +142,14 @@ where ) { match request { zwp_relative_pointer_manager_v1::Request::GetRelativePointer { id, pointer } => { - let handle = &pointer.data::>().unwrap().handle; + let handle = &pointer + .delegated_data::, SeatState>() + .unwrap() + .handle; let user_data = RelativePointerUserData { handle: handle.clone(), }; - let pointer = data_init.init(id, user_data); + let pointer = data_init.init_delegated::<_, _, Self>(id, user_data); if let Some(handle) = handle { handle.new_relative_pointer(pointer); } @@ -168,10 +162,7 @@ where impl GlobalDispatch for RelativePointerManagerState where - D: GlobalDispatch - + Dispatch - + SeatHandler - + 'static, + D: SeatHandler, { fn bind( _state: &mut D, @@ -181,15 +172,13 @@ where _global_data: &(), data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } impl Dispatch, D> for RelativePointerManagerState where - D: Dispatch>, D: SeatHandler, - D: 'static, { fn request( _state: &mut D, @@ -223,17 +212,8 @@ where } /// Macro to delegate implementation of the relative pointer protocol +#[deprecated(note = "No longer needed, this is now NOP")] #[macro_export] macro_rules! delegate_relative_pointer { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::relative_pointer::zv1::server::zwp_relative_pointer_manager_v1::ZwpRelativePointerManagerV1: () - ] => $crate::wayland::relative_pointer::RelativePointerManagerState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::relative_pointer::zv1::server::zwp_relative_pointer_manager_v1::ZwpRelativePointerManagerV1: () - ] => $crate::wayland::relative_pointer::RelativePointerManagerState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::relative_pointer::zv1::server::zwp_relative_pointer_v1::ZwpRelativePointerV1: $crate::wayland::relative_pointer::RelativePointerUserData - ] => $crate::wayland::relative_pointer::RelativePointerManagerState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/seat/keyboard.rs b/src/wayland/seat/keyboard.rs index 1ccd81108df9..693a04d01591 100644 --- a/src/wayland/seat/keyboard.rs +++ b/src/wayland/seat/keyboard.rs @@ -23,7 +23,7 @@ use crate::{ impl KeyboardHandle where - D: SeatHandler + 'static, + D: SeatHandler, ::KeyboardFocus: WaylandFocus, { /// Check if client of given resource currently has keyboard focus @@ -97,7 +97,6 @@ impl fmt::Debug for KeyboardUserData { impl Dispatch, D> for SeatState where - D: 'static + Dispatch>, D: SeatHandler, { fn request( diff --git a/src/wayland/seat/mod.rs b/src/wayland/seat/mod.rs index d81027db2402..2dc037b28036 100644 --- a/src/wayland/seat/mod.rs +++ b/src/wayland/seat/mod.rs @@ -8,7 +8,6 @@ //! ### Initialization //! //! ``` -//! use smithay::delegate_seat; //! use smithay::input::{Seat, SeatState, SeatHandler, pointer::CursorImageStatus}; //! use smithay::reexports::wayland_server::{Display, protocol::wl_surface::WlSurface}; //! @@ -41,7 +40,6 @@ //! // ... //! } //! } -//! delegate_seat!(State); //! ``` //! //! ### Run usage @@ -73,11 +71,8 @@ pub use self::{ use wayland_server::{ backend::{ClientId, GlobalId, ObjectId}, protocol::{ - wl_keyboard::WlKeyboard, - wl_pointer::WlPointer, wl_seat::{self, WlSeat}, - wl_surface, - wl_touch::WlTouch, + wl_surface::{self, WlSurface}, }, Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, }; @@ -88,7 +83,7 @@ pub trait WaylandFocus { /// /// *Note*: This has to return `Some`, if `same_client_as` can return true /// for any provided `ObjectId` - fn wl_surface(&self) -> Option; + fn wl_surface(&self) -> Option; /// Returns true, if the underlying wayland object originates from /// the same client connection as the provided `ObjectId`. /// @@ -100,8 +95,8 @@ pub trait WaylandFocus { } } -impl WaylandFocus for wl_surface::WlSurface { - fn wl_surface(&self) -> Option { +impl WaylandFocus for WlSurface { + fn wl_surface(&self) -> Option { Some(self.clone()) } } @@ -153,14 +148,15 @@ impl SeatState { /// in case you want to remove it. pub fn new_wl_seat(&mut self, display: &DisplayHandle, name: N) -> Seat where - D: GlobalDispatch> + SeatHandler + 'static, + D: SeatHandler, ::PointerFocus: WaylandFocus, ::KeyboardFocus: WaylandFocus, N: Into, { let Seat { arc } = self.new_seat(name); - let global_id = display.create_global::(9, SeatGlobalData { arc: arc.clone() }); + let global_id = + display.create_delegated_global::(9, SeatGlobalData { arc: arc.clone() }); arc.inner.lock().unwrap().global = Some(global_id); Seat { arc } @@ -176,7 +172,7 @@ impl Seat { /// Attempt to retrieve a [`Seat`] from an existing resource pub fn from_resource(seat: &WlSeat) -> Option { - seat.data::>() + seat.delegated_data::, SeatState>() .map(|d| d.arc.clone()) .map(|arc| Self { arc }) } @@ -211,38 +207,18 @@ impl fmt::Debug for SeatUserData { } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_seat { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_seat::WlSeat: $crate::wayland::seat::SeatGlobalData<$ty> - ] => $crate::input::SeatState<$ty>); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_seat::WlSeat: $crate::wayland::seat::SeatUserData<$ty> - ] => $crate::input::SeatState<$ty>); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_pointer::WlPointer: $crate::wayland::seat::PointerUserData<$ty> - ] => $crate::input::SeatState<$ty>); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_keyboard::WlKeyboard: $crate::wayland::seat::KeyboardUserData<$ty> - ] => $crate::input::SeatState<$ty>); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)?$ty: [ - $crate::reexports::wayland_server::protocol::wl_touch::WlTouch: $crate::wayland::seat::TouchUserData<$ty> - ] => $crate::input::SeatState<$ty>); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } impl Dispatch, D> for SeatState where - D: Dispatch>, - D: Dispatch>, - D: Dispatch>, - D: Dispatch>, D: SeatHandler, ::KeyboardFocus: WaylandFocus, - D: 'static, + ::PointerFocus: WaylandFocus, { fn request( _state: &mut D, @@ -257,7 +233,7 @@ where wl_seat::Request::GetPointer { id } => { let inner = data.arc.inner.lock().unwrap(); - let pointer = data_init.init( + let pointer = data_init.init_delegated::<_, _, Self>( id, PointerUserData { handle: inner.pointer.clone(), @@ -274,7 +250,7 @@ where wl_seat::Request::GetKeyboard { id } => { let inner = data.arc.inner.lock().unwrap(); - let keyboard = data_init.init( + let keyboard = data_init.init_delegated::<_, _, Self>( id, KeyboardUserData { handle: inner.keyboard.clone(), @@ -290,7 +266,7 @@ where wl_seat::Request::GetTouch { id } => { let inner = data.arc.inner.lock().unwrap(); - let touch = data_init.init( + let touch = data_init.init_delegated::<_, _, Self>( id, TouchUserData { handle: inner.touch.clone(), @@ -322,13 +298,9 @@ where impl GlobalDispatch, D> for SeatState where - D: GlobalDispatch>, - D: Dispatch>, - D: Dispatch>, - D: Dispatch>, - D: Dispatch>, D: SeatHandler, - D: 'static, + ::KeyboardFocus: WaylandFocus, + ::PointerFocus: WaylandFocus, { fn bind( _state: &mut D, @@ -342,7 +314,7 @@ where arc: global_data.arc.clone(), }; - let resource = data_init.init(resource, data); + let resource = data_init.init_delegated::<_, _, Self>(resource, data); if resource.version() >= 2 { resource.name(global_data.arc.name.clone()); diff --git a/src/wayland/seat/pointer.rs b/src/wayland/seat/pointer.rs index 14c0cc31630b..fd3bbe23e90c 100644 --- a/src/wayland/seat/pointer.rs +++ b/src/wayland/seat/pointer.rs @@ -154,7 +154,7 @@ fn for_each_focused_hold_gestures( #[cfg(feature = "wayland_frontend")] impl PointerTarget for WlSurface where - D: SeatHandler + 'static, + D: SeatHandler, { fn enter(&self, seat: &Seat, _data: &mut D, event: &MotionEvent) { let serial = event.serial; @@ -167,7 +167,9 @@ where } fn leave(&self, seat: &Seat, _data: &mut D, serial: Serial, time: u32) { for_each_focused_swipe_gestures(seat, self, |gesture| { - let data = gesture.data::>().unwrap(); + let data = gesture + .delegated_data::, SeatState>() + .unwrap(); let ongoing = data.in_progress_on.lock().unwrap().take(); if ongoing.is_some() { // Cancel the ongoing gesture. @@ -175,7 +177,9 @@ where } }); for_each_focused_pinch_gestures(seat, self, |gesture| { - let data = gesture.data::>().unwrap(); + let data = gesture + .delegated_data::, SeatState>() + .unwrap(); let ongoing = data.in_progress_on.lock().unwrap().take(); if ongoing.is_some() { // Cancel the ongoing gesture. @@ -183,7 +187,9 @@ where } }); for_each_focused_hold_gestures(seat, self, |gesture| { - let data = gesture.data::>().unwrap(); + let data = gesture + .delegated_data::, SeatState>() + .unwrap(); let ongoing = data.in_progress_on.lock().unwrap().take(); if ongoing.is_some() { // Cancel the ongoing gesture. @@ -332,7 +338,9 @@ where fn gesture_swipe_begin(&self, seat: &Seat, _data: &mut D, event: &GestureSwipeBeginEvent) { for_each_focused_swipe_gestures(seat, self, |gesture| { - let data = gesture.data::>().unwrap(); + let data = gesture + .delegated_data::, SeatState>() + .unwrap(); let ongoing = data.in_progress_on.lock().unwrap().replace(self.clone()); if ongoing.is_some() { // Cancel an ongoing gesture for a different surface. @@ -344,7 +352,9 @@ where fn gesture_swipe_update(&self, seat: &Seat, _data: &mut D, event: &GestureSwipeUpdateEvent) { for_each_focused_swipe_gestures(seat, self, |gesture| { - let data = gesture.data::>().unwrap(); + let data = gesture + .delegated_data::, SeatState>() + .unwrap(); let mut ongoing = data.in_progress_on.lock().unwrap(); // Check that the ongoing gesture is for this surface. if ongoing.as_ref() == Some(self) { @@ -358,7 +368,9 @@ where fn gesture_swipe_end(&self, seat: &Seat, _data: &mut D, event: &GestureSwipeEndEvent) { for_each_focused_swipe_gestures(seat, self, |gesture| { - let data = gesture.data::>().unwrap(); + let data = gesture + .delegated_data::, SeatState>() + .unwrap(); let ongoing = data.in_progress_on.lock().unwrap().take(); // Check if the gesture was ongoing. if ongoing.is_some() { @@ -375,7 +387,9 @@ where fn gesture_pinch_begin(&self, seat: &Seat, _data: &mut D, event: &GesturePinchBeginEvent) { for_each_focused_pinch_gestures(seat, self, |gesture| { - let data = gesture.data::>().unwrap(); + let data = gesture + .delegated_data::, SeatState>() + .unwrap(); let ongoing = data.in_progress_on.lock().unwrap().replace(self.clone()); if ongoing.is_some() { // Cancel an ongoing gesture for a different surface. @@ -387,7 +401,9 @@ where fn gesture_pinch_update(&self, seat: &Seat, _data: &mut D, event: &GesturePinchUpdateEvent) { for_each_focused_pinch_gestures(seat, self, |gesture| { - let data = gesture.data::>().unwrap(); + let data = gesture + .delegated_data::, SeatState>() + .unwrap(); let mut ongoing = data.in_progress_on.lock().unwrap(); // Check that the ongoing gesture is for this surface. if ongoing.as_ref() == Some(self) { @@ -407,7 +423,9 @@ where fn gesture_pinch_end(&self, seat: &Seat, _data: &mut D, event: &GesturePinchEndEvent) { for_each_focused_pinch_gestures(seat, self, |gesture| { - let data = gesture.data::>().unwrap(); + let data = gesture + .delegated_data::, SeatState>() + .unwrap(); let ongoing = data.in_progress_on.lock().unwrap().take(); // Check if the gesture was ongoing. if ongoing.is_some() { @@ -424,7 +442,9 @@ where fn gesture_hold_begin(&self, seat: &Seat, _data: &mut D, event: &GestureHoldBeginEvent) { for_each_focused_hold_gestures(seat, self, |gesture| { - let data = gesture.data::>().unwrap(); + let data = gesture + .delegated_data::, SeatState>() + .unwrap(); let ongoing = data.in_progress_on.lock().unwrap().replace(self.clone()); if ongoing.is_some() { // Cancel an ongoing gesture for a different surface. @@ -436,7 +456,9 @@ where fn gesture_hold_end(&self, seat: &Seat, _data: &mut D, event: &GestureHoldEndEvent) { for_each_focused_hold_gestures(seat, self, |gesture| { - let data = gesture.data::>().unwrap(); + let data = gesture + .delegated_data::, SeatState>() + .unwrap(); let ongoing = data.in_progress_on.lock().unwrap().take(); // Check if the gesture was ongoing. if ongoing.is_some() { @@ -467,10 +489,8 @@ impl fmt::Debug for PointerUserData { impl Dispatch, D> for SeatState where - D: Dispatch>, D: SeatHandler, ::PointerFocus: WaylandFocus, - D: 'static, { fn request( state: &mut D, diff --git a/src/wayland/seat/touch.rs b/src/wayland/seat/touch.rs index cd3f6054a04c..b060c534f7f2 100644 --- a/src/wayland/seat/touch.rs +++ b/src/wayland/seat/touch.rs @@ -116,9 +116,7 @@ impl fmt::Debug for TouchUserData { impl Dispatch, D> for SeatState where - D: Dispatch>, D: SeatHandler, - D: 'static, { fn request( _state: &mut D, diff --git a/src/wayland/security_context/mod.rs b/src/wayland/security_context/mod.rs index 7886f9d14609..b2b8a4bbb1f7 100644 --- a/src/wayland/security_context/mod.rs +++ b/src/wayland/security_context/mod.rs @@ -20,7 +20,7 @@ pub use listener_source::SecurityContextListenerSource; const MANAGER_VERSION: u32 = 1; /// Handler for security context protocol -pub trait SecurityContextHandler { +pub trait SecurityContextHandler: 'static { /// A client has created a security context. `source` is a callop `EventSource` that listens on /// the socket and produces streams when clients connect. `context` has the metadata associated /// with the security context. @@ -67,16 +67,14 @@ impl SecurityContextState { /// created through a security context for the protcol to be correct and secure. pub fn new(display: &DisplayHandle, filter: F) -> Self where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: 'static, + D: SecurityContextHandler, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, { let global_data = SecurityContextGlobalData { filter: Box::new(filter), }; - let global = display.create_global::(MANAGER_VERSION, global_data); + let global = display + .create_delegated_global::(MANAGER_VERSION, global_data); Self { global } } @@ -95,9 +93,7 @@ pub struct SecurityContextGlobalData { impl GlobalDispatch for SecurityContextState where - D: GlobalDispatch, - D: Dispatch, - D: 'static, + D: SecurityContextHandler, { fn bind( _state: &mut D, @@ -107,7 +103,7 @@ where _global_data: &SecurityContextGlobalData, data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } fn can_view(client: Client, global_data: &SecurityContextGlobalData) -> bool { @@ -117,9 +113,7 @@ where impl Dispatch for SecurityContextState where - D: Dispatch, - D: Dispatch, - D: 'static, + D: SecurityContextHandler, { fn request( _state: &mut D, @@ -143,7 +137,7 @@ where app_id: None, instance_id: None, }))); - data_init.init(id, data); + data_init.init_delegated::<_, _, Self>(id, data); } wp_security_context_manager_v1::Request::Destroy => {} _ => unreachable!(), @@ -153,7 +147,6 @@ where impl Dispatch for SecurityContextState where - D: Dispatch + 'static, D: SecurityContextHandler, { fn request( @@ -229,17 +222,8 @@ where } /// Macro to delegate implementation of the security context protocol +#[deprecated(note = "No longer needed, this is now NOP")] #[macro_export] macro_rules! delegate_security_context { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::security_context::v1::server::wp_security_context_manager_v1::WpSecurityContextManagerV1: $crate::wayland::security_context::SecurityContextGlobalData - ] => $crate::wayland::security_context::SecurityContextState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::security_context::v1::server::wp_security_context_manager_v1::WpSecurityContextManagerV1: () - ] => $crate::wayland::security_context::SecurityContextState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::security_context::v1::server::wp_security_context_v1::WpSecurityContextV1: $crate::wayland::security_context::SecurityContextUserData - ] => $crate::wayland::security_context::SecurityContextState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/selection/data_device/device.rs b/src/wayland/selection/data_device/device.rs index 5a65527c118e..2aa587e67088 100644 --- a/src/wayland/selection/data_device/device.rs +++ b/src/wayland/selection/data_device/device.rs @@ -11,7 +11,7 @@ use wayland_server::{ use crate::{ input::{pointer::Focus, Seat, SeatHandler}, - utils::Serial, + utils::{user_data::UserdataGetter, Serial}, wayland::{ compositor, seat::WaylandFocus, @@ -36,15 +36,14 @@ pub struct DataDeviceUserData { pub(crate) wl_seat: WlSeat, } +impl UserdataGetter for WlDataDevice {} + impl Dispatch for DataDeviceState where - D: Dispatch, D: DataDeviceHandler, - D: SeatHandler, ::PointerFocus: WaylandFocus, ::TouchFocus: WaylandFocus, ::KeyboardFocus: WaylandFocus, - D: 'static, { fn request( handler: &mut D, diff --git a/src/wayland/selection/data_device/dnd_grab.rs b/src/wayland/selection/data_device/dnd_grab.rs index 5fee3488f39f..8cdd3d1e5216 100644 --- a/src/wayland/selection/data_device/dnd_grab.rs +++ b/src/wayland/selection/data_device/dnd_grab.rs @@ -94,8 +94,6 @@ impl DnDGrab { impl DnDGrab where D: DataDeviceHandler, - D: SeatHandler, - D: 'static, { fn update_focus( &mut self, @@ -261,9 +259,7 @@ where impl PointerGrab for DnDGrab where D: DataDeviceHandler, - D: SeatHandler, ::PointerFocus: WaylandFocus, - D: 'static, { fn motion( &mut self, @@ -385,9 +381,7 @@ where impl TouchGrab for DnDGrab where D: DataDeviceHandler, - D: SeatHandler, ::TouchFocus: WaylandFocus, - D: 'static, { fn down( &mut self, @@ -470,7 +464,6 @@ struct DndDataOffer { impl ObjectData for DndDataOffer where D: DataDeviceHandler, - D: 'static, { fn request( self: Arc, @@ -500,7 +493,6 @@ where fn handle_dnd(handler: &mut D, offer: &WlDataOffer, request: wl_data_offer::Request, data: &DndDataOffer) where D: DataDeviceHandler, - D: 'static, { use self::wl_data_offer::Request; let source = &data.source; diff --git a/src/wayland/selection/data_device/mod.rs b/src/wayland/selection/data_device/mod.rs index 467c8d4fd312..888a3e2cef9f 100644 --- a/src/wayland/selection/data_device/mod.rs +++ b/src/wayland/selection/data_device/mod.rs @@ -29,7 +29,6 @@ //! ``` //! # extern crate wayland_server; //! # #[macro_use] extern crate smithay; -//! use smithay::delegate_data_device; //! use smithay::wayland::selection::SelectionHandler; //! use smithay::wayland::selection::data_device::{ClientDndGrabHandler, DataDeviceState, DataDeviceHandler, ServerDndGrabHandler}; //! # use smithay::input::{Seat, SeatState, SeatHandler, pointer::CursorImageStatus}; @@ -63,7 +62,6 @@ //! fn data_device_state(&self) -> &DataDeviceState { &self.data_device_state } //! // ... override default implementations here to customize handling ... //! } -//! delegate_data_device!(State); //! //! // You're now ready to go! //! ``` @@ -81,7 +79,7 @@ use wayland_server::{ wl_data_source::WlDataSource, wl_surface::WlSurface, }, - Client, DisplayHandle, GlobalDispatch, + Client, DisplayHandle, }; use crate::{ @@ -109,7 +107,9 @@ use super::{ /// Events that are generated by interactions of the clients with the data device #[allow(unused_variables)] -pub trait DataDeviceHandler: Sized + SelectionHandler + ClientDndGrabHandler + ServerDndGrabHandler { +pub trait DataDeviceHandler: + Sized + SelectionHandler + ClientDndGrabHandler + ServerDndGrabHandler + 'static +{ /// [DataDeviceState] getter fn data_device_state(&self) -> &DataDeviceState; @@ -196,10 +196,12 @@ impl DataDeviceState { /// Regiseter new [WlDataDeviceManager] global pub fn new(display: &DisplayHandle) -> Self where - D: GlobalDispatch + 'static, D: DataDeviceHandler, + ::PointerFocus: WaylandFocus, + ::KeyboardFocus: WaylandFocus, + ::TouchFocus: WaylandFocus, { - let manager_global = display.create_global::(3, ()); + let manager_global = display.create_delegated_global::(3, ()); Self { manager_global } } @@ -236,7 +238,7 @@ pub fn default_action_chooser(available: DndAction, preferred: DndAction) -> Dnd #[instrument(name = "wayland_data_device", level = "debug", skip(dh, seat, client), fields(seat = seat.name(), client = ?client.as_ref().map(|c| c.id())))] pub fn set_data_device_focus(dh: &DisplayHandle, seat: &Seat, client: Option) where - D: SeatHandler + DataDeviceHandler + 'static, + D: DataDeviceHandler, { seat.user_data() .insert_if_missing(|| RefCell::new(SeatData::::new())); @@ -260,7 +262,7 @@ pub fn set_data_device_selection( mime_types: Vec, user_data: D::SelectionUserData, ) where - D: SeatHandler + DataDeviceHandler + 'static, + D: DataDeviceHandler, { seat.user_data() .insert_if_missing(|| RefCell::new(SeatData::::new())); @@ -303,7 +305,7 @@ pub fn request_data_device_client_selection( fd: OwnedFd, ) -> Result<(), SelectionRequestError> where - D: SeatHandler + DataDeviceHandler + 'static, + D: DataDeviceHandler, { seat.user_data() .insert_if_missing(|| RefCell::new(SeatData::::new())); @@ -335,7 +337,7 @@ where #[instrument(name = "wayland_data_device", level = "debug", skip_all, fields(seat = seat.name()))] pub fn current_data_device_selection_userdata(seat: &Seat) -> Option> where - D: SeatHandler + DataDeviceHandler + 'static, + D: DataDeviceHandler, { seat.user_data() .insert_if_missing(|| RefCell::new(SeatData::::new())); @@ -356,7 +358,7 @@ where #[instrument(name = "wayland_data_device", level = "debug", skip_all, fields(seat = seat.name()))] pub fn clear_data_device_selection(dh: &DisplayHandle, seat: &Seat) where - D: SeatHandler + DataDeviceHandler + 'static, + D: DataDeviceHandler, { seat.user_data() .insert_if_missing(|| RefCell::new(SeatData::::new())); @@ -382,7 +384,7 @@ pub fn start_dnd( touch_start_data: Option>, metadata: SourceMetadata, ) where - D: SeatHandler + DataDeviceHandler + 'static, + D: DataDeviceHandler, ::PointerFocus: WaylandFocus, ::TouchFocus: WaylandFocus, { @@ -409,17 +411,16 @@ mod handlers { use tracing::error; use wayland_server::{ - protocol::{ - wl_data_device::WlDataDevice, - wl_data_device_manager::{self, WlDataDeviceManager}, - wl_data_source::WlDataSource, - }, + protocol::wl_data_device_manager::{self, WlDataDeviceManager}, Dispatch, DisplayHandle, GlobalDispatch, }; use crate::{ - input::Seat, - wayland::selection::{device::SelectionDevice, seat_data::SeatData}, + input::{Seat, SeatHandler}, + wayland::{ + seat::WaylandFocus, + selection::{device::SelectionDevice, seat_data::SeatData}, + }, }; use super::{device::DataDeviceUserData, source::DataSourceUserData}; @@ -427,12 +428,10 @@ mod handlers { impl GlobalDispatch for DataDeviceState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, D: DataDeviceHandler, - D: 'static, + ::PointerFocus: WaylandFocus, + ::KeyboardFocus: WaylandFocus, + ::TouchFocus: WaylandFocus, { fn bind( _state: &mut D, @@ -442,17 +441,16 @@ mod handlers { _global_data: &(), data_init: &mut wayland_server::DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } impl Dispatch for DataDeviceState where - D: Dispatch, - D: Dispatch, - D: Dispatch, D: DataDeviceHandler, - D: 'static, + ::PointerFocus: WaylandFocus, + ::KeyboardFocus: WaylandFocus, + ::TouchFocus: WaylandFocus, { fn request( _state: &mut D, @@ -465,7 +463,7 @@ mod handlers { ) { match request { wl_data_device_manager::Request::CreateDataSource { id } => { - data_init.init(id, DataSourceUserData::new()); + data_init.init_delegated::<_, _, Self>(id, DataSourceUserData::new()); } wl_data_device_manager::Request::GetDataDevice { id, seat: wl_seat } => { match Seat::::from_resource(&wl_seat) { @@ -474,7 +472,7 @@ mod handlers { .insert_if_missing(|| RefCell::new(SeatData::::new())); let device = SelectionDevice::DataDevice( - data_init.init(id, DataDeviceUserData { wl_seat }), + data_init.init_delegated::<_, _, Self>(id, DataDeviceUserData { wl_seat }), ); let seat_data = seat @@ -494,22 +492,9 @@ mod handlers { } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_data_device { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_data_device_manager::WlDataDeviceManager: () - ] => $crate::wayland::selection::data_device::DataDeviceState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_data_device_manager::WlDataDeviceManager: () - ] => $crate::wayland::selection::data_device::DataDeviceState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_data_device::WlDataDevice: $crate::wayland::selection::data_device::DataDeviceUserData - ] => $crate::wayland::selection::data_device::DataDeviceState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_data_source::WlDataSource: $crate::wayland::selection::data_device::DataSourceUserData - ] => $crate::wayland::selection::data_device::DataDeviceState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/selection/data_device/server_dnd_grab.rs b/src/wayland/selection/data_device/server_dnd_grab.rs index 9845f89e18ac..d96c1a49fc5c 100644 --- a/src/wayland/selection/data_device/server_dnd_grab.rs +++ b/src/wayland/selection/data_device/server_dnd_grab.rs @@ -15,7 +15,7 @@ use wayland_server::{ DisplayHandle, Resource, }; -use crate::utils::{Logical, Point, Serial, SERIAL_COUNTER}; +use crate::utils::{user_data::UserdataGetter, Logical, Point, Serial, SERIAL_COUNTER}; use crate::wayland::seat::WaylandFocus; use crate::{ input::{ @@ -31,7 +31,7 @@ use crate::{ wayland::selection::seat_data::SeatData, }; -use super::{DataDeviceHandler, DataDeviceUserData, ServerDndGrabHandler, SourceMetadata}; +use super::{DataDeviceHandler, ServerDndGrabHandler, SourceMetadata}; pub(crate) struct ServerDnDGrab { dh: DisplayHandle, @@ -85,8 +85,6 @@ impl ServerDnDGrab { impl ServerDnDGrab where D: DataDeviceHandler, - D: SeatHandler, - D: 'static, { fn update_focus( &mut self, @@ -139,7 +137,7 @@ where .filter(|d| d.id().same_client_as(&surface.id())) { let handle = self.dh.backend_handle(); - let wl_seat = match device.data::() { + let wl_seat = match device.user_data() { Some(data) => data.wl_seat.clone(), None => continue, }; @@ -229,9 +227,7 @@ where impl PointerGrab for ServerDnDGrab where D: DataDeviceHandler, - D: SeatHandler, ::PointerFocus: WaylandFocus, - D: 'static, { fn motion( &mut self, @@ -360,9 +356,7 @@ where impl TouchGrab for ServerDnDGrab where D: DataDeviceHandler, - D: SeatHandler, ::TouchFocus: WaylandFocus, - D: 'static, { fn down( &mut self, @@ -448,7 +442,7 @@ struct ServerDndData { impl ObjectData for ServerDndData where - D: DataDeviceHandler + SeatHandler + 'static, + D: DataDeviceHandler, { fn request( self: Arc, @@ -481,7 +475,7 @@ fn handle_server_dnd( request: wl_data_offer::Request, data: &ServerDndData, ) where - D: DataDeviceHandler + SeatHandler + 'static, + D: DataDeviceHandler, { use self::wl_data_offer::Request; diff --git a/src/wayland/selection/data_device/source.rs b/src/wayland/selection/data_device/source.rs index 6186f307324b..e079ebff5171 100644 --- a/src/wayland/selection/data_device/source.rs +++ b/src/wayland/selection/data_device/source.rs @@ -5,10 +5,10 @@ use wayland_server::{ backend::ClientId, protocol::wl_data_source::{self}, protocol::{wl_data_device_manager::DndAction, wl_data_source::WlDataSource}, - Dispatch, DisplayHandle, Resource, + Dispatch, DisplayHandle, }; -use crate::utils::{alive_tracker::AliveTracker, IsAlive}; +use crate::utils::{alive_tracker::AliveTracker, user_data::UserdataGetter, IsAlive}; use super::{DataDeviceHandler, DataDeviceState}; @@ -46,11 +46,11 @@ impl DataSourceUserData { } } +impl UserdataGetter for WlDataSource {} + impl Dispatch for DataDeviceState where - D: Dispatch, D: DataDeviceHandler, - D: 'static, { fn request( _state: &mut D, @@ -87,7 +87,7 @@ where impl IsAlive for WlDataSource { fn alive(&self) -> bool { - let data: &DataSourceUserData = self.data().unwrap(); + let data = self.user_data().unwrap(); data.alive_tracker.alive() } } @@ -97,7 +97,7 @@ pub fn with_source_metadata T>( source: &WlDataSource, f: F, ) -> Result { - match source.data::() { + match source.user_data() { Some(data) => Ok(f(&data.inner.lock().unwrap())), None => Err(crate::utils::UnmanagedResource), } diff --git a/src/wayland/selection/device.rs b/src/wayland/selection/device.rs index 4027d9e8376c..d118888bfe07 100644 --- a/src/wayland/selection/device.rs +++ b/src/wayland/selection/device.rs @@ -8,11 +8,10 @@ use wayland_server::protocol::wl_data_device::WlDataDevice; use wayland_server::protocol::wl_seat::WlSeat; use wayland_server::Resource; -use super::data_device::DataDeviceUserData; +use crate::utils::user_data::UserdataGetter; + use super::offer::SelectionOffer; -use super::primary_selection::PrimaryDeviceUserData; use super::private::selection_dispatch; -use super::wlr_data_control::DataControlDeviceUserData; #[derive(Debug, Clone, PartialEq, Eq)] pub enum SelectionDevice { @@ -43,15 +42,15 @@ impl SelectionDevice { pub fn seat(&self) -> WlSeat { match self { SelectionDevice::DataDevice(device) => { - let data: &DataDeviceUserData = device.data().unwrap(); + let data = device.user_data().unwrap(); data.wl_seat.clone() } SelectionDevice::Primary(device) => { - let data: &PrimaryDeviceUserData = device.data().unwrap(); + let data = device.user_data().unwrap(); data.wl_seat.clone() } SelectionDevice::DataControl(device) => { - let data: &DataControlDeviceUserData = device.data().unwrap(); + let data = device.user_data().unwrap(); data.wl_seat.clone() } } diff --git a/src/wayland/selection/primary_selection/device.rs b/src/wayland/selection/primary_selection/device.rs index 032e445c3467..1cbde33b51fc 100644 --- a/src/wayland/selection/primary_selection/device.rs +++ b/src/wayland/selection/primary_selection/device.rs @@ -8,6 +8,7 @@ use wayland_server::{protocol::wl_seat::WlSeat, Client, DataInit, Dispatch, Disp use crate::{ input::{Seat, SeatHandler}, + utils::user_data::UserdataGetter, wayland::{ seat::WaylandFocus, selection::{ @@ -15,12 +16,12 @@ use crate::{ offer::OfferReplySource, seat_data::SeatData, source::{SelectionSource, SelectionSourceProvider}, - SelectionHandler, SelectionTarget, + SelectionTarget, }, }, }; -use super::PrimarySelectionState; +use super::{PrimarySelectionHandler, PrimarySelectionState}; #[doc(hidden)] #[derive(Debug)] @@ -28,13 +29,12 @@ pub struct PrimaryDeviceUserData { pub(crate) wl_seat: WlSeat, } +impl UserdataGetter for PrimaryDevice {} + impl Dispatch for PrimarySelectionState where - D: Dispatch, - D: SelectionHandler, - D: SeatHandler, + D: PrimarySelectionHandler, ::KeyboardFocus: WaylandFocus, - D: 'static, { fn request( handler: &mut D, diff --git a/src/wayland/selection/primary_selection/mod.rs b/src/wayland/selection/primary_selection/mod.rs index 6d13968a54ea..3ba2101a07aa 100644 --- a/src/wayland/selection/primary_selection/mod.rs +++ b/src/wayland/selection/primary_selection/mod.rs @@ -26,7 +26,6 @@ //! ``` //! # extern crate wayland_server; //! # #[macro_use] extern crate smithay; -//! use smithay::delegate_primary_selection; //! use smithay::wayland::selection::SelectionHandler; //! use smithay::wayland::selection::primary_selection::{PrimarySelectionState, PrimarySelectionHandler}; //! # use smithay::input::{Seat, SeatHandler, SeatState, pointer::CursorImageStatus}; @@ -58,7 +57,6 @@ //! fn primary_selection_state(&self) -> &PrimarySelectionState { &self.primary_selection_state } //! // ... override default implementations here to customize handling ... //! } -//! delegate_primary_selection!(State); //! //! // You're now ready to go! //! ``` @@ -70,11 +68,11 @@ use std::{ use tracing::instrument; use wayland_protocols::wp::primary_selection::zv1::server::zwp_primary_selection_device_manager_v1::ZwpPrimarySelectionDeviceManagerV1 as PrimaryDeviceManager; -use wayland_server::{backend::GlobalId, Client, DisplayHandle, GlobalDispatch}; +use wayland_server::{backend::GlobalId, Client, DisplayHandle}; use crate::{ input::{Seat, SeatHandler}, - wayland::selection::SelectionTarget, + wayland::{seat::WaylandFocus, selection::SelectionTarget}, }; mod device; @@ -88,7 +86,7 @@ use super::SelectionHandler; use super::{offer::OfferReplySource, seat_data::SeatData}; /// Access the primary selection state. -pub trait PrimarySelectionHandler: Sized + SeatHandler + SelectionHandler { +pub trait PrimarySelectionHandler: Sized + SeatHandler + SelectionHandler + 'static { /// [PrimarySelectionState] getter. fn primary_selection_state(&self) -> &PrimarySelectionState; } @@ -103,10 +101,10 @@ impl PrimarySelectionState { /// Register new [`PrimaryDeviceManager`] global pub fn new(display: &DisplayHandle) -> Self where - D: GlobalDispatch + 'static, D: PrimarySelectionHandler, + ::KeyboardFocus: WaylandFocus, { - let manager_global = display.create_global::(1, ()); + let manager_global = display.create_delegated_global::(1, ()); Self { manager_global } } @@ -121,7 +119,7 @@ impl PrimarySelectionState { #[instrument(name = "wayland_primary_selection", level = "debug", skip(dh, seat, client), fields(seat = seat.name(), client = ?client.as_ref().map(|c| c.id())))] pub fn set_primary_focus(dh: &DisplayHandle, seat: &Seat, client: Option) where - D: SeatHandler + PrimarySelectionHandler + 'static, + D: PrimarySelectionHandler, { seat.user_data() .insert_if_missing(|| RefCell::new(SeatData::::new())); @@ -145,7 +143,7 @@ pub fn set_primary_selection( mime_types: Vec, user_data: D::SelectionUserData, ) where - D: SeatHandler + PrimarySelectionHandler + 'static, + D: PrimarySelectionHandler, { seat.user_data() .insert_if_missing(|| RefCell::new(SeatData::::new())); @@ -187,7 +185,7 @@ pub fn request_primary_client_selection( fd: OwnedFd, ) -> Result<(), SelectionRequestError> where - D: SeatHandler + PrimarySelectionHandler + 'static, + D: PrimarySelectionHandler, { seat.user_data() .insert_if_missing(|| RefCell::new(SeatData::::new())); @@ -219,7 +217,7 @@ where #[instrument(name = "wayland_primary_selection", level = "debug", skip_all, fields(seat = seat.name()))] pub fn current_primary_selection_userdata(seat: &Seat) -> Option> where - D: SeatHandler + PrimarySelectionHandler + 'static, + D: PrimarySelectionHandler, { seat.user_data() .insert_if_missing(|| RefCell::new(SeatData::::new())); @@ -240,7 +238,7 @@ where #[instrument(name = "wayland_primary_selection", level = "debug", skip_all, fields(seat = seat.name()))] pub fn clear_primary_selection(dh: &DisplayHandle, seat: &Seat) where - D: SeatHandler + PrimarySelectionHandler + 'static, + D: PrimarySelectionHandler, { seat.user_data() .insert_if_missing(|| RefCell::new(SeatData::::new())); @@ -255,18 +253,17 @@ mod handlers { use std::cell::RefCell; use tracing::error; - use wayland_protocols::wp::primary_selection::zv1::server::{ - zwp_primary_selection_device_manager_v1::{ - self as primary_device_manager, ZwpPrimarySelectionDeviceManagerV1 as PrimaryDeviceManager, - }, - zwp_primary_selection_device_v1::ZwpPrimarySelectionDeviceV1 as PrimaryDevice, - zwp_primary_selection_source_v1::ZwpPrimarySelectionSourceV1 as PrimarySource, + use wayland_protocols::wp::primary_selection::zv1::server::zwp_primary_selection_device_manager_v1::{ + self as primary_device_manager, ZwpPrimarySelectionDeviceManagerV1 as PrimaryDeviceManager, }; use wayland_server::{Dispatch, DisplayHandle, GlobalDispatch}; use crate::{ input::{Seat, SeatHandler}, - wayland::selection::{device::SelectionDevice, seat_data::SeatData}, + wayland::{ + seat::WaylandFocus, + selection::{device::SelectionDevice, seat_data::SeatData}, + }, }; use super::{device::PrimaryDeviceUserData, source::PrimarySourceUserData}; @@ -274,12 +271,8 @@ mod handlers { impl GlobalDispatch for PrimarySelectionState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, D: PrimarySelectionHandler, - D: 'static, + ::KeyboardFocus: WaylandFocus, { fn bind( _state: &mut D, @@ -289,18 +282,14 @@ mod handlers { _global_data: &(), data_init: &mut wayland_server::DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } impl Dispatch for PrimarySelectionState where - D: Dispatch, - D: Dispatch, - D: Dispatch, D: PrimarySelectionHandler, - D: SeatHandler, - D: 'static, + ::KeyboardFocus: WaylandFocus, { fn request( _state: &mut D, @@ -313,7 +302,7 @@ mod handlers { ) { match request { primary_device_manager::Request::CreateSource { id } => { - data_init.init(id, PrimarySourceUserData::new()); + data_init.init_delegated::<_, _, Self>(id, PrimarySourceUserData::new()); } primary_device_manager::Request::GetDevice { id, seat: wl_seat } => { match Seat::::from_resource(&wl_seat) { @@ -322,7 +311,7 @@ mod handlers { .insert_if_missing(|| RefCell::new(SeatData::::new())); let device = SelectionDevice::Primary( - data_init.init(id, PrimaryDeviceUserData { wl_seat }), + data_init.init_delegated::<_, _, Self>(id, PrimaryDeviceUserData { wl_seat }), ); let seat_data = seat @@ -348,22 +337,9 @@ mod handlers { } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_primary_selection { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::primary_selection::zv1::server::zwp_primary_selection_device_manager_v1::ZwpPrimarySelectionDeviceManagerV1: () - ] => $crate::wayland::selection::primary_selection::PrimarySelectionState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::primary_selection::zv1::server::zwp_primary_selection_device_manager_v1::ZwpPrimarySelectionDeviceManagerV1: () - ] => $crate::wayland::selection::primary_selection::PrimarySelectionState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::primary_selection::zv1::server::zwp_primary_selection_device_v1::ZwpPrimarySelectionDeviceV1: $crate::wayland::selection::primary_selection::PrimaryDeviceUserData - ] => $crate::wayland::selection::primary_selection::PrimarySelectionState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::primary_selection::zv1::server::zwp_primary_selection_source_v1::ZwpPrimarySelectionSourceV1: $crate::wayland::selection::primary_selection::PrimarySourceUserData - ] => $crate::wayland::selection::primary_selection::PrimarySelectionState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/selection/primary_selection/source.rs b/src/wayland/selection/primary_selection/source.rs index 129824fb7b6f..87aeae598f23 100644 --- a/src/wayland/selection/primary_selection/source.rs +++ b/src/wayland/selection/primary_selection/source.rs @@ -3,9 +3,9 @@ use std::sync::Mutex; use wayland_protocols::wp::primary_selection::zv1::server::zwp_primary_selection_source_v1::{ self as primary_source, ZwpPrimarySelectionSourceV1 as PrimarySource, }; -use wayland_server::{backend::ClientId, Dispatch, DisplayHandle, Resource}; +use wayland_server::{backend::ClientId, Dispatch, DisplayHandle}; -use crate::utils::{alive_tracker::AliveTracker, IsAlive}; +use crate::utils::{alive_tracker::AliveTracker, user_data::UserdataGetter, IsAlive}; use super::{PrimarySelectionHandler, PrimarySelectionState}; @@ -32,11 +32,11 @@ impl PrimarySourceUserData { } } +impl UserdataGetter for PrimarySource {} + impl Dispatch for PrimarySelectionState where - D: Dispatch, D: PrimarySelectionHandler, - D: 'static, { fn request( state: &mut D, @@ -66,7 +66,7 @@ where impl IsAlive for PrimarySource { fn alive(&self) -> bool { - let data: &PrimarySourceUserData = self.data().unwrap(); + let data = self.user_data().unwrap(); data.alive_tracker.alive() } } diff --git a/src/wayland/selection/source.rs b/src/wayland/selection/source.rs index 9e20a2ff17f4..056e37e9caf0 100644 --- a/src/wayland/selection/source.rs +++ b/src/wayland/selection/source.rs @@ -2,14 +2,12 @@ use std::os::unix::io::{AsFd, OwnedFd}; use wayland_protocols::wp::primary_selection::zv1::server::zwp_primary_selection_source_v1::ZwpPrimarySelectionSourceV1 as PrimarySource; use wayland_protocols_wlr::data_control::v1::server::zwlr_data_control_source_v1::ZwlrDataControlSourceV1 as DataControlSource; -use wayland_server::{protocol::wl_data_source::WlDataSource, Resource}; +use wayland_server::protocol::wl_data_source::WlDataSource; +use crate::utils::user_data::UserdataGetter; use crate::utils::IsAlive; -use crate::wayland::selection::primary_selection::PrimarySourceUserData; -use super::data_device::DataSourceUserData; use super::private::selection_dispatch; -use super::wlr_data_control::DataControlSourceUserData; use super::SelectionTarget; /// The source of the selection data. @@ -52,15 +50,15 @@ impl SelectionSourceProvider { pub fn contains_mime_type(&self, mime_type: &String) -> bool { match self { Self::DataDevice(source) => { - let data: &DataSourceUserData = source.data().unwrap(); + let data = source.user_data().unwrap(); data.inner.lock().unwrap().mime_types.contains(mime_type) } Self::Primary(source) => { - let data: &PrimarySourceUserData = source.data().unwrap(); + let data = source.user_data().unwrap(); data.inner.lock().unwrap().mime_types.contains(mime_type) } Self::DataControl(source) => { - let data: &DataControlSourceUserData = source.data().unwrap(); + let data = source.user_data().unwrap(); data.inner.lock().unwrap().mime_types.contains(mime_type) } } @@ -70,15 +68,15 @@ impl SelectionSourceProvider { pub fn mime_types(&self) -> Vec { match self { Self::DataDevice(source) => { - let data: &DataSourceUserData = source.data().unwrap(); + let data = source.user_data().unwrap(); data.inner.lock().unwrap().mime_types.clone() } Self::Primary(source) => { - let data: &PrimarySourceUserData = source.data().unwrap(); + let data = source.user_data().unwrap(); data.inner.lock().unwrap().mime_types.clone() } Self::DataControl(source) => { - let data: &DataControlSourceUserData = source.data().unwrap(); + let data = source.user_data().unwrap(); data.inner.lock().unwrap().mime_types.clone() } } diff --git a/src/wayland/selection/wlr_data_control/device.rs b/src/wayland/selection/wlr_data_control/device.rs index 3c77a85950cb..6e0bb9908e66 100644 --- a/src/wayland/selection/wlr_data_control/device.rs +++ b/src/wayland/selection/wlr_data_control/device.rs @@ -7,6 +7,7 @@ use wayland_server::protocol::wl_seat::WlSeat; use wayland_server::{Client, Dispatch, DisplayHandle}; use crate::input::Seat; +use crate::utils::user_data::UserdataGetter; use crate::wayland::selection::device::SelectionDevice; use crate::wayland::selection::offer::OfferReplySource; use crate::wayland::selection::seat_data::SeatData; @@ -22,11 +23,11 @@ pub struct DataControlDeviceUserData { pub(crate) wl_seat: WlSeat, } +impl UserdataGetter for ZwlrDataControlDeviceV1 {} + impl Dispatch for DataControlState where - D: Dispatch, D: DataControlHandler, - D: 'static, { fn request( handler: &mut D, diff --git a/src/wayland/selection/wlr_data_control/mod.rs b/src/wayland/selection/wlr_data_control/mod.rs index a3d98199a6db..cb53a9fa7188 100644 --- a/src/wayland/selection/wlr_data_control/mod.rs +++ b/src/wayland/selection/wlr_data_control/mod.rs @@ -39,7 +39,6 @@ //! fn data_control_state(&self) -> &DataControlState { &self.data_control_state } //! // ... override default implementations here to customize handling ... //! } -//! delegate_data_control!(State); //! //! // You're now ready to go! //! ``` @@ -49,7 +48,7 @@ use wayland_protocols_wlr::data_control::v1::server::zwlr_data_control_manager_v1::ZwlrDataControlManagerV1; use wayland_server::backend::GlobalId; -use wayland_server::{Client, DisplayHandle, GlobalDispatch}; +use wayland_server::{Client, DisplayHandle}; mod device; mod source; @@ -61,7 +60,7 @@ use super::primary_selection::PrimarySelectionState; use super::SelectionHandler; /// Access the data control state. -pub trait DataControlHandler: Sized + SelectionHandler { +pub trait DataControlHandler: Sized + SelectionHandler + 'static { /// [`DataControlState`] getter. fn data_control_state(&self) -> &DataControlState; } @@ -82,14 +81,14 @@ impl DataControlState { filter: F, ) -> Self where - D: GlobalDispatch + 'static, + D: DataControlHandler, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, { let data = DataControlManagerGlobalData { primary: primary_selection.is_some(), filter: Box::new(filter), }; - let manager_global = display.create_global::(2, data); + let manager_global = display.create_delegated_global::(2, data); Self { manager_global } } @@ -120,10 +119,8 @@ mod handlers { use std::cell::RefCell; use tracing::error; - use wayland_protocols_wlr::data_control::v1::server::zwlr_data_control_device_v1::ZwlrDataControlDeviceV1; use wayland_protocols_wlr::data_control::v1::server::zwlr_data_control_manager_v1; use wayland_protocols_wlr::data_control::v1::server::zwlr_data_control_manager_v1::ZwlrDataControlManagerV1; - use wayland_protocols_wlr::data_control::v1::server::zwlr_data_control_source_v1::ZwlrDataControlSourceV1; use wayland_server::{Client, Dispatch, DisplayHandle, GlobalDispatch}; use crate::input::Seat; @@ -140,12 +137,7 @@ mod handlers { impl GlobalDispatch for DataControlState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, D: DataControlHandler, - D: 'static, { fn bind( _state: &mut D, @@ -155,7 +147,7 @@ mod handlers { global_data: &DataControlManagerGlobalData, data_init: &mut wayland_server::DataInit<'_, D>, ) { - data_init.init( + data_init.init_delegated::<_, _, Self>( resource, DataControlManagerUserData { primary: global_data.primary, @@ -170,11 +162,7 @@ mod handlers { impl Dispatch for DataControlState where - D: Dispatch, - D: Dispatch, - D: Dispatch, D: DataControlHandler, - D: 'static, { fn request( _handler: &mut D, @@ -187,7 +175,7 @@ mod handlers { ) { match request { zwlr_data_control_manager_v1::Request::CreateDataSource { id } => { - data_init.init(id, DataControlSourceUserData::new()); + data_init.init_delegated::<_, _, Self>(id, DataControlSourceUserData::new()); } zwlr_data_control_manager_v1::Request::GetDataDevice { id, seat: wl_seat } => { match Seat::::from_resource(&wl_seat) { @@ -195,13 +183,14 @@ mod handlers { seat.user_data() .insert_if_missing(|| RefCell::new(SeatData::::new())); - let device = SelectionDevice::DataControl(data_init.init( - id, - DataControlDeviceUserData { - wl_seat, - primary: data.primary, - }, - )); + let device = + SelectionDevice::DataControl(data_init.init_delegated::<_, _, Self>( + id, + DataControlDeviceUserData { + wl_seat, + primary: data.primary, + }, + )); let mut seat_data = seat .user_data() @@ -234,21 +223,9 @@ mod handlers { } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_data_control { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols_wlr::data_control::v1::server::zwlr_data_control_manager_v1::ZwlrDataControlManagerV1: $crate::wayland::selection::wlr_data_control::DataControlManagerGlobalData - ] => $crate::wayland::selection::wlr_data_control::DataControlState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols_wlr::data_control::v1::server::zwlr_data_control_manager_v1::ZwlrDataControlManagerV1: $crate::wayland::selection::wlr_data_control::DataControlManagerUserData - ] => $crate::wayland::selection::wlr_data_control::DataControlState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols_wlr::data_control::v1::server::zwlr_data_control_device_v1::ZwlrDataControlDeviceV1: $crate::wayland::selection::wlr_data_control::DataControlDeviceUserData - ] => $crate::wayland::selection::wlr_data_control::DataControlState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols_wlr::data_control::v1::server::zwlr_data_control_source_v1::ZwlrDataControlSourceV1: $crate::wayland::selection::wlr_data_control::DataControlSourceUserData - ] => $crate::wayland::selection::wlr_data_control::DataControlState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/selection/wlr_data_control/source.rs b/src/wayland/selection/wlr_data_control/source.rs index 7e90638d2a05..7ce26e5c6750 100644 --- a/src/wayland/selection/wlr_data_control/source.rs +++ b/src/wayland/selection/wlr_data_control/source.rs @@ -4,9 +4,10 @@ use wayland_protocols_wlr::data_control::v1::server::zwlr_data_control_source_v1 self, ZwlrDataControlSourceV1, }; use wayland_server::backend::ClientId; -use wayland_server::{Dispatch, DisplayHandle, Resource}; +use wayland_server::{Dispatch, DisplayHandle}; use crate::utils::alive_tracker::AliveTracker; +use crate::utils::user_data::UserdataGetter; use crate::utils::IsAlive; use super::{DataControlHandler, DataControlState}; @@ -31,11 +32,11 @@ pub struct SourceMetadata { pub mime_types: Vec, } +impl UserdataGetter for ZwlrDataControlSourceV1 {} + impl Dispatch for DataControlState where - D: Dispatch, D: DataControlHandler, - D: 'static, { fn request( _state: &mut D, @@ -68,7 +69,7 @@ where impl IsAlive for ZwlrDataControlSourceV1 { fn alive(&self) -> bool { - let data: &DataControlSourceUserData = self.data().unwrap(); + let data = self.user_data().unwrap(); data.alive_tracker.alive() } } diff --git a/src/wayland/session_lock/lock.rs b/src/wayland/session_lock/lock.rs index 4b2b877d4ac6..1884d6b09dd7 100644 --- a/src/wayland/session_lock/lock.rs +++ b/src/wayland/session_lock/lock.rs @@ -7,7 +7,6 @@ use crate::backend::renderer::buffer_dimensions; use crate::utils::Size; use crate::wayland::compositor::SurfaceAttributes; use crate::wayland::compositor::{self, BufferAssignment}; -use _session_lock::ext_session_lock_surface_v1::ExtSessionLockSurfaceV1; use _session_lock::ext_session_lock_v1::{Error, ExtSessionLockV1, Request}; use wayland_protocols::ext::session_lock::v1::server::{self as _session_lock, ext_session_lock_surface_v1}; use wayland_server::{Client, DataInit, Dispatch, DisplayHandle, Resource}; @@ -34,10 +33,7 @@ impl SessionLockState { impl Dispatch for SessionLockManagerState where - D: Dispatch, - D: Dispatch, D: SessionLockHandler, - D: 'static, { fn request( state: &mut D, @@ -79,7 +75,7 @@ where let data = ExtLockSurfaceUserData { surface: surface.clone(), }; - let lock_surface = data_init.init(id, data); + let lock_surface = data_init.init_delegated::<_, _, Self>(id, data); // Initialize surface data. compositor::with_states(&surface, |states| { diff --git a/src/wayland/session_lock/mod.rs b/src/wayland/session_lock/mod.rs index 4981dd080c95..250ea1082331 100644 --- a/src/wayland/session_lock/mod.rs +++ b/src/wayland/session_lock/mod.rs @@ -8,7 +8,6 @@ //! implement the [`SessionLockHandler`], as shown in this example: //! //! ``` -//! use smithay::delegate_session_lock; //! use smithay::reexports::wayland_server::protocol::wl_output::WlOutput; //! use smithay::wayland::session_lock::{ //! LockSurface, SessionLockManagerState, SessionLockHandler, SessionLocker, @@ -43,7 +42,6 @@ //! // Display `LockSurface` on `WlOutput`. //! } //! } -//! delegate_session_lock!(State); //! //! // You're now ready to go! //! ``` @@ -78,17 +76,13 @@ impl SessionLockManagerState { /// Create new [`ExtSessionLockManagerV1`] global. pub fn new(display: &DisplayHandle, filter: F) -> Self where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: SessionLockHandler, - D: 'static, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, { let data = SessionLockManagerGlobalData { filter: Box::new(filter), }; - display.create_global::(MANAGER_VERSION, data); + display.create_delegated_global::(MANAGER_VERSION, data); Self { locked_outputs: Vec::new(), @@ -105,11 +99,7 @@ pub struct SessionLockManagerGlobalData { impl GlobalDispatch for SessionLockManagerState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: SessionLockHandler, - D: 'static, { fn bind( _state: &mut D, @@ -119,7 +109,7 @@ where _global_data: &SessionLockManagerGlobalData, data_init: &mut DataInit<'_, D>, ) { - data_init.init(manager, ()); + data_init.init_delegated::<_, _, Self>(manager, ()); } fn can_view(client: Client, global_data: &SessionLockManagerGlobalData) -> bool { @@ -129,11 +119,7 @@ where impl Dispatch for SessionLockManagerState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: SessionLockHandler, - D: 'static, { fn request( state: &mut D, @@ -148,7 +134,7 @@ where Request::Lock { id } => { let lock_state = SessionLockState::new(); let lock_status = lock_state.lock_status.clone(); - let lock = data_init.init(id, lock_state); + let lock = data_init.init_delegated::<_, _, Self>(id, lock_state); state.lock(SessionLocker::new(lock, lock_status)); } Request::Destroy => (), @@ -158,7 +144,7 @@ where } /// Handler trait for ext-session-lock. -pub trait SessionLockHandler { +pub trait SessionLockHandler: 'static { /// Session lock state. fn lock_state(&mut self) -> &mut SessionLockManagerState; @@ -222,24 +208,9 @@ impl SessionLocker { } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] #[macro_export] macro_rules! delegate_session_lock { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::ext::session_lock::v1::server::ext_session_lock_manager_v1::ExtSessionLockManagerV1: $crate::wayland::session_lock::SessionLockManagerGlobalData - ] => $crate::wayland::session_lock::SessionLockManagerState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::ext::session_lock::v1::server::ext_session_lock_manager_v1::ExtSessionLockManagerV1: () - ] => $crate::wayland::session_lock::SessionLockManagerState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::ext::session_lock::v1::server::ext_session_lock_v1::ExtSessionLockV1: $crate::wayland::session_lock::SessionLockState - ] => $crate::wayland::session_lock::SessionLockManagerState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::ext::session_lock::v1::server::ext_session_lock_surface_v1::ExtSessionLockSurfaceV1: $crate::wayland::session_lock::ExtLockSurfaceUserData - ] => $crate::wayland::session_lock::SessionLockManagerState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/session_lock/surface.rs b/src/wayland/session_lock/surface.rs index 2847040be5f4..149888f20a74 100644 --- a/src/wayland/session_lock/surface.rs +++ b/src/wayland/session_lock/surface.rs @@ -19,9 +19,7 @@ pub struct ExtLockSurfaceUserData { impl Dispatch for SessionLockManagerState where - D: Dispatch, D: SessionLockHandler, - D: 'static, { fn request( state: &mut D, diff --git a/src/wayland/shell/kde/decoration.rs b/src/wayland/shell/kde/decoration.rs index 41c3c5f06de5..9facab273052 100644 --- a/src/wayland/shell/kde/decoration.rs +++ b/src/wayland/shell/kde/decoration.rs @@ -8,7 +8,6 @@ //! extern crate wayland_server; //! extern crate smithay; //! -//! use smithay::delegate_kde_decoration; //! use smithay::wayland::shell::kde::decoration::{KdeDecorationHandler, KdeDecorationState}; //! use wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration_manager::Mode; //! @@ -27,8 +26,6 @@ //! &self.kde_decoration_state //! } //! } -//! -//! delegate_kde_decoration!(State); //! ``` use wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration::{ @@ -39,7 +36,7 @@ use wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decor }; use wayland_server::backend::GlobalId; use wayland_server::protocol::wl_surface::WlSurface; -use wayland_server::{Client, Dispatch, DisplayHandle, GlobalDispatch, WEnum}; +use wayland_server::{Client, DisplayHandle, WEnum}; /// KDE server decoration handler. pub trait KdeDecorationHandler { @@ -93,11 +90,7 @@ impl KdeDecorationState { /// Create a new KDE server decoration global. pub fn new(display: &DisplayHandle, default_mode: DefaultMode) -> Self where - D: GlobalDispatch - + Dispatch - + Dispatch - + KdeDecorationHandler - + 'static, + D: KdeDecorationHandler + 'static, { Self::new_with_filter::(display, default_mode, |_| true) } @@ -107,18 +100,14 @@ impl KdeDecorationState { /// Filters can be used to limit visibility of a global to certain clients. pub fn new_with_filter(display: &DisplayHandle, default_mode: DefaultMode, filter: F) -> Self where - D: GlobalDispatch - + Dispatch - + Dispatch - + KdeDecorationHandler - + 'static, + D: KdeDecorationHandler + 'static, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, { let data = KdeDecorationManagerGlobalData { filter: Box::new(filter), }; let kde_decoration_manager = - display.create_global::(1, data); + display.create_delegated_global::(1, data); Self { kde_decoration_manager, @@ -132,20 +121,9 @@ impl KdeDecorationState { } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_kde_decoration { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration_manager::OrgKdeKwinServerDecorationManager: $crate::wayland::shell::kde::decoration::KdeDecorationManagerGlobalData - ] => $crate::wayland::shell::kde::decoration::KdeDecorationState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration_manager::OrgKdeKwinServerDecorationManager: () - ] => $crate::wayland::shell::kde::decoration::KdeDecorationState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration::OrgKdeKwinServerDecoration: $crate::reexports::wayland_server::protocol::wl_surface::WlSurface - ] => $crate::wayland::shell::kde::decoration::KdeDecorationState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/shell/kde/handlers.rs b/src/wayland/shell/kde/handlers.rs index 2d6d33d5e459..9af73d658e6a 100644 --- a/src/wayland/shell/kde/handlers.rs +++ b/src/wayland/shell/kde/handlers.rs @@ -8,8 +8,9 @@ use wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decor OrgKdeKwinServerDecorationManager, Request as ManagerRequest, }; use wayland_server::protocol::wl_surface::WlSurface; -use wayland_server::{Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource}; +use wayland_server::{Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New}; +use crate::utils::user_data::UserdataGetter; use crate::wayland::shell::kde::decoration::{KdeDecorationHandler, KdeDecorationState}; use super::decoration::KdeDecorationManagerGlobalData; @@ -17,11 +18,7 @@ use super::decoration::KdeDecorationManagerGlobalData; impl GlobalDispatch for KdeDecorationState where - D: GlobalDispatch - + Dispatch - + Dispatch - + KdeDecorationHandler - + 'static, + D: KdeDecorationHandler + 'static, { fn bind( state: &mut D, @@ -31,7 +28,7 @@ where _global_data: &KdeDecorationManagerGlobalData, data_init: &mut DataInit<'_, D>, ) { - let kde_decoration_manager = data_init.init(resource, ()); + let kde_decoration_manager = data_init.init_delegated::<_, _, Self>(resource, ()); // Set default decoration mode. let default_mode = state.kde_decoration_state().default_mode; @@ -47,11 +44,7 @@ where impl Dispatch for KdeDecorationState where - D: Dispatch - + Dispatch - + Dispatch - + KdeDecorationHandler - + 'static, + D: KdeDecorationHandler + 'static, { fn request( state: &mut D, @@ -67,18 +60,20 @@ where _ => unreachable!(), }; - let kde_decoration = data_init.init(id, surface); + let kde_decoration = data_init.init_delegated::<_, _, Self>(id, surface); - let surface = kde_decoration.data().unwrap(); + let surface = kde_decoration.user_data().unwrap(); state.new_decoration(surface, &kde_decoration); trace!(surface = ?surface, "Created decoration object for surface"); } } +impl UserdataGetter for OrgKdeKwinServerDecoration {} + impl Dispatch for KdeDecorationState where - D: Dispatch + KdeDecorationHandler + 'static, + D: KdeDecorationHandler, { fn request( state: &mut D, diff --git a/src/wayland/shell/wlr_layer/handlers.rs b/src/wayland/shell/wlr_layer/handlers.rs index 3f052a5f3af1..f13e85821c9c 100644 --- a/src/wayland/shell/wlr_layer/handlers.rs +++ b/src/wayland/shell/wlr_layer/handlers.rs @@ -6,6 +6,7 @@ use wayland_protocols_wlr::layer_shell::v1::server::zwlr_layer_surface_v1::ZwlrL use wayland_server::protocol::wl_surface; use wayland_server::{Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, Resource}; +use crate::utils::user_data::UserdataGetter; use crate::utils::{ alive_tracker::{AliveTracker, IsAlive}, Serial, @@ -26,11 +27,7 @@ use super::LAYER_SURFACE_ROLE; impl GlobalDispatch for WlrLayerShellState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, D: WlrLayerShellHandler, - D: 'static, { fn bind( _state: &mut D, @@ -40,7 +37,7 @@ where _global_data: &WlrLayerShellGlobalData, data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } fn can_view(client: Client, global_data: &WlrLayerShellGlobalData) -> bool { @@ -50,10 +47,7 @@ where impl Dispatch for WlrLayerShellState where - D: Dispatch, - D: Dispatch, D: WlrLayerShellHandler, - D: 'static, { fn request( state: &mut D, @@ -88,7 +82,7 @@ where return; } - let id = data_init.init( + let id = data_init.init_delegated::<_, _, Self>( id, WlrLayerSurfaceUserData { shell_data: state.shell_state().clone(), @@ -188,14 +182,15 @@ pub struct WlrLayerSurfaceUserData { impl IsAlive for ZwlrLayerSurfaceV1 { fn alive(&self) -> bool { - let data: &WlrLayerSurfaceUserData = self.data().unwrap(); + let data: &WlrLayerSurfaceUserData = self.user_data().unwrap(); data.alive_tracker.alive() } } +impl UserdataGetter for ZwlrLayerSurfaceV1 {} + impl Dispatch for WlrLayerShellState where - D: Dispatch, D: WlrLayerShellHandler, { fn request( @@ -274,9 +269,7 @@ where zwlr_layer_surface_v1::Request::GetPopup { popup } => { let parent_surface = data.wl_surface.clone(); - let data = popup - .data::() - .unwrap(); + let data = popup.user_data().unwrap(); compositor::with_states(&data.wl_surface, move |states| { states @@ -362,7 +355,7 @@ fn with_surface_pending_state(layer_surface: &zwlr_layer_surface_v1::ZwlrL where F: FnOnce(&mut LayerSurfaceCachedState) -> T, { - let data = layer_surface.data::().unwrap(); + let data = layer_surface.user_data().unwrap(); compositor::with_states(&data.wl_surface, |states| { f(&mut states.cached_state.pending::()) }) @@ -371,7 +364,7 @@ where pub fn make_surface_handle( resource: &zwlr_layer_surface_v1::ZwlrLayerSurfaceV1, ) -> crate::wayland::shell::wlr_layer::LayerSurface { - let data = resource.data::().unwrap(); + let data = resource.user_data().unwrap(); crate::wayland::shell::wlr_layer::LayerSurface { wl_surface: data.wl_surface.clone(), shell_surface: resource.clone(), diff --git a/src/wayland/shell/wlr_layer/mod.rs b/src/wayland/shell/wlr_layer/mod.rs index 2ada43494aa0..968259167d83 100644 --- a/src/wayland/shell/wlr_layer/mod.rs +++ b/src/wayland/shell/wlr_layer/mod.rs @@ -11,7 +11,6 @@ //! ```no_run //! # extern crate wayland_server; //! # -//! use smithay::delegate_layer_shell; //! use smithay::wayland::shell::wlr_layer::{WlrLayerShellState, WlrLayerShellHandler, LayerSurface, Layer}; //! use smithay::reexports::wayland_server::protocol::wl_output::WlOutput; //! @@ -39,8 +38,6 @@ //! // your implementation //! } //! } -//! // let smithay implement wayland_server::DelegateDispatch -//! delegate_layer_shell!(State); //! //! // You're now ready to go! //! ``` @@ -54,7 +51,7 @@ use wayland_protocols_wlr::layer_shell::v1::server::{ use wayland_server::{ backend::GlobalId, protocol::{wl_output::WlOutput, wl_surface}, - Client, DisplayHandle, GlobalDispatch, Resource, + Client, DisplayHandle, Resource, }; use crate::{ @@ -226,8 +223,7 @@ impl WlrLayerShellState { /// Create a new `wlr_layer_shell` global pub fn new(display: &DisplayHandle) -> WlrLayerShellState where - D: GlobalDispatch, - D: 'static, + D: WlrLayerShellHandler, { Self::new_with_filter::(display, |_| true) } @@ -235,11 +231,10 @@ impl WlrLayerShellState { /// Create a new `wlr_layer_shell` global with a client filter pub fn new_with_filter(display: &DisplayHandle, filter: F) -> WlrLayerShellState where - D: GlobalDispatch, - D: 'static, + D: WlrLayerShellHandler, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, { - let shell_global = display.create_global::( + let shell_global = display.create_delegated_global::( 4, WlrLayerShellGlobalData { filter: Box::new(filter), @@ -265,7 +260,7 @@ impl WlrLayerShellState { /// Handler for wlr layer shell #[allow(unused_variables)] -pub trait WlrLayerShellHandler { +pub trait WlrLayerShellHandler: 'static { /// [WlrLayerShellState] getter fn shell_state(&mut self) -> &mut WlrLayerShellState; @@ -511,23 +506,8 @@ pub struct LayerSurfaceConfigure { /// Macro to delegate implementation of wlr layer shell to [`WlrLayerShellState`]. /// /// You must also implement [`WlrLayerShellHandler`] to use this. +#[deprecated(note = "No longer needed, this is now NOP")] #[macro_export] macro_rules! delegate_layer_shell { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - type __ZwlrLayerShellV1 = - $crate::reexports::wayland_protocols_wlr::layer_shell::v1::server::zwlr_layer_shell_v1::ZwlrLayerShellV1; - type __ZwlrLayerShellSurfaceV1 = - $crate::reexports::wayland_protocols_wlr::layer_shell::v1::server::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1; - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - __ZwlrLayerShellV1: () - ] => $crate::wayland::shell::wlr_layer::WlrLayerShellState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - __ZwlrLayerShellSurfaceV1: $crate::wayland::shell::wlr_layer::WlrLayerSurfaceUserData - ] => $crate::wayland::shell::wlr_layer::WlrLayerShellState); - - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - __ZwlrLayerShellV1: $crate::wayland::shell::wlr_layer::WlrLayerShellGlobalData - ] => $crate::wayland::shell::wlr_layer::WlrLayerShellState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/shell/xdg/decoration.rs b/src/wayland/shell/xdg/decoration.rs index 215ffe4d2de5..54b3e5093e5e 100644 --- a/src/wayland/shell/xdg/decoration.rs +++ b/src/wayland/shell/xdg/decoration.rs @@ -8,7 +8,6 @@ //! ```no_run //! # extern crate wayland_server; //! # -//! use smithay::{delegate_xdg_decoration, delegate_xdg_shell}; //! use smithay::wayland::shell::xdg::{ToplevelSurface, XdgShellHandler}; //! # use smithay::utils::Serial; //! # use smithay::wayland::shell::xdg::{XdgShellState, PopupSurface, PositionerState}; @@ -81,22 +80,20 @@ //! // handle new images for the cursor ... //! } //! } -//! delegate_xdg_shell!(State); -//! delegate_xdg_decoration!(State); //! //! // You are ready to go! // TODO: Describe how to change decoration mode. use wayland_protocols::xdg::decoration::zv1::server::{ - zxdg_decoration_manager_v1, - zxdg_toplevel_decoration_v1::{self, Mode}, + zxdg_decoration_manager_v1::{self, ZxdgDecorationManagerV1}, + zxdg_toplevel_decoration_v1::{self, Mode, ZxdgToplevelDecorationV1}, }; use wayland_server::{ backend::GlobalId, Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, WEnum, }; use super::{ToplevelSurface, XdgShellHandler}; -use crate::wayland::shell::xdg::XdgShellSurfaceUserData; +use crate::utils::user_data::UserdataGetter; /// Delegate type for handling xdg decoration events. #[derive(Debug)] @@ -116,11 +113,7 @@ impl XdgDecorationState { /// A global id is also returned to allow destroying the global in the future. pub fn new(display: &DisplayHandle) -> XdgDecorationState where - D: GlobalDispatch< - zxdg_decoration_manager_v1::ZxdgDecorationManagerV1, - XdgDecorationManagerGlobalData, - > + Dispatch - + 'static, + D: XdgDecorationHandler, { Self::new_with_filter::(display, |_| true) } @@ -132,18 +125,16 @@ impl XdgDecorationState { /// A global id is also returned to allow destroying the global in the future. pub fn new_with_filter(display: &DisplayHandle, filter: F) -> XdgDecorationState where - D: GlobalDispatch< - zxdg_decoration_manager_v1::ZxdgDecorationManagerV1, - XdgDecorationManagerGlobalData, - > + Dispatch - + 'static, + D: XdgDecorationHandler, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, { let data = XdgDecorationManagerGlobalData { filter: Box::new(filter), }; - let global = - display.create_global::(1, data); + let global = display + .create_delegated_global::( + 1, data, + ); XdgDecorationState { global } } @@ -155,7 +146,7 @@ impl XdgDecorationState { } /// Handler trait for xdg decoration events. -pub trait XdgDecorationHandler { +pub trait XdgDecorationHandler: XdgShellHandler + 'static { /// Notification the client supports server side decoration on the toplevel. fn new_decoration(&mut self, toplevel: ToplevelSurface); @@ -169,48 +160,29 @@ pub trait XdgDecorationHandler { /// Macro to delegate implementation of the xdg decoration to [`XdgDecorationState`]. /// /// You must also implement [`XdgDecorationHandler`] to use this. +#[deprecated(note = "No longer needed, this is now NOP")] #[macro_export] macro_rules! delegate_xdg_decoration { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_decoration_manager_v1::ZxdgDecorationManagerV1: $crate::wayland::shell::xdg::decoration::XdgDecorationManagerGlobalData - ] => $crate::wayland::shell::xdg::decoration::XdgDecorationState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_decoration_manager_v1::ZxdgDecorationManagerV1: () - ] => $crate::wayland::shell::xdg::decoration::XdgDecorationState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1: $crate::wayland::shell::xdg::ToplevelSurface - ] => $crate::wayland::shell::xdg::decoration::XdgDecorationState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } -pub(super) fn send_decoration_configure( - id: &zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1, - mode: Mode, -) { +pub(super) fn send_decoration_configure(id: &ZxdgToplevelDecorationV1, mode: Mode) { id.configure(mode) } -impl GlobalDispatch - for XdgDecorationState +impl GlobalDispatch for XdgDecorationState where - D: GlobalDispatch - + Dispatch - + Dispatch - + XdgShellHandler - + XdgDecorationHandler - + 'static, + D: XdgDecorationHandler, { fn bind( _: &mut D, _: &DisplayHandle, _: &Client, - resource: New, + resource: New, _: &XdgDecorationManagerGlobalData, data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } fn can_view(client: Client, global_data: &XdgDecorationManagerGlobalData) -> bool { @@ -218,28 +190,24 @@ where } } -impl Dispatch for XdgDecorationState +impl Dispatch for XdgDecorationState where - D: Dispatch - + Dispatch - + XdgShellHandler - + XdgDecorationHandler - + 'static, + D: XdgDecorationHandler, { fn request( state: &mut D, _: &Client, - resource: &zxdg_decoration_manager_v1::ZxdgDecorationManagerV1, + resource: &ZxdgDecorationManagerV1, request: zxdg_decoration_manager_v1::Request, _: &(), _dh: &DisplayHandle, data_init: &mut DataInit<'_, D>, ) { - use self::zxdg_decoration_manager_v1::Request; + use zxdg_decoration_manager_v1::Request; match request { Request::GetToplevelDecoration { id, toplevel } => { - let data = toplevel.data::().unwrap(); + let data = toplevel.user_data().unwrap(); let mut decoration_guard = data.decoration.lock().unwrap(); @@ -252,7 +220,7 @@ where } let toplevel = state.xdg_shell_state().get_toplevel(&toplevel).unwrap(); - let toplevel_decoration = data_init.init(id, toplevel.clone()); + let toplevel_decoration = data_init.init_delegated::<_, _, Self>(id, toplevel.clone()); *decoration_guard = Some(toplevel_decoration); drop(decoration_guard); @@ -269,22 +237,20 @@ where // zxdg_toplevel_decoration_v1 -impl Dispatch - for XdgDecorationState +impl Dispatch for XdgDecorationState where - D: Dispatch - + XdgDecorationHandler, + D: XdgDecorationHandler, { fn request( state: &mut D, _: &Client, - _: &zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1, + _: &ZxdgToplevelDecorationV1, request: zxdg_toplevel_decoration_v1::Request, data: &ToplevelSurface, _dh: &DisplayHandle, _: &mut DataInit<'_, D>, ) { - use self::zxdg_toplevel_decoration_v1::Request; + use zxdg_toplevel_decoration_v1::Request; match request { Request::SetMode { mode } => { @@ -298,7 +264,7 @@ where } Request::Destroy => { - if let Some(data) = data.xdg_toplevel().data::() { + if let Some(data) = data.xdg_toplevel().user_data() { data.decoration.lock().unwrap().take(); } } diff --git a/src/wayland/shell/xdg/handlers/positioner.rs b/src/wayland/shell/xdg/handlers/positioner.rs index c054e377bf0c..ffbd22420797 100644 --- a/src/wayland/shell/xdg/handlers/positioner.rs +++ b/src/wayland/shell/xdg/handlers/positioner.rs @@ -1,6 +1,9 @@ use std::sync::Mutex; -use crate::{utils::Rectangle, utils::Serial}; +use crate::{ + utils::Rectangle, + utils::{user_data::UserdataGetter, Serial}, +}; use wayland_protocols::xdg::shell::server::{xdg_positioner, xdg_positioner::XdgPositioner}; @@ -18,11 +21,11 @@ pub struct XdgPositionerUserData { pub(crate) inner: Mutex, } +impl UserdataGetter for XdgPositioner {} + impl Dispatch for XdgShellState where - D: Dispatch, D: XdgShellHandler, - D: 'static, { fn request( _state: &mut D, diff --git a/src/wayland/shell/xdg/handlers/surface.rs b/src/wayland/shell/xdg/handlers/surface.rs index 2b4b7cc47d41..5326f686315c 100644 --- a/src/wayland/shell/xdg/handlers/surface.rs +++ b/src/wayland/shell/xdg/handlers/surface.rs @@ -5,7 +5,7 @@ use std::sync::Mutex; use indexmap::IndexSet; use crate::utils::alive_tracker::{AliveTracker, IsAlive}; -use crate::wayland::shell::xdg::{XdgPopupSurfaceData, XdgToplevelSurfaceData}; +use crate::wayland::shell::xdg::{UserdataGetter, XdgPopupSurfaceData, XdgToplevelSurfaceData}; use crate::{ utils::{Rectangle, Serial}, wayland::{ @@ -24,8 +24,8 @@ use wayland_protocols::{ use wayland_server::{protocol::wl_surface, DataInit, Dispatch, DisplayHandle, Resource, Weak}; use super::{ - PopupConfigure, SurfaceCachedState, ToplevelConfigure, XdgPopupSurfaceRoleAttributes, - XdgPositionerUserData, XdgShellHandler, XdgToplevelSurfaceRoleAttributes, + PopupConfigure, SurfaceCachedState, ToplevelConfigure, XdgPopupSurfaceRoleAttributes, XdgShellHandler, + XdgToplevelSurfaceRoleAttributes, }; mod toplevel; @@ -44,13 +44,11 @@ pub struct XdgSurfaceUserData { pub(crate) has_active_role: AtomicBool, } +impl UserdataGetter for XdgSurface {} + impl Dispatch for XdgShellState where - D: Dispatch, - D: Dispatch, - D: Dispatch, D: XdgShellHandler, - D: 'static, { fn request( state: &mut D, @@ -126,7 +124,7 @@ where ); } - let toplevel = data_init.init( + let toplevel = data_init.init_delegated::<_, _, Self>( id, XdgShellSurfaceUserData { wl_surface: data.wl_surface.clone(), @@ -151,15 +149,10 @@ where parent, positioner, } => { - let positioner_data = *positioner - .data::() - .unwrap() - .inner - .lock() - .unwrap(); + let positioner_data = *positioner.user_data().unwrap().inner.lock().unwrap(); let parent_surface = parent.map(|parent| { - let parent_data = parent.data::().unwrap(); + let parent_data = parent.user_data().unwrap(); parent_data.wl_surface.clone() }); @@ -200,7 +193,7 @@ where compositor::add_pre_commit_hook::(surface, super::super::PopupSurface::commit_hook); } - let popup = data_init.init( + let popup = data_init.init_delegated::<_, _, Self>( id, XdgShellSurfaceUserData { wl_surface: data.wl_surface.clone(), @@ -335,14 +328,14 @@ pub struct XdgShellSurfaceUserData { impl IsAlive for XdgToplevel { fn alive(&self) -> bool { - let data: &XdgShellSurfaceUserData = self.data().unwrap(); + let data: &XdgShellSurfaceUserData = self.user_data().unwrap(); data.alive_tracker.alive() } } impl IsAlive for XdgPopup { fn alive(&self) -> bool { - let data: &XdgShellSurfaceUserData = self.data().unwrap(); + let data: &XdgShellSurfaceUserData = self.user_data().unwrap(); data.alive_tracker.alive() } } diff --git a/src/wayland/shell/xdg/handlers/surface/popup.rs b/src/wayland/shell/xdg/handlers/surface/popup.rs index 3f9d2f871a8e..977753ed1e45 100644 --- a/src/wayland/shell/xdg/handlers/surface/popup.rs +++ b/src/wayland/shell/xdg/handlers/surface/popup.rs @@ -1,11 +1,10 @@ use std::sync::atomic::Ordering; use crate::{ - input::SeatHandler, utils::Serial, wayland::{ compositor, - shell::xdg::{SurfaceCachedState, XdgPopupSurfaceData, XdgPositionerUserData}, + shell::xdg::{SurfaceCachedState, UserdataGetter, XdgPopupSurfaceData}, }, }; @@ -13,14 +12,13 @@ use wayland_protocols::xdg::shell::server::xdg_popup::{self, XdgPopup}; use wayland_server::{backend::ClientId, DataInit, Dispatch, DisplayHandle, Resource}; -use super::{PopupConfigure, XdgShellHandler, XdgShellState, XdgShellSurfaceUserData, XdgSurfaceUserData}; +use super::{PopupConfigure, XdgShellHandler, XdgShellState, XdgShellSurfaceUserData}; + +impl UserdataGetter for XdgPopup {} impl Dispatch for XdgShellState where - D: Dispatch, D: XdgShellHandler, - D: SeatHandler, - D: 'static, { fn request( state: &mut D, @@ -33,7 +31,7 @@ where ) { match request { xdg_popup::Request::Destroy => { - if let Some(surface_data) = data.xdg_surface.data::() { + if let Some(surface_data) = data.xdg_surface.user_data() { surface_data.has_active_role.store(false, Ordering::Release); } } @@ -53,12 +51,7 @@ where shell_surface: popup.clone(), }; - let positioner_data = *positioner - .data::() - .unwrap() - .inner - .lock() - .unwrap(); + let positioner_data = *positioner.user_data().unwrap().inner.lock().unwrap(); XdgShellHandler::reposition_request(state, handle, positioner_data, token); } @@ -94,7 +87,7 @@ where } pub fn send_popup_configure(resource: &XdgPopup, configure: PopupConfigure) { - let data = resource.data::().unwrap(); + let data = resource.user_data().unwrap(); let serial = configure.serial; let geometry = configure.state.geometry; @@ -113,7 +106,7 @@ pub fn send_popup_configure(resource: &XdgPopup, configure: PopupConfigure) { } pub fn make_popup_handle(resource: &XdgPopup) -> crate::wayland::shell::xdg::PopupSurface { - let data = resource.data::().unwrap(); + let data = resource.user_data().unwrap(); crate::wayland::shell::xdg::PopupSurface { wl_surface: data.wl_surface.clone(), shell_surface: resource.clone(), diff --git a/src/wayland/shell/xdg/handlers/surface/toplevel.rs b/src/wayland/shell/xdg/handlers/surface/toplevel.rs index fdbb4faffea0..026c7886c3b5 100644 --- a/src/wayland/shell/xdg/handlers/surface/toplevel.rs +++ b/src/wayland/shell/xdg/handlers/surface/toplevel.rs @@ -1,7 +1,7 @@ use std::sync::atomic::Ordering; use crate::{ - utils::Serial, + utils::{user_data::UserdataGetter, Serial}, wayland::{compositor, shell::xdg::XdgToplevelSurfaceData}, }; @@ -13,14 +13,14 @@ use wayland_server::{ use super::{ SurfaceCachedState, ToplevelConfigure, XdgShellHandler, XdgShellState, XdgShellSurfaceUserData, - XdgSurfaceUserData, XdgToplevelSurfaceRoleAttributes, + XdgToplevelSurfaceRoleAttributes, }; +impl UserdataGetter for XdgToplevel {} + impl Dispatch for XdgShellState where - D: Dispatch, D: XdgShellHandler, - D: 'static, { fn request( state: &mut D, @@ -33,17 +33,13 @@ where ) { match request { xdg_toplevel::Request::Destroy => { - if let Some(surface_data) = data.xdg_surface.data::() { + if let Some(surface_data) = data.xdg_surface.user_data() { surface_data.has_active_role.store(false, Ordering::Release); } } xdg_toplevel::Request::SetParent { parent } => { let parent_surface = parent.map(|toplevel_surface_parent| { - toplevel_surface_parent - .data::() - .unwrap() - .wl_surface - .clone() + toplevel_surface_parent.user_data().unwrap().wl_surface.clone() }); // Parent is not double buffered, we can set it directly @@ -177,7 +173,7 @@ fn with_surface_toplevel_role_data(toplevel: &xdg_toplevel::XdgToplevel, f where F: FnOnce(&mut XdgToplevelSurfaceRoleAttributes) -> T, { - let data = toplevel.data::().unwrap(); + let data = toplevel.user_data().unwrap(); compositor::with_states(&data.wl_surface, |states| { f(&mut states .data_map @@ -191,7 +187,7 @@ where pub(super) fn make_toplevel_handle( resource: &xdg_toplevel::XdgToplevel, ) -> crate::wayland::shell::xdg::ToplevelSurface { - let data = resource.data::().unwrap(); + let data = resource.user_data().unwrap(); crate::wayland::shell::xdg::ToplevelSurface { wl_surface: data.wl_surface.clone(), shell_surface: resource.clone(), @@ -230,7 +226,7 @@ pub fn send_toplevel_configure( send_bounds: bool, send_capabilities: bool, ) { - let data = resource.data::().unwrap(); + let data = resource.user_data().unwrap(); let (width, height) = configure.state.size.unwrap_or_default().into(); // convert the Vec (which is really a Vec) into Vec let states = { diff --git a/src/wayland/shell/xdg/handlers/wm_base.rs b/src/wayland/shell/xdg/handlers/wm_base.rs index c26872a41bc7..607019ca3166 100644 --- a/src/wayland/shell/xdg/handlers/wm_base.rs +++ b/src/wayland/shell/xdg/handlers/wm_base.rs @@ -4,12 +4,10 @@ use indexmap::IndexSet; use crate::{ utils::{alive_tracker::AliveTracker, IsAlive, Serial}, - wayland::shell::xdg::XdgShellState, + wayland::shell::xdg::{UserdataGetter, XdgShellState}, }; -use wayland_protocols::xdg::shell::server::{ - xdg_positioner::XdgPositioner, xdg_surface, xdg_surface::XdgSurface, xdg_wm_base, xdg_wm_base::XdgWmBase, -}; +use wayland_protocols::xdg::shell::server::{xdg_surface, xdg_wm_base, xdg_wm_base::XdgWmBase}; use wayland_server::{ backend::ClientId, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, Weak, @@ -19,12 +17,7 @@ use super::{ShellClient, ShellClientData, XdgPositionerUserData, XdgShellHandler impl GlobalDispatch for XdgShellState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, D: XdgShellHandler, - D: 'static, { fn bind( state: &mut D, @@ -34,19 +27,17 @@ where _global_data: &(), data_init: &mut DataInit<'_, D>, ) { - let shell = data_init.init(resource, XdgWmBaseUserData::default()); + let shell = data_init.init_delegated::<_, _, Self>(resource, XdgWmBaseUserData::default()); XdgShellHandler::new_client(state, ShellClient::new(&shell)); } } +impl UserdataGetter for XdgWmBase {} + impl Dispatch for XdgShellState where - D: Dispatch, - D: Dispatch, - D: Dispatch, D: XdgShellHandler, - D: 'static, { fn request( state: &mut D, @@ -59,13 +50,13 @@ where ) { match request { xdg_wm_base::Request::CreatePositioner { id } => { - data_init.init(id, XdgPositionerUserData::default()); + data_init.init_delegated::<_, _, Self>(id, XdgPositionerUserData::default()); } xdg_wm_base::Request::GetXdgSurface { id, surface } => { // Do not assign a role to the surface here // xdg_surface is not role, only xdg_toplevel and // xdg_popup are defined as roles - let xdg_surface = data_init.init( + let xdg_surface = data_init.init_delegated::<_, _, Self>( id, XdgSurfaceUserData { known_surfaces: data.known_surfaces.clone(), @@ -114,7 +105,7 @@ where impl IsAlive for XdgWmBase { fn alive(&self) -> bool { - let data: &XdgWmBaseUserData = self.data().unwrap(); + let data: &XdgWmBaseUserData = self.user_data().unwrap(); data.alive_tracker.alive() } } diff --git a/src/wayland/shell/xdg/mod.rs b/src/wayland/shell/xdg/mod.rs index 4f4654e36421..3419d512274e 100644 --- a/src/wayland/shell/xdg/mod.rs +++ b/src/wayland/shell/xdg/mod.rs @@ -25,7 +25,6 @@ //! ```no_run //! # extern crate wayland_server; //! # -//! use smithay::delegate_xdg_shell; //! use smithay::reexports::wayland_server::protocol::{wl_seat, wl_surface}; //! use smithay::wayland::shell::xdg::{XdgShellState, XdgShellHandler, ToplevelSurface, PopupSurface, PositionerState}; //! use smithay::utils::Serial; @@ -94,7 +93,6 @@ //! // handle new images for the cursor ... //! } //! } -//! delegate_xdg_shell!(State); //! //! // You're now ready to go! //! ``` @@ -119,6 +117,7 @@ //! the [`XdgShellHandler`], or via methods on the [`XdgShellState`]. use crate::utils::alive_tracker::IsAlive; +use crate::utils::user_data::UserdataGetter; use crate::utils::{user_data::UserDataMap, Logical, Point, Rectangle, Size}; use crate::utils::{Serial, SERIAL_COUNTER}; use crate::wayland::compositor; @@ -135,7 +134,7 @@ use wayland_protocols::xdg::shell::server::{xdg_popup, xdg_positioner, xdg_tople use wayland_server::backend::GlobalId; use wayland_server::{ protocol::{wl_output, wl_seat, wl_surface}, - DisplayHandle, GlobalDispatch, Resource, + DisplayHandle, Resource, }; use super::PingError; @@ -1045,7 +1044,7 @@ impl Cacheable for SurfaceCachedState { /// Xdg Shell handler type #[allow(unused_variables)] -pub trait XdgShellHandler { +pub trait XdgShellHandler: 'static { /// [XdgShellState] getter fn xdg_shell_state(&mut self) -> &mut XdgShellState; @@ -1182,7 +1181,7 @@ impl XdgShellState { /// Create a new `xdg_shell` global with all [`WmCapabilities`](xdg_toplevel::WmCapabilities) pub fn new(display: &DisplayHandle) -> XdgShellState where - D: GlobalDispatch + 'static, + D: XdgShellHandler, { Self::new_with_capabilities::( display, @@ -1201,9 +1200,9 @@ impl XdgShellState { capabilities: impl Into, ) -> XdgShellState where - D: GlobalDispatch + 'static, + D: XdgShellHandler, { - let global = display.create_global::(6, ()); + let global = display.create_delegated_global::(6, ()); XdgShellState { known_toplevels: Vec::new(), @@ -1306,7 +1305,7 @@ impl ShellClient { if !self.alive() { return Err(PingError::DeadSurface); } - let user_data = self.kind.data::().unwrap(); + let user_data = self.kind.user_data().unwrap(); let mut guard = user_data.client_data.lock().unwrap(); if let Some(pending_ping) = guard.pending_ping { return Err(PingError::PingAlreadyPending(pending_ping)); @@ -1340,7 +1339,7 @@ impl ShellClient { if !self.alive() { return Err(crate::utils::DeadResource); } - let data = self.kind.data::().unwrap(); + let data = self.kind.user_data().unwrap(); let mut guard = data.client_data.lock().unwrap(); Ok(f(&mut guard.data)) } @@ -1374,10 +1373,7 @@ impl ToplevelSurface { /// Retrieve the shell client owning this toplevel surface pub fn client(&self) -> ShellClient { let shell = { - let data = self - .shell_surface - .data::() - .unwrap(); + let data = self.shell_surface.user_data().unwrap(); data.wm_base.clone() }; @@ -1439,7 +1435,7 @@ impl ToplevelSurface { /// Note: This will always send a configure event, if you intend to only send a configure event on changes take a look at /// [`send_pending_configure`](ToplevelSurface::send_pending_configure) pub fn send_configure(&self) -> Serial { - let shell_surface_data = self.shell_surface.data::(); + let shell_surface_data = &self.shell_surface.user_data(); let decoration = shell_surface_data.and_then(|data| data.decoration.lock().unwrap().as_ref().cloned()); let (configure, decoration_mode_changed, bounds_changed, capabilities_changed) = @@ -1555,10 +1551,7 @@ impl ToplevelSurface { .configured }); if !configured { - let data = self - .shell_surface - .data::() - .unwrap(); + let data = self.shell_surface.user_data().unwrap(); data.xdg_surface.post_error( xdg_surface::Error::NotConstructed, "Surface has not been configured yet.", @@ -1720,10 +1713,7 @@ impl PopupSurface { /// Retrieve the shell client owning this popup surface pub fn client(&self) -> ShellClient { let shell = { - let data = self - .shell_surface - .data::() - .unwrap(); + let data = self.shell_surface.user_data().unwrap(); data.wm_base.clone() }; @@ -1858,7 +1848,7 @@ impl PopupSurface { } }); if let Some(handle) = send_error_to { - let data = handle.data::().unwrap(); + let data = handle.user_data().unwrap(); data.xdg_surface.post_error( xdg_surface::Error::NotConstructed, "Surface has not been configured yet.", @@ -1904,10 +1894,7 @@ impl PopupSurface { .configured }); if !configured { - let data = self - .shell_surface - .data::() - .unwrap(); + let data = self.shell_surface.user_data().unwrap(); data.xdg_surface.post_error( xdg_surface::Error::NotConstructed, "Surface has not been configured yet.", @@ -2004,28 +1991,9 @@ impl From for Configure { } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_xdg_shell { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::xdg::shell::server::xdg_wm_base::XdgWmBase: () - ] => $crate::wayland::shell::xdg::XdgShellState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::xdg::shell::server::xdg_wm_base::XdgWmBase: $crate::wayland::shell::xdg::XdgWmBaseUserData - ] => $crate::wayland::shell::xdg::XdgShellState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::xdg::shell::server::xdg_positioner::XdgPositioner: $crate::wayland::shell::xdg::XdgPositionerUserData - ] => $crate::wayland::shell::xdg::XdgShellState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::xdg::shell::server::xdg_popup::XdgPopup: $crate::wayland::shell::xdg::XdgShellSurfaceUserData - ] => $crate::wayland::shell::xdg::XdgShellState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::xdg::shell::server::xdg_surface::XdgSurface: $crate::wayland::shell::xdg::XdgSurfaceUserData - ] => $crate::wayland::shell::xdg::XdgShellState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::XdgToplevel: $crate::wayland::shell::xdg::XdgShellSurfaceUserData - ] => $crate::wayland::shell::xdg::XdgShellState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/shm/handlers.rs b/src/wayland/shm/handlers.rs index f29a3e100b02..1d3361501d2e 100644 --- a/src/wayland/shm/handlers.rs +++ b/src/wayland/shm/handlers.rs @@ -1,7 +1,4 @@ -use crate::wayland::{ - buffer::BufferHandler, - shm::{wl_bytes_per_pixel, ShmBufferUserData}, -}; +use crate::wayland::shm::{wl_bytes_per_pixel, ShmBufferUserData}; use super::{ pool::{Pool, ResizeError}, @@ -20,11 +17,7 @@ use wayland_server::{ impl GlobalDispatch for ShmState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: ShmHandler, - D: 'static, + D: ShmHandler + 'static, { fn bind( state: &mut D, @@ -34,7 +27,7 @@ where _global_data: &(), data_init: &mut DataInit<'_, D>, ) { - let shm = data_init.init(resource, ()); + let shm = data_init.init_delegated::<_, _, Self>(resource, ()); // send the formats for &f in &state.shm_state().formats { @@ -45,7 +38,7 @@ where impl Dispatch for ShmState where - D: Dispatch + Dispatch + ShmHandler + 'static, + D: ShmHandler + 'static, { fn request( _state: &mut D, @@ -79,7 +72,7 @@ where } }; - data_init.init( + data_init.init_delegated::<_, _, Self>( pool, ShmPoolUserData { inner: Arc::new(mmap_pool), @@ -94,11 +87,7 @@ where impl Dispatch for ShmState where - D: Dispatch - + Dispatch - + BufferHandler - + ShmHandler - + 'static, + D: ShmHandler + 'static, { fn request( state: &mut D, @@ -172,7 +161,7 @@ where }, }; - data_init.init(buffer, data); + data_init.init_delegated::<_, _, Self>(buffer, data); } WEnum::Unknown(unknown) => { @@ -211,7 +200,7 @@ where impl Dispatch for ShmState where - D: Dispatch + BufferHandler, + D: ShmHandler, { fn request( data: &mut D, diff --git a/src/wayland/shm/mod.rs b/src/wayland/shm/mod.rs index 723e047dfafd..8f5cd7cd673d 100644 --- a/src/wayland/shm/mod.rs +++ b/src/wayland/shm/mod.rs @@ -21,7 +21,6 @@ //! //! use smithay::wayland::buffer::BufferHandler; //! use smithay::wayland::shm::{ShmState, ShmHandler}; -//! use smithay::delegate_shm; //! use wayland_server::protocol::wl_shm::Format; //! //! # struct State { shm_state: ShmState }; @@ -49,7 +48,6 @@ //! &self.shm_state //! } //! } -//! delegate_shm!(State); //! ``` //! //! Then, when you have a [`WlBuffer`](wayland_server::protocol::wl_buffer::WlBuffer) @@ -100,11 +98,10 @@ use std::{collections::HashSet, sync::Arc}; use wayland_server::{ backend::GlobalId, protocol::{ - wl_buffer, + wl_buffer::{self, WlBuffer}, wl_shm::{self, WlShm}, - wl_shm_pool::WlShmPool, }, - Dispatch, DisplayHandle, GlobalDispatch, Resource, WEnum, + DisplayHandle, Resource, WEnum, }; mod handlers; @@ -134,12 +131,7 @@ impl ShmState { /// remove this global in the future. pub fn new(display: &DisplayHandle, formats: impl IntoIterator) -> ShmState where - D: GlobalDispatch - + Dispatch - + Dispatch - + BufferHandler - + ShmHandler - + 'static, + D: ShmHandler + 'static, { let mut formats = formats.into_iter().collect::>(); @@ -147,7 +139,7 @@ impl ShmState { formats.insert(wl_shm::Format::Argb8888); formats.insert(wl_shm::Format::Xrgb8888); - let shm = display.create_global::(1, ()); + let shm = display.create_delegated_global::(1, ()); ShmState { formats, shm } } @@ -171,10 +163,14 @@ impl ShmState { self.formats.insert(wl_shm::Format::Argb8888); self.formats.insert(wl_shm::Format::Xrgb8888); } + + fn buffer_user_data(buffer: &WlBuffer) -> Option<&ShmBufferUserData> { + buffer.delegated_data::<_, Self>() + } } /// Shm global handler -pub trait ShmHandler { +pub trait ShmHandler: BufferHandler { /// Return the Shm global state fn shm_state(&self) -> &ShmState; } @@ -234,9 +230,7 @@ pub fn with_buffer_contents(buffer: &wl_buffer::WlBuffer, f: F) -> Result< where F: FnOnce(*const u8, usize, BufferData) -> T, { - let data = buffer - .data::() - .ok_or(BufferAccessError::NotManaged)?; + let data = ShmState::buffer_user_data(buffer).ok_or(BufferAccessError::NotManaged)?; match data.pool.with_data(|ptr, len| f(ptr, len, data.data)) { Ok(t) => Ok(t), @@ -272,9 +266,7 @@ pub fn with_buffer_contents_mut(buffer: &wl_buffer::WlBuffer, f: F) -> Res where F: FnOnce(*mut u8, usize, BufferData) -> T, { - let data = buffer - .data::() - .ok_or(BufferAccessError::NotManaged)?; + let data = ShmState::buffer_user_data(buffer).ok_or(BufferAccessError::NotManaged)?; match data.pool.with_data_mut(|ptr, len| f(ptr, len, data.data)) { Ok(t) => Ok(t), @@ -469,22 +461,9 @@ pub struct ShmBufferUserData { pub(crate) data: BufferData, } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_shm { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_shm::WlShm: () - ] => $crate::wayland::shm::ShmState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_shm::WlShm: () - ] => $crate::wayland::shm::ShmState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_shm_pool::WlShmPool: $crate::wayland::shm::ShmPoolUserData - ] => $crate::wayland::shm::ShmState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_server::protocol::wl_buffer::WlBuffer: $crate::wayland::shm::ShmBufferUserData - ] => $crate::wayland::shm::ShmState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/tablet_manager/mod.rs b/src/wayland/tablet_manager/mod.rs index 494aafd021fd..89ddaf18398a 100644 --- a/src/wayland/tablet_manager/mod.rs +++ b/src/wayland/tablet_manager/mod.rs @@ -3,7 +3,6 @@ //! This module provides helpers to handle graphics tablets. //! //! ``` -//! use smithay::{delegate_seat, delegate_tablet_manager}; //! use smithay::input::{Seat, SeatState, SeatHandler, pointer::CursorImageStatus}; //! use smithay::wayland::tablet_manager::{TabletManagerState, TabletDescriptor}; //! use smithay::reexports::wayland_server::{Display, protocol::wl_surface::WlSurface}; @@ -51,8 +50,6 @@ //! // ... //! } //! } -//! delegate_seat!(State); -//! delegate_tablet_manager!(State); //! ``` //! ```ignore //! // Init the manager global @@ -80,12 +77,7 @@ //! ``` use crate::input::{Seat, SeatHandler}; -use wayland_protocols::wp::tablet::zv2::server::{ - zwp_tablet_manager_v2::{self, ZwpTabletManagerV2}, - zwp_tablet_seat_v2::ZwpTabletSeatV2, - zwp_tablet_tool_v2::ZwpTabletToolV2, - zwp_tablet_v2::ZwpTabletV2, -}; +use wayland_protocols::wp::tablet::zv2::server::zwp_tablet_manager_v2::{self, ZwpTabletManagerV2}; use wayland_server::{backend::GlobalId, Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New}; const MANAGER_VERSION: u32 = 1; @@ -122,13 +114,9 @@ impl TabletManagerState { /// Initialize a tablet manager global. pub fn new(display: &DisplayHandle) -> Self where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, - D: 'static, + D: SeatHandler + 'static, { - let global = display.create_global::(MANAGER_VERSION, ()); + let global = display.create_delegated_global::(MANAGER_VERSION, ()); Self { global } } @@ -141,10 +129,7 @@ impl TabletManagerState { impl GlobalDispatch for TabletManagerState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: 'static, + D: SeatHandler + 'static, { fn bind( _: &mut D, @@ -154,16 +139,12 @@ where _: &(), data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } impl Dispatch for TabletManagerState where - D: Dispatch, - D: Dispatch, - D: Dispatch, - D: Dispatch, D: SeatHandler + 'static, { fn request( @@ -183,7 +164,7 @@ where user_data.insert_if_missing(TabletSeatHandle::default); let handle = user_data.get::().unwrap(); - let instance = data_init.init( + let instance = data_init.init_delegated::<_, _, Self>( tablet_seat, TabletSeatUserData { handle: handle.clone(), @@ -200,25 +181,9 @@ where } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_tablet_manager { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::tablet::zv2::server::zwp_tablet_manager_v2::ZwpTabletManagerV2: () - ] => $crate::wayland::tablet_manager::TabletManagerState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::tablet::zv2::server::zwp_tablet_manager_v2::ZwpTabletManagerV2: () - ] => $crate::wayland::tablet_manager::TabletManagerState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::tablet::zv2::server::zwp_tablet_seat_v2::ZwpTabletSeatV2: $crate::wayland::tablet_manager::TabletSeatUserData - ] => $crate::wayland::tablet_manager::TabletManagerState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::tablet::zv2::server::zwp_tablet_tool_v2::ZwpTabletToolV2: $crate::wayland::tablet_manager::TabletToolUserData - ] => $crate::wayland::tablet_manager::TabletManagerState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::tablet::zv2::server::zwp_tablet_v2::ZwpTabletV2: $crate::wayland::tablet_manager::TabletUserData - ] => $crate::wayland::tablet_manager::TabletManagerState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/tablet_manager/tablet.rs b/src/wayland/tablet_manager/tablet.rs index 448117e75359..2bed852591c2 100644 --- a/src/wayland/tablet_manager/tablet.rs +++ b/src/wayland/tablet_manager/tablet.rs @@ -57,11 +57,14 @@ impl TabletHandle { seat: &ZwpTabletSeatV2, tablet: &TabletDescriptor, ) where - D: Dispatch, D: 'static, { let wl_tablet = client - .create_resource::(dh, seat.version(), TabletUserData { handle: self.clone() }) + .create_delegated_resource::( + dh, + seat.version(), + TabletUserData { handle: self.clone() }, + ) .unwrap(); seat.tablet_added(&wl_tablet); @@ -106,7 +109,6 @@ pub struct TabletUserData { impl Dispatch for TabletManagerState where - D: Dispatch, D: 'static, { fn request( diff --git a/src/wayland/tablet_manager/tablet_seat.rs b/src/wayland/tablet_manager/tablet_seat.rs index c85ca6ccca3b..7d46efa5d7ba 100644 --- a/src/wayland/tablet_manager/tablet_seat.rs +++ b/src/wayland/tablet_manager/tablet_seat.rs @@ -1,17 +1,10 @@ -use wayland_protocols::wp::tablet::zv2::server::{ - zwp_tablet_seat_v2::{self, ZwpTabletSeatV2}, - zwp_tablet_tool_v2::ZwpTabletToolV2, - zwp_tablet_v2::ZwpTabletV2, -}; +use wayland_protocols::wp::tablet::zv2::server::zwp_tablet_seat_v2::{self, ZwpTabletSeatV2}; use wayland_server::{backend::ClientId, Client, DataInit, Dispatch, DisplayHandle, Resource}; use crate::backend::input::TabletToolDescriptor; use crate::input::pointer::CursorImageStatus; -use super::{ - tablet::TabletUserData, - tablet_tool::{TabletToolHandle, TabletToolUserData}, -}; +use super::tablet_tool::TabletToolHandle; use super::{ tablet::{TabletDescriptor, TabletHandle}, TabletManagerState, @@ -61,8 +54,6 @@ pub struct TabletSeatHandle { impl TabletSeatHandle { pub(super) fn add_instance(&self, dh: &DisplayHandle, seat: &ZwpTabletSeatV2, client: &Client) where - D: Dispatch, - D: Dispatch, D: 'static, { let mut inner = self.inner.lock().unwrap(); @@ -101,7 +92,6 @@ impl TabletSeatHandle { /// Returns new [TabletHandle] if tablet was not know by this seat, if tablet was already know it returns existing handle. pub fn add_tablet(&self, dh: &DisplayHandle, tablet_desc: &TabletDescriptor) -> TabletHandle where - D: Dispatch, D: 'static, { let inner = &mut *self.inner.lock().unwrap(); @@ -154,7 +144,6 @@ impl TabletSeatHandle { /// it allows you to send tool input events to clients. pub fn add_tool(&self, dh: &DisplayHandle, tool_desc: &TabletToolDescriptor) -> TabletToolHandle where - D: Dispatch, D: 'static, { let inner = &mut *self.inner.lock().unwrap(); @@ -215,7 +204,6 @@ pub struct TabletSeatUserData { impl Dispatch for TabletManagerState where - D: Dispatch, D: 'static, { fn request( diff --git a/src/wayland/tablet_manager/tablet_tool.rs b/src/wayland/tablet_manager/tablet_tool.rs index ffd4bb720b98..a8525c98e7a8 100644 --- a/src/wayland/tablet_manager/tablet_tool.rs +++ b/src/wayland/tablet_manager/tablet_tool.rs @@ -3,6 +3,7 @@ use std::sync::{Arc, Mutex}; use crate::backend::input::{ButtonState, TabletToolCapabilities, TabletToolDescriptor, TabletToolType}; use crate::input::pointer::{CursorImageAttributes, CursorImageStatus}; +use crate::utils::user_data::UserdataGetter; use crate::utils::{Logical, Point}; use crate::wayland::seat::CURSOR_IMAGE_ROLE; use wayland_protocols::wp::tablet::zv2::server::{ @@ -223,14 +224,13 @@ impl TabletToolHandle { tool: &TabletToolDescriptor, cb: F, ) where - D: Dispatch, D: 'static, F: FnMut(&TabletToolDescriptor, CursorImageStatus) + Send + 'static, { let desc = tool.clone(); let wl_tool = client - .create_resource::( + .create_delegated_resource::( dh, seat.version(), TabletToolUserData { @@ -432,9 +432,10 @@ impl fmt::Debug for TabletToolUserData { } } +impl UserdataGetter for ZwpTabletToolV2 {} + impl Dispatch for TabletManagerState where - D: Dispatch, D: 'static, { fn request( diff --git a/src/wayland/text_input/mod.rs b/src/wayland/text_input/mod.rs index 10aa2a02e8da..d5e5155818a3 100644 --- a/src/wayland/text_input/mod.rs +++ b/src/wayland/text_input/mod.rs @@ -6,19 +6,12 @@ //! Text input focus is automatically set to the same surface that has keyboard focus. //! //! ``` -//! use smithay::{ -//! delegate_seat, delegate_text_input_manager, -//! }; //! use smithay::input::{Seat, SeatState, SeatHandler, pointer::CursorImageStatus}; //! use smithay::wayland::text_input::TextInputManagerState; //! use smithay::reexports::wayland_server::{Display, protocol::wl_surface::WlSurface}; //! //! # struct State { seat_state: SeatState }; //! -//! delegate_seat!(State); -//! // Delegate text input handling for State to TextInputManagerState. -//! delegate_text_input_manager!(State); -//! //! # let mut display = Display::::new().unwrap(); //! # let display_handle = display.handle(); //! @@ -38,13 +31,11 @@ //! //! // Add the seat state to your state and create manager global //! TextInputManagerState::new::(&display_handle); -//! //! ``` //! -use wayland_protocols::wp::text_input::zv3::server::{ - zwp_text_input_manager_v3::{self, ZwpTextInputManagerV3}, - zwp_text_input_v3::ZwpTextInputV3, +use wayland_protocols::wp::text_input::zv3::server::zwp_text_input_manager_v3::{ + self, ZwpTextInputManagerV3, }; use wayland_server::{backend::GlobalId, Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New}; @@ -83,12 +74,10 @@ impl TextInputManagerState { /// Initialize a text input manager global. pub fn new(display: &DisplayHandle) -> Self where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: 'static, + D: SeatHandler, { - let global = display.create_global::(MANAGER_VERSION, ()); + let global = + display.create_delegated_global::(MANAGER_VERSION, ()); Self { global } } @@ -101,10 +90,7 @@ impl TextInputManagerState { impl GlobalDispatch for TextInputManagerState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: 'static, + D: SeatHandler, { fn bind( _: &mut D, @@ -114,16 +100,13 @@ where _: &(), data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } impl Dispatch for TextInputManagerState where - D: Dispatch, - D: Dispatch, D: SeatHandler, - D: 'static, { fn request( _state: &mut D, @@ -143,7 +126,7 @@ where user_data.insert_if_missing(InputMethodHandle::default); let handle = user_data.get::().unwrap(); let input_method_handle = user_data.get::().unwrap(); - let instance = data_init.init( + let instance = data_init.init_delegated::<_, _, Self>( id, TextInputUserData { handle: handle.clone(), @@ -163,21 +146,9 @@ where } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_text_input_manager { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::text_input::zv3::server::zwp_text_input_manager_v3::ZwpTextInputManagerV3: () - ] => $crate::wayland::text_input::TextInputManagerState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::text_input::zv3::server::zwp_text_input_manager_v3::ZwpTextInputManagerV3: () - ] => $crate::wayland::text_input::TextInputManagerState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::text_input::zv3::server::zwp_text_input_v3::ZwpTextInputV3: - $crate::wayland::text_input::TextInputUserData - ] => $crate::wayland::text_input::TextInputManagerState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/text_input/text_input_handle.rs b/src/wayland/text_input/text_input_handle.rs index 53356d664c4c..0a8809c55fd7 100644 --- a/src/wayland/text_input/text_input_handle.rs +++ b/src/wayland/text_input/text_input_handle.rs @@ -148,9 +148,7 @@ pub struct TextInputUserData { impl Dispatch for TextInputManagerState where - D: Dispatch, D: SeatHandler, - D: 'static, { fn request( state: &mut D, diff --git a/src/wayland/viewporter/mod.rs b/src/wayland/viewporter/mod.rs index a17d759f3d45..f0d3d17d8c7f 100644 --- a/src/wayland/viewporter/mod.rs +++ b/src/wayland/viewporter/mod.rs @@ -9,7 +9,6 @@ //! //! ``` //! use smithay::wayland::viewporter::ViewporterState; -//! use smithay::delegate_viewporter; //! //! # struct State; //! # let mut display = wayland_server::Display::::new().unwrap(); @@ -19,9 +18,6 @@ //! &display.handle(), // the display //! ); //! -//! // implement Dispatch for the Viewporter types -//! delegate_viewporter!(State); -//! //! // You're now ready to go! //! ``` //! @@ -46,7 +42,10 @@ use std::cell::RefCell; use tracing::trace; -use wayland_protocols::wp::viewporter::server::{wp_viewport, wp_viewporter}; +use wayland_protocols::wp::viewporter::server::{ + wp_viewport::{self, WpViewport}, + wp_viewporter::{self, WpViewporter}, +}; use wayland_server::{ backend::GlobalId, protocol::wl_surface, Dispatch, DisplayHandle, GlobalDispatch, Resource, Weak, }; @@ -68,13 +67,10 @@ impl ViewporterState { /// the event loop in the future. pub fn new(display: &DisplayHandle) -> ViewporterState where - D: GlobalDispatch - + Dispatch - + Dispatch - + 'static, + D: 'static, { ViewporterState { - global: display.create_global::(1, ()), + global: display.create_delegated_global::(1, ()), } } @@ -84,35 +80,25 @@ impl ViewporterState { } } -impl GlobalDispatch for ViewporterState -where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, -{ +impl GlobalDispatch for ViewporterState { fn bind( _state: &mut D, _handle: &DisplayHandle, _client: &wayland_server::Client, - resource: wayland_server::New, + resource: wayland_server::New, _global_data: &(), data_init: &mut wayland_server::DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } -impl Dispatch for ViewporterState -where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, -{ +impl Dispatch for ViewporterState { fn request( _state: &mut D, _client: &wayland_server::Client, - _resource: &wp_viewporter::WpViewporter, - request: ::Request, + _resource: &WpViewporter, + request: wp_viewporter::Request, _data: &(), _dhandle: &DisplayHandle, data_init: &mut wayland_server::DataInit<'_, D>, @@ -135,9 +121,9 @@ where return; } - let viewport = data_init.init( + let viewport = data_init.init_delegated::( id, - ViewportState { + ViewportUserData { surface: surface.downgrade(), }, ); @@ -173,18 +159,13 @@ where } } -impl Dispatch for ViewportState -where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, -{ +impl Dispatch for ViewporterState { fn request( _state: &mut D, _client: &wayland_server::Client, - resource: &wp_viewport::WpViewport, - request: ::Request, - data: &ViewportState, + resource: &WpViewport, + request: wp_viewport::Request, + data: &ViewportUserData, _dhandle: &DisplayHandle, _data_init: &mut wayland_server::DataInit<'_, D>, ) { @@ -284,11 +265,11 @@ where /// State of a single viewport attached to a surface #[derive(Debug)] -pub struct ViewportState { +pub struct ViewportUserData { surface: Weak, } -struct ViewportMarker(Weak); +struct ViewportMarker(Weak); fn viewport_commit_hook(_state: &mut D, _dh: &DisplayHandle, surface: &wl_surface::WlSurface) { with_states(surface, |states| { @@ -394,19 +375,9 @@ impl Cacheable for ViewportCachedState { } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] // TODO #[macro_export] macro_rules! delegate_viewporter { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::viewporter::server::wp_viewporter::WpViewporter: () - ] => $crate::wayland::viewporter::ViewporterState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::viewporter::server::wp_viewporter::WpViewporter: () - ] => $crate::wayland::viewporter::ViewporterState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::wp::viewporter::server::wp_viewport::WpViewport: $crate::wayland::viewporter::ViewportState - ] => $crate::wayland::viewporter::ViewportState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/virtual_keyboard/mod.rs b/src/wayland/virtual_keyboard/mod.rs index a2e499fcb8e3..2a3d421aeb1a 100644 --- a/src/wayland/virtual_keyboard/mod.rs +++ b/src/wayland/virtual_keyboard/mod.rs @@ -5,19 +5,12 @@ //! an input method to pass through keys from the keyboard. //! //! ``` -//! use smithay::{ -//! delegate_seat, delegate_virtual_keyboard_manager, -//! }; //! use smithay::input::{Seat, SeatState, SeatHandler, pointer::CursorImageStatus}; //! use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState; //! use smithay::reexports::wayland_server::{Display, protocol::wl_surface::WlSurface}; //! //! # struct State { seat_state: SeatState }; //! -//! delegate_seat!(State); -//! // Delegate virtual keyboard handling for State to VirtualKeyboardManagerState. -//! delegate_virtual_keyboard_manager!(State); -//! //! # let mut display = Display::::new().unwrap(); //! # let display_handle = display.handle(); //! @@ -38,13 +31,10 @@ //! // Add the seat state to your state, create manager global and add client filter //! // to avoid untrusted clients requesting a new keyboard //! VirtualKeyboardManagerState::new::(&display_handle, |_client| true); -//! //! ``` -//! -use wayland_protocols_misc::zwp_virtual_keyboard_v1::server::{ - zwp_virtual_keyboard_manager_v1::{self, ZwpVirtualKeyboardManagerV1}, - zwp_virtual_keyboard_v1::ZwpVirtualKeyboardV1, +use wayland_protocols_misc::zwp_virtual_keyboard_v1::server::zwp_virtual_keyboard_manager_v1::{ + self, ZwpVirtualKeyboardManagerV1, }; use wayland_server::{backend::GlobalId, Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New}; @@ -58,6 +48,8 @@ mod virtual_keyboard_handle; pub use virtual_keyboard_handle::VirtualKeyboardUserData; +use super::seat::WaylandFocus; + /// State of wp misc virtual keyboard protocol #[derive(Debug)] pub struct VirtualKeyboardManagerState { @@ -70,30 +62,21 @@ pub struct VirtualKeyboardManagerGlobalData { filter: Box Fn(&'c Client) -> bool + Send + Sync>, } -fn create_global_with_filter(display: &DisplayHandle, filter: F) -> GlobalId -where - D: GlobalDispatch + 'static, - F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, -{ - let data = VirtualKeyboardManagerGlobalData { - filter: Box::new(filter), - }; - - display.create_global::(MANAGER_VERSION, data) -} - impl VirtualKeyboardManagerState { /// Initialize a virtual keyboard manager global. pub fn new(display: &DisplayHandle, filter: F) -> Self where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch>, D: SeatHandler, - D: 'static, + ::KeyboardFocus: WaylandFocus, F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, { - let global = create_global_with_filter::(display, filter); + let global = display + .create_delegated_global::( + MANAGER_VERSION, + VirtualKeyboardManagerGlobalData { + filter: Box::new(filter), + }, + ); Self { global } } @@ -107,11 +90,8 @@ impl VirtualKeyboardManagerState { impl GlobalDispatch for VirtualKeyboardManagerState where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch>, D: SeatHandler, - D: 'static, + ::KeyboardFocus: WaylandFocus, { fn bind( _: &mut D, @@ -121,7 +101,7 @@ where _: &VirtualKeyboardManagerGlobalData, data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } fn can_view(client: Client, global_data: &VirtualKeyboardManagerGlobalData) -> bool { @@ -131,10 +111,8 @@ where impl Dispatch for VirtualKeyboardManagerState where - D: Dispatch, - D: Dispatch>, D: SeatHandler, - D: 'static, + ::KeyboardFocus: WaylandFocus, { fn request( _state: &mut D, @@ -151,7 +129,7 @@ where let user_data = seat.user_data(); user_data.insert_if_missing(VirtualKeyboardHandle::default); let virtual_keyboard_handle = user_data.get::().unwrap(); - data_init.init( + data_init.init_delegated::<_, _, Self>( id, VirtualKeyboardUserData { handle: virtual_keyboard_handle.clone(), @@ -166,20 +144,9 @@ where } } +#[deprecated(note = "No longer needed, this is now NOP")] #[allow(missing_docs)] //TODO #[macro_export] macro_rules! delegate_virtual_keyboard_manager { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols_misc::zwp_virtual_keyboard_v1::server::zwp_virtual_keyboard_manager_v1::ZwpVirtualKeyboardManagerV1: $crate::wayland::virtual_keyboard::VirtualKeyboardManagerGlobalData - ] => $crate::wayland::virtual_keyboard::VirtualKeyboardManagerState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols_misc::zwp_virtual_keyboard_v1::server::zwp_virtual_keyboard_manager_v1::ZwpVirtualKeyboardManagerV1: () - ] => $crate::wayland::virtual_keyboard::VirtualKeyboardManagerState); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols_misc::zwp_virtual_keyboard_v1::server::zwp_virtual_keyboard_v1::ZwpVirtualKeyboardV1: $crate::wayland::virtual_keyboard::VirtualKeyboardUserData - ] => $crate::wayland::virtual_keyboard::VirtualKeyboardManagerState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } diff --git a/src/wayland/virtual_keyboard/virtual_keyboard_handle.rs b/src/wayland/virtual_keyboard/virtual_keyboard_handle.rs index 286583e67e64..4467475caaa7 100644 --- a/src/wayland/virtual_keyboard/virtual_keyboard_handle.rs +++ b/src/wayland/virtual_keyboard/virtual_keyboard_handle.rs @@ -81,8 +81,7 @@ impl fmt::Debug for VirtualKeyboardUserData { impl Dispatch, D> for VirtualKeyboardManagerState where - D: Dispatch>, - D: SeatHandler + 'static, + D: SeatHandler, ::KeyboardFocus: WaylandFocus, { fn request( @@ -186,7 +185,7 @@ where /// The `true` returns when keymap was properly loaded. fn update_keymap(data: &VirtualKeyboardUserData, format: u32, fd: OwnedFd, size: usize) where - D: SeatHandler + 'static, + D: SeatHandler, { // Only libxkbcommon compatible keymaps are supported. if format != KeymapFormat::XkbV1 as u32 { diff --git a/src/wayland/xdg_activation/dispatch.rs b/src/wayland/xdg_activation/dispatch.rs index 823207131da8..bd5a8b545c50 100644 --- a/src/wayland/xdg_activation/dispatch.rs +++ b/src/wayland/xdg_activation/dispatch.rs @@ -14,10 +14,7 @@ use super::{ impl Dispatch for XdgActivationState where - D: Dispatch - + Dispatch - + XdgActivationHandler - + 'static, + D: XdgActivationHandler, { fn request( state: &mut D, @@ -32,7 +29,7 @@ where xdg_activation_v1::Request::Destroy => {} xdg_activation_v1::Request::GetActivationToken { id } => { - data_init.init( + data_init.init_delegated::<_, _, Self>( id, ActivationTokenData { constructed: AtomicBool::new(false), @@ -63,11 +60,7 @@ where impl GlobalDispatch for XdgActivationState where - D: GlobalDispatch - + Dispatch - + Dispatch - + XdgActivationHandler - + 'static, + D: XdgActivationHandler, { fn bind( _: &mut D, @@ -77,13 +70,13 @@ where _: &(), data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } impl Dispatch for XdgActivationState where - D: Dispatch + XdgActivationHandler, + D: XdgActivationHandler, { fn request( state: &mut D, diff --git a/src/wayland/xdg_activation/mod.rs b/src/wayland/xdg_activation/mod.rs index a4f256fb9637..1e045f576ed9 100644 --- a/src/wayland/xdg_activation/mod.rs +++ b/src/wayland/xdg_activation/mod.rs @@ -7,7 +7,6 @@ //! # //! use wayland_server::{protocol::wl_surface::WlSurface, DisplayHandle}; //! use smithay::{ -//! delegate_xdg_activation, //! wayland::xdg_activation::{XdgActivationHandler, XdgActivationState, XdgActivationToken, XdgActivationTokenData} //! }; //! @@ -32,9 +31,6 @@ //! } //! } //! -//! // Delegate xdg activation handling for State to XdgActivationState. -//! delegate_xdg_activation!(State); -//! //! # let mut display = wayland_server::Display::::new().unwrap(); //! # let display_handle = display.handle(); //! let state = State { @@ -55,7 +51,7 @@ use wayland_protocols::xdg::activation::v1::server::xdg_activation_v1; use wayland_server::{ backend::{ClientId, GlobalId}, protocol::{wl_seat::WlSeat, wl_surface::WlSurface}, - Dispatch, DisplayHandle, GlobalDispatch, + DisplayHandle, }; use rand::distributions::{Alphanumeric, DistString}; @@ -163,12 +159,9 @@ impl XdgActivationState { /// In order to use this abstraction, your `D` type needs to implement [`XdgActivationHandler`]. pub fn new(display: &DisplayHandle) -> XdgActivationState where - D: GlobalDispatch - + Dispatch - + XdgActivationHandler - + 'static, + D: XdgActivationHandler, { - let global = display.create_global::(1, ()); + let global = display.create_delegated_global::(1, ()); XdgActivationState { global, @@ -219,7 +212,7 @@ impl XdgActivationState { } /// A trait implemented to be notified of activation requests using the xdg activation protocol. -pub trait XdgActivationHandler { +pub trait XdgActivationHandler: 'static { /// Returns the activation state. fn activation_state(&mut self) -> &mut XdgActivationState; @@ -260,27 +253,10 @@ pub struct ActivationTokenData { /// Macro to delegate implementation of the xdg activation to [`XdgActivationState`]. /// /// You must also implement [`XdgActivationHandler`] to use this. +#[deprecated(note = "No longer needed, this is now NOP")] #[macro_export] macro_rules! delegate_xdg_activation { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - type __XdgActivationV1 = - $crate::reexports::wayland_protocols::xdg::activation::v1::server::xdg_activation_v1::XdgActivationV1; - type __XdgActivationTokenV1 = - $crate::reexports::wayland_protocols::xdg::activation::v1::server::xdg_activation_token_v1::XdgActivationTokenV1; - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - __XdgActivationV1: () - ] => $crate::wayland::xdg_activation::XdgActivationState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - __XdgActivationTokenV1: $crate::wayland::xdg_activation::ActivationTokenData - ] => $crate::wayland::xdg_activation::XdgActivationState); - - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __XdgActivationV1: () - ] => $crate::wayland::xdg_activation::XdgActivationState - ); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; } #[derive(Debug)] diff --git a/src/wayland/xdg_foreign/handlers.rs b/src/wayland/xdg_foreign/handlers.rs index 61b6bfe0bb3c..f1fec145e67f 100644 --- a/src/wayland/xdg_foreign/handlers.rs +++ b/src/wayland/xdg_foreign/handlers.rs @@ -19,10 +19,7 @@ use super::{ // Export // -impl GlobalDispatch for XdgForeignState -where - D: Dispatch, -{ +impl GlobalDispatch for XdgForeignState { fn bind( _state: &mut D, _handle: &DisplayHandle, @@ -31,15 +28,11 @@ where _global_data: &(), data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } -impl Dispatch for XdgForeignState -where - D: Dispatch, - D: XdgForeignHandler, -{ +impl Dispatch for XdgForeignState { fn request( state: &mut D, _client: &Client, @@ -52,7 +45,7 @@ where match request { zxdg_exporter_v2::Request::ExportToplevel { id, surface } => { let handle = XdgForeignHandle::new(); - let exported = data_init.init( + let exported = data_init.init_delegated::<_, _, Self>( id, XdgExportedUserData { handle: handle.clone(), @@ -100,10 +93,7 @@ impl Dispatch for // Import // -impl GlobalDispatch for XdgForeignState -where - D: Dispatch, -{ +impl GlobalDispatch for XdgForeignState { fn bind( _state: &mut D, _handle: &DisplayHandle, @@ -112,14 +102,11 @@ where _global_data: &(), data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } } -impl Dispatch for XdgForeignState -where - D: Dispatch, -{ +impl Dispatch for XdgForeignState { fn request( state: &mut D, _client: &Client, @@ -137,7 +124,7 @@ where .iter_mut() .find(|(key, _)| key.as_str() == handle.as_str()); - let imported = data_init.init( + let imported = data_init.init_delegated::<_, _, Self>( id, XdgImportedUserData { handle: XdgForeignHandle(handle), diff --git a/src/wayland/xdg_foreign/mod.rs b/src/wayland/xdg_foreign/mod.rs index 78a978b459b7..fb20a31576d2 100644 --- a/src/wayland/xdg_foreign/mod.rs +++ b/src/wayland/xdg_foreign/mod.rs @@ -38,7 +38,7 @@ use rand::distributions::{Alphanumeric, DistString}; use wayland_protocols::xdg::foreign::zv2::server::{ zxdg_exporter_v2::ZxdgExporterV2, zxdg_imported_v2::ZxdgImportedV2, zxdg_importer_v2::ZxdgImporterV2, }; -use wayland_server::{backend::GlobalId, protocol::wl_surface::WlSurface, DisplayHandle, GlobalDispatch}; +use wayland_server::{backend::GlobalId, protocol::wl_surface::WlSurface, DisplayHandle}; mod handlers; @@ -102,13 +102,9 @@ impl XdgForeignState { /// Creates a new xdg activation global. /// /// In order to use this abstraction, your `D` type needs to implement [`XdgForeignHandler`]. - pub fn new(display: &DisplayHandle) -> Self - where - D: GlobalDispatch, - D: GlobalDispatch, - { - let exporter = display.create_global::(1, ()); - let importer = display.create_global::(1, ()); + pub fn new(display: &DisplayHandle) -> Self { + let exporter = display.create_delegated_global::(1, ()); + let importer = display.create_delegated_global::(1, ()); Self { exported: HashMap::new(), @@ -127,54 +123,3 @@ impl XdgForeignState { self.importer.clone() } } - -/// Macro to delegate implementation of the xdg foreign to [`XdgForeignState`]. -/// -/// You must also implement [`XdgForeignHandler`] to use this. -#[macro_export] -macro_rules! delegate_xdg_foreign { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - type __ZxdgExporterV2 = - $crate::reexports::wayland_protocols::xdg::foreign::zv2::server::zxdg_exporter_v2::ZxdgExporterV2; - type __ZxdgImporterV2 = - $crate::reexports::wayland_protocols::xdg::foreign::zv2::server::zxdg_importer_v2::ZxdgImporterV2; - - type __ZxdgExportedV2 = - $crate::reexports::wayland_protocols::xdg::foreign::zv2::server::zxdg_exported_v2::ZxdgExportedV2; - type __ZxdgImportedV2 = - $crate::reexports::wayland_protocols::xdg::foreign::zv2::server::zxdg_imported_v2::ZxdgImportedV2; - - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __ZxdgExporterV2: () - ] => $crate::wayland::xdg_foreign::XdgForeignState - ); - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __ZxdgImporterV2: () - ] => $crate::wayland::xdg_foreign::XdgForeignState - ); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __ZxdgExporterV2: () - ] => $crate::wayland::xdg_foreign::XdgForeignState - ); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __ZxdgImporterV2: () - ] => $crate::wayland::xdg_foreign::XdgForeignState - ); - - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __ZxdgExportedV2: $crate::wayland::xdg_foreign::XdgExportedUserData - ] => $crate::wayland::xdg_foreign::XdgForeignState - ); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __ZxdgImportedV2: $crate::wayland::xdg_foreign::XdgImportedUserData - ] => $crate::wayland::xdg_foreign::XdgForeignState - ); - }; -} diff --git a/src/wayland/xwayland_keyboard_grab.rs b/src/wayland/xwayland_keyboard_grab.rs index 646dfdccdc8e..fc8d67be2a59 100644 --- a/src/wayland/xwayland_keyboard_grab.rs +++ b/src/wayland/xwayland_keyboard_grab.rs @@ -5,7 +5,6 @@ //! XWaylandKeyboardGrabHandler, //! XWaylandKeyboardGrabState //! }; -//! use smithay::delegate_xwayland_keyboard_grab; //! //! # struct State; //! # let mut display = wayland_server::Display::::new().unwrap(); @@ -32,9 +31,6 @@ //! todo!() //! } //! } -//! -//! // implement Dispatch for the keyboard grab types -//! delegate_xwayland_keyboard_grab!(State); //! ``` use wayland_protocols::xwayland::keyboard_grab::zv1::server::{ @@ -135,12 +131,10 @@ impl XWaylandKeyboardGrabState { /// Register new [ZwpXwaylandKeyboardGrabManagerV1] global pub fn new(display: &DisplayHandle) -> Self where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: 'static, + D: XWaylandKeyboardGrabHandler, { - let global = display.create_global::(MANAGER_VERSION, ()); + let global = display + .create_delegated_global::(MANAGER_VERSION, ()); Self { global } } @@ -153,9 +147,7 @@ impl XWaylandKeyboardGrabState { impl GlobalDispatch for XWaylandKeyboardGrabState where - D: GlobalDispatch - + Dispatch - + 'static, + D: XWaylandKeyboardGrabHandler, { fn bind( _state: &mut D, @@ -165,7 +157,7 @@ where _global_data: &(), data_init: &mut DataInit<'_, D>, ) { - data_init.init(resource, ()); + data_init.init_delegated::<_, _, Self>(resource, ()); } fn can_view(client: Client, _global_data: &()) -> bool { @@ -175,8 +167,6 @@ where impl Dispatch for XWaylandKeyboardGrabState where - D: Dispatch + 'static, - D: Dispatch + 'static, D: XWaylandKeyboardGrabHandler, { fn request( @@ -190,7 +180,7 @@ where ) { match request { zwp_xwayland_keyboard_grab_manager_v1::Request::GrabKeyboard { id, surface, seat } => { - let grab = data_init.init(id, ()); + let grab = data_init.init_delegated::<_, _, Self>(id, ()); if let Some(focus) = state.keyboard_focus_for_xsurface(&surface) { let grab = XWaylandKeyboardGrab { grab, @@ -208,7 +198,7 @@ where impl Dispatch for XWaylandKeyboardGrabState where - D: Dispatch + 'static, + D: XWaylandKeyboardGrabHandler, { fn request( _state: &mut D, @@ -227,17 +217,8 @@ where } /// Macro to delegate implementation of the xwayland keyboard grab protocol +#[deprecated(note = "No longer needed, this is now NOP")] #[macro_export] macro_rules! delegate_xwayland_keyboard_grab { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::xwayland::keyboard_grab::zv1::server::zwp_xwayland_keyboard_grab_manager_v1::ZwpXwaylandKeyboardGrabManagerV1: () - ] => $crate::wayland::xwayland_keyboard_grab::XWaylandKeyboardGrabState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::xwayland::keyboard_grab::zv1::server::zwp_xwayland_keyboard_grab_manager_v1::ZwpXwaylandKeyboardGrabManagerV1: () - ] => $crate::wayland::xwayland_keyboard_grab::XWaylandKeyboardGrabState); - $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ - $crate::reexports::wayland_protocols::xwayland::keyboard_grab::zv1::server::zwp_xwayland_keyboard_grab_v1::ZwpXwaylandKeyboardGrabV1: () - ] => $crate::wayland::xwayland_keyboard_grab::XWaylandKeyboardGrabState); - }; + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {}; }