refactor(clippy): apply various lint fixes and recs

This commit is contained in:
LGUG2Z
2024-02-25 13:33:44 -08:00
parent 0581950b21
commit fd57d32bb5
4 changed files with 98 additions and 22 deletions

View File

@@ -131,21 +131,23 @@ impl Arrangement for DefaultLayout {
layouts layouts
} }
Self::UltrawideVerticalStack => ultrawide(area, len, layout_flip, resize_dimensions), Self::UltrawideVerticalStack => ultrawide(area, len, layout_flip, resize_dimensions),
#[allow(
clippy::cast_precision_loss,
clippy::cast_possible_truncation,
clippy::cast_possible_wrap
)]
Self::Grid => { Self::Grid => {
// Shamelessly lifted from LeftWM // Shamelessly lifted from LeftWM
// https://github.com/leftwm/leftwm/blob/18675067b8450e520ef75db2ebbb0d973aa1199e/leftwm-core/src/layouts/grid_horizontal.rs // https://github.com/leftwm/leftwm/blob/18675067b8450e520ef75db2ebbb0d973aa1199e/leftwm-core/src/layouts/grid_horizontal.rs
let mut layouts: Vec<Rect> = vec![]; let mut layouts: Vec<Rect> = vec![];
layouts.resize(len, Rect::default()); layouts.resize(len, Rect::default());
#[allow(clippy::cast_possible_truncation)]
let len = len as i32; let len = len as i32;
#[allow(clippy::cast_possible_truncation)]
let num_cols = (len as f32).sqrt().ceil() as i32; let num_cols = (len as f32).sqrt().ceil() as i32;
let mut iter = layouts.iter_mut().enumerate().peekable(); let mut iter = layouts.iter_mut().enumerate().peekable();
for col in 0..num_cols { for col in 0..num_cols {
#[allow(clippy::cast_possible_truncation)]
let iter_peek = iter.peek().map(|x| x.0).unwrap_or_default() as i32; let iter_peek = iter.peek().map(|x| x.0).unwrap_or_default() as i32;
let remaining_windows = len - iter_peek; let remaining_windows = len - iter_peek;
let remaining_columns = num_cols - col; let remaining_columns = num_cols - col;

View File

@@ -150,7 +150,7 @@ impl DefaultLayout {
Self::VerticalStack => Self::Rows, Self::VerticalStack => Self::Rows,
Self::Rows => Self::Columns, Self::Rows => Self::Columns,
Self::Columns => Self::Grid, Self::Columns => Self::Grid,
Self::Grid => Self::BSP Self::Grid => Self::BSP,
} }
} }
} }

View File

