From c30aa2497e49451f3915707fb79be2858408eb87 Mon Sep 17 00:00:00 2001 From: Breadway Date: Wed, 17 Jun 2026 12:42:12 +0800 Subject: [PATCH] Fix illegible text on light pywal palettes + hot-reload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use bread-theme 0.2.7's luminance-picked ink (@on-*): type chips on @overlay and selected sidebar rows / confirm buttons on @blue kept @fg or @bg, which vanished when those slots came out light/dark. They now use @on-overlay / @on-accent. Add breadpad_shared::theme::apply_live (wraps bread_theme::gtk::apply_app_css) so breadpad and breadman recolour live on `bread-theme reload` and re-read the user's style.css — replacing the build-once provider. bread-theme bumped to v0.2.7 (gtk feature). --- Cargo.lock | 3 ++- breadman/src/main.rs | 19 +++---------------- breadpad-shared/Cargo.toml | 2 +- breadpad-shared/src/theme.rs | 21 +++++++++++++++++---- breadpad/src/main.rs | 21 ++++----------------- 5 files changed, 27 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 46fa8d0..11b33d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -305,9 +305,10 @@ dependencies = [ [[package]] name = "bread-theme" version = "0.2.3" -source = "git+https://github.com/Breadway/bread-ecosystem?tag=v0.2.6#0c8c5c00e435fedff4f81e36d603424c153519a9" +source = "git+https://github.com/Breadway/bread-ecosystem?tag=v0.2.7#ea87083c0615fc9141b0ae4c99f833748a0189d1" dependencies = [ "dirs 5.0.1", + "gtk4", "serde", "serde_json", ] diff --git a/breadman/src/main.rs b/breadman/src/main.rs index 0ee89bc..d46557a 100644 --- a/breadman/src/main.rs +++ b/breadman/src/main.rs @@ -4,7 +4,6 @@ use breadpad_shared::{ parser::parse_rule_based, scheduler::Scheduler, store::Store, - theme::{build_css, load_palette}, types::{Note, NoteType, RecurrenceRule}, }; use chrono::Local; @@ -924,19 +923,7 @@ fn show_add_note_window(parent: >k4::ApplicationWindow, state: AppState) { // ── CSS ─────────────────────────────────────────────────────────────────────── fn apply_css(_cfg: &Config) { - let palette = load_palette(); - let user_css = std::fs::read_to_string(breadpad_shared::config::style_css_path()).ok(); - let css = build_css(&palette, user_css.as_deref()); - - let provider = gtk4::CssProvider::new(); - provider.load_from_string(&css); - let Some(display) = gtk4::gdk::Display::default() else { - tracing::warn!("no default display; skipping CSS provider"); - return; - }; - gtk4::style_context_add_provider_for_display( - &display, - &provider, - gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION, - ); + // Hot-reloads on `bread-theme reload` (recolours to the new pywal palette + // and re-reads the user's style.css). See breadpad_shared::theme::apply_live. + breadpad_shared::theme::apply_live(); } diff --git a/breadpad-shared/Cargo.toml b/breadpad-shared/Cargo.toml index cea30b3..52a5b21 100644 --- a/breadpad-shared/Cargo.toml +++ b/breadpad-shared/Cargo.toml @@ -7,7 +7,7 @@ authors.workspace = true [dependencies] -bread-theme = { git = "https://github.com/Breadway/bread-ecosystem", tag = "v0.2.6" } +bread-theme = { git = "https://github.com/Breadway/bread-ecosystem", tag = "v0.2.7", features = ["gtk"] } anyhow.workspace = true tracing.workspace = true serde.workspace = true diff --git a/breadpad-shared/src/theme.rs b/breadpad-shared/src/theme.rs index 857dcfe..cb1139a 100644 --- a/breadpad-shared/src/theme.rs +++ b/breadpad-shared/src/theme.rs @@ -1,5 +1,18 @@ pub use bread_theme::{load_palette, Palette}; +/// Apply breadpad/breadman's stylesheet and keep it live across palette changes. +/// [`build_css`] bundles the shared component sheet with the app's own rules from +/// the current pywal palette; `bread_theme::gtk::apply_app_css` re-runs this +/// whenever `bread-theme reload` rewrites the shared theme file, so the UI +/// recolours in place (and re-reads the user's `style.css` override too). +pub fn apply_live() { + bread_theme::gtk::apply_app_css(|| { + let palette = load_palette(); + let user_css = std::fs::read_to_string(crate::config::style_css_path()).ok(); + build_css(&palette, user_css.as_deref()) + }); +} + /// Generate the full breadpad/breadman CSS string. The base — `@define-color` /// palette, fonts, and generic widget styling — comes from the shared /// `bread_theme::stylesheet`, so breadpad and breadman look identical to the @@ -32,7 +45,7 @@ window { border-radius: 8px; } .type-chip { background: @overlay; - color: @fg; + color: @on-overlay; border-radius: 999px; padding: 4px 12px; font-size: 12px; @@ -41,12 +54,12 @@ window { border-radius: 8px; } .type-chip.active { background: @blue; - color: @bg; + color: @on-accent; } .confirm-button { background: @blue; - color: @bg; + color: @on-accent; border: none; border-radius: 8px; padding: 8px 16px; @@ -90,7 +103,7 @@ window { border-radius: 8px; } .sidebar-row:selected { background: @blue; - color: @bg; + color: @on-accent; font-weight: 500; } diff --git a/breadpad/src/main.rs b/breadpad/src/main.rs index c840557..aa924d0 100644 --- a/breadpad/src/main.rs +++ b/breadpad/src/main.rs @@ -2,10 +2,9 @@ use anyhow::Result; use breadpad_shared::{ calendar::CalDavClient, classifier::Classifier, - config::{style_css_path, Config}, + config::Config, scheduler::Scheduler, store::Store, - theme::{build_css, load_palette}, types::{Note, NoteType}, }; use gtk4::{glib, prelude::*}; @@ -765,19 +764,7 @@ fn save_note_classified( } fn apply_css(_cfg: &Config) { - let palette = load_palette(); - let user_css = std::fs::read_to_string(style_css_path()).ok(); - let css = build_css(&palette, user_css.as_deref()); - - let provider = gtk4::CssProvider::new(); - provider.load_from_string(&css); - let Some(display) = gtk4::gdk::Display::default() else { - tracing::warn!("no default display; skipping CSS provider"); - return; - }; - gtk4::style_context_add_provider_for_display( - &display, - &provider, - gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION, - ); + // Hot-reloads on `bread-theme reload` (recolours to the new pywal palette + // and re-reads the user's style.css). See breadpad_shared::theme::apply_live. + breadpad_shared::theme::apply_live(); }