From c944c049a0e3fd5be77a25fe9ba46e7459c89a3f Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sun, 18 Sep 2022 12:37:42 -0400 Subject: [PATCH 01/23] feat: Add default modifier to config struct --- README.md | 3 +- lefthk/src/config.rs | 137 +++++++++++++++++++++---------------------- 2 files changed, 69 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 74e6583..0db0f67 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,14 @@ The configuration file should be created in ~/.config/lefthk/ and called config. Example config: ```ron Config( + default_modifier: ["Mod4", "Shift"], keybinds: [ Keybind( command: Execute("st -e htop"), - modifier: ["Mod4", "Shift"], key: Key("x"), ), Keybind( command: Executes(["st -e htop", "st -e bpytop"]), - modifier: ["Mod4", "Shift"], key: Keys(["x", "m"]), ), Keybind( diff --git a/lefthk/src/config.rs b/lefthk/src/config.rs index 94c7e22..3b6f3bb 100644 --- a/lefthk/src/config.rs +++ b/lefthk/src/config.rs @@ -2,7 +2,7 @@ use crate::errors::{LeftError, Result}; use lefthk_core::config::Command as core_command; use lefthk_core::config::Keybind as core_keybind; use serde::{Deserialize, Serialize}; -use std::{convert::TryFrom, fs, path::Path}; +use std::{fs, path::Path}; use xdg::BaseDirectories; #[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)] @@ -42,76 +42,73 @@ macro_rules! get_keys { #[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)] pub struct Keybind { pub command: Command, - pub modifier: Vec, + pub modifier: Option>, pub key: Key, } -impl TryFrom for Vec { - type Error = LeftError; - - fn try_from(kb: Keybind) -> Result { - let command_key_pairs: Vec<(core_command, String)> = match kb.command { - Command::Chord(children) if !children.is_empty() => { - let key = get_key!(kb.key); - let children = children - .iter() - .filter_map(|kb| match TryFrom::try_from(kb.clone()) { - Ok(keybinds) => Some::>(keybinds), - Err(err) => { - tracing::error!("Invalid key binding: {}\n{:?}", err, kb); - None - } - }) - .flatten() - .collect(); +fn try_from(kb: Keybind, default_modifier: Vec) -> Result> { + let command_key_pairs: Vec<(core_command, String)> = match kb.command { + Command::Chord(children) if !children.is_empty() => { + let key = get_key!(kb.key); + let children = children + .iter() + .filter_map(|kb| match try_from(kb.clone(), default_modifier.clone()) { + Ok(keybinds) => Some::>(keybinds), + Err(err) => { + tracing::error!("Invalid key binding: {}\n{:?}", err, kb); + None + } + }) + .flatten() + .collect(); - vec![(core_command::Chord(children), key)] - } - Command::Chord(_) => return Err(LeftError::ChildrenNotFound), - Command::Execute(value) if !value.is_empty() => { - let keys = get_key!(kb.key); - vec![(core_command::Execute(value), keys)] - } - Command::Execute(_) => return Err(LeftError::ValueNotFound), - Command::Executes(values) if !values.is_empty() => { - let keys = get_keys!(kb.key); - if keys.len() != values.len() { - return Err(LeftError::NumberOfKeysDiffersFromValues); - } - values - .iter() - .enumerate() - .map(|(i, v)| (core_command::Execute(v.to_owned()), keys[i].clone())) - .collect() - } - Command::Executes(_) => return Err(LeftError::ValuesNotFound), - Command::ExitChord => { - let keys = get_key!(kb.key); - vec![(core_command::ExitChord, keys)] - } - Command::Reload => { - let keys = get_key!(kb.key); - vec![(core_command::Reload, keys)] - } - Command::Kill => { - let keys = get_key!(kb.key); - vec![(core_command::Kill, keys)] + vec![(core_command::Chord(children), key)] + } + Command::Chord(_) => return Err(LeftError::ChildrenNotFound), + Command::Execute(value) if !value.is_empty() => { + let keys = get_key!(kb.key); + vec![(core_command::Execute(value), keys)] + } + Command::Execute(_) => return Err(LeftError::ValueNotFound), + Command::Executes(values) if !values.is_empty() => { + let keys = get_keys!(kb.key); + if keys.len() != values.len() { + return Err(LeftError::NumberOfKeysDiffersFromValues); } - }; - let keybinds = command_key_pairs - .iter() - .map(|(c, k)| core_keybind { - command: c.clone(), - modifier: kb.modifier.clone(), - key: k.to_owned(), - }) - .collect(); - Ok(keybinds) - } + values + .iter() + .enumerate() + .map(|(i, v)| (core_command::Execute(v.to_owned()), keys[i].clone())) + .collect() + } + Command::Executes(_) => return Err(LeftError::ValuesNotFound), + Command::ExitChord => { + let keys = get_key!(kb.key); + vec![(core_command::ExitChord, keys)] + } + Command::Reload => { + let keys = get_key!(kb.key); + vec![(core_command::Reload, keys)] + } + Command::Kill => { + let keys = get_key!(kb.key); + vec![(core_command::Kill, keys)] + } + }; + let keybinds = command_key_pairs + .iter() + .map(|(c, k)| core_keybind { + command: c.clone(), + modifier: kb.modifier.clone().unwrap_or(default_modifier.clone()), + key: k.to_owned(), + }) + .collect(); + Ok(keybinds) } #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] pub struct Config { + default_modifier: Vec, keybinds: Vec, } @@ -119,13 +116,15 @@ impl lefthk_core::config::Config for Config { fn mapped_bindings(&self) -> Vec { self.keybinds .iter() - .filter_map(|kb| match TryFrom::try_from(kb.clone()) { - Ok(keybinds) => Some::>(keybinds), - Err(err) => { - tracing::error!("Invalid key binding: {}\n{:?}", err, kb); - None - } - }) + .filter_map( + |kb| match try_from(kb.clone(), self.default_modifier.clone()) { + Ok(keybinds) => Some::>(keybinds), + Err(err) => { + tracing::error!("Invalid key binding: {}\n{:?}", err, kb); + None + } + }, + ) .flatten() .collect() } From fa15a03bf7f36c4d2ee89b67965b16035820955e Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sun, 18 Sep 2022 13:48:41 -0400 Subject: [PATCH 02/23] feat: Add test to new parse config --- lefthk/src/config.rs | 71 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/lefthk/src/config.rs b/lefthk/src/config.rs index 3b6f3bb..d6412a0 100644 --- a/lefthk/src/config.rs +++ b/lefthk/src/config.rs @@ -130,12 +130,9 @@ impl lefthk_core::config::Config for Config { } } -pub fn load() -> Result { - let path = BaseDirectories::with_prefix(lefthk_core::LEFTHK_DIR_NAME)?; - fs::create_dir_all(&path.get_config_home())?; - let file_name = path.place_config_file("config.ron")?; - if Path::new(&file_name).exists() { - let contents = fs::read_to_string(file_name)?; +impl Config { + pub fn from_string(contents: String) -> Result { + println!("{contents}"); let mut config: Config = ron::from_str(&contents)?; let global_exit_chord = config .keybinds @@ -151,6 +148,16 @@ pub fn load() -> Result { return Ok(config); } +} + +pub fn load() -> Result { + let path = BaseDirectories::with_prefix(lefthk_core::LEFTHK_DIR_NAME)?; + fs::create_dir_all(&path.get_config_home())?; + let file_name = path.place_config_file("config.ron")?; + if Path::new(&file_name).exists() { + let contents = fs::read_to_string(file_name)?; + return Ok(Config::from_string(contents)?); + } Err(LeftError::NoConfigFound) } @@ -174,3 +181,55 @@ fn propagate_exit_chord(chords: Vec<&mut Keybind>, exit_chord: Option) } } } + +#[cfg(test)] +mod test { + use lefthk_core::config::Config; + + use super::Config as Cfg; + + #[test] + fn parse_config() { + let config = r#"#![enable(implicit_some)] +Config( + default_modifier: ["Mod4", "Shift"], + keybinds: [ + Keybind( + command: Execute("st -e htop"), + key: Key("x"), + ), + Keybind( + command: Executes(["st -e htop", "st -e bpytop"]), + key: Keys(["x", "m"]), + ), + Keybind( + command: Chord([ + Keybind( + command: Execute("st -e htop"), + modifier: ["Mod4"], + key: Key("c"), + ), + ]), + modifier: ["Mod4"], + key: Key("c"), + ), + ] +)"#; + let conf = Cfg::from_string(config.to_string()); + println!("{:?}", conf.as_ref().err()); + assert!(conf.is_ok()); + let conf = conf.unwrap(); + println!("{conf:?}"); + assert_eq!(conf.default_modifier.len(), 2); + assert_eq!( + conf.default_modifier, + vec!["Mod4".to_string(), "Shift".to_string()] + ); + let conf_mapped = conf.mapped_bindings(); + let first_keybind = conf_mapped.get(0).unwrap(); + assert_eq!(first_keybind.modifier.len(), 2); + let first_modifier = first_keybind.modifier.clone(); + assert_eq!(first_modifier.len(), 2); + assert_eq!(first_modifier, conf.default_modifier); + } +} From 1ba8c6b996f3f50f81d1e773b848d57d46c682a3 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sun, 18 Sep 2022 14:03:02 -0400 Subject: [PATCH 03/23] feat: make better test --- README.md | 13 ++----------- lefthk/src/config.rs | 27 +++++++++++---------------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 0db0f67..255aeec 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ LeftHK - A hotkey daemon written in Rust The configuration file should be created in ~/.config/lefthk/ and called config.ron. If the configuration file is not created the program will exit. Example config: ```ron +#![enable(implicit_some)] Config( default_modifier: ["Mod4", "Shift"], keybinds: [ @@ -14,17 +15,7 @@ Config( key: Key("x"), ), Keybind( - command: Executes(["st -e htop", "st -e bpytop"]), - key: Keys(["x", "m"]), - ), - Keybind( - command: Chord([ - Keybind( - command: Execute("st -e htop"), - modifier: ["Mod4"], - key: Key("c"), - ), - ]), + command: Execute("st -e btm"), modifier: ["Mod4"], key: Key("c"), ), diff --git a/lefthk/src/config.rs b/lefthk/src/config.rs index d6412a0..a780845 100644 --- a/lefthk/src/config.rs +++ b/lefthk/src/config.rs @@ -199,17 +199,7 @@ Config( key: Key("x"), ), Keybind( - command: Executes(["st -e htop", "st -e bpytop"]), - key: Keys(["x", "m"]), - ), - Keybind( - command: Chord([ - Keybind( - command: Execute("st -e htop"), - modifier: ["Mod4"], - key: Key("c"), - ), - ]), + command: Execute("st -e btm"), modifier: ["Mod4"], key: Key("c"), ), @@ -226,10 +216,15 @@ Config( vec!["Mod4".to_string(), "Shift".to_string()] ); let conf_mapped = conf.mapped_bindings(); - let first_keybind = conf_mapped.get(0).unwrap(); - assert_eq!(first_keybind.modifier.len(), 2); - let first_modifier = first_keybind.modifier.clone(); - assert_eq!(first_modifier.len(), 2); - assert_eq!(first_modifier, conf.default_modifier); + + // Verify default modifier implementation + let default_keybind = conf_mapped.first().unwrap(); + assert_eq!(default_keybind.modifier.len(), 2); + assert_eq!(default_keybind.modifier, conf.default_modifier); + + // Verify own implementation + let custom_keybind = conf_mapped.last().unwrap(); + assert_eq!(custom_keybind.modifier.len(), 1); + assert_eq!(custom_keybind.modifier, vec!["Mod4".to_string()]); } } From 060a50603e208474ba8a340cfd8cff8156474e3d Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sun, 18 Sep 2022 14:03:38 -0400 Subject: [PATCH 04/23] feat: fix readme --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 255aeec..24f9726 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,17 @@ Config( key: Key("x"), ), Keybind( - command: Execute("st -e btm"), + command: Executes(["st -e htop", "st -e bpytop"]), + key: Keys(["x", "m"]), + ), + Keybind( + command: Chord([ + Keybind( + command: Execute("st -e htop"), + modifier: ["Mod4"], + key: Key("c"), + ), + ]), modifier: ["Mod4"], key: Key("c"), ), From 9d5a0cac5b18d3e56019fa556a9e2a6d4270ee70 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sun, 18 Sep 2022 14:07:18 -0400 Subject: [PATCH 05/23] feat: add more test for parser --- lefthk/src/config.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lefthk/src/config.rs b/lefthk/src/config.rs index a780845..d95f7ae 100644 --- a/lefthk/src/config.rs +++ b/lefthk/src/config.rs @@ -227,4 +227,34 @@ Config( assert_eq!(custom_keybind.modifier.len(), 1); assert_eq!(custom_keybind.modifier, vec!["Mod4".to_string()]); } + + #[test] + fn parse_empty_config() { + let config = r#"Config( + default_modifier: ["Mod4", "Shift"], + keybinds: [] +)"#; + let conf = Cfg::from_string(config.to_string()); + println!("{:?}", conf.as_ref().err()); + assert!(conf.is_ok()); + let conf = conf.unwrap(); + println!("{conf:?}"); + assert_eq!(conf.default_modifier.len(), 2); + assert_eq!( + conf.default_modifier, + vec!["Mod4".to_string(), "Shift".to_string()] + ); + let conf_mapped = conf.mapped_bindings(); + + // Verify implementation + assert_eq!(conf_mapped.len(), 0); + } + + #[test] + fn parse_none_config() { + // Define empty string + let conf = Cfg::from_string(String::new()); + println!("{:?}", conf.as_ref().err()); + assert!(conf.is_err()); + } } From 27a9b359631a79e325ac88d4716cbfaf58179abb Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sun, 18 Sep 2022 14:10:25 -0400 Subject: [PATCH 06/23] feat: add subkeybind validation test --- lefthk/src/config.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lefthk/src/config.rs b/lefthk/src/config.rs index d95f7ae..37b90c4 100644 --- a/lefthk/src/config.rs +++ b/lefthk/src/config.rs @@ -257,4 +257,41 @@ Config( println!("{:?}", conf.as_ref().err()); assert!(conf.is_err()); } + + #[test] + fn parse_sub_keybind_config() { + let config = r#"#![enable(implicit_some)] +Config( + default_modifier: ["Mod4", "Shift"], + keybinds: [ + Keybind( + command: Chord([ + Keybind( + command: Execute("st -e htop"), + modifier: ["Mod4"], + key: Key("c"), + ), + ]), + modifier: ["Mod4"], + key: Key("c"), + ), + ] +)"#; + let conf = Cfg::from_string(config.to_string()); + println!("{:?}", conf.as_ref().err()); + assert!(conf.is_ok()); + let conf = conf.unwrap(); + println!("{conf:?}"); + assert_eq!(conf.default_modifier.len(), 2); + assert_eq!( + conf.default_modifier, + vec!["Mod4".to_string(), "Shift".to_string()] + ); + let conf_mapped = conf.mapped_bindings(); + + // Verify default modifier implementation + let default_keybind = conf_mapped.first().unwrap(); + assert_eq!(default_keybind.modifier.len(), 2); + assert_eq!(default_keybind.modifier, conf.default_modifier); + } } From a961aec2351a9b866ee9585ffc2c5728b24bed10 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sun, 18 Sep 2022 14:23:40 -0400 Subject: [PATCH 07/23] feat: remove print lines from test and add chord command test --- lefthk/src/config.rs | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/lefthk/src/config.rs b/lefthk/src/config.rs index 37b90c4..19bd570 100644 --- a/lefthk/src/config.rs +++ b/lefthk/src/config.rs @@ -184,7 +184,7 @@ fn propagate_exit_chord(chords: Vec<&mut Keybind>, exit_chord: Option) #[cfg(test)] mod test { - use lefthk_core::config::Config; + use lefthk_core::config::{Command, Config, Keybind}; use super::Config as Cfg; @@ -206,10 +206,8 @@ Config( ] )"#; let conf = Cfg::from_string(config.to_string()); - println!("{:?}", conf.as_ref().err()); assert!(conf.is_ok()); let conf = conf.unwrap(); - println!("{conf:?}"); assert_eq!(conf.default_modifier.len(), 2); assert_eq!( conf.default_modifier, @@ -235,10 +233,8 @@ Config( keybinds: [] )"#; let conf = Cfg::from_string(config.to_string()); - println!("{:?}", conf.as_ref().err()); assert!(conf.is_ok()); let conf = conf.unwrap(); - println!("{conf:?}"); assert_eq!(conf.default_modifier.len(), 2); assert_eq!( conf.default_modifier, @@ -254,7 +250,6 @@ Config( fn parse_none_config() { // Define empty string let conf = Cfg::from_string(String::new()); - println!("{:?}", conf.as_ref().err()); assert!(conf.is_err()); } @@ -275,6 +270,15 @@ Config( modifier: ["Mod4"], key: Key("c"), ), + Keybind( + command: Chord([ + Keybind( + command: Execute("st -e htop"), + key: Key("c"), + ), + ]), + key: Key("c"), + ), ] )"#; let conf = Cfg::from_string(config.to_string()); @@ -290,8 +294,29 @@ Config( let conf_mapped = conf.mapped_bindings(); // Verify default modifier implementation - let default_keybind = conf_mapped.first().unwrap(); + let default_keybind = conf_mapped.last().unwrap(); assert_eq!(default_keybind.modifier.len(), 2); assert_eq!(default_keybind.modifier, conf.default_modifier); + assert_eq!( + default_keybind.command, + Command::Chord(vec![Keybind { + command: Command::Execute("st -e htop".to_string()), + modifier: vec!["Mod4".to_string(), "Shift".to_string()], + key: "c".to_string(), + }]) + ); + + // Verify custom modifier implementation + let custom_keybind = conf_mapped.first().unwrap(); + assert_eq!(custom_keybind.modifier.len(), 1); + assert_eq!(custom_keybind.modifier, vec!["Mod4".to_string()]); + assert_eq!( + custom_keybind.command, + Command::Chord(vec![Keybind { + command: Command::Execute("st -e htop".to_string()), + modifier: vec!["Mod4".to_string()], + key: "c".to_string(), + }]) + ); } } From a731958bbc40ab65fc5eb7e794ee4ef17e210fd2 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sun, 18 Sep 2022 14:24:59 -0400 Subject: [PATCH 08/23] feat: remove print lines from test --- lefthk/src/config.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/lefthk/src/config.rs b/lefthk/src/config.rs index 19bd570..ce68ce9 100644 --- a/lefthk/src/config.rs +++ b/lefthk/src/config.rs @@ -282,10 +282,8 @@ Config( ] )"#; let conf = Cfg::from_string(config.to_string()); - println!("{:?}", conf.as_ref().err()); assert!(conf.is_ok()); let conf = conf.unwrap(); - println!("{conf:?}"); assert_eq!(conf.default_modifier.len(), 2); assert_eq!( conf.default_modifier, From a801d6eafc7111cde8808589e3f050bf124bfefa Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sun, 18 Sep 2022 14:26:58 -0400 Subject: [PATCH 09/23] fix: clippy warnings --- lefthk-core/src/child.rs | 2 +- lefthk-core/src/worker.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lefthk-core/src/child.rs b/lefthk-core/src/child.rs index 9f6faea..69994eb 100644 --- a/lefthk-core/src/child.rs +++ b/lefthk-core/src/child.rs @@ -32,7 +32,7 @@ impl Children { let (guard, _task_guard) = oneshot::channel(); let task_notify = Arc::new(Notify::new()); let notify = task_notify.clone(); - let mut signals = Signals::new(&[signal::SIGCHLD]).expect("Couldn't setup signals."); + let mut signals = Signals::new([signal::SIGCHLD]).expect("Couldn't setup signals."); tokio::task::spawn_blocking(move || loop { if guard.is_closed() { return; diff --git a/lefthk-core/src/worker.rs b/lefthk-core/src/worker.rs index cc71bf9..0ba4e80 100644 --- a/lefthk-core/src/worker.rs +++ b/lefthk-core/src/worker.rs @@ -141,7 +141,7 @@ impl Worker { pub fn exec(&mut self, command: &str) -> Error { let child = Command::new("sh") .arg("-c") - .arg(&command) + .arg(command) .stdin(Stdio::null()) .stdout(Stdio::null()) .spawn()?; From 244f3554094e033be24bf6e6027dec898a581d3e Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Tue, 4 Oct 2022 20:32:29 -0400 Subject: [PATCH 10/23] Move individual tests to test file --- lefthk/src/config.rs | 141 +--------------------------------- lefthk/src/tests.rs | 179 ++++++++++++++++++++++++++++++++----------- 2 files changed, 135 insertions(+), 185 deletions(-) diff --git a/lefthk/src/config.rs b/lefthk/src/config.rs index ce68ce9..22c205d 100644 --- a/lefthk/src/config.rs +++ b/lefthk/src/config.rs @@ -108,8 +108,8 @@ fn try_from(kb: Keybind, default_modifier: Vec) -> Result, - keybinds: Vec, + pub default_modifier: Vec, + pub keybinds: Vec, } impl lefthk_core::config::Config for Config { @@ -181,140 +181,3 @@ fn propagate_exit_chord(chords: Vec<&mut Keybind>, exit_chord: Option) } } } - -#[cfg(test)] -mod test { - use lefthk_core::config::{Command, Config, Keybind}; - - use super::Config as Cfg; - - #[test] - fn parse_config() { - let config = r#"#![enable(implicit_some)] -Config( - default_modifier: ["Mod4", "Shift"], - keybinds: [ - Keybind( - command: Execute("st -e htop"), - key: Key("x"), - ), - Keybind( - command: Execute("st -e btm"), - modifier: ["Mod4"], - key: Key("c"), - ), - ] -)"#; - let conf = Cfg::from_string(config.to_string()); - assert!(conf.is_ok()); - let conf = conf.unwrap(); - assert_eq!(conf.default_modifier.len(), 2); - assert_eq!( - conf.default_modifier, - vec!["Mod4".to_string(), "Shift".to_string()] - ); - let conf_mapped = conf.mapped_bindings(); - - // Verify default modifier implementation - let default_keybind = conf_mapped.first().unwrap(); - assert_eq!(default_keybind.modifier.len(), 2); - assert_eq!(default_keybind.modifier, conf.default_modifier); - - // Verify own implementation - let custom_keybind = conf_mapped.last().unwrap(); - assert_eq!(custom_keybind.modifier.len(), 1); - assert_eq!(custom_keybind.modifier, vec!["Mod4".to_string()]); - } - - #[test] - fn parse_empty_config() { - let config = r#"Config( - default_modifier: ["Mod4", "Shift"], - keybinds: [] -)"#; - let conf = Cfg::from_string(config.to_string()); - assert!(conf.is_ok()); - let conf = conf.unwrap(); - assert_eq!(conf.default_modifier.len(), 2); - assert_eq!( - conf.default_modifier, - vec!["Mod4".to_string(), "Shift".to_string()] - ); - let conf_mapped = conf.mapped_bindings(); - - // Verify implementation - assert_eq!(conf_mapped.len(), 0); - } - - #[test] - fn parse_none_config() { - // Define empty string - let conf = Cfg::from_string(String::new()); - assert!(conf.is_err()); - } - - #[test] - fn parse_sub_keybind_config() { - let config = r#"#![enable(implicit_some)] -Config( - default_modifier: ["Mod4", "Shift"], - keybinds: [ - Keybind( - command: Chord([ - Keybind( - command: Execute("st -e htop"), - modifier: ["Mod4"], - key: Key("c"), - ), - ]), - modifier: ["Mod4"], - key: Key("c"), - ), - Keybind( - command: Chord([ - Keybind( - command: Execute("st -e htop"), - key: Key("c"), - ), - ]), - key: Key("c"), - ), - ] -)"#; - let conf = Cfg::from_string(config.to_string()); - assert!(conf.is_ok()); - let conf = conf.unwrap(); - assert_eq!(conf.default_modifier.len(), 2); - assert_eq!( - conf.default_modifier, - vec!["Mod4".to_string(), "Shift".to_string()] - ); - let conf_mapped = conf.mapped_bindings(); - - // Verify default modifier implementation - let default_keybind = conf_mapped.last().unwrap(); - assert_eq!(default_keybind.modifier.len(), 2); - assert_eq!(default_keybind.modifier, conf.default_modifier); - assert_eq!( - default_keybind.command, - Command::Chord(vec![Keybind { - command: Command::Execute("st -e htop".to_string()), - modifier: vec!["Mod4".to_string(), "Shift".to_string()], - key: "c".to_string(), - }]) - ); - - // Verify custom modifier implementation - let custom_keybind = conf_mapped.first().unwrap(); - assert_eq!(custom_keybind.modifier.len(), 1); - assert_eq!(custom_keybind.modifier, vec!["Mod4".to_string()]); - assert_eq!( - custom_keybind.command, - Command::Chord(vec![Keybind { - command: Command::Execute("st -e htop".to_string()), - modifier: vec!["Mod4".to_string()], - key: "c".to_string(), - }]) - ); - } -} diff --git a/lefthk/src/tests.rs b/lefthk/src/tests.rs index 9ae3c01..f6f7a31 100644 --- a/lefthk/src/tests.rs +++ b/lefthk/src/tests.rs @@ -1,50 +1,137 @@ /// Config Testing #[cfg(test)] mod config { - // use crate::{ - // config::{Command, Keybind}, - // errors::Result, - // }; - // use std::convert::TryFrom; - - // #[test] - // fn parse_kdl_nodes() { - // let execute_kb: Keybind = Keybind { - // command: Command::Execute, - // value: Some("st".to_owned()), - // modifier: vec!["Mod4".to_owned()], - // key: "x".to_owned(), - // children: None, - // }; - // let reload_kb: Keybind = Keybind { - // command: Command::Reload, - // value: None, - // modifier: vec!["Mod4".to_owned()], - // key: "x".to_owned(), - // children: None, - // }; - // let kill_kb: Keybind = Keybind { - // command: Command::Kill, - // value: None, - // modifier: vec!["Mod4".to_owned()], - // key: "x".to_owned(), - // children: None, - // }; - // let exit_chord_kb: Keybind = Keybind { - // command: Command::ExitChord, - // value: None, - // modifier: vec!["Mod4".to_owned()], - // key: "x".to_owned(), - // children: None, - // }; - // let chord_kb: Keybind = Keybind { - // command: Command::Chord, - // value: None, - // modifier: vec!["Mod4".to_owned()], - // key: "x".to_owned(), - // children: Some(vec![execute_kb.clone(), reload_kb.clone(), kill_kb.clone()]), - // }; - // let keybinds: Vec = vec![chord_kb, execute_kb, exit_chord_kb, reload_kb, kill_kb]; - // assert_eq!(parsed_keybands, keybinds); - // } + use lefthk_core::config::{Command, Config, Keybind}; + + use crate::config::Config as Cfg; + + #[test] + fn parse_config() { + let config = r#"#![enable(implicit_some)] +Config( + default_modifier: ["Mod4", "Shift"], + keybinds: [ + Keybind( + command: Execute("st -e htop"), + key: Key("x"), + ), + Keybind( + command: Execute("st -e btm"), + modifier: ["Mod4"], + key: Key("c"), + ), + ] +)"#; + let conf = Cfg::from_string(config.to_string()); + assert!(conf.is_ok()); + let conf = conf.unwrap(); + assert_eq!(conf.default_modifier.len(), 2); + assert_eq!( + conf.default_modifier, + vec!["Mod4".to_string(), "Shift".to_string()] + ); + let conf_mapped = conf.mapped_bindings(); + + // Verify default modifier implementation + let default_keybind = conf_mapped.first().unwrap(); + assert_eq!(default_keybind.modifier.len(), 2); + assert_eq!(default_keybind.modifier, conf.default_modifier); + + // Verify own implementation + let custom_keybind = conf_mapped.last().unwrap(); + assert_eq!(custom_keybind.modifier.len(), 1); + assert_eq!(custom_keybind.modifier, vec!["Mod4".to_string()]); + } + + #[test] + fn parse_empty_config() { + let config = r#"Config( + default_modifier: ["Mod4", "Shift"], + keybinds: [] +)"#; + let conf = Cfg::from_string(config.to_string()); + assert!(conf.is_ok()); + let conf = conf.unwrap(); + assert_eq!(conf.default_modifier.len(), 2); + assert_eq!( + conf.default_modifier, + vec!["Mod4".to_string(), "Shift".to_string()] + ); + let conf_mapped = conf.mapped_bindings(); + + // Verify implementation + assert_eq!(conf_mapped.len(), 0); + } + + #[test] + fn parse_none_config() { + // Define empty string + let conf = Cfg::from_string(String::new()); + assert!(conf.is_err()); + } + + #[test] + fn parse_sub_keybind_config() { + let config = r#"#![enable(implicit_some)] +Config( + default_modifier: ["Mod4", "Shift"], + keybinds: [ + Keybind( + command: Chord([ + Keybind( + command: Execute("st -e htop"), + modifier: ["Mod4"], + key: Key("c"), + ), + ]), + modifier: ["Mod4"], + key: Key("c"), + ), + Keybind( + command: Chord([ + Keybind( + command: Execute("st -e htop"), + key: Key("c"), + ), + ]), + key: Key("c"), + ), + ] +)"#; + let conf = Cfg::from_string(config.to_string()); + assert!(conf.is_ok()); + let conf = conf.unwrap(); + assert_eq!(conf.default_modifier.len(), 2); + assert_eq!( + conf.default_modifier, + vec!["Mod4".to_string(), "Shift".to_string()] + ); + let conf_mapped = conf.mapped_bindings(); + + // Verify default modifier implementation + let default_keybind = conf_mapped.last().unwrap(); + assert_eq!(default_keybind.modifier.len(), 2); + assert_eq!(default_keybind.modifier, conf.default_modifier); + assert_eq!( + default_keybind.command, + Command::Chord(vec![Keybind { + command: Command::Execute("st -e htop".to_string()), + modifier: vec!["Mod4".to_string(), "Shift".to_string()], + key: "c".to_string(), + }]) + ); + + // Verify custom modifier implementation + let custom_keybind = conf_mapped.first().unwrap(); + assert_eq!(custom_keybind.modifier.len(), 1); + assert_eq!(custom_keybind.modifier, vec!["Mod4".to_string()]); + assert_eq!( + custom_keybind.command, + Command::Chord(vec![Keybind { + command: Command::Execute("st -e htop".to_string()), + modifier: vec!["Mod4".to_string()], + key: "c".to_string(), + }]) + ); + } } From d3363e8f6474f044cc517ef6fe924c5efb9ea4b4 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Tue, 4 Oct 2022 21:11:16 -0400 Subject: [PATCH 11/23] fix clippy warnings and format --- lefthk/src/config.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lefthk/src/config.rs b/lefthk/src/config.rs index 22c205d..fcf3585 100644 --- a/lefthk/src/config.rs +++ b/lefthk/src/config.rs @@ -99,7 +99,10 @@ fn try_from(kb: Keybind, default_modifier: Vec) -> Result Result { let file_name = path.place_config_file("config.ron")?; if Path::new(&file_name).exists() { let contents = fs::read_to_string(file_name)?; - return Ok(Config::from_string(contents)?); + Config::from_string(contents)?; } Err(LeftError::NoConfigFound) } From b3e5ffdda0d36a76385d5988a3c5d5005cc6768c Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sun, 16 Oct 2022 18:27:25 -0400 Subject: [PATCH 12/23] feat: Impl TryFrom for Config from String --- lefthk/src/config.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lefthk/src/config.rs b/lefthk/src/config.rs index fcf3585..01a79e1 100644 --- a/lefthk/src/config.rs +++ b/lefthk/src/config.rs @@ -133,9 +133,10 @@ impl lefthk_core::config::Config for Config { } } -impl Config { - pub fn from_string(contents: String) -> Result { - println!("{contents}"); +impl TryFrom for Config { + type Error = LeftError; + + fn try_from(contents: String) -> Result { let mut config: Config = ron::from_str(&contents)?; let global_exit_chord = config .keybinds @@ -159,7 +160,7 @@ pub fn load() -> Result { let file_name = path.place_config_file("config.ron")?; if Path::new(&file_name).exists() { let contents = fs::read_to_string(file_name)?; - Config::from_string(contents)?; + Config::try_from(contents)?; } Err(LeftError::NoConfigFound) } From 13267895bdc79565f963350bb25a151c29deadcd Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sun, 16 Oct 2022 18:31:21 -0400 Subject: [PATCH 13/23] fix: Fix tests, change from_string to try_from --- lefthk/src/tests.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lefthk/src/tests.rs b/lefthk/src/tests.rs index f6f7a31..d51e816 100644 --- a/lefthk/src/tests.rs +++ b/lefthk/src/tests.rs @@ -22,7 +22,7 @@ Config( ), ] )"#; - let conf = Cfg::from_string(config.to_string()); + let conf = Cfg::try_from(config.to_string()); assert!(conf.is_ok()); let conf = conf.unwrap(); assert_eq!(conf.default_modifier.len(), 2); @@ -49,7 +49,7 @@ Config( default_modifier: ["Mod4", "Shift"], keybinds: [] )"#; - let conf = Cfg::from_string(config.to_string()); + let conf = Cfg::try_from(config.to_string()); assert!(conf.is_ok()); let conf = conf.unwrap(); assert_eq!(conf.default_modifier.len(), 2); @@ -66,7 +66,7 @@ Config( #[test] fn parse_none_config() { // Define empty string - let conf = Cfg::from_string(String::new()); + let conf = Cfg::try_from(String::new()); assert!(conf.is_err()); } @@ -98,7 +98,7 @@ Config( ), ] )"#; - let conf = Cfg::from_string(config.to_string()); + let conf = Cfg::try_from(config.to_string()); assert!(conf.is_ok()); let conf = conf.unwrap(); assert_eq!(conf.default_modifier.len(), 2); From a99d83c8354dfbfd07b484dd4a57ecb719db6626 Mon Sep 17 00:00:00 2001 From: VuiMuich Date: Wed, 14 Dec 2022 16:48:06 +0100 Subject: [PATCH 14/23] make clippy (pedantic) happy --- lefthk-core/src/child.rs | 6 +++--- lefthk-core/src/config/command/execute.rs | 4 ++-- lefthk-core/src/config/command/mod.rs | 16 +++++++++++----- lefthk-core/src/ipc.rs | 8 ++++---- lefthk-core/src/worker/mod.rs | 2 +- lefthk-core/src/xwrap.rs | 6 ++++-- lefthk/src/config/keybind.rs | 7 +++---- lefthk/src/config/mod.rs | 10 +++++++--- lefthk/src/main.rs | 15 ++++++++------- 9 files changed, 43 insertions(+), 31 deletions(-) diff --git a/lefthk-core/src/child.rs b/lefthk-core/src/child.rs index b713fae..85a500d 100644 --- a/lefthk-core/src/child.rs +++ b/lefthk-core/src/child.rs @@ -29,10 +29,10 @@ impl Default for Children { impl Children { pub fn new() -> Self { - let (guard, _task_guard) = oneshot::channel(); + let (guard, task_guard) = oneshot::channel(); let task_notify = Arc::new(Notify::new()); let notify = task_notify.clone(); - let mut signals = Signals::new(&[signal::SIGCHLD]).expect("Couldn't setup signals."); + let mut signals = Signals::new([signal::SIGCHLD]).expect("Couldn't setup signals."); tokio::task::spawn_blocking(move || loop { if guard.is_closed() { return; @@ -45,7 +45,7 @@ impl Children { Self { task_notify, - _task_guard, + _task_guard: task_guard, inner: HashMap::default(), } } diff --git a/lefthk-core/src/config/command/execute.rs b/lefthk-core/src/config/command/execute.rs index d742d30..b37fdb0 100644 --- a/lefthk-core/src/config/command/execute.rs +++ b/lefthk-core/src/config/command/execute.rs @@ -16,7 +16,7 @@ inventory::submit! {DenormalizeCommandFunction::new::()} pub struct Execute(String); impl Execute { - pub fn new(shell_command: T) -> Self { + pub fn new(shell_command: &T) -> Self { Self(shell_command.to_string()) } } @@ -59,7 +59,7 @@ mod tests { #[test] fn normalize_process() { - let command = Execute::new("echo 'I use Arch by the way'"); + let command = Execute::new(&"echo 'I use Arch by the way'"); let normalized = command.normalize(); let denormalized = Execute::denormalize(&normalized).unwrap(); diff --git a/lefthk-core/src/config/command/mod.rs b/lefthk-core/src/config/command/mod.rs index c8acd8e..a394a4f 100644 --- a/lefthk-core/src/config/command/mod.rs +++ b/lefthk-core/src/config/command/mod.rs @@ -16,9 +16,9 @@ pub use self::{chord::Chord, execute::Execute, exit_chord::ExitChord, kill::Kill inventory::collect!(DenormalizeCommandFunction); -// When adding a command: -// - a command has to submit itself to the inventory -// - write a test that it's conversion between normalizel and denormalize works +/// When adding a command: +/// - a command has to submit itself to the inventory +/// - write a test that it's conversion between normalizel and denormalize works pub trait Command: std::fmt::Debug { fn normalize(&self) -> NormalizedCommand; @@ -26,14 +26,20 @@ pub trait Command: std::fmt::Debug { where Self: Sized; + /// # Errors + /// + /// This errors when the command cannot be executed by the worker fn execute(&self, worker: &mut Worker) -> Error; fn get_name(&self) -> &'static str; } -pub fn denormalize(normalized_command: NormalizedCommand) -> Result> { +/// # Errors +/// +/// This errors when the command cannot be matched with the known commands +pub fn denormalize(normalized_command: &NormalizedCommand) -> Result> { for denormalizer in inventory::iter:: { - if let Some(denormalized_command) = (denormalizer.0)(&normalized_command) { + if let Some(denormalized_command) = (denormalizer.0)(normalized_command) { return Ok(denormalized_command); } } diff --git a/lefthk-core/src/ipc.rs b/lefthk-core/src/ipc.rs index b998fea..dff6750 100644 --- a/lefthk-core/src/ipc.rs +++ b/lefthk-core/src/ipc.rs @@ -21,7 +21,7 @@ impl Drop for Pipe { // Open fifo for write to unblock pending open for read operation that prevents tokio runtime // from shutting down. - let _ = std::fs::OpenOptions::new() + let _unplock_pending_open = std::fs::OpenOptions::new() .write(true) .custom_flags(nix::fcntl::OFlag::O_NONBLOCK.bits()) .open(self.pipe_file.clone()); @@ -35,7 +35,7 @@ impl Pipe { /// Will error if unable to `mkfifo`, likely a filesystem issue /// such as inadequate permissions. pub async fn new(pipe_file: PathBuf) -> Result { - let _ = fs::remove_file(pipe_file.as_path()).await; + let _pipe_reset = fs::remove_file(pipe_file.as_path()).await; nix::unistd::mkfifo(&pipe_file, nix::sys::stat::Mode::S_IRWXU)?; let path = pipe_file.clone(); @@ -61,7 +61,7 @@ impl Pipe { pub async fn get_next_command(&mut self) -> Option> { if let Some(normalized_command) = self.rx.recv().await { - return command::denormalize(normalized_command).ok(); + return command::denormalize(&normalized_command).ok(); } None } @@ -74,7 +74,7 @@ async fn read_from_pipe<'a>(pipe_file: &Path, tx: &mpsc::UnboundedSender Self { const SERVER: mio::Token = mio::Token(0); let xlib = errors::exit_on_error!(xlib::Xlib::open()); @@ -36,7 +37,7 @@ impl XWrap { assert!(!display.is_null(), "Null pointer in display"); let fd = unsafe { (xlib.XConnectionNumber)(display) }; - let (guard, _task_guard) = oneshot::channel(); + let (guard, task_guard) = oneshot::channel(); let notify = Arc::new(Notify::new()); let task_notify = notify.clone(); let mut poll = errors::exit_on_error!(mio::Poll::new()); @@ -69,7 +70,7 @@ impl XWrap { display, root, task_notify, - _task_guard, + _task_guard: task_guard, }; // Setup cached keymap/modifier information, otherwise MappingNotify might never be called @@ -80,6 +81,7 @@ impl XWrap { // This is allowed for now as const extern fns // are not yet stable (1.56.0, 16 Sept 2021) // see issue #64926 for more information + // also this is the reason for #[allow(clippy::items_after_statements)] above #[allow(clippy::missing_const_for_fn)] extern "C" fn on_error_from_xlib( _: *mut xlib::Display, diff --git a/lefthk/src/config/keybind.rs b/lefthk/src/config/keybind.rs index 8b34e2c..31cbc01 100644 --- a/lefthk/src/config/keybind.rs +++ b/lefthk/src/config/keybind.rs @@ -60,7 +60,7 @@ impl TryFrom for Vec { Command::Chord(_) => return Err(LeftError::ChildrenNotFound), Command::Execute(value) if !value.is_empty() => { let keys = get_key!(kb.key); - vec![(Box::new(command_mod::Execute::new(value)), keys)] + vec![(Box::new(command_mod::Execute::new(&value)), keys)] } Command::Execute(_) => return Err(LeftError::ValueNotFound), Command::Executes(values) if !values.is_empty() => { @@ -73,8 +73,7 @@ impl TryFrom for Vec { .enumerate() .map(|(i, v)| { ( - Box::new(command_mod::Execute::new(v.to_owned())) - as Box, + Box::new(command_mod::Execute::new(&v)) as Box, keys[i].clone(), ) }) @@ -99,7 +98,7 @@ impl TryFrom for Vec { .map(|(c, k)| core_keybind { command: c.normalize(), modifier: kb.modifier.clone(), - key: k.to_owned(), + key: k.clone(), }) .collect(); Ok(keybinds) diff --git a/lefthk/src/config/mod.rs b/lefthk/src/config/mod.rs index a75aaa2..6cc28d1 100644 --- a/lefthk/src/config/mod.rs +++ b/lefthk/src/config/mod.rs @@ -34,6 +34,10 @@ impl lefthk_core::config::Config for Config { } } +/// # Errors +/// +/// Thes will error when no config file is found, most propably as system or +/// user error for provideng a wrong path pub fn load() -> Result { let path = BaseDirectories::with_prefix(lefthk_core::LEFTHK_DIR_NAME)?; fs::create_dir_all(&path.get_config_home())?; @@ -51,14 +55,14 @@ pub fn load() -> Result { .iter_mut() .filter(|kb| matches!(kb.command, Command::Chord(_))) .collect(); - propagate_exit_chord(chords, global_exit_chord); + propagate_exit_chord(chords, &global_exit_chord); return Ok(config); } Err(LeftError::NoConfigFound) } -fn propagate_exit_chord(chords: Vec<&mut Keybind>, exit_chord: Option) { +fn propagate_exit_chord(chords: Vec<&mut Keybind>, exit_chord: &Option) { for chord in chords { if let Command::Chord(children) = &mut chord.command { if !children.iter().any(|kb| kb.command == Command::ExitChord) { @@ -74,7 +78,7 @@ fn propagate_exit_chord(chords: Vec<&mut Keybind>, exit_chord: Option) .iter_mut() .filter(|kb| matches!(kb.command, Command::Chord(_))) .collect(); - propagate_exit_chord(sub_chords, parent_exit_chord); + propagate_exit_chord(sub_chords, &parent_exit_chord); } } } diff --git a/lefthk/src/main.rs b/lefthk/src/main.rs index d663003..d59c70e 100644 --- a/lefthk/src/main.rs +++ b/lefthk/src/main.rs @@ -25,9 +25,9 @@ fn main() { tracing::info!("lefthk booted!"); if matches.contains_id(QUIT_COMMAND) { - send_command(command::Kill::new()); + send_command(&command::Kill::new()); } else if matches.contains_id(RELOAD_COMMAND) { - send_command(command::Reload::new()); + send_command(&command::Reload::new()); } else { let mut old_config = None; let path = @@ -35,13 +35,14 @@ fn main() { loop { let config = match config::load() { Ok(config) => config, - Err(err) => match old_config { - Some(config) => config, - None => { + Err(err) => { + if let Some(config) = old_config { + config + } else { tracing::error!("Unable to load new config due to error: {}", err); return; } - }, + } }; let kill_requested = AtomicBool::new(false); let completed = std::panic::catch_unwind(|| { @@ -65,7 +66,7 @@ fn main() { } } -fn send_command(command: impl Command) { +fn send_command(command: &impl Command) { let path = errors::exit_on_error!(BaseDirectories::with_prefix(lefthk_core::LEFTHK_DIR_NAME)); let pipe_name = Pipe::pipe_name(); let pipe_file = errors::exit_on_error!(path.place_runtime_file(pipe_name)); From 7b6cb8544f149b758db06e6d053422a017a04992 Mon Sep 17 00:00:00 2001 From: VuiMuich Date: Wed, 14 Dec 2022 23:46:06 +0100 Subject: [PATCH 15/23] fix remaining merge issues --- lefthk/src/config.rs | 187 ----------------------------------- lefthk/src/config/command.rs | 2 +- lefthk/src/config/keybind.rs | 145 +++++++++++++-------------- lefthk/src/config/mod.rs | 41 +++++--- lefthk/src/main.rs | 21 ++-- 5 files changed, 109 insertions(+), 287 deletions(-) delete mode 100644 lefthk/src/config.rs diff --git a/lefthk/src/config.rs b/lefthk/src/config.rs deleted file mode 100644 index 01a79e1..0000000 --- a/lefthk/src/config.rs +++ /dev/null @@ -1,187 +0,0 @@ -use crate::errors::{LeftError, Result}; -use lefthk_core::config::Command as core_command; -use lefthk_core::config::Keybind as core_keybind; -use serde::{Deserialize, Serialize}; -use std::{fs, path::Path}; -use xdg::BaseDirectories; - -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)] -pub enum Command { - Chord(Vec), - Execute(String), - Executes(Vec), - ExitChord, - Reload, - Kill, -} - -#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)] -pub enum Key { - Key(String), - Keys(Vec), -} - -macro_rules! get_key { - ($expr:expr $(,)?) => { - match $expr { - Key::Key(key) => key, - Key::Keys(_) => return Err(LeftError::SingleKeyNeeded), - } - }; -} - -macro_rules! get_keys { - ($expr:expr $(,)?) => { - match $expr { - Key::Key(_) => return Err(LeftError::MultipleKeysNeeded), - Key::Keys(keys) => keys, - } - }; -} - -#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)] -pub struct Keybind { - pub command: Command, - pub modifier: Option>, - pub key: Key, -} - -fn try_from(kb: Keybind, default_modifier: Vec) -> Result> { - let command_key_pairs: Vec<(core_command, String)> = match kb.command { - Command::Chord(children) if !children.is_empty() => { - let key = get_key!(kb.key); - let children = children - .iter() - .filter_map(|kb| match try_from(kb.clone(), default_modifier.clone()) { - Ok(keybinds) => Some::>(keybinds), - Err(err) => { - tracing::error!("Invalid key binding: {}\n{:?}", err, kb); - None - } - }) - .flatten() - .collect(); - - vec![(core_command::Chord(children), key)] - } - Command::Chord(_) => return Err(LeftError::ChildrenNotFound), - Command::Execute(value) if !value.is_empty() => { - let keys = get_key!(kb.key); - vec![(core_command::Execute(value), keys)] - } - Command::Execute(_) => return Err(LeftError::ValueNotFound), - Command::Executes(values) if !values.is_empty() => { - let keys = get_keys!(kb.key); - if keys.len() != values.len() { - return Err(LeftError::NumberOfKeysDiffersFromValues); - } - values - .iter() - .enumerate() - .map(|(i, v)| (core_command::Execute(v.to_owned()), keys[i].clone())) - .collect() - } - Command::Executes(_) => return Err(LeftError::ValuesNotFound), - Command::ExitChord => { - let keys = get_key!(kb.key); - vec![(core_command::ExitChord, keys)] - } - Command::Reload => { - let keys = get_key!(kb.key); - vec![(core_command::Reload, keys)] - } - Command::Kill => { - let keys = get_key!(kb.key); - vec![(core_command::Kill, keys)] - } - }; - let keybinds = command_key_pairs - .iter() - .map(|(c, k)| core_keybind { - command: c.clone(), - modifier: kb - .modifier - .clone() - .unwrap_or_else(|| default_modifier.clone()), - key: k.to_owned(), - }) - .collect(); - Ok(keybinds) -} - -#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] -pub struct Config { - pub default_modifier: Vec, - pub keybinds: Vec, -} - -impl lefthk_core::config::Config for Config { - fn mapped_bindings(&self) -> Vec { - self.keybinds - .iter() - .filter_map( - |kb| match try_from(kb.clone(), self.default_modifier.clone()) { - Ok(keybinds) => Some::>(keybinds), - Err(err) => { - tracing::error!("Invalid key binding: {}\n{:?}", err, kb); - None - } - }, - ) - .flatten() - .collect() - } -} - -impl TryFrom for Config { - type Error = LeftError; - - fn try_from(contents: String) -> Result { - let mut config: Config = ron::from_str(&contents)?; - let global_exit_chord = config - .keybinds - .iter() - .find(|kb| matches!(kb.command, Command::ExitChord)) - .cloned(); - let chords: Vec<&mut Keybind> = config - .keybinds - .iter_mut() - .filter(|kb| matches!(kb.command, Command::Chord(_))) - .collect(); - propagate_exit_chord(chords, global_exit_chord); - - Ok(config) - } -} - -pub fn load() -> Result { - let path = BaseDirectories::with_prefix(lefthk_core::LEFTHK_DIR_NAME)?; - fs::create_dir_all(&path.get_config_home())?; - let file_name = path.place_config_file("config.ron")?; - if Path::new(&file_name).exists() { - let contents = fs::read_to_string(file_name)?; - Config::try_from(contents)?; - } - Err(LeftError::NoConfigFound) -} - -fn propagate_exit_chord(chords: Vec<&mut Keybind>, exit_chord: Option) { - for chord in chords { - if let Command::Chord(children) = &mut chord.command { - if !children.iter().any(|kb| kb.command == Command::ExitChord) { - if let Some(ref exit_chord) = exit_chord { - children.push(exit_chord.clone()); - } - } - let parent_exit_chord = children - .iter() - .find(|kb| matches!(kb.command, Command::ExitChord)) - .cloned(); - let sub_chords = children - .iter_mut() - .filter(|kb| matches!(kb.command, Command::Chord(_))) - .collect(); - propagate_exit_chord(sub_chords, parent_exit_chord); - } - } -} diff --git a/lefthk/src/config/command.rs b/lefthk/src/config/command.rs index 265ba0b..0f5e1cd 100644 --- a/lefthk/src/config/command.rs +++ b/lefthk/src/config/command.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use super::keybind::Keybind; +use crate::config::keybind::Keybind; #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)] pub enum Command { diff --git a/lefthk/src/config/keybind.rs b/lefthk/src/config/keybind.rs index 8b34e2c..f4c028d 100644 --- a/lefthk/src/config/keybind.rs +++ b/lefthk/src/config/keybind.rs @@ -1,13 +1,10 @@ use crate::errors::{LeftError, Result}; -use lefthk_core::config::command as command_mod; -use lefthk_core::config::Command as core_command; -use lefthk_core::config::Keybind as core_keybind; -use serde::Deserialize; -use serde::Serialize; +use lefthk_core::config::{ + command as command_mod, Command as core_command, Keybind as core_keybind, +}; +use serde::{Deserialize, Serialize}; -use super::{command::Command, key::Key}; - -use std::convert::TryFrom; +use crate::config::{command::Command, key::Key}; macro_rules! get_key { ($expr:expr $(,)?) => { @@ -32,76 +29,74 @@ pub type Keybinds = Vec; #[derive(Debug, PartialEq, Clone, Eq, Serialize, Deserialize)] pub struct Keybind { pub command: Command, - pub modifier: Vec, + pub modifier: Option>, pub key: Key, } -impl TryFrom for Vec { - type Error = LeftError; - - fn try_from(kb: Keybind) -> Result { - let command_key_pairs: Vec<(Box, String)> = match kb.command { - Command::Chord(children) if !children.is_empty() => { - let key = get_key!(kb.key); - let children = children - .iter() - .filter_map(|kb| match TryFrom::try_from(kb.clone()) { - Ok(keybinds) => Some::>(keybinds), - Err(err) => { - tracing::error!("Invalid key binding: {}\n{:?}", err, kb); - None - } - }) - .flatten() - .collect(); +pub(crate) fn try_from(kb: Keybind, default_modifier: Vec) -> Result> { + let command_key_pairs: Vec<(Box, String)> = match kb.command { + Command::Chord(children) if !children.is_empty() => { + let key = get_key!(kb.key); + let children = children + .iter() + .filter_map(|kb| match try_from(kb.clone(), default_modifier.clone()) { + Ok(keybinds) => Some::>(keybinds), + Err(err) => { + tracing::error!("Invalid key binding: {}\n{:?}", err, kb); + None + } + }) + .flatten() + .collect(); - vec![(Box::new(command_mod::Chord::new(children)), key)] - } - Command::Chord(_) => return Err(LeftError::ChildrenNotFound), - Command::Execute(value) if !value.is_empty() => { - let keys = get_key!(kb.key); - vec![(Box::new(command_mod::Execute::new(value)), keys)] - } - Command::Execute(_) => return Err(LeftError::ValueNotFound), - Command::Executes(values) if !values.is_empty() => { - let keys = get_keys!(kb.key); - if keys.len() != values.len() { - return Err(LeftError::NumberOfKeysDiffersFromValues); - } - values - .iter() - .enumerate() - .map(|(i, v)| { - ( - Box::new(command_mod::Execute::new(v.to_owned())) - as Box, - keys[i].clone(), - ) - }) - .collect() - } - Command::Executes(_) => return Err(LeftError::ValuesNotFound), - Command::ExitChord => { - let keys = get_key!(kb.key); - vec![(Box::new(command_mod::ExitChord::new()), keys)] - } - Command::Reload => { - let keys = get_key!(kb.key); - vec![(Box::new(command_mod::Reload::new()), keys)] - } - Command::Kill => { - let keys = get_key!(kb.key); - vec![(Box::new(command_mod::Kill::new()), keys)] + vec![(Box::new(command_mod::Chord::new(children)), key)] + } + Command::Chord(_) => return Err(LeftError::ChildrenNotFound), + Command::Execute(value) if !value.is_empty() => { + let keys = get_key!(kb.key); + vec![((Box::new(command_mod::Execute::new(&value))), keys)] + } + Command::Execute(_) => return Err(LeftError::ValueNotFound), + Command::Executes(values) if !values.is_empty() => { + let keys = get_keys!(kb.key); + if keys.len() != values.len() { + return Err(LeftError::NumberOfKeysDiffersFromValues); } - }; - let keybinds = command_key_pairs - .iter() - .map(|(c, k)| core_keybind { - command: c.normalize(), - modifier: kb.modifier.clone(), - key: k.to_owned(), - }) - .collect(); - Ok(keybinds) - } + values + .iter() + .enumerate() + .map(|(i, v)| { + ( + Box::new(command_mod::Execute::new(&v)) as Box, + keys[i].clone(), + ) + }) + .collect() + } + Command::Executes(_) => return Err(LeftError::ValuesNotFound), + Command::ExitChord => { + let keys = get_key!(kb.key); + vec![((Box::new(command_mod::ExitChord::new())), keys)] + } + Command::Reload => { + let keys = get_key!(kb.key); + vec![((Box::new(command_mod::Reload::new())), keys)] + } + Command::Kill => { + let keys = get_key!(kb.key); + vec![((Box::new(command_mod::Kill::new())), keys)] + } + }; + let keybinds = command_key_pairs + .iter() + .map(|(c, k)| core_keybind { + command: c.normalize(), + modifier: kb + .modifier + .clone() + .unwrap_or_else(|| default_modifier.clone()), + key: k.to_owned(), + }) + .collect(); + Ok(keybinds) } diff --git a/lefthk/src/config/mod.rs b/lefthk/src/config/mod.rs index a75aaa2..509aeef 100644 --- a/lefthk/src/config/mod.rs +++ b/lefthk/src/config/mod.rs @@ -5,7 +5,7 @@ pub mod keybind; use crate::errors::{LeftError, Result}; use serde::{Deserialize, Serialize}; -use std::{convert::TryFrom, fs, path::Path}; +use std::{fs, path::Path}; use xdg::BaseDirectories; use self::{ @@ -15,6 +15,7 @@ use self::{ #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)] pub struct Config { + default_modifier: Vec, keybinds: Keybinds, } @@ -22,24 +23,24 @@ impl lefthk_core::config::Config for Config { fn mapped_bindings(&self) -> Vec { self.keybinds .iter() - .filter_map(|kb| match TryFrom::try_from(kb.clone()) { - Ok(keybinds) => Some::>(keybinds), - Err(err) => { - tracing::error!("Invalid key binding: {}\n{:?}", err, kb); - None - } - }) + .filter_map( + |kb| match keybind::try_from(kb.clone(), self.default_modifier.clone()) { + Ok(keybinds) => Some::>(keybinds), + Err(err) => { + tracing::error!("Invalid key binding: {}\n{:?}", err, kb); + None + } + }, + ) .flatten() .collect() } } -pub fn load() -> Result { - let path = BaseDirectories::with_prefix(lefthk_core::LEFTHK_DIR_NAME)?; - fs::create_dir_all(&path.get_config_home())?; - let file_name = path.place_config_file("config.ron")?; - if Path::new(&file_name).exists() { - let contents = fs::read_to_string(file_name)?; +impl TryFrom for Config { + type Error = LeftError; + + fn try_from(contents: String) -> Result { let mut config: Config = ron::from_str(&contents)?; let global_exit_chord = config .keybinds @@ -53,7 +54,17 @@ pub fn load() -> Result { .collect(); propagate_exit_chord(chords, global_exit_chord); - return Ok(config); + Ok(config) + } +} + +pub fn load() -> Result { + let path = BaseDirectories::with_prefix(lefthk_core::LEFTHK_DIR_NAME)?; + fs::create_dir_all(&path.get_config_home())?; + let file_name = path.place_config_file("config.ron")?; + if Path::new(&file_name).exists() { + let contents = fs::read_to_string(file_name)?; + Config::try_from(contents)?; } Err(LeftError::NoConfigFound) } diff --git a/lefthk/src/main.rs b/lefthk/src/main.rs index d663003..84ed3aa 100644 --- a/lefthk/src/main.rs +++ b/lefthk/src/main.rs @@ -1,18 +1,21 @@ use crate::errors::LeftError; use clap::{App, Arg}; -use lefthk_core::config::{command, Command}; -use lefthk_core::ipc::Pipe; -use lefthk_core::worker::Status; -use lefthk_core::{config::Config, worker::Worker}; -use std::fs; -use std::io::Write; -use std::sync::atomic::{AtomicBool, Ordering}; +use lefthk_core::{ + config::{command, Command, Config}, + ipc::Pipe, + worker::{Status, Worker}, +}; +use std::{ + fs, + io::Write, + sync::atomic::{AtomicBool, Ordering}, +}; use xdg::BaseDirectories; use tracing_subscriber::{filter::EnvFilter, filter::LevelFilter, fmt, layer::SubscriberExt}; -pub mod config; -pub mod errors; +pub(crate) mod config; +pub(crate) mod errors; mod tests; const QUIT_COMMAND: &str = "quit"; From 5b29df7886f40a1daab39a4587e08e08d386debb Mon Sep 17 00:00:00 2001 From: VuiMuich Date: Thu, 15 Dec 2022 00:19:43 +0100 Subject: [PATCH 16/23] make clippy happy again --- lefthk/src/config/keybind.rs | 8 ++++---- lefthk/src/config/mod.rs | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lefthk/src/config/keybind.rs b/lefthk/src/config/keybind.rs index f4c028d..1edc6fc 100644 --- a/lefthk/src/config/keybind.rs +++ b/lefthk/src/config/keybind.rs @@ -33,13 +33,13 @@ pub struct Keybind { pub key: Key, } -pub(crate) fn try_from(kb: Keybind, default_modifier: Vec) -> Result> { +pub(crate) fn try_from(kb: Keybind, default_modifier: &[String]) -> Result> { let command_key_pairs: Vec<(Box, String)> = match kb.command { Command::Chord(children) if !children.is_empty() => { let key = get_key!(kb.key); let children = children .iter() - .filter_map(|kb| match try_from(kb.clone(), default_modifier.clone()) { + .filter_map(|kb| match try_from(kb.clone(), default_modifier) { Ok(keybinds) => Some::>(keybinds), Err(err) => { tracing::error!("Invalid key binding: {}\n{:?}", err, kb); @@ -94,8 +94,8 @@ pub(crate) fn try_from(kb: Keybind, default_modifier: Vec) -> Result Some::>(keybinds), Err(err) => { tracing::error!("Invalid key binding: {}\n{:?}", err, kb); @@ -58,6 +58,9 @@ impl TryFrom for Config { } } +/// # Errors +/// +/// This errors, when no Config is found at the path pub fn load() -> Result { let path = BaseDirectories::with_prefix(lefthk_core::LEFTHK_DIR_NAME)?; fs::create_dir_all(&path.get_config_home())?; From 55683d1e241b2e1131294bd852d79025d3ce2e7b Mon Sep 17 00:00:00 2001 From: VuiMuich Date: Thu, 15 Dec 2022 01:11:58 +0100 Subject: [PATCH 17/23] fix part of the tests --- lefthk/src/config/mod.rs | 2 +- lefthk/src/tests.rs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lefthk/src/config/mod.rs b/lefthk/src/config/mod.rs index b53a71c..646ca06 100644 --- a/lefthk/src/config/mod.rs +++ b/lefthk/src/config/mod.rs @@ -15,7 +15,7 @@ use self::{ #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)] pub struct Config { - default_modifier: Vec, + pub(crate) default_modifier: Vec, keybinds: Keybinds, } diff --git a/lefthk/src/tests.rs b/lefthk/src/tests.rs index d51e816..7475dc6 100644 --- a/lefthk/src/tests.rs +++ b/lefthk/src/tests.rs @@ -1,9 +1,9 @@ /// Config Testing #[cfg(test)] mod config { - use lefthk_core::config::{Command, Config, Keybind}; + use lefthk_core::config::{Command, Config}; - use crate::config::Config as Cfg; + use crate::config::{self, command::Command as Cmd, keybind::Keybind as Kbd, Config as Cfg}; #[test] fn parse_config() { @@ -114,10 +114,10 @@ Config( assert_eq!(default_keybind.modifier, conf.default_modifier); assert_eq!( default_keybind.command, - Command::Chord(vec![Keybind { - command: Command::Execute("st -e htop".to_string()), - modifier: vec!["Mod4".to_string(), "Shift".to_string()], - key: "c".to_string(), + Cmd::Chord(vec![Kbd { + command: Cmd::Execute("st -e htop".to_string()), + modifier: Some(vec!["Mod4".to_string(), "Shift".to_string()]), + key: config::key::Key::Key("c".to_string()), }]) ); @@ -127,10 +127,10 @@ Config( assert_eq!(custom_keybind.modifier, vec!["Mod4".to_string()]); assert_eq!( custom_keybind.command, - Command::Chord(vec![Keybind { - command: Command::Execute("st -e htop".to_string()), - modifier: vec!["Mod4".to_string()], - key: "c".to_string(), + Cmd::Chord(vec![Kbd { + command: Cmd::Execute("st -e htop".to_string()), + modifier: Some(vec!["Mod4".to_string()]), + key: config::key::Key::Key("c".to_string()), }]) ); } From ceee98e7f366f6d165ebc864198ba514135a7be9 Mon Sep 17 00:00:00 2001 From: VuiMuich Date: Tue, 27 Jun 2023 12:33:35 +0200 Subject: [PATCH 18/23] alias media keys --- lefthk-core/src/xkeysym_lookup.rs | 354 +++++++++++++++--------------- 1 file changed, 177 insertions(+), 177 deletions(-) diff --git a/lefthk-core/src/xkeysym_lookup.rs b/lefthk-core/src/xkeysym_lookup.rs index b915f3a..c479219 100644 --- a/lefthk-core/src/xkeysym_lookup.rs +++ b/lefthk-core/src/xkeysym_lookup.rs @@ -1040,183 +1040,183 @@ pub fn into_keysym(key: &str) -> Option { "hebrew_taw" => Some(XK_hebrew_taw), "hebrew_taf" => Some(XK_hebrew_taf), "Hebrew_switch" => Some(XK_Hebrew_switch), - "XF86XK_ModeLock" => Some(XF86XK_ModeLock), - "XF86XK_MonBrightnessUp" => Some(XF86XK_MonBrightnessUp), - "XF86XK_MonBrightnessDown" => Some(XF86XK_MonBrightnessDown), - "XF86XK_KbdLightOnOff" => Some(XF86XK_KbdLightOnOff), - "XF86XK_KbdBrightnessUp" => Some(XF86XK_KbdBrightnessUp), - "XF86XK_KbdBrightnessDown" => Some(XF86XK_KbdBrightnessDown), - "XF86XK_Standby" => Some(XF86XK_Standby), - "XF86XK_AudioLowerVolume" => Some(XF86XK_AudioLowerVolume), - "XF86XK_AudioMute" => Some(XF86XK_AudioMute), - "XF86XK_AudioRaiseVolume" => Some(XF86XK_AudioRaiseVolume), - "XF86XK_AudioPlay" => Some(XF86XK_AudioPlay), - "XF86XK_AudioStop" => Some(XF86XK_AudioStop), - "XF86XK_AudioPrev" => Some(XF86XK_AudioPrev), - "XF86XK_AudioNext" => Some(XF86XK_AudioNext), - "XF86XK_HomePage" => Some(XF86XK_HomePage), - "XF86XK_Mail" => Some(XF86XK_Mail), - "XF86XK_Start" => Some(XF86XK_Start), - "XF86XK_Search" => Some(XF86XK_Search), - "XF86XK_AudioRecord" => Some(XF86XK_AudioRecord), - "XF86XK_Calculator" => Some(XF86XK_Calculator), - "XF86XK_Memo" => Some(XF86XK_Memo), - "XF86XK_ToDoList" => Some(XF86XK_ToDoList), - "XF86XK_Calendar" => Some(XF86XK_Calendar), - "XF86XK_PowerDown" => Some(XF86XK_PowerDown), - "XF86XK_ContrastAdjust" => Some(XF86XK_ContrastAdjust), - "XF86XK_RockerUp" => Some(XF86XK_RockerUp), - "XF86XK_RockerDown" => Some(XF86XK_RockerDown), - "XF86XK_RockerEnter" => Some(XF86XK_RockerEnter), - "XF86XK_Back" => Some(XF86XK_Back), - "XF86XK_Forward" => Some(XF86XK_Forward), - "XF86XK_Stop" => Some(XF86XK_Stop), - "XF86XK_Refresh" => Some(XF86XK_Refresh), - "XF86XK_PowerOff" => Some(XF86XK_PowerOff), - "XF86XK_WakeUp" => Some(XF86XK_WakeUp), - "XF86XK_Eject" => Some(XF86XK_Eject), - "XF86XK_ScreenSaver" => Some(XF86XK_ScreenSaver), - "XF86XK_WWW" => Some(XF86XK_WWW), - "XF86XK_Sleep" => Some(XF86XK_Sleep), - "XF86XK_Favorites" => Some(XF86XK_Favorites), - "XF86XK_AudioPause" => Some(XF86XK_AudioPause), - "XF86XK_AudioMedia" => Some(XF86XK_AudioMedia), - "XF86XK_MyComputer" => Some(XF86XK_MyComputer), - "XF86XK_VendorHome" => Some(XF86XK_VendorHome), - "XF86XK_LightBulb" => Some(XF86XK_LightBulb), - "XF86XK_Shop" => Some(XF86XK_Shop), - "XF86XK_History" => Some(XF86XK_History), - "XF86XK_OpenURL" => Some(XF86XK_OpenURL), - "XF86XK_AddFavorite" => Some(XF86XK_AddFavorite), - "XF86XK_HotLinks" => Some(XF86XK_HotLinks), - "XF86XK_BrightnessAdjust" => Some(XF86XK_BrightnessAdjust), - "XF86XK_Finance" => Some(XF86XK_Finance), - "XF86XK_Community" => Some(XF86XK_Community), - "XF86XK_AudioRewind" => Some(XF86XK_AudioRewind), - "XF86XK_BackForward" => Some(XF86XK_BackForward), - "XF86XK_Launch0" => Some(XF86XK_Launch0), - "XF86XK_Launch1" => Some(XF86XK_Launch1), - "XF86XK_Launch2" => Some(XF86XK_Launch2), - "XF86XK_Launch3" => Some(XF86XK_Launch3), - "XF86XK_Launch4" => Some(XF86XK_Launch4), - "XF86XK_Launch5" => Some(XF86XK_Launch5), - "XF86XK_Launch6" => Some(XF86XK_Launch6), - "XF86XK_Launch7" => Some(XF86XK_Launch7), - "XF86XK_Launch8" => Some(XF86XK_Launch8), - "XF86XK_Launch9" => Some(XF86XK_Launch9), - "XF86XK_LaunchA" => Some(XF86XK_LaunchA), - "XF86XK_LaunchB" => Some(XF86XK_LaunchB), - "XF86XK_LaunchC" => Some(XF86XK_LaunchC), - "XF86XK_LaunchD" => Some(XF86XK_LaunchD), - "XF86XK_LaunchE" => Some(XF86XK_LaunchE), - "XF86XK_LaunchF" => Some(XF86XK_LaunchF), - "XF86XK_ApplicationLeft" => Some(XF86XK_ApplicationLeft), - "XF86XK_ApplicationRight" => Some(XF86XK_ApplicationRight), - "XF86XK_Book" => Some(XF86XK_Book), - "XF86XK_CD" => Some(XF86XK_CD), - "XF86XK_Calculater" => Some(XF86XK_Calculater), - "XF86XK_Clear" => Some(XF86XK_Clear), - "XF86XK_Close" => Some(XF86XK_Close), - "XF86XK_Copy" => Some(XF86XK_Copy), - "XF86XK_Cut" => Some(XF86XK_Cut), - "XF86XK_Display" => Some(XF86XK_Display), - "XF86XK_DOS" => Some(XF86XK_DOS), - "XF86XK_Documents" => Some(XF86XK_Documents), - "XF86XK_Excel" => Some(XF86XK_Excel), - "XF86XK_Explorer" => Some(XF86XK_Explorer), - "XF86XK_Game" => Some(XF86XK_Game), - "XF86XK_Go" => Some(XF86XK_Go), - "XF86XK_iTouch" => Some(XF86XK_iTouch), - "XF86XK_LogOff" => Some(XF86XK_LogOff), - "XF86XK_Market" => Some(XF86XK_Market), - "XF86XK_Meeting" => Some(XF86XK_Meeting), - "XF86XK_MenuKB" => Some(XF86XK_MenuKB), - "XF86XK_MenuPB" => Some(XF86XK_MenuPB), - "XF86XK_MySites" => Some(XF86XK_MySites), - "XF86XK_New" => Some(XF86XK_New), - "XF86XK_News" => Some(XF86XK_News), - "XF86XK_OfficeHome" => Some(XF86XK_OfficeHome), - "XF86XK_Open" => Some(XF86XK_Open), - "XF86XK_Option" => Some(XF86XK_Option), - "XF86XK_Paste" => Some(XF86XK_Paste), - "XF86XK_Phone" => Some(XF86XK_Phone), - "XF86XK_Q" => Some(XF86XK_Q), - "XF86XK_Reply" => Some(XF86XK_Reply), - "XF86XK_Reload" => Some(XF86XK_Reload), - "XF86XK_RotateWindows" => Some(XF86XK_RotateWindows), - "XF86XK_RotationPB" => Some(XF86XK_RotationPB), - "XF86XK_RotationKB" => Some(XF86XK_RotationKB), - "XF86XK_Save" => Some(XF86XK_Save), - "XF86XK_ScrollUp" => Some(XF86XK_ScrollUp), - "XF86XK_ScrollDown" => Some(XF86XK_ScrollDown), - "XF86XK_ScrollClick" => Some(XF86XK_ScrollClick), - "XF86XK_Send" => Some(XF86XK_Send), - "XF86XK_Spell" => Some(XF86XK_Spell), - "XF86XK_SplitScreen" => Some(XF86XK_SplitScreen), - "XF86XK_Support" => Some(XF86XK_Support), - "XF86XK_TaskPane" => Some(XF86XK_TaskPane), - "XF86XK_Terminal" => Some(XF86XK_Terminal), - "XF86XK_Tools" => Some(XF86XK_Tools), - "XF86XK_Travel" => Some(XF86XK_Travel), - "XF86XK_UserPB" => Some(XF86XK_UserPB), - "XF86XK_User1KB" => Some(XF86XK_User1KB), - "XF86XK_User2KB" => Some(XF86XK_User2KB), - "XF86XK_Video" => Some(XF86XK_Video), - "XF86XK_WheelButton" => Some(XF86XK_WheelButton), - "XF86XK_Word" => Some(XF86XK_Word), - "XF86XK_Xfer" => Some(XF86XK_Xfer), - "XF86XK_ZoomIn" => Some(XF86XK_ZoomIn), - "XF86XK_ZoomOut" => Some(XF86XK_ZoomOut), - "XF86XK_Away" => Some(XF86XK_Away), - "XF86XK_Messenger" => Some(XF86XK_Messenger), - "XF86XK_WebCam" => Some(XF86XK_WebCam), - "XF86XK_MailForward" => Some(XF86XK_MailForward), - "XF86XK_Pictures" => Some(XF86XK_Pictures), - "XF86XK_Music" => Some(XF86XK_Music), - "XF86XK_Battery" => Some(XF86XK_Battery), - "XF86XK_Bluetooth" => Some(XF86XK_Bluetooth), - "XF86XK_WLAN" => Some(XF86XK_WLAN), - "XF86XK_UWB" => Some(XF86XK_UWB), - "XF86XK_AudioForward" => Some(XF86XK_AudioForward), - "XF86XK_AudioRepeat" => Some(XF86XK_AudioRepeat), - "XF86XK_AudioRandomPlay" => Some(XF86XK_AudioRandomPlay), - "XF86XK_Subtitle" => Some(XF86XK_Subtitle), - "XF86XK_AudioCycleTrack" => Some(XF86XK_AudioCycleTrack), - "XF86XK_CycleAngle" => Some(XF86XK_CycleAngle), - "XF86XK_FrameBack" => Some(XF86XK_FrameBack), - "XF86XK_FrameForward" => Some(XF86XK_FrameForward), - "XF86XK_Time" => Some(XF86XK_Time), - "XF86XK_Select" => Some(XF86XK_Select), - "XF86XK_View" => Some(XF86XK_View), - "XF86XK_TopMenu" => Some(XF86XK_TopMenu), - "XF86XK_Red" => Some(XF86XK_Red), - "XF86XK_Green" => Some(XF86XK_Green), - "XF86XK_Yellow" => Some(XF86XK_Yellow), - "XF86XK_Blue" => Some(XF86XK_Blue), - "XF86XK_Suspend" => Some(XF86XK_Suspend), - "XF86XK_Hibernate" => Some(XF86XK_Hibernate), - "XF86XK_TouchpadToggle" => Some(XF86XK_TouchpadToggle), - "XF86XK_TouchpadOn" => Some(XF86XK_TouchpadOn), - "XF86XK_TouchpadOff" => Some(XF86XK_TouchpadOff), - "XF86XK_AudioMicMute" => Some(XF86XK_AudioMicMute), - "XF86XK_Switch_VT_1" => Some(XF86XK_Switch_VT_1), - "XF86XK_Switch_VT_2" => Some(XF86XK_Switch_VT_2), - "XF86XK_Switch_VT_3" => Some(XF86XK_Switch_VT_3), - "XF86XK_Switch_VT_4" => Some(XF86XK_Switch_VT_4), - "XF86XK_Switch_VT_5" => Some(XF86XK_Switch_VT_5), - "XF86XK_Switch_VT_6" => Some(XF86XK_Switch_VT_6), - "XF86XK_Switch_VT_7" => Some(XF86XK_Switch_VT_7), - "XF86XK_Switch_VT_8" => Some(XF86XK_Switch_VT_8), - "XF86XK_Switch_VT_9" => Some(XF86XK_Switch_VT_9), - "XF86XK_Switch_VT_10" => Some(XF86XK_Switch_VT_10), - "XF86XK_Switch_VT_11" => Some(XF86XK_Switch_VT_11), - "XF86XK_Switch_VT_12" => Some(XF86XK_Switch_VT_12), - "XF86XK_Ungrab" => Some(XF86XK_Ungrab), - "XF86XK_ClearGrab" => Some(XF86XK_ClearGrab), - "XF86XK_Next_VMode" => Some(XF86XK_Next_VMode), - "XF86XK_Prev_VMode" => Some(XF86XK_Prev_VMode), - "XF86XK_LogWindowTree" => Some(XF86XK_LogWindowTree), - "XF86XK_LogGrabInfo" => Some(XF86XK_LogGrabInfo), + "XF86XK_ModeLock" | "XF86ModeLock" => Some(XF86XK_ModeLock), + "XF86XK_MonBrightnessUp" | "XF86MonBrightnessUp" => Some(XF86XK_MonBrightnessUp), + "XF86XK_MonBrightnessDown" | "XF86MonBrightnessDown" => Some(XF86XK_MonBrightnessDown), + "XF86XK_KbdLightOnOff" | "XF86KbdLightOnOff" => Some(XF86XK_KbdLightOnOff), + "XF86XK_KbdBrightnessUp" | "XF86KbdBrightnessUp" => Some(XF86XK_KbdBrightnessUp), + "XF86XK_KbdBrightnessDown" | "XF86KbdBrightnessDown" => Some(XF86XK_KbdBrightnessDown), + "XF86XK_Standby" | "XF86Standby" => Some(XF86XK_Standby), + "XF86XK_AudioLowerVolume" | "XF86AudioLowerVolume" => Some(XF86XK_AudioLowerVolume), + "XF86XK_AudioMute" | "XF86AudioMute" => Some(XF86XK_AudioMute), + "XF86XK_AudioRaiseVolume" | "XF86AudioRaiseVolume" => Some(XF86XK_AudioRaiseVolume), + "XF86XK_AudioPlay" | "XF86AudioPlay" => Some(XF86XK_AudioPlay), + "XF86XK_AudioStop" | "XF86AudioStop" => Some(XF86XK_AudioStop), + "XF86XK_AudioPrev" | "XF86AudioPrev" => Some(XF86XK_AudioPrev), + "XF86XK_AudioNext" | "XF86AudioNext" => Some(XF86XK_AudioNext), + "XF86XK_HomePage" | "XF86HomePage" => Some(XF86XK_HomePage), + "XF86XK_Mail" | "XF86Mail" => Some(XF86XK_Mail), + "XF86XK_Start" | "XF86Start" => Some(XF86XK_Start), + "XF86XK_Search" | "XF86Search" => Some(XF86XK_Search), + "XF86XK_AudioRecord" | "XF86AudioRecord" => Some(XF86XK_AudioRecord), + "XF86XK_Calculator" | "XF86Calculator" => Some(XF86XK_Calculator), + "XF86XK_Memo" | "XF86Memo" => Some(XF86XK_Memo), + "XF86XK_ToDoList" | "XF86ToDoList" => Some(XF86XK_ToDoList), + "XF86XK_Calendar" | "XF86Calendar" => Some(XF86XK_Calendar), + "XF86XK_PowerDown" | "XF86PowerDown" => Some(XF86XK_PowerDown), + "XF86XK_ContrastAdjust" | "XF86ContrastAdjust" => Some(XF86XK_ContrastAdjust), + "XF86XK_RockerUp" | "XF86RockerUp" => Some(XF86XK_RockerUp), + "XF86XK_RockerDown" | "XF86RockerDown" => Some(XF86XK_RockerDown), + "XF86XK_RockerEnter" | "XF86RockerEnter" => Some(XF86XK_RockerEnter), + "XF86XK_Back" | "XF86Back" => Some(XF86XK_Back), + "XF86XK_Forward" | "XF86Forward" => Some(XF86XK_Forward), + "XF86XK_Stop" | "XF86Stop" => Some(XF86XK_Stop), + "XF86XK_Refresh" | "XF86Refresh" => Some(XF86XK_Refresh), + "XF86XK_PowerOff" | "XF86PowerOff" => Some(XF86XK_PowerOff), + "XF86XK_WakeUp" | "XF86WakeUp" => Some(XF86XK_WakeUp), + "XF86XK_Eject" | "XF86Eject" => Some(XF86XK_Eject), + "XF86XK_ScreenSaver" | "XF86ScreenSaver" => Some(XF86XK_ScreenSaver), + "XF86XK_WWW" | "XF86WWW" => Some(XF86XK_WWW), + "XF86XK_Sleep" | "XF86Sleep" => Some(XF86XK_Sleep), + "XF86XK_Favorites" | "XF86Favorites" => Some(XF86XK_Favorites), + "XF86XK_AudioPause" | "XF86AudioPause" => Some(XF86XK_AudioPause), + "XF86XK_AudioMedia" | "XF86AudioMedia" => Some(XF86XK_AudioMedia), + "XF86XK_MyComputer" | "XF86MyComputer" => Some(XF86XK_MyComputer), + "XF86XK_VendorHome" | "XF86VendorHome" => Some(XF86XK_VendorHome), + "XF86XK_LightBulb" | "XF86LightBulb" => Some(XF86XK_LightBulb), + "XF86XK_Shop" | "XF86Shop" => Some(XF86XK_Shop), + "XF86XK_History" | "XF86History" => Some(XF86XK_History), + "XF86XK_OpenURL" | "XF86OpenURL" => Some(XF86XK_OpenURL), + "XF86XK_AddFavorite" | "XF86AddFavorite" => Some(XF86XK_AddFavorite), + "XF86XK_HotLinks" | "XF86HotLinks" => Some(XF86XK_HotLinks), + "XF86XK_BrightnessAdjust" | "XF86BrightnessAdjust" => Some(XF86XK_BrightnessAdjust), + "XF86XK_Finance" | "XF86Finance" => Some(XF86XK_Finance), + "XF86XK_Community" | "XF86Community" => Some(XF86XK_Community), + "XF86XK_AudioRewind" | "XF86AudioRewind" => Some(XF86XK_AudioRewind), + "XF86XK_BackForward" | "XF86BackForward" => Some(XF86XK_BackForward), + "XF86XK_Launch0" | "XF86Launch0" => Some(XF86XK_Launch0), + "XF86XK_Launch1" | "XF86Launch1" => Some(XF86XK_Launch1), + "XF86XK_Launch2" | "XF86Launch2" => Some(XF86XK_Launch2), + "XF86XK_Launch3" | "XF86Launch3" => Some(XF86XK_Launch3), + "XF86XK_Launch4" | "XF86Launch4" => Some(XF86XK_Launch4), + "XF86XK_Launch5" | "XF86Launch5" => Some(XF86XK_Launch5), + "XF86XK_Launch6" | "XF86Launch6" => Some(XF86XK_Launch6), + "XF86XK_Launch7" | "XF86Launch7" => Some(XF86XK_Launch7), + "XF86XK_Launch8" | "XF86Launch8" => Some(XF86XK_Launch8), + "XF86XK_Launch9" | "XF86Launch9" => Some(XF86XK_Launch9), + "XF86XK_LaunchA" | "XF86LaunchA" => Some(XF86XK_LaunchA), + "XF86XK_LaunchB" | "XF86LaunchB" => Some(XF86XK_LaunchB), + "XF86XK_LaunchC" | "XF86LaunchC" => Some(XF86XK_LaunchC), + "XF86XK_LaunchD" | "XF86LaunchD" => Some(XF86XK_LaunchD), + "XF86XK_LaunchE" | "XF86LaunchE" => Some(XF86XK_LaunchE), + "XF86XK_LaunchF" | "XF86LaunchF" => Some(XF86XK_LaunchF), + "XF86XK_ApplicationLeft" | "XF86ApplicationLeft" => Some(XF86XK_ApplicationLeft), + "XF86XK_ApplicationRight" | "XF86ApplicationRight" => Some(XF86XK_ApplicationRight), + "XF86XK_Book" | "XF86Book" => Some(XF86XK_Book), + "XF86XK_CD" | "XF86CD" => Some(XF86XK_CD), + "XF86XK_Calculater" | "XF86Calculater" => Some(XF86XK_Calculater), + "XF86XK_Clear" | "XF86Clear" => Some(XF86XK_Clear), + "XF86XK_Close" | "XF86Close" => Some(XF86XK_Close), + "XF86XK_Copy" | "XF86Copy" => Some(XF86XK_Copy), + "XF86XK_Cut" | "XF86Cut" => Some(XF86XK_Cut), + "XF86XK_Display" | "XF86Display" => Some(XF86XK_Display), + "XF86XK_DOS" | "XF86DOS" => Some(XF86XK_DOS), + "XF86XK_Documents" | "XF86Documents" => Some(XF86XK_Documents), + "XF86XK_Excel" | "XF86Excel" => Some(XF86XK_Excel), + "XF86XK_Explorer" | "XF86Explorer" => Some(XF86XK_Explorer), + "XF86XK_Game" | "XF86Game" => Some(XF86XK_Game), + "XF86XK_Go" | "XF86Go" => Some(XF86XK_Go), + "XF86XK_iTouch" | "XF86iTouch" => Some(XF86XK_iTouch), + "XF86XK_LogOff" | "XF86LogOff" => Some(XF86XK_LogOff), + "XF86XK_Market" | "XF86Market" => Some(XF86XK_Market), + "XF86XK_Meeting" | "XF86Meeting" => Some(XF86XK_Meeting), + "XF86XK_MenuKB" | "XF86MenuKB" => Some(XF86XK_MenuKB), + "XF86XK_MenuPB" | "XF86MenuPB" => Some(XF86XK_MenuPB), + "XF86XK_MySites" | "XF86MySites" => Some(XF86XK_MySites), + "XF86XK_New" | "XF86New" => Some(XF86XK_New), + "XF86XK_News" | "XF86News" => Some(XF86XK_News), + "XF86XK_OfficeHome" | "XF86OfficeHome" => Some(XF86XK_OfficeHome), + "XF86XK_Open" | "XF86Open" => Some(XF86XK_Open), + "XF86XK_Option" | "XF86Option" => Some(XF86XK_Option), + "XF86XK_Paste" | "XF86Paste" => Some(XF86XK_Paste), + "XF86XK_Phone" | "XF86Phone" => Some(XF86XK_Phone), + "XF86XK_Q" | "XF86Q" => Some(XF86XK_Q), + "XF86XK_Reply" | "XF86Reply" => Some(XF86XK_Reply), + "XF86XK_Reload" | "XF86Reload" => Some(XF86XK_Reload), + "XF86XK_RotateWindows" | "XF86RotateWindows" => Some(XF86XK_RotateWindows), + "XF86XK_RotationPB" | "XF86RotationPB" => Some(XF86XK_RotationPB), + "XF86XK_RotationKB" | "XF86RotationKB" => Some(XF86XK_RotationKB), + "XF86XK_Save" | "XF86Save" => Some(XF86XK_Save), + "XF86XK_ScrollUp" | "XF86ScrollUp" => Some(XF86XK_ScrollUp), + "XF86XK_ScrollDown" | "XF86ScrollDown" => Some(XF86XK_ScrollDown), + "XF86XK_ScrollClick" | "XF86ScrollClick" => Some(XF86XK_ScrollClick), + "XF86XK_Send" | "XF86Send" => Some(XF86XK_Send), + "XF86XK_Spell" | "XF86Spell" => Some(XF86XK_Spell), + "XF86XK_SplitScreen" | "XF86SplitScreen" => Some(XF86XK_SplitScreen), + "XF86XK_Support" | "XF86Support" => Some(XF86XK_Support), + "XF86XK_TaskPane" | "XF86TaskPane" => Some(XF86XK_TaskPane), + "XF86XK_Terminal" | "XF86Terminal" => Some(XF86XK_Terminal), + "XF86XK_Tools" | "XF86Tools" => Some(XF86XK_Tools), + "XF86XK_Travel" | "XF86Travel" => Some(XF86XK_Travel), + "XF86XK_UserPB" | "XF86UserPB" => Some(XF86XK_UserPB), + "XF86XK_User1KB" | "XF86User1KB" => Some(XF86XK_User1KB), + "XF86XK_User2KB" | "XF86User2KB" => Some(XF86XK_User2KB), + "XF86XK_Video" | "XF86Video" => Some(XF86XK_Video), + "XF86XK_WheelButton" | "XF86WheelButton" => Some(XF86XK_WheelButton), + "XF86XK_Word" | "XF86Word" => Some(XF86XK_Word), + "XF86XK_Xfer" | "XF86Xfer" => Some(XF86XK_Xfer), + "XF86XK_ZoomIn" | "XF86ZoomIn" => Some(XF86XK_ZoomIn), + "XF86XK_ZoomOut" | "XF86ZoomOut" => Some(XF86XK_ZoomOut), + "XF86XK_Away" | "XF86Away" => Some(XF86XK_Away), + "XF86XK_Messenger" | "XF86Messenger" => Some(XF86XK_Messenger), + "XF86XK_WebCam" | "XF86WebCam" => Some(XF86XK_WebCam), + "XF86XK_MailForward" | "XF86MailForward" => Some(XF86XK_MailForward), + "XF86XK_Pictures" | "XF86Pictures" => Some(XF86XK_Pictures), + "XF86XK_Music" | "XF86Music" => Some(XF86XK_Music), + "XF86XK_Battery" | "XF86Battery" => Some(XF86XK_Battery), + "XF86XK_Bluetooth" | "XF86Bluetooth" => Some(XF86XK_Bluetooth), + "XF86XK_WLAN" | "XF86WLAN" => Some(XF86XK_WLAN), + "XF86XK_UWB" | "XF86UWB" => Some(XF86XK_UWB), + "XF86XK_AudioForward" | "XF86AudioForward" => Some(XF86XK_AudioForward), + "XF86XK_AudioRepeat" | "XF86AudioRepeat" => Some(XF86XK_AudioRepeat), + "XF86XK_AudioRandomPlay" | "XF86AudioRandomPlay" => Some(XF86XK_AudioRandomPlay), + "XF86XK_Subtitle" | "XF86Subtitle" => Some(XF86XK_Subtitle), + "XF86XK_AudioCycleTrack" | "XF86AudioCycleTrack" => Some(XF86XK_AudioCycleTrack), + "XF86XK_CycleAngle" | "XF86CycleAngle" => Some(XF86XK_CycleAngle), + "XF86XK_FrameBack" | "XF86FrameBack" => Some(XF86XK_FrameBack), + "XF86XK_FrameForward" | "XF86FrameForward" => Some(XF86XK_FrameForward), + "XF86XK_Time" | "XF86Time" => Some(XF86XK_Time), + "XF86XK_Select" | "XF86Select" => Some(XF86XK_Select), + "XF86XK_View" | "XF86View" => Some(XF86XK_View), + "XF86XK_TopMenu" | "XF86TopMenu" => Some(XF86XK_TopMenu), + "XF86XK_Red" | "XF86Red" => Some(XF86XK_Red), + "XF86XK_Green" | "XF86Green" => Some(XF86XK_Green), + "XF86XK_Yellow" | "XF86Yellow" => Some(XF86XK_Yellow), + "XF86XK_Blue" | "XF86Blue" => Some(XF86XK_Blue), + "XF86XK_Suspend" | "XF86Suspend" => Some(XF86XK_Suspend), + "XF86XK_Hibernate" | "XF86Hibernate" => Some(XF86XK_Hibernate), + "XF86XK_TouchpadToggle" | "XF86TouchpadToggle" => Some(XF86XK_TouchpadToggle), + "XF86XK_TouchpadOn" | "XF86TouchpadOn" => Some(XF86XK_TouchpadOn), + "XF86XK_TouchpadOff" | "XF86TouchpadOff" => Some(XF86XK_TouchpadOff), + "XF86XK_AudioMicMute" | "XF86AudioMicMute" => Some(XF86XK_AudioMicMute), + "XF86XK_Switch_VT_1" | "XF86Switch_VT_1" => Some(XF86XK_Switch_VT_1), + "XF86XK_Switch_VT_2" | "XF86Switch_VT_2" => Some(XF86XK_Switch_VT_2), + "XF86XK_Switch_VT_3" | "XF86Switch_VT_3" => Some(XF86XK_Switch_VT_3), + "XF86XK_Switch_VT_4" | "XF86Switch_VT_4" => Some(XF86XK_Switch_VT_4), + "XF86XK_Switch_VT_5" | "XF86Switch_VT_5" => Some(XF86XK_Switch_VT_5), + "XF86XK_Switch_VT_6" | "XF86Switch_VT_6" => Some(XF86XK_Switch_VT_6), + "XF86XK_Switch_VT_7" | "XF86Switch_VT_7" => Some(XF86XK_Switch_VT_7), + "XF86XK_Switch_VT_8" | "XF86Switch_VT_8" => Some(XF86XK_Switch_VT_8), + "XF86XK_Switch_VT_9" | "XF86Switch_VT_9" => Some(XF86XK_Switch_VT_9), + "XF86XK_Switch_VT_10" | "XF86Switch_VT_10" => Some(XF86XK_Switch_VT_10), + "XF86XK_Switch_VT_11" | "XF86Switch_VT_11" => Some(XF86XK_Switch_VT_11), + "XF86XK_Switch_VT_12" | "XF86Switch_VT_12" => Some(XF86XK_Switch_VT_12), + "XF86XK_Ungrab" | "XF86Ungrab" => Some(XF86XK_Ungrab), + "XF86XK_ClearGrab" | "XF86ClearGrab" => Some(XF86XK_ClearGrab), + "XF86XK_Next_VMode" | "XF86Next_VMode" => Some(XF86XK_Next_VMode), + "XF86XK_Prev_VMode" | "XF86Prev_VMode" => Some(XF86XK_Prev_VMode), + "XF86XK_LogWindowTree" | "XF86LogWindowTree" => Some(XF86XK_LogWindowTree), + "XF86XK_LogGrabInfo" | "XF86LogGrabInfo" => Some(XF86XK_LogGrabInfo), "ISO_Lock" => Some(XK_ISO_Lock), "ISO_Level2_Latch" => Some(XK_ISO_Level2_Latch), "ISO_Level3_Shift" => Some(XK_ISO_Level3_Shift), From 3c387175a39004370c05ab9614542ea801c2e234 Mon Sep 17 00:00:00 2001 From: VuiMuich Date: Tue, 27 Jun 2023 12:46:02 +0200 Subject: [PATCH 19/23] clippy auto fix --- lefthk/src/config/mod.rs | 2 +- lefthk/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lefthk/src/config/mod.rs b/lefthk/src/config/mod.rs index 6cc28d1..3a2362f 100644 --- a/lefthk/src/config/mod.rs +++ b/lefthk/src/config/mod.rs @@ -40,7 +40,7 @@ impl lefthk_core::config::Config for Config { /// user error for provideng a wrong path pub fn load() -> Result { let path = BaseDirectories::with_prefix(lefthk_core::LEFTHK_DIR_NAME)?; - fs::create_dir_all(&path.get_config_home())?; + fs::create_dir_all(path.get_config_home())?; let file_name = path.place_config_file("config.ron")?; if Path::new(&file_name).exists() { let contents = fs::read_to_string(file_name)?; diff --git a/lefthk/src/main.rs b/lefthk/src/main.rs index d59c70e..6bd9d6b 100644 --- a/lefthk/src/main.rs +++ b/lefthk/src/main.rs @@ -70,7 +70,7 @@ fn send_command(command: &impl Command) { let path = errors::exit_on_error!(BaseDirectories::with_prefix(lefthk_core::LEFTHK_DIR_NAME)); let pipe_name = Pipe::pipe_name(); let pipe_file = errors::exit_on_error!(path.place_runtime_file(pipe_name)); - let mut pipe = fs::OpenOptions::new().write(true).open(&pipe_file).unwrap(); + let mut pipe = fs::OpenOptions::new().write(true).open(pipe_file).unwrap(); writeln!(pipe, "{}", command.normalize()).unwrap(); } From 38d254feadf81de5aeb3711b62be7cb6e8a912c9 Mon Sep 17 00:00:00 2001 From: VuiMuich Date: Wed, 28 Jun 2023 13:11:35 +0200 Subject: [PATCH 20/23] bump `lefthk-core` to `0.2.0` to better reflect breaking changes --- lefthk-core/Cargo.toml | 2 +- lefthk/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lefthk-core/Cargo.toml b/lefthk-core/Cargo.toml index b2c4d8e..17a93c3 100644 --- a/lefthk-core/Cargo.toml +++ b/lefthk-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lefthk-core" -version = "0.1.9" +version = "0.2.0" edition = "2021" license = "BSD-3-Clause" readme = "README.md" diff --git a/lefthk/Cargo.toml b/lefthk/Cargo.toml index 484c2d0..1be3282 100644 --- a/lefthk/Cargo.toml +++ b/lefthk/Cargo.toml @@ -9,7 +9,7 @@ description = "A hotkey daemon for Adventurers" [dependencies] clap = {version = "3.2.20", features = ["cargo"]} -lefthk-core = { path = "../lefthk-core", version = '0.1' } +lefthk-core = { path = "../lefthk-core", version = '0.2' } ron = "0.8" serde = { version = "1.0", features = ["derive"] } thiserror = "1.0.30" From 3310bc43b08f29311d16393026ed539a2dd28b84 Mon Sep 17 00:00:00 2001 From: VuiMuich Date: Mon, 23 Oct 2023 19:02:32 +0200 Subject: [PATCH 21/23] fix fmt and clippy, merge main --- Cargo.lock | 2 +- lefthk/src/config/mod.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ada0618..4cd06bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -208,7 +208,7 @@ dependencies = [ [[package]] name = "lefthk-core" -version = "0.1.9" +version = "0.2.0" dependencies = [ "inventory", "mio", diff --git a/lefthk/src/config/mod.rs b/lefthk/src/config/mod.rs index 3b54f40..3ae27a2 100644 --- a/lefthk/src/config/mod.rs +++ b/lefthk/src/config/mod.rs @@ -39,10 +39,10 @@ impl lefthk_core::config::Config for Config { impl TryFrom for Config { type Error = LeftError; -/// # Errors -/// -/// Thes will error when no config file is found, most propably as system or -/// user error for provideng a wrong path + /// # Errors + /// + /// Thes will error when no config file is found, most propably as system or + /// user error for provideng a wrong path fn try_from(contents: String) -> Result { let mut config: Config = ron::from_str(&contents)?; let global_exit_chord = config @@ -66,7 +66,7 @@ impl TryFrom for Config { /// This errors, when no Config is found at the path pub fn load() -> Result { let path = BaseDirectories::with_prefix(lefthk_core::LEFTHK_DIR_NAME)?; - fs::create_dir_all(&path.get_config_home())?; + fs::create_dir_all(path.get_config_home())?; let file_name = path.place_config_file("config.ron")?; if Path::new(&file_name).exists() { let contents = fs::read_to_string(file_name)?; From 5862ea09ca8a9dc6d2359abfb46281c846c43539 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Tue, 24 Oct 2023 00:32:20 -0400 Subject: [PATCH 22/23] fix: clippy test --- lefthk/src/tests.rs | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/lefthk/src/tests.rs b/lefthk/src/tests.rs index 7475dc6..00a9dd4 100644 --- a/lefthk/src/tests.rs +++ b/lefthk/src/tests.rs @@ -1,9 +1,10 @@ /// Config Testing #[cfg(test)] mod config { - use lefthk_core::config::{Command, Config}; + use lefthk_core::config::command::utils::normalized_command::NormalizedCommand; + use lefthk_core::config::Config; - use crate::config::{self, command::Command as Cmd, keybind::Keybind as Kbd, Config as Cfg}; + use crate::config::Config as Cfg; #[test] fn parse_config() { @@ -114,24 +115,33 @@ Config( assert_eq!(default_keybind.modifier, conf.default_modifier); assert_eq!( default_keybind.command, - Cmd::Chord(vec![Kbd { - command: Cmd::Execute("st -e htop".to_string()), - modifier: Some(vec!["Mod4".to_string(), "Shift".to_string()]), - key: config::key::Key::Key("c".to_string()), - }]) + NormalizedCommand( + r#"Chord([ + Keybind( + command: NormalizedCommand("Execute(\"st -e htop\")"), + modifier: [ + "Mod4", + "Shift", + ], + key: "c", + ), +])"# + .to_string() + ) ); // Verify custom modifier implementation let custom_keybind = conf_mapped.first().unwrap(); assert_eq!(custom_keybind.modifier.len(), 1); assert_eq!(custom_keybind.modifier, vec!["Mod4".to_string()]); - assert_eq!( - custom_keybind.command, - Cmd::Chord(vec![Kbd { - command: Cmd::Execute("st -e htop".to_string()), - modifier: Some(vec!["Mod4".to_string()]), - key: config::key::Key::Key("c".to_string()), - }]) - ); + assert_eq!(custom_keybind.command, NormalizedCommand(r#"Chord([ + Keybind( + command: NormalizedCommand("Execute(\"st -e htop\")"), + modifier: [ + "Mod4", + ], + key: "c", + ), +])"#.to_string())); } } From d29aa0de282295954d0447427890ab81c0a72a1d Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Tue, 24 Oct 2023 03:04:07 -0400 Subject: [PATCH 23/23] fix: format style --- lefthk/src/tests.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lefthk/src/tests.rs b/lefthk/src/tests.rs index 00a9dd4..49cb540 100644 --- a/lefthk/src/tests.rs +++ b/lefthk/src/tests.rs @@ -134,7 +134,10 @@ Config( let custom_keybind = conf_mapped.first().unwrap(); assert_eq!(custom_keybind.modifier.len(), 1); assert_eq!(custom_keybind.modifier, vec!["Mod4".to_string()]); - assert_eq!(custom_keybind.command, NormalizedCommand(r#"Chord([ + assert_eq!( + custom_keybind.command, + NormalizedCommand( + r#"Chord([ Keybind( command: NormalizedCommand("Execute(\"st -e htop\")"), modifier: [ @@ -142,6 +145,9 @@ Config( ], key: "c", ), -])"#.to_string())); +])"# + .to_string() + ) + ); } }