diff --git a/anvil/src/shell.rs b/anvil/src/shell.rs index 455230c..46ccb85 100644 --- a/anvil/src/shell.rs +++ b/anvil/src/shell.rs @@ -31,12 +31,12 @@ use crate::window_map::{Kind as SurfaceKind, WindowMap}; define_roles!(Roles => [ XdgSurface, XdgSurfaceRole ] - [ ShellSurface, ShellSurfaceRole<()>] + [ ShellSurface, ShellSurfaceRole] [ DnDIcon, DnDIconRole ] [ CursorImage, CursorImageRole ] ); -pub type MyWindowMap = WindowMap Option<(i32, i32)>>; +pub type MyWindowMap = WindowMap Option<(i32, i32)>>; pub type MyCompositorToken = CompositorToken; @@ -45,8 +45,8 @@ pub fn init_shell( log: ::slog::Logger, ) -> ( CompositorToken, - Arc>>, - Arc>>, + Arc>>, + Arc>>, Rc>, ) { // Create the compositor @@ -62,7 +62,7 @@ pub fn init_shell( ); // Init a window map, to track the location of our windows - let window_map = Rc::new(RefCell::new(WindowMap::<_, (), (), _>::new( + let window_map = Rc::new(RefCell::new(WindowMap::<_, _>::new( compositor_token, get_size as _, ))); @@ -104,7 +104,7 @@ pub fn init_shell( let (wl_shell_state, _) = wl_shell_init( display, compositor_token, - move |req: ShellRequest<_, ()>| { + move |req: ShellRequest<_>| { if let ShellRequest::SetKind { surface, kind: ShellSurfaceKind::Toplevel, diff --git a/anvil/src/window_map.rs b/anvil/src/window_map.rs index 2645b44..dc4b8fe 100644 --- a/anvil/src/window_map.rs +++ b/anvil/src/window_map.rs @@ -12,16 +12,14 @@ use smithay::{ }, }; -pub enum Kind { - Xdg(ToplevelSurface), - Wl(ShellSurface), +pub enum Kind { + Xdg(ToplevelSurface), + Wl(ShellSurface), } -impl Kind +impl Kind where - R: Role + Role + Role> + 'static, - SD: 'static, - D: 'static, + R: Role + Role + Role + 'static, { pub fn alive(&self) -> bool { match *self { @@ -37,17 +35,15 @@ where } } -struct Window { +struct Window { location: (i32, i32), surface: Rectangle, - toplevel: Kind, + toplevel: Kind, } -impl Window +impl Window where - R: Role + Role + Role> + 'static, - SD: 'static, - D: 'static, + R: Role + Role + Role + 'static, { // Find the topmost surface under this point if any and the location of this surface fn matching( @@ -146,20 +142,18 @@ where } } -pub struct WindowMap { +pub struct WindowMap { ctoken: CompositorToken, - windows: Vec>, + windows: Vec>, get_size: F, } -impl WindowMap +impl WindowMap where F: Fn(&SurfaceAttributes) -> Option<(i32, i32)>, - R: Role + Role + Role> + 'static, - SD: 'static, - D: 'static, + R: Role + Role + Role + 'static, { - pub fn new(ctoken: CompositorToken, get_size: F) -> WindowMap { + pub fn new(ctoken: CompositorToken, get_size: F) -> WindowMap { WindowMap { ctoken, windows: Vec::new(), @@ -167,7 +161,7 @@ where } } - pub fn insert(&mut self, toplevel: Kind, location: (i32, i32)) { + pub fn insert(&mut self, toplevel: Kind, location: (i32, i32)) { let mut window = Window { location, surface: Rectangle { @@ -213,7 +207,7 @@ where pub fn with_windows_from_bottom_to_top(&self, mut f: Func) where - Func: FnMut(&Kind, (i32, i32)), + Func: FnMut(&Kind, (i32, i32)), { for w in self.windows.iter().rev() { f(&w.toplevel, w.location) diff --git a/src/wayland/shell/xdg/mod.rs b/src/wayland/shell/xdg/mod.rs index bf33910..219114f 100644 --- a/src/wayland/shell/xdg/mod.rs +++ b/src/wayland/shell/xdg/mod.rs @@ -60,7 +60,7 @@ //! // token from the compositor implementation //! compositor_token, //! // your implementation -//! |event: XdgRequest<_, MyShellData>| { /* ... */ }, +//! |event: XdgRequest<_>| { /* ... */ }, //! None // put a logger if you want //! ); //! @@ -96,6 +96,7 @@ use std::{ rc::Rc, sync::{Arc, Mutex}, }; +use wayland_commons::utils::UserDataMap; use wayland_protocols::{ unstable::xdg_shell::v6::server::{zxdg_popup_v6, zxdg_shell_v6, zxdg_surface_v6, zxdg_toplevel_v6}, xdg_shell::server::{xdg_popup, xdg_positioner, xdg_surface, xdg_toplevel, xdg_wm_base}, @@ -258,14 +259,14 @@ impl Default for XdgSurfacePendingState { } } -pub(crate) struct ShellData { +pub(crate) struct ShellData { log: ::slog::Logger, compositor_token: CompositorToken, - user_impl: Rc)>>, - shell_state: Arc>>, + user_impl: Rc)>>, + shell_state: Arc>>, } -impl Clone for ShellData { +impl Clone for ShellData { fn clone(&self) -> Self { ShellData { log: self.log.clone(), @@ -277,21 +278,20 @@ impl Clone for ShellData { } /// Create a new `xdg_shell` globals -pub fn xdg_shell_init( +pub fn xdg_shell_init( display: &mut Display, ctoken: CompositorToken, implementation: Impl, logger: L, ) -> ( - Arc>>, + Arc>>, Global, Global, ) where R: Role + 'static, - SD: Default + 'static, L: Into>, - Impl: FnMut(XdgRequest) + 'static, + Impl: FnMut(XdgRequest) + 'static, { let log = crate::slog_or_stdlog(logger); let shell_state = Arc::new(Mutex::new(ShellState { @@ -323,23 +323,22 @@ where /// /// This state allows you to retrieve a list of surfaces /// currently known to the shell global. -pub struct ShellState { - known_toplevels: Vec>, - known_popups: Vec>, +pub struct ShellState { + known_toplevels: Vec>, + known_popups: Vec>, } -impl ShellState +impl ShellState where R: Role + 'static, - SD: 'static, { /// Access all the shell surfaces known by this handler - pub fn toplevel_surfaces(&self) -> &[ToplevelSurface] { + pub fn toplevel_surfaces(&self) -> &[ToplevelSurface] { &self.known_toplevels[..] } /// Access all the popup surfaces known by this handler - pub fn popup_surfaces(&self) -> &[PopupSurface] { + pub fn popup_surfaces(&self) -> &[PopupSurface] { &self.known_popups[..] } } @@ -353,15 +352,15 @@ enum ShellClientKind { ZxdgV6(zxdg_shell_v6::ZxdgShellV6), } -pub(crate) struct ShellClientData { +pub(crate) struct ShellClientData { pending_ping: u32, - data: SD, + data: UserDataMap, } -fn make_shell_client_data() -> ShellClientData { +fn make_shell_client_data() -> ShellClientData { ShellClientData { pending_ping: 0, - data: Default::default(), + data: UserDataMap::new(), } } @@ -375,16 +374,14 @@ fn make_shell_client_data() -> ShellClientData { /// /// You can use this handle to access a storage for any /// client-specific data you wish to associate with it. -pub struct ShellClient { +pub struct ShellClient { kind: ShellClientKind, _token: CompositorToken, - _data: ::std::marker::PhantomData<*mut SD>, } -impl ShellClient +impl ShellClient where R: Role + 'static, - SD: 'static, { /// Is the shell client represented by this handle still connected? pub fn alive(&self) -> bool { @@ -423,7 +420,7 @@ where ShellClientKind::Xdg(ref shell) => { let user_data = shell .as_ref() - .user_data::>() + .user_data::>() .unwrap(); let mut guard = user_data.client_data.lock().unwrap(); if guard.pending_ping == 0 { @@ -435,7 +432,7 @@ where ShellClientKind::ZxdgV6(ref shell) => { let user_data = shell .as_ref() - .user_data::>() + .user_data::>() .unwrap(); let mut guard = user_data.client_data.lock().unwrap(); if guard.pending_ping == 0 { @@ -451,7 +448,7 @@ where /// Access the user data associated with this shell client pub fn with_data(&self, f: F) -> Result where - F: FnOnce(&mut SD) -> T, + F: FnOnce(&mut UserDataMap) -> T, { if !self.alive() { return Err(()); @@ -460,7 +457,7 @@ where ShellClientKind::Xdg(ref shell) => { let data = shell .as_ref() - .user_data::>() + .user_data::>() .unwrap(); let mut guard = data.client_data.lock().unwrap(); Ok(f(&mut guard.data)) @@ -468,7 +465,7 @@ where ShellClientKind::ZxdgV6(ref shell) => { let data = shell .as_ref() - .user_data::>() + .user_data::>() .unwrap(); let mut guard = data.client_data.lock().unwrap(); Ok(f(&mut guard.data)) @@ -483,17 +480,15 @@ pub(crate) enum ToplevelKind { } /// A handle to a toplevel surface -pub struct ToplevelSurface { +pub struct ToplevelSurface { wl_surface: wl_surface::WlSurface, shell_surface: ToplevelKind, token: CompositorToken, - _shell_data: ::std::marker::PhantomData, } -impl ToplevelSurface +impl ToplevelSurface where R: Role + 'static, - SD: 'static, { /// Is the toplevel surface referred by this handle still alive? pub fn alive(&self) -> bool { @@ -512,7 +507,7 @@ where /// Retrieve the shell client owning this toplevel surface /// /// Returns `None` if the surface does actually no longer exist. - pub fn client(&self) -> Option> { + pub fn client(&self) -> Option> { if !self.alive() { return None; } @@ -521,14 +516,14 @@ where ToplevelKind::Xdg(ref s) => { let data = s .as_ref() - .user_data::>() + .user_data::>() .unwrap(); ShellClientKind::Xdg(data.wm_base.clone()) } ToplevelKind::ZxdgV6(ref s) => { let data = s .as_ref() - .user_data::>() + .user_data::>() .unwrap(); ShellClientKind::ZxdgV6(data.shell.clone()) } @@ -537,7 +532,6 @@ where Some(ShellClient { kind: shell, _token: self.token, - _data: ::std::marker::PhantomData, }) } @@ -549,8 +543,8 @@ where return; } match self.shell_surface { - ToplevelKind::Xdg(ref s) => self::xdg_handlers::send_toplevel_configure::(s, cfg), - ToplevelKind::ZxdgV6(ref s) => self::zxdgv6_handlers::send_toplevel_configure::(s, cfg), + ToplevelKind::Xdg(ref s) => self::xdg_handlers::send_toplevel_configure::(s, cfg), + ToplevelKind::ZxdgV6(ref s) => self::zxdgv6_handlers::send_toplevel_configure::(s, cfg), } } @@ -575,7 +569,7 @@ where ToplevelKind::Xdg(ref s) => { let data = s .as_ref() - .user_data::>() + .user_data::>() .unwrap(); data.xdg_surface.as_ref().post_error( xdg_surface::Error::NotConstructed as u32, @@ -585,7 +579,7 @@ where ToplevelKind::ZxdgV6(ref s) => { let data = s .as_ref() - .user_data::>() + .user_data::>() .unwrap(); data.xdg_surface.as_ref().post_error( zxdg_surface_v6::Error::NotConstructed as u32, @@ -642,17 +636,15 @@ pub(crate) enum PopupKind { /// /// This is an unified abstraction over the popup surfaces /// of both `wl_shell` and `xdg_shell`. -pub struct PopupSurface { +pub struct PopupSurface { wl_surface: wl_surface::WlSurface, shell_surface: PopupKind, token: CompositorToken, - _shell_data: ::std::marker::PhantomData, } -impl PopupSurface +impl PopupSurface where R: Role + 'static, - SD: 'static, { /// Is the popup surface referred by this handle still alive? pub fn alive(&self) -> bool { @@ -671,7 +663,7 @@ where /// Retrieve the shell client owning this popup surface /// /// Returns `None` if the surface does actually no longer exist. - pub fn client(&self) -> Option> { + pub fn client(&self) -> Option> { if !self.alive() { return None; } @@ -680,14 +672,14 @@ where PopupKind::Xdg(ref p) => { let data = p .as_ref() - .user_data::>() + .user_data::>() .unwrap(); ShellClientKind::Xdg(data.wm_base.clone()) } PopupKind::ZxdgV6(ref p) => { let data = p .as_ref() - .user_data::>() + .user_data::>() .unwrap(); ShellClientKind::ZxdgV6(data.shell.clone()) } @@ -696,7 +688,6 @@ where Some(ShellClient { kind: shell, _token: self.token, - _data: ::std::marker::PhantomData, }) } @@ -709,10 +700,10 @@ where } match self.shell_surface { PopupKind::Xdg(ref p) => { - self::xdg_handlers::send_popup_configure::(p, cfg); + self::xdg_handlers::send_popup_configure::(p, cfg); } PopupKind::ZxdgV6(ref p) => { - self::zxdgv6_handlers::send_popup_configure::(p, cfg); + self::zxdgv6_handlers::send_popup_configure::(p, cfg); } } } @@ -738,7 +729,7 @@ where PopupKind::Xdg(ref s) => { let data = s .as_ref() - .user_data::>() + .user_data::>() .unwrap(); data.xdg_surface.as_ref().post_error( xdg_surface::Error::NotConstructed as u32, @@ -748,7 +739,7 @@ where PopupKind::ZxdgV6(ref s) => { let data = s .as_ref() - .user_data::>() + .user_data::>() .unwrap(); data.xdg_surface.as_ref().post_error( zxdg_surface_v6::Error::NotConstructed as u32, @@ -837,11 +828,11 @@ pub struct PopupConfigure { /// for you directly. /// /// Depending on what you want to do, you might ignore some of them -pub enum XdgRequest { +pub enum XdgRequest { /// A new shell client was instantiated NewClient { /// the client - client: ShellClient, + client: ShellClient, }, /// The pong for a pending ping of this shell client was received /// @@ -849,7 +840,7 @@ pub enum XdgRequest { /// from the pending ping. ClientPong { /// the client - client: ShellClient, + client: ShellClient, }, /// A new toplevel surface was created /// @@ -857,7 +848,7 @@ pub enum XdgRequest { /// client as to how its window should be NewToplevel { /// the surface - surface: ToplevelSurface, + surface: ToplevelSurface, }, /// A new popup surface was created /// @@ -865,12 +856,12 @@ pub enum XdgRequest { /// client as to how its popup should be NewPopup { /// the surface - surface: PopupSurface, + surface: PopupSurface, }, /// The client requested the start of an interactive move for this surface Move { /// the surface - surface: ToplevelSurface, + surface: ToplevelSurface, /// the seat associated to this move seat: wl_seat::WlSeat, /// the grab serial @@ -879,7 +870,7 @@ pub enum XdgRequest { /// The client requested the start of an interactive resize for this surface Resize { /// The surface - surface: ToplevelSurface, + surface: ToplevelSurface, /// The seat associated with this resize seat: wl_seat::WlSeat, /// The grab serial @@ -893,7 +884,7 @@ pub enum XdgRequest { /// the grab area. Grab { /// The surface - surface: PopupSurface, + surface: PopupSurface, /// The seat to grab seat: wl_seat::WlSeat, /// The grab serial @@ -902,29 +893,29 @@ pub enum XdgRequest { /// A toplevel surface requested to be maximized Maximize { /// The surface - surface: ToplevelSurface, + surface: ToplevelSurface, }, /// A toplevel surface requested to stop being maximized UnMaximize { /// The surface - surface: ToplevelSurface, + surface: ToplevelSurface, }, /// A toplevel surface requested to be set fullscreen Fullscreen { /// The surface - surface: ToplevelSurface, + surface: ToplevelSurface, /// The output (if any) on which the fullscreen is requested output: Option, }, /// A toplevel surface request to stop being fullscreen UnFullscreen { /// The surface - surface: ToplevelSurface, + surface: ToplevelSurface, }, /// A toplevel surface requested to be minimized Minimize { /// The surface - surface: ToplevelSurface, + surface: ToplevelSurface, }, /// The client requests the window menu to be displayed on this surface at this location /// @@ -932,7 +923,7 @@ pub enum XdgRequest { /// control of the window (maximize/minimize/close/move/etc...). ShowWindowMenu { /// The surface - surface: ToplevelSurface, + surface: ToplevelSurface, /// The seat associated with this input grab seat: wl_seat::WlSeat, /// the grab serial diff --git a/src/wayland/shell/xdg/xdg_handlers.rs b/src/wayland/shell/xdg/xdg_handlers.rs index 7b47503..b07c9ad 100644 --- a/src/wayland/shell/xdg/xdg_handlers.rs +++ b/src/wayland/shell/xdg/xdg_handlers.rs @@ -14,20 +14,19 @@ use super::{ XdgSurfacePendingState, XdgSurfaceRole, }; -pub(crate) fn implement_wm_base( +pub(crate) fn implement_wm_base( shell: NewResource, - shell_data: &ShellData, + shell_data: &ShellData, ) -> xdg_wm_base::XdgWmBase where R: Role + 'static, - SD: Default + 'static, { let shell = shell.implement_closure( - wm_implementation::, + wm_implementation::, None::, ShellUserData { shell_data: shell_data.clone(), - client_data: Mutex::new(make_shell_client_data::()), + client_data: Mutex::new(make_shell_client_data()), }, ); let mut user_impl = shell_data.user_impl.borrow_mut(); @@ -41,28 +40,26 @@ where * xdg_shell */ -pub(crate) struct ShellUserData { - shell_data: ShellData, - pub(crate) client_data: Mutex>, +pub(crate) struct ShellUserData { + shell_data: ShellData, + pub(crate) client_data: Mutex, } -pub(crate) fn make_shell_client( +pub(crate) fn make_shell_client( resource: &xdg_wm_base::XdgWmBase, token: CompositorToken, -) -> ShellClient { +) -> ShellClient { ShellClient { kind: super::ShellClientKind::Xdg(resource.clone()), _token: token, - _data: ::std::marker::PhantomData, } } -fn wm_implementation(request: xdg_wm_base::Request, shell: xdg_wm_base::XdgWmBase) +fn wm_implementation(request: xdg_wm_base::Request, shell: xdg_wm_base::XdgWmBase) where R: Role + 'static, - SD: 'static, { - let data = shell.as_ref().user_data::>().unwrap(); + let data = shell.as_ref().user_data::>().unwrap(); match request { xdg_wm_base::Request::Destroy => { // all is handled by destructor @@ -90,8 +87,8 @@ where return; } id.implement_closure( - xdg_surface_implementation::, - Some(destroy_surface::), + xdg_surface_implementation::, + Some(destroy_surface::), XdgSurfaceUserData { shell_data: data.shell_data.clone(), wl_surface: surface, @@ -186,18 +183,17 @@ fn implement_positioner( * xdg_surface */ -struct XdgSurfaceUserData { - shell_data: ShellData, +struct XdgSurfaceUserData { + shell_data: ShellData, wl_surface: wl_surface::WlSurface, wm_base: xdg_wm_base::XdgWmBase, } -fn destroy_surface(surface: xdg_surface::XdgSurface) +fn destroy_surface(surface: xdg_surface::XdgSurface) where R: Role + 'static, - SD: 'static, { - let data = surface.as_ref().user_data::>().unwrap(); + let data = surface.as_ref().user_data::>().unwrap(); if !data.wl_surface.as_ref().is_alive() { // the wl_surface is destroyed, this means the client is not // trying to change the role but it's a cleanup (possibly a @@ -219,15 +215,11 @@ where .expect("xdg_surface exists but surface has not shell_surface role?!"); } -fn xdg_surface_implementation(request: xdg_surface::Request, xdg_surface: xdg_surface::XdgSurface) +fn xdg_surface_implementation(request: xdg_surface::Request, xdg_surface: xdg_surface::XdgSurface) where R: Role + 'static, - SD: 'static, { - let data = xdg_surface - .as_ref() - .user_data::>() - .unwrap(); + let data = xdg_surface.as_ref().user_data::>().unwrap(); match request { xdg_surface::Request::Destroy => { // all is handled by our destructor @@ -246,8 +238,8 @@ where }) .expect("xdg_surface exists but surface has not shell_surface role?!"); let toplevel = id.implement_closure( - toplevel_implementation::, - Some(destroy_toplevel::), + toplevel_implementation::, + Some(destroy_toplevel::), ShellSurfaceUserData { shell_data: data.shell_data.clone(), wl_surface: data.wl_surface.clone(), @@ -278,7 +270,7 @@ where .unwrap(); let parent_surface = parent.map(|parent| { - let parent_data = parent.as_ref().user_data::>().unwrap(); + let parent_data = parent.as_ref().user_data::>().unwrap(); parent_data.wl_surface.clone() }); data.shell_data @@ -291,8 +283,8 @@ where }) .expect("xdg_surface exists but surface has not shell_surface role?!"); let popup = id.implement_closure( - xg_popup_implementation::, - Some(destroy_popup::), + xg_popup_implementation::, + Some(destroy_popup::), ShellSurfaceUserData { shell_data: data.shell_data.clone(), wl_surface: data.wl_surface.clone(), @@ -350,27 +342,20 @@ where * xdg_toplevel */ -pub(crate) struct ShellSurfaceUserData { - pub(crate) shell_data: ShellData, +pub(crate) struct ShellSurfaceUserData { + pub(crate) shell_data: ShellData, pub(crate) wl_surface: wl_surface::WlSurface, pub(crate) wm_base: xdg_wm_base::XdgWmBase, pub(crate) xdg_surface: xdg_surface::XdgSurface, } // Utility functions allowing to factor out a lot of the upcoming logic -fn with_surface_toplevel_data( - shell_data: &ShellData, - toplevel: &xdg_toplevel::XdgToplevel, - f: F, -) where +fn with_surface_toplevel_data(shell_data: &ShellData, toplevel: &xdg_toplevel::XdgToplevel, f: F) +where R: Role + 'static, - SD: 'static, F: FnOnce(&mut ToplevelState), { - let toplevel_data = toplevel - .as_ref() - .user_data::>() - .unwrap(); + let toplevel_data = toplevel.as_ref().user_data::>().unwrap(); shell_data .compositor_token .with_role_data::(&toplevel_data.wl_surface, |data| match data.pending_state { @@ -380,15 +365,11 @@ fn with_surface_toplevel_data( .expect("xdg_toplevel exists but surface has not shell_surface role?!"); } -pub fn send_toplevel_configure(resource: &xdg_toplevel::XdgToplevel, configure: ToplevelConfigure) +pub fn send_toplevel_configure(resource: &xdg_toplevel::XdgToplevel, configure: ToplevelConfigure) where R: Role + 'static, - SD: 'static, { - let data = resource - .as_ref() - .user_data::>() - .unwrap(); + let data = resource.as_ref().user_data::>().unwrap(); let (width, height) = configure.size.unwrap_or((0, 0)); // convert the Vec (which is really a Vec) into Vec let states = { @@ -409,30 +390,20 @@ where .expect("xdg_toplevel exists but surface has not shell_surface role?!"); } -fn make_toplevel_handle( - resource: &xdg_toplevel::XdgToplevel, -) -> super::ToplevelSurface { - let data = resource - .as_ref() - .user_data::>() - .unwrap(); +fn make_toplevel_handle(resource: &xdg_toplevel::XdgToplevel) -> super::ToplevelSurface { + let data = resource.as_ref().user_data::>().unwrap(); super::ToplevelSurface { wl_surface: data.wl_surface.clone(), shell_surface: ToplevelKind::Xdg(resource.clone()), token: data.shell_data.compositor_token, - _shell_data: ::std::marker::PhantomData, } } -fn toplevel_implementation(request: xdg_toplevel::Request, toplevel: xdg_toplevel::XdgToplevel) +fn toplevel_implementation(request: xdg_toplevel::Request, toplevel: xdg_toplevel::XdgToplevel) where R: Role + 'static, - SD: 'static, { - let data = toplevel - .as_ref() - .user_data::>() - .unwrap(); + let data = toplevel.as_ref().user_data::>().unwrap(); match request { xdg_toplevel::Request::Destroy => { // all it done by the destructor @@ -442,7 +413,7 @@ where toplevel_data.parent = parent.map(|toplevel_surface_parent| { toplevel_surface_parent .as_ref() - .user_data::>() + .user_data::>() .unwrap() .wl_surface .clone() @@ -531,15 +502,11 @@ where } } -fn destroy_toplevel(toplevel: xdg_toplevel::XdgToplevel) +fn destroy_toplevel(toplevel: xdg_toplevel::XdgToplevel) where R: Role + 'static, - SD: 'static, { - let data = toplevel - .as_ref() - .user_data::>() - .unwrap(); + let data = toplevel.as_ref().user_data::>().unwrap(); if !data.wl_surface.as_ref().is_alive() { // the wl_surface is destroyed, this means the client is not // trying to change the role but it's a cleanup (possibly a @@ -566,15 +533,11 @@ where * xdg_popup */ -pub(crate) fn send_popup_configure(resource: &xdg_popup::XdgPopup, configure: PopupConfigure) +pub(crate) fn send_popup_configure(resource: &xdg_popup::XdgPopup, configure: PopupConfigure) where R: Role + 'static, - SD: 'static, { - let data = resource - .as_ref() - .user_data::>() - .unwrap(); + let data = resource.as_ref().user_data::>().unwrap(); let (x, y) = configure.position; let (width, height) = configure.size; let serial = configure.serial; @@ -587,25 +550,20 @@ where .expect("xdg_toplevel exists but surface has not shell_surface role?!"); } -fn make_popup_handle(resource: &xdg_popup::XdgPopup) -> super::PopupSurface { - let data = resource - .as_ref() - .user_data::>() - .unwrap(); +fn make_popup_handle(resource: &xdg_popup::XdgPopup) -> super::PopupSurface { + let data = resource.as_ref().user_data::>().unwrap(); super::PopupSurface { wl_surface: data.wl_surface.clone(), shell_surface: PopupKind::Xdg(resource.clone()), token: data.shell_data.compositor_token, - _shell_data: ::std::marker::PhantomData, } } -fn xg_popup_implementation(request: xdg_popup::Request, popup: xdg_popup::XdgPopup) +fn xg_popup_implementation(request: xdg_popup::Request, popup: xdg_popup::XdgPopup) where R: Role + 'static, - SD: 'static, { - let data = popup.as_ref().user_data::>().unwrap(); + let data = popup.as_ref().user_data::>().unwrap(); match request { xdg_popup::Request::Destroy => { // all is handled by our destructor @@ -623,12 +581,11 @@ where } } -fn destroy_popup(popup: xdg_popup::XdgPopup) +fn destroy_popup(popup: xdg_popup::XdgPopup) where R: Role + 'static, - SD: 'static, { - let data = popup.as_ref().user_data::>().unwrap(); + let data = popup.as_ref().user_data::>().unwrap(); if !data.wl_surface.as_ref().is_alive() { // the wl_surface is destroyed, this means the client is not // trying to change the role but it's a cleanup (possibly a diff --git a/src/wayland/shell/xdg/zxdgv6_handlers.rs b/src/wayland/shell/xdg/zxdgv6_handlers.rs index 74ee194..3abb73b 100644 --- a/src/wayland/shell/xdg/zxdgv6_handlers.rs +++ b/src/wayland/shell/xdg/zxdgv6_handlers.rs @@ -17,20 +17,19 @@ use super::{ XdgSurfacePendingState, XdgSurfaceRole, }; -pub(crate) fn implement_shell( +pub(crate) fn implement_shell( shell: NewResource, - shell_data: &ShellData, + shell_data: &ShellData, ) -> zxdg_shell_v6::ZxdgShellV6 where R: Role + 'static, - SD: Default + 'static, { let shell = shell.implement_closure( - shell_implementation::, + shell_implementation::, None::, ShellUserData { shell_data: shell_data.clone(), - client_data: Mutex::new(make_shell_client_data::()), + client_data: Mutex::new(make_shell_client_data()), }, ); let mut user_impl = shell_data.user_impl.borrow_mut(); @@ -44,28 +43,26 @@ where * xdg_shell */ -pub(crate) struct ShellUserData { - shell_data: ShellData, - pub(crate) client_data: Mutex>, +pub(crate) struct ShellUserData { + shell_data: ShellData, + pub(crate) client_data: Mutex, } -pub(crate) fn make_shell_client( +pub(crate) fn make_shell_client( resource: &zxdg_shell_v6::ZxdgShellV6, token: CompositorToken, -) -> ShellClient { +) -> ShellClient { ShellClient { kind: super::ShellClientKind::ZxdgV6(resource.clone()), _token: token, - _data: ::std::marker::PhantomData, } } -fn shell_implementation(request: zxdg_shell_v6::Request, shell: zxdg_shell_v6::ZxdgShellV6) +fn shell_implementation(request: zxdg_shell_v6::Request, shell: zxdg_shell_v6::ZxdgShellV6) where R: Role + 'static, - SD: 'static, { - let data = shell.as_ref().user_data::>().unwrap(); + let data = shell.as_ref().user_data::>().unwrap(); match request { zxdg_shell_v6::Request::Destroy => { // all is handled by destructor @@ -93,8 +90,8 @@ where return; } id.implement_closure( - xdg_surface_implementation::, - Some(destroy_surface::), + xdg_surface_implementation::, + Some(destroy_surface::), XdgSurfaceUserData { shell_data: data.shell_data.clone(), wl_surface: surface.clone(), @@ -203,18 +200,17 @@ fn implement_positioner( * xdg_surface */ -struct XdgSurfaceUserData { - shell_data: ShellData, +struct XdgSurfaceUserData { + shell_data: ShellData, wl_surface: wl_surface::WlSurface, shell: zxdg_shell_v6::ZxdgShellV6, } -fn destroy_surface(surface: zxdg_surface_v6::ZxdgSurfaceV6) +fn destroy_surface(surface: zxdg_surface_v6::ZxdgSurfaceV6) where R: Role + 'static, - SD: 'static, { - let data = surface.as_ref().user_data::>().unwrap(); + let data = surface.as_ref().user_data::>().unwrap(); if !data.wl_surface.as_ref().is_alive() { // the wl_surface is destroyed, this means the client is not // trying to change the role but it's a cleanup (possibly a @@ -236,17 +232,13 @@ where .expect("xdg_surface exists but surface has not shell_surface role?!"); } -fn xdg_surface_implementation( +fn xdg_surface_implementation( request: zxdg_surface_v6::Request, xdg_surface: zxdg_surface_v6::ZxdgSurfaceV6, ) where R: Role + 'static, - SD: 'static, { - let data = xdg_surface - .as_ref() - .user_data::>() - .unwrap(); + let data = xdg_surface.as_ref().user_data::>().unwrap(); match request { zxdg_surface_v6::Request::Destroy => { // all is handled by our destructor @@ -265,8 +257,8 @@ fn xdg_surface_implementation( }) .expect("xdg_surface exists but surface has not shell_surface role?!"); let toplevel = id.implement_closure( - toplevel_implementation::, - Some(destroy_toplevel::), + toplevel_implementation::, + Some(destroy_toplevel::), ShellSurfaceUserData { shell_data: data.shell_data.clone(), wl_surface: data.wl_surface.clone(), @@ -296,7 +288,7 @@ fn xdg_surface_implementation( .user_data::>() .unwrap(); - let parent_data = parent.as_ref().user_data::>().unwrap(); + let parent_data = parent.as_ref().user_data::>().unwrap(); data.shell_data .compositor_token .with_role_data::(&data.wl_surface, |data| { @@ -307,8 +299,8 @@ fn xdg_surface_implementation( }) .expect("xdg_surface exists but surface has not shell_surface role?!"); let popup = id.implement_closure( - popup_implementation::, - Some(destroy_popup::), + popup_implementation::, + Some(destroy_popup::), ShellSurfaceUserData { shell_data: data.shell_data.clone(), wl_surface: data.wl_surface.clone(), @@ -366,24 +358,20 @@ fn xdg_surface_implementation( * xdg_toplevel */ -pub struct ShellSurfaceUserData { - pub(crate) shell_data: ShellData, +pub struct ShellSurfaceUserData { + pub(crate) shell_data: ShellData, pub(crate) wl_surface: wl_surface::WlSurface, pub(crate) shell: zxdg_shell_v6::ZxdgShellV6, pub(crate) xdg_surface: zxdg_surface_v6::ZxdgSurfaceV6, } // Utility functions allowing to factor out a lot of the upcoming logic -fn with_surface_toplevel_data(toplevel: &zxdg_toplevel_v6::ZxdgToplevelV6, f: F) +fn with_surface_toplevel_data(toplevel: &zxdg_toplevel_v6::ZxdgToplevelV6, f: F) where R: Role + 'static, - SD: 'static, F: FnOnce(&mut ToplevelState), { - let data = toplevel - .as_ref() - .user_data::>() - .unwrap(); + let data = toplevel.as_ref().user_data::>().unwrap(); data.shell_data .compositor_token .with_role_data::(&data.wl_surface, |data| match data.pending_state { @@ -393,17 +381,11 @@ where .expect("xdg_toplevel exists but surface has not shell_surface role?!"); } -pub fn send_toplevel_configure( - resource: &zxdg_toplevel_v6::ZxdgToplevelV6, - configure: ToplevelConfigure, -) where +pub fn send_toplevel_configure(resource: &zxdg_toplevel_v6::ZxdgToplevelV6, configure: ToplevelConfigure) +where R: Role + 'static, - SD: 'static, { - let data = resource - .as_ref() - .user_data::>() - .unwrap(); + let data = resource.as_ref().user_data::>().unwrap(); let (width, height) = configure.size.unwrap_or((0, 0)); // convert the Vec (which is really a Vec) into Vec let states = { @@ -424,54 +406,44 @@ pub fn send_toplevel_configure( .expect("xdg_toplevel exists but surface has not shell_surface role?!"); } -fn make_toplevel_handle( +fn make_toplevel_handle( resource: &zxdg_toplevel_v6::ZxdgToplevelV6, -) -> super::ToplevelSurface { - let data = resource - .as_ref() - .user_data::>() - .unwrap(); +) -> super::ToplevelSurface { + let data = resource.as_ref().user_data::>().unwrap(); super::ToplevelSurface { wl_surface: data.wl_surface.clone(), shell_surface: ToplevelKind::ZxdgV6(resource.clone()), token: data.shell_data.compositor_token, - _shell_data: ::std::marker::PhantomData, } } -fn toplevel_implementation( - request: zxdg_toplevel_v6::Request, - toplevel: zxdg_toplevel_v6::ZxdgToplevelV6, -) where +fn toplevel_implementation(request: zxdg_toplevel_v6::Request, toplevel: zxdg_toplevel_v6::ZxdgToplevelV6) +where R: Role + 'static, - SD: 'static, { - let data = toplevel - .as_ref() - .user_data::>() - .unwrap(); + let data = toplevel.as_ref().user_data::>().unwrap(); match request { zxdg_toplevel_v6::Request::Destroy => { // all it done by the destructor } zxdg_toplevel_v6::Request::SetParent { parent } => { - with_surface_toplevel_data::(&toplevel, |toplevel_data| { + with_surface_toplevel_data::(&toplevel, |toplevel_data| { toplevel_data.parent = parent.map(|toplevel_surface_parent| { let parent_data = toplevel_surface_parent .as_ref() - .user_data::>() + .user_data::>() .unwrap(); parent_data.wl_surface.clone() }) }); } zxdg_toplevel_v6::Request::SetTitle { title } => { - with_surface_toplevel_data::(&toplevel, |toplevel_data| { + with_surface_toplevel_data::(&toplevel, |toplevel_data| { toplevel_data.title = title; }); } zxdg_toplevel_v6::Request::SetAppId { app_id } => { - with_surface_toplevel_data::(&toplevel, |toplevel_data| { + with_surface_toplevel_data::(&toplevel, |toplevel_data| { toplevel_data.app_id = app_id; }); } @@ -507,12 +479,12 @@ fn toplevel_implementation( }); } zxdg_toplevel_v6::Request::SetMaxSize { width, height } => { - with_surface_toplevel_data::(&toplevel, |toplevel_data| { + with_surface_toplevel_data::(&toplevel, |toplevel_data| { toplevel_data.max_size = (width, height); }); } zxdg_toplevel_v6::Request::SetMinSize { width, height } => { - with_surface_toplevel_data::(&toplevel, |toplevel_data| { + with_surface_toplevel_data::(&toplevel, |toplevel_data| { toplevel_data.max_size = (width, height); }); } @@ -548,15 +520,11 @@ fn toplevel_implementation( } } -fn destroy_toplevel(toplevel: zxdg_toplevel_v6::ZxdgToplevelV6) +fn destroy_toplevel(toplevel: zxdg_toplevel_v6::ZxdgToplevelV6) where R: Role + 'static, - SD: 'static, { - let data = toplevel - .as_ref() - .user_data::>() - .unwrap(); + let data = toplevel.as_ref().user_data::>().unwrap(); if !data.wl_surface.as_ref().is_alive() { // the wl_surface is destroyed, this means the client is not // trying to change the role but it's a cleanup (possibly a @@ -583,15 +551,11 @@ where * xdg_popup */ -pub(crate) fn send_popup_configure(resource: &zxdg_popup_v6::ZxdgPopupV6, configure: PopupConfigure) +pub(crate) fn send_popup_configure(resource: &zxdg_popup_v6::ZxdgPopupV6, configure: PopupConfigure) where R: Role + 'static, - SD: 'static, { - let data = resource - .as_ref() - .user_data::>() - .unwrap(); + let data = resource.as_ref().user_data::>().unwrap(); let (x, y) = configure.position; let (width, height) = configure.size; let serial = configure.serial; @@ -604,27 +568,20 @@ where .expect("xdg_toplevel exists but surface has not shell_surface role?!"); } -fn make_popup_handle( - resource: &zxdg_popup_v6::ZxdgPopupV6, -) -> super::PopupSurface { - let data = resource - .as_ref() - .user_data::>() - .unwrap(); +fn make_popup_handle(resource: &zxdg_popup_v6::ZxdgPopupV6) -> super::PopupSurface { + let data = resource.as_ref().user_data::>().unwrap(); super::PopupSurface { wl_surface: data.wl_surface.clone(), shell_surface: PopupKind::ZxdgV6(resource.clone()), token: data.shell_data.compositor_token, - _shell_data: ::std::marker::PhantomData, } } -fn popup_implementation(request: zxdg_popup_v6::Request, popup: zxdg_popup_v6::ZxdgPopupV6) +fn popup_implementation(request: zxdg_popup_v6::Request, popup: zxdg_popup_v6::ZxdgPopupV6) where R: Role + 'static, - SD: 'static, { - let data = popup.as_ref().user_data::>().unwrap(); + let data = popup.as_ref().user_data::>().unwrap(); match request { zxdg_popup_v6::Request::Destroy => { // all is handled by our destructor @@ -642,12 +599,11 @@ where } } -fn destroy_popup(popup: zxdg_popup_v6::ZxdgPopupV6) +fn destroy_popup(popup: zxdg_popup_v6::ZxdgPopupV6) where R: Role + 'static, - SD: 'static, { - let data = popup.as_ref().user_data::>().unwrap(); + let data = popup.as_ref().user_data::>().unwrap(); if !data.wl_surface.as_ref().is_alive() { // the wl_surface is destroyed, this means the client is not // trying to change the role but it's a cleanup (possibly a