diff --git a/data/meson.build b/data/meson.build index 8e01f39..b3099cf 100644 --- a/data/meson.build +++ b/data/meson.build @@ -53,3 +53,20 @@ configure_file( output: '@BASENAME@', install_dir: systemd_service_install_dir ) + +# SCSS Compilation +style_css = custom_target( + 'SCSS Compilation', + build_by_default: true, + input : 'style/style.scss', + output : 'style.css', + install: true, + install_dir: config_path, + command : [ + sassc, + '@INPUT@', + '@OUTPUT@' + ], +) + +message(style_css.full_path()) diff --git a/data/style/style.css b/data/style/style.css deleted file mode 100644 index f67118f..0000000 --- a/data/style/style.css +++ /dev/null @@ -1,38 +0,0 @@ -window { - padding: 12px 20px; - border-radius: 999px; - border: none; - background: alpha(@theme_bg_color, 0.8); -} - -#container { - margin: 16px; -} - -image, label { - color: @theme_fg_color; -} - -progressbar:disabled, -image:disabled { - opacity: 0.5; -} - -progressbar { - min-height: 6px; - border-radius: 999px; - background: transparent; - border: none; -} -trough { - min-height: inherit; - border-radius: inherit; - border: none; - background: alpha(@theme_fg_color, 0.5); -} -progress { - min-height: inherit; - border-radius: inherit; - border: none; - background: @theme_fg_color; -} diff --git a/data/style/style.scss b/data/style/style.scss new file mode 100644 index 0000000..4ec28ac --- /dev/null +++ b/data/style/style.scss @@ -0,0 +1,50 @@ +window#osd { + padding: 12px 20px; + border-radius: 999px; + border: none; + background: #{"alpha(@theme_bg_color, 0.8)"}; + + #container { + margin: 16px; + } + + image, + label { + color: #{"@theme_fg_color"}; + } + + progressbar:disabled, + image:disabled { + opacity: 0.5; + } + + progressbar { + min-height: 6px; + border-radius: 999px; + background: transparent; + border: none; + } + trough { + min-height: inherit; + border-radius: inherit; + border: none; + background: #{"alpha(@theme_fg_color, 0.5)"}; + } + progress { + min-height: inherit; + border-radius: inherit; + border: none; + background: #{"@theme_fg_color"}; + } +} + +window#alt-tab { + padding: 12px 20px; + border-radius: 12px; + border: none; + background: #{"alpha(@theme_bg_color, 0.8)"}; + + flowbox { + background-color: red; + } +} diff --git a/data/swayosd.gresource.xml b/data/swayosd.gresource.xml index 842d2fd..ffc363c 100644 --- a/data/swayosd.gresource.xml +++ b/data/swayosd.gresource.xml @@ -18,7 +18,5 @@ icons/scalable/status/source-volume-medium-symbolic.svg icons/scalable/status/source-volume-low-symbolic.svg icons/scalable/status/source-volume-muted-symbolic.svg - - style/style.css diff --git a/meson.build b/meson.build index bef3828..a648b59 100644 --- a/meson.build +++ b/meson.build @@ -1,9 +1,18 @@ -project('swayosd', 'rust', +project('swayosd', 'rust', version: '0.1.0', meson_version: '>= 0.62.0', default_options: [ 'warning_level=2', 'werror=false', ], ) +config_path = join_paths(get_option('sysconfdir'), 'xdg', 'swayosd') + +# glib-compile-resources Dependency +assert(find_program('glib-compile-resources').found()) + +# SCSS Dependency +sassc = find_program('sassc') +assert(sassc.found()) + subdir('data') subdir('src') diff --git a/src/meson.build b/src/meson.build index 9af1066..eb316b0 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,6 +1,7 @@ pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name()) cargo_bin = find_program('cargo') +assert(cargo_bin.found()) cargo_opt = [ '--manifest-path', meson.project_source_root() / 'Cargo.toml' ] cargo_opt += [ '--target-dir', meson.project_build_root() / 'src' ] cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ] diff --git a/src/server/main.rs b/src/server/main.rs index 11192a2..b7b7ebb 100644 --- a/src/server/main.rs +++ b/src/server/main.rs @@ -32,7 +32,7 @@ use gtk::{ }; use std::future::pending; use std::str::FromStr; -use utils::user_style_path; +use utils::{get_system_css_path, user_style_path}; use zbus::{dbus_interface, ConnectionBuilder}; struct DbusServer { @@ -92,12 +92,17 @@ fn main() { // Load the provided default CSS theme let provider = CssProvider::new(); - provider.load_from_resource(&format!("{}/style/style.css", GRESOURCE_BASE_PATH)); - StyleContext::add_provider_for_screen( - &screen, - &provider, - gtk::STYLE_PROVIDER_PRIORITY_APPLICATION as u32, - ); + match get_system_css_path() { + Some(path) => match provider.load_from_path(path.to_str().unwrap()) { + Ok(_) => StyleContext::add_provider_for_screen( + &screen, + &provider, + gtk::STYLE_PROVIDER_PRIORITY_APPLICATION as u32, + ), + Err(error) => eprintln!("Could not load default CSS stylesheet: {}", error), + }, + None => eprintln!("Could not find the system CSS file..."), + } // Try loading the users CSS theme if let Some(user_config_path) = user_style_path() { diff --git a/src/server/utils.rs b/src/server/utils.rs index 8b87b56..0e8b3e1 100644 --- a/src/server/utils.rs +++ b/src/server/utils.rs @@ -1,10 +1,11 @@ -use gtk::glib::user_config_dir; +use gtk::glib::{system_config_dirs, user_config_dir}; use lazy_static::lazy_static; use substring::Substring; use std::{ fs::{self, File}, io::{prelude::*, BufReader}, + path::{Path, PathBuf}, sync::Mutex, }; @@ -351,6 +352,25 @@ pub fn volume_to_f64(volume: &Volume) -> f64 { (100.0 * tmp_vol / f64::from(Volume::NORMAL.0 - Volume::MUTED.0)).round() } +pub fn get_system_css_path() -> Option { + let mut paths: Vec = Vec::new(); + for path in system_config_dirs() { + paths.push(path.join("swayosd").join("style.css")); + } + + paths.push(Path::new("/usr/local/etc/xdg/swaync/style.css").to_path_buf()); + + let mut path: Option = None; + for try_path in paths { + if try_path.exists() { + path = Some(try_path); + break; + } + } + + path +} + pub fn user_style_path() -> Option { let path = user_config_dir().join("swayosd/style.css"); if path.exists() {