Add support for system-level config in /etc/xdg/swayr/

timeout_old
Jakub Jirutka 3 years ago committed by Tassilo Horn
parent 546e0e326b
commit c20e887dbd
  1. 5
      README.md
  2. 12
      src/config.rs

@ -153,9 +153,10 @@ and logging are optional.
## Configuration ## 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) first invocation for use with the [wofi](https://todo.sr.ht/~scoopta/wofi)
menu program. menu program.

@ -258,14 +258,18 @@ impl Default for Config {
fn get_config_file_path() -> Box<Path> { fn get_config_file_path() -> Box<Path> {
let proj_dirs = ProjectDirs::from("", "", "swayr").expect(""); let proj_dirs = ProjectDirs::from("", "", "swayr").expect("");
let config_dir = proj_dirs.config_dir(); let user_config_dir = proj_dirs.config_dir();
if !config_dir.exists() { 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() DirBuilder::new()
.recursive(true) .recursive(true)
.create(config_dir) .create(user_config_dir)
.unwrap(); .unwrap();
} }
config_dir.join("config.toml").into_boxed_path() user_config_dir.join("config.toml").into_boxed_path()
} }
pub fn save_config(cfg: Config) { pub fn save_config(cfg: Config) {

Loading…
Cancel
Save