diff --git a/src/wayland/shell/legacy/mod.rs b/src/wayland/shell/legacy/mod.rs index 11128ec..ccee438 100644 --- a/src/wayland/shell/legacy/mod.rs +++ b/src/wayland/shell/legacy/mod.rs @@ -36,17 +36,10 @@ //! use smithay::wayland::compositor::CompositorToken; //! use smithay::wayland::shell::legacy::{wl_shell_init, ShellSurfaceRole, ShellRequest}; //! # use wayland_server::protocol::{wl_seat, wl_output}; -//! # #[derive(Default)] struct MySurfaceData; -//! -//! // define the metadata you want associated with the shell surfaces -//! #[derive(Default)] -//! pub struct MyShellSurfaceData { -//! /* ... */ -//! } //! //! // define the roles type. You need to integrate the XdgSurface role: //! define_roles!(MyRoles => -//! [ShellSurface, ShellSurfaceRole] +//! [ShellSurface, ShellSurfaceRole] //! ); //! //! # fn main() { @@ -62,7 +55,7 @@ //! // token from the compositor implementation //! compositor_token, //! // your implementation -//! |event: ShellRequest<_, MyShellSurfaceData>| { /* ... */ }, +//! |event: ShellRequest<_>| { /* ... */ }, //! None // put a logger if you want //! ); //! @@ -86,28 +79,24 @@ use wayland_server::{ mod wl_handlers; /// Metadata associated with the `wl_surface` role -pub struct ShellSurfaceRole { +pub struct ShellSurfaceRole { /// Title of the surface pub title: String, /// Class of the surface pub class: String, pending_ping: u32, - /// Some user data you may want to associate with the surface - pub user_data: D, } /// A handle to a shell surface -pub struct ShellSurface { +pub struct ShellSurface { wl_surface: wl_surface::WlSurface, shell_surface: wl_shell_surface::WlShellSurface, token: CompositorToken, - _d: ::std::marker::PhantomData, } -impl ShellSurface +impl ShellSurface where - R: Role> + 'static, - D: 'static, + R: Role + 'static, { /// Is the shell surface referred by this handle still alive? pub fn alive(&self) -> bool { @@ -168,16 +157,6 @@ where pub fn send_popup_done(&self) { self.shell_surface.popup_done() } - - /// Access the user data you associated to this surface - pub fn with_user_data(&self, f: F) -> Result - where - F: FnOnce(&mut D) -> T, - { - self.token - .with_role_data(&self.wl_surface, |data| f(&mut data.user_data)) - .map_err(|_| ()) - } } /// Possible kinds of shell surface of the `wl_shell` protocol @@ -234,13 +213,13 @@ pub enum ShellSurfaceKind { } /// A request triggered by a `wl_shell_surface` -pub enum ShellRequest { +pub enum ShellRequest { /// A new shell surface was created /// /// by default it has no kind and this should not be displayed NewShellSurface { /// The created surface - surface: ShellSurface, + surface: ShellSurface, }, /// A pong event /// @@ -248,14 +227,14 @@ pub enum ShellRequest { /// event, smithay has already checked that the responded serial was valid. Pong { /// The surface that sent the pong - surface: ShellSurface, + surface: ShellSurface, }, /// Start of an interactive move /// /// The surface requests that an interactive move is started on it Move { /// The surface requesting the move - surface: ShellSurface, + surface: ShellSurface, /// Serial of the implicit grab that initiated the move serial: u32, /// Seat associated with the move @@ -266,7 +245,7 @@ pub enum ShellRequest { /// The surface requests that an interactive resize is started on it Resize { /// The surface requesting the resize - surface: ShellSurface, + surface: ShellSurface, /// Serial of the implicit grab that initiated the resize serial: u32, /// Seat associated with the resize @@ -277,7 +256,7 @@ pub enum ShellRequest { /// The surface changed its kind SetKind { /// The surface - surface: ShellSurface, + surface: ShellSurface, /// Its new kind kind: ShellSurfaceKind, }, @@ -287,14 +266,13 @@ pub enum ShellRequest { /// /// This state allows you to retrieve a list of surfaces /// currently known to the shell global. -pub struct ShellState { - known_surfaces: Vec>, +pub struct ShellState { + known_surfaces: Vec>, } -impl ShellState +impl ShellState where - R: Role> + 'static, - D: 'static, + R: Role + 'static, { /// Cleans the internal surface storage by removing all dead surfaces pub(crate) fn cleanup_surfaces(&mut self) { @@ -302,23 +280,22 @@ where } /// Access all the shell surfaces known by this handler - pub fn surfaces(&self) -> &[ShellSurface] { + pub fn surfaces(&self) -> &[ShellSurface] { &self.known_surfaces[..] } } /// Create a new `wl_shell` global -pub fn wl_shell_init( +pub fn wl_shell_init( display: &mut Display, ctoken: CompositorToken, implementation: Impl, logger: L, -) -> (Arc>>, Global) +) -> (Arc>>, Global) where - D: Default + 'static, - R: Role> + 'static, + R: Role + 'static, L: Into>, - Impl: FnMut(ShellRequest) + 'static, + Impl: FnMut(ShellRequest) + 'static, { let _log = crate::slog_or_stdlog(logger); diff --git a/src/wayland/shell/legacy/wl_handlers.rs b/src/wayland/shell/legacy/wl_handlers.rs index d60752f..0392ffe 100644 --- a/src/wayland/shell/legacy/wl_handlers.rs +++ b/src/wayland/shell/legacy/wl_handlers.rs @@ -13,15 +13,14 @@ use crate::wayland::compositor::{roles::Role, CompositorToken}; use super::{ShellRequest, ShellState, ShellSurface, ShellSurfaceKind, ShellSurfaceRole}; -pub(crate) fn implement_shell( +pub(crate) fn implement_shell( shell: NewResource, ctoken: CompositorToken, implementation: Rc>, - state: Arc>>, + state: Arc>>, ) where - D: Default + 'static, - R: Role> + 'static, - Impl: FnMut(ShellRequest) + 'static, + R: Role + 'static, + Impl: FnMut(ShellRequest) + 'static, { shell.implement_closure( move |req, shell| { @@ -33,7 +32,6 @@ pub(crate) fn implement_shell( title: "".into(), class: "".into(), pending_ping: 0, - user_data: Default::default(), }; if ctoken.give_role_with(&surface, role_data).is_err() { shell @@ -58,49 +56,46 @@ pub(crate) fn implement_shell( ); } -fn make_handle( +fn make_handle( shell_surface: &wl_shell_surface::WlShellSurface, token: CompositorToken, -) -> ShellSurface +) -> ShellSurface where - R: Role> + 'static, - SD: 'static, + R: Role + 'static, { let data = shell_surface .as_ref() - .user_data::>() + .user_data::>() .unwrap(); ShellSurface { wl_surface: data.surface.clone(), shell_surface: shell_surface.clone(), token, - _d: ::std::marker::PhantomData, } } -pub(crate) struct ShellSurfaceUserData { +pub(crate) struct ShellSurfaceUserData { surface: wl_surface::WlSurface, - state: Arc>>, + state: Arc>>, } -fn implement_shell_surface( +fn implement_shell_surface( shell_surface: NewResource, surface: wl_surface::WlSurface, implementation: Rc>, ctoken: CompositorToken, - state: Arc>>, + state: Arc>>, ) -> wl_shell_surface::WlShellSurface where - SD: 'static, - R: Role> + 'static, - Impl: FnMut(ShellRequest) + 'static, + R: Role + 'static, + Impl: FnMut(ShellRequest) + 'static, { use self::wl_shell_surface::Request; shell_surface.implement_closure( move |req, shell_surface| { let data = shell_surface .as_ref() - .user_data::>() + .user_data::>() .unwrap(); let mut user_impl = implementation.borrow_mut(); match req { @@ -193,7 +188,7 @@ where Some(|shell_surface: wl_shell_surface::WlShellSurface| { let data = shell_surface .as_ref() - .user_data::>() + .user_data::>() .unwrap(); data.state.lock().unwrap().cleanup_surfaces(); }),