fix: sync GTK/Qt themes on session start, follow GTK-3 in Qt, and keep anode-lock above systray
This commit is contained in:
1 parent
0d8b7994bc
commit
c4bee91e6b
11 files changed
+352
-25
No files matched your search
@@ -47,6 +47,7 @@ def test_fractional_scales():
|
||||
env.pop("DISPLAY", None)
|
||||
env["HOME"] = tmp
|
||||
env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config")
|
||||
env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share")
|
||||
env["ANODE_PREFIX"] = ROOT
|
||||
env["ANODE_NO_SIGNAL"] = "1"
|
||||
|
||||
@@ -61,6 +62,7 @@ def test_fractional_scales():
|
||||
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 'export QT_QPA_PLATFORMTHEME="gtk3:qt6ct:qt5ct"' in senv, senv
|
||||
assert f'export XCURSOR_SIZE="{exp_cur}"' in senv, senv
|
||||
|
||||
scale_conf_p = os.path.join(tmp, ".config", "anode", "scale.conf")
|
||||
@@ -92,6 +94,14 @@ def test_fractional_scales():
|
||||
assert 'gtk-font-name="Fira Code 10"' in gtk2, gtk2
|
||||
assert f"gtk-cursor-theme-size={exp_cur}" in gtk2, gtk2
|
||||
|
||||
assert os.path.isfile(os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "index.theme"))
|
||||
assert os.path.islink(os.path.join(tmp, ".local", "share", "themes", "ANODE-AnodeDefault"))
|
||||
with open(os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "gtk-2.0", "gtkrc"), "r", encoding="utf-8") as f:
|
||||
gtk2rc = f.read()
|
||||
assert "GtkButton::inner-border" in gtk2rc, gtk2rc
|
||||
assert "GtkEntry::inner-border" in gtk2rc, gtk2rc
|
||||
assert 'style "anode-menu" = "anode-default"' in gtk2rc, gtk2rc
|
||||
|
||||
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()
|
||||
@@ -151,6 +161,7 @@ def test_all_22_themes_and_legacy_192dpi_import():
|
||||
env.pop("DISPLAY", None)
|
||||
env["HOME"] = tmp
|
||||
env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config")
|
||||
env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share")
|
||||
env["ANODE_PREFIX"] = ROOT
|
||||
env["ANODE_NO_SIGNAL"] = "1"
|
||||
run_env(env, [APPLY_SCALE, "1.00", "--touch=0", "--no-apply"])
|
||||
@@ -193,6 +204,7 @@ def test_st_overrides_and_xresources_local():
|
||||
env.pop("DISPLAY", None)
|
||||
env["HOME"] = tmp
|
||||
env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config")
|
||||
env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share")
|
||||
env["ANODE_PREFIX"] = ROOT
|
||||
env["ANODE_NO_SIGNAL"] = "1"
|
||||
run_env(env, [APPLY_SCALE, "1.50", "--touch=0", "--no-apply"])
|
||||
@@ -244,6 +256,7 @@ def test_auto_scale_honors_explicit_server_dpi():
|
||||
env["DISPLAY"] = ":99"
|
||||
env["HOME"] = tmp
|
||||
env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config")
|
||||
env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share")
|
||||
env["ANODE_PREFIX"] = ROOT
|
||||
env["ANODE_NO_SIGNAL"] = "1"
|
||||
env["PATH"] = fbin + ":" + env.get("PATH", "")
|
||||
@@ -261,6 +274,7 @@ def test_stale_env_does_not_override_scale_conf():
|
||||
env.pop("DISPLAY", None)
|
||||
env["HOME"] = tmp
|
||||
env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config")
|
||||
env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share")
|
||||
env["ANODE_PREFIX"] = ROOT
|
||||
env["ANODE_NO_SIGNAL"] = "1"
|
||||
env["ANODE_NO_DBUS"] = "1"
|
||||
@@ -302,6 +316,7 @@ def test_gtk_theme_light_dark_detection_and_css_parse():
|
||||
env.pop("DISPLAY", None)
|
||||
env["HOME"] = tmp
|
||||
env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config")
|
||||
env["XDG_DATA_HOME"] = os.path.join(tmp, ".local", "share")
|
||||
env["ANODE_PREFIX"] = ROOT
|
||||
env["ANODE_NO_SIGNAL"] = "1"
|
||||
run_env(env, [APPLY_SCALE, "1.25", "--touch=0", "--no-apply"])
|
||||
@@ -321,6 +336,12 @@ def test_gtk_theme_light_dark_detection_and_css_parse():
|
||||
|
||||
run_env(env, [APPLY_THEME, "AnodeDefault"])
|
||||
t3_dark = os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "gtk-3.0", "gtk.css")
|
||||
with open(t3_dark, "r", encoding="utf-8") as f:
|
||||
t3_txt = f.read()
|
||||
assert "menu separator" in t3_txt, t3_txt
|
||||
assert "popover.menu.background > contents" in t3_txt, t3_txt
|
||||
for bad in ("min-height:", "min-width:", "padding:", "margin:", "font-family:"):
|
||||
assert bad not in t3_txt, f"Unexpected {bad} in {t3_dark}"
|
||||
try:
|
||||
import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
@@ -333,8 +354,39 @@ def test_gtk_theme_light_dark_detection_and_css_parse():
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
import sys
|
||||
gtk4_check = (
|
||||
"import sys\n"
|
||||
"try:\n"
|
||||
" import gi; gi.require_version('Gtk', '4.0'); from gi.repository import Gtk\n"
|
||||
"except Exception:\n"
|
||||
" sys.exit(0)\n"
|
||||
"Gtk.init()\n"
|
||||
"for p in sys.argv[1:]:\n"
|
||||
" prov = Gtk.CssProvider()\n"
|
||||
" errs = []\n"
|
||||
" prov.connect('parsing-error', lambda pr, s, e: errs.append(str(e)))\n"
|
||||
" prov.load_from_path(p)\n"
|
||||
" assert not errs, f'GTK4 CSS parse errors in {p}: {errs}'\n"
|
||||
)
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-c",
|
||||
gtk4_check,
|
||||
os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "gtk-4.0", "gtk.css"),
|
||||
os.path.join(tmp, ".themes", "ANODE-AnodeDefault", "gtk-4.0", "gtk-dark.css"),
|
||||
os.path.join(tmp, ".config", "gtk-4.0", "gtk.css"),
|
||||
],
|
||||
env=env,
|
||||
check=True,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open(os.path.join(ROOT, "data", "env.sh"), "r", encoding="utf-8") as f:
|
||||
env_sh = f.read()
|
||||
assert 'QT_QPA_PLATFORMTHEME:=gtk3:qt6ct:qt5ct' in env_sh, env_sh
|
||||
test_fractional_scales()
|
||||
test_all_22_themes_and_legacy_192dpi_import()
|
||||
test_st_overrides_and_xresources_local()
|
||||
|
||||
@@ -504,6 +504,124 @@ def test_st_font_override_and_dunst():
|
||||
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)")
|
||||
@@ -518,6 +636,8 @@ def main():
|
||||
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
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user