refactor(clippy): apply lints

This commit is contained in:
LGUG2Z
2024-05-12 16:03:01 -07:00
parent f02703876a
commit 9fd0c7bf39
3 changed files with 100 additions and 101 deletions
+65 -60
View File
@@ -26,7 +26,7 @@ pub trait Arrangement {
} }
impl Arrangement for DefaultLayout { impl Arrangement for DefaultLayout {
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines, clippy::cognitive_complexity)]
fn calculate( fn calculate(
&self, &self,
area: &Rect, area: &Rect,
@@ -58,12 +58,13 @@ impl Arrangement for DefaultLayout {
layout.right += adjustment.right; layout.right += adjustment.right;
}); });
match layout_flip { if matches!(
Some(Axis::Horizontal | Axis::HorizontalAndVertical) => match len { layout_flip,
2.. => columns_reverse(&mut layouts), Some(Axis::Horizontal | Axis::HorizontalAndVertical)
_ => {} ) {
}, if let 2.. = len {
_ => {} columns_reverse(&mut layouts);
}
} }
layouts layouts
@@ -82,12 +83,13 @@ impl Arrangement for DefaultLayout {
layout.right += adjustment.right; layout.right += adjustment.right;
}); });
match layout_flip { if matches!(
Some(Axis::Vertical | Axis::HorizontalAndVertical) => match len { layout_flip,
2.. => rows_reverse(&mut layouts), Some(Axis::Vertical | Axis::HorizontalAndVertical)
_ => {} ) {
}, if let 2.. = len {
_ => {} rows_reverse(&mut layouts);
}
} }
layouts layouts
@@ -135,9 +137,11 @@ impl Arrangement for DefaultLayout {
layout.right += adjustment.right; layout.right += adjustment.right;
}); });
match layout_flip { if matches!(
Some(Axis::Horizontal | Axis::HorizontalAndVertical) => match len { layout_flip,
2.. => { Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) {
if let 2.. = len {
let (primary, rest) = layouts.split_at_mut(1); let (primary, rest) = layouts.split_at_mut(1);
let primary = &mut primary[0]; let primary = &mut primary[0];
@@ -146,17 +150,15 @@ impl Arrangement for DefaultLayout {
} }
primary.left = rest[0].left + rest[0].right; primary.left = rest[0].left + rest[0].right;
} }
_ => {}
},
_ => {}
} }
match layout_flip { if matches!(
Some(Axis::Vertical | Axis::HorizontalAndVertical) => match len { layout_flip,
3.. => rows_reverse(&mut layouts[1..]), Some(Axis::Vertical | Axis::HorizontalAndVertical)
_ => {} ) {
}, if let 3.. = len {
_ => {} rows_reverse(&mut layouts[1..]);
}
} }
layouts layouts
@@ -207,9 +209,11 @@ impl Arrangement for DefaultLayout {
layout.right += adjustment.right; layout.right += adjustment.right;
}); });
match layout_flip { if matches!(
Some(Axis::Horizontal | Axis::HorizontalAndVertical) => match len { layout_flip,
2.. => { Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) {
if let 2.. = len {
let (primary, rest) = layouts.split_at_mut(1); let (primary, rest) = layouts.split_at_mut(1);
let primary = &mut primary[0]; let primary = &mut primary[0];
@@ -218,17 +222,15 @@ impl Arrangement for DefaultLayout {
rect.left = primary.left + primary.right; rect.left = primary.left + primary.right;
} }
} }
_ => {}
},
_ => {}
} }
match layout_flip { if matches!(
Some(Axis::Vertical | Axis::HorizontalAndVertical) => match len { layout_flip,
3.. => rows_reverse(&mut layouts[1..]), Some(Axis::Vertical | Axis::HorizontalAndVertical)
_ => {} ) {
}, if let 3.. = len {
_ => {} rows_reverse(&mut layouts[1..]);
}
} }
layouts layouts
@@ -276,9 +278,11 @@ impl Arrangement for DefaultLayout {
layout.right += adjustment.right; layout.right += adjustment.right;
}); });
match layout_flip { if matches!(
Some(Axis::Vertical | Axis::HorizontalAndVertical) => match len { layout_flip,
2.. => { Some(Axis::Vertical | Axis::HorizontalAndVertical)
) {
if let 2.. = len {
let (primary, rest) = layouts.split_at_mut(1); let (primary, rest) = layouts.split_at_mut(1);
let primary = &mut primary[0]; let primary = &mut primary[0];
@@ -287,17 +291,15 @@ impl Arrangement for DefaultLayout {
} }
primary.top = rest[0].top + rest[0].bottom; primary.top = rest[0].top + rest[0].bottom;
} }
_ => {}
},
_ => {}
} }
match layout_flip { if matches!(
Some(Axis::Horizontal | Axis::HorizontalAndVertical) => match len { layout_flip,
3.. => columns_reverse(&mut layouts[1..]), Some(Axis::Horizontal | Axis::HorizontalAndVertical)
_ => {} ) {
}, if let 3.. = len {
_ => {} columns_reverse(&mut layouts[1..]);
}
} }
layouts layouts
@@ -374,8 +376,11 @@ impl Arrangement for DefaultLayout {
layout.right += adjustment.right; layout.right += adjustment.right;
}); });
match layout_flip { if matches!(
Some(Axis::Horizontal | Axis::HorizontalAndVertical) => match len { layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) {
match len {
2 => { 2 => {
let (primary, secondary) = layouts.split_at_mut(1); let (primary, secondary) = layouts.split_at_mut(1);
let primary = &mut primary[0]; let primary = &mut primary[0];
@@ -397,20 +402,20 @@ impl Arrangement for DefaultLayout {
secondary.left = primary.left + primary.right; secondary.left = primary.left + primary.right;
} }
_ => {} _ => {}
}, }
_ => {}
} }
match layout_flip { if matches!(
Some(Axis::Vertical | Axis::HorizontalAndVertical) => match len { layout_flip,
4.. => rows_reverse(&mut layouts[2..]), Some(Axis::Vertical | Axis::HorizontalAndVertical)
_ => {} ) {
}, if let 4.. = len {
_ => {} rows_reverse(&mut layouts[2..]);
}
} }
layouts layouts
}, }
#[allow( #[allow(
clippy::cast_precision_loss, clippy::cast_precision_loss,
clippy::cast_possible_truncation, clippy::cast_possible_truncation,
+5 -9
View File
@@ -206,13 +206,11 @@ pub fn listen_for_notifications(wm: Arc<Mutex<WindowManager>>) {
let mut to_remove = vec![]; let mut to_remove = vec![];
for (id, border) in borders.iter() { for (id, border) in borders.iter() {
if borders_monitors.get(id).copied().unwrap_or_default() == monitor_idx { if borders_monitors.get(id).copied().unwrap_or_default() == monitor_idx && !container_ids.contains(id) {
if !container_ids.contains(id) {
border.destroy()?; border.destroy()?;
to_remove.push(id.clone()); to_remove.push(id.clone());
} }
} }
}
for id in &to_remove { for id in &to_remove {
borders.remove(id); borders.remove(id);
@@ -268,12 +266,10 @@ pub fn listen_for_notifications(wm: Arc<Mutex<WindowManager>>) {
|| monitor_idx != focused_monitor_idx || monitor_idx != focused_monitor_idx
{ {
WindowKind::Unfocused WindowKind::Unfocused
} else { } else if c.windows().len() > 1 {
if c.windows().len() > 1 {
WindowKind::Stack WindowKind::Stack
} else { } else {
WindowKind::Single WindowKind::Single
}
}, },
); );
} }
@@ -302,9 +298,9 @@ pub enum ZOrder {
TopMost, TopMost,
} }
impl Into<isize> for ZOrder { impl From<ZOrder> for isize {
fn into(self) -> isize { fn from(val: ZOrder) -> Self {
match self { match val {
ZOrder::Top => 0, ZOrder::Top => 0,
ZOrder::NoTopMost => -2, ZOrder::NoTopMost => -2,
ZOrder::Bottom => 1, ZOrder::Bottom => 1,
+1 -3
View File
@@ -270,8 +270,7 @@ impl WindowManager {
for (i, monitors) in self.monitors().iter().enumerate() { for (i, monitors) in self.monitors().iter().enumerate() {
for (j, workspace) in monitors.workspaces().iter().enumerate() { for (j, workspace) in monitors.workspaces().iter().enumerate() {
if workspace.contains_window(window.hwnd) { if workspace.contains_window(window.hwnd) && focused_pair != (i, j) {
if focused_pair != (i, j) {
workspace_reconciliator::event_tx().send( workspace_reconciliator::event_tx().send(
workspace_reconciliator::Notification { workspace_reconciliator::Notification {
monitor_idx: i, monitor_idx: i,
@@ -283,7 +282,6 @@ impl WindowManager {
} }
} }
} }
}
// There are some applications such as Firefox where, if they are focused when a // There are some applications such as Firefox where, if they are focused when a
// workspace switch takes place, it will fire an additional Show event, which will // workspace switch takes place, it will fire an additional Show event, which will