Follow the desktop accent colour and colour scheme (XDG portal)
Read org.freedesktop.appearance accent-color and color-scheme from org.freedesktop.portal.Settings over GDBus in the GTK stub and follow SettingChanged. The accent recolours the selected tab, sliders, peak meters and the checked Default button through an application-priority GtkCssProvider (named colours and --accent-* variables too, for themes that use them); the colour scheme sets the theme's dark/light variant. Without a portal or accent the theme's own stays. Colour conversion, WCAG contrast (readable foreground on the accent, readable accent text on the window) and the CSS live in model/accent.mbt with unit tests. The smoke test runs a fake portal on a private session bus, switches the accent live from green to orange and renders the tabs again (docs/screenshots/accent-*.png). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bc675459d9
commit
74d85ecdfc
16 files changed
+947
-12
No files matched your search
+65
-5
@@ -134,6 +134,8 @@ fn new_row_view(app : App, tab : @model.Tab, row : @model.Row) -> RowView {
|
||||
)
|
||||
tags.push(tag)
|
||||
b.set_tooltip("Set as default (fallback) device")
|
||||
// Shown in the accent colour when checked (see @model.accent_css).
|
||||
b.add_css_class("mm-default")
|
||||
header.append(b)
|
||||
Some(b)
|
||||
}
|
||||
@@ -470,10 +472,52 @@ fn build_ui() -> App {
|
||||
app
|
||||
}
|
||||
|
||||
///|
|
||||
/// Follow the desktop's accent colour and dark/light preference (XDG Desktop
|
||||
/// Portal). Without a portal, or with no accent set, the theme's own accent
|
||||
/// stays.
|
||||
|
||||
///|
|
||||
/// The accent applied last ("#rrggbb", or "" for the theme's own).
|
||||
let applied_accent : Ref[String] = { val: "", }
|
||||
|
||||
///|
|
||||
fn follow_appearance(log~ : Bool = false) -> Unit {
|
||||
let _ = @gtk.watch_appearance(fn(a) {
|
||||
let scheme = @model.ColorScheme::from_portal(a.color_scheme)
|
||||
@gtk.set_color_scheme(a.color_scheme)
|
||||
let dark = match scheme {
|
||||
Dark => true
|
||||
Light => false
|
||||
NoPreference => @gtk.prefers_dark()
|
||||
}
|
||||
let (r, g, b) = a.accent
|
||||
let accent = @model.Rgb::from_portal(r, g, b)
|
||||
match accent {
|
||||
Some(c) => @gtk.set_accent_css(@model.accent_css(c, dark))
|
||||
None => @gtk.set_accent_css("")
|
||||
}
|
||||
applied_accent.val = match accent {
|
||||
Some(c) => c.to_hex()
|
||||
None => ""
|
||||
}
|
||||
if log {
|
||||
// The smoke test checks these lines to see live updates arrive.
|
||||
let name = match accent {
|
||||
Some(c) => c.to_hex()
|
||||
None => "theme default"
|
||||
}
|
||||
println("moonmix: accent \{name}, \{if dark { "dark" } else { "light" }}")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
///|
|
||||
/// Test hook: MOONMIX_SCREENSHOT=/path/prefix renders every tab to
|
||||
/// <prefix>-<n>.png once connected, then exits. Used for headless CI/smoke
|
||||
/// runs (GDK_BACKEND=broadway or x11 under Xvfb).
|
||||
/// runs (GDK_BACKEND=broadway or x11 under Xvfb). With
|
||||
/// MOONMIX_SCREENSHOT_ACCENT=#rrggbb it first waits (up to 20 s) until the
|
||||
/// portal has delivered that accent colour.
|
||||
fn screenshot_mode(app : App, prefix : String) -> Unit {
|
||||
let tab_count = app.tabs.length()
|
||||
// Offscreen rendering occasionally yields an empty frame right after a tab
|
||||
@@ -504,7 +548,19 @@ fn screenshot_mode(app : App, prefix : String) -> Unit {
|
||||
})
|
||||
}
|
||||
|
||||
@gtk.timeout(1500, fn() { shoot(0, 0) })
|
||||
let want = env_var("MOONMIX_SCREENSHOT_ACCENT").unwrap_or("")
|
||||
fn start(waited : Int32) -> Unit {
|
||||
if want == "" || applied_accent.val == want || waited >= 200 {
|
||||
if waited >= 200 {
|
||||
println("moonmix: accent \{want} never arrived")
|
||||
}
|
||||
shoot(0, 0)
|
||||
} else {
|
||||
@gtk.timeout(100, fn() { start(waited + 1) })
|
||||
}
|
||||
}
|
||||
|
||||
@gtk.timeout(1500, fn() { start(0) })
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -518,6 +574,11 @@ fn main {
|
||||
println("moonmix: cannot open a display (is WAYLAND_DISPLAY/DISPLAY set?)")
|
||||
c_exit(1)
|
||||
}
|
||||
let screenshot = match env_var("MOONMIX_SCREENSHOT") {
|
||||
Some(prefix) if prefix != "" => Some(prefix)
|
||||
_ => None
|
||||
}
|
||||
follow_appearance(log=screenshot is Some(_))
|
||||
let app = build_ui()
|
||||
@wp.on_event(fn(ev) { app.on_wp_event(ev) })
|
||||
if !@wp.start() {
|
||||
@@ -525,9 +586,8 @@ fn main {
|
||||
}
|
||||
app.window.present()
|
||||
app.start_meter_timer()
|
||||
match env_var("MOONMIX_SCREENSHOT") {
|
||||
Some(prefix) if prefix != "" => screenshot_mode(app, prefix)
|
||||
_ => ()
|
||||
if screenshot is Some(prefix) {
|
||||
screenshot_mode(app, prefix)
|
||||
}
|
||||
@gtk.run()
|
||||
}
|
||||
Reference in new issue
Block a user