feat: improve session switching, fractional DPI/GTK theming, XDG launcher, CPU/RAM status, and power policy

This commit is contained in:
Luxferre committed 2026-11-26 14:46:03 +02:00
1 parent 72b05b650e
commit 07d9134d2d
28 files changed
+2670 -302

No files matched your search

+152 -1
View File
@@ -253,6 +253,20 @@ def test_resolution(res_str, scale_str, width, height):
time.sleep(0.25)
X11.XGetWindowAttributes(dpy, tray_win, ctypes.byref(tray_attr))
assert tray_attr.height >= pre_h, f"Tray height did not preserve/scale after SIGUSR1: {tray_attr.height} vs {pre_h}"
# Stale exported ANODE_SCALE must not block live scale updates + SIGUSR1 reload
stale_env = dict(env)
stale_env["ANODE_SCALE"] = "2.00"
stale_env["ANODE_TOUCH"] = "1"
stale_env["ANODE_NO_DBUS"] = "1"
subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-scale"), "1.25", "--touch=0"], env=stale_env, check=True)
if shutil.which("xrdb"):
xq = subprocess.check_output(["xrdb", "-query"], env=env, text=True)
assert "theme.scale:\t1.25" in xq or "theme.scale: 1.25" in xq, xq
dwm.send_signal(signal.SIGUSR1)
time.sleep(0.2)
assert dwm.poll() is None, "dwm exited after SIGUSR1 live scale update"
subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-scale"), scale_str, "--touch=1"], env=env, check=True)
dwm.send_signal(signal.SIGUSR1)
time.sleep(0.2)
@@ -273,7 +287,7 @@ def test_resolution(res_str, scale_str, width, height):
assert wait_until(lambda: (lambda w: w if w and len(w) >= 4 and w[3] < wa0[3] else None)(get_cardinal_prop(dpy, root, "_NET_WORKAREA"))), "Workarea did not re-reserve on vkbd show"
terminate(vkbd)
# Test anode-statusd updates root WM_NAME and tracks XKB layout left of datetime
# Test anode-statusd publishes CPU/RAM (never net/docker0) and lowercase XKB left of datetime
sd = subprocess.Popen([os.path.join(BUILD, "daemons", "anode-statusd")], env=env)
procs.append(sd)
@@ -290,9 +304,14 @@ def test_resolution(res_str, scale_str, width, height):
s = get_status()
if not s:
return None
assert "NET " not in s and "docker" not in s.lower(), f"Unexpected network segment in status: {s!r}"
parts = [p.strip() for p in s.split("|")]
if len(parts) < 4:
return None
if not any(re.fullmatch(r"CPU \d+%", p) for p in parts):
return None
if not any(re.fullmatch(r"RAM \d+%", p) for p in parts):
return None
if not re.fullmatch(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}", parts[-1]):
return None
kbd = parts[-2]
@@ -319,6 +338,43 @@ def test_resolution(res_str, scale_str, width, height):
assert wait_until(lambda: get_kbd_left_of_dt() == "us"), f"Expected 'us' restore: {get_status()!r}"
terminate(sd)
# Test dmenu -l 0 (fills full screen height) vs dmenu -l 5 (exact list height)
dm_full = subprocess.Popen(
[os.path.join(BUILD, "dmenu", "dmenu"), "-l", "0"],
env=env, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
)
procs.append(dm_full)
dm_full.stdin.write(b"\n".join(f"item{i}".encode() for i in range(60)) + b"\n")
dm_full.stdin.close()
def find_win_with_height(target_min_w, check_fn):
for w in query_children(dpy, root):
a = XWindowAttributes()
if X11.XGetWindowAttributes(dpy, w, ctypes.byref(a)) and a.map_state == 2 and a.width >= target_min_w:
if check_fn(a.height):
return a.height
return None
h_full = wait_until(lambda: find_win_with_height(width - 10, lambda hh: hh == height))
assert h_full == height, f"dmenu -l 0 did not fill screen height {height}: got {h_full}"
terminate(dm_full)
dm_five = subprocess.Popen(
[os.path.join(BUILD, "dmenu", "dmenu"), "-l", "5"],
env=env, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
)
procs.append(dm_five)
dm_five.stdin.write(b"\n".join(f"item{i}".encode() for i in range(60)) + b"\n")
dm_five.stdin.close()
h_five = wait_until(lambda: find_win_with_height(width - 10, lambda hh: 100 <= hh < height))
assert h_five and h_five < height, f"dmenu -l 5 height invalid: {h_five} vs {height}"
terminate(dm_five)
# Test anode-checkpw rejects wrong password cleanly
chk = subprocess.run(
[os.path.join(BUILD, "daemons", "anode-checkpw")],
input="definitely_wrong_pw_12345\n", env=env, capture_output=True, text=True, timeout=3,
)
assert chk.returncode != 0
# Test core + GemUI utilities launch, map cleanly inside screen, and exit cleanly
for bin_path, extra_stdin in [
(os.path.join(BUILD, "st", "st"), None),
@@ -350,6 +406,99 @@ def test_resolution(res_str, scale_str, width, height):
terminate(xvfb)
def test_st_font_override_and_dunst():
disp = pick_display()
with tempfile.TemporaryDirectory() as home:
env = dict(os.environ)
env["DISPLAY"] = disp
env["HOME"] = home
env["XDG_CONFIG_HOME"] = os.path.join(home, ".config")
env["ANODE_PREFIX"] = ROOT
env["ANODE_NO_SIGNAL"] = "1"
env["LD_LIBRARY_PATH"] = os.path.join(BUILD, "libgemui") + (":" + env["LD_LIBRARY_PATH"] if env.get("LD_LIBRARY_PATH") else "")
env["PATH"] = (
os.path.join(BUILD, "dwm") + ":" +
os.path.join(BUILD, "st") + ":" +
os.path.join(ROOT, "scripts") + ":" +
env.get("PATH", "")
)
xvfb = subprocess.Popen(
["Xvfb", disp, "-screen", "0", "1920x1200x24", "-nolisten", "tcp"],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
)
dpy = None
procs = []
try:
dpy = wait_until(lambda: X11.XOpenDisplay(disp.encode()))
assert dpy, f"Failed to open Xvfb {disp}"
root = X11.XDefaultRootWindow(dpy)
def launch_st_and_get_height_inc(xres_text):
xr_path = os.path.join(home, ".Xresources")
with open(xr_path, "w", encoding="utf-8") as f:
f.write(xres_text)
if shutil.which("xrdb"):
subprocess.run(["xrdb", "-load", xr_path], env=env, check=True)
before = set(query_children(dpy, root))
stp = subprocess.Popen(
[os.path.join(BUILD, "st", "st"), "-e", "sh", "-c", "sleep 4"],
env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
)
procs.append(stp)
def get_inc():
for w in query_children(dpy, root):
if w in before:
continue
a = XWindowAttributes()
if X11.XGetWindowAttributes(dpy, w, ctypes.byref(a)) and a.map_state == 2:
out = subprocess.check_output(["xprop", "-id", hex(w), "WM_NORMAL_HINTS"], env=env, text=True)
m = re.search(r"resize increment:\s*\d+\s+by\s+(\d+)", out)
if m:
return int(m.group(1))
return None
inc = wait_until(get_inc)
terminate(stp)
procs.remove(stp)
return inc
if shutil.which("xprop"):
inc_small = launch_st_and_get_height_inc(
"Xft.dpi: 144\nst.font: Fira Code:pixelsize=15:style=Regular:antialias=true:autohint=true\n"
)
assert inc_small and inc_small <= 22, f"Expected pixelsize=15 height_inc <= 22, got {inc_small}"
inc_override = launch_st_and_get_height_inc(
"Xft.dpi: 144\nst.font: Fira Code:pixelsize=15:style=Regular:antialias=true:autohint=true\n"
"St.font: Fira Code:size=14:antialias=true:autohint=true\n"
)
assert inc_override and inc_override >= 32, f"Expected St.font size=14 @ 144 DPI height_inc >= 32, got {inc_override}"
subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-scale"), "1.50", "--touch=0"], env=env, check=True)
dunstrc = os.path.join(home, ".config", "dunst", "dunstrc")
if shutil.which("dunst"):
denv = dict(env)
denv.pop("DBUS_SESSION_BUS_ADDRESS", None)
dp = subprocess.Popen(
["dunst", "-conf", dunstrc, "-verbosity", "debug"],
env=denv, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True,
)
time.sleep(0.4)
terminate(dp)
dout, derr = dp.communicate(timeout=3)
combined = dout + "\n" + derr
assert "Trying to set scale to 1" in combined, combined
assert "Fira Code 23px" in combined, combined
finally:
for p in reversed(procs):
terminate(p)
if dpy:
X11.XCloseDisplay(dpy)
terminate(xvfb)
def main():
if not shutil.which("Xvfb"):
print("test_x11_xvfb: Xvfb not installed (skipping)")
@@ -362,6 +511,8 @@ def main():
for res, sc, w, h in cases:
test_resolution(res, sc, w, h)
print(f"test_x11_xvfb: {res} @ {sc}x OK")
test_st_font_override_and_dunst()
print("test_x11_xvfb: St.font override & Dunst scale=1 OK")
return 0