From c20e887dbde2bb42259490e39dff20f7eff85da7 Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Tue, 12 Oct 2021 22:33:15 +0200 Subject: [PATCH] Add support for system-level config in /etc/xdg/swayr/ --- README.md | 5 +++-- src/config.rs | 12 ++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a18c0fd..8f62bc1 100644 --- a/README.md +++ b/README.md @@ -153,9 +153,10 @@ and logging are optional. ## Configuration -Swayr can be configured using the `~/.config/swayr/config.toml` config file. +Swayr can be configured using the `~/.config/swayr/config.toml` or +`/etc/xdg/swayr/config.toml` config file. -If it doesn't exist, a simple default configuration will be created on the +If no config files exists, a simple default configuration will be created on the first invocation for use with the [wofi](https://todo.sr.ht/~scoopta/wofi) menu program. diff --git a/src/config.rs b/src/config.rs index 33bdcaa..3ad532e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -258,14 +258,18 @@ impl Default for Config { fn get_config_file_path() -> Box { let proj_dirs = ProjectDirs::from("", "", "swayr").expect(""); - let config_dir = proj_dirs.config_dir(); - if !config_dir.exists() { + let user_config_dir = proj_dirs.config_dir(); + if !user_config_dir.exists() { + let sys_config_file = Path::new("/etc/xdg/swayr/config.toml"); + if sys_config_file.exists() { + return sys_config_file.into(); + } DirBuilder::new() .recursive(true) - .create(config_dir) + .create(user_config_dir) .unwrap(); } - config_dir.join("config.toml").into_boxed_path() + user_config_dir.join("config.toml").into_boxed_path() } pub fn save_config(cfg: Config) {