Skip to content

Commit

Permalink
Move to SCSS and load from path
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikReider committed Dec 10, 2023
1 parent e844bca commit 20d23ea
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 49 deletions.
17 changes: 17 additions & 0 deletions data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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())
38 changes: 0 additions & 38 deletions data/style/style.css

This file was deleted.

50 changes: 50 additions & 0 deletions data/style/style.scss
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 0 additions & 2 deletions data/swayosd.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@
<file>icons/scalable/status/source-volume-medium-symbolic.svg</file>
<file>icons/scalable/status/source-volume-low-symbolic.svg</file>
<file>icons/scalable/status/source-volume-muted-symbolic.svg</file>

<file>style/style.css</file>
</gresource>
</gresources>
11 changes: 10 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -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')
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -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' ]
Expand Down
19 changes: 12 additions & 7 deletions src/server/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
22 changes: 21 additions & 1 deletion src/server/utils.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand Down Expand Up @@ -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<PathBuf> {
let mut paths: Vec<PathBuf> = 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<PathBuf> = None;
for try_path in paths {
if try_path.exists() {
path = Some(try_path);
break;
}
}

path
}

pub fn user_style_path() -> Option<String> {
let path = user_config_dir().join("swayosd/style.css");
if path.exists() {
Expand Down

0 comments on commit 20d23ea

Please sign in to comment.