Follow the desktop accent colour and colour scheme (XDG portal) (#3)
This commit was merged in pull request #3.
This commit is contained in:
1 parent
02b08cb471
commit
1746884744
16 files changed
+947
-12
No files matched your search
Executable
+114
@@ -0,0 +1,114 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Fake org.freedesktop.portal.Settings for the smoke test.
|
||||
|
||||
Owns org.freedesktop.portal.Desktop on the session bus and serves the
|
||||
org.freedesktop.appearance namespace with a fixed accent colour and colour
|
||||
scheme, like GNOME 47+ / KDE Plasma 6 do.
|
||||
|
||||
fake-portal.py R G B [COLOR_SCHEME] (channels 0..1; scheme 0/1/2)
|
||||
|
||||
Writing a line "R G B [SCHEME]" to stdin changes the values and emits
|
||||
SettingChanged, to exercise live updates.
|
||||
"""
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||
|
||||
from gi.repository import Gio, GLib
|
||||
|
||||
XML = """
|
||||
<node>
|
||||
<interface name="org.freedesktop.portal.Settings">
|
||||
<method name="ReadAll">
|
||||
<arg type="as" name="namespaces" direction="in"/>
|
||||
<arg type="a{sa{sv}}" name="value" direction="out"/>
|
||||
</method>
|
||||
<method name="Read">
|
||||
<arg type="s" name="namespace" direction="in"/>
|
||||
<arg type="s" name="key" direction="in"/>
|
||||
<arg type="v" name="value" direction="out"/>
|
||||
</method>
|
||||
<method name="ReadOne">
|
||||
<arg type="s" name="namespace" direction="in"/>
|
||||
<arg type="s" name="key" direction="in"/>
|
||||
<arg type="v" name="value" direction="out"/>
|
||||
</method>
|
||||
<signal name="SettingChanged">
|
||||
<arg type="s" name="namespace"/>
|
||||
<arg type="s" name="key"/>
|
||||
<arg type="v" name="value"/>
|
||||
</signal>
|
||||
<property name="version" type="u" access="read"/>
|
||||
</interface>
|
||||
</node>
|
||||
"""
|
||||
NS = "org.freedesktop.appearance"
|
||||
PATH = "/org/freedesktop/portal/desktop"
|
||||
IFACE = "org.freedesktop.portal.Settings"
|
||||
|
||||
state = {}
|
||||
|
||||
|
||||
def values():
|
||||
return {
|
||||
"accent-color": GLib.Variant("(ddd)", state["accent"]),
|
||||
"color-scheme": GLib.Variant("u", state["scheme"]),
|
||||
}
|
||||
|
||||
|
||||
def parse(args):
|
||||
r, g, b = (float(x) for x in args[:3])
|
||||
return (r, g, b), int(args[3]) if len(args) > 3 else 0
|
||||
|
||||
|
||||
def on_call(conn, sender, path, iface, method, params, inv):
|
||||
if method == "ReadAll":
|
||||
(namespaces,) = params.unpack()
|
||||
want = not namespaces or any(
|
||||
n == NS or (n.endswith("*") and NS.startswith(n[:-1])) or n == ""
|
||||
for n in namespaces
|
||||
)
|
||||
inv.return_value(GLib.Variant("(a{sa{sv}})", ({NS: values()} if want else {},)))
|
||||
return
|
||||
ns, key = params.unpack()
|
||||
v = values().get(key) if ns == NS else None
|
||||
if v is None:
|
||||
inv.return_dbus_error("org.freedesktop.portal.Error.NotFound", "no such setting")
|
||||
elif method == "Read": # version 1 wraps the value in another variant
|
||||
inv.return_value(GLib.Variant("(v)", (GLib.Variant("v", v),)))
|
||||
else:
|
||||
inv.return_value(GLib.Variant("(v)", (v,)))
|
||||
|
||||
|
||||
def on_get(conn, sender, path, iface, prop):
|
||||
return GLib.Variant("u", 2)
|
||||
|
||||
|
||||
def main():
|
||||
state["accent"], state["scheme"] = parse(sys.argv[1:])
|
||||
loop = GLib.MainLoop()
|
||||
bus = Gio.bus_get_sync(Gio.BusType.SESSION)
|
||||
info = Gio.DBusNodeInfo.new_for_xml(XML).interfaces[0]
|
||||
bus.register_object(PATH, info, on_call, on_get, None)
|
||||
|
||||
def on_stdin(ch, cond):
|
||||
line = ch.readline()
|
||||
if not line:
|
||||
return False
|
||||
state["accent"], state["scheme"] = parse(line.split())
|
||||
for key, v in values().items():
|
||||
bus.emit_signal(None, PATH, IFACE, "SettingChanged",
|
||||
GLib.Variant("(ssv)", (NS, key, v)))
|
||||
return True
|
||||
|
||||
GLib.io_add_watch(GLib.IOChannel.unix_new(0), GLib.IO_IN | GLib.IO_HUP, on_stdin)
|
||||
Gio.bus_own_name_on_connection(
|
||||
bus, "org.freedesktop.portal.Desktop", Gio.BusNameOwnerFlags.NONE,
|
||||
lambda *_: print("fake portal: ready", flush=True),
|
||||
lambda *_: (print("fake portal: name lost", flush=True), loop.quit()))
|
||||
loop.run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+36
-4
@@ -2,7 +2,8 @@
|
||||
# Headless smoke test: start a private PipeWire + WirePlumber (two null
|
||||
# sinks, a loopback virtual microphone, a playback and a capture stream),
|
||||
# run every moonmix-probe action and check its effect, then, if
|
||||
# gtk4-broadwayd is available, render GUI screenshots.
|
||||
# gtk4-broadwayd is available, render GUI screenshots: with the theme's
|
||||
# accent and, through a fake XDG Desktop Portal, with a system accent colour.
|
||||
#
|
||||
# Only this *test harness* uses pw-cat (to create a playing stream); moonmix
|
||||
# itself talks to PipeWire through libwireplumber.
|
||||
@@ -60,7 +61,7 @@ CONF
|
||||
|
||||
PIDS=""
|
||||
cleanup() { for p in $PIDS; do kill "$p" 2>/dev/null || true; done; [ -n "${KEEP:-}" ] || rm -rf "$XDG_RUNTIME_DIR"; }
|
||||
trap cleanup EXIT INT TERM
|
||||
trap cleanup EXIT INT TERM PIPE
|
||||
|
||||
pipewire >"$XDG_RUNTIME_DIR/pipewire.log" 2>&1 & PIDS="$PIDS $!"
|
||||
sleep 1
|
||||
@@ -156,8 +157,39 @@ if [ -n "$SHOTS" ] && [ -x "$GUI" ]; then
|
||||
if command -v gtk4-broadwayd >/dev/null; then
|
||||
gtk4-broadwayd :5 >/dev/null 2>&1 & PIDS="$PIDS $!"
|
||||
sleep 1
|
||||
MOONMIX_ICON_DIR="$ROOT/data/icons" GDK_BACKEND=broadway BROADWAY_DISPLAY=:5 MOONMIX_SCREENSHOT="$SHOTS" \
|
||||
timeout 30 "$GUI" || fail=1
|
||||
gui() { MOONMIX_ICON_DIR="$ROOT/data/icons" GDK_BACKEND=broadway BROADWAY_DISPLAY=:5 timeout 30 stdbuf -oL "$GUI"; }
|
||||
# Default look: no session bus, so no portal and the theme's own accent.
|
||||
DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/no-bus" MOONMIX_SCREENSHOT="$SHOTS" gui || fail=1
|
||||
# System accent: a fake org.freedesktop.portal.Settings on a private
|
||||
# session bus reports a green accent, then switches to orange while
|
||||
# moonmix runs (SettingChanged); it takes the shots once orange is applied.
|
||||
PY=""
|
||||
for p in python3 /usr/bin/python3; do
|
||||
if "$p" -c 'from gi.repository import Gio' 2>/dev/null; then PY=$p; break; fi
|
||||
done
|
||||
if [ -n "$PY" ] && command -v dbus-daemon >/dev/null; then
|
||||
echo "### system accent colour (fake portal) -> $SHOTS-accent-<tab>.png"
|
||||
dbus-daemon --session --nofork --address="unix:path=$XDG_RUNTIME_DIR/bus" \
|
||||
>/dev/null 2>&1 & PIDS="$PIDS $!"
|
||||
export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"
|
||||
for _ in $(seq 1 40); do [ -S "$XDG_RUNTIME_DIR/bus" ] && break; sleep 0.25; done
|
||||
mkfifo "$LOGS/portal.in"
|
||||
"$PY" "$ROOT/tools/fake-portal.py" 0.2 0.82 0.48 0 <"$LOGS/portal.in" >"$LOGS/portal.log" 2>&1 & PIDS="$PIDS $!"
|
||||
exec 4>"$LOGS/portal.in"
|
||||
for _ in $(seq 1 40); do grep -q ready "$LOGS/portal.log" 2>/dev/null && break; sleep 0.25; done
|
||||
MOONMIX_SCREENSHOT="$SHOTS-accent" MOONMIX_SCREENSHOT_ACCENT="#ff7800" gui >"$LOGS/accent.log" 2>&1 & GUIPID=$!
|
||||
for _ in $(seq 1 40); do grep -q 'accent #33d17a' "$LOGS/accent.log" && break; sleep 0.25; done
|
||||
echo "1 0.471 0 0" >&4 || true
|
||||
wait "$GUIPID" || fail=1
|
||||
exec 4>&-
|
||||
cat "$LOGS/accent.log"
|
||||
if ! grep -q 'accent #33d17a, light' "$LOGS/accent.log" || ! grep -q 'accent #ff7800, light' "$LOGS/accent.log"; then
|
||||
echo "FAIL: accent colour not read from the portal or not updated live"
|
||||
cat "$LOGS/portal.log"; fail=1
|
||||
fi
|
||||
else
|
||||
echo "python3 with gi or dbus-daemon not found; skipping the accent colour screenshots"
|
||||
fi
|
||||
else
|
||||
echo "gtk4-broadwayd not found; skipping GUI"
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user