From e7bb4c38703af07cb5c3fd78f506e0cd860500c4 Mon Sep 17 00:00:00 2001 From: innocentzero Date: Wed, 27 Mar 2024 00:16:33 +0530 Subject: [PATCH] [fix] Apply env refactoring to swhkd Signed-off-by: innocentzero --- Cargo.lock | 66 +++------------------------------------------ swhkd/src/daemon.rs | 30 +-------------------- 2 files changed, 5 insertions(+), 91 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0c741b7..7c58ee0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,7 +6,7 @@ version = 3 name = "Simple-Wayland-HotKey-Daemon" version = "1.3.0-dev" dependencies = [ - "clap 4.5.1", + "clap", "env_logger", "evdev", "flate2", @@ -137,21 +137,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "clap" -version = "3.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" -dependencies = [ - "atty", - "bitflags", - "clap_lex 0.2.4", - "indexmap", - "strsim 0.10.0", - "termcolor", - "textwrap", -] - [[package]] name = "clap" version = "4.5.1" @@ -170,8 +155,8 @@ checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" dependencies = [ "anstream", "anstyle", - "clap_lex 0.7.0", - "strsim 0.11.0", + "clap_lex", + "strsim", ] [[package]] @@ -186,15 +171,6 @@ dependencies = [ "syn 2.0.52", ] -[[package]] -name = "clap_lex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] - [[package]] name = "clap_lex" version = "0.7.0" @@ -321,12 +297,6 @@ version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "heck" version = "0.4.1" @@ -348,16 +318,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown", -] - [[package]] name = "itertools" version = "0.10.5" @@ -485,12 +445,6 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" -[[package]] -name = "os_str_bytes" -version = "6.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" - [[package]] name = "parking_lot" version = "0.12.1" @@ -651,12 +605,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - [[package]] name = "strsim" version = "0.11.0" @@ -667,7 +615,7 @@ checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" name = "swhks" version = "1.3.0-dev" dependencies = [ - "clap 3.2.25", + "clap", "env_logger", "log", "nix", @@ -726,12 +674,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" - [[package]] name = "thiserror" version = "1.0.38" diff --git a/swhkd/src/daemon.rs b/swhkd/src/daemon.rs index 2ba1e57..eab40e8 100644 --- a/swhkd/src/daemon.rs +++ b/swhkd/src/daemon.rs @@ -90,7 +90,7 @@ async fn main() -> Result<(), Box> { perms::drop_privileges(invoking_uid); let config_file_path: PathBuf = - args.config.as_ref().map_or_else(fetch_xdg_config_path, |file| file.clone()); + args.config.as_ref().map_or_else(|| env.fetch_xdg_config_path(), |file| file.clone()); log::debug!("Using config file path: {:#?}", config_file_path); @@ -479,34 +479,6 @@ pub fn check_device_is_keyboard(device: &Device) -> bool { } } -pub fn fetch_xdg_config_path() -> PathBuf { - let config_file_path: PathBuf = match env::var("XDG_CONFIG_HOME") { - Ok(val) => { - log::debug!("XDG_CONFIG_HOME exists: {:#?}", val); - Path::new(&val).join("swhkd/swhkdrc") - } - Err(_) => { - log::error!("XDG_CONFIG_HOME has not been set."); - Path::new("/etc/swhkd/swhkdrc").to_path_buf() - } - }; - config_file_path -} - -pub fn fetch_xdg_runtime_socket_path() -> PathBuf { - match env::var("XDG_RUNTIME_DIR") { - Ok(val) => { - log::debug!("XDG_RUNTIME_DIR exists: {:#?}", val); - Path::new(&val).join("swhkd.sock") - } - Err(_) => { - log::error!("XDG_RUNTIME_DIR has not been set."); - Path::new(&format!("/run/user/{}/swhkd.sock", env::var("PKEXEC_UID").unwrap())) - .to_path_buf() - } - } -} - pub fn setup_swhkd(invoking_uid: u32, runtime_path: String) { // Set a sane process umask. log::trace!("Setting process umask.");