~tsdh/swayr

c20e887dbde2bb42259490e39dff20f7eff85da7 — Jakub Jirutka a month ago 546e0e3
Add support for system-level config in /etc/xdg/swayr/
2 files changed, 11 insertions(+), 6 deletions(-)

M README.md
M src/config.rs
M README.md => README.md +3 -2
@@ 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.


M src/config.rs => src/config.rs +8 -4
@@ 258,14 258,18 @@ impl Default for Config {

fn get_config_file_path() -> Box<Path> {
    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) {