feat: improve session switching, fractional DPI/GTK theming, XDG launcher, CPU/RAM status, and power policy
This commit is contained in:
1 parent
72b05b650e
commit
07d9134d2d
28 files changed
+2670
-302
No files matched your search
+210
-11
@@ -34,13 +34,13 @@ def parse_xres(path):
|
||||
|
||||
def test_fractional_scales():
|
||||
scales = [
|
||||
("0.75", 72, "1", 11),
|
||||
("1.00", 96, "1", 15),
|
||||
("1.25", 120, "1", 19),
|
||||
("1.50", 144, "1", 23),
|
||||
("1.75", 168, "2", 26),
|
||||
("2.00", 192, "2", 30),
|
||||
("2.50", 240, "3", 38),
|
||||
("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)
|
||||
@@ -50,33 +50,81 @@ def test_fractional_scales():
|
||||
env["ANODE_PREFIX"] = ROOT
|
||||
env["ANODE_NO_SIGNAL"] = "1"
|
||||
|
||||
for s_str, exp_dpi, exp_gdk, exp_px in scales:
|
||||
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 f'export GDK_SCALE="{exp_gdk}"' in senv, senv
|
||||
assert 'export GDK_DPI_SCALE="1.0"' in senv, senv
|
||||
assert f'export GDK_DPI_SCALE="{exp_gdk_dpi}"' 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 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 "Fira Code" in xres["st.font"] and f"pixelsize={exp_px}" in xres["st.font"]
|
||||
assert "Fira Code" in xres["dwm.font"] and f"{exp_px}px" in xres["dwm.font"]
|
||||
assert xres["*TkTheme"] == "gtkTtk"
|
||||
assert xres["theme.touchMode"] == "1"
|
||||
|
||||
# Verify xsettingsd omits Xft/DPI so GTK3 does not double-scale
|
||||
# Verify xsettingsd omits Xft/DPI and keeps unscaled logical pt + GDK-adjusted cursor
|
||||
xs_p = os.path.join(tmp, ".config", "xsettingsd", "xsettingsd.conf")
|
||||
with open(xs_p, "r", encoding="utf-8") as f:
|
||||
xs = f.read()
|
||||
assert "Xft/DPI" not in xs, f"Xft/DPI must not exist in xsettingsd.conf:\n{xs}"
|
||||
assert f"Gdk/WindowScalingFactor {exp_gdk}" in xs, xs
|
||||
assert 'Gtk/FontName "Fira Code 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 'gtk-font-name="Fira Code 10"' in gtk2, gtk2
|
||||
assert f"gtk-cursor-theme-size={exp_cur}" in gtk2, gtk2
|
||||
|
||||
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 "gtk-font-name=Fira Code 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 'general="Fira Code,10,' in qconf, qconf
|
||||
assert 'fixed="Fira Code,10,' in qconf, qconf
|
||||
|
||||
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 Qt5 + Qt6 + Kvantum + Dunst + GTK2/3/4 files
|
||||
for p in [
|
||||
@@ -138,7 +186,158 @@ def test_all_22_themes_and_legacy_192dpi_import():
|
||||
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["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["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["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["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")
|
||||
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
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_fractional_scales()
|
||||
test_all_22_themes_and_legacy_192dpi_import()
|
||||
print("test_theme_scale: ALL PASSED (7 fractional scales, 22 themes, legacy 192-DPI 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()
|
||||
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)")
|
||||
Reference in new issue
Block a user