diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-11 18:32:31 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-11 18:32:31 +0200 |
| commit | b7a660d5587b7d23dbcfbb39d14de22eb9600754 (patch) | |
| tree | 99123d900377fa06f43e08fa961901afb28b97bb /bin/udt-palette | |
| parent | 1f37c129ac0b72fd2e177618ae6aed5f4233873d (diff) | |
| download | unified-desktop-theme-b7a660d5587b7d23dbcfbb39d14de22eb9600754.tar.gz unified-desktop-theme-b7a660d5587b7d23dbcfbb39d14de22eb9600754.zip | |
fix(palette): emit the rofi palette from roles, not scheme colour names
Switching to tokyo-night broke every rofi launcher. The themes reference
Catppuccin spellings (@base, @text, @surface0), and gen_rofi emitted whatever
names the scheme happened to use, so under Tokyo Night the palette defined bg
and fg instead and rofi refused to parse a theme referencing colours that did
not exist.
The names the themes ask for are now filled from roles, the same way every
other consumer already worked. The spellings stay Catppuccin's because that is
what the themes were written against; only the values change per scheme.
Adds a selftest that collects every @name used in a colour property across the
themes and asserts the generator emits it. Verified it fails when a name is
removed, rather than passing vacuously, and all seven themes now parse under
all four schemes.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015gbjA2bmswN8jyPDKzrvqe
Diffstat (limited to 'bin/udt-palette')
| -rwxr-xr-x | bin/udt-palette | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/bin/udt-palette b/bin/udt-palette index 1a1c6b0..1df0c4f 100755 --- a/bin/udt-palette +++ b/bin/udt-palette @@ -114,17 +114,34 @@ def rgba(c): BANNER = "Generated by udt-palette from palette/{scheme}.conf. Do not edit." +# The names the rofi themes reference. They are Catppuccin spellings because +# that is what the themes were written against, but each is filled from a role, +# so a scheme that names nothing "base" still produces a parseable palette. +ROFI_NAMES = [ + ("base", "bg"), ("mantle", "bg_alt"), ("crust", "bg_deep"), + ("surface0", "surface"), ("surface1", "surface_alt"), + ("surface2", "surface_high"), + ("text", "fg"), ("subtext0", "fg_dim"), ("subtext1", "fg_bright"), + ("overlay0", "fg_faint"), ("overlay1", "mid_low"), ("overlay2", "mid_high"), + ("red", "critical"), ("green", "success"), ("yellow", "warning"), + ("teal", "info"), ("blue", "border_active"), ("lavender", "accent"), +] + + def gen_rofi(res, scheme, palette): - """rofi: the structural palette, under the scheme's own colour names. + """rofi: the structural palette, under the names the themes reference. - Emits palette names rather than roles because the rofi themes were written - against Catppuccin names and still use them. The role layer reaches rofi - through accent.rasi, which udt-accent generates per wallpaper. + Every value comes from a role, not from the scheme's own colour names: the + themes ask for @base and @text, and Tokyo Night calls those bg and fg, so + emitting palette names outright left the themes referencing colours that + did not exist and rofi refusing to parse the file. """ - rows = "\n".join(f" {k + ':':11}{v}ff;" for k, v in sorted(palette.items())) + rows = "\n".join(f" {name + ':':11}{hex8(res[role])};" + for name, role in ROFI_NAMES) return ( f"/*\n * {BANNER.format(scheme=scheme)}\n *\n" - " * Structural colors only. The accent lives in accent.rasi.\n */\n\n" + " * Structural colors only. The accent lives in accent.rasi.\n" + " * Names are Catppuccin's; values come from the scheme's roles.\n */\n\n" f"* {{\n{rows}\n}}\n" ) @@ -444,6 +461,26 @@ def selftest(): assert not missing, f"{scheme} is missing roles: {sorted(missing)}" assert not extra, f"{scheme} has roles no other scheme has: {sorted(extra)}" + # Every name the rofi themes reference must be emitted, or rofi refuses to + # parse the theme and every launcher on the desktop stops opening. This is + # a real regression that shipped: gen_rofi used to emit the scheme's own + # colour names, which only happened to match under Catppuccin. + theme_dir = REPO / "rofi" / "udt" + used = set() + for theme in theme_dir.glob("*.rasi"): + if theme.name in ("palette.rasi", "accent.rasi"): + continue + # Only @name in a colour-property value: @import is a directive and + # @radius a dimension, neither of which this file defines. + # Only @name in a colour-property value. @import is a directive and + # border-radius a dimension, so neither is a colour this file owes. + used |= set(re.findall( + r"(?!border-radius)(?:[\w-]*color|background[\w-]*|border):\s*@(\w+)", + theme.read_text())) + emitted = {name for name, _ in ROFI_NAMES} | {"accent"} + missing = used - emitted + assert not missing, f"rofi themes reference undefined colours: {sorted(missing)}" + # Alpha survives the round trip into each syntax. assert hex8((202, 211, 245, 75)) == "#cad3f5bf", hex8((202, 211, 245, 75)) assert hex8((202, 211, 245, 100)) == "#cad3f5ff" |
