clippy warnings fix

This commit is contained in:
Alexander Mohr 2025-06-29 00:54:03 +02:00
parent 01facc5866
commit 6b1c9e57fb
15 changed files with 95 additions and 72 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 KiB

View file

@ -1 +1,15 @@
# Worf Hyprspace # Worf Hyprspace
This allows to manage workspaces in hyprland using the Worf API.
Inspired by https://github.com/sslater11/hyprland-dynamic-workspaces-manager
<img src="../images/hyprspace.png">
## Features
-Auto: Automatic detection of mode
-Rename: Change the name of the chosen workspace
-SwitchToWorkspace: Change the active workspace
-MoveCurrentWindowToOtherWorkspace: Move the focused window to a new workspace and follow it
-MoveCurrentWindowToOtherWorkspaceSilent: Move the focused window to a new workspace and don't follow it
-MoveAllWindowsToOtherWorkSpace: Move all windows to a new workspace
-DeleteWorkspace: Close all windows and go to another workspace

View file

@ -157,7 +157,7 @@ fn main() -> Result<(), String> {
&cache, &cache,
)?)); )?));
let windows = provider.lock().unwrap().windows.clone(); let windows = provider.lock().unwrap().windows.clone();
let result = gui::show(config, provider, None, None, ExpandMode::Verbatim, None) let result = gui::show(&config, provider, None, None, ExpandMode::Verbatim, None)
.map_err(|e| e.to_string())?; .map_err(|e| e.to_string())?;
let update_cache = thread::spawn(move || { let update_cache = thread::spawn(move || {
windows.iter().for_each(|item| { windows.iter().for_each(|item| {

View file

@ -1,9 +1,19 @@
use std::{collections::HashMap, env, process::Command, thread::sleep, time::Duration, sync::{Arc, Mutex, RwLock}}; use std::{
collections::HashMap,
env,
process::Command,
sync::{Arc, Mutex, RwLock},
thread::sleep,
time::Duration,
};
use worf::{ use worf::{
config::{self, Config, CustomKeyHintLocation, Key}, config::{self, Config, CustomKeyHintLocation, Key},
desktop::{copy_to_clipboard, spawn_fork}, desktop::{copy_to_clipboard, spawn_fork},
gui::{self, CustomKeyHint, CustomKeys, ItemProvider, KeyBinding, MenuItem, Modifier, ProviderData, ExpandMode}, gui::{
self, CustomKeyHint, CustomKeys, ExpandMode, ItemProvider, KeyBinding, MenuItem, Modifier,
ProviderData,
},
}; };
#[derive(Clone)] #[derive(Clone)]
@ -138,7 +148,7 @@ fn rbw(cmd: &str, args: Option<Vec<&str>>) -> Result<String, String> {
let output = command let output = command
.output() .output()
.map_err(|e| format!("Failed to execute command: {}", e))?; .map_err(|e| format!("Failed to execute command: {e}"))?;
if !output.status.success() { if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr); let stderr = String::from_utf8_lossy(&output.stderr);
@ -146,7 +156,7 @@ fn rbw(cmd: &str, args: Option<Vec<&str>>) -> Result<String, String> {
} }
let stdout = let stdout =
String::from_utf8(output.stdout).map_err(|e| format!("Invalid UTF-8 output: {}", e))?; String::from_utf8(output.stdout).map_err(|e| format!("Invalid UTF-8 output: {e}"))?;
Ok(stdout.trim().to_string()) Ok(stdout.trim().to_string())
} }
@ -273,7 +283,7 @@ fn key_lock() -> KeyBinding {
fn show(config: Arc<RwLock<Config>>, provider: Arc<Mutex<PasswordProvider>>) -> Result<(), String> { fn show(config: Arc<RwLock<Config>>, provider: Arc<Mutex<PasswordProvider>>) -> Result<(), String> {
match gui::show( match gui::show(
Arc::clone(&config), &config,
provider, provider,
None, None,
None, None,
@ -301,7 +311,10 @@ fn show(config: Arc<RwLock<Config>>, provider: Arc<Mutex<PasswordProvider>>) ->
Ok(selection) => { Ok(selection) => {
if let Some(meta) = selection.menu.data { if let Some(meta) = selection.menu.data {
if meta.ids.len() > 1 { if meta.ids.len() > 1 {
return show(config, Arc::new(Mutex::new(PasswordProvider::sub_provider(meta.ids)?))); return show(
config,
Arc::new(Mutex::new(PasswordProvider::sub_provider(meta.ids)?)),
);
} }
let id = meta.ids.first().unwrap_or(&selection.menu.label); let id = meta.ids.first().unwrap_or(&selection.menu.label);
@ -351,7 +364,9 @@ fn main() -> Result<(), String> {
.init(); .init();
let args = config::parse_args(); let args = config::parse_args();
let config = Arc::new(RwLock::new(config::load_config(Some(&args)).unwrap_or(args))); let config = Arc::new(RwLock::new(
config::load_config(Some(&args)).unwrap_or(args),
));
if !groups().contains("input") { if !groups().contains("input") {
log::error!( log::error!(

View file

@ -75,13 +75,20 @@ pub struct DefaultItemFactory<T: Clone> {
} }
impl<T: Clone> DefaultItemFactory<T> { impl<T: Clone> DefaultItemFactory<T> {
#[must_use]
pub fn new() -> DefaultItemFactory<T> { pub fn new() -> DefaultItemFactory<T> {
DefaultItemFactory::<T> { DefaultItemFactory::<T> {
_marker: Default::default(), _marker: PhantomData,
} }
} }
} }
impl<T: Clone> Default for DefaultItemFactory<T> {
fn default() -> Self {
Self::new()
}
}
impl<T: Clone> ItemFactory<T> for DefaultItemFactory<T> { impl<T: Clone> ItemFactory<T> for DefaultItemFactory<T> {
fn new_menu_item(&self, label: String) -> Option<MenuItem<T>> { fn new_menu_item(&self, label: String) -> Option<MenuItem<T>> {
Some(MenuItem::new(label, None, None, vec![], None, 0.0, None)) Some(MenuItem::new(label, None, None, vec![], None, 0.0, None))
@ -516,8 +523,10 @@ struct UiElements<T: Clone> {
/// # Errors /// # Errors
/// ///
/// Will return Err when the channel between the UI and this is broken /// Will return Err when the channel between the UI and this is broken
/// # Panics
/// When failing to unwrap the arc lock
pub fn show<T>( pub fn show<T>(
config: Arc<RwLock<Config>>, config: &Arc<RwLock<Config>>,
item_provider: ArcProvider<T>, item_provider: ArcProvider<T>,
item_factory: Option<ArcFactory<T>>, item_factory: Option<ArcFactory<T>>,
search_ignored_words: Option<Vec<Regex>>, search_ignored_words: Option<Vec<Regex>>,
@ -550,12 +559,12 @@ where
item_provider, item_provider,
item_factory, item_factory,
selected_sender: sender, selected_sender: sender,
config: config.clone(), config: Arc::clone(config),
search_ignored_words, search_ignored_words,
expand_mode, expand_mode,
}); });
let connect_cfg = Arc::clone(&config); let connect_cfg = Arc::clone(config);
app.connect_activate(move |app| { app.connect_activate(move |app| {
build_ui::<T>(&connect_cfg, &meta, app.clone(), custom_keys.as_ref()); build_ui::<T>(&connect_cfg, &meta, app.clone(), custom_keys.as_ref());
}); });
@ -673,7 +682,7 @@ fn build_ui<T>(
let provider_elements = get_provider_elements.join().unwrap(); let provider_elements = get_provider_elements.join().unwrap();
log::debug!("got items after {:?}", wait_for_items.elapsed()); log::debug!("got items after {:?}", wait_for_items.elapsed());
let cfg = config.clone(); let cfg = Arc::clone(config);
let ui = Rc::clone(&ui_elements); let ui = Rc::clone(&ui_elements);
ui_elements.window.connect_is_active_notify(move |_| { ui_elements.window.connect_is_active_notify(move |_| {
window_show_resize(&cfg.read().unwrap(), &ui); window_show_resize(&cfg.read().unwrap(), &ui);

View file

@ -1,6 +1,7 @@
use regex::Regex; use regex::Regex;
use std::sync::{Arc, Mutex, RwLock}; use std::sync::{Arc, Mutex, RwLock};
use crate::gui::ArcProvider;
use crate::{ use crate::{
Error, Error,
config::Config, config::Config,
@ -15,7 +16,6 @@ use crate::{
ssh::SshProvider, ssh::SshProvider,
}, },
}; };
use crate::gui::ArcProvider;
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
enum AutoRunType { enum AutoRunType {
@ -153,7 +153,7 @@ pub fn show(config: &Arc<RwLock<Config>>) -> Result<(), Error> {
loop { loop {
let selection_result = gui::show( let selection_result = gui::show(
Arc::clone(&config), config,
Arc::clone(&arc_provider), Arc::clone(&arc_provider),
Some(Arc::new(Mutex::new(DefaultItemFactory::new()))), Some(Arc::new(Mutex::new(DefaultItemFactory::new()))),
Some( Some(

View file

@ -52,7 +52,9 @@ impl ItemProvider<String> for DMenuProvider {
/// # Errors /// # Errors
/// ///
/// Forwards errors from the gui. See `gui::show` for details. /// Forwards errors from the gui. See `gui::show` for details.
pub fn show(config: Arc<RwLock<Config>>) -> Result<(), Error> { /// # Panics
/// When failing to unwrap the arc lock
pub fn show(config: &Arc<RwLock<Config>>) -> Result<(), Error> {
let provider = Arc::new(Mutex::new(DMenuProvider::new( let provider = Arc::new(Mutex::new(DMenuProvider::new(
&config.read().unwrap().sort_order(), &config.read().unwrap().sort_order(),
))); )));

View file

@ -219,17 +219,12 @@ pub(crate) fn update_drun_cache_and_run<T: Clone>(
/// # Errors /// # Errors
/// ///
/// Will return `Err` if it was not able to spawn the process /// Will return `Err` if it was not able to spawn the process
pub fn show(config: Arc<RwLock<Config>>) -> Result<(), Error> { /// # Panics
/// When failing to unwrap the arc lock
pub fn show(config: &Arc<RwLock<Config>>) -> Result<(), Error> {
let provider = Arc::new(Mutex::new(DRunProvider::new((), &config.read().unwrap()))); let provider = Arc::new(Mutex::new(DRunProvider::new((), &config.read().unwrap())));
let arc_provider = Arc::clone(&provider) as ArcProvider<()>; let arc_provider = Arc::clone(&provider) as ArcProvider<()>;
let selection_result = gui::show( let selection_result = gui::show(config, arc_provider, None, None, ExpandMode::Verbatim, None);
config.clone(),
arc_provider,
None,
None,
ExpandMode::Verbatim,
None,
);
match selection_result { match selection_result {
Ok(s) => { Ok(s) => {
let p = provider.lock().unwrap(); let p = provider.lock().unwrap();

View file

@ -62,7 +62,9 @@ impl ItemProvider<String> for EmojiProvider {
/// # Errors /// # Errors
/// ///
/// Forwards errors from the gui. See `gui::show` for details. /// Forwards errors from the gui. See `gui::show` for details.
pub fn show(config: Arc<RwLock<Config>>) -> Result<(), Error> { /// # Panics
/// When failing to unwrap the arc lock
pub fn show(config: &Arc<RwLock<Config>>) -> Result<(), Error> {
let cfg = config.read().unwrap(); let cfg = config.read().unwrap();
let provider = Arc::new(Mutex::new(EmojiProvider::new( let provider = Arc::new(Mutex::new(EmojiProvider::new(
&cfg.sort_order(), &cfg.sort_order(),
@ -70,14 +72,7 @@ pub fn show(config: Arc<RwLock<Config>>) -> Result<(), Error> {
))); )));
drop(cfg); drop(cfg);
let selection_result = gui::show( let selection_result = gui::show(config, provider, None, None, ExpandMode::Verbatim, None)?;
config.clone(),
provider,
None,
None,
ExpandMode::Verbatim,
None,
)?;
match selection_result.menu.data { match selection_result.menu.data {
None => Err(Error::MissingAction), None => Err(Error::MissingAction),
Some(action) => copy_to_clipboard(action, None), Some(action) => copy_to_clipboard(action, None),

View file

@ -200,7 +200,7 @@ impl<T: Clone> ItemProvider<T> for FileItemProvider<T> {
/// ///
/// # Panics /// # Panics
/// In case an internal regex does not parse anymore, this should never happen /// In case an internal regex does not parse anymore, this should never happen
pub fn show(config: Arc<RwLock<Config>>) -> Result<(), Error> { pub fn show(config: &Arc<RwLock<Config>>) -> Result<(), Error> {
let provider = Arc::new(Mutex::new(FileItemProvider::new( let provider = Arc::new(Mutex::new(FileItemProvider::new(
0, 0,
config.read().unwrap().sort_order(), config.read().unwrap().sort_order(),
@ -208,7 +208,7 @@ pub fn show(config: Arc<RwLock<Config>>) -> Result<(), Error> {
// todo ues a arc instead of cloning the config // todo ues a arc instead of cloning the config
let selection_result = gui::show( let selection_result = gui::show(
config.clone(), config,
provider, provider,
None, None,
Some(vec![Regex::new("^\\$\\w+").unwrap()]), Some(vec![Regex::new("^\\$\\w+").unwrap()]),

View file

@ -248,7 +248,9 @@ fn calc(input: &str) -> String {
} }
/// Shows the math mode /// Shows the math mode
pub fn show(config: Arc<RwLock<Config>>) { /// # Panics
/// When failing to unwrap the arc lock
pub fn show(config: &Arc<RwLock<Config>>) {
let mut calc: Vec<MenuItem<()>> = vec![]; let mut calc: Vec<MenuItem<()>> = vec![];
let provider = Arc::new(Mutex::new(MathProvider::new(()))); let provider = Arc::new(Mutex::new(MathProvider::new(())));
let factory: ArcFactory<()> = Arc::new(Mutex::new(DefaultItemFactory::new())); let factory: ArcFactory<()> = Arc::new(Mutex::new(DefaultItemFactory::new()));
@ -256,7 +258,7 @@ pub fn show(config: Arc<RwLock<Config>>) {
loop { loop {
provider.lock().unwrap().add_elements(&mut calc.clone()); provider.lock().unwrap().add_elements(&mut calc.clone());
let selection_result = gui::show( let selection_result = gui::show(
config.clone(), config,
Arc::clone(&arc_provider), Arc::clone(&arc_provider),
Some(Arc::clone(&factory)), Some(Arc::clone(&factory)),
None, None,

View file

@ -134,18 +134,13 @@ fn update_run_cache_and_run<T: Clone>(
/// # Errors /// # Errors
/// ///
/// Will return `Err` if it was not able to spawn the process /// Will return `Err` if it was not able to spawn the process
pub fn show(config: Arc<RwLock<Config>>) -> Result<(), Error> { /// # Panics
/// When failing to unwrap the arc lock
pub fn show(config: &Arc<RwLock<Config>>) -> Result<(), Error> {
let provider = Arc::new(Mutex::new(RunProvider::new(&config.read().unwrap())?)); let provider = Arc::new(Mutex::new(RunProvider::new(&config.read().unwrap())?));
let arc_provider = Arc::clone(&provider) as ArcProvider<()>; let arc_provider = Arc::clone(&provider) as ArcProvider<()>;
let selection_result = gui::show( let selection_result = gui::show(config, arc_provider, None, None, ExpandMode::Verbatim, None);
config,
arc_provider,
None,
None,
ExpandMode::Verbatim,
None,
);
match selection_result { match selection_result {
Ok(s) => { Ok(s) => {
let prov = provider.lock().unwrap(); let prov = provider.lock().unwrap();

View file

@ -54,14 +54,16 @@ impl<T: Clone> ItemProvider<T> for SearchProvider<T> {
/// # Errors /// # Errors
/// ///
/// Forwards errors from the gui. See `gui::show` for details. /// Forwards errors from the gui. See `gui::show` for details.
pub fn show(config: Arc<RwLock<Config>>) -> Result<(), Error> { /// # Panics
/// When failing to unwrap the arc lock
pub fn show(config: &Arc<RwLock<Config>>) -> Result<(), Error> {
let provider = Arc::new(Mutex::new(SearchProvider::new( let provider = Arc::new(Mutex::new(SearchProvider::new(
(), (),
config.read().unwrap().search_query(), config.read().unwrap().search_query(),
))); )));
let factory: ArcFactory<()> = Arc::new(Mutex::new(DefaultItemFactory::new())); let factory: ArcFactory<()> = Arc::new(Mutex::new(DefaultItemFactory::new()));
let selection_result = gui::show( let selection_result = gui::show(
config.clone(), config,
provider, provider,
Some(factory), Some(factory),
None, None,

View file

@ -94,19 +94,14 @@ pub(crate) fn launch<T: Clone>(menu_item: &MenuItem<T>, config: &Config) -> Resu
/// Will return `Err` /// Will return `Err`
/// * if it was not able to spawn the process /// * if it was not able to spawn the process
/// * if it didn't find a terminal /// * if it didn't find a terminal
pub fn show(config: Arc<RwLock<Config>>) -> Result<(), Error> { /// # Panics
/// When failing to unwrap the arc lock
pub fn show(config: &Arc<RwLock<Config>>) -> Result<(), Error> {
let provider = Arc::new(Mutex::new(SshProvider::new( let provider = Arc::new(Mutex::new(SshProvider::new(
0, 0,
&config.read().unwrap().sort_order(), &config.read().unwrap().sort_order(),
))); )));
let selection_result = gui::show( let selection_result = gui::show(config, provider, None, None, ExpandMode::Verbatim, None);
Arc::clone(&config),
provider,
None,
None,
ExpandMode::Verbatim,
None,
);
if let Ok(mi) = selection_result { if let Ok(mi) = selection_result {
launch(&mi.menu, &config.read().unwrap())?; launch(&mi.menu, &config.read().unwrap())?;
} else { } else {

View file

@ -1,13 +1,12 @@
use clap::Parser;
use std::fmt::Display;
use std::str::FromStr;
use std::{ use std::{
env, env,
sync::{Arc, RwLock}, sync::{Arc, RwLock},
}; };
use std::fmt::Display;
use std::str::FromStr;
use clap::Parser;
use worf::{Error, config, desktop::fork_if_configured, modes}; use worf::{Error, config, desktop::fork_if_configured, modes};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum Mode { pub enum Mode {
/// searches `$PATH` for executables and allows them to be run by selecting them. /// searches `$PATH` for executables and allows them to be run by selecting them.
@ -109,18 +108,18 @@ fn main() {
let cfg_arc = Arc::new(RwLock::new(config.worf)); let cfg_arc = Arc::new(RwLock::new(config.worf));
let result = match config.show { let result = match config.show {
Mode::Run => modes::run::show(cfg_arc), Mode::Run => modes::run::show(&cfg_arc),
Mode::Drun => modes::drun::show(cfg_arc), Mode::Drun => modes::drun::show(&cfg_arc),
Mode::Dmenu => modes::dmenu::show(cfg_arc), Mode::Dmenu => modes::dmenu::show(&cfg_arc),
Mode::File => modes::file::show(cfg_arc), Mode::File => modes::file::show(&cfg_arc),
Mode::Math => { Mode::Math => {
modes::math::show(cfg_arc); modes::math::show(&cfg_arc);
Ok(()) Ok(())
} }
Mode::Ssh => modes::ssh::show(cfg_arc), Mode::Ssh => modes::ssh::show(&cfg_arc),
Mode::Emoji => modes::emoji::show(cfg_arc), Mode::Emoji => modes::emoji::show(&cfg_arc),
Mode::Auto => modes::auto::show(&cfg_arc), Mode::Auto => modes::auto::show(&cfg_arc),
Mode::WebSearch => modes::search::show(cfg_arc), Mode::WebSearch => modes::search::show(&cfg_arc),
}; };
if let Err(err) = result { if let Err(err) = result {