Files
chandra/scripts/test-kde-colors.sh
T
nandiandClaude Sonnet 5.5 70b24ffe47
CI / test (push) Canceled after 24m10s
Private bus: don't take over the session's document portal mount
A nested compositor's private D-Bus kept the session's XDG_RUNTIME_DIR, so
an xdg-document-portal activated on it mounted over $XDG_RUNTIME_DIR/doc and
removed the mount when the bus exited. The session's portal kept running
without it, and flatpak apps stopped starting.

The bus now has its own config that starts the document portal with a runtime
directory per compositor. scripts/test-private-bus.sh covers it. The KDE
colors test gets its own runtime directory for the same reason.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-25 22:06:51 -08:00

78 lines
4.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Test session/chandra-kde-colors, the Dark mode switch's KDE/Qt part (docs/dark-mode.md).
#
# 1. kdeglobals handling, with no KDE packages needed: the scheme's color groups replace the old
# ones, other groups and keys stay, ColorScheme is set, Chandra's own schemes are the fallback,
# a FooLight/FooDark pair is kept.
# 2. With kwrite, Xvfb and ImageMagick installed (apt: kwrite plasma-integration xvfb imagemagick
# dbus), the real thing: KWrite starts light, the script flips it, and with the KDE platform
# theme (QT_QPA_PLATFORMTHEME=kde) the running window turns dark. Skipped when they're missing.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
KC="$ROOT/session/chandra-kde-colors"
tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT
fail() { echo "FAIL: $*" >&2; exit 1; }
mkdir -p "$tmp/data/color-schemes" "$tmp/cfg"
cp "$ROOT"/session/color-schemes/*.colors "$tmp/data/color-schemes/"
run() { XDG_CONFIG_HOME="$tmp/cfg" XDG_DATA_HOME="$tmp/none" XDG_DATA_DIRS="$tmp/data" "$KC" "$@"; }
kg="$tmp/cfg/kdeglobals"
val() { sed -n "/^\[$1\]\$/,/^\[/s/^$2=//p" "$kg" | head -n 1; }
# No kdeglobals yet, no Breeze: Chandra's schemes.
[ "$(run dark)" = ChandraDark ] || fail "dark without Breeze should pick ChandraDark"
[ "$(val General ColorScheme)" = ChandraDark ] || fail "ColorScheme not set"
[ "$(val Colors:Window BackgroundNormal)" = 31,41,55 ] || fail "Colors:Window not copied"
[ "$(val WM activeBackground)" = 31,41,55 ] || fail "WM not copied"
# Existing settings survive; stale colors are replaced, not duplicated.
printf '[General]\nColorScheme=BreezeLight\nfont=Sans,10\n\n[Colors:Window]\nBackgroundNormal=1,2,3\nStale=1\n\n[Icons]\nTheme=breeze\n' >"$kg"
run dark >/dev/null
[ "$(val General font)" = Sans,10 ] || fail "[General] font lost"
[ "$(val Icons Theme)" = breeze ] || fail "[Icons] lost"
grep -q '^Stale=' "$kg" && fail "old color group kept"
[ "$(grep -c '^\[Colors:Window\]' "$kg")" = 1 ] || fail "Colors:Window duplicated"
[ "$(grep -c '^ColorScheme=' "$kg")" = 1 ] || fail "ColorScheme duplicated"
run light >/dev/null
[ "$(val General ColorScheme)" = ChandraLight ] || fail "light"
[ "$(val Colors:View BackgroundNormal)" = 255,255,255 ] || fail "light colors"
# A dark/light pair of the user's own is kept: MyLight -> MyDark.
sed 's/^ColorScheme=.*/ColorScheme=MyDark/; s/^BackgroundNormal=17,24,39/BackgroundNormal=9,9,9/' \
"$tmp/data/color-schemes/ChandraDark.colors" >"$tmp/data/color-schemes/MyDark.colors"
sed -i 's/^ColorScheme=.*/ColorScheme=MyLight/' "$kg"
[ "$(run dark)" = MyDark ] || fail "MyLight should become MyDark"
[ "$(val Colors:View BackgroundNormal)" = 9,9,9 ] || fail "MyDark colors"
# No kdeglobals [General] at all.
printf '[Icons]\nTheme=breeze\n' >"$kg"
run dark >/dev/null
[ "$(val General ColorScheme)" = ChandraDark ] || fail "[General] not added"
run bogus 2>/dev/null && fail "bad argument accepted"
echo "kdeglobals: ok"
# 2. Real KWrite.
for c in kwrite Xvfb import convert dbus-run-session; do
command -v $c >/dev/null 2>&1 || { echo "skipping the KWrite check ($c not installed)"; exit 0; }
done
# Its own runtime dir: a document portal started on this private bus would otherwise take over the
# session's $XDG_RUNTIME_DIR/doc mount, and remove it on exit.
export XDG_CONFIG_HOME="$tmp/kw" HOME="$tmp/kw/home" XDG_RUNTIME_DIR="$tmp/run" DISPLAY=:77 \
QT_QPA_PLATFORM=xcb QT_QPA_PLATFORMTHEME=kde KC tmp
mkdir -p "$HOME"
mkdir -m 700 "$XDG_RUNTIME_DIR"
Xvfb :77 -screen 0 800x600x24 >/dev/null 2>&1 & xvfb=$!
trap 'kill $xvfb 2>/dev/null; rm -rf "$tmp"' EXIT
sleep 1
dbus-run-session -- sh -c '
"$KC" light >/dev/null
kwrite >/dev/null 2>&1 & k=$!
sleep 6; import -window root "$tmp/before.png"
"$KC" dark >/dev/null
sleep 3; import -window root "$tmp/after.png"
kill $k' 2>/dev/null
lum() { convert "$1" -crop 1x1+400+300 -colorspace Gray -format '%[fx:int(255*mean)]' info:; }
b=$(lum "$tmp/before.png"); a=$(lum "$tmp/after.png")
echo "KWrite window gray level: light $b, after the switch $a"
[ "$b" -gt 150 ] || fail "KWrite didn't start light"
[ "$a" -lt 100 ] || fail "KWrite didn't turn dark live"
echo "KWrite: ok"