#!/usr/bin/env python3 """Verify all Geminux .xth themes, dunst synchronization, and GTK2/3/4/Qt synchronization.""" import glob import os import re import subprocess import sys import tempfile BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) THEMES_DIR = os.path.join(BASE_DIR, "overlay", "rootfs", "etc", "skel", ".xthemes") SYNC_SCRIPT = os.path.join(BASE_DIR, "overlay", "rootfs", "usr", "bin", "geminux-sync-dunst-theme") GTK_SYNC_SCRIPT = os.path.join(BASE_DIR, "overlay", "rootfs", "usr", "bin", "geminux-sync-gtk-theme") LIGHT_THEMES = frozenset({"CatppuccinLatte", "GruvboxLight", "SolarizedLight"}) REQUIRED_KEYS = ( "theme.name", "theme.fontFace", "theme.iconFontFace", "theme.baseFontSize", "theme.bgMain", "theme.bgBar", "theme.bgHeader", "theme.bgOverlay", "theme.fgMain", "theme.fgBright", "theme.fgMuted", "theme.selBg", "theme.selFg", "theme.accent", "theme.border", "theme.danger", "theme.dangerBg", "dmenu.font", "dmenu.background", "dmenu.foreground", "dmenu.selbackground", "dmenu.selforeground", "dwm.font", "dwm.normbgcolor", "dwm.normfgcolor", "dwm.selbgcolor", "dwm.selfgcolor", "st.font", "st.background", "st.foreground", "st.cursorColor", "Xft.dpi", "*TkTheme", ) HEX_RE = re.compile(r"^#[0-9a-fA-F]{6}$") def parse_xres(path): vals = {} with open(path) as f: for line in f: line = line.strip() if not line or line.startswith("!") or line.startswith("#") or ":" not in line: continue k, v = line.split(":", 1) vals[k.strip()] = v.strip() return vals def main(): themes = sorted(glob.glob(os.path.join(THEMES_DIR, "*.xth"))) assert len(themes) >= 20, f"Expected >= 20 themes, found {len(themes)}" with tempfile.TemporaryDirectory(prefix="geminux-dunst-test-") as tmp: for idx, th in enumerate(themes): vals = parse_xres(th) for req in REQUIRED_KEYS: assert req in vals and vals[req], f"Missing {req} in {os.path.basename(th)}" assert int(vals["Xft.dpi"]) >= 168, f"Expected Xft.dpi >= 168 in {os.path.basename(th)}" assert int(vals["theme.baseFontSize"]) >= 28, f"Expected baseFontSize >= 28 in {os.path.basename(th)}" assert vals["*TkTheme"] == "gtkTtk", f"Expected *TkTheme: gtkTtk in {os.path.basename(th)}" assert "Fira Code" in vals["theme.fontFace"], f"Expected Fira Code in {os.path.basename(th)}" assert "Fira Code" in vals["st.font"], f"Expected Fira Code in st.font of {os.path.basename(th)}" assert "Fira Code" in vals["dmenu.font"], f"Expected Fira Code in dmenu.font of {os.path.basename(th)}" assert "Fira Code" in vals["dwm.font"], f"Expected Fira Code in dwm.font of {os.path.basename(th)}" for color_key in ("theme.bgMain", "theme.fgMain", "theme.accent", "theme.danger"): assert HEX_RE.match(vals[color_key]), f"Invalid hex color {color_key}={vals[color_key]} in {th}" dunstrc = os.path.join(tmp, f"{os.path.basename(th)}.dunstrc") env = dict(os.environ, GEMINUX_XRESOURCES=th, GEMINUX_DUNSTRC=dunstrc) subprocess.run([SYNC_SCRIPT, "--no-restart"], env=env, check=True) with open(dunstrc) as df: txt = df.read() assert vals["theme.accent"] in txt assert vals["theme.bgMain"] in txt assert vals["theme.dangerBg"] in txt assert "font = Fira Code " in txt assert "width = 720" in txt th_home = os.path.join(tmp, f"home-{idx}") os.makedirs(th_home, exist_ok=True) gtk_env = { k: v for k, v in os.environ.items() if k not in ( "GEMINUX_RUNTIME_HOME", "GEMINUX_GTK_THEMES_DIR", "GEMINUX_XDG_THEMES_DIR", "GEMINUX_GTK2_RC", "GEMINUX_GTK3_DIR", "GEMINUX_GTK4_DIR", "GEMINUX_XSETTINGSD_CONF", "GEMINUX_QT6CT_DIR", "GEMINUX_KVANTUM_DIR", ) } gtk_env["HOME"] = th_home gtk_env["GEMINUX_XRESOURCES"] = th subprocess.run([GTK_SYNC_SCRIPT, "--no-reload"], env=gtk_env, check=True) tname = vals["theme.name"] gtk_name = f"Geminux-{tname}" theme_root = os.path.join(th_home, ".themes", gtk_name) is_light = tname in LIGHT_THEMES for cfg_rel in ( ".gtkrc-2.0", ".config/gtk-3.0/settings.ini", ".config/gtk-4.0/settings.ini", ".config/xsettingsd/xsettingsd.conf", ): cfg_path = os.path.join(th_home, cfg_rel) with open(cfg_path, encoding="utf-8") as cf: cfg_txt = cf.read() assert gtk_name in cfg_txt, f"Missing {gtk_name} in {cfg_rel} for {tname}" assert "/tmp" not in cfg_txt and "/home" not in cfg_txt, ( f"Hardcoded path leaked into {cfg_rel} for {tname}: {cfg_txt}" ) for ini_rel in (".config/gtk-3.0/settings.ini", ".config/gtk-4.0/settings.ini"): with open(os.path.join(th_home, ini_rel), encoding="utf-8") as sf: ini_txt = sf.read() exp_dark_bool = "false" if is_light else "true" assert f"gtk-application-prefer-dark-theme={exp_dark_bool}" in ini_txt, ( f"Expected gtk-application-prefer-dark-theme={exp_dark_bool} in {ini_rel} for {tname}" ) with open(os.path.join(th_home, ".config/gtk-3.0/gtk.css"), encoding="utf-8") as css3u: css3u_txt = css3u.read() assert "@import" not in css3u_txt, f"Unexpected @import in user gtk-3.0/gtk.css for {tname}" assert f"@define-color theme_bg_color {vals['theme.bgMain']};" in css3u_txt with open(os.path.join(th_home, ".config/gtk-4.0/gtk.css"), encoding="utf-8") as adw_f: adw_txt = adw_f.read() assert "@import" not in adw_txt and "Default-" not in adw_txt, ( f"Unexpected Default theme @import in user gtk-4.0/gtk.css for {tname}" ) assert adw_txt.count("{") == adw_txt.count("}"), f"Unbalanced braces in gtk-4.0/gtk.css for {tname}" assert f"@define-color window_bg_color {vals['theme.bgMain']};" in adw_txt assert f"--window-bg-color: {vals['theme.bgMain']};" in adw_txt with open(os.path.join(th_home, ".config/qt6ct/qt6ct.conf"), encoding="utf-8") as qtf: qt_txt = qtf.read() assert "style=Fusion" in qt_txt assert "custom_palette=true" in qt_txt assert f"color_scheme_path={th_home}/.config/qt6ct/colors/{gtk_name}.conf" in qt_txt assert f"Theme: {tname}" in qt_txt assert vals["theme.fontFace"] in qt_txt for qtc_rel in (f".config/qt6ct/colors/{gtk_name}.conf", ".config/qt6ct/colors/Geminux.conf"): with open(os.path.join(th_home, qtc_rel), encoding="utf-8") as qtcf: qtc_txt = qtcf.read() qtc_map = {} for line in qtc_txt.splitlines(): if "=" in line and not line.lstrip().startswith("#"): k, v = line.split("=", 1) qtc_map[k.strip()] = [c.strip() for c in v.split(",")] for section in ("active_colors", "disabled_colors", "inactive_colors"): cols = qtc_map.get(section, []) assert len(cols) == 21, f"Expected 21 qt6ct palette roles in {section} for {tname}, got {len(cols)}" for col in cols: assert re.match(r"^#[0-9a-fA-F]{8}$", col), f"Invalid ARGB entry '{col}' in {section} for {tname}" assert qtc_map["active_colors"][10] == f"#ff{vals['theme.bgMain'][1:].lower()}" assert qtc_map["active_colors"][12] == f"#ff{vals['theme.selBg'][1:].lower()}" with open(os.path.join(th_home, ".config/Kvantum/kvantum.kvconfig"), encoding="utf-8") as kvf: assert "theme=Geminux" in kvf.read() with open(os.path.join(th_home, ".config/Kvantum/Geminux/Geminux.kvconfig"), encoding="utf-8") as kvtf: kvt_txt = kvtf.read() assert f"window.color={vals['theme.bgMain']}" in kvt_txt assert f"highlight.color={vals['theme.selBg']}" in kvt_txt with open(os.path.join(th_home, ".config/xsettingsd/xsettingsd.conf"), encoding="utf-8") as xf: xsd_txt = xf.read() assert f'Net/ThemeName "{gtk_name}"' in xsd_txt assert "Xft/DPI" not in xsd_txt, f"Unexpected Xft/DPI in xsettingsd.conf for {tname}" with open(os.path.join(theme_root, "index.theme"), encoding="utf-8") as itf: idx_txt = itf.read() assert f"GtkTheme={gtk_name}" in idx_txt with open(os.path.join(theme_root, "gtk-2.0/gtkrc"), encoding="utf-8") as rc2f: rc2_txt = rc2f.read() assert 'engine "' not in rc2_txt, f"External GTK2 engine referenced in {tname}" for ck in ("theme.bgMain", "theme.fgMain", "theme.selBg", "theme.accent"): assert vals[ck] in rc2_txt, f"Missing {ck} in gtkrc for {tname}" with open(os.path.join(theme_root, "gtk-3.0/gtk.css"), encoding="utf-8") as css3f: css3_txt = css3f.read() exp_base = "gtk-contained.css" if is_light else "gtk-contained-dark.css" assert f'@import url("resource:///org/gtk/libgtk/theme/Adwaita/{exp_base}");' in css3_txt, ( f"Wrong Adwaita base CSS in {tname}: expected {exp_base}" ) assert css3_txt.count("{") == css3_txt.count("}"), f"Unbalanced braces in gtk.css for {tname}" for ck in ("theme.bgMain", "theme.fgMain", "theme.selBg", "theme.accent", "theme.dangerBg"): assert vals[ck] in css3_txt, f"Missing {ck} in gtk.css for {tname}" with open(os.path.join(theme_root, "gtk-3.0/gtk-dark.css"), encoding="utf-8") as css3df: assert '@import url("gtk.css");' in css3df.read() with open(os.path.join(theme_root, "gtk-4.0/gtk.css"), encoding="utf-8") as css4f: css4_txt = css4f.read() exp_gtk4_base = "Default-light.css" if is_light else "Default-dark.css" assert f'@import url("resource:///org/gtk/libgtk/theme/Default/{exp_gtk4_base}");' in css4_txt, ( f"Wrong GTK4 base CSS in {tname}: expected {exp_gtk4_base}" ) assert css4_txt.count("{") == css4_txt.count("}"), f"Unbalanced braces in gtk-4.0/gtk.css for {tname}" for ck in ("theme.bgMain", "theme.fgMain", "theme.selBg", "theme.accent", "theme.dangerBg"): assert vals[ck] in css4_txt, f"Missing {ck} in gtk-4.0/gtk.css for {tname}" with open(os.path.join(theme_root, "gtk-4.0/gtk-dark.css"), encoding="utf-8") as css4df: assert '@import url("gtk.css");' in css4df.read() xdg_link = os.path.join(th_home, ".local/share/themes", gtk_name) assert os.path.islink(xdg_link), f"Missing XDG symlink {xdg_link}" assert os.readlink(xdg_link) == f"../../../.themes/{gtk_name}", ( f"Unexpected XDG symlink target for {tname}: {os.readlink(xdg_link)}" ) assert os.path.isfile(os.path.join(xdg_link, "gtk-3.0/gtk.css")) assert os.path.isfile(os.path.join(xdg_link, "gtk-4.0/gtk.css")) skel_home = os.path.join(tmp, "skel") os.makedirs(skel_home, exist_ok=True) skel_env = dict(gtk_env, HOME=skel_home, GEMINUX_RUNTIME_HOME="/home/user", GEMINUX_XRESOURCES=themes[0]) subprocess.run([GTK_SYNC_SCRIPT, "--no-reload"], env=skel_env, check=True) with open(os.path.join(skel_home, ".config/qt6ct/qt6ct.conf"), encoding="utf-8") as skf: skel_qt = skf.read() first_name = f"Geminux-{parse_xres(themes[0])['theme.name']}" assert f"color_scheme_path=/home/user/.config/qt6ct/colors/{first_name}.conf" in skel_qt print(f"[PASS] Verified {len(themes)} .xth themes, dunst synchronization, and GTK2/3/4/Qt/Tk theme generation") return 0 if __name__ == "__main__": sys.exit(main())