diff --git a/src/client/main.rs b/src/client/main.rs index fee2279..702e3f3 100644 --- a/src/client/main.rs +++ b/src/client/main.rs @@ -30,6 +30,11 @@ pub fn get_proxy() -> zbus::Result> { } fn main() -> Result<(), glib::Error> { + // Parse Config + let _client_config = config::user::read_user_config() + .expect("Failed to parse config file") + .client; + // Make sure that the server is running let proxy = match get_proxy() { Ok(proxy) => match proxy.introspect() { diff --git a/src/input-backend/main.rs b/src/input-backend/main.rs index 889d9d5..9186b80 100644 --- a/src/input-backend/main.rs +++ b/src/input-backend/main.rs @@ -42,6 +42,11 @@ impl LibinputInterface for Interface { } fn main() -> Result<(), zbus::Error> { + // Parse Config + let _input_config = config::backend::read_backend_config() + .expect("Failed to parse config file") + .input; + // Create DBUS server let connection = task::block_on(DbusServer.init()); let object_server = connection.object_server(); diff --git a/src/server/application.rs b/src/server/application.rs index 13c6c3c..77eb444 100644 --- a/src/server/application.rs +++ b/src/server/application.rs @@ -13,6 +13,8 @@ use std::cell::RefCell; use std::rc::Rc; use std::sync::{Arc, Mutex}; +use super::config::user::ServerConfig; + #[derive(Clone, Shrinkwrap)] pub struct SwayOSDApplication { #[shrinkwrap(main_field)] @@ -21,7 +23,7 @@ pub struct SwayOSDApplication { } impl SwayOSDApplication { - pub fn new(action_receiver: Receiver<(ArgTypes, String)>) -> Self { + pub fn new(server_config: ServerConfig, action_receiver: Receiver<(ArgTypes, String)>) -> Self { let app = Application::new(Some(APPLICATION_NAME), ApplicationFlags::FLAGS_NONE); app.add_main_option( @@ -50,6 +52,16 @@ impl SwayOSDApplication { windows: Rc::new(RefCell::new(Vec::new())), }; + // Apply Server Config + if let Some(margin) = server_config.top_margin { + if (0_f32..1_f32).contains(&margin) { + set_top_margin(margin); + } + } + if let Some(max_volume) = server_config.max_volume { + set_default_max_volume(max_volume); + } + // Parse args app.connect_handle_local_options(clone!(@strong osd_app => move |_app, args| { let actions = match handle_application_args(args.to_variant()) { @@ -59,24 +71,21 @@ impl SwayOSDApplication { for (arg_type, data) in actions { match (arg_type, data) { (ArgTypes::TopMargin, margin) => { - let margin: Option = match margin { - Some(margin) => match margin.parse::() { - Ok(margin) => (0_f32..1_f32).contains(&margin).then_some(margin), - _ => None, - }, - _ => None, - }; - set_top_margin(margin.unwrap_or(*TOP_MARGIN_DEFAULT)) + let margin: Option = margin + .and_then(|margin| margin.parse().ok()) + .and_then(|margin| (0_f32..1_f32).contains(&margin).then_some(margin)); + + if let Some(margin) = margin { + set_top_margin(margin) + } }, (ArgTypes::MaxVolume, max) => { - let volume: u8 = match max { - Some(max) => match max.parse() { - Ok(max) => max, - _ => get_default_max_volume(), - } - _ => get_default_max_volume(), - }; - set_default_max_volume(volume); + let max: Option = max + .and_then(|max| max.parse().ok()); + + if let Some(max) = max { + set_default_max_volume(max); + } }, (arg_type, data) => Self::action_activated(&osd_app, arg_type, data), } diff --git a/src/server/main.rs b/src/server/main.rs index fb571d9..21cbf0d 100644 --- a/src/server/main.rs +++ b/src/server/main.rs @@ -79,6 +79,11 @@ fn main() { std::process::exit(1); } + // Parse Config + let server_config = config::user::read_user_config() + .expect("Failed to parse config file") + .server; + // Load the compiled resource bundle let resources_bytes = include_bytes!(concat!(env!("OUT_DIR"), "/swayosd.gresource")); let resource_data = Bytes::from(&resources_bytes[..]); @@ -107,7 +112,7 @@ fn main() { } // Try loading the users CSS theme - let mut custom_user_css: Option = None; + let mut custom_user_css: Option = server_config.style.clone(); let mut args = args_os().into_iter(); while let Some(arg) = args.next() { match arg.to_str() { @@ -135,5 +140,5 @@ fn main() { // Start the DBus Server async_std::task::spawn(DbusServer::new(sender)); // Start the GTK Application - std::process::exit(SwayOSDApplication::new(receiver).start()); + std::process::exit(SwayOSDApplication::new(server_config, receiver).start()); }