chore: clippy

This commit is contained in:
Vukašin Vojinović 2026-02-23 16:25:06 +01:00 committed by Victoria Brekenfeld
parent c13e52da04
commit 2ca99c670a
59 changed files with 1974 additions and 2137 deletions

View file

@ -204,20 +204,20 @@ impl State {
}
}
}
if let Some(blocklist) = dev_list_var("COSMIC_DRM_BLOCK_DEVICES") {
if let Ok(node) = DrmNode::from_dev_id(dev) {
let node = node
.node_with_type(NodeType::Render)
.and_then(|res| res.ok())
.unwrap_or(node);
for ident in blocklist {
if ident.matches(&node) {
info!(
"Skipping device {} due to COSMIC_DRM_BLOCK_DEVICE list.",
path.display()
);
return Ok(Vec::new());
}
if let Some(blocklist) = dev_list_var("COSMIC_DRM_BLOCK_DEVICES")
&& let Ok(node) = DrmNode::from_dev_id(dev)
{
let node = node
.node_with_type(NodeType::Render)
.and_then(|res| res.ok())
.unwrap_or(node);
for ident in blocklist {
if ident.matches(&node) {
info!(
"Skipping device {} due to COSMIC_DRM_BLOCK_DEVICE list.",
path.display()
);
return Ok(Vec::new());
}
}
}
@ -271,10 +271,10 @@ impl State {
notifier,
move |event, metadata, state: &mut State| match event {
DrmEvent::VBlank(crtc) => {
if let Some(device) = state.backend.kms().drm_devices.get_mut(&drm_node) {
if let Some(surface) = device.inner.surfaces.get_mut(&crtc) {
surface.on_vblank(metadata.take());
}
if let Some(device) = state.backend.kms().drm_devices.get_mut(&drm_node)
&& let Some(surface) = device.inner.surfaces.get_mut(&crtc)
{
surface.on_vblank(metadata.take());
}
}
DrmEvent::Error(err) => {
@ -676,10 +676,10 @@ impl LockedDevice<'_> {
let mut compositor = compositor.lock().unwrap();
compositor.render_frame(renderer, &elements, CLEAR_COLOR, FrameFlags::empty())?;
if let Err(err) = compositor.commit_frame() {
if !matches!(err, FrameError::EmptyFrame) {
return Err(err.into());
}
if let Err(err) = compositor.commit_frame()
&& !matches!(err, FrameError::EmptyFrame)
{
return Err(err.into());
}
}
}

View file

@ -32,17 +32,17 @@ pub fn display_configuration(
.iter()
.flat_map(|conn| device.get_connector(*conn, true).ok())
{
if let Some(enc) = conn.current_encoder() {
if let Some(crtc) = device.get_encoder(enc)?.crtc() {
// If is is connected we found a mapping
if conn.state() == ConnectorState::Connected {
map.insert(conn.handle(), Some(crtc));
// If not, the user just unplugged something,
// or the drm master did not cleanup?
// Well, I guess we cleanup after them.
} else {
cleanup.push(crtc);
}
if let Some(enc) = conn.current_encoder()
&& let Some(crtc) = device.get_encoder(enc)?.crtc()
{
// If is is connected we found a mapping
if conn.state() == ConnectorState::Connected {
map.insert(conn.handle(), Some(crtc));
// If not, the user just unplugged something,
// or the drm master did not cleanup?
// Well, I guess we cleanup after them.
} else {
cleanup.push(crtc);
}
}
}
@ -81,12 +81,11 @@ pub fn display_configuration(
.iter()
.flat_map(|conn| device.get_connector(*conn, false).ok())
.filter(|conn| {
if let Some(enc) = conn.current_encoder() {
if let Ok(enc) = device.get_encoder(enc) {
if let Some(crtc) = enc.crtc() {
return cleanup.contains(&crtc);
}
}
if let Some(enc) = conn.current_encoder()
&& let Ok(enc) = device.get_encoder(enc)
&& let Some(crtc) = enc.crtc()
{
return cleanup.contains(&crtc);
}
false
})

View file

@ -230,14 +230,14 @@ fn determine_primary_gpu(
drm_devices: &IndexMap<DrmNode, Device>,
seat: String,
) -> Result<Option<DrmNode>> {
if let Some(device) = dev_var("COSMIC_RENDER_DEVICE") {
if let Some(node) = drm_devices.values().find_map(|dev| {
if let Some(device) = dev_var("COSMIC_RENDER_DEVICE")
&& let Some(node) = drm_devices.values().find_map(|dev| {
device
.matches(&dev.inner.render_node)
.then_some(dev.inner.render_node)
}) {
return Ok(Some(node));
}
})
{
return Ok(Some(node));
}
// try to find builtin display
@ -256,13 +256,12 @@ fn determine_primary_gpu(
// else try to find the boot gpu
let boot = determine_boot_gpu(seat);
if let Some(boot) = boot {
if drm_devices
if let Some(boot) = boot
&& drm_devices
.values()
.any(|dev| dev.inner.render_node == boot)
{
return Ok(Some(boot));
}
{
return Ok(Some(boot));
}
// else just take the first
@ -319,10 +318,9 @@ fn init_udev(
let backend = state.backend.kms();
if matches!(event, UdevEvent::Added { .. } | UdevEvent::Removed { .. })
&& backend.primary_node.read().unwrap().is_none()
&& let Err(err) = state.backend.kms().select_primary_gpu(&dh)
{
if let Err(err) = state.backend.kms().select_primary_gpu(&dh) {
warn!("Failed to determine a new primary gpu: {}", err);
}
warn!("Failed to determine a new primary gpu: {}", err);
}
}
@ -462,18 +460,17 @@ impl KmsState {
if let Some(primary_node) = primary_node
.as_ref()
.and_then(|node| node.node_with_type(NodeType::Primary).and_then(|x| x.ok()))
&& let Some(device) = self.drm_devices.get(&primary_node)
{
if let Some(device) = self.drm_devices.get(&primary_node) {
let import_device = device.drm.device().device_fd().clone();
if supports_syncobj_eventfd(&import_device) {
if let Some(state) = self.syncobj_state.as_mut() {
state.update_device(import_device);
} else {
let syncobj_state = DrmSyncobjState::new::<State>(dh, import_device);
self.syncobj_state = Some(syncobj_state);
}
return Ok(());
let import_device = device.drm.device().device_fd().clone();
if supports_syncobj_eventfd(&import_device) {
if let Some(state) = self.syncobj_state.as_mut() {
state.update_device(import_device);
} else {
let syncobj_state = DrmSyncobjState::new::<State>(dh, import_device);
self.syncobj_state = Some(syncobj_state);
}
return Ok(());
}
}
@ -939,15 +936,15 @@ impl KmsGuard<'_> {
compositor
};
if let Some(bpc) = output_config.0.max_bpc {
if let Err(err) = drm_helpers::set_max_bpc(drm.device(), conn, bpc) {
warn!(
?bpc,
?err,
"Failed to set max_bpc on connector: {}",
surface.output.name()
);
}
if let Some(bpc) = output_config.0.max_bpc
&& let Err(err) = drm_helpers::set_max_bpc(drm.device(), conn, bpc)
{
warn!(
?bpc,
?err,
"Failed to set max_bpc on connector: {}",
surface.output.name()
);
}
let vrr = output_config.0.vrr;

View file

@ -782,91 +782,90 @@ impl SurfaceThreadState {
// mark last frame completed
if let Ok(Some(Some((mut feedback, frames, estimated_presentation_time)))) =
compositor.frame_submitted()
&& self.mirroring.is_none()
{
if self.mirroring.is_none() {
let name = self.output.name();
let message = if let Some(presentation_time) = presentation_time {
let misprediction_s =
presentation_time.as_secs_f64() - estimated_presentation_time.as_secs_f64();
tracy_client::Client::running().unwrap().plot(
self.presentation_misprediction_plot_name,
misprediction_s * 1000.,
);
let name = self.output.name();
let message = if let Some(presentation_time) = presentation_time {
let misprediction_s =
presentation_time.as_secs_f64() - estimated_presentation_time.as_secs_f64();
tracy_client::Client::running().unwrap().plot(
self.presentation_misprediction_plot_name,
misprediction_s * 1000.,
);
let now = Duration::from(now);
if presentation_time > now {
let diff = presentation_time - now;
tracy_client::Client::running().unwrap().plot(
self.time_since_presentation_plot_name,
-diff.as_secs_f64() * 1000.,
);
format!("vblank on {name}, presentation is {diff:?} later")
} else {
let diff = now - presentation_time;
tracy_client::Client::running().unwrap().plot(
self.time_since_presentation_plot_name,
diff.as_secs_f64() * 1000.,
);
format!("vblank on {name}, presentation was {diff:?} ago")
}
let now = Duration::from(now);
if presentation_time > now {
let diff = presentation_time - now;
tracy_client::Client::running().unwrap().plot(
self.time_since_presentation_plot_name,
-diff.as_secs_f64() * 1000.,
);
format!("vblank on {name}, presentation is {diff:?} later")
} else {
format!("vblank on {name}, presentation time unknown")
};
let diff = now - presentation_time;
tracy_client::Client::running().unwrap().plot(
self.time_since_presentation_plot_name,
diff.as_secs_f64() * 1000.,
);
format!("vblank on {name}, presentation was {diff:?} ago")
}
} else {
format!("vblank on {name}, presentation time unknown")
};
tracy_client::Client::running()
.unwrap()
.message(&message, 0);
let (clock, flags) = if let Some(tp) = presentation_time {
(
tp.into(),
wp_presentation_feedback::Kind::Vsync
| wp_presentation_feedback::Kind::HwClock
| wp_presentation_feedback::Kind::HwCompletion,
)
} else {
(
now,
wp_presentation_feedback::Kind::Vsync
| wp_presentation_feedback::Kind::HwCompletion,
)
};
let rate = self
.output
.current_mode()
.map(|mode| Duration::from_secs_f64(1_000.0 / mode.refresh as f64));
let refresh = match rate {
Some(rate)
if self
.compositor
.as_ref()
.is_some_and(|comp| comp.with_compositor(|c| c.vrr_enabled())) =>
{
Refresh::Variable(rate)
}
Some(rate) => Refresh::Fixed(rate),
None => Refresh::Unknown,
};
if let Some(last_sequence) = self.last_sequence {
let delta = sequence as f64 - last_sequence as f64;
tracy_client::Client::running()
.unwrap()
.message(&message, 0);
.plot(self.sequence_delta_plot_name, delta);
}
self.last_sequence = Some(sequence);
let (clock, flags) = if let Some(tp) = presentation_time {
(
tp.into(),
wp_presentation_feedback::Kind::Vsync
| wp_presentation_feedback::Kind::HwClock
| wp_presentation_feedback::Kind::HwCompletion,
)
} else {
(
now,
wp_presentation_feedback::Kind::Vsync
| wp_presentation_feedback::Kind::HwCompletion,
)
};
feedback.presented(clock, refresh, sequence as u64, flags);
let rate = self
.output
.current_mode()
.map(|mode| Duration::from_secs_f64(1_000.0 / mode.refresh as f64));
let refresh = match rate {
Some(rate)
if self
.compositor
.as_ref()
.is_some_and(|comp| comp.with_compositor(|c| c.vrr_enabled())) =>
{
Refresh::Variable(rate)
}
Some(rate) => Refresh::Fixed(rate),
None => Refresh::Unknown,
};
self.timings.presented(clock);
if let Some(last_sequence) = self.last_sequence {
let delta = sequence as f64 - last_sequence as f64;
tracy_client::Client::running()
.unwrap()
.plot(self.sequence_delta_plot_name, delta);
}
self.last_sequence = Some(sequence);
feedback.presented(clock, refresh, sequence as u64, flags);
self.timings.presented(clock);
while let Ok(pending_image_copy_data) = frames.recv() {
pending_image_copy_data.send_success_when_ready(
self.output.current_transform(),
&self.loop_handle,
clock,
);
}
while let Ok(pending_image_copy_data) = frames.recv() {
pending_image_copy_data.send_success_when_ready(
self.output.current_transform(),
&self.loop_handle,
clock,
);
}
}
@ -1077,11 +1076,11 @@ impl SurfaceThreadState {
// we can't use the elements after `compositor.render_frame`,
// so let's collect everything we need for screencopy now
let mut has_cursor_mode_none = false;
let frames = self
.mirroring
.is_none()
.then(|| take_screencopy_frames(&self.output, &elements, &mut has_cursor_mode_none))
.unwrap_or_default();
let frames = if self.mirroring.is_none() {
take_screencopy_frames(&self.output, &elements, &mut has_cursor_mode_none)
} else {
Default::default()
};
// actual rendering
let source_output = self
@ -1312,10 +1311,10 @@ impl SurfaceThreadState {
None
};
if frame_result.needs_sync() {
if let PrimaryPlaneElement::Swapchain(elem) = &frame_result.primary_element {
elem.sync.wait()?;
}
if frame_result.needs_sync()
&& let PrimaryPlaneElement::Swapchain(elem) = &frame_result.primary_element
{
elem.sync.wait()?;
}
match compositor.queue_frame(feedback) {