Refactor theme onto bread-theme; add bakery.toml and release workflow

- Cargo.toml: depend on bread-theme (path dep for local dev, git dep for
  production) with gtk feature; remove local theme dependencies
- src/theme.rs: replace local pywal/Catppuccin impl with bread_theme::gtk
  helpers; local bar-specific CSS is preserved
- bakery.toml: describes breadbar for bakery install
- release.yml: builds on hestia self-hosted runner, publishes binary to
  dl.breadway.dev and GitHub Releases on v* tags

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Breadway 2026-06-06 22:31:10 +08:00
parent 9b9705520e
commit 9e829d3663
8 changed files with 456 additions and 114 deletions

View file

@ -3,7 +3,9 @@ use relm4::ComponentSender;
pub fn current() -> String {
let dt = gtk4::glib::DateTime::now_local().expect("local time");
format!("{:02}:{:02}", dt.hour(), dt.minute())
let date = dt.format("%a %d/%m").expect("date format");
let time = format!("{:02}:{:02}", dt.hour(), dt.minute());
format!("{} {}", date, time)
}
pub fn spawn_ticker(sender: ComponentSender<App>) {

View file

@ -6,6 +6,7 @@ macro_rules! asset {
mod bar;
mod notifications;
mod osd;
mod theme;
use gtk4::prelude::*;
@ -185,6 +186,7 @@ impl SimpleComponent for App {
bar::clock::spawn_ticker(sender.clone());
bar::stats::spawn_poller(sender);
notifications::spawn();
osd::spawn();
ComponentParts { model, widgets }
}
@ -255,9 +257,10 @@ fn stat_pair(icon_path: &str, label: &gtk4::Label) -> gtk4::Box {
}
fn svg_texture(path: &str) -> gtk4::gdk::Texture {
let fg = theme::fg_color();
let svg = std::fs::read_to_string(path)
.unwrap_or_default()
.replace("currentColor", "white")
.replace("currentColor", &fg)
.replace(r#"width="24" height="24""#, r#"width="16" height="16""#);
let bytes = gtk4::glib::Bytes::from_owned(svg.into_bytes());
gtk4::gdk::Texture::from_bytes(&bytes).expect("svg load")

184
src/osd.rs Normal file
View file

@ -0,0 +1,184 @@
use std::{cell::Cell, rc::Rc, time::Duration};
use gtk4::prelude::*;
use gtk4_layer_shell::{Edge, Layer, LayerShell};
use tokio::sync::mpsc;
enum OsdEvent {
Volume { pct: u8, muted: bool },
Brightness { pct: u8 },
}
pub fn spawn() {
let (tx, rx) = mpsc::channel::<OsdEvent>(8);
let tx1 = tx.clone();
std::thread::spawn(move || volume_watcher(tx1));
std::thread::spawn(move || brightness_watcher(tx));
relm4::spawn_local(run_osd(rx));
}
fn volume_watcher(tx: mpsc::Sender<OsdEvent>) {
use std::io::{BufRead, BufReader};
use std::process::{Command, Stdio};
let Ok(mut child) = Command::new("pactl")
.args(["subscribe"])
.stdout(Stdio::piped())
.stderr(Stdio::null())
.spawn()
else {
return;
};
let stdout = child.stdout.take().unwrap();
let reader = BufReader::new(stdout);
for line in reader.lines().flatten() {
if line.contains("'change' on sink") {
if let Some(evt) = query_volume() {
let _ = tx.blocking_send(evt);
}
}
}
}
fn query_volume() -> Option<OsdEvent> {
use std::process::Command;
let vol = Command::new("pactl")
.args(["get-sink-volume", "@DEFAULT_SINK@"])
.output()
.ok()?;
let mute = Command::new("pactl")
.args(["get-sink-mute", "@DEFAULT_SINK@"])
.output()
.ok()?;
let vol_str = String::from_utf8_lossy(&vol.stdout);
let mute_str = String::from_utf8_lossy(&mute.stdout);
// "Volume: front-left: 45875 / 70% / -8.58 dB, ..."
let pct: u8 = vol_str
.split('/')
.nth(1)?
.trim()
.trim_end_matches('%')
.trim()
.parse()
.ok()?;
let muted = mute_str.contains(": yes");
Some(OsdEvent::Volume { pct, muted })
}
fn brightness_watcher(tx: mpsc::Sender<OsdEvent>) {
use std::fs;
let base = match fs::read_dir("/sys/class/backlight")
.ok()
.and_then(|mut d| d.next())
.and_then(|e| e.ok())
.map(|e| e.path())
{
Some(p) => p,
None => return,
};
let bright_path = base.join("brightness");
let max_path = base.join("max_brightness");
let max: u64 = match fs::read_to_string(&max_path)
.ok()
.and_then(|s| s.trim().parse().ok())
{
Some(v) if v > 0 => v,
_ => return,
};
// Initialize to current value so startup doesn't trigger OSD.
let mut last: u64 = fs::read_to_string(&bright_path)
.ok()
.and_then(|s| s.trim().parse().ok())
.unwrap_or(u64::MAX);
loop {
if let Some(val) = fs::read_to_string(&bright_path)
.ok()
.and_then(|s| s.trim().parse::<u64>().ok())
{
if val != last {
last = val;
let pct = ((val * 100) / max).min(100) as u8;
let _ = tx.blocking_send(OsdEvent::Brightness { pct });
}
}
std::thread::sleep(Duration::from_millis(200));
}
}
async fn run_osd(mut rx: mpsc::Receiver<OsdEvent>) {
let window = create_window();
let container = gtk4::Box::new(gtk4::Orientation::Vertical, 6);
container.set_margin_top(12);
container.set_margin_bottom(12);
container.set_margin_start(16);
container.set_margin_end(16);
window.set_child(Some(&container));
let header = gtk4::Box::new(gtk4::Orientation::Horizontal, 0);
let kind_lbl = gtk4::Label::new(Some("Volume"));
kind_lbl.add_css_class("osd-kind");
kind_lbl.set_hexpand(true);
kind_lbl.set_xalign(0.0);
let pct_lbl = gtk4::Label::new(Some("0%"));
pct_lbl.add_css_class("osd-pct");
header.append(&kind_lbl);
header.append(&pct_lbl);
container.append(&header);
let pbar = gtk4::ProgressBar::new();
pbar.add_css_class("osd-bar");
container.append(&pbar);
let dismiss_token = Rc::new(Cell::new(0u32));
while let Some(event) = rx.recv().await {
let (kind, pct) = match event {
OsdEvent::Volume { pct, muted } => {
(if muted { "Volume (Muted)" } else { "Volume" }, pct)
}
OsdEvent::Brightness { pct } => ("Brightness", pct),
};
kind_lbl.set_label(kind);
pct_lbl.set_label(&format!("{pct}%"));
pbar.set_fraction(pct as f64 / 100.0);
window.set_visible(true);
let token = dismiss_token.get().wrapping_add(1);
dismiss_token.set(token);
let dtok = dismiss_token.clone();
let win = window.clone();
relm4::spawn_local(async move {
gtk4::glib::timeout_future(Duration::from_millis(2000)).await;
if dtok.get() == token {
win.set_visible(false);
}
});
}
}
fn create_window() -> gtk4::Window {
let window = gtk4::Window::new();
window.add_css_class("breadbar-osd");
window.init_layer_shell();
window.set_layer(Layer::Overlay);
window.set_anchor(Edge::Bottom, true);
window.set_margin(Edge::Bottom, 80);
window.set_default_width(280);
window
}

View file

@ -1,5 +1,5 @@
use bread_theme::{gtk as bgtk, hex_to_rgba, load_palette};
use gtk4::CssProvider;
use serde::Deserialize;
use std::cell::RefCell;
thread_local! {
@ -7,125 +7,53 @@ thread_local! {
static USER_PROVIDER: RefCell<Option<CssProvider>> = const { RefCell::new(None) };
}
#[derive(Deserialize)]
struct WalColors {
special: Special,
colors: Colors,
}
#[derive(Deserialize)]
struct Special {
background: String,
}
#[derive(Deserialize)]
struct Colors {
color0: String,
color1: String,
color15: String,
}
fn hex_to_rgba(hex: &str, alpha: f32) -> String {
let h = hex.trim_start_matches('#');
let r = u8::from_str_radix(&h[0..2], 16).unwrap_or(0);
let g = u8::from_str_radix(&h[2..4], 16).unwrap_or(0);
let b = u8::from_str_radix(&h[4..6], 16).unwrap_or(0);
format!("rgba({r},{g},{b},{alpha})")
}
fn load_css() -> String {
let home = std::env::var("HOME").unwrap_or_default();
let text =
std::fs::read_to_string(format!("{home}/.cache/wal/colors.json")).unwrap_or_default();
let (bg, surface, fg, accent) = if let Ok(wal) = serde_json::from_str::<WalColors>(&text) {
(
wal.special.background,
wal.colors.color0,
wal.colors.color15,
wal.colors.color1,
)
} else {
(
"#1e1e2e".to_string(),
"#181825".to_string(),
"#cdd6f4".to_string(),
"#89b4fa".to_string(),
)
};
let p = load_palette();
format!(
"* {{ font-family: 'JetBrainsMono Nerd Font Mono', monospace; font-size: 14px; }}\
"* {{ font-family: 'Varela Round', sans-serif; font-size: 14px; }}\
window.breadbar {{ background-color: {bg_rgba}; border-radius: 0; }}\
label {{ color: {fg}; }}\
.workspace-btn {{ background: transparent; color: {fg}; opacity: 0.45;\
border-radius: 0 0 8px 8px; border: none; outline: none; box-shadow: none;\
min-width: 24px; padding: 2px 8px; }}\
min-width: 24px; padding: 4px 8px; }}\
.workspace-btn:hover {{ opacity: 0.8; }}\
.workspace-btn.active {{ background: {accent}; opacity: 1; }}\
.stats-box {{ margin-right: 8px; }}\
.stat-pair {{ margin-right: 8px; }}\
.stat-icon {{ margin-right: 3px; }}\
.bt-icon {{ margin-right: 8px; }}\
.stat-pair {{ margin-right: 12px; }}\
.stat-icon {{ margin-right: 5px; }}\
.bt-icon {{ margin-right: 12px; }}\
window.breadbar-notification {{ background-color: alpha({bg_plain}, 0.95); }}\
.notification-card {{ background: {surface}; border-radius: 6px;\
padding: 10px; margin-bottom: 4px; }}\
.notification-card {{ background: {surface}; border-radius: 8px;\
padding: 12px; margin-bottom: 8px; }}\
.notification-summary {{ font-weight: bold; color: {fg}; }}\
.notification-app {{ color: {fg}; opacity: 0.6; }}\
.notification-body {{ color: {fg}; }}",
bg_plain = bg,
bg_rgba = hex_to_rgba(&bg, 0.92),
surface = surface,
fg = fg,
accent = accent,
.notification-body {{ color: {fg}; }}\
window.breadbar-osd {{ background-color: alpha({bg_plain}, 0.95); border-radius: 8px; }}\
.osd-kind {{ color: {fg}; opacity: 0.75; font-size: 12px; }}\
.osd-pct {{ color: {fg}; font-weight: bold; font-size: 12px; }}\
progressbar.osd-bar {{ min-height: 8px; }}\
progressbar.osd-bar trough {{ background-image: none; background-color: {trough}; border-radius: 4px; min-height: 8px; }}\
progressbar.osd-bar trough progress {{ background-image: none; background-color: {accent}; border-radius: 4px; min-height: 8px; }}",
bg_plain = p.background,
bg_rgba = hex_to_rgba(&p.background, 0.92),
surface = p.color0,
fg = p.foreground,
accent = p.color4,
trough = hex_to_rgba(&p.color4, 0.25),
)
}
/// Returns the current foreground colour (used for icon tinting in the stats bar).
pub fn fg_color() -> String {
load_palette().foreground
}
/// Apply (or reload) the theme CSS. Safe to call from `glib::MainContext::invoke`.
pub fn apply() {
let css = load_css();
let display = gtk4::gdk::Display::default().expect("no display");
PROVIDER.with(|cell| bgtk::apply_css(&css, cell));
PROVIDER.with(|cell| {
let mut guard = cell.borrow_mut();
if let Some(p) = guard.as_ref() {
p.load_from_string(&css);
} else {
let p = CssProvider::new();
p.load_from_string(&css);
gtk4::style_context_add_provider_for_display(
&display,
&p,
gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION,
);
*guard = Some(p);
}
});
// User override: ~/.config/breadbar/style.css — send SIGHUP to reload.
let home = std::env::var("HOME").unwrap_or_default();
let user_path = format!("{home}/.config/breadbar/style.css");
USER_PROVIDER.with(|cell| {
let mut guard = cell.borrow_mut();
match std::fs::read_to_string(&user_path) {
Ok(user_css) => {
if let Some(p) = guard.as_ref() {
p.load_from_string(&user_css);
} else {
let p = CssProvider::new();
p.load_from_string(&user_css);
gtk4::style_context_add_provider_for_display(
&display,
&p,
gtk4::STYLE_PROVIDER_PRIORITY_USER,
);
*guard = Some(p);
}
}
Err(_) => {
if let Some(p) = guard.as_ref() {
p.load_from_string("");
}
}
}
});
let user_path = std::path::PathBuf::from(format!("{home}/.config/breadbar/style.css"));
USER_PROVIDER.with(|cell| bgtk::apply_user_css(&user_path, cell));
}