diff --git a/anvil/src/glium_drawer.rs b/anvil/src/glium_drawer.rs index 99460ca..3292edc 100644 --- a/anvil/src/glium_drawer.rs +++ b/anvil/src/glium_drawer.rs @@ -28,7 +28,7 @@ use smithay::{ }; use crate::shaders; -use crate::shell::{MyCompositorToken, MyWindowMap}; +use crate::shell::{MyCompositorToken, MyWindowMap, SurfaceData}; #[derive(Copy, Clone)] struct Vertex { @@ -299,70 +299,77 @@ impl GliumDrawer { location, |_surface, attributes, role, &(mut x, mut y)| { // Pull a new buffer if available - if attributes.user_data.texture.is_none() { - if let Some(buffer) = attributes.user_data.buffer.take() { - if let Ok(m) = self.texture_from_buffer(buffer.clone()) { - // release the buffer if it was an SHM buffer - #[cfg(feature = "egl")] - { - if m.images.is_none() { + if let Some(data) = attributes.user_data.get_mut::() { + if data.texture.is_none() { + if let Some(buffer) = data.buffer.take() { + if let Ok(m) = self.texture_from_buffer(buffer.clone()) { + // release the buffer if it was an SHM buffer + #[cfg(feature = "egl")] + { + if m.images.is_none() { + buffer.release(); + } + } + #[cfg(not(feature = "egl"))] + { buffer.release(); } - } - #[cfg(not(feature = "egl"))] - { + + data.texture = Some(m); + } else { + // there was an error reading the buffer, release it, we + // already logged the error buffer.release(); } - - attributes.user_data.texture = Some(m); - } else { - // there was an error reading the buffer, release it, we - // already logged the error - buffer.release(); } } - } - // Now, should we be drawn ? - if attributes.user_data.texture.is_some() { - // if yes, also process the children - if let Ok(subdata) = Role::::data(role) { - x += subdata.location.0; - y += subdata.location.1; + // Now, should we be drawn ? + if data.texture.is_some() { + // if yes, also process the children + if let Ok(subdata) = Role::::data(role) { + x += subdata.location.0; + y += subdata.location.1; + } + TraversalAction::DoChildren((x, y)) + } else { + // we are not displayed, so our children are neither + TraversalAction::SkipChildren } - TraversalAction::DoChildren((x, y)) } else { - // we are not display, so our children are neither + // we are not displayed, so our children are neither TraversalAction::SkipChildren } }, |_surface, attributes, role, &(mut x, mut y)| { - if let Some(ref metadata) = attributes.user_data.texture { - // we need to re-extract the subsurface offset, as the previous closure - // only passes it to our children - if let Ok(subdata) = Role::::data(role) { - x += subdata.location.0; - y += subdata.location.1; + if let Some(ref data) = attributes.user_data.get::() { + if let Some(ref metadata) = data.texture { + // we need to re-extract the subsurface offset, as the previous closure + // only passes it to our children + if let Ok(subdata) = Role::::data(role) { + x += subdata.location.0; + y += subdata.location.1; + } + self.render_texture( + frame, + &metadata.texture, + metadata.fragment, + metadata.y_inverted, + metadata.dimensions, + (x, y), + screen_dimensions, + ::glium::Blend { + color: ::glium::BlendingFunction::Addition { + source: ::glium::LinearBlendingFactor::One, + destination: ::glium::LinearBlendingFactor::OneMinusSourceAlpha, + }, + alpha: ::glium::BlendingFunction::Addition { + source: ::glium::LinearBlendingFactor::One, + destination: ::glium::LinearBlendingFactor::OneMinusSourceAlpha, + }, + ..Default::default() + }, + ); } - self.render_texture( - frame, - &metadata.texture, - metadata.fragment, - metadata.y_inverted, - metadata.dimensions, - (x, y), - screen_dimensions, - ::glium::Blend { - color: ::glium::BlendingFunction::Addition { - source: ::glium::LinearBlendingFactor::One, - destination: ::glium::LinearBlendingFactor::OneMinusSourceAlpha, - }, - alpha: ::glium::BlendingFunction::Addition { - source: ::glium::LinearBlendingFactor::One, - destination: ::glium::LinearBlendingFactor::OneMinusSourceAlpha, - }, - ..Default::default() - }, - ); } }, |_, _, _, _| true, diff --git a/anvil/src/shell.rs b/anvil/src/shell.rs index 54a8d18..455230c 100644 --- a/anvil/src/shell.rs +++ b/anvil/src/shell.rs @@ -36,18 +36,17 @@ define_roles!(Roles => [ CursorImage, CursorImageRole ] ); -pub type MyWindowMap = - WindowMap) -> Option<(i32, i32)>>; +pub type MyWindowMap = WindowMap Option<(i32, i32)>>; -pub type MyCompositorToken = CompositorToken; +pub type MyCompositorToken = CompositorToken; pub fn init_shell( display: &mut Display, log: ::slog::Logger, ) -> ( - CompositorToken, - Arc>>, - Arc>>, + CompositorToken, + Arc>>, + Arc>>, Rc>, ) { // Create the compositor @@ -63,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 _, ))); @@ -105,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, @@ -135,31 +134,34 @@ pub struct SurfaceData { pub texture: Option, } -fn surface_commit(surface: &wl_surface::WlSurface, token: CompositorToken) { +fn surface_commit(surface: &wl_surface::WlSurface, token: CompositorToken) { // we retrieve the contents of the associated buffer and copy it token.with_surface_data(surface, |attributes| { + attributes.user_data.insert_if_missing(|| SurfaceData::default()); match attributes.buffer.take() { Some(Some((buffer, (_x, _y)))) => { // new contents // TODO: handle hotspot coordinates - attributes.user_data.buffer = Some(buffer); - attributes.user_data.texture = None; + let data = attributes.user_data.get_mut::().unwrap(); + data.buffer = Some(buffer); + data.texture = None; } Some(None) => { // erase the contents - attributes.user_data.buffer = None; - attributes.user_data.texture = None; + let data = attributes.user_data.get_mut::().unwrap(); + data.buffer = None; + data.texture = None; } None => {} } }); } -fn get_size(attrs: &SurfaceAttributes) -> Option<(i32, i32)> { - attrs - .user_data - .texture - .as_ref() - .map(|ref meta| meta.dimensions) - .map(|(x, y)| (x as i32, y as i32)) +fn get_size(attrs: &SurfaceAttributes) -> Option<(i32, i32)> { + attrs.user_data.get::().and_then(|data| { + data.texture + .as_ref() + .map(|ref meta| meta.dimensions) + .map(|(x, y)| (x as i32, y as i32)) + }) } diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index 7e970b4..fdfdebf 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -63,7 +63,7 @@ use smithay::{ use crate::glium_drawer::GliumDrawer; use crate::input_handler::AnvilInputHandler; -use crate::shell::{init_shell, MyWindowMap, Roles, SurfaceData}; +use crate::shell::{init_shell, MyWindowMap, Roles}; pub struct SessionFd(RawFd); impl AsRawFd for SessionFd { @@ -272,7 +272,7 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop<()>, log: Logger } struct UdevHandlerImpl { - compositor_token: CompositorToken, + compositor_token: CompositorToken, #[cfg(feature = "egl")] active_egl_context: Rc>>, session: AutoSession, @@ -522,7 +522,7 @@ impl UdevHandler for UdevHandlerImpl } pub struct DrmHandlerImpl { - compositor_token: CompositorToken, + compositor_token: CompositorToken, backends: Rc>>>, window_map: Rc>, pointer_location: Rc>, diff --git a/anvil/src/window_map.rs b/anvil/src/window_map.rs index f7ff7af..2645b44 100644 --- a/anvil/src/window_map.rs +++ b/anvil/src/window_map.rs @@ -12,14 +12,13 @@ use smithay::{ }, }; -pub enum Kind { - Xdg(ToplevelSurface), - Wl(ShellSurface), +pub enum Kind { + Xdg(ToplevelSurface), + Wl(ShellSurface), } -impl Kind +impl Kind where - U: 'static, R: Role + Role + Role> + 'static, SD: 'static, D: 'static, @@ -38,15 +37,14 @@ where } } -struct Window { +struct Window { location: (i32, i32), surface: Rectangle, - toplevel: Kind, + toplevel: Kind, } -impl Window +impl Window where - U: 'static, R: Role + Role + Role> + 'static, SD: 'static, D: 'static, @@ -55,11 +53,11 @@ where fn matching( &self, point: (f64, f64), - ctoken: CompositorToken, + ctoken: CompositorToken, get_size: F, ) -> Option<(wl_surface::WlSurface, (f64, f64))> where - F: Fn(&SurfaceAttributes) -> Option<(i32, i32)>, + F: Fn(&SurfaceAttributes) -> Option<(i32, i32)>, { if !self.surface.contains((point.0 as i32, point.1 as i32)) { return None; @@ -101,9 +99,9 @@ where found.into_inner() } - fn self_update(&mut self, ctoken: CompositorToken, get_size: F) + fn self_update(&mut self, ctoken: CompositorToken, get_size: F) where - F: Fn(&SurfaceAttributes) -> Option<(i32, i32)>, + F: Fn(&SurfaceAttributes) -> Option<(i32, i32)>, { let (base_x, base_y) = self.location; let (mut min_x, mut min_y, mut max_x, mut max_y) = (base_x, base_y, base_x, base_y); @@ -148,21 +146,20 @@ where } } -pub struct WindowMap { - ctoken: CompositorToken, - windows: Vec>, +pub struct WindowMap { + ctoken: CompositorToken, + windows: Vec>, get_size: F, } -impl WindowMap +impl WindowMap where - F: Fn(&SurfaceAttributes) -> Option<(i32, i32)>, - U: 'static, + F: Fn(&SurfaceAttributes) -> Option<(i32, i32)>, R: Role + Role + Role> + 'static, SD: 'static, D: 'static, { - pub fn new(ctoken: CompositorToken, get_size: F) -> WindowMap { + pub fn new(ctoken: CompositorToken, get_size: F) -> WindowMap { WindowMap { ctoken, windows: Vec::new(), @@ -170,7 +167,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 { @@ -216,7 +213,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/backend/egl/mod.rs b/src/backend/egl/mod.rs index 38876c0..316df5d 100644 --- a/src/backend/egl/mod.rs +++ b/src/backend/egl/mod.rs @@ -300,7 +300,6 @@ impl Drop for EGLImages { } } } - println!("RELEASING EGL BUFFER"); self.buffer.release(); } } diff --git a/src/wayland/compositor/handlers.rs b/src/wayland/compositor/handlers.rs index c483dfd..ac76cdb 100644 --- a/src/wayland/compositor/handlers.rs +++ b/src/wayland/compositor/handlers.rs @@ -15,15 +15,14 @@ use super::{ * wl_compositor */ -pub(crate) fn implement_compositor( +pub(crate) fn implement_compositor( compositor: NewResource, log: ::slog::Logger, implem: Rc>, ) -> wl_compositor::WlCompositor where - U: Default + 'static, R: Default + 'static, - Impl: FnMut(SurfaceEvent, wl_surface::WlSurface, CompositorToken) + 'static, + Impl: FnMut(SurfaceEvent, wl_surface::WlSurface, CompositorToken) + 'static, { compositor.implement_closure( move |request, _compositor| match request { @@ -47,34 +46,33 @@ where */ // Internal implementation data of surfaces -pub(crate) struct SurfaceImplem { +pub(crate) struct SurfaceImplem { log: ::slog::Logger, - implem: Rc)>>, + implem: Rc)>>, } -impl SurfaceImplem { - fn make(log: ::slog::Logger, implem: Rc>) -> SurfaceImplem +impl SurfaceImplem { + fn make(log: ::slog::Logger, implem: Rc>) -> SurfaceImplem where - Impl: FnMut(SurfaceEvent, wl_surface::WlSurface, CompositorToken) + 'static, + Impl: FnMut(SurfaceEvent, wl_surface::WlSurface, CompositorToken) + 'static, { SurfaceImplem { log, implem } } } -impl SurfaceImplem +impl SurfaceImplem where - U: 'static, R: 'static, { fn receive_surface_request(&mut self, req: wl_surface::Request, surface: wl_surface::WlSurface) { match req { wl_surface::Request::Attach { buffer, x, y } => { - SurfaceData::::with_data(&surface, |d| { + SurfaceData::::with_data(&surface, |d| { d.buffer = Some(buffer.map(|b| (b.clone(), (x, y)))) }); } wl_surface::Request::Damage { x, y, width, height } => { - SurfaceData::::with_data(&surface, |d| { + SurfaceData::::with_data(&surface, |d| { d.damage = Damage::Surface(Rectangle { x, y, width, height }) }); } @@ -88,14 +86,14 @@ where let attributes_mutex = r.as_ref().user_data::>().unwrap(); attributes_mutex.lock().unwrap().clone() }); - SurfaceData::::with_data(&surface, |d| d.opaque_region = attributes); + SurfaceData::::with_data(&surface, |d| d.opaque_region = attributes); } wl_surface::Request::SetInputRegion { region } => { let attributes = region.map(|r| { let attributes_mutex = r.as_ref().user_data::>().unwrap(); attributes_mutex.lock().unwrap().clone() }); - SurfaceData::::with_data(&surface, |d| d.input_region = attributes); + SurfaceData::::with_data(&surface, |d| d.input_region = attributes); } wl_surface::Request::Commit => { let mut user_impl = self.implem.borrow_mut(); @@ -103,13 +101,13 @@ where (&mut *user_impl)(SurfaceEvent::Commit, surface, CompositorToken::make()); } wl_surface::Request::SetBufferTransform { transform } => { - SurfaceData::::with_data(&surface, |d| d.buffer_transform = transform); + SurfaceData::::with_data(&surface, |d| d.buffer_transform = transform); } wl_surface::Request::SetBufferScale { scale } => { - SurfaceData::::with_data(&surface, |d| d.buffer_scale = scale); + SurfaceData::::with_data(&surface, |d| d.buffer_scale = scale); } wl_surface::Request::DamageBuffer { x, y, width, height } => { - SurfaceData::::with_data(&surface, |d| { + SurfaceData::::with_data(&surface, |d| { d.damage = Damage::Buffer(Rectangle { x, y, width, height }) }); } @@ -121,25 +119,24 @@ where } } -fn implement_surface( +fn implement_surface( surface: NewResource, log: ::slog::Logger, implem: Rc>, ) -> wl_surface::WlSurface where - U: Default + 'static, R: Default + 'static, - Impl: FnMut(SurfaceEvent, wl_surface::WlSurface, CompositorToken) + 'static, + Impl: FnMut(SurfaceEvent, wl_surface::WlSurface, CompositorToken) + 'static, { let surface = surface.implement_closure( { let mut implem = SurfaceImplem::make(log, implem); move |req, surface| implem.receive_surface_request(req, surface) }, - Some(|surface| SurfaceData::::cleanup(&surface)), - SurfaceData::::new(), + Some(|surface| SurfaceData::::cleanup(&surface)), + SurfaceData::::new(), ); - SurfaceData::::init(&surface); + SurfaceData::::init(&surface); surface } @@ -176,24 +173,23 @@ fn implement_region(region: NewResource) -> wl_region::WlRe * wl_subcompositor */ -pub(crate) fn implement_subcompositor( +pub(crate) fn implement_subcompositor( subcompositor: NewResource, ) -> wl_subcompositor::WlSubcompositor where R: RoleType + Role + 'static, - U: 'static, { subcompositor.implement_closure( move |request, subcompositor| match request { wl_subcompositor::Request::GetSubsurface { id, surface, parent } => { - if let Err(()) = SurfaceData::::set_parent(&surface, &parent) { + if let Err(()) = SurfaceData::::set_parent(&surface, &parent) { subcompositor.as_ref().post_error( wl_subcompositor::Error::BadSurface as u32, "Surface already has a role.".into(), ); return; } - implement_subsurface::(id, surface.clone()); + implement_subsurface::(id, surface.clone()); } wl_subcompositor::Request::Destroy => {} _ => unreachable!(), @@ -207,36 +203,34 @@ where * wl_subsurface */ -fn with_subsurface_attributes(subsurface: &wl_subsurface::WlSubsurface, f: F) +fn with_subsurface_attributes(subsurface: &wl_subsurface::WlSubsurface, f: F) where F: FnOnce(&mut SubsurfaceRole), - U: 'static, R: RoleType + Role + 'static, { let surface = subsurface.as_ref().user_data::().unwrap(); - SurfaceData::::with_role_data::(surface, |d| f(d)) + SurfaceData::::with_role_data::(surface, |d| f(d)) .expect("The surface does not have a subsurface role while it has a wl_subsurface?!"); } -fn implement_subsurface( +fn implement_subsurface( subsurface: NewResource, surface: wl_surface::WlSurface, ) -> wl_subsurface::WlSubsurface where - U: 'static, R: RoleType + Role + 'static, { subsurface.implement_closure( |request, subsurface| { match request { wl_subsurface::Request::SetPosition { x, y } => { - with_subsurface_attributes::(&subsurface, |attrs| { + with_subsurface_attributes::(&subsurface, |attrs| { attrs.location = (x, y); }) } wl_subsurface::Request::PlaceAbove { sibling } => { let surface = subsurface.as_ref().user_data::().unwrap(); - if let Err(()) = SurfaceData::::reorder(surface, Location::After, &sibling) { + if let Err(()) = SurfaceData::::reorder(surface, Location::After, &sibling) { subsurface.as_ref().post_error( wl_subsurface::Error::BadSurface as u32, "Provided surface is not a sibling or parent.".into(), @@ -245,20 +239,18 @@ where } wl_subsurface::Request::PlaceBelow { sibling } => { let surface = subsurface.as_ref().user_data::().unwrap(); - if let Err(()) = SurfaceData::::reorder(surface, Location::Before, &sibling) { + if let Err(()) = SurfaceData::::reorder(surface, Location::Before, &sibling) { subsurface.as_ref().post_error( wl_subsurface::Error::BadSurface as u32, "Provided surface is not a sibling or parent.".into(), ) } } - wl_subsurface::Request::SetSync => { - with_subsurface_attributes::(&subsurface, |attrs| { - attrs.sync = true; - }) - } + wl_subsurface::Request::SetSync => with_subsurface_attributes::(&subsurface, |attrs| { + attrs.sync = true; + }), wl_subsurface::Request::SetDesync => { - with_subsurface_attributes::(&subsurface, |attrs| { + with_subsurface_attributes::(&subsurface, |attrs| { attrs.sync = false; }) } @@ -268,18 +260,17 @@ where _ => unreachable!(), } }, - Some(|subsurface| destroy_subsurface::(&subsurface)), + Some(|subsurface| destroy_subsurface::(&subsurface)), surface, ) } -fn destroy_subsurface(subsurface: &wl_subsurface::WlSubsurface) +fn destroy_subsurface(subsurface: &wl_subsurface::WlSubsurface) where - U: 'static, R: RoleType + Role + 'static, { let surface = subsurface.as_ref().user_data::().unwrap(); if surface.as_ref().is_alive() { - SurfaceData::::unset_parent(&surface); + SurfaceData::::unset_parent(&surface); } } diff --git a/src/wayland/compositor/mod.rs b/src/wayland/compositor/mod.rs index fd3ede5..ddb4818 100644 --- a/src/wayland/compositor/mod.rs +++ b/src/wayland/compositor/mod.rs @@ -32,14 +32,6 @@ //! # #[macro_use] extern crate smithay; //! use smithay::wayland::compositor::compositor_init; //! -//! // Define some user data to be associated with the surfaces. -//! // It must implement the Default trait, which will represent the state of a surface which -//! // has just been created. -//! #[derive(Default)] -//! struct MyData { -//! // whatever you need here -//! } -//! //! // Declare the roles enum //! define_roles!(MyRoles); //! @@ -47,7 +39,7 @@ //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut display = wayland_server::Display::new(event_loop.handle()); //! // Call the init function: -//! let (token, _, _) = compositor_init::( +//! let (token, _, _) = compositor_init::( //! &mut display, //! |request, surface, compositor_token| { //! /* @@ -112,8 +104,7 @@ pub enum Damage { } #[derive(Copy, Clone, Default)] -struct Marker { - _u: ::std::marker::PhantomData, +struct Marker { _r: ::std::marker::PhantomData, } @@ -125,7 +116,7 @@ struct Marker { /// /// You are responsible for setting those values as you see fit to avoid /// processing them two times. -pub struct SurfaceAttributes { +pub struct SurfaceAttributes { /// Buffer defining the contents of the surface /// /// The tuple represent the coordinates of this buffer @@ -164,11 +155,11 @@ pub struct SurfaceAttributes { /// User-controlled data /// /// This is your field to host whatever you need. - pub user_data: U, + pub user_data: ::wayland_commons::utils::UserDataMap, } -impl Default for SurfaceAttributes { - fn default() -> SurfaceAttributes { +impl Default for SurfaceAttributes { + fn default() -> SurfaceAttributes { SurfaceAttributes { buffer: None, buffer_scale: 1, @@ -176,7 +167,7 @@ impl Default for SurfaceAttributes { opaque_region: None, input_region: None, damage: Damage::Full, - user_data: Default::default(), + user_data: ::wayland_commons::utils::UserDataMap::new(), } } } @@ -239,33 +230,30 @@ impl Default for RegionAttributes { /// access data associated with the [`wl_surface`](wayland_server::protocol::wl_surface) /// and [`wl_region`](wayland_server::protocol::wl_region) managed /// by the `CompositorGlobal` that provided it. -pub struct CompositorToken { - _data: ::std::marker::PhantomData<*mut U>, +pub struct CompositorToken { _role: ::std::marker::PhantomData<*mut R>, } -// we implement them manually because #[derive(..)] would require -// U: Clone and R: Clone -impl Copy for CompositorToken {} -impl Clone for CompositorToken { - fn clone(&self) -> CompositorToken { +// we implement them manually because #[derive(..)] would require R: Clone +impl Copy for CompositorToken {} +impl Clone for CompositorToken { + fn clone(&self) -> CompositorToken { *self } } -unsafe impl Send for CompositorToken {} -unsafe impl Sync for CompositorToken {} +unsafe impl Send for CompositorToken {} +unsafe impl Sync for CompositorToken {} -impl CompositorToken { - pub(crate) fn make() -> CompositorToken { +impl CompositorToken { + pub(crate) fn make() -> CompositorToken { CompositorToken { - _data: ::std::marker::PhantomData, _role: ::std::marker::PhantomData, } } } -impl CompositorToken { +impl CompositorToken { /// Access the data of a surface /// /// The closure will be called with the contents of the data associated with this surface. @@ -274,15 +262,14 @@ impl CompositorToken { /// will panic (having more than one compositor is not supported). pub fn with_surface_data(&self, surface: &WlSurface, f: F) -> T where - F: FnOnce(&mut SurfaceAttributes) -> T, + F: FnOnce(&mut SurfaceAttributes) -> T, { - SurfaceData::::with_data(surface, f) + SurfaceData::::with_data(surface, f) } } -impl CompositorToken +impl CompositorToken where - U: 'static, R: RoleType + Role + 'static, { /// Access the data of a surface tree from bottom to top @@ -319,11 +306,11 @@ where processor: F2, post_filter: F3, ) where - F1: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> TraversalAction, - F2: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T), - F3: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> bool, + F1: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> TraversalAction, + F2: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T), + F3: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> bool, { - SurfaceData::::map_tree(surface, &initial, filter, processor, post_filter, false); + SurfaceData::::map_tree(surface, &initial, filter, processor, post_filter, false); } /// Access the data of a surface tree from top to bottom @@ -340,11 +327,11 @@ where processor: F2, post_filter: F3, ) where - F1: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> TraversalAction, - F2: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T), - F3: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> bool, + F1: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> TraversalAction, + F2: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T), + F3: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> bool, { - SurfaceData::::map_tree(surface, &initial, filter, processor, post_filter, true); + SurfaceData::::map_tree(surface, &initial, filter, processor, post_filter, true); } /// Retrieve the parent of this surface @@ -354,7 +341,7 @@ where /// If the surface is not managed by the `CompositorGlobal` that provided this token, this /// will panic (having more than one compositor is not supported). pub fn get_parent(&self, surface: &WlSurface) -> Option { - SurfaceData::::get_parent(surface) + SurfaceData::::get_parent(surface) } /// Retrieve the children of this surface @@ -362,17 +349,17 @@ where /// If the surface is not managed by the `CompositorGlobal` that provided this token, this /// will panic (having more than one compositor is not supported). pub fn get_children(&self, surface: &WlSurface) -> Vec { - SurfaceData::::get_children(surface) + SurfaceData::::get_children(surface) } } -impl CompositorToken { +impl CompositorToken { /// Check whether this surface as a role or not /// /// If the surface is not managed by the `CompositorGlobal` that provided this token, this /// will panic (having more than one compositor is not supported). pub fn has_a_role(&self, surface: &WlSurface) -> bool { - SurfaceData::::has_a_role(surface) + SurfaceData::::has_a_role(surface) } /// Check whether this surface as a specific role @@ -383,7 +370,7 @@ impl CompositorToken { where R: Role, { - SurfaceData::::has_role::(surface) + SurfaceData::::has_role::(surface) } /// Register that this surface has given role with default data @@ -397,7 +384,7 @@ impl CompositorToken { R: Role, RoleData: Default, { - SurfaceData::::give_role::(surface) + SurfaceData::::give_role::(surface) } /// Register that this surface has given role with given data @@ -410,7 +397,7 @@ impl CompositorToken { where R: Role, { - SurfaceData::::give_role_with::(surface, data) + SurfaceData::::give_role_with::(surface, data) } /// Access the role data of a surface @@ -424,7 +411,7 @@ impl CompositorToken { R: Role, F: FnOnce(&mut RoleData) -> T, { - SurfaceData::::with_role_data::(surface, f) + SurfaceData::::with_role_data::(surface, f) } /// Register that this surface does not have a role any longer and retrieve the data @@ -437,7 +424,7 @@ impl CompositorToken { where R: Role, { - SurfaceData::::remove_role::(surface) + SurfaceData::::remove_role::(surface) } /// Retrieve the metadata associated with a `wl_region` @@ -461,30 +448,29 @@ impl CompositorToken { /// /// It also returns the two global handles, in case you wish to remove these /// globals from the event loop in the future. -pub fn compositor_init( +pub fn compositor_init( display: &mut Display, implem: Impl, logger: L, ) -> ( - CompositorToken, + CompositorToken, Global, Global, ) where L: Into>, - U: Default + 'static, R: Default + RoleType + Role + 'static, - Impl: FnMut(SurfaceEvent, WlSurface, CompositorToken) + 'static, + Impl: FnMut(SurfaceEvent, WlSurface, CompositorToken) + 'static, { let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "compositor_handler")); let implem = Rc::new(RefCell::new(implem)); let compositor = display.create_global(4, move |new_compositor, _version| { - self::handlers::implement_compositor::(new_compositor, log.clone(), implem.clone()); + self::handlers::implement_compositor::(new_compositor, log.clone(), implem.clone()); }); let subcompositor = display.create_global(1, move |new_subcompositor, _version| { - self::handlers::implement_subcompositor::(new_subcompositor); + self::handlers::implement_subcompositor::(new_subcompositor); }); (CompositorToken::make(), compositor, subcompositor) diff --git a/src/wayland/compositor/tree.rs b/src/wayland/compositor/tree.rs index 45c69a3..0b10736 100644 --- a/src/wayland/compositor/tree.rs +++ b/src/wayland/compositor/tree.rs @@ -15,11 +15,11 @@ use wayland_server::protocol::wl_surface::WlSurface; /// /// Each node also appears within its children list, to allow relative placement /// between them. -pub struct SurfaceData { +pub struct SurfaceData { parent: Option, children: Vec, role: R, - attributes: SurfaceAttributes, + attributes: SurfaceAttributes, } pub enum Location { @@ -37,8 +37,8 @@ pub enum TraversalAction { Break, } -impl SurfaceData { - pub fn new() -> Mutex> { +impl SurfaceData { + pub fn new() -> Mutex> { Mutex::new(SurfaceData { parent: None, children: vec![], @@ -48,14 +48,13 @@ impl SurfaceData { } } -impl SurfaceData +impl SurfaceData where - U: 'static, R: 'static, { /// Initializes the surface, must be called at creation for state coherence pub fn init(surface: &WlSurface) { - let my_data_mutex = surface.as_ref().user_data::>>().unwrap(); + let my_data_mutex = surface.as_ref().user_data::>>().unwrap(); let mut my_data = my_data_mutex.lock().unwrap(); debug_assert!(my_data.children.len() == 0); my_data.children.push(surface.clone()); @@ -63,14 +62,11 @@ where /// Cleans the `as_ref().user_data` of that surface, must be called when it is destroyed pub fn cleanup(surface: &WlSurface) { - let my_data_mutex = surface.as_ref().user_data::>>().unwrap(); + let my_data_mutex = surface.as_ref().user_data::>>().unwrap(); 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 - .as_ref() - .user_data::>>() - .unwrap(); + let old_parent_mutex = old_parent.as_ref().user_data::>>().unwrap(); let mut old_parent_guard = old_parent_mutex.lock().unwrap(); old_parent_guard .children @@ -82,17 +78,17 @@ where if child.as_ref().equals(surface.as_ref()) { continue; } - let child_mutex = child.as_ref().user_data::>>().unwrap(); + let child_mutex = child.as_ref().user_data::>>().unwrap(); let mut child_guard = child_mutex.lock().unwrap(); child_guard.parent = None; } } } -impl SurfaceData { +impl SurfaceData { pub fn has_a_role(surface: &WlSurface) -> bool { debug_assert!(surface.as_ref().is_alive()); - let data_mutex = surface.as_ref().user_data::>>().unwrap(); + let data_mutex = surface.as_ref().user_data::>>().unwrap(); let data_guard = data_mutex.lock().unwrap(); ::has_role(&data_guard.role) } @@ -103,7 +99,7 @@ impl SurfaceData { R: Role, { debug_assert!(surface.as_ref().is_alive()); - let data_mutex = surface.as_ref().user_data::>>().unwrap(); + let data_mutex = surface.as_ref().user_data::>>().unwrap(); let data_guard = data_mutex.lock().unwrap(); >::has(&data_guard.role) } @@ -115,7 +111,7 @@ impl SurfaceData { RoleData: Default, { debug_assert!(surface.as_ref().is_alive()); - let data_mutex = surface.as_ref().user_data::>>().unwrap(); + let data_mutex = surface.as_ref().user_data::>>().unwrap(); let mut data_guard = data_mutex.lock().unwrap(); >::set(&mut data_guard.role) } @@ -128,7 +124,7 @@ impl SurfaceData { R: Role, { debug_assert!(surface.as_ref().is_alive()); - let data_mutex = surface.as_ref().user_data::>>().unwrap(); + let data_mutex = surface.as_ref().user_data::>>().unwrap(); let mut data_guard = data_mutex.lock().unwrap(); >::set_with(&mut data_guard.role, data) } @@ -142,7 +138,7 @@ impl SurfaceData { R: Role, { debug_assert!(surface.as_ref().is_alive()); - let data_mutex = surface.as_ref().user_data::>>().unwrap(); + let data_mutex = surface.as_ref().user_data::>>().unwrap(); let mut data_guard = data_mutex.lock().unwrap(); >::unset(&mut data_guard.role) } @@ -154,17 +150,17 @@ impl SurfaceData { F: FnOnce(&mut RoleData) -> T, { debug_assert!(surface.as_ref().is_alive()); - let data_mutex = surface.as_ref().user_data::>>().unwrap(); + let data_mutex = surface.as_ref().user_data::>>().unwrap(); let mut data_guard = data_mutex.lock().unwrap(); let data = >::data_mut(&mut data_guard.role)?; Ok(f(data)) } } -impl + 'static> SurfaceData { +impl + 'static> SurfaceData { /// Checks if the first surface is an ancestor of the second pub fn is_ancestor(a: &WlSurface, b: &WlSurface) -> bool { - let b_mutex = b.as_ref().user_data::>>().unwrap(); + let b_mutex = b.as_ref().user_data::>>().unwrap(); let b_guard = b_mutex.lock().unwrap(); if let Some(ref parent) = b_guard.parent { if parent.as_ref().equals(a.as_ref()) { @@ -191,7 +187,7 @@ impl + 'static> SurfaceData // change child's parent { - let child_mutex = child.as_ref().user_data::>>().unwrap(); + let child_mutex = child.as_ref().user_data::>>().unwrap(); let mut child_guard = child_mutex.lock().unwrap(); // if surface already has a role, it cannot become a subsurface >::set(&mut child_guard.role)?; @@ -200,7 +196,7 @@ impl + 'static> SurfaceData } // register child to new parent { - let parent_mutex = parent.as_ref().user_data::>>().unwrap(); + let parent_mutex = parent.as_ref().user_data::>>().unwrap(); let mut parent_guard = parent_mutex.lock().unwrap(); parent_guard.children.push(child.clone()) } @@ -213,7 +209,7 @@ impl + 'static> SurfaceData pub fn unset_parent(child: &WlSurface) { debug_assert!(child.as_ref().is_alive()); let old_parent = { - let child_mutex = child.as_ref().user_data::>>().unwrap(); + let child_mutex = child.as_ref().user_data::>>().unwrap(); let mut child_guard = child_mutex.lock().unwrap(); let old_parent = child_guard.parent.take(); if old_parent.is_some() { @@ -225,10 +221,7 @@ impl + 'static> SurfaceData }; // unregister from our parent if let Some(old_parent) = old_parent { - let parent_mutex = old_parent - .as_ref() - .user_data::>>() - .unwrap(); + let parent_mutex = old_parent.as_ref().user_data::>>().unwrap(); let mut parent_guard = parent_mutex.lock().unwrap(); parent_guard .children @@ -238,14 +231,14 @@ impl + 'static> SurfaceData /// Retrieve the parent surface (if any) of this surface pub fn get_parent(child: &WlSurface) -> Option { - let child_mutex = child.as_ref().user_data::>>().unwrap(); + let child_mutex = child.as_ref().user_data::>>().unwrap(); let child_guard = child_mutex.lock().unwrap(); child_guard.parent.as_ref().cloned() } /// Retrieve the children surface (if any) of this surface pub fn get_children(parent: &WlSurface) -> Vec { - let parent_mutex = parent.as_ref().user_data::>>().unwrap(); + let parent_mutex = parent.as_ref().user_data::>>().unwrap(); let parent_guard = parent_mutex.lock().unwrap(); parent_guard .children @@ -260,7 +253,7 @@ impl + 'static> SurfaceData /// Fails if `relative_to` is not a sibling or parent of `surface`. pub fn reorder(surface: &WlSurface, to: Location, relative_to: &WlSurface) -> Result<(), ()> { let parent = { - let data_mutex = surface.as_ref().user_data::>>().unwrap(); + let data_mutex = surface.as_ref().user_data::>>().unwrap(); let data_guard = data_mutex.lock().unwrap(); data_guard.parent.as_ref().cloned().unwrap() }; @@ -274,7 +267,7 @@ impl + 'static> SurfaceData None } - let parent_mutex = parent.as_ref().user_data::>>().unwrap(); + let parent_mutex = parent.as_ref().user_data::>>().unwrap(); let mut parent_guard = parent_mutex.lock().unwrap(); let my_index = index_of(surface, &parent_guard.children).unwrap(); let mut other_index = match index_of(relative_to, &parent_guard.children) { @@ -294,18 +287,18 @@ impl + 'static> SurfaceData } } -impl SurfaceData { +impl SurfaceData { /// Access the attributes associated with a surface /// /// Note that an internal lock is taken during access of this data, /// so the tree cannot be manipulated at the same time pub fn with_data(surface: &WlSurface, f: F) -> T where - F: FnOnce(&mut SurfaceAttributes) -> T, + F: FnOnce(&mut SurfaceAttributes) -> T, { let data_mutex = surface .as_ref() - .user_data::>>() + .user_data::>>() .expect("Accessing the data of foreign surfaces is not supported."); let mut data_guard = data_mutex.lock().unwrap(); f(&mut data_guard.attributes) @@ -332,9 +325,9 @@ impl SurfaceData { mut post_filter: F3, reverse: bool, ) where - F1: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> TraversalAction, - F2: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T), - F3: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> bool, + F1: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> TraversalAction, + F2: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T), + F3: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> bool, { Self::map( surface, @@ -356,11 +349,11 @@ impl SurfaceData { reverse: bool, ) -> bool where - F1: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> TraversalAction, - F2: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T), - F3: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> bool, + F1: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> TraversalAction, + F2: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T), + F3: FnMut(&WlSurface, &mut SurfaceAttributes, &mut R, &T) -> bool, { - let data_mutex = surface.as_ref().user_data::>>().unwrap(); + let data_mutex = surface.as_ref().user_data::>>().unwrap(); let mut data_guard = data_mutex.lock().unwrap(); let data_guard = &mut *data_guard; // call the filter on ourselves diff --git a/src/wayland/data_device/dnd_grab.rs b/src/wayland/data_device/dnd_grab.rs index b98bbdb..7977e20 100644 --- a/src/wayland/data_device/dnd_grab.rs +++ b/src/wayland/data_device/dnd_grab.rs @@ -13,7 +13,7 @@ use crate::wayland::{ use super::{with_source_metadata, DataDeviceData, DnDIconRole, SeatData}; -pub(crate) struct DnDGrab { +pub(crate) struct DnDGrab { data_source: Option, current_focus: Option, pending_offers: Vec, @@ -21,19 +21,19 @@ pub(crate) struct DnDGrab { icon: Option, origin: wl_surface::WlSurface, callback: Rc>, - token: CompositorToken, + token: CompositorToken, seat: Seat, } -impl + 'static> DnDGrab { +impl + 'static> DnDGrab { pub(crate) fn new( source: Option, origin: wl_surface::WlSurface, seat: Seat, icon: Option, - token: CompositorToken, + token: CompositorToken, callback: Rc>, - ) -> DnDGrab { + ) -> DnDGrab { DnDGrab { data_source: source, current_focus: None, @@ -48,7 +48,7 @@ impl + 'static> DnDGrab { } } -impl + 'static> PointerGrab for DnDGrab { +impl + 'static> PointerGrab for DnDGrab { fn motion( &mut self, _handle: &mut PointerInnerHandle<'_>, diff --git a/src/wayland/data_device/mod.rs b/src/wayland/data_device/mod.rs index c24cef1..0255f65 100644 --- a/src/wayland/data_device/mod.rs +++ b/src/wayland/data_device/mod.rs @@ -43,7 +43,7 @@ //! # fn main(){ //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut display = wayland_server::Display::new(event_loop.handle()); -//! # let (compositor_token, _, _) = compositor_init::<(), Roles, _, _>(&mut display, |_, _, _| {}, None); +//! # let (compositor_token, _, _) = compositor_init::(&mut display, |_, _, _| {}, None); //! // init the data device: //! init_data_device( //! &mut display, // the display @@ -286,18 +286,17 @@ impl SeatData { /// and the second argument is the preferred action reported by the target. If no action should be /// chosen (and thus the drag'n'drop should abort on drop), return /// [`DndAction::empty()`](wayland_server::protocol::wl_data_device_manager::DndAction::empty). -pub fn init_data_device( +pub fn init_data_device( display: &mut Display, callback: C, action_choice: F, - token: CompositorToken, + token: CompositorToken, logger: L, ) -> Global where F: FnMut(DndAction, DndAction) -> DndAction + 'static, C: FnMut(DataDeviceEvent) + 'static, R: Role + 'static, - U: 'static, L: Into>, { let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "data_device_mgr")); @@ -378,18 +377,17 @@ where } } -fn implement_ddm( +fn implement_ddm( new_ddm: NewResource, callback: Rc>, action_choice: Rc>, - token: CompositorToken, + token: CompositorToken, log: ::slog::Logger, ) -> wl_data_device_manager::WlDataDeviceManager where F: FnMut(DndAction, DndAction) -> DndAction + 'static, C: FnMut(DataDeviceEvent) + 'static, R: Role + 'static, - U: 'static, { use self::wl_data_device_manager::Request; new_ddm.implement_closure( @@ -429,19 +427,18 @@ struct DataDeviceData { action_choice: Rc DndAction + 'static>>, } -fn implement_data_device( +fn implement_data_device( new_dd: NewResource, seat: Seat, callback: Rc>, action_choice: Rc>, - token: CompositorToken, + token: CompositorToken, log: ::slog::Logger, ) -> wl_data_device::WlDataDevice where F: FnMut(DndAction, DndAction) -> DndAction + 'static, C: FnMut(DataDeviceEvent) + 'static, R: Role + 'static, - U: 'static, { use self::wl_data_device::Request; let dd_data = DataDeviceData { diff --git a/src/wayland/seat/mod.rs b/src/wayland/seat/mod.rs index d0f925d..baa1c26 100644 --- a/src/wayland/seat/mod.rs +++ b/src/wayland/seat/mod.rs @@ -20,7 +20,7 @@ //! # fn main(){ //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut display = wayland_server::Display::new(event_loop.handle()); -//! # let (compositor_token, _, _) = compositor_init::<(), Roles, _, _>(&mut display, |_, _, _| {}, None); +//! # let (compositor_token, _, _) = compositor_init::(&mut display, |_, _, _| {}, None); //! // insert the seat: //! let (seat, seat_global) = Seat::new( //! &mut display, // the display @@ -121,14 +121,13 @@ impl Seat { /// You are provided with the state token to retrieve it (allowing /// you to add or remove capabilities from it), and the global handle, /// in case you want to remove it. - pub fn new( + pub fn new( display: &mut Display, name: String, - token: CompositorToken, + token: CompositorToken, logger: L, ) -> (Seat, Global) where - U: 'static, R: Role + 'static, L: Into>, { @@ -194,7 +193,7 @@ impl Seat { /// # fn main(){ /// # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); /// # let mut display = wayland_server::Display::new(event_loop.handle()); - /// # let (compositor_token, _, _) = compositor_init::<(), Roles, _, _>(&mut display, |_, _, _| {}, None); + /// # let (compositor_token, _, _) = compositor_init::(&mut display, |_, _, _| {}, None); /// # let (mut seat, seat_global) = Seat::new( /// # &mut display, /// # "seat-0".into(), @@ -207,9 +206,8 @@ impl Seat { /// ); /// # } /// ``` - pub fn add_pointer(&mut self, token: CompositorToken, cb: F) -> PointerHandle + pub fn add_pointer(&mut self, token: CompositorToken, cb: F) -> PointerHandle where - U: 'static, R: Role + 'static, F: FnMut(CursorImageStatus) + 'static, { @@ -336,14 +334,13 @@ impl ::std::cmp::PartialEq for Seat { } } -fn implement_seat( +fn implement_seat( new_seat: NewResource, arc: Rc, - token: CompositorToken, + token: CompositorToken, ) -> wl_seat::WlSeat where R: Role + 'static, - U: 'static, { let dest_arc = arc.clone(); new_seat.implement_closure( diff --git a/src/wayland/seat/pointer.rs b/src/wayland/seat/pointer.rs index 2e0fc4f..a16c694 100644 --- a/src/wayland/seat/pointer.rs +++ b/src/wayland/seat/pointer.rs @@ -46,9 +46,8 @@ struct PointerInternal { } impl PointerInternal { - fn new(token: CompositorToken, mut cb: F) -> PointerInternal + fn new(token: CompositorToken, mut cb: F) -> PointerInternal where - U: 'static, R: Role + 'static, F: FnMut(CursorImageStatus) + 'static, { @@ -514,10 +513,9 @@ impl AxisFrame { } } -pub(crate) fn create_pointer_handler(token: CompositorToken, cb: F) -> PointerHandle +pub(crate) fn create_pointer_handler(token: CompositorToken, cb: F) -> PointerHandle where R: Role + 'static, - U: 'static, F: FnMut(CursorImageStatus) + 'static, { PointerHandle { @@ -525,14 +523,13 @@ where } } -pub(crate) fn implement_pointer( +pub(crate) fn implement_pointer( new_pointer: NewResource, handle: Option<&PointerHandle>, - token: CompositorToken, + token: CompositorToken, ) -> WlPointer where R: Role + 'static, - U: 'static, { let inner = handle.map(|h| h.inner.clone()); let destructor = match inner.clone() { diff --git a/src/wayland/shell/legacy/mod.rs b/src/wayland/shell/legacy/mod.rs index 94ddbd2..11128ec 100644 --- a/src/wayland/shell/legacy/mod.rs +++ b/src/wayland/shell/legacy/mod.rs @@ -52,7 +52,7 @@ //! # fn main() { //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut display = wayland_server::Display::new(event_loop.handle()); -//! # let (compositor_token, _, _) = smithay::wayland::compositor::compositor_init::<(), MyRoles, _, _>( +//! # let (compositor_token, _, _) = smithay::wayland::compositor::compositor_init::( //! # &mut display, //! # |_, _, _| {}, //! # None @@ -62,7 +62,7 @@ //! // token from the compositor implementation //! compositor_token, //! // your implementation -//! |event: ShellRequest<_, _, MyShellSurfaceData>| { /* ... */ }, +//! |event: ShellRequest<_, MyShellSurfaceData>| { /* ... */ }, //! None // put a logger if you want //! ); //! @@ -97,16 +97,15 @@ pub struct ShellSurfaceRole { } /// 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, + token: CompositorToken, _d: ::std::marker::PhantomData, } -impl ShellSurface +impl ShellSurface where - U: 'static, R: Role> + 'static, D: 'static, { @@ -235,13 +234,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 /// @@ -249,14 +248,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 @@ -267,7 +266,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 @@ -278,7 +277,7 @@ pub enum ShellRequest { /// The surface changed its kind SetKind { /// The surface - surface: ShellSurface, + surface: ShellSurface, /// Its new kind kind: ShellSurfaceKind, }, @@ -288,13 +287,12 @@ 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 - U: 'static, R: Role> + 'static, D: 'static, { @@ -304,24 +302,23 @@ 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, + ctoken: CompositorToken, implementation: Impl, logger: L, -) -> (Arc>>, Global) +) -> (Arc>>, Global) where - U: 'static, D: Default + '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 1cebb7d..d60752f 100644 --- a/src/wayland/shell/legacy/wl_handlers.rs +++ b/src/wayland/shell/legacy/wl_handlers.rs @@ -13,16 +13,15 @@ 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, + ctoken: CompositorToken, implementation: Rc>, - state: Arc>>, + state: Arc>>, ) where - U: 'static, D: Default + 'static, R: Role> + 'static, - Impl: FnMut(ShellRequest) + 'static, + Impl: FnMut(ShellRequest) + 'static, { shell.implement_closure( move |req, shell| { @@ -59,18 +58,17 @@ pub(crate) fn implement_shell( ); } -fn make_handle( +fn make_handle( shell_surface: &wl_shell_surface::WlShellSurface, - token: CompositorToken, -) -> ShellSurface + token: CompositorToken, +) -> ShellSurface where - U: 'static, R: Role> + 'static, SD: 'static, { let data = shell_surface .as_ref() - .user_data::>() + .user_data::>() .unwrap(); ShellSurface { wl_surface: data.surface.clone(), @@ -80,30 +78,29 @@ where } } -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>>, + ctoken: CompositorToken, + state: Arc>>, ) -> wl_shell_surface::WlShellSurface where - U: 'static, SD: 'static, R: Role> + 'static, - Impl: FnMut(ShellRequest) + '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 { @@ -196,7 +193,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(); }), diff --git a/src/wayland/shell/xdg/mod.rs b/src/wayland/shell/xdg/mod.rs index 1e9fd8d..bf33910 100644 --- a/src/wayland/shell/xdg/mod.rs +++ b/src/wayland/shell/xdg/mod.rs @@ -35,7 +35,6 @@ //! use smithay::wayland::shell::xdg::{xdg_shell_init, XdgSurfaceRole, XdgRequest}; //! use wayland_protocols::unstable::xdg_shell::v6::server::zxdg_shell_v6::ZxdgShellV6; //! # use wayland_server::protocol::{wl_seat, wl_output}; -//! # #[derive(Default)] struct MySurfaceData; //! //! // define the roles type. You need to integrate the XdgSurface role: //! define_roles!(MyRoles => @@ -51,7 +50,7 @@ //! # fn main() { //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut display = wayland_server::Display::new(event_loop.handle()); -//! # let (compositor_token, _, _) = smithay::wayland::compositor::compositor_init::<(), MyRoles, _, _>( +//! # let (compositor_token, _, _) = smithay::wayland::compositor::compositor_init::( //! # &mut display, //! # |_, _, _| {}, //! # None @@ -61,7 +60,7 @@ //! // token from the compositor implementation //! compositor_token, //! // your implementation -//! |event: XdgRequest<_, _, MyShellData>| { /* ... */ }, +//! |event: XdgRequest<_, MyShellData>| { /* ... */ }, //! None // put a logger if you want //! ); //! @@ -259,14 +258,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>>, + compositor_token: CompositorToken, + user_impl: Rc)>>, + shell_state: Arc>>, } -impl Clone for ShellData { +impl Clone for ShellData { fn clone(&self) -> Self { ShellData { log: self.log.clone(), @@ -278,22 +277,21 @@ 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, + ctoken: CompositorToken, implementation: Impl, logger: L, ) -> ( - Arc>>, + Arc>>, Global, Global, ) where - U: 'static, 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 { @@ -325,24 +323,23 @@ 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 - U: 'static, 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[..] } } @@ -378,15 +375,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, + _token: CompositorToken, _data: ::std::marker::PhantomData<*mut SD>, } -impl ShellClient +impl ShellClient where - U: 'static, R: Role + 'static, SD: 'static, { @@ -427,7 +423,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 { @@ -439,7 +435,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 { @@ -464,7 +460,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)) @@ -472,7 +468,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)) @@ -487,16 +483,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, + token: CompositorToken, _shell_data: ::std::marker::PhantomData, } -impl ToplevelSurface +impl ToplevelSurface where - U: 'static, R: Role + 'static, SD: 'static, { @@ -517,7 +512,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; } @@ -526,14 +521,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()) } @@ -554,8 +549,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), } } @@ -580,7 +575,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, @@ -590,7 +585,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, @@ -647,16 +642,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, + token: CompositorToken, _shell_data: ::std::marker::PhantomData, } -impl PopupSurface +impl PopupSurface where - U: 'static, R: Role + 'static, SD: 'static, { @@ -677,7 +671,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; } @@ -686,14 +680,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()) } @@ -715,10 +709,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); } } } @@ -744,7 +738,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, @@ -754,7 +748,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, @@ -843,11 +837,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 /// @@ -855,7 +849,7 @@ pub enum XdgRequest { /// from the pending ping. ClientPong { /// the client - client: ShellClient, + client: ShellClient, }, /// A new toplevel surface was created /// @@ -863,7 +857,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 /// @@ -871,12 +865,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 @@ -885,7 +879,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 @@ -899,7 +893,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 @@ -908,29 +902,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 /// @@ -938,7 +932,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 252a5d4..7b47503 100644 --- a/src/wayland/shell/xdg/xdg_handlers.rs +++ b/src/wayland/shell/xdg/xdg_handlers.rs @@ -14,17 +14,16 @@ 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 - U: 'static, R: Role + 'static, SD: Default + 'static, { let shell = shell.implement_closure( - wm_implementation::, + wm_implementation::, None::, ShellUserData { shell_data: shell_data.clone(), @@ -42,15 +41,15 @@ where * xdg_shell */ -pub(crate) struct ShellUserData { - shell_data: ShellData, +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 { + token: CompositorToken, +) -> ShellClient { ShellClient { kind: super::ShellClientKind::Xdg(resource.clone()), _token: token, @@ -58,13 +57,12 @@ pub(crate) fn make_shell_client( } } -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 - U: 'static, 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 @@ -92,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, @@ -188,22 +186,18 @@ 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 - U: 'static, 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 @@ -225,15 +219,14 @@ 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 - U: 'static, R: Role + 'static, SD: 'static, { let data = xdg_surface .as_ref() - .user_data::>() + .user_data::>() .unwrap(); match request { xdg_surface::Request::Destroy => { @@ -253,8 +246,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(), @@ -285,10 +278,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 @@ -301,8 +291,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(), @@ -360,27 +350,26 @@ 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, +fn with_surface_toplevel_data( + shell_data: &ShellData, toplevel: &xdg_toplevel::XdgToplevel, f: F, ) where - U: 'static, R: Role + 'static, SD: 'static, F: FnOnce(&mut ToplevelState), { let toplevel_data = toplevel .as_ref() - .user_data::>() + .user_data::>() .unwrap(); shell_data .compositor_token @@ -391,15 +380,14 @@ 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 - U: 'static, R: Role + 'static, SD: 'static, { let data = resource .as_ref() - .user_data::>() + .user_data::>() .unwrap(); let (width, height) = configure.size.unwrap_or((0, 0)); // convert the Vec (which is really a Vec) into Vec @@ -421,12 +409,12 @@ where .expect("xdg_toplevel exists but surface has not shell_surface role?!"); } -fn make_toplevel_handle( +fn make_toplevel_handle( resource: &xdg_toplevel::XdgToplevel, -) -> super::ToplevelSurface { +) -> super::ToplevelSurface { let data = resource .as_ref() - .user_data::>() + .user_data::>() .unwrap(); super::ToplevelSurface { wl_surface: data.wl_surface.clone(), @@ -436,15 +424,14 @@ fn make_toplevel_handle( } } -fn toplevel_implementation(request: xdg_toplevel::Request, toplevel: xdg_toplevel::XdgToplevel) +fn toplevel_implementation(request: xdg_toplevel::Request, toplevel: xdg_toplevel::XdgToplevel) where - U: 'static, R: Role + 'static, SD: 'static, { let data = toplevel .as_ref() - .user_data::>() + .user_data::>() .unwrap(); match request { xdg_toplevel::Request::Destroy => { @@ -455,7 +442,7 @@ where toplevel_data.parent = parent.map(|toplevel_surface_parent| { toplevel_surface_parent .as_ref() - .user_data::>() + .user_data::>() .unwrap() .wl_surface .clone() @@ -544,15 +531,14 @@ where } } -fn destroy_toplevel(toplevel: xdg_toplevel::XdgToplevel) +fn destroy_toplevel(toplevel: xdg_toplevel::XdgToplevel) where - U: 'static, R: Role + 'static, SD: 'static, { let data = toplevel .as_ref() - .user_data::>() + .user_data::>() .unwrap(); if !data.wl_surface.as_ref().is_alive() { // the wl_surface is destroyed, this means the client is not @@ -580,15 +566,14 @@ 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 - U: 'static, R: Role + 'static, SD: 'static, { let data = resource .as_ref() - .user_data::>() + .user_data::>() .unwrap(); let (x, y) = configure.position; let (width, height) = configure.size; @@ -602,12 +587,10 @@ where .expect("xdg_toplevel exists but surface has not shell_surface role?!"); } -fn make_popup_handle( - resource: &xdg_popup::XdgPopup, -) -> super::PopupSurface { +fn make_popup_handle(resource: &xdg_popup::XdgPopup) -> super::PopupSurface { let data = resource .as_ref() - .user_data::>() + .user_data::>() .unwrap(); super::PopupSurface { wl_surface: data.wl_surface.clone(), @@ -617,16 +600,12 @@ fn make_popup_handle( } } -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 - U: 'static, 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 @@ -644,16 +623,12 @@ where } } -fn destroy_popup(popup: xdg_popup::XdgPopup) +fn destroy_popup(popup: xdg_popup::XdgPopup) where - U: 'static, 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 0492065..74ee194 100644 --- a/src/wayland/shell/xdg/zxdgv6_handlers.rs +++ b/src/wayland/shell/xdg/zxdgv6_handlers.rs @@ -17,17 +17,16 @@ 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 - U: 'static, R: Role + 'static, SD: Default + 'static, { let shell = shell.implement_closure( - shell_implementation::, + shell_implementation::, None::, ShellUserData { shell_data: shell_data.clone(), @@ -45,15 +44,15 @@ where * xdg_shell */ -pub(crate) struct ShellUserData { - shell_data: ShellData, +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 { + token: CompositorToken, +) -> ShellClient { ShellClient { kind: super::ShellClientKind::ZxdgV6(resource.clone()), _token: token, @@ -61,13 +60,12 @@ pub(crate) fn make_shell_client( } } -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 - U: 'static, 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 @@ -95,8 +93,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(), @@ -205,22 +203,18 @@ 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 - U: 'static, 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 @@ -242,17 +236,16 @@ 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 - U: 'static, R: Role + 'static, SD: 'static, { let data = xdg_surface .as_ref() - .user_data::>() + .user_data::>() .unwrap(); match request { zxdg_surface_v6::Request::Destroy => { @@ -272,8 +265,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(), @@ -303,10 +296,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| { @@ -317,8 +307,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(), @@ -376,24 +366,23 @@ 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 - U: 'static, R: Role + 'static, SD: 'static, F: FnOnce(&mut ToplevelState), { let data = toplevel .as_ref() - .user_data::>() + .user_data::>() .unwrap(); data.shell_data .compositor_token @@ -404,17 +393,16 @@ where .expect("xdg_toplevel exists but surface has not shell_surface role?!"); } -pub fn send_toplevel_configure( +pub fn send_toplevel_configure( resource: &zxdg_toplevel_v6::ZxdgToplevelV6, configure: ToplevelConfigure, ) where - U: 'static, R: Role + 'static, SD: 'static, { let data = resource .as_ref() - .user_data::>() + .user_data::>() .unwrap(); let (width, height) = configure.size.unwrap_or((0, 0)); // convert the Vec (which is really a Vec) into Vec @@ -436,12 +424,12 @@ 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 { +) -> super::ToplevelSurface { let data = resource .as_ref() - .user_data::>() + .user_data::>() .unwrap(); super::ToplevelSurface { wl_surface: data.wl_surface.clone(), @@ -451,40 +439,39 @@ fn make_toplevel_handle( } } -fn toplevel_implementation( +fn toplevel_implementation( request: zxdg_toplevel_v6::Request, toplevel: zxdg_toplevel_v6::ZxdgToplevelV6, ) where - U: 'static, R: Role + 'static, SD: 'static, { let data = toplevel .as_ref() - .user_data::>() + .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; }); } @@ -520,12 +507,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); }); } @@ -561,15 +548,14 @@ fn toplevel_implementation( } } -fn destroy_toplevel(toplevel: zxdg_toplevel_v6::ZxdgToplevelV6) +fn destroy_toplevel(toplevel: zxdg_toplevel_v6::ZxdgToplevelV6) where - U: 'static, R: Role + 'static, SD: 'static, { let data = toplevel .as_ref() - .user_data::>() + .user_data::>() .unwrap(); if !data.wl_surface.as_ref().is_alive() { // the wl_surface is destroyed, this means the client is not @@ -597,15 +583,14 @@ 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 - U: 'static, R: Role + 'static, SD: 'static, { let data = resource .as_ref() - .user_data::>() + .user_data::>() .unwrap(); let (x, y) = configure.position; let (width, height) = configure.size; @@ -619,12 +604,12 @@ where .expect("xdg_toplevel exists but surface has not shell_surface role?!"); } -fn make_popup_handle( +fn make_popup_handle( resource: &zxdg_popup_v6::ZxdgPopupV6, -) -> super::PopupSurface { +) -> super::PopupSurface { let data = resource .as_ref() - .user_data::>() + .user_data::>() .unwrap(); super::PopupSurface { wl_surface: data.wl_surface.clone(), @@ -634,16 +619,12 @@ fn make_popup_handle( } } -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 - U: 'static, 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 @@ -661,16 +642,12 @@ where } } -fn destroy_popup(popup: zxdg_popup_v6::ZxdgPopupV6) +fn destroy_popup(popup: zxdg_popup_v6::ZxdgPopupV6) where - U: 'static, 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