diff --git a/Cargo.lock b/Cargo.lock index 6ebacb1..9fd0487 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -200,6 +200,11 @@ dependencies = [ "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "linked-hash-map" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "maplit" version = "1.0.2" @@ -476,6 +481,17 @@ dependencies = [ "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "serde_yaml" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "sha-1" version = "0.8.1" @@ -678,6 +694,7 @@ dependencies = [ "rusttype 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_yaml 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)", "shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "smithay-client-toolkit 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "wayland-client 0.23.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -694,6 +711,14 @@ name = "xml-rs" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "yaml-rust" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] "checksum andrew 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9b7f09f89872c2b6b29e319377b1fbe91c6f5947df19a25596e121cf19a7b35e" "checksum approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3" @@ -723,6 +748,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum libpulse-binding 2.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e7712e3c895da914d7d969475238cc43933c5c4cf7ef3654106be9db2b327cbb" "checksum libpulse-sys 1.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "67df96705dc149577155690c05e067334d1d8a62bcac1a1611ef28eaaeb76354" "checksum line_drawing 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5cc7ad3d82c845bdb5dde34ffdcc7a5fb4d2996e1e1ee0f19c33bc80e15196b9" +"checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" "checksum maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" "checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" "checksum nix 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4dbdc256eaac2e3bd236d93ad999d3479ef775c863dbda3068c4006a92eec51b" @@ -755,6 +781,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "fec2851eb56d010dc9a21b89ca53ee75e6528bab60c11e89d38390904982da9f" "checksum serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "cb4dc18c61206b08dc98216c98faa0232f4337e1e1b8574551d5bad29ea1b425" "checksum serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "051c49229f282f7c6f3813f8286cc1e3323e8051823fce42c7ea80fe13521704" +"checksum serde_yaml 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)" = "38b08a9a90e5260fe01c6480ec7c811606df6d3a660415808c3c3fa8ed95b582" "checksum sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "23962131a91661d643c98940b20fcaffe62d776a823247be80a48fcb8b6fce68" "checksum shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" "checksum smithay-client-toolkit 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "93960e8975909fcb14cc755de93af2149d8b8f4eb368315537d40cfd0f324054" @@ -779,3 +806,4 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum xdg 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57" "checksum xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "541b12c998c5b56aa2b4e6f18f03664eef9a4fd0a246a55594efae6cc2d964b5" +"checksum yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "65923dd1784f44da1d2c3dbbc5e822045628c590ba72123e1c73d3c230c4434d" diff --git a/Cargo.toml b/Cargo.toml index a7c461d..6f33e2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,4 +28,5 @@ rcalc_lib = { version = "0.9" } rust-ini = "0.13" shlex = "0.1" serde_json = "1.0" +serde_yaml = "0.8" serde = { version = "1.0", features = ["derive"] } diff --git a/config.json b/config.json index 722e3ee..1885378 100644 --- a/config.json +++ b/config.json @@ -34,7 +34,13 @@ } ]}, {"calendar": {"font_size": 16.0,"sections": 3}}, - {"launcher": {"font_size": 32.0,"length": 1200}} + {"launcher": { + "font_size": 32.0, + "length": 1200, + "app_opener": "swaymsg exec ", + "term_opener": "alacritty -e ", + "url_opener": "xdg-open " + }} ]} } }, diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..dddbee9 --- /dev/null +++ b/config.yaml @@ -0,0 +1,49 @@ +outputMode: active +scale: 1 +background: + red: 0.0 + green: 0.0 + blue: 0.0 + opacity: 0.9 +widget: + margin: + margins: [20, 20, 20, 20] + widget: + verticalLayout: + - horizontalLayout: + - margin: + margins: [0, 88, 0, 32] + widget: + verticalLayout: + - date: + font_size: 64.0 + - clock: + font_size: 256.0 + - verticalLayout: + - margin: + margins: [0, 0, 0, 8] + widget: + battery: + font_size: 24.0 + length: 600 + - margin: + margins: [0, 0, 0, 8] + widget: + backlight: + font_size: 24.0 + length: 600 + - margin: + margins: [0, 0, 0, 8] + widget: + pulseAudio: + font_size: 24.0 + length: 600 + - calendar: + font_size: 16.0 + sections: 3 + - launcher: + font_size: 32.0 + length: 1200 + app_opener: "swaymsg exec " + term_opener: "alacritty -e " + url_opener: "xdg-open " diff --git a/src/config.rs b/src/config.rs index 622744f..7a8e9a0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -147,10 +147,10 @@ impl Default for OutputMode { #[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "camelCase")] pub struct Config { - pub widget: Widget, pub output_mode: OutputMode, pub scale: u32, pub background: Color, + pub widget: Widget, } impl Default for Config { diff --git a/src/main.rs b/src/main.rs index e150ba1..4d70427 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ enum Mode { Start, StartOrKill, ToggleVisible, - PrintConfig, + PrintConfig(bool), } fn main() { @@ -43,12 +43,18 @@ fn main() { }, }; - let config: config::Config = match File::open(config_home + "/config.json") { + let (is_yaml, config): (bool, config::Config) = match File::open(config_home.clone() + "/config.yaml") { Ok(f) => { let reader = BufReader::new(f); - serde_json::from_reader(reader).unwrap() + (true, serde_yaml::from_reader(reader).unwrap()) + } + Err(_) => match File::open(config_home + "/config.json") { + Ok(f) => { + let reader = BufReader::new(f); + (false, serde_json::from_reader(reader).unwrap()) + } + Err(_) => (true, Default::default()), } - Err(_) => Default::default(), }; let scale = config.scale; @@ -60,7 +66,9 @@ fn main() { "start" => Mode::Start, "start-or-kill" => Mode::StartOrKill, "toggle-visible" => Mode::ToggleVisible, - "print-config" => Mode::PrintConfig, + "print-config" => Mode::PrintConfig(!is_yaml), + "print-config-json" => Mode::PrintConfig(true), + "print-config-yaml" => Mode::PrintConfig(false), s => { eprintln!("unsupported sub-command {}", s); std::process::exit(1); @@ -93,8 +101,12 @@ fn main() { std::process::exit(1); }; } - Mode::PrintConfig => { - println!("{}", serde_json::to_string_pretty(&config).unwrap()); + Mode::PrintConfig(json) => { + if json { + println!("{}", serde_json::to_string_pretty(&config).unwrap()); + } else { + println!("{}", serde_yaml::to_string(&config).unwrap()); + } std::process::exit(0); } }