Use BaseDirectories for config dir

This commit is contained in:
Ottatop 2023-09-10 23:40:22 -05:00
parent dd5992ed98
commit b2b23a88c9
2 changed files with 16 additions and 14 deletions

View file

@ -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"]

View file

@ -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::<Msg>();
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<Con
let mut command = metaconfig.command.split(' ');
let arg1 = command.next().expect("empty command");
let arg1 = command
.next()
.context("command in metaconfig.toml was empty")?;
std::env::set_var("PINNACLE_DIR", std::env::current_dir()?);