fix(wm,tray,replace): fix fullscreen focus, systray XEmbed race, and display-scoped cleanup

This commit is contained in:
Luxferre committed 2026-11-26 19:28:26 +02:00
1 parent be7e3a3155
commit 8da5c5d1cb
4 files changed
+989 -69

No files matched your search

+113
View File
@@ -786,6 +786,118 @@ def test_switch_session_stale_i3sock_fallback():
terminate(xvfb)
def test_replace_display_scoped_daemon_cleanup():
disp = pick_display()
other_disp = ":199"
cc = os.environ.get("CC", "cc")
with tempfile.TemporaryDirectory() as tmp:
env = make_env(tmp, disp)
daemon_dir = os.path.join(tmp, "daemons")
os.makedirs(daemon_dir, exist_ok=True)
sleeper_c = os.path.join(tmp, "sleeper.c")
sleeper_bin = os.path.join(tmp, "sleeper")
with open(sleeper_c, "w", encoding="utf-8") as f:
f.write(
"#include <signal.h>\n"
"#include <unistd.h>\n"
"static void on_term(int s) { (void)s; _exit(0); }\n"
"int main(void) {\n"
" signal(SIGTERM, on_term);\n"
" while (1) pause();\n"
" return 0;\n"
"}\n"
)
subprocess.run([cc, "-O2", sleeper_c, "-o", sleeper_bin], check=True)
statusd_bin = os.path.join(daemon_dir, "anode-statusd")
dunst_bin = os.path.join(daemon_dir, "dunst")
os.link(sleeper_bin, statusd_bin)
os.link(sleeper_bin, dunst_bin)
xvfb = subprocess.Popen(
["Xvfb", disp, "-screen", "0", "1280x720x24", "-nolisten", "tcp"],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
)
dwm1 = None
dpy = None
new_pid = None
procs = []
try:
dpy = wait_until(lambda: X11.XOpenDisplay(disp.encode()), timeout=5.0)
assert dpy
root = X11.XDefaultRootWindow(dpy)
dwm1 = subprocess.Popen([DWM_BIN], env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
wm1 = wait_until(lambda: get_win_prop_ulong(dpy, root, "_NET_SUPPORTING_WM_CHECK"), timeout=5.0)
assert wm1
same_statusd = subprocess.Popen(
[statusd_bin], env=dict(env, DISPLAY=f"{disp}.0"),
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
)
other_statusd = subprocess.Popen(
[statusd_bin], env=dict(env, DISPLAY=other_disp),
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
)
same_dunst = subprocess.Popen(
[dunst_bin], env=dict(env, DISPLAY=disp),
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
)
other_dunst = subprocess.Popen(
[dunst_bin], env=dict(env, DISPLAY=other_disp),
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
)
procs = [same_statusd, other_statusd, same_dunst, other_dunst]
if os.path.isdir(f"/proc/{os.getpid()}"):
expected_comm = [
(same_statusd, "anode-statusd"),
(other_statusd, "anode-statusd"),
(same_dunst, "dunst"),
(other_dunst, "dunst"),
]
def comms_ready():
for p, name in expected_comm:
try:
with open(f"/proc/{p.pid}/comm", "r", encoding="utf-8") as cf:
if cf.read().strip() != name:
return False
except OSError:
return False
return True
assert wait_until(comms_ready, timeout=3.0), "dummy daemons did not finish exec"
else:
time.sleep(0.15)
rep = subprocess.run(
[REPLACE_BIN, "--no-autostart"],
env=env, capture_output=True, text=True,
)
assert rep.returncode == 0, f"anode-replace failed: stdout={rep.stdout} stderr={rep.stderr}"
wm2 = get_win_prop_ulong(dpy, root, "_NET_SUPPORTING_WM_CHECK")
if wm2 and wm2 != wm1:
new_pid = get_win_prop_ulong(dpy, wm2, "_NET_WM_PID")
assert wait_until(lambda: same_statusd.poll() is not None, timeout=4.0), (
f"anode-statusd on {disp}.0 was not stopped by anode-replace"
)
assert wait_until(lambda: same_dunst.poll() is not None, timeout=4.0), (
f"dunst on {disp} was not stopped by anode-replace"
)
time.sleep(0.2)
assert other_statusd.poll() is None, f"anode-statusd on {other_disp} was killed across displays"
assert other_dunst.poll() is None, f"dunst on {other_disp} was killed across displays"
finally:
for p in procs:
terminate(p)
terminate(dwm1)
kill_pid_and_wait(new_pid)
time.sleep(0.15)
if dpy:
X11.XCloseDisplay(dpy)
terminate(xvfb)
def main():
if not shutil.which("Xvfb"):
print("test_replace: Xvfb not installed (skipping)")
@@ -798,6 +910,7 @@ def main():
test_dm_session_leader_guard()
test_switch_session_xprofile_handoff()
test_switch_session_stale_i3sock_fallback()
test_replace_display_scoped_daemon_cleanup()
print("test_replace: OK")
return 0