Write the eight accents down once

They were written down five times: ThemeProfileModel.js for QML,
looks.lua for the compositor, and again in panama-theme-apps and
panama-lock. The GNOME accent-name mapping was a sixth list. Adding a
ninth accent meant editing all of them, and the file most likely to be
missed was the lock screen, which fails silently -- the machine locks
in last season's colour and nothing says why. panama-theme-apps
admitted it in a comment: "there is no shared source between QML and a
shell script".

config/palette.json is that source now. looks.lua reads it through a
new prefs.readJson, which uses the same never-raise parser the settings
store uses, so an unreadable palette costs the accent colours and never
the compositor config. The two shell generators read it through
scripts/panama-palette, which also carries the hex-to-rgb conversion
hyprlock needs and the GNOME member lookup.

QML keeps its table, because a .js module imported into QML cannot read
a file. That is still a copy, so the palette contract compares the two
value by value -- every accent, every field -- and fails on any
disagreement. Verified by planting a wrong hex and watching it name the
exact field.

The adwaita contract used to check the shell's own copy of the GNOME
mapping. It now checks that the shell resolves through the palette, and
fails if that copy ever grows back.
This commit is contained in:
Gabriel Brown
2026-08-22 05:42:53 -04:00
parent 202b5b89ac
commit e1a04d2d70
9 changed files with 378 additions and 87 deletions
+25 -22
View File
@@ -70,36 +70,39 @@ if command -v gsettings >/dev/null 2>&1; then
fi
# ── The shell helper must agree with the table ───────────────────────────────
# panama-theme-apps carries its own copy of this mapping because a shell script
# cannot read a QML object. A copy that drifts is exactly how an accent ends up
# correct in Panama's own surfaces and wrong everywhere else.
shell_member() {
local name="$1" body
body="$(sed -n '/^gnome_accent() {/,/^}/p' "$script")"
[[ -n "$body" ]] || fail 'gnome_accent() is missing from panama-theme-apps'
local line
line="$(grep -E "^\s+${name}\)" <<<"$body" | head -1)"
if [[ -z "$line" ]]; then
# Not listed means it falls through to the default branch.
line="$(grep -E '^\s+\*\)' <<<"$body" | head -1)"
fi
sed -E "s/.*printf '([a-z]+)'.*/\1/" <<<"$line"
}
# The mapping used to be a second copy of this table, written out as a case
# statement in panama-theme-apps. It now lives in config/palette.json beside
# each accent's colours, and scripts/panama-palette reads it -- so the shell
# and QML resolve the same member from the same file rather than from two
# lists somebody has to remember to edit together.
#
# palette-contract checks palette.json against the QML table value by value;
# this checks that the shell actually resolves through it, which is the half
# that would let an accent be correct in Panama's own surfaces and wrong
# everywhere else.
helper="$repo_dir/config/dot/quickshell/scripts/panama-palette"
[[ -r "$helper" ]] || fail 'scripts/panama-palette is missing, so nothing maps accents for the shell'
grep -q 'accent_gnome()' "$helper" \
|| fail 'panama-palette does not resolve a GNOME accent member'
grep -q 'accent_gnome' "$script" \
|| fail 'panama-theme-apps no longer asks the palette for the GNOME accent member'
grep -q 'gnome_accent() {' "$script" \
&& fail 'panama-theme-apps has grown its own copy of the mapping again'
while IFS=$'\t' read -r name member; do
[[ -n "$name" ]] || continue
actual="$(shell_member "$name")"
actual="$(bash -c "source '$helper'; accent_gnome '$name'")"
[[ "$actual" == "$member" ]] \
|| fail "Theme.qml maps \"$name\" to \"$member\" but panama-theme-apps maps it to \"$actual\""
|| fail "Theme.qml maps \"$name\" to \"$member\" but the shell resolves \"$actual\""
done <<<"$mapping"
# The helper also validates the accent name it is handed; an accent the table
# knows but the helper rejects silently degrades to blue.
accepted="$(grep -oE '^\s+blue\|[a-z|]+\)' "$script" | head -1 | tr -d ' )' )"
# An accent the table knows but the palette does not would silently degrade to
# blue, which is the failure this pair of files exists to prevent.
palette="$repo_dir/config/dot/quickshell/config/palette.json"
while IFS=$'\t' read -r name member; do
[[ -n "$name" ]] || continue
grep -qE "(^|\|)$name(\||$)" <<<"$accepted" \
|| fail "panama-theme-apps does not accept the \"$name\" accent, so choosing it falls back to blue"
jq -e --arg n "$name" '.accents | has($n)' "$palette" >/dev/null \
|| fail "the palette has no \"$name\" accent, so choosing it falls back to blue"
done <<<"$mapping"
# ── The portal has to be able to serve it ────────────────────────────────────