489 lines
23 KiB
Python
Executable File
489 lines
23 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Verify .xth theme switching and fractional DPI scaling across toolkits without double-scaling."""
|
|
|
|
import glob
|
|
import os
|
|
import re
|
|
import subprocess
|
|
import tempfile
|
|
|
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
|
THEMES_DIR = os.path.join(ROOT, "data", "themes")
|
|
APPLY_SCALE = os.path.join(ROOT, "scripts", "anode-apply-scale")
|
|
APPLY_THEME = os.path.join(ROOT, "scripts", "anode-apply-theme")
|
|
|
|
|
|
def run_env(env, cmd):
|
|
res = subprocess.run(cmd, env=env, capture_output=True, text=True)
|
|
assert res.returncode == 0, f"Command failed: {cmd}\nstdout={res.stdout}\nstderr={res.stderr}"
|
|
return res
|
|
|
|
|
|
def parse_xres(path):
|
|
out = {}
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
for line in f:
|
|
s = line.strip()
|
|
if not s or s.startswith("!") or s.startswith("#"):
|
|
continue
|
|
if ":" in s:
|
|
k, v = s.split(":", 1)
|
|
out[k.strip()] = v.strip()
|
|
return out
|
|
|
|
|
|
def detect_expected_ui_font():
|
|
if os.environ.get("ANODE_TEST_UI_FONT"):
|
|
return os.environ["ANODE_TEST_UI_FONT"]
|
|
try:
|
|
out = subprocess.check_output(["fc-list", ":", "family"], text=True)
|
|
except Exception:
|
|
return "Roboto"
|
|
fams = set()
|
|
for line in out.splitlines():
|
|
for part in line.split(","):
|
|
p = part.strip().lower()
|
|
if p:
|
|
fams.add(p)
|
|
if "roboto" in fams:
|
|
return "Roboto"
|
|
if "noto sans" in fams:
|
|
return "Noto Sans"
|
|
return "Roboto"
|
|
|
|
|
|
def test_fractional_scales():
|
|
exp_ui = detect_expected_ui_font()
|
|
scales = [
|
|
("0.75", 72, "1", "1.0", 11, 16, 16),
|
|
("1.00", 96, "1", "1.0", 15, 24, 24),
|
|
("1.25", 120, "1", "1.0", 19, 24, 24),
|
|
("1.50", 144, "1", "1.0", 23, 32, 32),
|
|
("1.75", 168, "2", "0.5", 26, 32, 16),
|
|
("2.00", 192, "2", "0.5", 30, 48, 24),
|
|
("2.50", 240, "3", "0.333", 38, 48, 16),
|
|
]
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
env = dict(os.environ)
|
|
env.pop("DISPLAY", None)
|
|
env["HOME"] = tmp
|
|
env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config")
|
|
env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share")
|
|
env["ANODE_PREFIX"] = ROOT
|
|
env["ANODE_NO_SIGNAL"] = "1"
|
|
|
|
for s_str, exp_dpi, exp_gdk, exp_gdk_dpi, exp_px, exp_cur, exp_gtk_cur in scales:
|
|
run_env(env, [APPLY_SCALE, s_str, "--touch=1"])
|
|
scale_env_p = os.path.join(tmp, ".config", "anode", "scale.env")
|
|
with open(scale_env_p, "r", encoding="utf-8") as f:
|
|
senv = f.read()
|
|
assert 'unset GDK_SCALE GDK_DPI_SCALE' in senv, senv
|
|
assert 'export GDK_SCALE=' not in senv, senv
|
|
assert 'export GDK_DPI_SCALE=' not in senv, senv
|
|
assert f'export QT_SCALE_FACTOR="{s_str}"' in senv, senv
|
|
assert 'export QT_FONT_DPI="96"' in senv, senv
|
|
assert 'export QT_AUTO_SCREEN_SCALE_FACTOR="0"' in senv, senv
|
|
assert 'export QT_SCALE_FACTOR_ROUNDING_POLICY="PassThrough"' in senv, senv
|
|
assert 'export QT_QPA_PLATFORMTHEME="gtk3:qt6ct:qt5ct"' in senv, senv
|
|
assert f'export XCURSOR_SIZE="{exp_cur}"' in senv, senv
|
|
|
|
scale_conf_p = os.path.join(tmp, ".config", "anode", "scale.conf")
|
|
with open(scale_conf_p, "r", encoding="utf-8") as f:
|
|
sconf = f.read()
|
|
assert f"XCURSOR_SIZE={exp_cur}" in sconf, sconf
|
|
|
|
xres = parse_xres(os.path.join(tmp, ".Xresources"))
|
|
assert int(xres["Xft.dpi"]) == exp_dpi, f"scale={s_str} dpi={xres['Xft.dpi']}"
|
|
assert int(xres["theme.baseFontSize"]) == exp_px, f"scale={s_str} base={xres['theme.baseFontSize']}"
|
|
assert int(xres["Xcursor.size"]) == exp_cur, f"scale={s_str} cur={xres['Xcursor.size']}"
|
|
assert xres["theme.fontFace"] == "Fira Code"
|
|
assert xres["theme.uiFontFace"] == exp_ui
|
|
assert "Fira Code" in xres["st.font"] and "size=13" in xres["st.font"]
|
|
assert "Fira Code" in xres["dwm.font"] and f"{exp_px}px" in xres["dwm.font"]
|
|
assert "Fira Code" in xres["dmenu.font"] and f"{exp_px}px" in xres["dmenu.font"]
|
|
assert xres["*TkTheme"] == "gtkTtk"
|
|
assert xres["theme.touchMode"] == "1"
|
|
|
|
# Verify xsettingsd publishes balanced Gdk/WindowScalingFactor + Gdk/UnscaledDPI + Xft/DPI
|
|
xs_p = os.path.join(tmp, ".config", "xsettingsd", "xsettingsd.conf")
|
|
with open(xs_p, "r", encoding="utf-8") as f:
|
|
xs = f.read()
|
|
exp_xft_dpi = exp_dpi * 1024
|
|
exp_unscaled = int((exp_dpi * 1024) / int(exp_gdk) + 0.5)
|
|
assert f"Gdk/WindowScalingFactor {exp_gdk}" in xs, xs
|
|
assert f"Gdk/UnscaledDPI {exp_unscaled}" in xs, xs
|
|
assert f"Xft/DPI {exp_xft_dpi}" in xs, xs
|
|
assert f'Gtk/FontName "{exp_ui} 10"' in xs, xs
|
|
assert f"Gtk/CursorThemeSize {exp_gtk_cur}" in xs, xs
|
|
|
|
with open(os.path.join(tmp, ".gtkrc-2.0"), "r", encoding="utf-8") as f:
|
|
gtk2 = f.read()
|
|
assert f'gtk-font-name="{exp_ui} 10"' in gtk2, gtk2
|
|
assert f"gtk-cursor-theme-size={exp_cur}" in gtk2, gtk2
|
|
|
|
assert os.path.isfile(os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "index.theme"))
|
|
assert os.path.islink(os.path.join(tmp, ".local", "share", "themes", "ANODE-AnodeDefault"))
|
|
with open(os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "gtk-2.0", "gtkrc"), "r", encoding="utf-8") as f:
|
|
gtk2rc = f.read()
|
|
assert "GtkButton::inner-border" in gtk2rc, gtk2rc
|
|
assert "GtkEntry::inner-border" in gtk2rc, gtk2rc
|
|
assert 'style "anode-menu" = "anode-default"' in gtk2rc, gtk2rc
|
|
|
|
for gver in ("gtk-3.0", "gtk-4.0"):
|
|
with open(os.path.join(tmp, ".config", gver, "settings.ini"), "r", encoding="utf-8") as f:
|
|
gini = f.read()
|
|
assert f"gtk-font-name={exp_ui} 10" in gini, gini
|
|
assert f"gtk-cursor-theme-size={exp_gtk_cur}" in gini, gini
|
|
with open(os.path.join(tmp, ".config", gver, "gtk.css"), "r", encoding="utf-8") as f:
|
|
gcss = f.read()
|
|
assert "@define-color" in gcss, gcss
|
|
for bad in ("min-height:", "min-width:", "padding:", "margin:", "font-family:"):
|
|
assert bad not in gcss, f"Unexpected {bad} in .config/{gver}/gtk.css"
|
|
|
|
tcss_p = os.path.join(tmp, ".themes", "ANODE-AnodeDefault", gver, "gtk.css")
|
|
with open(tcss_p, "r", encoding="utf-8") as f:
|
|
tcss = f.read()
|
|
exp_imp = (
|
|
'@import url("resource:///org/gtk/libgtk/theme/Default/Default-dark.css");'
|
|
if gver == "gtk-4.0"
|
|
else '@import url("resource:///org/gtk/libgtk/theme/Adwaita/gtk-contained-dark.css");'
|
|
)
|
|
assert tcss.splitlines()[0] == exp_imp, tcss.splitlines()[:3]
|
|
for bad in ("min-height:", "min-width:", "padding:", "margin:", "font-family:"):
|
|
assert bad not in tcss, f"Unexpected {bad} in theme {gver}/gtk.css"
|
|
|
|
for qver in ("qt5ct", "qt6ct"):
|
|
with open(os.path.join(tmp, ".config", qver, f"{qver}.conf"), "r", encoding="utf-8") as f:
|
|
qconf = f.read()
|
|
assert f'general="{exp_ui},10,' in qconf, qconf
|
|
assert 'fixed="Fira Code,10,' in qconf, qconf
|
|
|
|
fc_p = os.path.join(tmp, ".config", "fontconfig", "conf.d", "60-anode-fonts.conf")
|
|
import xml.etree.ElementTree as ET
|
|
fc_root = ET.parse(fc_p).getroot()
|
|
aliases = {
|
|
al.findtext("family"): [el.text for el in al.findall("./prefer/family")]
|
|
for al in fc_root.findall("./alias")
|
|
}
|
|
assert aliases.get("sans-serif", [None])[0] == exp_ui, aliases
|
|
assert aliases.get("monospace", [None])[0] == "Fira Code", aliases
|
|
|
|
with open(os.path.join(tmp, ".config", "dunst", "dunstrc"), "r", encoding="utf-8") as f:
|
|
drc = f.read()
|
|
assert "scale = 1" in drc, drc
|
|
assert f"font = Fira Code {exp_px}px" in drc, drc
|
|
|
|
# Verify Fontconfig + Qt5 + Qt6 + Kvantum + Dunst + GTK2/3/4 files
|
|
for p in [
|
|
".gtkrc-2.0",
|
|
".config/fontconfig/conf.d/60-anode-fonts.conf",
|
|
".config/gtk-3.0/gtk.css",
|
|
".config/gtk-3.0/settings.ini",
|
|
".config/gtk-4.0/gtk.css",
|
|
".config/gtk-4.0/settings.ini",
|
|
".config/qt5ct/qt5ct.conf",
|
|
".config/qt6ct/qt6ct.conf",
|
|
".config/Kvantum/kvantum.kvconfig",
|
|
".config/dunst/dunstrc",
|
|
]:
|
|
full = os.path.join(tmp, p)
|
|
assert os.path.isfile(full) and os.path.getsize(full) > 20, f"Missing/empty {p}"
|
|
|
|
|
|
def test_all_22_themes_and_legacy_192dpi_import():
|
|
themes = sorted(glob.glob(os.path.join(THEMES_DIR, "*.xth")))
|
|
assert len(themes) == 22, f"Expected 22 .xth themes, got {len(themes)}"
|
|
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
env = dict(os.environ)
|
|
env.pop("DISPLAY", None)
|
|
env["HOME"] = tmp
|
|
env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config")
|
|
env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share")
|
|
env["ANODE_PREFIX"] = ROOT
|
|
env["ANODE_NO_SIGNAL"] = "1"
|
|
run_env(env, [APPLY_SCALE, "1.00", "--touch=0", "--no-apply"])
|
|
|
|
for th in themes:
|
|
run_env(env, [APPLY_THEME, th])
|
|
xres = parse_xres(os.path.join(tmp, ".Xresources"))
|
|
tname = xres["theme.name"]
|
|
assert xres["Xft.dpi"] == "96"
|
|
assert xres["theme.baseFontSize"] == "15"
|
|
assert xres["theme.fontFace"] == "Fira Code"
|
|
assert "Fira Code" in xres["st.font"] and "size=13" in xres["st.font"]
|
|
assert os.path.isfile(os.path.join(tmp, ".config", "qt6ct", "colors", f"ANODE-{tname}.conf"))
|
|
assert os.path.isfile(os.path.join(tmp, ".config", "qt5ct", "colors", f"ANODE-{tname}.conf"))
|
|
|
|
# Legacy 192-DPI import must normalize back to 96 DPI / 15px at 1.00x scale
|
|
legacy_xth = os.path.join(tmp, "LegacyHiDpi.xth")
|
|
with open(legacy_xth, "w", encoding="utf-8") as f:
|
|
f.write(
|
|
"theme.name: LegacyHiDpi\n"
|
|
"Xft.dpi: 192\n"
|
|
"Xcursor.size: 64\n"
|
|
"theme.fontFace: Fira Code\n"
|
|
"theme.baseFontSize: 32\n"
|
|
"dwm.borderpx: 4\n"
|
|
"theme.bgMain: #101010\n"
|
|
"theme.fgMain: #eeeeee\n"
|
|
"theme.accent: #55aaff\n"
|
|
)
|
|
run_env(env, [APPLY_THEME, legacy_xth])
|
|
xres = parse_xres(os.path.join(tmp, ".Xresources"))
|
|
assert xres["Xft.dpi"] == "96"
|
|
assert int(xres["theme.baseFontSize"]) == 16, xres["theme.baseFontSize"]
|
|
assert int(xres["dwm.borderpx"]) == 2, xres["dwm.borderpx"]
|
|
|
|
|
|
def test_st_overrides_and_xresources_local():
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
env = dict(os.environ)
|
|
env.pop("DISPLAY", None)
|
|
env["HOME"] = tmp
|
|
env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config")
|
|
env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share")
|
|
env["ANODE_PREFIX"] = ROOT
|
|
env["ANODE_NO_SIGNAL"] = "1"
|
|
run_env(env, [APPLY_SCALE, "1.50", "--touch=0", "--no-apply"])
|
|
|
|
xres_p = os.path.join(tmp, ".Xresources")
|
|
with open(xres_p, "w", encoding="utf-8") as f:
|
|
f.write("St.font: Fira Code:size=14:antialias=true:autohint=true\n")
|
|
f.write("St.alpha: 0.95\n")
|
|
|
|
# Repeated theme applications must preserve St.* cleanly without duplication
|
|
run_env(env, [APPLY_THEME, "AnodeDefault"])
|
|
run_env(env, [APPLY_THEME, "AnodeDefault"])
|
|
with open(xres_p, "r", encoding="utf-8") as f:
|
|
content = f.read()
|
|
assert content.count("St.font:") == 1, content
|
|
assert content.count("St.alpha:") == 1, content
|
|
assert "St.font: Fira Code:size=14:antialias=true:autohint=true" in content, content
|
|
|
|
# Adding Xresources.local must replace duplicate keys from preserved section and persist
|
|
local_p = os.path.join(tmp, ".config", "anode", "Xresources.local")
|
|
with open(local_p, "w", encoding="utf-8") as f:
|
|
f.write("St.font: Fira Code:size=16:antialias=true\n")
|
|
f.write("*.cursorBlink: true\n")
|
|
|
|
run_env(env, [APPLY_THEME, "AnodeDefault"])
|
|
run_env(env, [APPLY_THEME, "AnodeDefault"])
|
|
with open(xres_p, "r", encoding="utf-8") as f:
|
|
content2 = f.read()
|
|
assert content2.count("St.font:") == 1, content2
|
|
assert content2.count("St.alpha:") == 1, content2
|
|
assert content2.count("*.cursorBlink:") == 1, content2
|
|
assert "St.font: Fira Code:size=16:antialias=true" in content2, content2
|
|
|
|
|
|
def test_auto_scale_honors_explicit_server_dpi():
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
fbin = os.path.join(tmp, "bin")
|
|
os.makedirs(fbin)
|
|
xdpy_p = os.path.join(fbin, "xdpyinfo")
|
|
xrandr_p = os.path.join(fbin, "xrandr")
|
|
with open(xdpy_p, "w", encoding="utf-8") as f:
|
|
f.write("#!/bin/sh\necho ' dimensions: 1920x1200 pixels (338x211 millimeters)'\necho ' resolution: 144x144 dots per inch'\n")
|
|
with open(xrandr_p, "w", encoding="utf-8") as f:
|
|
f.write("#!/bin/sh\necho 'eDP connected primary 1920x1200+0+0 (normal left inverted right x axis y axis) 301mm x 188mm'\n")
|
|
os.chmod(xdpy_p, 0o755)
|
|
os.chmod(xrandr_p, 0o755)
|
|
|
|
env = dict(os.environ)
|
|
env["DISPLAY"] = ":99"
|
|
env["HOME"] = tmp
|
|
env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config")
|
|
env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share")
|
|
env["ANODE_PREFIX"] = ROOT
|
|
env["ANODE_NO_SIGNAL"] = "1"
|
|
env["PATH"] = fbin + ":" + env.get("PATH", "")
|
|
|
|
run_env(env, [APPLY_SCALE, "auto", "--no-apply"])
|
|
with open(os.path.join(tmp, ".config", "anode", "scale.conf"), "r", encoding="utf-8") as f:
|
|
sconf = f.read()
|
|
assert "SCALE=1.50" in sconf, sconf
|
|
assert "XCURSOR_SIZE=32" in sconf, sconf
|
|
|
|
|
|
def test_stale_env_does_not_override_scale_conf():
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
env = dict(os.environ)
|
|
env.pop("DISPLAY", None)
|
|
env["HOME"] = tmp
|
|
env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config")
|
|
env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share")
|
|
env["ANODE_PREFIX"] = ROOT
|
|
env["ANODE_NO_SIGNAL"] = "1"
|
|
env["ANODE_NO_DBUS"] = "1"
|
|
|
|
run_env(env, [APPLY_SCALE, "2.00", "--touch=1"])
|
|
|
|
stale_env = dict(env)
|
|
stale_env["ANODE_SCALE"] = "2.00"
|
|
stale_env["ANODE_TOUCH"] = "1"
|
|
run_env(stale_env, [APPLY_SCALE, "1.25", "--touch=0"])
|
|
|
|
with open(os.path.join(tmp, ".config", "anode", "scale.conf"), "r", encoding="utf-8") as f:
|
|
sconf = f.read()
|
|
assert "SCALE=1.25" in sconf and "TOUCH=0" in sconf, sconf
|
|
|
|
with open(os.path.join(tmp, ".config", "anode", "scale.env"), "r", encoding="utf-8") as f:
|
|
senv = f.read()
|
|
assert 'export ANODE_SCALE="1.25"' in senv and 'export ANODE_TOUCH="0"' in senv, senv
|
|
|
|
xres = parse_xres(os.path.join(tmp, ".Xresources"))
|
|
assert xres["theme.scale"] == "1.25", xres["theme.scale"]
|
|
assert xres["Xft.dpi"] == "120", xres["Xft.dpi"]
|
|
assert xres["theme.touchMode"] == "0", xres["theme.touchMode"]
|
|
|
|
with open(os.path.join(tmp, ".config", "dunst", "dunstrc"), "r", encoding="utf-8") as f:
|
|
assert "font = Fira Code 19px" in f.read()
|
|
with open(os.path.join(tmp, ".config", "gtk-3.0", "settings.ini"), "r", encoding="utf-8") as f:
|
|
assert "gtk-cursor-theme-size=24" in f.read()
|
|
|
|
# Re-applying theme with stale ANODE_SCALE/ANODE_TOUCH still honors scale.conf
|
|
run_env(stale_env, [APPLY_THEME, "AnodeDefault"])
|
|
xres2 = parse_xres(os.path.join(tmp, ".Xresources"))
|
|
assert xres2["theme.scale"] == "1.25" and xres2["Xft.dpi"] == "120" and xres2["theme.touchMode"] == "0"
|
|
|
|
|
|
def test_gtk_theme_light_dark_detection_and_css_parse():
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
env = dict(os.environ)
|
|
env.pop("DISPLAY", None)
|
|
env["HOME"] = tmp
|
|
env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config")
|
|
env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share")
|
|
env["ANODE_PREFIX"] = ROOT
|
|
env["ANODE_NO_SIGNAL"] = "1"
|
|
run_env(env, [APPLY_SCALE, "1.25", "--touch=0", "--no-apply"])
|
|
|
|
for light_th in ("CatppuccinLatte", "GruvboxLight", "SolarizedLight"):
|
|
run_env(env, [APPLY_THEME, light_th])
|
|
with open(os.path.join(tmp, ".config", "gtk-3.0", "settings.ini"), "r", encoding="utf-8") as f:
|
|
assert "gtk-application-prefer-dark-theme=0" in f.read()
|
|
t3 = os.path.join(tmp, ".themes", f"ANODE-{light_th}", "gtk-3.0", "gtk.css")
|
|
t4 = os.path.join(tmp, ".themes", f"ANODE-{light_th}", "gtk-4.0", "gtk.css")
|
|
with open(t3, "r", encoding="utf-8") as f:
|
|
txt3 = f.read()
|
|
with open(t4, "r", encoding="utf-8") as f:
|
|
txt4 = f.read()
|
|
assert txt3.splitlines()[0] == '@import url("resource:///org/gtk/libgtk/theme/Adwaita/gtk-contained.css");'
|
|
assert txt4.splitlines()[0] == '@import url("resource:///org/gtk/libgtk/theme/Default/Default-light.css");'
|
|
|
|
run_env(env, [APPLY_THEME, "AnodeDefault"])
|
|
t3_dark = os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "gtk-3.0", "gtk.css")
|
|
with open(t3_dark, "r", encoding="utf-8") as f:
|
|
t3_txt = f.read()
|
|
assert "menu separator" in t3_txt, t3_txt
|
|
assert "popover.menu.background > contents" in t3_txt, t3_txt
|
|
for bad in ("min-height:", "min-width:", "padding:", "margin:", "font-family:"):
|
|
assert bad not in t3_txt, f"Unexpected {bad} in {t3_dark}"
|
|
try:
|
|
import gi
|
|
gi.require_version("Gtk", "3.0")
|
|
from gi.repository import Gtk
|
|
prov = Gtk.CssProvider()
|
|
errs = []
|
|
prov.connect("parsing-error", lambda p, s, e: errs.append(str(e)))
|
|
prov.load_from_path(t3_dark)
|
|
assert not errs, f"GTK3 CSS parse errors: {errs}"
|
|
except ImportError:
|
|
pass
|
|
|
|
import sys
|
|
gtk4_check = (
|
|
"import sys\n"
|
|
"try:\n"
|
|
" import gi; gi.require_version('Gtk', '4.0'); from gi.repository import Gtk\n"
|
|
"except Exception:\n"
|
|
" sys.exit(0)\n"
|
|
"Gtk.init()\n"
|
|
"for p in sys.argv[1:]:\n"
|
|
" prov = Gtk.CssProvider()\n"
|
|
" errs = []\n"
|
|
" prov.connect('parsing-error', lambda pr, s, e: errs.append(str(e)))\n"
|
|
" prov.load_from_path(p)\n"
|
|
" assert not errs, f'GTK4 CSS parse errors in {p}: {errs}'\n"
|
|
)
|
|
subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"-c",
|
|
gtk4_check,
|
|
os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "gtk-4.0", "gtk.css"),
|
|
os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "gtk-4.0", "gtk-dark.css"),
|
|
os.path.join(tmp, ".config", "gtk-4.0", "gtk.css"),
|
|
],
|
|
env=env,
|
|
check=True,
|
|
)
|
|
|
|
|
|
def test_ui_font_fallback_roboto_to_noto_sans():
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
fbin = os.path.join(tmp, "bin")
|
|
os.makedirs(fbin)
|
|
fc_list_p = os.path.join(fbin, "fc-list")
|
|
with open(fc_list_p, "w", encoding="utf-8") as f:
|
|
f.write("#!/bin/sh\nprintf 'Noto Sans\\nFira Code\\n'\n")
|
|
os.chmod(fc_list_p, 0o755)
|
|
|
|
env = dict(os.environ)
|
|
env.pop("DISPLAY", None)
|
|
env["HOME"] = tmp
|
|
env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config")
|
|
env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share")
|
|
env["ANODE_PREFIX"] = ROOT
|
|
env["ANODE_NO_SIGNAL"] = "1"
|
|
env["ANODE_NO_DBUS"] = "1"
|
|
env["PATH"] = fbin + ":" + env.get("PATH", "")
|
|
|
|
run_env(env, [APPLY_SCALE, "1.25", "--touch=0"])
|
|
|
|
xres = parse_xres(os.path.join(tmp, ".Xresources"))
|
|
assert xres["theme.uiFontFace"] == "Noto Sans", xres
|
|
assert xres["theme.fontFace"] == "Fira Code", xres
|
|
assert "Fira Code" in xres["dwm.font"] and "Fira Code" in xres["dmenu.font"] and "Fira Code" in xres["st.font"]
|
|
|
|
with open(os.path.join(tmp, ".config", "xsettingsd", "xsettingsd.conf"), "r", encoding="utf-8") as f:
|
|
assert 'Gtk/FontName "Noto Sans 10"' in f.read()
|
|
with open(os.path.join(tmp, ".gtkrc-2.0"), "r", encoding="utf-8") as f:
|
|
assert 'gtk-font-name="Noto Sans 10"' in f.read()
|
|
for gver in ("gtk-3.0", "gtk-4.0"):
|
|
with open(os.path.join(tmp, ".config", gver, "settings.ini"), "r", encoding="utf-8") as f:
|
|
assert "gtk-font-name=Noto Sans 10" in f.read()
|
|
for qver in ("qt5ct", "qt6ct"):
|
|
with open(os.path.join(tmp, ".config", qver, f"{qver}.conf"), "r", encoding="utf-8") as f:
|
|
qc = f.read()
|
|
assert 'general="Noto Sans,10,' in qc, qc
|
|
assert 'fixed="Fira Code,10,' in qc, qc
|
|
with open(os.path.join(tmp, ".config", "dunst", "dunstrc"), "r", encoding="utf-8") as f:
|
|
assert "font = Fira Code 19px" in f.read()
|
|
|
|
import xml.etree.ElementTree as ET
|
|
fc_root = ET.parse(os.path.join(tmp, ".config", "fontconfig", "conf.d", "60-anode-fonts.conf")).getroot()
|
|
aliases = {
|
|
al.findtext("family"): [el.text for el in al.findall("./prefer/family")]
|
|
for al in fc_root.findall("./alias")
|
|
}
|
|
assert aliases.get("sans-serif") == ["Noto Sans"], aliases
|
|
assert aliases.get("monospace") == ["Fira Code"], aliases
|
|
|
|
|
|
if __name__ == "__main__":
|
|
with open(os.path.join(ROOT, "data", "env.sh"), "r", encoding="utf-8") as f:
|
|
env_sh = f.read()
|
|
assert 'QT_QPA_PLATFORMTHEME:=gtk3:qt6ct:qt5ct' in env_sh, env_sh
|
|
assert 'unset GDK_SCALE GDK_DPI_SCALE' in env_sh, env_sh
|
|
assert 'export ANODE_SCALE ANODE_TOUCH GDK_SCALE' not in env_sh, env_sh
|
|
test_fractional_scales()
|
|
test_all_22_themes_and_legacy_192dpi_import()
|
|
test_st_overrides_and_xresources_local()
|
|
test_auto_scale_honors_explicit_server_dpi()
|
|
test_stale_env_does_not_override_scale_conf()
|
|
test_gtk_theme_light_dark_detection_and_css_parse()
|
|
test_ui_font_fallback_roboto_to_noto_sans()
|
|
print("test_theme_scale: ALL PASSED (7 fractional scales, 22 themes, legacy 192-DPI import, St overrides, auto DPI, scale.conf precedence, GTK light/dark, Roboto->Noto Sans fallback)")
|