diff options
Diffstat (limited to 'bin/udt-palette')
| -rwxr-xr-x | bin/udt-palette | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/bin/udt-palette b/bin/udt-palette index a9aa005..95b9092 100755 --- a/bin/udt-palette +++ b/bin/udt-palette @@ -368,6 +368,38 @@ def gen_kvantum(res, scheme, palette, template): return out +# Shades upstream computed from a palette colour rather than taking one. Each +# paints exactly one widget surface, so leaving them literal (the rule that is +# right for the neutral greys) left twelve lavender and Macchiato-tinted spots +# on every other scheme: the window close/min/max hover fills among them. +# +# The percentage is that shade's brightness relative to its base, measured off +# the Macchiato theme these were derived from. Reproducing the exact upstream +# value is not the goal; keeping the relationship is. +GTK_TINTS = [ + ("@ACCENT_93@", "accent", 93), + ("@ACCENT_103@", "accent", 103), + ("@ACCENT_109@", "accent", 109), + ("@ACCENT_118@", "accent", 118), + ("@CRITICAL_110@", "critical", 110), + ("@CRITICAL_92@", "critical", 92), + ("@CRITICAL_79@", "critical", 79), + ("@WARNING_105@", "warning", 105), + ("@WARNING_94@", "warning", 94), + ("@WARNING_86@", "warning", 86), + ("@SUCCESS_109@", "success", 109), + ("@SUCCESS_81@", "success", 81), +] + + +def shade(c, pct): + """Scale a colour's channels by pct, clamped to 0-255.""" + r, g, b, a = c + return (min(255, round(r * pct / 100)), + min(255, round(g * pct / 100)), + min(255, round(b * pct / 100)), a) + + def gen_gtk(res, scheme, palette, template): """GTK3/GTK4: substitute the palette into the upstream stylesheet. @@ -380,6 +412,10 @@ def gen_gtk(res, scheme, palette, template): exactly as drawn, the same rule the Kvantum SVG follows. """ out = template + # Tints first: @ACCENT_93@ starts with @ACCENT, so the plain role loop + # below would otherwise replace that prefix and leave a stray "_93@". + for placeholder, role, pct in GTK_TINTS: + out = out.replace(placeholder, hex6(shade(res[role], pct))) for role in GTK_ROLES: # _RGB@ first: @FG@ is a prefix of @FG_RGB@, so the bare form would # otherwise eat the start of the triple placeholder and leave "_RGB@". @@ -732,6 +768,7 @@ def selftest(): gtk_dir = REPO / "templates" / "gtk" known = {f"@{r.upper()}@" for r in GTK_ROLES} known |= {f"@{r.upper()}_RGB@" for r in GTK_ROLES} + known |= {placeholder for placeholder, _, _ in GTK_TINTS} known.add("@MAUVE@") for tpl in sorted(gtk_dir.glob("*.in")) + sorted((gtk_dir / "assets").glob("*.in")): used = set(re.findall(r"@[A-Z][A-Z_]*@", tpl.read_text())) |
