From 681a023b04b513b3283d85fe157d6b38987bc42e Mon Sep 17 00:00:00 2001 From: srdusr <99972264+srdusr@users.noreply.github.com> Date: Tue, 18 Feb 2025 21:15:00 +0200 Subject: Fix clippy warnings surfaced by the merge Pre-existing issues in the uncommitted rust-rewrite work (unused imports, over-arity glyph-drawing functions, a couple of complex inline types, or_insert_with(T::default) instead of or_default(), and one unsimplified test-only arithmetic expression), plus two imports left unused by switching to or_default(). None of these are behavior changes. Full workspace build + clippy -D warnings + test suite (378 tests) all green after this. --- crates/wayland/src/decoration/buttons.rs | 5 +++++ crates/wayland/src/decoration/tests.rs | 4 ---- crates/wayland/src/elements.rs | 10 +++++++++- crates/wayland/src/state/mod.rs | 2 +- crates/wayland/src/udev/mod.rs | 3 +-- crates/wayland/src/udev/render.rs | 3 ++- crates/wayland/src/winit/mod.rs | 1 - crates/wayland/src/winit/render.rs | 2 +- 8 files changed, 19 insertions(+), 11 deletions(-) diff --git a/crates/wayland/src/decoration/buttons.rs b/crates/wayland/src/decoration/buttons.rs index a965ef6..bb2a709 100644 --- a/crates/wayland/src/decoration/buttons.rs +++ b/crates/wayland/src/decoration/buttons.rs @@ -169,6 +169,7 @@ fn glossy_shade(color: (u8, u8, u8), dx: f32, dy: f32, radius: f32) -> (u8, u8, /// the titlebar's real foreground colour for one drawn straight on the /// titlebar background instead (see `titlebar::render_titlebar`'s own /// `glyph_shade` local for which, and why). +#[allow(clippy::too_many_arguments)] fn blend_glyph_px(buf: &mut [u8], width: usize, height: usize, x: i32, y: i32, alpha: u8, coverage: f32, shade: (u8, u8, u8)) { if x < 0 || y < 0 || x as usize >= width || y as usize >= height || alpha == 0 || coverage <= 0.0 { return; @@ -243,6 +244,7 @@ fn glyph_box(width: usize, height: usize, offset: usize, from_left: bool, margin ((cx - half).round() as i32, (cy - half).round() as i32, (cx + half).round() as i32, (cy + half).round() as i32) } +#[allow(clippy::too_many_arguments)] pub(super) fn draw_close_glyph(buf: &mut [u8], width: usize, height: usize, offset: usize, from_left: bool, margin: f32, alpha: u8, shade: (u8, u8, u8)) { let (x0, y0, x1, y1) = glyph_box(width, height, offset, from_left, margin); blend_glyph_line(buf, width, height, (x0, y0), (x1, y1), alpha, shade); @@ -254,6 +256,7 @@ pub(super) fn draw_close_glyph(buf: &mut [u8], width: usize, height: usize, offs /// convention), and still what a traffic-light-style maximize falls back /// to if it doesn't get `draw_zoom_glyph` instead. See `titlebar:: /// render_titlebar`'s own call site for which mode picks which. +#[allow(clippy::too_many_arguments)] pub(super) fn draw_maximize_glyph(buf: &mut [u8], width: usize, height: usize, offset: usize, from_left: bool, margin: f32, alpha: u8, shade: (u8, u8, u8)) { let (x0, y0, x1, y1) = glyph_box(width, height, offset, from_left, margin); blend_glyph_line(buf, width, height, (x0, y0), (x1, y0), alpha, shade); @@ -262,6 +265,7 @@ pub(super) fn draw_maximize_glyph(buf: &mut [u8], width: usize, height: usize, o blend_glyph_line(buf, width, height, (x1, y0), (x1, y1), alpha, shade); } +#[allow(clippy::too_many_arguments)] pub(super) fn draw_minimize_glyph(buf: &mut [u8], width: usize, height: usize, offset: usize, from_left: bool, margin: f32, alpha: u8, shade: (u8, u8, u8)) { let (x0, y0, x1, y1) = glyph_box(width, height, offset, from_left, margin); let mid = (y0 + y1) / 2; @@ -277,6 +281,7 @@ pub(super) fn draw_minimize_glyph(buf: &mut [u8], width: usize, height: usize, o /// glyph here already uses, so this reads as the same family of icon /// rather than a different rendering technique bolted on just for this one /// shape. +#[allow(clippy::too_many_arguments)] pub(super) fn draw_zoom_glyph(buf: &mut [u8], width: usize, height: usize, offset: usize, from_left: bool, margin: f32, alpha: u8, shade: (u8, u8, u8)) { let (x0, y0, x1, y1) = glyph_box(width, height, offset, from_left, margin); blend_glyph_line(buf, width, height, (x0, y1), (x1, y0), alpha, shade); diff --git a/crates/wayland/src/decoration/tests.rs b/crates/wayland/src/decoration/tests.rs index 0cc5d45..e9ef02e 100644 --- a/crates/wayland/src/decoration/tests.rs +++ b/crates/wayland/src/decoration/tests.rs @@ -1,11 +1,7 @@ use super::*; -use super::border::*; use super::buttons::*; use super::color::*; -use super::corners::*; -use super::font::*; use super::shadow::*; -use super::titlebar::*; #[test] fn border_strips_surround_geometry_without_overlapping_it() { diff --git a/crates/wayland/src/elements.rs b/crates/wayland/src/elements.rs index d64a02d..de50ccf 100644 --- a/crates/wayland/src/elements.rs +++ b/crates/wayland/src/elements.rs @@ -171,8 +171,16 @@ where /// comment) or because it hasn't been attempted yet this call; either way /// the caller's fallback is the same: render `surface`'s content unrounded /// via [`surface_content_elements`]. +/// Cache entry for [`rounded_content_buffer`]: `(content_epoch, radius_bits, +/// loc, size, masked_buffer)` - keyed by [`srdwm_core::WindowId`], one entry +/// per window. The four values ahead of the buffer are exactly what that +/// function's own staleness check compares against on every call; see its +/// doc comment for why each one has to be part of the key. +pub(crate) type RoundedContentCache = std::collections::HashMap; + +#[allow(clippy::too_many_arguments)] pub(crate) fn rounded_content_buffer<'a>( - cache: &'a mut std::collections::HashMap, + cache: &'a mut RoundedContentCache, renderer: &mut smithay::backend::renderer::pixman::PixmanRenderer, epoch: u64, id: srdwm_core::WindowId, diff --git a/crates/wayland/src/state/mod.rs b/crates/wayland/src/state/mod.rs index e315b2e..a3e9b1a 100644 --- a/crates/wayland/src/state/mod.rs +++ b/crates/wayland/src/state/mod.rs @@ -481,7 +481,7 @@ pub(crate) struct CompState { /// shader instead, `rounded_corners_program`), but costs nothing to /// declare here unconditionally, the same call `rounded_corners_ /// program` itself already makes. - pub(crate) rounded_content_buffers: HashMap, + pub(crate) rounded_content_buffers: crate::elements::RoundedContentCache, /// Persistent solid-colour buffers backing a window's other three /// border strips (bottom, left, right - `decoration::border_strips`' /// order past index 0), reused by position every frame rather than diff --git a/crates/wayland/src/udev/mod.rs b/crates/wayland/src/udev/mod.rs index ae0bd7f..83ffa87 100644 --- a/crates/wayland/src/udev/mod.rs +++ b/crates/wayland/src/udev/mod.rs @@ -40,7 +40,6 @@ use smithay::backend::input::{ use smithay::backend::libinput::{LibinputInputBackend, LibinputSessionInterface}; use smithay::backend::renderer::damage::OutputDamageTracker; use smithay::backend::renderer::element::memory::MemoryRenderBufferRenderElement; -use smithay::backend::renderer::element::solid::SolidColorBuffer; use smithay::backend::renderer::element::Kind; use smithay::backend::renderer::pixman::PixmanRenderer; use smithay::backend::renderer::{Bind, ImportDma}; @@ -474,7 +473,7 @@ mod copy_damaged_rows_tests { let mut dst = vec![0u8; w * h * 4]; // Only the single pixel at (1, 1). copy_damaged_rows(&src, &mut dst, w * 4, w * 4, w, h, &[rect(1, 1, 1, 1)]); - let idx = (1 * w + 1) * 4; + let idx = (w + 1) * 4; assert_eq!(dst[idx], src[idx], "the damaged pixel must be copied"); assert_eq!(dst[0], 0, "a pixel outside the damage rect must stay untouched"); assert_eq!(dst[dst.len() - 4], 0, "the last row's pixel is also outside the rect and must stay untouched"); diff --git a/crates/wayland/src/udev/render.rs b/crates/wayland/src/udev/render.rs index 3a62292..bbabc40 100644 --- a/crates/wayland/src/udev/render.rs +++ b/crates/wayland/src/udev/render.rs @@ -154,6 +154,7 @@ impl CompState { // frame-callback loop below (after `udev` is no longer borrowed) // can notify only the windows that damage actually overlapped -- // see `windows_touched_by_damage`'s doc comment in elements.rs. + #[allow(clippy::type_complexity)] let mut presented: Vec<(Output, Point, Vec>)> = Vec::new(); for (index, output) in ready { let lock_surface = self.lock_surface_for(&output).cloned(); @@ -193,7 +194,7 @@ impl CompState { // pointer itself. See `color_filter::render_element` for // why an overlay rather than a true per-pixel shader. let color_filter = self.wm.borrow().color_filter; - let buf = self.color_filter_buffers.entry(output.name()).or_insert_with(SolidColorBuffer::default); + let buf = self.color_filter_buffers.entry(output.name()).or_default(); if let Some(elem) = crate::color_filter::render_element(buf, color_filter, hsize) { custom_elements.push(crate::elements::OverlayElement::Solid(elem)); } diff --git a/crates/wayland/src/winit/mod.rs b/crates/wayland/src/winit/mod.rs index 6a7bac0..5a08a9a 100644 --- a/crates/wayland/src/winit/mod.rs +++ b/crates/wayland/src/winit/mod.rs @@ -19,7 +19,6 @@ use smithay::backend::input::{ }; use smithay::backend::renderer::damage::OutputDamageTracker; use smithay::backend::renderer::element::memory::MemoryRenderBufferRenderElement; -use smithay::backend::renderer::element::solid::SolidColorBuffer; use smithay::backend::renderer::element::Kind; use smithay::backend::renderer::gles::GlesRenderer; use smithay::backend::renderer::ImportDma; diff --git a/crates/wayland/src/winit/render.rs b/crates/wayland/src/winit/render.rs index 5784520..c245aa2 100644 --- a/crates/wayland/src/winit/render.rs +++ b/crates/wayland/src/winit/render.rs @@ -105,7 +105,7 @@ impl WaylandPlatform { { let color_filter = self.wm.borrow().color_filter; let output_name = self.output.name(); - let buf = self.state.color_filter_buffers.entry(output_name).or_insert_with(SolidColorBuffer::default); + let buf = self.state.color_filter_buffers.entry(output_name).or_default(); if let Some(elem) = crate::color_filter::render_element(buf, color_filter, (size.w, size.h)) { custom_elements.push(crate::rounded_corners::WinitElement::Base(crate::elements::OverlayElement::Solid(elem))); } -- cgit v1.2.3