diff --git a/anvil/src/drawing.rs b/anvil/src/drawing.rs index 72aac05..c5c5aef 100644 --- a/anvil/src/drawing.rs +++ b/anvil/src/drawing.rs @@ -1,3 +1,5 @@ +#![allow(clippy::too_many_arguments)] + use std::{ cell::RefCell, rc::Rc, diff --git a/anvil/src/input_handler.rs b/anvil/src/input_handler.rs index 6525043..46940bd 100644 --- a/anvil/src/input_handler.rs +++ b/anvil/src/input_handler.rs @@ -290,7 +290,7 @@ fn process_keyboard_shortcut(modifiers: ModifiersState, keysym: Keysym) -> KeyAc // ctrl+alt+backspace = quit // logo + q = quit KeyAction::Quit - } else if keysym >= xkb::KEY_XF86Switch_VT_1 && keysym <= xkb::KEY_XF86Switch_VT_12 { + } else if (xkb::KEY_XF86Switch_VT_1..=xkb::KEY_XF86Switch_VT_12).contains(&keysym) { // VTSwicth KeyAction::VtSwitch((keysym - xkb::KEY_XF86Switch_VT_1 + 1) as i32) } else if modifiers.logo && keysym == xkb::KEY_Return { diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index 1c10dbf..27651b6 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -436,7 +436,7 @@ impl UdevHandlerImpl { self.logger.clone(), ), GbmDevice::new( - fd.clone() + fd ), ) } @@ -513,7 +513,7 @@ impl UdevHandlerImpl { window_map: self.window_map.clone(), output_map: self.output_map.clone(), pointer_location: self.pointer_location.clone(), - pointer_image: pointer_image, + pointer_image, cursor_status: self.cursor_status.clone(), dnd_icon: self.dnd_icon.clone(), logger: self.logger.clone(), @@ -694,14 +694,12 @@ impl DrmRenderer { match err { SwapBuffersError::AlreadySwapped => false, SwapBuffersError::TemporaryFailure(err) => { - match err.downcast_ref::() { - Some(&DrmError::DeviceInactive) => false, + !matches!(err.downcast_ref::(), + Some(&DrmError::DeviceInactive) | Some(&DrmError::Access { source: drm::SystemError::PermissionDenied, .. - }) => false, - _ => true, - } + })) } SwapBuffersError::ContextLost(err) => panic!("Rendering loop lost: {}", err), }; @@ -751,6 +749,7 @@ impl DrmRenderer { } } + #[allow(clippy::too_many_arguments)] fn render_surface( surface: &mut RenderSurface, texture_destruction_callback: &mpsc::Sender, @@ -795,7 +794,7 @@ impl DrmRenderer { width: width as i32, height: height as i32, }), - compositor_token.clone(), + *compositor_token, logger, )?; @@ -810,7 +809,7 @@ impl DrmRenderer { { if let Some(ref wl_surface) = dnd_icon.as_ref() { if wl_surface.as_ref().is_alive() { - draw_dnd_icon(surface, device_id, texture_destruction_callback, buffer_utils, wl_surface, (ptr_x, ptr_y), compositor_token.clone(), logger)?; + draw_dnd_icon(surface, device_id, texture_destruction_callback, buffer_utils, wl_surface, (ptr_x, ptr_y), *compositor_token, logger)?; } } } @@ -833,7 +832,7 @@ impl DrmRenderer { buffer_utils, wl_surface, (ptr_x, ptr_y), - compositor_token.clone(), + *compositor_token, logger, )?; } else { diff --git a/src/backend/allocator/dmabuf.rs b/src/backend/allocator/dmabuf.rs index 5220d79..142f3a6 100644 --- a/src/backend/allocator/dmabuf.rs +++ b/src/backend/allocator/dmabuf.rs @@ -116,7 +116,7 @@ impl Dmabuf { impl WeakDmabuf { pub fn upgrade(&self) -> Option { - self.0.upgrade().map(|internal| Dmabuf(internal)) + self.0.upgrade().map(Dmabuf) } } diff --git a/src/backend/allocator/gbm.rs b/src/backend/allocator/gbm.rs index 9927ac4..8b878f8 100644 --- a/src/backend/allocator/gbm.rs +++ b/src/backend/allocator/gbm.rs @@ -54,14 +54,16 @@ impl std::convert::TryFrom> for Dmabuf { //TODO switch to gbm_bo_get_plane_fd when it lands let mut iter = (0i32..planes).map(|i| buf.handle_for_plane(i)); let first = iter.next().expect("Encountered a buffer with zero planes"); - if iter.try_fold(first, |first, next| { + // check that all handles are the same + let handle = iter.try_fold(first, |first, next| { if let (Ok(next), Ok(first)) = (next, first) { if unsafe { next.u64_ == first.u64_ } { return Some(Ok(first)); } } None - }).is_none() { + }); + if handle.is_none() { // GBM is lacking a function to get a FD for a given plane. Instead, // check all planes have the same handle. We can't use // drmPrimeHandleToFD because that messes up handle ref'counting in diff --git a/src/backend/allocator/swapchain.rs b/src/backend/allocator/swapchain.rs index 95081ec..0232c7a 100644 --- a/src/backend/allocator/swapchain.rs +++ b/src/backend/allocator/swapchain.rs @@ -103,7 +103,7 @@ where } pub fn acquire(&mut self) -> Result>, SwapchainError> { - if let Some(free_slot) = self.slots.iter_mut().filter(|s| !s.acquired.load(Ordering::SeqCst)).next() { + if let Some(free_slot) = self.slots.iter_mut().find(|s| !s.acquired.load(Ordering::SeqCst)) { if free_slot.buffer.is_none() { free_slot.buffer = Arc::new(Some( self.allocator diff --git a/src/backend/drm/error.rs b/src/backend/drm/error.rs index 1776f5c..6edee60 100644 --- a/src/backend/drm/error.rs +++ b/src/backend/drm/error.rs @@ -60,22 +60,21 @@ pub enum Error { TestFailed(crtc::Handle), } -impl Into for Error { - fn into(self) -> SwapBuffersError { - match self { +impl From for SwapBuffersError { + fn from(err: Error) -> SwapBuffersError { + match err { x @ Error::DeviceInactive => SwapBuffersError::TemporaryFailure(Box::new(x)), Error::Access { errmsg, dev, source, .. - } if match source { - drm::SystemError::PermissionDenied => true, + } if matches!(source, + drm::SystemError::PermissionDenied | drm::SystemError::Unknown { errno: nix::errno::Errno::EBUSY, - } => true, + } | drm::SystemError::Unknown { errno: nix::errno::Errno::EINTR, - } => true, - _ => false, - } => + } + ) => { SwapBuffersError::TemporaryFailure(Box::new(Error::Access { errmsg, dev, source })) } diff --git a/src/backend/drm/render.rs b/src/backend/drm/render.rs index f9c5040..d306d6b 100644 --- a/src/backend/drm/render.rs +++ b/src/backend/drm/render.rs @@ -40,6 +40,7 @@ where E2: std::error::Error + 'static, E3: std::error::Error + 'static, { + #[allow(clippy::type_complexity)] pub fn new>>(drm: DrmSurface, allocator: A, renderer: R, log: L) -> Result, Error> { // we cannot simply pick the first supported format of the intersection of *all* formats, because: @@ -102,6 +103,7 @@ where DrmRenderSurface::new_internal(drm, allocator, renderer, iter, logger) } + #[allow(clippy::type_complexity)] fn new_internal(drm: Arc>, allocator: A, mut renderer: R, mut formats: impl Iterator, logger: ::slog::Logger) -> Result, Error> { let format = formats.next().ok_or(Error::NoSupportedPlaneFormat)?; diff --git a/src/backend/drm/surface/atomic.rs b/src/backend/drm/surface/atomic.rs index 909ef81..0de3a72 100644 --- a/src/backend/drm/surface/atomic.rs +++ b/src/backend/drm/surface/atomic.rs @@ -34,6 +34,7 @@ pub struct AtomicDrmSurface { } impl AtomicDrmSurface { + #[allow(clippy::too_many_arguments)] pub fn new( fd: Arc>, active: Arc, diff --git a/src/backend/egl/context.rs b/src/backend/egl/context.rs index 7a0cc2c..752de85 100644 --- a/src/backend/egl/context.rs +++ b/src/backend/egl/context.rs @@ -280,9 +280,6 @@ pub struct PixelFormatRequirements { /// Contains the minimum number of samples per pixel in the color, depth and stencil buffers. /// `None` means "don't care". Default is `None`. A value of `Some(0)` indicates that multisampling must not be enabled. pub multisampling: Option, - /// If `true`, only stereoscopic formats will be considered. If `false`, only non-stereoscopic formats. - /// The default is `false`. - pub stereoscopy: bool, } impl Default for PixelFormatRequirements { @@ -296,14 +293,13 @@ impl Default for PixelFormatRequirements { stencil_bits: Some(8), double_buffer: Some(true), multisampling: None, - stereoscopy: false, } } } impl PixelFormatRequirements { /// Append the requirements to the given attribute list - pub fn create_attributes(&self, out: &mut Vec, logger: &slog::Logger) -> Result<(), ()> { + pub fn create_attributes(&self, out: &mut Vec, logger: &slog::Logger) { if let Some(hardware_accelerated) = self.hardware_accelerated { out.push(ffi::egl::CONFIG_CAVEAT as c_int); out.push(if hardware_accelerated { @@ -358,12 +354,5 @@ impl PixelFormatRequirements { out.push(ffi::egl::SAMPLES as c_int); out.push(multisampling as c_int); } - - if self.stereoscopy { - error!(logger, "Stereoscopy is currently unsupported (sorry!)"); - return Err(()); - } - - Ok(()) } } diff --git a/src/backend/egl/display.rs b/src/backend/egl/display.rs index 0fb327f..b268f70 100644 --- a/src/backend/egl/display.rs +++ b/src/backend/egl/display.rs @@ -217,9 +217,7 @@ impl EGLDisplay { } }; - reqs.create_attributes(&mut out, &self.logger) - .map_err(|()| Error::NoAvailablePixelFormat)?; - + reqs.create_attributes(&mut out, &self.logger); out.push(ffi::egl::NONE as c_int); out }; @@ -363,10 +361,8 @@ impl EGLDisplay { return Err(Error::EglExtensionNotSupported(&["EGL_KHR_image_base", "EGL_EXT_image_dma_buf_import"])); } - if dmabuf.has_modifier() { - if !self.extensions.iter().any(|s| s == "EGL_EXT_image_dma_buf_import_modifiers") { - return Err(Error::EglExtensionNotSupported(&["EGL_EXT_image_dma_buf_import_modifiers"])); - } + if dmabuf.has_modifier() && !self.extensions.iter().any(|s| s == "EGL_EXT_image_dma_buf_import_modifiers") { + return Err(Error::EglExtensionNotSupported(&["EGL_EXT_image_dma_buf_import_modifiers"])); }; let mut out: Vec = Vec::with_capacity(50); @@ -515,11 +511,11 @@ fn get_dmabuf_formats(display: &ffi::egl::types::EGLDisplay, extensions: &[Strin if num == 0 { texture_formats.insert(DrmFormat { code: fourcc, - modifier: Modifier::Invalid.into() + modifier: Modifier::Invalid }); render_formats.insert(DrmFormat { code: fourcc, - modifier: Modifier::Invalid.into() + modifier: Modifier::Invalid }); } else { let mut mods: Vec = Vec::with_capacity(num as usize); @@ -650,10 +646,11 @@ impl EGLBufferReader { let mut images = Vec::with_capacity(format.num_planes()); for i in 0..format.num_planes() { - let mut out = Vec::with_capacity(3); - out.push(ffi::egl::WAYLAND_PLANE_WL as i32); - out.push(i as i32); - out.push(ffi::egl::NONE as i32); + let out = [ + ffi::egl::WAYLAND_PLANE_WL as i32, + i as i32, + ffi::egl::NONE as i32, + ]; images.push({ wrap_egl_call(|| unsafe { diff --git a/src/backend/renderer/gles2/mod.rs b/src/backend/renderer/gles2/mod.rs index dff871d..7330069 100644 --- a/src/backend/renderer/gles2/mod.rs +++ b/src/backend/renderer/gles2/mod.rs @@ -559,11 +559,11 @@ impl Renderer for Gles2Renderer { Ok(texture) } - fn destroy_texture(&mut self, mut texture: Self::TextureId) -> Result<(), Self::Error> { + fn destroy_texture(&mut self, texture: Self::TextureId) -> Result<(), Self::Error> { self.make_current()?; unsafe { - self.gl.DeleteTextures(1, &mut texture.texture); + self.gl.DeleteTextures(1, &texture.texture); } self.egl.unbind()?; diff --git a/src/lib.rs b/src/lib.rs index a9d1b5f..23c7c97 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,7 @@ #![warn(missing_docs, rust_2018_idioms)] +// Allow acronyms like EGL +#![allow(clippy::upper_case_acronyms)] + //! **Smithay: the Wayland compositor smithy** //! //! Most entry points in the modules can take an optional [`slog::Logger`](::slog::Logger) as argument @@ -7,9 +10,6 @@ //! `log` crate. If not, the logs will discarded. This cargo feature is part of the default set of //! features of Smithay. -// `error_chain!` can recurse deeply -#![recursion_limit = "1024"] - #[cfg_attr(feature = "backend_session", macro_use)] #[doc(hidden)] pub extern crate nix;