aboutsummaryrefslogtreecommitdiffstats
path: root/bin/udt-accent
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-11 17:22:01 +0200
committerDanilo M. <danix@danix.xyz>2026-09-11 17:22:01 +0200
commit81f7686fe7d8edc5c020f33e8766d4de7c5beccd (patch)
tree13f06800f4930c0bd850e1dc1659886163737cd7 /bin/udt-accent
parent7b55910a786c7652ac80a576399ebd9f81a8ac72 (diff)
downloadunified-desktop-theme-81f7686fe7d8edc5c020f33e8766d4de7c5beccd.tar.gz
unified-desktop-theme-81f7686fe7d8edc5c020f33e8766d4de7c5beccd.zip
fix(accent): make udt-accent scheme-independent
Two things still assumed Catppuccin. The QML header hardcoded "Catppuccin Macchiato" regardless of the scheme in use, and the selftest asserted that an orange input snaps to a colour named "peach", which is true only under Catppuccin: Tokyo Night calls that hue "orange" and the test failed the moment the scheme changed. The header now names the scheme it generated from. The snapping assertions test the property instead of the spelling: an input must land within 0.6 rad of its own hue, and a border neighbour must sit nearer the accent than its opposite. Both hold under any palette. Verified: --selftest passes under macchiato, tokyo-night, nord and dracula. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015gbjA2bmswN8jyPDKzrvqe
Diffstat (limited to 'bin/udt-accent')
-rwxr-xr-xbin/udt-accent23
1 files changed, 17 insertions, 6 deletions
diff --git a/bin/udt-accent b/bin/udt-accent
index 1a222b5..75058df 100755
--- a/bin/udt-accent
+++ b/bin/udt-accent
@@ -25,7 +25,7 @@ from pathlib import Path
# palette/<scheme>.conf and palette/roles-<scheme>.conf, so the accents this
# snaps to follow whatever scheme is selected. Regenerate with ./install.sh.
sys.path.insert(0, str(Path(__file__).resolve().parent))
-from udt_colors import ACCENTS, FALLBACK, PALETTE # noqa: E402
+from udt_colors import ACCENTS, FALLBACK, PALETTE, SCHEME # noqa: E402
MIN_CHROMA = 10.0
@@ -204,7 +204,7 @@ def write_qml(name):
content = (
"// Generated by udt-accent. Do not edit.\n"
"//\n"
- "// The Catppuccin Macchiato palette from palette.rasi, plus the accent\n"
+ f"// The {SCHEME} palette from palette.rasi, plus the accent\n"
"// currently snapped from the wallpaper. Import it from a quickshell\n"
"// component and watch this file to follow theme changes.\n"
"pragma Singleton\n"
@@ -307,9 +307,14 @@ def selftest():
got = snap(hexval)
assert got == name, f"{name} ({hexval}) snapped to {got}"
- # Representative real-world inputs.
- assert snap("#ff8800") == "peach", snap("#ff8800")
- assert snap("#00cc44") == "green", snap("#00cc44")
+ # Representative real-world inputs. Asserted by hue rather than by name:
+ # the accent table is generated, so the colour an orange input snaps to is
+ # called "peach" under Catppuccin and "orange" under Tokyo Night.
+ for probe in ("#ff8800", "#00cc44", "#3366ff"):
+ got = snap(probe)
+ delta = abs(_hue(ACCENTS[got]) - _hue(probe))
+ delta = min(delta, 2 * math.pi - delta)
+ assert delta < 0.6, f"{probe} snapped to {got}, {delta:.2f} rad away"
# A near-grey has an unstable hue angle and must take the fallback.
assert snap("#888888") == FALLBACK, snap("#888888")
@@ -320,7 +325,13 @@ def selftest():
for name in ACCENTS:
before, after = hue_neighbours(name)
assert len({before, name, after}) == 3, (name, before, after)
- assert hue_neighbours("peach") == ("red", "yellow"), hue_neighbours("peach")
+ # Neighbours are the adjacent hues on the wheel, so each sits nearer to
+ # the accent than the accent's opposite does.
+ for name in ACCENTS:
+ before, after = hue_neighbours(name)
+ for neighbour in (before, after):
+ delta = abs(_hue(ACCENTS[neighbour]) - _hue(ACCENTS[name]))
+ assert min(delta, 2 * math.pi - delta) < math.pi, (name, neighbour)
print("selftest OK")