From 0140de89fb9fd0cc671ba045bc1bc86e68a48fac Mon Sep 17 00:00:00 2001 From: nycex Date: Wed, 1 Jan 2020 11:43:16 +0100 Subject: [PATCH] fix some clippy warnings (#147) This commit removes some clippy warnings (to advance #45) by doing the following: - replace usage of `mem::uninitialized()` with `MaybeUninit` - replace usage of `nix::libc::{uint64_t, int32_t}` with `{u64, i32}` - replace functions inside of `Option::ok_or` with `Option::ok_or_else` - replace functions inside of `Result::unwrap_or` with `Result::unwrap_or_else` - replace occurrences of pass-by-reference with pass-by-value when appropriate - replace unused variables in pattern-matching with wildcards - replace `match` expressions that have only one case with `if let` expressions - replace UpperCamelCase names of consts with SCREAMING_SNAKE_CASE - remove `clone()` on types that implement Copy - remove redundant imports - remove `fn main()` from doctests - remove let binding for variables that are returned afterwards --- anvil/build.rs | 2 +- anvil/src/input_handler.rs | 16 +++++----- anvil/src/main.rs | 2 +- anvil/src/shell.rs | 2 +- anvil/src/udev.rs | 4 +-- anvil/src/window_map.rs | 4 +-- anvil/src/winit.rs | 4 +-- src/backend/drm/legacy/surface.rs | 16 +++++----- src/backend/egl/context.rs | 34 +++++++++++++++------ src/backend/egl/ffi.rs | 18 +++++------ src/backend/egl/native.rs | 6 ++-- src/backend/graphics/errors.rs | 1 - src/backend/input.rs | 8 ++--- src/backend/libinput.rs | 10 +++--- src/backend/session/direct.rs | 2 -- src/backend/udev.rs | 4 +-- src/backend/winit.rs | 12 ++++---- src/wayland/compositor/mod.rs | 26 ++++++++-------- src/wayland/compositor/roles.rs | 5 +-- src/wayland/data_device/dnd_grab.rs | 6 ++-- src/wayland/data_device/mod.rs | 26 +++++++--------- src/wayland/data_device/server_dnd_grab.rs | 2 +- src/wayland/dmabuf/mod.rs | 13 +++----- src/wayland/explicit_synchronization/mod.rs | 11 ++++--- src/wayland/output/mod.rs | 2 -- src/wayland/seat/mod.rs | 8 ++--- src/wayland/seat/pointer.rs | 2 +- src/wayland/shell/legacy/mod.rs | 2 -- src/wayland/shell/xdg/mod.rs | 2 -- src/wayland/shm/mod.rs | 3 -- 30 files changed, 118 insertions(+), 135 deletions(-) diff --git a/anvil/build.rs b/anvil/build.rs index 5270b19..5cafce0 100644 --- a/anvil/build.rs +++ b/anvil/build.rs @@ -1,7 +1,7 @@ use std::env::var; fn main() { - if !var("CARGO_FEATURE_LOGIND").ok().is_some() { + if var("CARGO_FEATURE_LOGIND").ok().is_none() { println!("cargo:warning=You are compiling anvil without logind support."); println!("cargo:warning=This means that you'll likely need to run it as root if you want to launch it from a tty."); println!("cargo:warning=To enable logind support add `--feature logind` to your cargo invocation:"); diff --git a/anvil/src/input_handler.rs b/anvil/src/input_handler.rs index 78a8172..1e87c64 100644 --- a/anvil/src/input_handler.rs +++ b/anvil/src/input_handler.rs @@ -113,7 +113,7 @@ impl InputHandler for AnvilInputHandler { "mods" => format!("{:?}", modifiers), "keysym" => ::xkbcommon::xkb::keysym_get_name(keysym) ); - action = process_keyboard_shortcut(modifiers, keysym); + action = process_keyboard_shortcut(*modifiers, keysym); // forward to client only if action == KeyAction::Forward // both for pressed and released, to avoid inconsistencies if let KeyAction::Forward = action { @@ -229,13 +229,13 @@ impl InputHandler for AnvilInputHandler { input::AxisSource::Wheel | input::AxisSource::WheelTilt => wl_pointer::AxisSource::Wheel, }; let horizontal_amount = evt - .amount(&input::Axis::Horizontal) - .unwrap_or_else(|| evt.amount_discrete(&input::Axis::Horizontal).unwrap() * 3.0); + .amount(input::Axis::Horizontal) + .unwrap_or_else(|| evt.amount_discrete(input::Axis::Horizontal).unwrap() * 3.0); let vertical_amount = evt - .amount(&input::Axis::Vertical) - .unwrap_or_else(|| evt.amount_discrete(&input::Axis::Vertical).unwrap() * 3.0); - let horizontal_amount_discrete = evt.amount_discrete(&input::Axis::Horizontal); - let vertical_amount_discrete = evt.amount_discrete(&input::Axis::Vertical); + .amount(input::Axis::Vertical) + .unwrap_or_else(|| evt.amount_discrete(input::Axis::Vertical).unwrap() * 3.0); + let horizontal_amount_discrete = evt.amount_discrete(input::Axis::Horizontal); + let vertical_amount_discrete = evt.amount_discrete(input::Axis::Vertical); { let mut frame = AxisFrame::new(evt.time()).source(source); @@ -293,7 +293,7 @@ enum KeyAction { None, } -fn process_keyboard_shortcut(modifiers: &ModifiersState, keysym: Keysym) -> KeyAction { +fn process_keyboard_shortcut(modifiers: ModifiersState, keysym: Keysym) -> KeyAction { if modifiers.ctrl && modifiers.alt && keysym == xkb::KEY_BackSpace || modifiers.logo && keysym == xkb::KEY_q { diff --git a/anvil/src/main.rs b/anvil/src/main.rs index a207c17..079802e 100644 --- a/anvil/src/main.rs +++ b/anvil/src/main.rs @@ -22,7 +22,7 @@ mod window_map; #[cfg(feature = "winit")] mod winit; -static POSSIBLE_BACKENDS: &'static [&'static str] = &[ +static POSSIBLE_BACKENDS: &[&str] = &[ #[cfg(feature = "winit")] "--winit : Run anvil as a X11 or Wayland client using winit.", #[cfg(feature = "udev")] diff --git a/anvil/src/shell.rs b/anvil/src/shell.rs index ed13150..8e26fd9 100644 --- a/anvil/src/shell.rs +++ b/anvil/src/shell.rs @@ -137,7 +137,7 @@ pub struct SurfaceData { 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()); + attributes.user_data.insert_if_missing(SurfaceData::default); match attributes.buffer.take() { Some(Some((buffer, (_x, _y)))) => { // new contents diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index fdfdebf..24ddb21 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -156,7 +156,7 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop<()>, log: Logger _ => {} }, default_action_chooser, - compositor_token.clone(), + compositor_token, log.clone(), ); @@ -166,7 +166,7 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop<()>, log: Logger let (mut w_seat, _) = Seat::new( &mut display.borrow_mut(), session.seat(), - compositor_token.clone(), + compositor_token, log.clone(), ); diff --git a/anvil/src/window_map.rs b/anvil/src/window_map.rs index dc4b8fe..401c2e4 100644 --- a/anvil/src/window_map.rs +++ b/anvil/src/window_map.rs @@ -61,7 +61,7 @@ where // need to check more carefully let found = RefCell::new(None); if let Some(wl_surface) = self.toplevel.get_surface() { - let _ = ctoken.with_surface_tree_downward( + ctoken.with_surface_tree_downward( wl_surface, self.location, |wl_surface, attributes, role, &(mut x, mut y)| { @@ -102,7 +102,7 @@ where 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); if let Some(wl_surface) = self.toplevel.get_surface() { - let _ = ctoken.with_surface_tree_downward( + ctoken.with_surface_tree_downward( wl_surface, (base_x, base_y), |_, attributes, role, &(mut x, mut y)| { diff --git a/anvil/src/winit.rs b/anvil/src/winit.rs index 3be41e5..48ceb7e 100644 --- a/anvil/src/winit.rs +++ b/anvil/src/winit.rs @@ -75,11 +75,11 @@ pub fn run_winit(display: &mut Display, event_loop: &mut EventLoop<()>, log: Log _ => {} }, default_action_chooser, - compositor_token.clone(), + compositor_token, log.clone(), ); - let (mut seat, _) = Seat::new(display, "winit".into(), compositor_token.clone(), log.clone()); + let (mut seat, _) = Seat::new(display, "winit".into(), compositor_token, log.clone()); let cursor_status = Arc::new(Mutex::new(CursorImageStatus::Default)); diff --git a/src/backend/drm/legacy/surface.rs b/src/backend/drm/legacy/surface.rs index b6ee4ab..51fd63d 100644 --- a/src/backend/drm/legacy/surface.rs +++ b/src/backend/drm/legacy/surface.rs @@ -78,11 +78,11 @@ impl Surface for LegacyDrmSurfaceInternal { } fn current_mode(&self) -> Option { - self.state.read().unwrap().mode.clone() + self.state.read().unwrap().mode } fn pending_mode(&self) -> Option { - self.pending.read().unwrap().mode.clone() + self.pending.read().unwrap().mode } fn add_connector(&self, connector: connector::Handle) -> Result<()> { @@ -135,13 +135,11 @@ impl Surface for LegacyDrmSurfaceInternal { // check the connectors to see if this mode is supported if let Some(mode) = mode { for connector in &pending.connectors { - if !connector::Info::load_from_device(self, *connector) - .chain_err(|| { - ErrorKind::DrmDev(format!("Error loading connector info on {:?}", self.dev_path())) - })? - .modes() - .contains(&mode) - { + let info = connector::Info::load_from_device(self, *connector).chain_err(|| { + ErrorKind::DrmDev(format!("Error loading connector info on {:?}", self.dev_path())) + })?; + + if !info.modes().contains(&mode) { bail!(ErrorKind::ModeNotSuitable(mode)); } } diff --git a/src/backend/egl/context.rs b/src/backend/egl/context.rs index ba44c55..cf527e7 100644 --- a/src/backend/egl/context.rs +++ b/src/backend/egl/context.rs @@ -8,7 +8,8 @@ use std::{ cell::{Ref, RefCell, RefMut}, ffi::{CStr, CString}, marker::PhantomData, - mem, ptr, + mem::MaybeUninit, + ptr, rc::Rc, }; @@ -149,12 +150,14 @@ impl> EGLContext { } let egl_version = { - let mut major: ffi::egl::types::EGLint = mem::uninitialized(); - let mut minor: ffi::egl::types::EGLint = mem::uninitialized(); + let mut major: MaybeUninit = MaybeUninit::uninit(); + let mut minor: MaybeUninit = MaybeUninit::uninit(); - if ffi::egl::Initialize(display, &mut major, &mut minor) == 0 { + if ffi::egl::Initialize(display, major.as_mut_ptr(), minor.as_mut_ptr()) == 0 { bail!(ErrorKind::InitFailed); } + let major = major.assume_init(); + let minor = minor.assume_init(); info!(log, "EGL Initialized"); info!(log, "EGL Version: {:?}", (major, minor)); @@ -294,11 +297,22 @@ impl> EGLContext { }; // calling `eglChooseConfig` - let mut config_id = mem::uninitialized(); - let mut num_configs = mem::uninitialized(); - if ffi::egl::ChooseConfig(display, descriptor.as_ptr(), &mut config_id, 1, &mut num_configs) == 0 { + let mut config_id = MaybeUninit::uninit(); + let mut num_configs = MaybeUninit::uninit(); + if ffi::egl::ChooseConfig( + display, + descriptor.as_ptr(), + config_id.as_mut_ptr(), + 1, + num_configs.as_mut_ptr(), + ) == 0 + { bail!(ErrorKind::ConfigFailed); } + + let config_id = config_id.assume_init(); + let num_configs = num_configs.assume_init(); + if num_configs == 0 { error!(log, "No matching color format found"); bail!(ErrorKind::NoAvailablePixelFormat); @@ -307,17 +321,17 @@ impl> EGLContext { // analyzing each config macro_rules! attrib { ($display:expr, $config:expr, $attr:expr) => {{ - let mut value = mem::uninitialized(); + let mut value = MaybeUninit::uninit(); let res = ffi::egl::GetConfigAttrib( $display, $config, $attr as ffi::egl::types::EGLint, - &mut value, + value.as_mut_ptr(), ); if res == 0 { bail!(ErrorKind::ConfigFailed); } - value + value.assume_init() }}; }; diff --git a/src/backend/egl/ffi.rs b/src/backend/egl/ffi.rs index ba18d3a..042ef9f 100644 --- a/src/backend/egl/ffi.rs +++ b/src/backend/egl/ffi.rs @@ -1,11 +1,11 @@ #![allow(missing_docs)] -use nix::libc::{c_long, c_uint, c_void, int32_t, uint64_t}; +use nix::libc::{c_long, c_uint, c_void}; pub type khronos_utime_nanoseconds_t = khronos_uint64_t; -pub type khronos_uint64_t = uint64_t; +pub type khronos_uint64_t = u64; pub type khronos_ssize_t = c_long; -pub type EGLint = int32_t; +pub type EGLint = i32; pub type EGLNativeDisplayType = NativeDisplayType; pub type EGLNativePixmapType = NativePixmapType; pub type EGLNativeWindowType = NativeWindowType; @@ -162,11 +162,11 @@ pub mod egl { // Accepted in the parameter of eglCreateImageKHR: pub const WAYLAND_PLANE_WL: c_uint = 0x31D6; // Possible values for EGL_TEXTURE_FORMAT: - pub const TEXTURE_Y_U_V_WL: int32_t = 0x31D7; - pub const TEXTURE_Y_UV_WL: int32_t = 0x31D8; - pub const TEXTURE_Y_XUXV_WL: int32_t = 0x31D9; - pub const TEXTURE_EXTERNAL_WL: int32_t = 0x31DA; + pub const TEXTURE_Y_U_V_WL: i32 = 0x31D7; + pub const TEXTURE_Y_UV_WL: i32 = 0x31D8; + pub const TEXTURE_Y_XUXV_WL: i32 = 0x31D9; + pub const TEXTURE_EXTERNAL_WL: i32 = 0x31DA; // Accepted in the parameter of eglQueryWaylandBufferWL: - pub const EGL_TEXTURE_FORMAT: int32_t = 0x3080; - pub const WAYLAND_Y_INVERTED_WL: int32_t = 0x31DB; + pub const EGL_TEXTURE_FORMAT: i32 = 0x3080; + pub const WAYLAND_Y_INVERTED_WL: i32 = 0x31DB; } diff --git a/src/backend/egl/native.rs b/src/backend/egl/native.rs index cb13e0a..709aab8 100644 --- a/src/backend/egl/native.rs +++ b/src/backend/egl/native.rs @@ -122,13 +122,13 @@ unsafe impl NativeDisplay for WinitWindow { fn ptr(&self) -> Result { self.get_xlib_display() .map(|ptr| ptr as *const _) - .ok_or(ErrorKind::NonMatchingBackend("X11").into()) + .ok_or_else(|| ErrorKind::NonMatchingBackend("X11").into()) } fn create_surface(&mut self, _args: ()) -> Result { self.get_xlib_window() .map(XlibWindow) - .ok_or(ErrorKind::NonMatchingBackend("X11").into()) + .ok_or_else(|| ErrorKind::NonMatchingBackend("X11").into()) } } @@ -144,7 +144,7 @@ unsafe impl NativeDisplay for WinitWindow { fn ptr(&self) -> Result { self.get_wayland_display() .map(|ptr| ptr as *const _) - .ok_or(ErrorKind::NonMatchingBackend("Wayland").into()) + .ok_or_else(|| ErrorKind::NonMatchingBackend("Wayland").into()) } fn create_surface(&mut self, _args: ()) -> Result { diff --git a/src/backend/graphics/errors.rs b/src/backend/graphics/errors.rs index e0c3b5b..c169d8d 100644 --- a/src/backend/graphics/errors.rs +++ b/src/backend/graphics/errors.rs @@ -23,7 +23,6 @@ pub enum SwapBuffersError { impl fmt::Display for SwapBuffersError { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - use std::error::Error; write!(formatter, "{}", self.description()) } } diff --git a/src/backend/input.rs b/src/backend/input.rs index a9317cb..fd230d1 100644 --- a/src/backend/input.rs +++ b/src/backend/input.rs @@ -215,23 +215,23 @@ pub trait PointerAxisEvent: Event { /// Amount of scrolling in pixels on the given [`Axis`]. /// /// Guaranteed to be `Some` when source returns either [`AxisSource::Finger`] or [`AxisSource::Continuous`]. - fn amount(&self, axis: &Axis) -> Option; + fn amount(&self, axis: Axis) -> Option; /// Amount of scrolling in discrete steps on the given [`Axis`]. /// /// Guaranteed to be `Some` when source returns either [`AxisSource::Wheel`] or [`AxisSource::WheelTilt`]. - fn amount_discrete(&self, axis: &Axis) -> Option; + fn amount_discrete(&self, axis: Axis) -> Option; /// Source of the scroll event. fn source(&self) -> AxisSource; } impl PointerAxisEvent for UnusedEvent { - fn amount(&self, _axis: &Axis) -> Option { + fn amount(&self, _axis: Axis) -> Option { match *self {} } - fn amount_discrete(&self, _axis: &Axis) -> Option { + fn amount_discrete(&self, _axis: Axis) -> Option { match *self {} } diff --git a/src/backend/libinput.rs b/src/backend/libinput.rs index d3f366a..8e7f7db 100644 --- a/src/backend/libinput.rs +++ b/src/backend/libinput.rs @@ -87,12 +87,12 @@ impl<'a> backend::Event for event::pointer::PointerAxisEvent { } impl backend::PointerAxisEvent for event::pointer::PointerAxisEvent { - fn amount(&self, axis: &Axis) -> Option { - Some(self.axis_value((*axis).into())) + fn amount(&self, axis: Axis) -> Option { + Some(self.axis_value(axis.into())) } - fn amount_discrete(&self, axis: &Axis) -> Option { - self.axis_value_discrete((*axis).into()) + fn amount_discrete(&self, axis: Axis) -> Option { + self.axis_value_discrete(axis.into()) } fn source(&self) -> backend::AxisSource { @@ -612,8 +612,6 @@ pub fn libinput_bind( source.set_interest(Ready::readable()); handle.insert_source(source, move |evt, _| { - use crate::backend::input::InputBackend; - let mut backend = evt.source.borrow_mut(); if let Err(error) = backend.0.dispatch_new_events() { warn!(backend.0.logger, "Libinput errored: {}", error); diff --git a/src/backend/session/direct.rs b/src/backend/session/direct.rs index 2e75998..15a243d 100644 --- a/src/backend/session/direct.rs +++ b/src/backend/session/direct.rs @@ -19,9 +19,7 @@ //! //! use smithay::backend::session::direct::DirectSession; //! -//! # fn main() { //! let (session, mut notifier) = DirectSession::new(None, None).unwrap(); -//! # } //! ``` //! //! ### Usage of the session diff --git a/src/backend/udev.rs b/src/backend/udev.rs index 9925d2f..6512044 100644 --- a/src/backend/udev.rs +++ b/src/backend/udev.rs @@ -183,7 +183,7 @@ pub fn primary_gpu>(context: &Context, seat: S) -> UdevResult>(context: &Context, seat: S) -> UdevResult Option { + fn amount(&self, axis: Axis) -> Option { match (axis, self.delta) { - (&Axis::Horizontal, MouseScrollDelta::PixelDelta(delta)) => Some(delta.x), - (&Axis::Vertical, MouseScrollDelta::PixelDelta(delta)) => Some(delta.y), + (Axis::Horizontal, MouseScrollDelta::PixelDelta(delta)) => Some(delta.x), + (Axis::Vertical, MouseScrollDelta::PixelDelta(delta)) => Some(delta.y), (_, MouseScrollDelta::LineDelta(_, _)) => None, } } - fn amount_discrete(&self, axis: &Axis) -> Option { + fn amount_discrete(&self, axis: Axis) -> Option { match (axis, self.delta) { - (&Axis::Horizontal, MouseScrollDelta::LineDelta(x, _)) => Some(x as f64), - (&Axis::Vertical, MouseScrollDelta::LineDelta(_, y)) => Some(y as f64), + (Axis::Horizontal, MouseScrollDelta::LineDelta(x, _)) => Some(x as f64), + (Axis::Vertical, MouseScrollDelta::LineDelta(_, y)) => Some(y as f64), (_, MouseScrollDelta::PixelDelta(_)) => None, } } diff --git a/src/wayland/compositor/mod.rs b/src/wayland/compositor/mod.rs index ddb4818..74a833f 100644 --- a/src/wayland/compositor/mod.rs +++ b/src/wayland/compositor/mod.rs @@ -35,7 +35,6 @@ //! // Declare the roles enum //! define_roles!(MyRoles); //! -//! # fn main() { //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut display = wayland_server::Display::new(event_loop.handle()); //! // Call the init function: @@ -52,7 +51,6 @@ //! // this `token` is what you'll use to access the surface associated data //! //! // You're now ready to go! -//! # } //! ``` //! //! ### Use the surface metadata @@ -260,7 +258,7 @@ impl CompositorToken { /// /// 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 with_surface_data(&self, surface: &WlSurface, f: F) -> T + pub fn with_surface_data(self, surface: &WlSurface, f: F) -> T where F: FnOnce(&mut SurfaceAttributes) -> T, { @@ -299,7 +297,7 @@ where /// If the surface not managed by the `CompositorGlobal` that provided this token, this /// will panic (having more than one compositor is not supported). pub fn with_surface_tree_upward( - &self, + self, surface: &WlSurface, initial: T, filter: F1, @@ -320,7 +318,7 @@ where /// /// This would typically be used to find out which surface of a subsurface tree has been clicked for example. pub fn with_surface_tree_downward( - &self, + self, surface: &WlSurface, initial: T, filter: F1, @@ -340,7 +338,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 { + pub fn get_parent(self, surface: &WlSurface) -> Option { SurfaceData::::get_parent(surface) } @@ -348,7 +346,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_children(&self, surface: &WlSurface) -> Vec { + pub fn get_children(self, surface: &WlSurface) -> Vec { SurfaceData::::get_children(surface) } } @@ -358,7 +356,7 @@ impl CompositorToken { /// /// 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 { + pub fn has_a_role(self, surface: &WlSurface) -> bool { SurfaceData::::has_a_role(surface) } @@ -366,7 +364,7 @@ impl CompositorToken { /// /// 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_role(&self, surface: &WlSurface) -> bool + pub fn has_role(self, surface: &WlSurface) -> bool where R: Role, { @@ -379,7 +377,7 @@ impl CompositorToken { /// /// 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 give_role(&self, surface: &WlSurface) -> Result<(), ()> + pub fn give_role(self, surface: &WlSurface) -> Result<(), ()> where R: Role, RoleData: Default, @@ -393,7 +391,7 @@ impl CompositorToken { /// /// 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 give_role_with(&self, surface: &WlSurface, data: RoleData) -> Result<(), RoleData> + pub fn give_role_with(self, surface: &WlSurface, data: RoleData) -> Result<(), RoleData> where R: Role, { @@ -406,7 +404,7 @@ impl CompositorToken { /// /// 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 with_role_data(&self, surface: &WlSurface, f: F) -> Result + pub fn with_role_data(self, surface: &WlSurface, f: F) -> Result where R: Role, F: FnOnce(&mut RoleData) -> T, @@ -420,7 +418,7 @@ impl CompositorToken { /// /// 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 remove_role(&self, surface: &WlSurface) -> Result + pub fn remove_role(self, surface: &WlSurface) -> Result where R: Role, { @@ -431,7 +429,7 @@ impl CompositorToken { /// /// If the region is not managed by the `CompositorGlobal` that provided this token, this /// will panic (having more than one compositor is not supported). - pub fn get_region_attributes(&self, region: &wl_region::WlRegion) -> RegionAttributes { + pub fn get_region_attributes(self, region: &wl_region::WlRegion) -> RegionAttributes { match region.as_ref().user_data::>() { Some(mutex) => mutex.lock().unwrap().clone(), None => panic!("Accessing the data of foreign regions is not supported."), diff --git a/src/wayland/compositor/roles.rs b/src/wayland/compositor/roles.rs index 736f7cb..aadf5ef 100644 --- a/src/wayland/compositor/roles.rs +++ b/src/wayland/compositor/roles.rs @@ -32,9 +32,7 @@ //! type. You can call it like this: //! //! ``` -//! # #[macro_use] -//! # extern crate smithay; -//! # +//! # use smithay::define_roles; //! // Metadata for a first role //! #[derive(Default)] //! pub struct MyRoleMetadata { @@ -55,7 +53,6 @@ //! /* ... */ //! ); //! -//! # fn main() {} //! ``` //! //! And this will expand to an enum like this: diff --git a/src/wayland/data_device/dnd_grab.rs b/src/wayland/data_device/dnd_grab.rs index d1beb1f..f97fd62 100644 --- a/src/wayland/data_device/dnd_grab.rs +++ b/src/wayland/data_device/dnd_grab.rs @@ -242,7 +242,7 @@ fn implement_dnd_data_offer( move |req, offer| { let mut data = offer_data.borrow_mut(); match req { - Request::Accept { serial: _, mime_type } => { + Request::Accept { mime_type, .. } => { if let Some(mtype) = mime_type { if let Err(()) = with_source_metadata(&source, |meta| { data.accepted = meta.mime_types.contains(&mtype); @@ -304,8 +304,8 @@ fn implement_dnd_data_offer( "Invalid preferred action.".into(), ); } - let source_actions = - with_source_metadata(&source, |meta| meta.dnd_action).unwrap_or(DndAction::empty()); + let source_actions = with_source_metadata(&source, |meta| meta.dnd_action) + .unwrap_or_else(|_| DndAction::empty()); let possible_actions = source_actions & DndAction::from_bits_truncate(dnd_actions); data.chosen_action = (&mut *action_choice.borrow_mut())(possible_actions, preferred_action); diff --git a/src/wayland/data_device/mod.rs b/src/wayland/data_device/mod.rs index a8d2286..74ae600 100644 --- a/src/wayland/data_device/mod.rs +++ b/src/wayland/data_device/mod.rs @@ -40,7 +40,6 @@ //! // to set a surface as a dnd icon //! define_roles!(Roles => [DnDIcon, DnDIconRole]); //! -//! # 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::(&mut display, |_, _, _| {}, None); @@ -53,7 +52,6 @@ //! compositor_token.clone(), // a compositor token //! None // insert a logger here //! ); -//! # } //! ``` use std::cell::RefCell; @@ -179,8 +177,9 @@ impl SeatData { .create_resource::(dd.as_ref().version()) .unwrap() .implement_closure( - move |req, _offer| match req { - wl_data_offer::Request::Receive { fd, mime_type } => { + move |req, _offer| { + // selection data offers only care about the `receive` event + if let wl_data_offer::Request::Receive { fd, mime_type } = req { // check if the source and associated mime type is still valid let valid = with_source_metadata(&source, |meta| { meta.mime_types.contains(&mime_type) @@ -195,7 +194,6 @@ impl SeatData { } let _ = ::nix::unistd::close(fd); } - _ => { /* seleciton data offers only care about the `receive` event */ } }, None::, (), @@ -230,8 +228,9 @@ impl SeatData { .create_resource::(dd.as_ref().version()) .unwrap() .implement_closure( - move |req, _offer| match req { - wl_data_offer::Request::Receive { fd, mime_type } => { + move |req, _offer| { + // selection data offers only care about the `receive` event + if let wl_data_offer::Request::Receive { fd, mime_type } = req { // check if the associated mime type is valid if !offer_meta.mime_types.contains(&mime_type) { // deny the receive @@ -244,7 +243,6 @@ impl SeatData { }); } } - _ => { /* seleciton data offers only care about the `receive` event */ } }, None::, (), @@ -302,7 +300,7 @@ where let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "data_device_mgr")); let action_choice = Rc::new(RefCell::new(action_choice)); let callback = Rc::new(RefCell::new(callback)); - let global = display.create_global(3, move |new_ddm, _version| { + display.create_global(3, move |new_ddm, _version| { implement_ddm( new_ddm, callback.clone(), @@ -310,9 +308,7 @@ where token, log.clone(), ); - }); - - global + }) } /// Set the data device focus to a certain client for a given seat @@ -406,7 +402,7 @@ where seat.clone(), callback.clone(), action_choice.clone(), - token.clone(), + token, log.clone(), ); seat_data.borrow_mut().known_devices.push(data_device); @@ -476,7 +472,7 @@ where origin, seat.clone(), icon, - token.clone(), + token, callback.clone(), ), serial, @@ -486,7 +482,7 @@ where } debug!(log, "denying drag from client without implicit grab"); } - Request::SetSelection { source, serial: _ } => { + Request::SetSelection { source, .. } => { if let Some(keyboard) = seat.get_keyboard() { if dd .as_ref() diff --git a/src/wayland/data_device/server_dnd_grab.rs b/src/wayland/data_device/server_dnd_grab.rs index 3820773..ab79fe4 100644 --- a/src/wayland/data_device/server_dnd_grab.rs +++ b/src/wayland/data_device/server_dnd_grab.rs @@ -236,7 +236,7 @@ where move |req, offer| { let mut data = offer_data.borrow_mut(); match req { - Request::Accept { serial: _, mime_type } => { + Request::Accept { mime_type, .. } => { if let Some(mtype) = mime_type { data.accepted = metadata.mime_types.contains(&mtype); } else { diff --git a/src/wayland/dmabuf/mod.rs b/src/wayland/dmabuf/mod.rs index f79115e..63f1177 100644 --- a/src/wayland/dmabuf/mod.rs +++ b/src/wayland/dmabuf/mod.rs @@ -51,7 +51,6 @@ //! //! // Once this is defined, you can in your setup initialize the dmabuf global: //! -//! # fn main() { //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut display = wayland_server::Display::new(event_loop.handle()); //! // define your supported formats @@ -64,7 +63,6 @@ //! MyDmabufHandler, //! None // we don't provide a logger in this example //! ); -//! # } //! ``` use std::{cell::RefCell, os::unix::io::RawFd, rc::Rc}; @@ -108,11 +106,11 @@ pub struct Plane { bitflags! { pub struct BufferFlags: u32 { /// The buffer content is Y-inverted - const YInvert = 1; + const Y_INVERT = 1; /// The buffer content is interlaced - const Interlaced = 2; + const INTERLACED = 2; /// The buffer content if interlaced is bottom-field first - const BottomFirst = 4; + const BOTTOM_FIRST = 4; } } @@ -200,8 +198,8 @@ where let dma_handler = handler.clone(); let dma_log = log.clone(); let dmabuf: zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1 = new_dmabuf.implement_closure( - move |req, _| match req { - zwp_linux_dmabuf_v1::Request::CreateParams { params_id } => { + move |req, _| { + if let zwp_linux_dmabuf_v1::Request::CreateParams { params_id } = req { params_id.implement( ParamsHandler { pending_planes: Vec::new(), @@ -215,7 +213,6 @@ where (), ); } - _ => (), }, None::, (), diff --git a/src/wayland/explicit_synchronization/mod.rs b/src/wayland/explicit_synchronization/mod.rs index 6786894..dfdf050 100644 --- a/src/wayland/explicit_synchronization/mod.rs +++ b/src/wayland/explicit_synchronization/mod.rs @@ -28,7 +28,6 @@ //! use smithay::wayland::explicit_synchronization::*; //! # define_roles!(MyRoles); //! # -//! # 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::( @@ -41,7 +40,6 @@ //! compositor_token, //! None /* You can insert a logger here */ //! ); -//! # } //! ``` //! //! Then when handling a surface commit, you can retrieve the synchronization information for the surface @@ -207,8 +205,12 @@ where 2, move |new_sync, _version| { new_sync.implement_closure( - move |req, explicit_sync| match req { - zwp_linux_explicit_synchronization_v1::Request::GetSynchronization { id, surface } => { + move |req, explicit_sync| { + if let zwp_linux_explicit_synchronization_v1::Request::GetSynchronization { + id, + surface, + } = req + { let exists = compositor.with_surface_data(&surface, |attrs| { attrs.user_data.insert_if_missing(|| ESUserData { state: None }); attrs @@ -236,7 +238,6 @@ where }); }); } - _ => {} }, None::, (), diff --git a/src/wayland/output/mod.rs b/src/wayland/output/mod.rs index 6620db1..2340622 100644 --- a/src/wayland/output/mod.rs +++ b/src/wayland/output/mod.rs @@ -21,7 +21,6 @@ //! use smithay::wayland::output::{Output, PhysicalProperties, Mode}; //! use wayland_server::protocol::wl_output; //! -//! # fn main() { //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut display = wayland_server::Display::new(event_loop.handle()); //! // Create the Output with given name and physical properties @@ -48,7 +47,6 @@ //! // add other supported modes //! output.add_mode(Mode { width: 800, height: 600, refresh: 60000 }); //! output.add_mode(Mode { width: 1024, height: 768, refresh: 60000 }); -//! # } //! ``` use std::sync::{Arc, Mutex}; diff --git a/src/wayland/seat/mod.rs b/src/wayland/seat/mod.rs index baa1c26..fe58900 100644 --- a/src/wayland/seat/mod.rs +++ b/src/wayland/seat/mod.rs @@ -17,7 +17,6 @@ //! // to set a surface as a cursor image //! define_roles!(Roles => [CursorImage, CursorImageRole]); //! -//! # 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::(&mut display, |_, _, _| {}, None); @@ -28,7 +27,6 @@ //! compositor_token.clone(), // the compositor token //! None // insert a logger here //! ); -//! # } //! ``` //! //! ### Run usage @@ -144,7 +142,7 @@ impl Seat { }); let seat = Seat { arc: arc.clone() }; let global = display.create_global(5, move |new_seat, _version| { - let seat = implement_seat(new_seat, arc.clone(), token.clone()); + let seat = implement_seat(new_seat, arc.clone(), token); let mut inner = arc.inner.borrow_mut(); if seat.as_ref().version() >= 2 { seat.name(arc.name.clone()); @@ -190,7 +188,6 @@ impl Seat { /// # /// # define_roles!(Roles => [CursorImage, CursorImageRole]); /// # - /// # 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::(&mut display, |_, _, _| {}, None); @@ -204,7 +201,6 @@ impl Seat { /// compositor_token.clone(), /// |new_status| { /* a closure handling requests from clients tot change the cursor icon */ } /// ); - /// # } /// ``` pub fn add_pointer(&mut self, token: CompositorToken, cb: F) -> PointerHandle where @@ -349,7 +345,7 @@ where let inner = arc.inner.borrow_mut(); match request { wl_seat::Request::GetPointer { id } => { - let pointer = self::pointer::implement_pointer(id, inner.pointer.as_ref(), token.clone()); + let pointer = self::pointer::implement_pointer(id, inner.pointer.as_ref(), token); if let Some(ref ptr_handle) = inner.pointer { ptr_handle.new_pointer(pointer); } else { diff --git a/src/wayland/seat/pointer.rs b/src/wayland/seat/pointer.rs index b3dd1a6..24aad26 100644 --- a/src/wayland/seat/pointer.rs +++ b/src/wayland/seat/pointer.rs @@ -545,10 +545,10 @@ where move |request, pointer: WlPointer| { match request { Request::SetCursor { - serial: _, surface, hotspot_x, hotspot_y, + .. } => { if let Some(ref inner) = inner { let mut guard = inner.borrow_mut(); diff --git a/src/wayland/shell/legacy/mod.rs b/src/wayland/shell/legacy/mod.rs index ccee438..4814738 100644 --- a/src/wayland/shell/legacy/mod.rs +++ b/src/wayland/shell/legacy/mod.rs @@ -42,7 +42,6 @@ //! [ShellSurface, ShellSurfaceRole] //! ); //! -//! # 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::( @@ -60,7 +59,6 @@ //! ); //! //! // You're now ready to go! -//! # } //! ``` use std::{ diff --git a/src/wayland/shell/xdg/mod.rs b/src/wayland/shell/xdg/mod.rs index 219114f..cd20236 100644 --- a/src/wayland/shell/xdg/mod.rs +++ b/src/wayland/shell/xdg/mod.rs @@ -47,7 +47,6 @@ //! /* ... */ //! } //! -//! # 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::( @@ -65,7 +64,6 @@ //! ); //! //! // You're now ready to go! -//! # } //! ``` //! //! ### Access to shell surface and clients data diff --git a/src/wayland/shm/mod.rs b/src/wayland/shm/mod.rs index 9e74a83..5114770 100644 --- a/src/wayland/shm/mod.rs +++ b/src/wayland/shm/mod.rs @@ -22,7 +22,6 @@ //! use smithay::wayland::shm::init_shm_global; //! use wayland_server::protocol::wl_shm::Format; //! -//! # fn main() { //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut display = wayland_server::Display::new(event_loop.handle()); //! // Insert the ShmGlobal into your event loop @@ -33,7 +32,6 @@ //! vec![Format::Yuyv, Format::C8], //! None // we don't provide a logger here //! ); -//! # } //! ``` //! //! Then, when you have a [`WlBuffer`](wayland_server::protocol::wl_buffer::WlBuffer) @@ -67,7 +65,6 @@ //! } //! } //! # } -//! # fn main() {} //! ``` //! //! **Note**