diff --git a/src/global_utils.rs b/src/global_utils.rs index 9fbd6ee..602fba7 100644 --- a/src/global_utils.rs +++ b/src/global_utils.rs @@ -111,6 +111,7 @@ pub(crate) fn handle_application_args( } } } + "style" => continue, e => { eprintln!("Unknown Variant Key: \"{}\"!...", e); return (HandleLocalStatus::FAILURE, actions); diff --git a/src/server/application.rs b/src/server/application.rs index e54ac81..13c6c3c 100644 --- a/src/server/application.rs +++ b/src/server/application.rs @@ -24,6 +24,15 @@ impl SwayOSDApplication { pub fn new(action_receiver: Receiver<(ArgTypes, String)>) -> Self { let app = Application::new(Some(APPLICATION_NAME), ApplicationFlags::FLAGS_NONE); + app.add_main_option( + "style", + glib::Char::from('s' as u8), + OptionFlags::NONE, + OptionArg::String, + "Use a custom Stylesheet file instead of looking for one", + Some(""), + ); + app.add_main_option( "top-margin", glib::Char::from(0), @@ -33,7 +42,7 @@ impl SwayOSDApplication { "OSD margin from top edge (0.5 would be screen center). Default is {}", *utils::TOP_MARGIN_DEFAULT ), - Some("from 0.0 to 1.0"), + Some(""), ); let osd_app = SwayOSDApplication { diff --git a/src/server/main.rs b/src/server/main.rs index b7b7ebb..fb571d9 100644 --- a/src/server/main.rs +++ b/src/server/main.rs @@ -30,7 +30,9 @@ use gtk::{ traits::IconThemeExt, CssProvider, IconTheme, StyleContext, }; +use std::env::args_os; use std::future::pending; +use std::path::PathBuf; use std::str::FromStr; use utils::{get_system_css_path, user_style_path}; use zbus::{dbus_interface, ConnectionBuilder}; @@ -105,7 +107,18 @@ fn main() { } // Try loading the users CSS theme - if let Some(user_config_path) = user_style_path() { + let mut custom_user_css: Option = None; + let mut args = args_os().into_iter(); + while let Some(arg) = args.next() { + match arg.to_str() { + Some("-s") | Some("--style") => match args.next() { + Some(path) => custom_user_css = path.to_str().map(|s| PathBuf::from(s)), + _ => (), + }, + _ => (), + } + } + if let Some(user_config_path) = user_style_path(custom_user_css) { let user_provider = CssProvider::new(); user_provider .load_from_path(&user_config_path) diff --git a/src/server/osd_window.rs b/src/server/osd_window.rs index e37f253..0c1cd6e 100644 --- a/src/server/osd_window.rs +++ b/src/server/osd_window.rs @@ -30,6 +30,7 @@ impl SwayosdWindow { /// Create a new window and assign it to the given application. pub fn new(app: >k::Application, display: &gdk::Display, monitor: &gdk::Monitor) -> Self { let window = gtk::ApplicationWindow::new(app); + window.set_widget_name("osd"); window .style_context() .add_class(>k::STYLE_CLASS_OSD.to_string()); diff --git a/src/server/utils.rs b/src/server/utils.rs index 0e8b3e1..5e14eec 100644 --- a/src/server/utils.rs +++ b/src/server/utils.rs @@ -371,8 +371,13 @@ pub fn get_system_css_path() -> Option { path } -pub fn user_style_path() -> Option { - let path = user_config_dir().join("swayosd/style.css"); +pub fn user_style_path(custom_path: Option) -> Option { + let path = user_config_dir().join("swayosd").join("style.css"); + if let Some(custom_path) = custom_path { + if custom_path.exists() { + return custom_path.to_str().map(|s| s.to_string()); + } + } if path.exists() { return path.to_str().map(|s| s.to_string()); }