fix(wm,st,theme): fix live theme reload across apps and top-bar artifacts
- Read XA_RESOURCE_MANAGER directly via XGetWindowProperty in anode_open_xres_db() instead of XResourceManagerString(), avoiding stale startup Xlib caches. - Switch xrdb -merge to xrdb -load in anode-apply-theme and reset default palettes/resources on reload in dwm and st so omitted keys do not linger. - Update Mod4+Shift+r (reloadxres) in dwm to run xrdb -load, signal running ANODE processes, and run anode-autostart reload while freeing old XftColors, preserving fullscreen borders, and updating non-ARGB tray icon backgrounds. - Watch root PropertyNotify(XA_RESOURCE_MANAGER) in st, use sigaction(SIGUSR1), free reloaded resource strings, and refresh window background and cursor colors. - Fix drw_text() return x-coordinate in dwm and dmenu and clear the bar pixmap in drawbar() to eliminate unpainted gaps before window titles on reload. - Sync active_name on external theme reload in anode-themes and add pixel-level test_live_theme_reload_and_bar_artifacts() in tests/test_x11_xvfb.py.
This commit is contained in:
1 parent
d1eff5562d
commit
86ca30db03
8 files changed
+343
-42
No files matched your search
+179
-2
@@ -92,6 +92,10 @@ class XSetWindowAttributes(ctypes.Structure):
|
||||
]
|
||||
|
||||
|
||||
class XClassHint(ctypes.Structure):
|
||||
_fields_ = [("res_name", ctypes.c_void_p), ("res_class", ctypes.c_void_p)]
|
||||
|
||||
|
||||
X11.XOpenDisplay.argtypes = [ctypes.c_char_p]
|
||||
X11.XOpenDisplay.restype = Display_p
|
||||
X11.XCloseDisplay.argtypes = [Display_p]
|
||||
@@ -130,6 +134,17 @@ X11.XQueryTree.argtypes = [
|
||||
X11.XQueryTree.restype = ctypes.c_int
|
||||
X11.XGetWindowAttributes.argtypes = [Display_p, Window, ctypes.POINTER(XWindowAttributes)]
|
||||
X11.XGetWindowAttributes.restype = ctypes.c_int
|
||||
X11.XGetClassHint.argtypes = [Display_p, Window, ctypes.POINTER(XClassHint)]
|
||||
X11.XGetClassHint.restype = ctypes.c_int
|
||||
X11.XGetImage.argtypes = [
|
||||
Display_p, Window, ctypes.c_int, ctypes.c_int,
|
||||
ctypes.c_uint, ctypes.c_uint, ctypes.c_ulong, ctypes.c_int,
|
||||
]
|
||||
X11.XGetImage.restype = ctypes.c_void_p
|
||||
X11.XGetPixel.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
|
||||
X11.XGetPixel.restype = ctypes.c_ulong
|
||||
X11.XDestroyImage.argtypes = [ctypes.c_void_p]
|
||||
X11.XDestroyImage.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)]
|
||||
@@ -266,8 +281,7 @@ def test_resolution(res_str, scale_str, width, height):
|
||||
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)"
|
||||
assert wait_until(lambda: (X11.XGetWindowAttributes(dpy, tray_win, ctypes.byref(tray_attr)) or True) and 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)
|
||||
@@ -1676,6 +1690,167 @@ def test_systray_xembed_dock_race():
|
||||
terminate(xvfb)
|
||||
|
||||
|
||||
def test_live_theme_reload_and_bar_artifacts():
|
||||
if not shutil.which("xrdb") or not shutil.which("xdotool"):
|
||||
print("test_x11_xvfb: xrdb or xdotool not installed (skipping live theme reload test)")
|
||||
return
|
||||
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(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)
|
||||
subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-theme"), "AnodeDefault"], env=env, check=True)
|
||||
|
||||
xvfb = subprocess.Popen(
|
||||
["Xvfb", disp, "-noreset", "-screen", "0", "1280x800x24", "-nolisten", "tcp"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
dpy = None
|
||||
dwm = None
|
||||
st_proc = None
|
||||
pwr_proc = None
|
||||
try:
|
||||
dpy = wait_until(lambda: X11.XOpenDisplay(disp.encode()))
|
||||
assert dpy, f"Failed to open Xvfb {disp}"
|
||||
root = X11.XDefaultRootWindow(dpy)
|
||||
|
||||
subprocess.run(["xrdb", "-load", os.path.join(home, ".Xresources")], env=env, check=True)
|
||||
dwm = subprocess.Popen([os.path.join(BUILD, "dwm", "dwm")], env=env)
|
||||
tray_atom = X11.XInternAtom(dpy, b"_NET_SYSTEM_TRAY_S0", 0)
|
||||
assert wait_until(lambda: X11.XGetSelectionOwner(dpy, tray_atom)), "DWM failed to start on Xvfb"
|
||||
|
||||
st_proc = subprocess.Popen(
|
||||
[os.path.join(BUILD, "st", "st"), "-e", "sh", "-c", "printf '\\033[2J\\033[H'; sleep 30"],
|
||||
env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
pwr_proc = subprocess.Popen(
|
||||
[os.path.join(BUILD, "apps", "anode-power")],
|
||||
env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
|
||||
def find_win_by_class(res_name):
|
||||
for w in query_children(dpy, root):
|
||||
attr = XWindowAttributes()
|
||||
if not X11.XGetWindowAttributes(dpy, w, ctypes.byref(attr)) or attr.map_state != 2:
|
||||
continue
|
||||
ch = XClassHint()
|
||||
if X11.XGetClassHint(dpy, w, ctypes.byref(ch)):
|
||||
name = ctypes.string_at(ch.res_name).decode("utf-8", errors="ignore") if ch.res_name else ""
|
||||
if ch.res_name:
|
||||
X11.XFree(ch.res_name)
|
||||
if ch.res_class:
|
||||
X11.XFree(ch.res_class)
|
||||
if name == res_name:
|
||||
return w, attr
|
||||
return None
|
||||
|
||||
bar_res = wait_until(lambda: find_win_by_class("anode-wm"))
|
||||
st_res = wait_until(lambda: find_win_by_class("st-256color"))
|
||||
pwr_res = wait_until(lambda: find_win_by_class("anode-power"))
|
||||
assert bar_res and st_res and pwr_res, f"Missing windows: bar={bar_res} st={st_res} pwr={pwr_res}"
|
||||
|
||||
def get_win_row_pixels(win, y, width):
|
||||
X11.XSync(dpy, 0)
|
||||
img = X11.XGetImage(dpy, win, 0, y, width, 1, 0xFFFFFFFF, 2)
|
||||
assert img, f"XGetImage failed for win={hex(win)} y={y} w={width}"
|
||||
try:
|
||||
return [int(X11.XGetPixel(img, x, 0)) & 0xFFFFFF for x in range(width)]
|
||||
finally:
|
||||
X11.XDestroyImage(img)
|
||||
|
||||
def get_win_pixel(win, x, y):
|
||||
X11.XSync(dpy, 0)
|
||||
img = X11.XGetImage(dpy, win, x, y, 1, 1, 0xFFFFFFFF, 2)
|
||||
if not img:
|
||||
return None
|
||||
try:
|
||||
return int(X11.XGetPixel(img, 0, 0)) & 0xFFFFFF
|
||||
finally:
|
||||
X11.XDestroyImage(img)
|
||||
|
||||
def check_palette(name, bar_allowed, st_expected, pwr_expected):
|
||||
def ok():
|
||||
bw_res = find_win_by_class("anode-wm")
|
||||
sw_res = find_win_by_class("st-256color")
|
||||
pw_res = find_win_by_class("anode-power")
|
||||
if not (bw_res and sw_res and pw_res):
|
||||
return None
|
||||
bw, battr = bw_res
|
||||
sw, sattr = sw_res
|
||||
pw, pattr = pw_res
|
||||
brow = get_win_row_pixels(bw, 0, battr.width)
|
||||
if not set(brow).issubset(bar_allowed) or len(set(brow)) < 2:
|
||||
return None
|
||||
spx = get_win_pixel(sw, sattr.width - 2, sattr.height - 2)
|
||||
if spx != st_expected:
|
||||
return None
|
||||
ppx = get_win_pixel(pw, 2, pattr.height - 2)
|
||||
if ppx != pwr_expected:
|
||||
return None
|
||||
return (brow, spx, ppx)
|
||||
|
||||
res = wait_until(ok, timeout=6.0)
|
||||
if not res:
|
||||
bw, battr = find_win_by_class("anode-wm")
|
||||
sw, sattr = find_win_by_class("st-256color")
|
||||
pw, pattr = find_win_by_class("anode-power")
|
||||
brow = get_win_row_pixels(bw, 0, battr.width)
|
||||
bad_x = [(x, hex(px)) for x, px in enumerate(brow) if px not in bar_allowed]
|
||||
spx = get_win_pixel(sw, sattr.width - 2, sattr.height - 2)
|
||||
ppx = get_win_pixel(pw, 2, pattr.height - 2)
|
||||
raise AssertionError(
|
||||
f"{name} palette mismatch: bar_unique={[hex(c) for c in set(brow)]} bad_x={bad_x[:10]} "
|
||||
f"st={hex(spx)} (exp {hex(st_expected)}) pwr={hex(ppx)} (exp {hex(pwr_expected)})"
|
||||
)
|
||||
return res
|
||||
|
||||
# Phase 1: Initial AnodeDefault
|
||||
check_palette("AnodeDefault", {0x11161F, 0x2B5278}, 0x0B0E14, 0x0B0E14)
|
||||
|
||||
# Phase 2: Switch to SolarizedLight via anode-apply-theme with ANODE_NO_SIGNAL=1
|
||||
# (must propagate purely via xrdb -load + live XA_RESOURCE_MANAGER lookup!)
|
||||
subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-theme"), "SolarizedLight"], env=env, check=True)
|
||||
check_palette("SolarizedLight", {0xFDF6E3, 0x268BD2}, 0xFDF6E3, 0xFDF6E3)
|
||||
|
||||
# Phase 3: Write Cyberpunk to ~/.Xresources on disk (without running xrdb),
|
||||
# then press Mod4+Shift+r via xdotool and confirm all 3 running windows update cleanly.
|
||||
with open(os.path.join(ROOT, "data", "themes", "Cyberpunk.xth"), encoding="utf-8") as f:
|
||||
cyber_xth = f.read()
|
||||
with open(os.path.join(home, ".Xresources"), "w", encoding="utf-8") as f:
|
||||
f.write(cyber_xth + "\ntheme.scale: 1.00\ntheme.touchMode: 0\n")
|
||||
|
||||
subprocess.run(["xdotool", "keydown", "Super_L"], env=env, check=True)
|
||||
time.sleep(0.05)
|
||||
subprocess.run(["xdotool", "keydown", "Shift_L"], env=env, check=True)
|
||||
time.sleep(0.05)
|
||||
subprocess.run(["xdotool", "key", "r"], env=env, check=True)
|
||||
time.sleep(0.06)
|
||||
subprocess.run(["xdotool", "keyup", "Shift_L"], env=env, check=True)
|
||||
time.sleep(0.05)
|
||||
subprocess.run(["xdotool", "keyup", "Super_L"], env=env, check=True)
|
||||
|
||||
check_palette("Cyberpunk", {0x000000, 0x0066CC}, 0x000000, 0x000000)
|
||||
finally:
|
||||
terminate(pwr_proc)
|
||||
terminate(st_proc)
|
||||
terminate(dwm)
|
||||
if dpy:
|
||||
X11.XCloseDisplay(dpy)
|
||||
terminate(xvfb)
|
||||
|
||||
|
||||
def main():
|
||||
if not shutil.which("Xvfb"):
|
||||
print("test_x11_xvfb: Xvfb not installed (skipping)")
|
||||
@@ -1702,6 +1877,8 @@ def main():
|
||||
print("test_x11_xvfb: Wine/DXVK WM_CHANGE_STATE iconic workspace switch OK")
|
||||
test_systray_xembed_dock_race()
|
||||
print("test_x11_xvfb: systray XEmbed dock/map race OK")
|
||||
test_live_theme_reload_and_bar_artifacts()
|
||||
print("test_x11_xvfb: live theme reload & bar artifact check OK")
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user