@@ -19,10 +19,30 @@ pub trait Direction {
idx: usize, idx: usize,
count: usize, count: usize,
) -> bool; ) -> bool;
fn up_index(&self, op_direction: Option<OperationDirection>, idx: usize, count: Option<usize>) -> usize; fn up_index(
fn down_index(&self, op_direction: Option<OperationDirection>, idx: usize, count: Option<usize>) -> usize; &self,
fn left_index(&self, op_direction: Option<OperationDirection>, idx: usize, count: Option<usize>) -> usize; op_direction: Option<OperationDirection>,
fn right_index(&self, op_direction: Option<OperationDirection>, idx: usize, count: Option<usize>) -> usize; idx: usize,
count: Option<usize>,
) -> usize;
fn down_index(
&self,
op_direction: Option<OperationDirection>,
idx: usize,
count: Option<usize>,
) -> usize;
fn left_index(
&self,
op_direction: Option<OperationDirection>,
idx: usize,
count: Option<usize>,
) -> usize;
fn right_index(
&self,
op_direction: Option<OperationDirection>,
idx: usize,
count: Option<usize>,
) -> usize;
} }
impl Direction for DefaultLayout { impl Direction for DefaultLayout {
@@ -112,7 +132,12 @@ impl Direction for DefaultLayout {
} }
} }
fn up_index(&self, op_direction: Option<OperationDirection>, idx: usize, count: Option<usize>) -> usize { fn up_index(
&self,
op_direction: Option<OperationDirection>,
idx: usize,
count: Option<usize>,
) -> usize {
match self { match self {
Self::BSP => { Self::BSP => {
if idx % 2 == 0 { if idx % 2 == 0 {
@@ -128,7 +153,12 @@ impl Direction for DefaultLayout {
} }
} }
fn down_index(&self, op_direction: Option<OperationDirection>, idx: usize, count: Option<usize>) -> usize { fn down_index(
&self,
op_direction: Option<OperationDirection>,
idx: usize,
count: Option<usize>,
) -> usize {
match self { match self {
Self::BSP | Self::Rows | Self::VerticalStack | Self::UltrawideVerticalStack => idx + 1, Self::BSP | Self::Rows | Self::VerticalStack | Self::UltrawideVerticalStack => idx + 1,
Self::Columns => unreachable!(), Self::Columns => unreachable!(),
@@ -137,7 +167,12 @@ impl Direction for DefaultLayout {
} }
} }
fn left_index(&self, op_direction: Option<OperationDirection>, idx: usize, count: Option<usize>) -> usize { fn left_index(
&self,
op_direction: Option<OperationDirection>,
idx: usize,
count: Option<usize>,
) -> usize {
match self { match self {
Self::BSP => { Self::BSP => {
if idx % 2 == 0 { if idx % 2 == 0 {
@@ -158,7 +193,12 @@ impl Direction for DefaultLayout {
} }
} }
fn right_index(&self, op_direction: Option<OperationDirection>, idx: usize, count: Option<usize>) -> usize { fn right_index(
&self,
op_direction: Option<OperationDirection>,
idx: usize,
count: Option<usize>,
) -> usize {
match self { match self {
Self::BSP | Self::Columns | Self::HorizontalStack => idx + 1, Self::BSP | Self::Columns | Self::HorizontalStack => idx + 1,
Self::Rows => unreachable!(), Self::Rows => unreachable!(),
@@ -185,6 +225,7 @@ enum GridItemState {
Invalid, Invalid,
} }
#[allow(clippy::struct_excessive_bools)]
struct GridTouchingEdges { struct GridTouchingEdges {
left: bool, left: bool,
right: bool, right: bool,
@@ -192,8 +233,12 @@ struct GridTouchingEdges {
down: bool, down: bool,
} }
#[allow(
clippy::cast_possible_truncation,
clippy::cast_precision_loss,
clippy::cast_sign_loss
)]
fn get_grid_item(idx: usize, count: usize) -> GridItem { fn get_grid_item(idx: usize, count: usize) -> GridItem {
#[allow(clippy::cast_possible_truncation)]
let num_cols = (count as f32).sqrt().ceil() as usize; let num_cols = (count as f32).sqrt().ceil() as usize;
let mut iter = 0; let mut iter = 0;
@@ -248,9 +293,18 @@ fn is_grid_edge(op_direction: OperationDirection, idx: usize, count: usize) -> b
} }
} }
fn grid_neighbor(op_direction: Option<OperationDirection>, idx: usize, count: Option<usize>) -> usize { fn grid_neighbor(
let op_direction = if let Some(dir) = op_direction { dir } else { return 0; }; op_direction: Option<OperationDirection>,
let count = if let Some(count) = count { count } else { return 0; }; idx: usize,
count: Option<usize>,
) -> usize {
let Some(op_direction) = op_direction else {
return 0;
};
let Some(count) = count else {
return 0;
};
let item = get_grid_item(idx, count); let item = get_grid_item(idx, count);
@@ -363,15 +417,30 @@ impl Direction for CustomLayout {
} }
} }
fn up_index(&self, _op_direction: Option<OperationDirection>, idx: usize, _count: Option<usize>) -> usize { fn up_index(
&self,
_op_direction: Option<OperationDirection>,
idx: usize,
_count: Option<usize>,
) -> usize {
idx - 1 idx - 1
} }
fn down_index(&self, _op_direction: Option<OperationDirection>, idx: usize, _count: Option<usize>) -> usize { fn down_index(
&self,
_op_direction: Option<OperationDirection>,
idx: usize,
_count: Option<usize>,
) -> usize {
idx + 1 idx + 1
} }
fn left_index(&self, _op_direction: Option<OperationDirection>, idx: usize, _count: Option<usize>) -> usize { fn left_index(
&self,
_op_direction: Option<OperationDirection>,
idx: usize,
_count: Option<usize>,
) -> usize {
let column_idx = self.column_for_container_idx(idx); let column_idx = self.column_for_container_idx(idx);
if column_idx - 1 == 0 { if column_idx - 1 == 0 {
0 0
@@ -380,7 +449,12 @@ impl Direction for CustomLayout {
} }
} }
fn right_index(&self, _op_direction: Option<OperationDirection>, idx: usize, _count: Option<usize>) -> usize { fn right_index(
&self,
_op_direction: Option<OperationDirection>,
idx: usize,
_count: Option<usize>,
) -> usize {
let column_idx = self.column_for_container_idx(idx); let column_idx = self.column_for_container_idx(idx);
self.first_container_idx(column_idx + 1) self.first_container_idx(column_idx + 1)
} }

View File

@@ -1488,7 +1488,7 @@ impl WindowManager {
if matches!(workspace.layout(), Layout::Default(DefaultLayout::Grid)) { if matches!(workspace.layout(), Layout::Default(DefaultLayout::Grid)) {
tracing::debug!("ignoring promote command for grid layout"); tracing::debug!("ignoring promote command for grid layout");
return Ok(()) return Ok(());
} }
tracing::info!("promoting container"); tracing::info!("promoting container");
@@ -1505,7 +1505,7 @@ impl WindowManager {
if matches!(workspace.layout(), Layout::Default(DefaultLayout::Grid)) { if matches!(workspace.layout(), Layout::Default(DefaultLayout::Grid)) {
tracing::info!("ignoring promote focus command for grid layout"); tracing::info!("ignoring promote focus command for grid layout");
return Ok(()) return Ok(());
} }
tracing::info!("promoting focus"); tracing::info!("promoting focus");