clippy fixes

This commit is contained in:
Victor Brekenfeld 2022-01-05 13:03:41 +01:00
parent d69d15630e
commit a5f3c5c5d2
12 changed files with 49 additions and 55 deletions

View File

@ -5,10 +5,7 @@ use std::ffi::CStr;
use std::fmt;
use std::ptr;
use std::rc::Rc;
use std::sync::{
atomic::{AtomicUsize, Ordering},
mpsc::{channel, Receiver, Sender},
};
use std::sync::mpsc::{channel, Receiver, Sender};
use std::{collections::HashSet, os::raw::c_char};
use cgmath::{prelude::*, Matrix3, Vector2, Vector3};

View File

@ -178,6 +178,7 @@ pub trait Frame {
/// Render a texture to the current target as a flat 2d-plane at a given
/// position and applying the given transformation with the given alpha value.
/// (Meaning `src_transform` should match the orientation of surface being rendered).
#[allow(clippy::too_many_arguments)]
fn render_texture_at(
&mut self,
texture: &Self::TextureId,

View File

@ -141,7 +141,7 @@ where
TraversalAction::SkipChildren
}
},
|surface, states, location| {
|_surface, states, location| {
let mut location = *location;
if let Some(data) = states.data_map.get::<RefCell<SurfaceState>>() {
let mut data = data.borrow_mut();

View File

@ -313,7 +313,8 @@ impl WinitGraphicsBackend {
damage: Option<&[Rectangle<i32, Logical>]>,
scale: f64,
) -> Result<(), crate::backend::SwapBuffersError> {
let mut damage = if self.damage_tracking && damage.is_some() && !damage.unwrap().is_empty() {
let mut damage = match damage {
Some(damage) if self.damage_tracking && !damage.is_empty() => {
let size = self
.size
.borrow()
@ -322,20 +323,22 @@ impl WinitGraphicsBackend {
.to_logical(scale)
.to_i32_round::<i32>();
let damage = damage
.unwrap()
.iter()
.map(|rect| {
Rectangle::from_loc_and_size((rect.loc.x, size.h - rect.loc.y - rect.size.h), rect.size)
Rectangle::from_loc_and_size(
(rect.loc.x, size.h - rect.loc.y - rect.size.h),
rect.size,
)
.to_f64()
.to_physical(scale)
.to_i32_round::<i32>()
})
.collect::<Vec<_>>();
Some(damage)
} else {
None
}
_ => None,
};
self.egl.swap_buffers(damage.as_mut().map(|x| &mut **x))?;
self.egl.swap_buffers(damage.as_deref_mut())?;
Ok(())
}
}

View File

@ -41,7 +41,7 @@ pub fn layer_map_for_output(o: &Output) -> RefMut<'_, LayerMap> {
(0, 0),
o.current_mode()
.map(|mode| mode.size.to_logical(o.current_scale()))
.unwrap_or((0, 0).into()),
.unwrap_or_else(|| (0, 0).into()),
),
})
});
@ -130,9 +130,9 @@ impl LayerMap {
output
.current_mode()
.map(|mode| mode.size.to_logical(output.current_scale()))
.unwrap_or((0, 0).into()),
.unwrap_or_else(|| (0, 0).into()),
);
let mut zone = output_rect.clone();
let mut zone = output_rect;
slog::debug!(
crate::slog_or_fallback(None),
"Arranging layers into {:?}",
@ -212,18 +212,18 @@ impl LayerMap {
location,
size
);
if layer
let size_changed = layer
.0
.surface
.with_pending_state(|state| {
state.size.replace(size).map(|old| old != size).unwrap_or(true)
})
.unwrap()
{
.unwrap();
if size_changed {
layer.0.surface.send_configure();
}
layer_state(&layer).location = location;
layer_state(layer).location = location;
}
slog::debug!(crate::slog_or_fallback(None), "Remaining zone {:?}", zone);

View File

@ -1,5 +1,5 @@
// TODO: Remove - but for now, this makes sure these files are not completely highlighted with warnings
#![allow(missing_docs, clippy::all)]
#![allow(missing_docs)]
pub(crate) mod layer;
mod popup;
pub mod space;

View File

@ -47,6 +47,7 @@ where
}
fn geometry(&self, space_id: usize) -> Rectangle<i32, Logical>;
fn accumulated_damage(&self, for_values: Option<(&Space, &Output)>) -> Vec<Rectangle<i32, Logical>>;
#[allow(clippy::too_many_arguments)]
fn draw(
&self,
space_id: usize,

View File

@ -30,7 +30,6 @@ use self::window::*;
crate::utils::ids::id_gen!(next_space_id, SPACE_ID, SPACE_IDS);
// TODO: Maybe replace UnmanagedResource if nothing else comes up?
#[derive(Debug, thiserror::Error)]
pub enum SpaceError {
#[error("Window is not mapped to this space")]
@ -43,11 +42,12 @@ pub struct Space {
// in z-order, back to front
windows: IndexSet<Window>,
outputs: Vec<Output>,
// TODO:
//layers: Vec<Layer>,
logger: ::slog::Logger,
}
pub type DynamicRenderElements<R> =
Box<dyn RenderElement<R, <R as Renderer>::Frame, <R as Renderer>::Error, <R as Renderer>::TextureId>>;
impl Drop for Space {
fn drop(&mut self) {
SPACE_IDS.lock().unwrap().remove(&self.id);
@ -382,9 +382,7 @@ impl Space {
output: &Output,
age: usize,
clear_color: [f32; 4],
custom_elements: &[Box<
dyn RenderElement<R, <R as Renderer>::Frame, <R as Renderer>::Error, <R as Renderer>::TextureId>,
>],
custom_elements: &[DynamicRenderElements<R>],
) -> Result<Option<Vec<Rectangle<i32, Logical>>>, RenderError<R>>
where
R: Renderer + ImportAll + 'static,

View File

@ -97,7 +97,7 @@ where
damage: &[Rectangle<i32, Logical>],
log: &slog::Logger,
) -> Result<(), R::Error> {
let res = draw_window(renderer, frame, &self, scale, location, damage, log);
let res = draw_window(renderer, frame, self, scale, location, damage, log);
if res.is_ok() {
window_state(space_id, self).drawn = true;
}

View File

@ -109,13 +109,12 @@ where
.as_ref()
.map(|key| !data.damage_seen.contains(key))
.unwrap_or(true)
&& states.role == Some("subsurface")
{
if states.role == Some("subsurface") {
let current = states.cached_state.current::<SubsurfaceCachedState>();
location += current.location;
}
}
}
TraversalAction::DoChildren(location)
},
|_surface, states, location| {

View File

@ -105,9 +105,6 @@ impl Window {
pub fn new(toplevel: Kind) -> Window {
let id = next_window_id();
// TODO: Do we want this? For new lets add Window::commit
//add_commit_hook(toplevel.get_surface().unwrap(), surface_commit);
Window(Rc::new(WindowInner {
id,
toplevel,
@ -127,7 +124,6 @@ impl Window {
}
/// A bounding box over this window and its children.
// TODO: Cache and document when to trigger updates. If possible let space do it
pub fn bbox(&self) -> Rectangle<i32, Logical> {
if self.0.toplevel.get_surface().is_some() {
self.0.bbox.get()
@ -154,7 +150,6 @@ impl Window {
}
/// Activate/Deactivate this window
// TODO: Add more helpers for Maximize? Minimize? Fullscreen? I dunno
pub fn set_activated(&self, active: bool) -> bool {
match self.0.toplevel {
Kind::Xdg(ref t) => t

View File

@ -449,7 +449,7 @@ mod tests {
#[test]
fn region_attributes_empty() {
let region = RegionAttributes { rects: vec![] };
assert_eq!(region.contains((0, 0)), false);
assert!(!region.contains((0, 0)));
}
#[test]
@ -458,7 +458,7 @@ mod tests {
rects: vec![(RectangleKind::Add, Rectangle::from_loc_and_size((0, 0), (10, 10)))],
};
assert_eq!(region.contains((0, 0)), true);
assert!(region.contains((0, 0)));
}
#[test]
@ -473,8 +473,8 @@ mod tests {
],
};
assert_eq!(region.contains((0, 0)), false);
assert_eq!(region.contains((5, 5)), true);
assert!(!region.contains((0, 0)));
assert!(region.contains((5, 5)));
}
#[test]
@ -490,8 +490,8 @@ mod tests {
],
};
assert_eq!(region.contains((0, 0)), false);
assert_eq!(region.contains((5, 5)), true);
assert_eq!(region.contains((2, 2)), true);
assert!(!region.contains((0, 0)));
assert!(region.contains((5, 5)));
assert!(region.contains((2, 2)));
}
}