#!/usr/bin/env python3 """Headless Xvfb E2E integration tests across 1024x600, 1920x1080, and 3840x2160.""" import ctypes import ctypes.util import os import re import shutil import signal import socket import subprocess import sys import tempfile import time ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) BUILD = os.path.join(ROOT, "build") libx11_name = ctypes.util.find_library("X11") or "libX11.so.6" X11 = ctypes.CDLL(libx11_name) Window = ctypes.c_ulong Atom = ctypes.c_ulong Display_p = ctypes.c_void_p class XWindowAttributes(ctypes.Structure): _fields_ = [ ("x", ctypes.c_int), ("y", ctypes.c_int), ("width", ctypes.c_int), ("height", ctypes.c_int), ("border_width", ctypes.c_int), ("depth", ctypes.c_int), ("visual", ctypes.c_void_p), ("root", Window), ("class", ctypes.c_int), ("bit_gravity", ctypes.c_int), ("win_gravity", ctypes.c_int), ("backing_store", ctypes.c_int), ("backing_planes", ctypes.c_ulong), ("backing_pixel", ctypes.c_ulong), ("save_under", ctypes.c_int), ("colormap", ctypes.c_ulong), ("map_installed", ctypes.c_int), ("map_state", ctypes.c_int), ("all_event_masks", ctypes.c_long), ("your_event_mask", ctypes.c_long), ("do_not_propagate_mask", ctypes.c_long), ("override_redirect", ctypes.c_int), ("screen", ctypes.c_void_p), ] class XClientMessageData(ctypes.Union): _fields_ = [("b", ctypes.c_char * 20), ("s", ctypes.c_short * 10), ("l", ctypes.c_long * 5)] class XClientMessageEvent(ctypes.Structure): _fields_ = [ ("type", ctypes.c_int), ("serial", ctypes.c_ulong), ("send_event", ctypes.c_int), ("display", Display_p), ("window", Window), ("message_type", Atom), ("format", ctypes.c_int), ("data", XClientMessageData), ] class XWMHints(ctypes.Structure): _fields_ = [ ("flags", ctypes.c_long), ("input", ctypes.c_int), ("initial_state", ctypes.c_int), ("icon_pixmap", ctypes.c_ulong), ("icon_window", Window), ("icon_x", ctypes.c_int), ("icon_y", ctypes.c_int), ("icon_mask", ctypes.c_ulong), ("window_group", Window), ] X11.XOpenDisplay.argtypes = [ctypes.c_char_p] X11.XOpenDisplay.restype = Display_p X11.XCloseDisplay.argtypes = [Display_p] X11.XDefaultRootWindow.argtypes = [Display_p] X11.XDefaultRootWindow.restype = Window X11.XInternAtom.argtypes = [Display_p, ctypes.c_char_p, ctypes.c_int] X11.XInternAtom.restype = Atom X11.XGetSelectionOwner.argtypes = [Display_p, Atom] X11.XGetSelectionOwner.restype = Window X11.XGetWindowProperty.argtypes = [ Display_p, Window, Atom, ctypes.c_long, ctypes.c_long, ctypes.c_int, Atom, ctypes.POINTER(Atom), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_ulong), ctypes.POINTER(ctypes.c_ulong), ctypes.POINTER(ctypes.POINTER(ctypes.c_ubyte)), ] X11.XGetWindowProperty.restype = ctypes.c_int X11.XFree.argtypes = [ctypes.c_void_p] X11.XCreateSimpleWindow.argtypes = [ Display_p, Window, ctypes.c_int, ctypes.c_int, ctypes.c_uint, ctypes.c_uint, ctypes.c_uint, ctypes.c_ulong, ctypes.c_ulong, ] X11.XCreateSimpleWindow.restype = Window X11.XDestroyWindow.argtypes = [Display_p, Window] X11.XChangeProperty.argtypes = [ Display_p, Window, Atom, Atom, ctypes.c_int, ctypes.c_int, ctypes.c_void_p, ctypes.c_int ] X11.XSendEvent.argtypes = [Display_p, Window, ctypes.c_int, ctypes.c_long, ctypes.c_void_p] X11.XFlush.argtypes = [Display_p] X11.XSync.argtypes = [Display_p, ctypes.c_int] X11.XQueryTree.argtypes = [ Display_p, Window, ctypes.POINTER(Window), ctypes.POINTER(Window), ctypes.POINTER(ctypes.POINTER(Window)), ctypes.POINTER(ctypes.c_uint), ] X11.XQueryTree.restype = ctypes.c_int X11.XGetWindowAttributes.argtypes = [Display_p, Window, ctypes.POINTER(XWindowAttributes)] X11.XGetWindowAttributes.restype = ctypes.c_int X11.XGetWMHints.argtypes = [Display_p, Window] X11.XGetWMHints.restype = ctypes.POINTER(XWMHints) X11.XFetchName.argtypes = [Display_p, Window, ctypes.POINTER(ctypes.c_char_p)] X11.XFetchName.restype = ctypes.c_int X11.XkbLockGroup.argtypes = [Display_p, ctypes.c_uint, ctypes.c_uint] X11.XkbLockGroup.restype = ctypes.c_int def pick_display(): for d in range(70, 120): if not os.path.exists(f"/tmp/.X{d}-lock") and not os.path.exists(f"/tmp/.X11-unix/X{d}"): return f":{d}" return ":99" def get_cardinal_prop(dpy, win, atom_name): atom = X11.XInternAtom(dpy, atom_name.encode(), 0) da = Atom() di = ctypes.c_int() n = ctypes.c_ulong() dl = ctypes.c_ulong() prop = ctypes.POINTER(ctypes.c_ubyte)() rc = X11.XGetWindowProperty(dpy, win, atom, 0, 16, 0, 0, ctypes.byref(da), ctypes.byref(di), ctypes.byref(n), ctypes.byref(dl), ctypes.byref(prop)) if rc != 0 or not prop: return [] vals = [] if di.value == 32 and n.value > 0: arr = ctypes.cast(prop, ctypes.POINTER(ctypes.c_ulong)) vals = [int(arr[i]) for i in range(n.value)] X11.XFree(prop) return vals def query_children(dpy, parent): r = Window() p = Window() ch = ctypes.POINTER(Window)() n = ctypes.c_uint() if X11.XQueryTree(dpy, parent, ctypes.byref(r), ctypes.byref(p), ctypes.byref(ch), ctypes.byref(n)): out = [int(ch[i]) for i in range(n.value)] if ch: X11.XFree(ch) return out return [] def wait_until(pred, timeout=5.0): end = time.monotonic() + timeout while time.monotonic() < end: res = pred() if res: return res time.sleep(0.05) return None def terminate(proc): if proc and proc.poll() is None: proc.terminate() try: proc.wait(timeout=3) except subprocess.TimeoutExpired: proc.kill() proc.wait(timeout=2) def test_resolution(res_str, scale_str, width, height): 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, "dmenu") + ":" + os.path.join(BUILD, "st") + ":" + os.path.join(BUILD, "apps") + ":" + os.path.join(BUILD, "daemons") + ":" + os.path.join(ROOT, "scripts") + ":" + env.get("PATH", "") ) # Configure theme + scale in sandbox subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-scale"), scale_str, "--touch=1"], env=env, check=True) xvfb = subprocess.Popen( ["Xvfb", disp, "-screen", "0", f"{res_str}x24", "-nolisten", "tcp"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ) dwm = None dpy = None procs = [] try: dpy = wait_until(lambda: X11.XOpenDisplay(disp.encode())) assert dpy, f"Failed to open Xvfb {disp}" root = X11.XDefaultRootWindow(dpy) dwm = subprocess.Popen([os.path.join(BUILD, "dwm", "dwm")], env=env) procs.append(dwm) tray_atom = X11.XInternAtom(dpy, b"_NET_SYSTEM_TRAY_S0", 0) tray_win = wait_until(lambda: X11.XGetSelectionOwner(dpy, tray_atom)) assert tray_win, f"DWM failed to acquire _NET_SYSTEM_TRAY_S0 on {res_str}" # Check initial _NET_WORKAREA and empty systray must be unmapped wa0 = wait_until(lambda: get_cardinal_prop(dpy, root, "_NET_WORKAREA")) assert len(wa0) >= 4 and wa0[2] == width and wa0[3] < height, f"Bad initial workarea: {wa0}" tray_attr = XWindowAttributes() X11.XGetWindowAttributes(dpy, tray_win, ctypes.byref(tray_attr)) assert tray_attr.map_state == 0, "Empty systray should stay unmapped!" # Test XEmbed systray docking + _XEMBED_INFO unmap/remap + SIGUSR1 resize + undock icon = X11.XCreateSimpleWindow(dpy, root, 0, 0, 24, 24, 0, 0, 0xffffff) xembed_info = X11.XInternAtom(dpy, b"_XEMBED_INFO", 0) info_arr = (ctypes.c_ulong * 2)(0, 1) # version=0, XEMBED_MAPPED=1 X11.XChangeProperty(dpy, icon, xembed_info, xembed_info, 32, 0, info_arr, 2) op_atom = X11.XInternAtom(dpy, b"_NET_SYSTEM_TRAY_OPCODE", 0) ev = XClientMessageEvent() ev.type = 33 # ClientMessage ev.display = dpy ev.window = tray_win ev.message_type = op_atom ev.format = 32 ev.data.l[0] = 0 ev.data.l[1] = 0 # SYSTEM_TRAY_REQUEST_DOCK ev.data.l[2] = icon X11.XSendEvent(dpy, tray_win, 0, 0, ctypes.byref(ev)) X11.XSync(dpy, 0) assert wait_until(lambda: icon in query_children(dpy, tray_win)), "Icon was not reparented into systray!" X11.XGetWindowAttributes(dpy, tray_win, ctypes.byref(tray_attr)) assert tray_attr.map_state == 2, "Non-empty systray must be mapped (IsViewable)" # Toggle _XEMBED_INFO unmapped -> tray unmaps info_unmap = (ctypes.c_ulong * 2)(0, 0) X11.XChangeProperty(dpy, icon, xembed_info, xembed_info, 32, 0, info_unmap, 2) X11.XSync(dpy, 0) assert wait_until(lambda: (X11.XGetWindowAttributes(dpy, tray_win, ctypes.byref(tray_attr)) or True) and tray_attr.map_state == 0), "Tray did not unmap when icon withdrew!" # Remap via _XEMBED_INFO, reload scale via SIGUSR1, then destroy cleanly X11.XChangeProperty(dpy, icon, xembed_info, xembed_info, 32, 0, info_arr, 2) X11.XSync(dpy, 0) assert wait_until(lambda: (X11.XGetWindowAttributes(dpy, tray_win, ctypes.byref(tray_attr)) or True) and tray_attr.map_state == 2) pre_h = tray_attr.height subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-scale"), "2.00", "--touch=1"], env=env, check=True) dwm.send_signal(signal.SIGUSR1) 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) X11.XDestroyWindow(dpy, icon) X11.XSync(dpy, 0) assert wait_until(lambda: icon not in query_children(dpy, tray_win)) # Refresh wa0 after scale restore before testing anode-vkbd dock strut wa0 = wait_until(lambda: get_cardinal_prop(dpy, root, "_NET_WORKAREA")) vkbd = subprocess.Popen([os.path.join(BUILD, "apps", "anode-vkbd")], env=env) procs.append(vkbd) wa_vk = 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"))) assert wa_vk, f"anode-vkbd did not reserve workarea strut on {res_str} (wa0={wa0})" # Hide via SIGUSR1 -> workarea restores, then re-show via SIGUSR1 -> strut reserves again vkbd.send_signal(signal.SIGUSR1) assert wait_until(lambda: get_cardinal_prop(dpy, root, "_NET_WORKAREA") == wa0), "Workarea did not restore on vkbd hide" vkbd.send_signal(signal.SIGUSR1) 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 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) def get_status(): nm = ctypes.c_char_p() if X11.XFetchName(dpy, root, ctypes.byref(nm)) and nm.value: s = nm.value.decode("utf-8", errors="ignore") X11.XFree(nm) if "|" in s: return s return None def get_kbd_left_of_dt(): 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] if not kbd or not kbd.isascii() or not kbd.isalnum() or kbd != kbd.lower(): return None return kbd init_kbd = wait_until(get_kbd_left_of_dt) assert init_kbd, f"anode-statusd missing lowercase XKB layout left of datetime: {get_status()!r}" if shutil.which("setxkbmap"): subprocess.run( ["setxkbmap", "-layout", "us,de,ru", "-variant", ",nodeadkeys,"], env=env, check=True, ) assert wait_until(lambda: get_kbd_left_of_dt() == "us"), f"Expected 'us': {get_status()!r}" X11.XkbLockGroup(dpy, 0x0100, 1) X11.XSync(dpy, 0) assert wait_until(lambda: get_kbd_left_of_dt() == "de"), f"Expected 'de': {get_status()!r}" X11.XkbLockGroup(dpy, 0x0100, 2) X11.XSync(dpy, 0) assert wait_until(lambda: get_kbd_left_of_dt() == "ru"), f"Expected 'ru': {get_status()!r}" X11.XkbLockGroup(dpy, 0x0100, 0) X11.XSync(dpy, 0) 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), (os.path.join(BUILD, "dmenu", "dmenu"), b"alpha\nbeta\n"), (os.path.join(BUILD, "apps", "anode-themes"), None), (os.path.join(BUILD, "apps", "anode-power"), None), (os.path.join(BUILD, "apps", "anode-display"), None), (os.path.join(BUILD, "apps", "anode-audio"), None), (os.path.join(BUILD, "apps", "anode-datetime"), None), (os.path.join(BUILD, "apps", "anode-net"), None), ]: before = set(query_children(dpy, root)) if extra_stdin: p = subprocess.Popen([bin_path], env=env, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) p.stdin.write(extra_stdin) p.stdin.close() else: p = subprocess.Popen([bin_path], env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) procs.append(p) time.sleep(0.35) assert p.poll() is None, f"{os.path.basename(bin_path)} exited prematurely on {res_str} with code {p.returncode}" terminate(p) finally: for p in reversed(procs): terminate(p) if dpy: X11.XCloseDisplay(dpy) 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_default = launch_st_and_get_height_inc( "Xft.dpi: 144\n" ) assert inc_default and inc_default >= 28, f"Expected default size=13 @ 144 DPI height_inc >= 28, got {inc_default}" 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 get_wm_class(dpy, win): atom = X11.XInternAtom(dpy, b"WM_CLASS", 0) da = Atom() di = ctypes.c_int() n = ctypes.c_ulong() dl = ctypes.c_ulong() prop = ctypes.POINTER(ctypes.c_ubyte)() rc = X11.XGetWindowProperty(dpy, win, atom, 0, 64, 0, 31, # XA_STRING=31 ctypes.byref(da), ctypes.byref(di), ctypes.byref(n), ctypes.byref(dl), ctypes.byref(prop)) if rc != 0 or not prop: return [] raw = bytes(prop[:n.value]) if n.value > 0 else b"" X11.XFree(prop) return [s for s in raw.decode("utf-8", errors="ignore").split("\0") if s] def test_lockscreen_overlaps_systray(): 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, "apps") + ":" + os.path.join(ROOT, "scripts") + ":" + env.get("PATH", "") ) subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-scale"), "1.00", "--touch=0"], env=env, check=True) xvfb = subprocess.Popen( ["Xvfb", disp, "-screen", "0", "1280x800x24", "-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) dwm = subprocess.Popen([os.path.join(BUILD, "dwm", "dwm")], env=env) procs.append(dwm) tray_atom = X11.XInternAtom(dpy, b"_NET_SYSTEM_TRAY_S0", 0) tray_win = wait_until(lambda: X11.XGetSelectionOwner(dpy, tray_atom)) assert tray_win, "DWM failed to acquire _NET_SYSTEM_TRAY_S0" def find_bar_win(): for w in query_children(dpy, root): if "anode-wm" in get_wm_class(dpy, w): return w return None bar_win = wait_until(find_bar_win) assert bar_win, "DWM barwin not found" xembed_info = X11.XInternAtom(dpy, b"_XEMBED_INFO", 0) op_atom = X11.XInternAtom(dpy, b"_NET_SYSTEM_TRAY_OPCODE", 0) info_arr = (ctypes.c_ulong * 2)(0, 1) def dock_dummy_icon(): ic = X11.XCreateSimpleWindow(dpy, root, 0, 0, 20, 20, 0, 0, 0xffffff) X11.XChangeProperty(dpy, ic, xembed_info, xembed_info, 32, 0, info_arr, 2) ev = XClientMessageEvent() ev.type = 33 ev.display = dpy ev.window = tray_win ev.message_type = op_atom ev.format = 32 ev.data.l[0] = 0 ev.data.l[1] = 0 ev.data.l[2] = ic X11.XSendEvent(dpy, tray_win, 0, 0, ctypes.byref(ev)) X11.XSync(dpy, 0) assert wait_until(lambda: ic in query_children(dpy, tray_win)), "Dummy icon failed to dock" return ic dock_dummy_icon() lockp = subprocess.Popen([os.path.join(BUILD, "apps", "anode-lock")], env=env) procs.append(lockp) def find_lock_win(): for w in query_children(dpy, root): if "anode-lock" in get_wm_class(dpy, w): a = XWindowAttributes() if X11.XGetWindowAttributes(dpy, w, ctypes.byref(a)) and a.map_state == 2: return w return None lock_win = wait_until(find_lock_win) assert lock_win, "anode-lock window did not map" # Trigger systray updates while locked: dock a 2nd icon and reload dwm via SIGUSR1 dock_dummy_icon() dwm.send_signal(signal.SIGUSR1) time.sleep(0.3) def lock_on_top(): stack = query_children(dpy, root) if lock_win not in stack or tray_win not in stack or bar_win not in stack: return False return stack.index(lock_win) > stack.index(tray_win) and stack.index(lock_win) > stack.index(bar_win) assert wait_until(lock_on_top), f"anode-lock did not overlap systray/bar: stack={query_children(dpy, root)}, lock={lock_win}, tray={tray_win}, bar={bar_win}" 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)") return 0 cases = [ ("1024x600", "1.00", 1024, 600), ("1920x1080", "1.25", 1920, 1080), ("3840x2160", "2.00", 3840, 2160), ] 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") test_lockscreen_overlaps_systray() print("test_x11_xvfb: lockscreen overlaps systray OK") return 0 if __name__ == "__main__": sys.exit(main())