S016: R1-11 system accent follows the Caelestia scheme

On niri with the Caelestia shell the desktop colours live in
~/.local/state/caelestia/scheme.json, while GNOME's accent-color (and the portal) stay at
a stale 'red'. system_accent reads the scheme's primary first. smoke.sh isolates
XDG_STATE_HOME so runs never see the user's state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-12 07:09:30 -06:00
commit 8fb9241b9d

View file

@ -48,10 +48,19 @@ pub fn to_hex(c: Color32) -> String {
format!("#{:02X}{:02X}{:02X}", c.r(), c.g(), c.b())
}
/// The system accent colour: KDE's kdeglobals, else GNOME's accent-color setting.
/// The system accent colour: the Caelestia shell's wallpaper scheme, else KDE's kdeglobals, else GNOME's
/// accent-color setting.
pub fn system_accent() -> Option<Color32> {
#[cfg(unix)]
{
// Caelestia (niri or KDE) themes the desktop from ~/.local/state/caelestia/scheme.json and leaves the
// GNOME accent at whatever it was.
if let Some(path) = dirs::state_dir().map(|d| d.join("caelestia/scheme.json"))
&& let Ok(text) = std::fs::read_to_string(path)
&& let Some(c) = caelestia_primary(&text)
{
return Some(c);
}
if let Some(path) = dirs::config_dir().map(|d| d.join("kdeglobals"))
&& let Ok(text) = std::fs::read_to_string(path)
{
@ -94,6 +103,13 @@ pub fn system_accent() -> Option<Color32> {
}
}
/// The primary colour of a Caelestia `scheme.json` (`{"colours": {"primary": "e6b6f1", ...}}`).
fn caelestia_primary(text: &str) -> Option<Color32> {
let json: serde_json::Value = serde_json::from_str(text).ok()?;
let hex = json.get("colours")?.get("primary")?.as_str()?;
parse_hex(hex)
}
/// Whether the system prefers dark (used for "System" mode before winit reports a theme).
pub fn system_dark(winit_theme: Option<winit::window::Theme>) -> bool {
match winit_theme {
@ -609,6 +625,15 @@ mod tests {
assert!(!output.shapes.is_empty());
}
// R1-11: on niri with the Caelestia shell, "System accent" took GNOME's stale accent instead of the desktop's.
#[test]
fn caelestia_scheme_primary() {
let text = r#"{"name": "dynamic", "mode": "dark", "colours": {"background": "161217", "primary": "e6b6f1"}}"#;
assert_eq!(caelestia_primary(text), Some(Color32::from_rgb(0xE6, 0xB6, 0xF1)));
assert_eq!(caelestia_primary(r#"{"colours": {}}"#), None);
assert_eq!(caelestia_primary("not json"), None);
}
#[test]
fn colours() {
assert_eq!(parse_hex("#6750A4"), Some(Color32::from_rgb(0x67, 0x50, 0xA4)));