feat: add XKB layout indicator, live X11 session replace, and ANODE WM/DE identity
This commit is contained in:
1 parent
8d6236a63f
commit
158345c168
12 files changed
+1303
-48
No files matched your search
@@ -55,6 +55,7 @@ def check_scripts() -> None:
|
||||
"scripts/anode-sync-gtk-theme",
|
||||
"scripts/anode-sync-dunst-theme",
|
||||
"scripts/anode-session",
|
||||
"scripts/anode-replace",
|
||||
"scripts/anode-autostart",
|
||||
"scripts/anode-launcher",
|
||||
"data/env.sh",
|
||||
|
||||
Executable
+385
@@ -0,0 +1,385 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Headless Xvfb tests for ANODE live X11 replacement and fastfetch DE/WM identity."""
|
||||
|
||||
import ctypes
|
||||
import ctypes.util
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import signal
|
||||
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")
|
||||
DWM_BIN = os.path.join(BUILD, "dwm", "dwm")
|
||||
REPLACE_BIN = os.path.join(ROOT, "scripts", "anode-replace")
|
||||
|
||||
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),
|
||||
]
|
||||
|
||||
|
||||
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.XDefaultScreen.argtypes = [Display_p]
|
||||
X11.XDefaultScreen.restype = ctypes.c_int
|
||||
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.XFetchName.argtypes = [Display_p, Window, ctypes.POINTER(ctypes.c_char_p)]
|
||||
X11.XFetchName.restype = ctypes.c_int
|
||||
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.XMapWindow.argtypes = [Display_p, Window]
|
||||
X11.XDestroyWindow.argtypes = [Display_p, Window]
|
||||
X11.XGetWindowAttributes.argtypes = [Display_p, Window, ctypes.POINTER(XWindowAttributes)]
|
||||
X11.XGetWindowAttributes.restype = ctypes.c_int
|
||||
X11.XSync.argtypes = [Display_p, 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 ":95"
|
||||
|
||||
|
||||
def wait_until(pred, timeout=6.0, interval=0.05):
|
||||
end = time.monotonic() + timeout
|
||||
while time.monotonic() < end:
|
||||
res = pred()
|
||||
if res:
|
||||
return res
|
||||
time.sleep(interval)
|
||||
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 get_win_prop_ulong(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, 1, 0, 0,
|
||||
ctypes.byref(da), ctypes.byref(di), ctypes.byref(n), ctypes.byref(dl), ctypes.byref(prop),
|
||||
)
|
||||
val = None
|
||||
if rc == 0 and prop and di.value == 32 and n.value >= 1:
|
||||
val = int(ctypes.cast(prop, ctypes.POINTER(ctypes.c_ulong))[0])
|
||||
if prop:
|
||||
X11.XFree(prop)
|
||||
return val
|
||||
|
||||
|
||||
def get_win_prop_str(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, 256, 0, 0,
|
||||
ctypes.byref(da), ctypes.byref(di), ctypes.byref(n), ctypes.byref(dl), ctypes.byref(prop),
|
||||
)
|
||||
out = None
|
||||
if rc == 0 and prop and di.value == 8 and n.value > 0:
|
||||
out = bytes(prop[i] for i in range(n.value)).decode("utf-8", errors="ignore").rstrip("\x00")
|
||||
if prop:
|
||||
X11.XFree(prop)
|
||||
return out
|
||||
|
||||
|
||||
def make_env(tmp, disp):
|
||||
home = os.path.join(tmp, "home")
|
||||
xdg_home = os.path.join(home, ".config")
|
||||
# Provide an isolated bin dir with anode binaries but without long-lived daemons interfering
|
||||
bin_dir = os.path.join(tmp, "bin")
|
||||
os.makedirs(xdg_home, exist_ok=True)
|
||||
os.makedirs(bin_dir, exist_ok=True)
|
||||
os.symlink(DWM_BIN, os.path.join(bin_dir, "dwm"))
|
||||
os.symlink(os.path.join(ROOT, "scripts", "anode-session"), os.path.join(bin_dir, "anode-session"))
|
||||
os.symlink(os.path.join(ROOT, "scripts", "anode-replace"), os.path.join(bin_dir, "anode-replace"))
|
||||
os.symlink(os.path.join(ROOT, "scripts", "anode-apply-scale"), os.path.join(bin_dir, "anode-apply-scale"))
|
||||
os.symlink(os.path.join(ROOT, "scripts", "anode-apply-theme"), os.path.join(bin_dir, "anode-apply-theme"))
|
||||
|
||||
env = dict(os.environ)
|
||||
env["DISPLAY"] = disp
|
||||
env["HOME"] = home
|
||||
env["XDG_CONFIG_HOME"] = xdg_home
|
||||
env["ANODE_PREFIX"] = ROOT
|
||||
env["ANODE_NO_SIGNAL"] = "1"
|
||||
env["ANODE_NO_DBUS"] = "1"
|
||||
env["PATH"] = bin_dir + ":" + env.get("PATH", "/usr/bin:/bin")
|
||||
for k in (
|
||||
"WAYLAND_DISPLAY", "SWAYSOCK", "HYPRLAND_INSTANCE_SIGNATURE", "I3SOCK",
|
||||
"KDE_FULL_SESSION", "GNOME_DESKTOP_SESSION_ID",
|
||||
):
|
||||
env.pop(k, None)
|
||||
return env
|
||||
|
||||
|
||||
def kill_pid_and_wait(pid):
|
||||
if not pid or pid <= 1:
|
||||
return
|
||||
try:
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
except ProcessLookupError:
|
||||
return
|
||||
for _ in range(30):
|
||||
try:
|
||||
os.kill(pid, 0)
|
||||
time.sleep(0.05)
|
||||
except ProcessLookupError:
|
||||
return
|
||||
try:
|
||||
os.kill(pid, signal.SIGKILL)
|
||||
except ProcessLookupError:
|
||||
pass
|
||||
|
||||
|
||||
def test_fastfetch_identity():
|
||||
disp = pick_display()
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
env = make_env(tmp, disp)
|
||||
env["XDG_CURRENT_DESKTOP"] = "ANODE"
|
||||
env["XDG_SESSION_DESKTOP"] = "anode"
|
||||
env["DESKTOP_SESSION"] = "anode"
|
||||
|
||||
xvfb = subprocess.Popen(
|
||||
["Xvfb", disp, "-screen", "0", "1280x720x24", "-nolisten", "tcp"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
dwm = None
|
||||
dpy = None
|
||||
try:
|
||||
dpy = wait_until(lambda: X11.XOpenDisplay(disp.encode()), timeout=5.0)
|
||||
assert dpy, f"Xvfb failed on {disp}"
|
||||
root = X11.XDefaultRootWindow(dpy)
|
||||
scr = X11.XDefaultScreen(dpy)
|
||||
wm_sel = X11.XInternAtom(dpy, f"WM_S{scr}".encode(), 0)
|
||||
|
||||
dwm = subprocess.Popen([DWM_BIN], env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
wmcheck = wait_until(lambda: get_win_prop_ulong(dpy, root, "_NET_SUPPORTING_WM_CHECK"), timeout=5.0)
|
||||
assert wmcheck, "dwm did not publish _NET_SUPPORTING_WM_CHECK"
|
||||
assert get_win_prop_str(dpy, wmcheck, "_NET_WM_NAME") == "ANODE WM"
|
||||
assert get_win_prop_ulong(dpy, wmcheck, "_NET_WM_PID") == dwm.pid
|
||||
assert X11.XGetSelectionOwner(dpy, wm_sel) == wmcheck
|
||||
|
||||
nm = ctypes.c_char_p()
|
||||
assert X11.XFetchName(dpy, wmcheck, ctypes.byref(nm)) and nm.value == b"ANODE WM"
|
||||
X11.XFree(nm)
|
||||
|
||||
if shutil.which("fastfetch"):
|
||||
r = subprocess.run(
|
||||
["fastfetch", "--format", "json", "--structure", "DE:WM"],
|
||||
env=env, capture_output=True, text=True, check=True,
|
||||
)
|
||||
data = json.loads(r.stdout)
|
||||
mods = {item["type"]: item.get("result", {}) for item in data}
|
||||
assert mods.get("DE", {}).get("prettyName") == "ANODE", f"unexpected DE: {data}"
|
||||
assert mods.get("WM", {}).get("prettyName") == "ANODE WM", f"unexpected WM: {data}"
|
||||
finally:
|
||||
terminate(dwm)
|
||||
if dpy:
|
||||
X11.XCloseDisplay(dpy)
|
||||
terminate(xvfb)
|
||||
|
||||
|
||||
def test_icccm_replace_and_client_preservation():
|
||||
disp = pick_display()
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
env = make_env(tmp, disp)
|
||||
env["XDG_CURRENT_DESKTOP"] = "XFCE"
|
||||
env["KDE_FULL_SESSION"] = "true"
|
||||
|
||||
xvfb = subprocess.Popen(
|
||||
["Xvfb", disp, "-screen", "0", "1280x720x24", "-nolisten", "tcp"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
dwm1 = None
|
||||
dpy = None
|
||||
new_pid = None
|
||||
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
|
||||
|
||||
client = X11.XCreateSimpleWindow(dpy, root, 40, 40, 300, 200, 0, 0, 0xffffff)
|
||||
X11.XMapWindow(dpy, client)
|
||||
X11.XSync(dpy, 0)
|
||||
|
||||
dry = subprocess.run([REPLACE_BIN, "--dry-run"], env=env, capture_output=True, text=True)
|
||||
assert dry.returncode == 0, dry.stderr
|
||||
assert "ANODE WM" in dry.stdout
|
||||
|
||||
rep = subprocess.run(
|
||||
[REPLACE_BIN, "--no-autostart", "--keep-panels"],
|
||||
env=env, capture_output=True, text=True,
|
||||
)
|
||||
assert rep.returncode == 0, f"anode-replace failed: stdout={rep.stdout} stderr={rep.stderr}"
|
||||
assert "DE: ANODE, WM: ANODE WM" in rep.stdout
|
||||
|
||||
# Original dwm must exit cleanly via SelectionClear
|
||||
assert wait_until(lambda: dwm1.poll() is not None, timeout=5.0), "old dwm did not exit on SelectionClear"
|
||||
assert dwm1.returncode == 0, f"old dwm exited non-zero: {dwm1.returncode}"
|
||||
|
||||
wm2 = get_win_prop_ulong(dpy, root, "_NET_SUPPORTING_WM_CHECK")
|
||||
assert wm2 and wm2 != wm1, f"expected new _NET_SUPPORTING_WM_CHECK window (wm1={wm1}, wm2={wm2})"
|
||||
assert get_win_prop_str(dpy, wm2, "_NET_WM_NAME") == "ANODE WM"
|
||||
new_pid = get_win_prop_ulong(dpy, wm2, "_NET_WM_PID")
|
||||
assert new_pid and new_pid != dwm1.pid
|
||||
|
||||
# Mapped client window must survive replacement
|
||||
attr = XWindowAttributes()
|
||||
assert X11.XGetWindowAttributes(dpy, client, ctypes.byref(attr)) != 0
|
||||
X11.XDestroyWindow(dpy, client)
|
||||
finally:
|
||||
terminate(dwm1)
|
||||
kill_pid_and_wait(new_pid)
|
||||
if dpy:
|
||||
X11.XCloseDisplay(dpy)
|
||||
terminate(xvfb)
|
||||
|
||||
|
||||
def test_non_icccm_wm_fallback_replace():
|
||||
disp = pick_display()
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
env = make_env(tmp, disp)
|
||||
xvfb = subprocess.Popen(
|
||||
["Xvfb", disp, "-screen", "0", "1280x720x24", "-nolisten", "tcp"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
mock_wm = None
|
||||
dpy = None
|
||||
new_pid = None
|
||||
mock_code = (
|
||||
"import ctypes, ctypes.util, os, signal, time\n"
|
||||
"X11 = ctypes.CDLL(ctypes.util.find_library('X11') or 'libX11.so.6')\n"
|
||||
"X11.XOpenDisplay.restype = ctypes.c_void_p\n"
|
||||
"X11.XDefaultRootWindow.argtypes = [ctypes.c_void_p]\n"
|
||||
"X11.XDefaultRootWindow.restype = ctypes.c_ulong\n"
|
||||
"X11.XSelectInput.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_long]\n"
|
||||
"X11.XCreateSimpleWindow.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_int, ctypes.c_int, ctypes.c_uint, ctypes.c_uint, ctypes.c_uint, ctypes.c_ulong, ctypes.c_ulong]\n"
|
||||
"X11.XCreateSimpleWindow.restype = ctypes.c_ulong\n"
|
||||
"X11.XInternAtom.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int]\n"
|
||||
"X11.XInternAtom.restype = ctypes.c_ulong\n"
|
||||
"X11.XChangeProperty.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_int, ctypes.c_int, ctypes.c_void_p, ctypes.c_int]\n"
|
||||
"X11.XSync.argtypes = [ctypes.c_void_p, ctypes.c_int]\n"
|
||||
"dpy = X11.XOpenDisplay(None)\n"
|
||||
"root = X11.XDefaultRootWindow(dpy)\n"
|
||||
"X11.XSelectInput(dpy, root, 1 << 20)\n"
|
||||
"w = X11.XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0)\n"
|
||||
"a_chk = X11.XInternAtom(dpy, b'_NET_SUPPORTING_WM_CHECK', 0)\n"
|
||||
"a_nm = X11.XInternAtom(dpy, b'_NET_WM_NAME', 0)\n"
|
||||
"a_pid = X11.XInternAtom(dpy, b'_NET_WM_PID', 0)\n"
|
||||
"a_utf = X11.XInternAtom(dpy, b'UTF8_STRING', 0)\n"
|
||||
"a_win = X11.XInternAtom(dpy, b'WINDOW', 0)\n"
|
||||
"a_card = X11.XInternAtom(dpy, b'CARDINAL', 0)\n"
|
||||
"wv = ctypes.c_ulong(w)\n"
|
||||
"pv = ctypes.c_ulong(os.getpid())\n"
|
||||
"X11.XChangeProperty(dpy, w, a_chk, a_win, 32, 0, ctypes.byref(wv), 1)\n"
|
||||
"X11.XChangeProperty(dpy, w, a_nm, a_utf, 8, 0, b'LegacyWM', 8)\n"
|
||||
"X11.XChangeProperty(dpy, w, a_pid, a_card, 32, 0, ctypes.byref(pv), 1)\n"
|
||||
"X11.XChangeProperty(dpy, root, a_chk, a_win, 32, 0, ctypes.byref(wv), 1)\n"
|
||||
"X11.XSync(dpy, 0)\n"
|
||||
"signal.signal(signal.SIGTERM, lambda s, f: os._exit(0))\n"
|
||||
"while True: time.sleep(0.2)\n"
|
||||
)
|
||||
try:
|
||||
dpy = wait_until(lambda: X11.XOpenDisplay(disp.encode()), timeout=5.0)
|
||||
assert dpy
|
||||
root = X11.XDefaultRootWindow(dpy)
|
||||
|
||||
mock_wm = subprocess.Popen([sys.executable, "-c", mock_code], env=env)
|
||||
wm1 = wait_until(lambda: get_win_prop_ulong(dpy, root, "_NET_SUPPORTING_WM_CHECK"), timeout=5.0)
|
||||
assert wm1
|
||||
assert get_win_prop_str(dpy, wm1, "_NET_WM_NAME") == "LegacyWM"
|
||||
|
||||
rep = subprocess.run(
|
||||
[REPLACE_BIN, "--no-autostart", "--keep-panels"],
|
||||
env=env, capture_output=True, text=True,
|
||||
)
|
||||
assert rep.returncode == 0, f"fallback replace failed: stdout={rep.stdout} stderr={rep.stderr}"
|
||||
assert wait_until(lambda: mock_wm.poll() is not None, timeout=3.0), "legacy WM was not stopped"
|
||||
|
||||
wm2 = get_win_prop_ulong(dpy, root, "_NET_SUPPORTING_WM_CHECK")
|
||||
assert wm2 and wm2 != wm1
|
||||
assert get_win_prop_str(dpy, wm2, "_NET_WM_NAME") == "ANODE WM"
|
||||
new_pid = get_win_prop_ulong(dpy, wm2, "_NET_WM_PID")
|
||||
finally:
|
||||
terminate(mock_wm)
|
||||
kill_pid_and_wait(new_pid)
|
||||
if dpy:
|
||||
X11.XCloseDisplay(dpy)
|
||||
terminate(xvfb)
|
||||
|
||||
|
||||
def main():
|
||||
if not shutil.which("Xvfb"):
|
||||
print("test_replace: Xvfb not installed (skipping)")
|
||||
return 0
|
||||
assert os.path.isfile(DWM_BIN), f"missing {DWM_BIN}"
|
||||
test_fastfetch_identity()
|
||||
test_icccm_replace_and_client_preservation()
|
||||
test_non_icccm_wm_fallback_replace()
|
||||
print("test_replace: OK")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "anode_wifi_list.h"
|
||||
#include "anode_bt_list.h"
|
||||
#include "anode_power_policy.h"
|
||||
#include "anode_xkb_parse.h"
|
||||
#include "anode-touch-gesture.h"
|
||||
|
||||
static void test_scale_math(void) {
|
||||
@@ -180,6 +181,50 @@ static void test_power_policy_and_gestures(void) {
|
||||
assert(anode_touch_finish(&tr, 1750, 500, 3200, 1920, 1080, 1.0) == ANODE_GEST_CONTROL);
|
||||
}
|
||||
|
||||
static void test_xkb_layout_parser(void) {
|
||||
char buf[16];
|
||||
|
||||
assert(anode_xkb_layout_from_symbols("pc+us+inet(evdev)", 0, buf, sizeof(buf)));
|
||||
assert(strcmp(buf, "us") == 0);
|
||||
|
||||
const char *multi = "pc+us+de(nodeadkeys):2+ru(phonetic):3+inet(evdev)+group(alt_shift_toggle)";
|
||||
assert(anode_xkb_layout_from_symbols(multi, 0, buf, sizeof(buf)));
|
||||
assert(strcmp(buf, "us") == 0);
|
||||
assert(anode_xkb_layout_from_symbols(multi, 1, buf, sizeof(buf)));
|
||||
assert(strcmp(buf, "de") == 0);
|
||||
assert(anode_xkb_layout_from_symbols(multi, 2, buf, sizeof(buf)));
|
||||
assert(strcmp(buf, "ru") == 0);
|
||||
assert(!anode_xkb_layout_from_symbols(multi, 3, buf, sizeof(buf)));
|
||||
|
||||
assert(anode_xkb_layout_from_symbols("pc+US(intl)+FR(oss):2+inet(evdev)", 0, buf, sizeof(buf)));
|
||||
assert(strcmp(buf, "us") == 0);
|
||||
assert(anode_xkb_layout_from_symbols("pc+US(intl)+FR(oss):2+inet(evdev)", 1, buf, sizeof(buf)));
|
||||
assert(strcmp(buf, "fr") == 0);
|
||||
|
||||
assert(anode_xkb_layout_from_symbols("pc+nec_vndr/jp+sun_vndr/us:2+inet(evdev)", 0, buf, sizeof(buf)));
|
||||
assert(strcmp(buf, "jp") == 0);
|
||||
assert(anode_xkb_layout_from_symbols("pc+nec_vndr/jp+sun_vndr/us:2+inet(evdev)", 1, buf, sizeof(buf)));
|
||||
assert(strcmp(buf, "us") == 0);
|
||||
|
||||
assert(anode_xkb_layout_from_symbols("pc+eurosign(e):2+ua:2+inet(evdev)", 1, buf, sizeof(buf)));
|
||||
assert(strcmp(buf, "ua") == 0);
|
||||
|
||||
static const unsigned char rules_prop[] = "evdev\0pc105\0US,de,UA\0,nodeadkeys,\0grp:alt_shift_toggle\0";
|
||||
assert(anode_xkb_layout_from_rules_prop(rules_prop, sizeof(rules_prop), 0, buf, sizeof(buf)));
|
||||
assert(strcmp(buf, "us") == 0);
|
||||
assert(anode_xkb_layout_from_rules_prop(rules_prop, sizeof(rules_prop), 1, buf, sizeof(buf)));
|
||||
assert(strcmp(buf, "de") == 0);
|
||||
assert(anode_xkb_layout_from_rules_prop(rules_prop, sizeof(rules_prop), 2, buf, sizeof(buf)));
|
||||
assert(strcmp(buf, "ua") == 0);
|
||||
assert(!anode_xkb_layout_from_rules_prop(rules_prop, sizeof(rules_prop), 3, buf, sizeof(buf)));
|
||||
|
||||
assert(anode_xkb_layout_from_group_name("English (US)", buf, sizeof(buf)));
|
||||
assert(strcmp(buf, "en") == 0);
|
||||
assert(anode_xkb_layout_from_group_name("Russian", buf, sizeof(buf)));
|
||||
assert(strcmp(buf, "ru") == 0);
|
||||
assert(!anode_xkb_layout_from_group_name("!!!", buf, sizeof(buf)));
|
||||
}
|
||||
|
||||
static void test_platform_probe(void) {
|
||||
anode_net_iface_t ifs[ANODE_MAX_IFACES];
|
||||
int n = anode_list_net_ifaces(ifs, ANODE_MAX_IFACES);
|
||||
@@ -201,6 +246,7 @@ int main(void) {
|
||||
test_audio_parsers();
|
||||
test_wifi_and_bt_parsers();
|
||||
test_power_policy_and_gestures();
|
||||
test_xkb_layout_parser();
|
||||
test_platform_probe();
|
||||
printf("test_units: ALL PASSED\n");
|
||||
return 0;
|
||||
|
||||
+38
-3
@@ -4,6 +4,7 @@
|
||||
import ctypes
|
||||
import ctypes.util
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import signal
|
||||
import socket
|
||||
@@ -101,6 +102,8 @@ 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():
|
||||
@@ -270,10 +273,11 @@ 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
|
||||
# Test anode-statusd updates root WM_NAME and tracks XKB layout left of datetime
|
||||
sd = subprocess.Popen([os.path.join(BUILD, "daemons", "anode-statusd")], env=env)
|
||||
procs.append(sd)
|
||||
def has_status():
|
||||
|
||||
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")
|
||||
@@ -281,7 +285,38 @@ def test_resolution(res_str, scale_str, width, height):
|
||||
if "|" in s:
|
||||
return s
|
||||
return None
|
||||
assert wait_until(has_status), "anode-statusd did not publish status to root WM_NAME"
|
||||
|
||||
def get_kbd_left_of_dt():
|
||||
s = get_status()
|
||||
if not s:
|
||||
return None
|
||||
parts = [p.strip() for p in s.split("|")]
|
||||
if len(parts) < 4:
|
||||
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 core + GemUI utilities launch, map cleanly inside screen, and exit cleanly
|
||||
|
||||
Reference in new issue
Block a user