From 078d8f624820a5e16f4ff55efeced42bff1776c7 Mon Sep 17 00:00:00 2001 From: Enrico Stemmer Date: Thu, 13 Feb 2025 03:15:00 +0100 Subject: [PATCH] chore: clippy Signed-off-by: Enrico Stemmer --- src/config/convert.rs | 12 ++--- src/daemon/gui/launcher/mod.rs | 8 +-- src/daemon/gui/maps.rs | 2 +- src/daemon/gui/windows/init.rs | 1 + src/daemon/mod.rs | 2 +- src/handle/next.rs | 91 +++++++++++++++------------------- 6 files changed, 55 insertions(+), 61 deletions(-) diff --git a/src/config/convert.rs b/src/config/convert.rs index d8bf15b..f68d8cc 100644 --- a/src/config/convert.rs +++ b/src/config/convert.rs @@ -9,7 +9,7 @@ use rand::Rng; use std::path::PathBuf; use tracing::{span, trace, Level}; -pub fn create_binds_and_submaps<'a>(binds: &Vec) -> anyhow::Result> { +pub fn create_binds_and_submaps<'a>(binds: &[Bind]) -> anyhow::Result> { let _span = span!(Level::DEBUG, "create_binds_and_submaps").entered(); let workspaces_per_row = global::OPTS .get() @@ -25,7 +25,7 @@ pub fn create_binds_and_submaps<'a>(binds: &Vec) -> anyhow::Result = matches.into_values().collect(); matches.sort_by(|(a_t, a), (b_t, b)| { if a_t != b_t { - return a_t.cmp(&b_t); + a_t.cmp(b_t) } else { let a_e = runs.get(&a.desktop_file); let b_e = runs.get(&b.desktop_file); @@ -189,7 +190,7 @@ pub(super) fn update_launcher( share.clone(), &entry.name, &entry.icon, - &*entry.exec, + &entry.exec, index, &match reverse_key { ReverseKey::Mod(m) => match i { @@ -229,6 +230,7 @@ pub(super) fn update_launcher( execs } +#[allow(clippy::too_many_arguments)] fn create_launch_widget( share: Share, name: &str, @@ -312,7 +314,7 @@ fn create_launch_widget( .unwrap_or_default() ) } else { - format!("{}", exec) // show full exec instead of only last part of /path/to/exec + exec.to_string() // show full exec instead of only last part of /path/to/exec }, ) .build(); diff --git a/src/daemon/gui/maps.rs b/src/daemon/gui/maps.rs index 8337261..afd640c 100644 --- a/src/daemon/gui/maps.rs +++ b/src/daemon/gui/maps.rs @@ -52,7 +52,7 @@ pub fn init_icon_map() { let mut dirs: Vec<_> = read_dir(&path).unwrap().flatten().collect(); while let Some(d) = dirs.pop() { if d.file_type().unwrap().is_dir() { - dirs.extend(read_dir(&d.path()).unwrap().flatten()); + dirs.extend(read_dir(d.path()).unwrap().flatten()); } else { let name = d.file_name(); let name = name.to_string_lossy(); diff --git a/src/daemon/gui/windows/init.rs b/src/daemon/gui/windows/init.rs index fa1dbc7..4e2453b 100644 --- a/src/daemon/gui/windows/init.rs +++ b/src/daemon/gui/windows/init.rs @@ -12,6 +12,7 @@ fn scale(value: i16, size_factor: f64) -> i32 { (value as f64 / 30.0 * size_factor) as i32 } +#[allow(clippy::too_many_arguments)] pub fn init_windows( share: Share, workspaces_p: &[(WorkspaceId, WorkspaceData)], diff --git a/src/daemon/mod.rs b/src/daemon/mod.rs index 6120dfe..e1eeacf 100644 --- a/src/daemon/mod.rs +++ b/src/daemon/mod.rs @@ -77,7 +77,7 @@ pub fn start_config_applier(binds: Vec) { .warn("Failed to start config reload event listener"); } -fn apply_config(binds: &Vec) { +fn apply_config(binds: &[config::Bind]) { if let Some(list) = config::create_binds_and_submaps(binds).warn("Failed to create binds and submaps") { diff --git a/src/handle/next.rs b/src/handle/next.rs index 7a893a7..2f2ff52 100644 --- a/src/handle/next.rs +++ b/src/handle/next.rs @@ -50,7 +50,7 @@ macro_rules! find_next { } } else { if index < 0 { - index += filtered.len() as i8 * (((index as i8) * -1 / filtered.len() as i8) + 1); + index += filtered.len() as i8 * ((-(index as i8) / filtered.len() as i8) + 1); } index %= filtered.len() as i8; } @@ -84,32 +84,30 @@ pub fn find_next( Some(id), gui_navigation ) - } else { - if let Some(id2) = active.workspace { - let mut clients = hypr_data.clients.iter().filter(|(_, c)| c.workspace == id2); - if reverse { - clients.last() - } else { - clients.next() - } - .context("Workspace not found")? - } else if let Some(id2) = active.monitor { - let mut clients = hypr_data.clients.iter().filter(|(_, c)| c.monitor == id2); - if reverse { - clients.last() - } else { - clients.next() - } - .context("Monitor not found")? + } else if let Some(id2) = active.workspace { + let mut clients = hypr_data.clients.iter().filter(|(_, c)| c.workspace == id2); + if reverse { + clients.last() } else { - find_next!( - reverse, - offset as i8, - &hypr_data.clients, - None::, - gui_navigation - ) + clients.next() } + .context("Workspace not found")? + } else if let Some(id2) = active.monitor { + let mut clients = hypr_data.clients.iter().filter(|(_, c)| c.monitor == id2); + if reverse { + clients.last() + } else { + clients.next() + } + .context("Monitor not found")? + } else { + find_next!( + reverse, + offset as i8, + &hypr_data.clients, + None::, + gui_navigation + ) }; info!("Next client: {:?}", id); Ok(Active { @@ -128,27 +126,25 @@ pub fn find_next( Some(id), gui_navigation ) - } else { - if let Some(id2) = active.monitor { - let mut workspaces = hypr_data - .workspaces - .iter() - .filter(|(_, c)| c.monitor == id2); - if reverse { - workspaces.last() - } else { - workspaces.next() - } - .context("Monitor not found")? + } else if let Some(id2) = active.monitor { + let mut workspaces = hypr_data + .workspaces + .iter() + .filter(|(_, c)| c.monitor == id2); + if reverse { + workspaces.last() } else { - find_next!( - reverse, - offset as i8, - &hypr_data.workspaces, - None::, - gui_navigation - ) + workspaces.next() } + .context("Monitor not found")? + } else { + find_next!( + reverse, + offset as i8, + &hypr_data.workspaces, + None::, + gui_navigation + ) }; info!("Next workspace: {:?}", id); Ok(Active { @@ -158,16 +154,11 @@ pub fn find_next( }) } (false, SwitchType::Monitor) => { - let active_id = if let Some(id) = active.monitor { - Some(id) - } else { - None - }; let (id, _) = find_next!( reverse, offset as i8, &hypr_data.monitors, - active_id, + active.monitor, gui_navigation ); info!("Next monitor: {:?}", id);