chore: clippy

This commit is contained in:
Vukašin Vojinović 2025-10-16 13:50:32 +02:00 committed by Victoria Brekenfeld
parent 3b70bc0265
commit 0847247c33
77 changed files with 865 additions and 1029 deletions

View file

@ -186,8 +186,7 @@ impl State {
if let Ok(node) = DrmNode::from_dev_id(dev) {
let node = node
.node_with_type(NodeType::Render)
.map(|res| res.ok())
.flatten()
.and_then(|res| res.ok())
.unwrap_or(node);
for ident in allowlist {
if ident.matches(&node) {
@ -208,8 +207,7 @@ impl State {
if let Ok(node) = DrmNode::from_dev_id(dev) {
let node = node
.node_with_type(NodeType::Render)
.map(|res| res.ok())
.flatten()
.and_then(|res| res.ok())
.unwrap_or(node);
for ident in blocklist {
if ident.matches(&node) {
@ -228,7 +226,7 @@ impl State {
.kms()
.session
.open(
&path,
path,
OFlags::RDWR | OFlags::CLOEXEC | OFlags::NOCTTY | OFlags::NONBLOCK,
)
.with_context(|| {
@ -595,7 +593,7 @@ impl Device {
let added = config
.iter()
.filter(|(conn, maybe)| match (surfaces.get(&conn), maybe) {
.filter(|(conn, maybe)| match (surfaces.get(conn), maybe) {
(Some(current_crtc), Some(new_crtc)) => current_crtc != new_crtc,
// see `removed`
(Some(_), None) => true,
@ -610,10 +608,10 @@ impl Device {
.outputs
.iter()
.filter(|(conn, _)| match config.get(conn) {
Some(Some(c)) => surfaces.get(&conn).is_some_and(|crtc| c != crtc),
Some(Some(c)) => surfaces.get(conn).is_some_and(|crtc| c != crtc),
// if don't have a crtc, we need to drop the surface if it exists.
// so it needs to be in both `removed` AND `added`.
Some(None) => surfaces.get(&conn).is_some(),
Some(None) => surfaces.get(conn).is_some(),
_ => true,
})
.map(|(conn, _)| *conn)
@ -630,7 +628,7 @@ impl Device {
}
}
impl<'a> LockedDevice<'a> {
impl LockedDevice<'_> {
fn allow_frame_flags(
&mut self,
flag: bool,
@ -660,7 +658,7 @@ impl<'a> LockedDevice<'a> {
renderer,
shell,
now,
&output,
output,
CursorMode::All,
None,
)
@ -759,7 +757,7 @@ impl InnerDevice {
.outputs
.get(&conn)
.cloned()
.map(|output| Ok(output))
.map(Ok)
.unwrap_or_else(|| create_output_for_conn(drm, conn))
.context("Failed to create `Output`")?;
@ -895,7 +893,7 @@ impl InnerDevice {
{
for surface in self.surfaces.values_mut() {
let known_nodes = surface.known_nodes().clone();
for gone_device in known_nodes.difference(&used_devices) {
for gone_device in known_nodes.difference(used_devices) {
surface.remove_node(*gone_device);
}
for new_device in used_devices.difference(&known_nodes) {
@ -993,7 +991,7 @@ fn populate_modes(
.iter()
.find(|mode| mode.mode_type().contains(ModeTypeFlags::PREFERRED))
.copied()
.or(conn_info.modes().get(0).copied())
.or(conn_info.modes().first().copied())
else {
anyhow::bail!("No mode found");
};
@ -1011,13 +1009,13 @@ fn populate_modes(
size: (mode.size().0 as i32, mode.size().1 as i32).into(),
refresh: refresh_rate as i32,
};
modes.push(mode.clone());
modes.push(mode);
output.add_mode(mode);
}
for mode in output
.modes()
.into_iter()
.filter(|mode| !modes.contains(&mode))
.filter(|mode| !modes.contains(mode))
{
output.delete_mode(mode);
}

View file

@ -82,7 +82,7 @@ pub fn display_configuration(
.flat_map(|conn| device.get_connector(*conn, false).ok())
.filter(|conn| {
if let Some(enc) = conn.current_encoder() {
if let Some(enc) = device.get_encoder(enc).ok() {
if let Ok(enc) = device.get_encoder(enc) {
if let Some(crtc) = enc.crtc() {
return cleanup.contains(&crtc);
}

View file

@ -135,7 +135,7 @@ pub fn init_backend(
// manually add already present gpus
let mut outputs = Vec::new();
for (dev, path) in udev_dispatcher.as_source_ref().device_list() {
match state.device_added(dev, path.into(), dh) {
match state.device_added(dev, path, dh) {
Ok(added) => outputs.extend(added),
Err(err) => warn!("Failed to add device {}: {:?}", path.display(), err),
}
@ -169,7 +169,7 @@ pub fn init_backend(
}
// start x11
let primary = state.backend.kms().primary_node.read().unwrap().clone();
let primary = *state.backend.kms().primary_node.read().unwrap();
state.launch_xwayland(primary);
Ok(())
@ -209,7 +209,7 @@ fn init_libinput(
.context("Failed to initialize libinput event source")?;
// Create relative pointer global
RelativePointerManagerState::new::<State>(&dh);
RelativePointerManagerState::new::<State>(dh);
Ok(libinput_context)
}
@ -239,7 +239,7 @@ fn determine_primary_gpu(
// try to find builtin display
for dev in drm_devices.values() {
if dev.inner.surfaces.values().any(|s| {
if let Some(conn_info) = dev.drm.device().get_connector(s.connector, false).ok() {
if let Ok(conn_info) = dev.drm.device().get_connector(s.connector, false) {
let i = conn_info.interface();
i == Interface::EmbeddedDisplayPort || i == Interface::LVDS || i == Interface::DSI
} else {
@ -392,7 +392,7 @@ impl State {
}
} else {
let dh = state.common.display_handle.clone();
match state.device_added(dev, path.into(), &dh) {
match state.device_added(dev, path, &dh) {
Ok(outputs) => added.extend(outputs),
Err(err) => error!(?err, "Failed to add drm device {}.", path.display(),),
}
@ -465,7 +465,7 @@ impl KmsState {
if let Some(state) = self.syncobj_state.as_mut() {
state.update_device(import_device);
} else {
let syncobj_state = DrmSyncobjState::new::<State>(&dh, import_device);
let syncobj_state = DrmSyncobjState::new::<State>(dh, import_device);
self.syncobj_state = Some(syncobj_state);
}
return Ok(());
@ -646,7 +646,7 @@ impl KmsState {
}
}
impl<'a> KmsGuard<'a> {
impl KmsGuard<'_> {
pub fn schedule_render(&mut self, output: &Output) {
for surface in self
.drm_devices
@ -755,7 +755,7 @@ impl<'a> KmsGuard<'a> {
.crtcs()
.iter()
.filter(|crtc| {
!device.inner.surfaces.get(crtc).is_some()
device.inner.surfaces.get(crtc).is_none()
// TODO: We can't do this. See https://github.com/Smithay/smithay/pull/1820
//.is_some_and(|surface| surface.output.is_enabled())
})
@ -915,7 +915,7 @@ impl<'a> KmsGuard<'a> {
&mut renderer,
&shell,
now,
&output,
output,
CursorMode::All,
None,
)
@ -1024,7 +1024,7 @@ impl<'a> KmsGuard<'a> {
&mut renderer,
&shell,
now,
&output,
output,
CursorMode::All,
None,
)
@ -1068,7 +1068,7 @@ impl<'a> KmsGuard<'a> {
&mut renderer,
&shell,
now,
&output,
output,
CursorMode::All,
None,
)
@ -1103,10 +1103,8 @@ impl<'a> KmsGuard<'a> {
None
};
if !test_only {
if mirrored_output != surface.output.mirroring() {
surface.set_mirroring(mirrored_output.clone());
}
if !test_only && mirrored_output != surface.output.mirroring() {
surface.set_mirroring(mirrored_output.clone());
}
}
}

View file

@ -42,6 +42,12 @@ impl fmt::Debug for GbmPixmanDevice {
}
}
impl<A: AsFd + 'static> Default for GbmPixmanBackend<A> {
fn default() -> Self {
Self::new()
}
}
impl<A: AsFd + 'static> GbmPixmanBackend<A> {
pub fn new() -> Self {
GbmPixmanBackend {

View file

@ -181,15 +181,14 @@ pub type GbmDrmOutput = DrmOutput<
DrmDeviceFd,
>;
#[derive(Debug)]
#[derive(Debug, Default)]
pub enum QueueState {
#[default]
Idle,
/// A redraw is queued.
Queued(RegistrationToken),
/// We submitted a frame to the KMS and waiting for it to be presented.
WaitingForVBlank {
redraw_needed: bool,
},
WaitingForVBlank { redraw_needed: bool },
/// We did not submit anything to KMS and made a timer to fire at the estimated VBlank.
WaitingForEstimatedVBlank(RegistrationToken),
/// A redraw is queued on top of the above.
@ -199,12 +198,6 @@ pub enum QueueState {
},
}
impl Default for QueueState {
fn default() -> Self {
QueueState::Idle
}
}
#[derive(Debug)]
pub enum ThreadCommand {
Suspend(SyncSender<()>),
@ -760,7 +753,7 @@ impl SurfaceThreadState {
let now = self.clock.now();
let presentation_time = match metadata.as_ref().map(|data| &data.time) {
Some(DrmEventTime::Monotonic(tp)) => Some(tp.clone()),
Some(DrmEventTime::Monotonic(tp)) => Some(*tp),
_ => None,
};
let sequence = metadata.as_ref().map(|data| data.sequence).unwrap_or(0);
@ -944,7 +937,7 @@ impl SurfaceThreadState {
warn!(?name, "Failed to submit rendering: {:?}", err);
state.queue_redraw(true);
}
return TimeoutAction::Drop;
TimeoutAction::Drop
})
.expect("Failed to schedule render");
@ -954,7 +947,7 @@ impl SurfaceThreadState {
}
QueueState::WaitingForEstimatedVBlank(estimated_vblank) => {
self.state = QueueState::WaitingForEstimatedVBlankAndQueued {
estimated_vblank: estimated_vblank.clone(),
estimated_vblank: *estimated_vblank,
queued_render: token,
};
}
@ -968,7 +961,7 @@ impl SurfaceThreadState {
} if force => {
self.loop_handle.remove(*queued_render);
self.state = QueueState::WaitingForEstimatedVBlankAndQueued {
estimated_vblank: estimated_vblank.clone(),
estimated_vblank: *estimated_vblank,
queued_render: token,
};
}
@ -990,7 +983,7 @@ impl SurfaceThreadState {
.as_ref()
.unwrap_or(&self.target_node),
&self.target_node,
&*self.shell.read(),
&self.shell.read(),
);
let mut renderer = if render_node != self.target_node {
@ -1016,7 +1009,7 @@ impl SurfaceThreadState {
(
true,
fullscreen_surface.wl_surface().is_some_and(|surface| {
recursive_frame_time_estimation(&self.clock, &*surface)
recursive_frame_time_estimation(&self.clock, &surface)
.is_some_and(|dur| dur <= _30_FPS)
}),
animations_going,
@ -1079,7 +1072,7 @@ impl SurfaceThreadState {
let source_output = self
.mirroring
.as_ref()
.or((!self.screen_filter.is_noop()).then(|| &self.output))
.or((!self.screen_filter.is_noop()).then_some(&self.output))
.filter(|output| {
PostprocessOutputConfig::for_output_untransformed(output)
!= PostprocessOutputConfig::for_output(&self.output)
@ -1258,7 +1251,7 @@ impl SurfaceThreadState {
&mut renderer,
&self.output,
&pre_postprocess_data,
&postprocess_state,
postprocess_state,
&self.screen_filter,
);
@ -1507,7 +1500,7 @@ fn render_node_for_output(
.flat_map(|w| w.wl_surface().and_then(|s| source_node_for_surface(&s)))
.collect::<Vec<_>>();
if nodes.contains(&target_node) || nodes.is_empty() {
if nodes.contains(target_node) || nodes.is_empty() {
*target_node
} else {
*primary_node
@ -1575,7 +1568,7 @@ fn get_surface_dmabuf_feedback(
FormatSet::from_iter(
primary_plane_formats
.into_iter()
.chain(overlay_plane_formats.into_iter()),
.chain(overlay_plane_formats),
),
)
.build()
@ -1648,7 +1641,7 @@ fn take_screencopy_frames(
} else {
damage_tracking.age_for_buffer(&buffer)
};
let res = damage_tracking.dt.damage_output(age, &elements);
let res = damage_tracking.dt.damage_output(age, elements);
if let Some(old_len) = old_len {
elements.truncate(old_len);
@ -1708,7 +1701,7 @@ fn send_screencopy_result<'a>(
.texture
.as_ref()
.is_some_and(|tex| tex.format() == Some(format))
&& (session.draw_cursor() == false || pre_postprocess_data.cursor_texture.is_none())
&& (!session.draw_cursor() || pre_postprocess_data.cursor_texture.is_none())
{
None
} else {

View file

@ -143,7 +143,6 @@ impl Timings {
Time::elapsed(&frame.render_start, clock.now())
- frame
.render_duration_elements
.clone()
.unwrap_or(Duration::ZERO),
);
}
@ -271,7 +270,7 @@ impl Timings {
}
let secs = match (self.previous_frames.front(), self.previous_frames.back()) {
(Some(Frame { render_start, .. }), Some(end_frame)) => {
Time::elapsed(render_start, end_frame.render_start.clone()) + end_frame.frame_time()
Time::elapsed(render_start, end_frame.render_start) + end_frame.frame_time()
}
_ => {
return 0.0;