From b2b23a88c962477c5ca95270c0cf260163a7fbeb Mon Sep 17 00:00:00 2001 From: Ottatop Date: Sun, 10 Sep 2023 23:40:22 -0500 Subject: [PATCH] Use BaseDirectories for config dir --- Cargo.toml | 5 ++--- src/state.rs | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c14514c..5150c0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,11 +6,9 @@ edition = "2021" license = "GPL-3.0+" description = "A WIP Smithay-based Wayland compositor, inspired by AwesomeWM" readme = "README.md" -repository = "https://github.com/Ottatop/pinnacle/" +repository = "https://github.com/pinnacle-comp/pinnacle/" keywords = ["wayland", "compositor", "smithay", "lua"] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] tracing = "0.1.37" tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } @@ -32,6 +30,7 @@ anyhow = { version = "1.0.75", features = ["backtrace"] } clap = { version = "4.4.2", features = ["derive"] } xkbcommon = "0.6.0" xdg = "2.5.2" +lazy_static = "1.4.0" [features] default = ["egl", "winit", "udev", "xwayland"] diff --git a/src/state.rs b/src/state.rs index 69d5b36..645366e 100644 --- a/src/state.rs +++ b/src/state.rs @@ -65,9 +65,15 @@ use smithay::{ }, xwayland::{X11Surface, X11Wm, XWayland, XWaylandEvent}, }; +use xdg::BaseDirectories; use crate::input::InputState; +lazy_static::lazy_static! { + static ref XDG_BASE_DIRS: BaseDirectories = + BaseDirectories::with_prefix("pinnacle").expect("couldn't create xdg BaseDirectories"); +} + pub enum Backend { Winit(Winit), Udev(Udev), @@ -204,6 +210,7 @@ impl State { let (tx_channel, rx_channel) = calloop::channel::channel::(); let config_dir = get_config_dir(); + tracing::debug!("config dir is {:?}", config_dir); let metaconfig = crate::metaconfig::parse(&config_dir)?; @@ -401,17 +408,11 @@ impl State { } fn get_config_dir() -> PathBuf { - let config_dir = std::env::var("PINNACLE_CONFIG_DIR").unwrap_or_else(|_| { - let default_config_dir = - std::env::var("XDG_CONFIG_HOME").unwrap_or("~/.config".to_string()); + let config_dir = std::env::var("PINNACLE_CONFIG_DIR") + .ok() + .and_then(|s| Some(PathBuf::from(shellexpand::full(&s).ok()?.to_string()))); - PathBuf::from(default_config_dir) - .join("pinnacle") - .to_string_lossy() - .to_string() - }); - - PathBuf::from(shellexpand::tilde(&config_dir).to_string()) + config_dir.unwrap_or(XDG_BASE_DIRS.get_config_home()) } /// This should be called *after* you have created the [`PinnacleSocketSource`] to ensure @@ -422,7 +423,9 @@ fn start_config(metaconfig: Metaconfig, config_dir: &Path) -> anyhow::Result