Skip to content

LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.

Test Bench (lordos-testbench, phase 1): a Wayland client with the test card ported from go-link-console, frame and presentation timing, the full keyboard with keysyms, modifiers and repeat, the pointer and wheel, and the compositor's globals; --auto prints JSON. Monitor → Network: ICMP ping sockets from /proc/net/icmp{,6}, and the remote desktop bridge's UDP ports given to Remote Desktop by its cgroup instead of '?'

Federico Pereirab3c4481a7a5d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8c165d2..bdf0b7c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,11 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),
configured or actually tried. **Run tests** starts a test app that tries, inside the same sandbox as
any isolated app, what it must not be able to do (your files, sockets, ptrace, leaving its scope,
exec), plus the decoders' sandbox and the requests the system must refuse.
+- **Test Bench** (`lordos-testbench`): a test pattern window that checks the display server from the
+ outside: frame timing and when frames really reach the screen, every key of the keyboard, the
+ mouse and wheel, and the Wayland protocols the system offers.
+- **Monitor → Network shows ping (ICMP) sockets**, under the app that opened them, and the remote
+ desktop's own UDP ports under Remote Desktop instead of an unknown "?".
- **`lordos-sysreport report`** prints the hardware of this computer and what the system made of it,
as Markdown or `--json`, with no serial numbers, addresses or names: the base of System
Information.
diff --git a/apps/monitor/Network.jsx b/apps/monitor/Network.jsx
index 0f499d5..217656f 100644
--- a/apps/monitor/Network.jsx
+++ b/apps/monitor/Network.jsx
@@ -97,7 +97,7 @@ function useGroups(conns) {
if (!g) {
const comp = !!COMPONENTS[key] || key === 'lordos';
g = { key, item: comp ? { app: key } : c, name: comp || (c.self && !c.cgApp) ? null : c.appName || c.name || '?', exe: c.exe, pids: new Set(), conns: [], hosts: new Map(),
- sent: 0, recv: 0, rateTx: 0, rateRx: 0, listen: [], incoming: 0, verdict: 'allow', programs: new Set() };
+ sent: 0, recv: 0, rateTx: 0, rateRx: 0, listen: [], icmp: [], incoming: 0, verdict: 'allow', programs: new Set() };
apps.set(key, g);
}
if (c.name && c.cgApp && !c.self) g.programs.add(c.name);
@@ -113,6 +113,7 @@ function useGroups(conns) {
g.rateTx += rtx;
g.rateRx += rrx;
if (c.dir === 'listen') { g.listen.push(c); continue; }
+ if (c.dir === 'icmp') { g.icmp.push(c); continue; } // a ping socket: the kernel keeps no destination
if (c.dir === 'in') g.incoming++;
rememberGeo(c);
const h = g.hosts.get(c.remote) || { remote: c.remote, cc: c.cc, scope: c.scope, ports: new Set(), sent: 0, recv: 0, rateTx: 0, rateRx: 0, count: 0 };
@@ -287,7 +288,8 @@ function AppRow({ g, node, ctx, open, selected, onToggle, onSelect, maxBytes, tr
</View>
{open && node ? <TreeChildren node={node} ctx={ctx} /> : null}
{open && !kids ? <Text style={{ fontSize: 11, color: t.textDim, height: 22, ...(direction() === 'rtl' ? { paddingRight: 40 } : { paddingLeft: 40 }) }}>
- {g.listen.length ? tr('monitor.net.onlyListening', { ports: g.listen.map((c) => c.lport).join(', ') }) : tr('monitor.net.noDestinations')}</Text> : null}
+ {[g.listen.length ? tr('monitor.net.onlyListening', { ports: g.listen.map((c) => c.lport).join(', ') }) : '',
+ g.icmp?.length ? tr('monitor.net.icmpSockets', { count: g.icmp.length }) : ''].filter(Boolean).join(' · ') || tr('monitor.net.noDestinations')}</Text> : null}
</View>
);
}
@@ -779,7 +781,11 @@ export function NetworkTab({ last, prefs }) {
const rd = useRemoteDesktop();
const rdg = remoteGroup(rd, tr);
const vpn = useVpnGroup(tr);
- const apps = [...fwApps, ...(rdg ? [rdg] : []), ...(vpn ? [vpn] : [])].sort((a, b) => b.sent + b.recv - (a.sent + a.recv) || b.conns.length - a.conns.length);
+ // the bridge's own sockets (its WebRTC UDP ports, found by its cgroup in conn.c) join that row
+ const bridge = fwApps.find((g) => g.key === REMOTE_KEY);
+ if (bridge && rdg) { rdg.listen = [...rdg.listen, ...bridge.listen]; rdg.conns = [...rdg.conns, ...bridge.conns]; }
+ else if (bridge) bridge.name = tr('monitor.net.remoteDesktop');
+ const apps = [...fwApps.filter((g) => !(rdg && g.key === REMOTE_KEY)), ...(rdg ? [rdg] : []), ...(vpn ? [vpn] : [])].sort((a, b) => b.sent + b.recv - (a.sent + a.recv) || b.conns.length - a.conns.length);
const [view, setView, mprefs, setPrefs] = useNetView();
const [chips, setChips] = useState([]);
const [text, setText] = useState('');
diff --git a/assets/locales/en/monitor.json b/assets/locales/en/monitor.json
index 5f967b9..0bb53b3 100644
--- a/assets/locales/en/monitor.json
+++ b/assets/locales/en/monitor.json
@@ -405,5 +405,9 @@
"status.mode": "Firewall",
"status.lists": "Blocklists",
"status.listsValue": "{lists} on · {entries} entries",
- "status.open": "Open Monitor…"
+ "status.open": "Open Monitor…",
+ "net.icmpSockets": {
+ "one": "{count} ICMP (ping) socket: the system doesn't keep its destination",
+ "other": "{count} ICMP (ping) sockets: the system doesn't keep their destination"
+ }
}
diff --git a/assets/locales/es/monitor.json b/assets/locales/es/monitor.json
index ce65fb1..b5ba311 100644
--- a/assets/locales/es/monitor.json
+++ b/assets/locales/es/monitor.json
@@ -405,5 +405,9 @@
"status.mode": "Cortafuegos",
"status.lists": "Listas de bloqueo",
"status.listsValue": "{lists} activas · {entries} entradas",
- "status.open": "Abrir el Monitor…"
+ "status.open": "Abrir el Monitor…",
+ "net.icmpSockets": {
+ "one": "{count} socket ICMP (ping): el sistema no guarda su destino",
+ "other": "{count} sockets ICMP (ping): el sistema no guarda su destino"
+ }
}
diff --git a/assets/locales/pt/monitor.json b/assets/locales/pt/monitor.json
index 3c3c6ac..ea2436e 100644
--- a/assets/locales/pt/monitor.json
+++ b/assets/locales/pt/monitor.json
@@ -405,5 +405,9 @@
"status.mode": "Firewall",
"status.lists": "Listas de bloqueio",
"status.listsValue": "{lists} ativas · {entries} entradas",
- "status.open": "Abrir o Monitor…"
+ "status.open": "Abrir o Monitor…",
+ "net.icmpSockets": {
+ "one": "{count} socket ICMP (ping): o sistema não guarda o destino",
+ "other": "{count} sockets ICMP (ping): o sistema não guarda o destino"
+ }
}
diff --git a/docs/MONITOR.md b/docs/MONITOR.md
index 6f7213d..3fbdf18 100644
--- a/docs/MONITOR.md
+++ b/docs/MONITOR.md
@@ -44,7 +44,13 @@ the rest of the tab, and the first generation of the list.
**each one's own allow/block switch** (see "Per-destination switches"); a click on a row selects
it in the right panel. Since 0.8.3 the app's name gets the row's whole width and wraps to two
lines (the connection count and the denied badge sit next to the traffic bar; the column is
- 336 px and the Data and Rule columns are narrower). At the bottom, the machine's traffic:
+ 336 px and the Data and Rule columns are narrower). Since 0.8.5 the list has three protocols: TCP and
+ UDP from `sock_diag`, and ICMP "ping" sockets from `/proc/net/icmp` and `icmp6` (`conn.c`,
+ `icmp_read`), shown on their app's row as "ICMP (ping)" without a destination (the kernel keeps none
+ for an unconnected ping socket). The remote desktop's bridge runs as the user but isn't dumpable, so
+ its sockets can't be traced to a pid; `conn.c` gives the sockets in `lordos.service`'s root-owned
+ `supervisor` group to Remote Desktop (its WebRTC UDP ports), instead of an unknown "?". At the bottom,
+ the machine's traffic:
- the current download and upload speed;
- two pills with what was sent (↑, orange) and received (↓, green) in the visible minute;
- a **mirrored chart** of the last 60 s (`TrafficChart.jsx`, `drawMirror` in `draw.js`): one bar
diff --git a/docs/PAPER-VALIDATION.md b/docs/PAPER-VALIDATION.md
index 47924e2..096dd17 100644
--- a/docs/PAPER-VALIDATION.md
+++ b/docs/PAPER-VALIDATION.md
@@ -134,7 +134,25 @@ what was measured once, what is not tested, and what the paper must correct. Upd
| Every key, the mouse, touchpads, gamepads, and the Wayland protocols | §3.3–§3.4 | The visual test bench below |
| Real hardware | §10.2 | Reports from System Information (0.8.7) |
-## Proposal: the visual test bench (`lordos-testbench`)
+## The visual test bench (`lordos-testbench`)
+
+**Phase 1 built (2026-10-26):** `server/src/testbench/` (`make -C server build/lordos-testbench`), packaged as
+`/usr/bin/lordos-testbench` with `packaging/desktop/lordos-testbench.desktop` (Test Bench in the launcher).
+The test card is ported from go-link-console's `pkg/testpattern` (same author). It shows the card with a
+live clock and a marker that moves one step per frame, frames a second and frame times, `wp_presentation`
+feedback (shown, discarded, refresh, skipped vblanks, zero-copy), the pointer (exact crosshair, eight
+buttons, wheel in steps and 120ths, axis source), the keyboard (a full ISO/ANSI layout with keypad and
+navigation keys lit while down and marked once seen, codes of keys not drawn, keysym and text from the
+compositor's keymap, modifiers and layout, repeat rate and delay) and every global with its version.
+`--auto [seconds]` prints the same as JSON. On VM 116 (headless session, CPU path) it found that
+`wp_presentation` reports every frame as discarded and no refresh rate when the session has no monitor.
+
+![Test Bench on VM 116](testbench.png)
+
+**Still to build** (from the plan below): the scripted protocol checklist, 3D with EGL and dmabuf,
+generated video at 24/30/60 fps, gamepads, and attaching its report to System Information.
+
+### The plan
LordOS writes its own compositor, so it needs its own tool to show, on any computer, that what it draws
and what it receives are right. The idea is a test-pattern window like a TV test card (and like the test
diff --git a/docs/VM-SETUP.md b/docs/VM-SETUP.md
index ffda72e..4f22240 100644
--- a/docs/VM-SETUP.md
+++ b/docs/VM-SETUP.md
@@ -1665,3 +1665,7 @@ over `/usr/local/lib/lordos`.
its own `HOME`, `XDG_RUNTIME_DIR` and `dbus-run-session`, removed afterwards), driven and captured
over its own `remote.sock` (keys, clicks and the still frame's lossless tiles); the user's session
was not touched.
+- **Installed build (with the user's go-ahead):** `/usr/local/lib/lordos` replaced by the 0.8.5 test build
+ (backup of the previous one in `/usr/local/lib/lordos.1026.bak`), `lordos.service` restarted;
+ `lordos-sysreport`, `lordos-fetch` and `lordos-testbench` in `/usr/local/bin`, and
+ `/usr/share/applications/lordos-testbench.desktop`.
diff --git a/docs/testbench.png b/docs/testbench.png
new file mode 100644
index 0000000..f3b7e0e
Binary files /dev/null and b/docs/testbench.png differ
diff --git a/packaging/desktop/lordos-testbench.desktop b/packaging/desktop/lordos-testbench.desktop
new file mode 100644
index 0000000..6e0f0c0
--- /dev/null
+++ b/packaging/desktop/lordos-testbench.desktop
@@ -0,0 +1,12 @@
+[Desktop Entry]
+Type=Application
+Name=Test Bench
+Name[es]=Banco de pruebas
+Name[pt]=Banco de testes
+Comment=Test pattern, frame timing, every key, the pointer and the Wayland protocols
+Comment[es]=Carta de ajuste, tiempos de cuadro, cada tecla, el puntero y los protocolos Wayland
+Comment[pt]=Padrão de teste, tempos de quadro, cada tecla, o ponteiro e os protocolos Wayland
+Exec=/usr/bin/lordos-testbench
+Icon=utilities-system-monitor
+Terminal=false
+Categories=System;Monitor;
diff --git a/server/mk/testbench.mk b/server/mk/testbench.mk
new file mode 100644
index 0000000..12e3fce
--- /dev/null
+++ b/server/mk/testbench.mk
@@ -0,0 +1,8 @@
+# lordos-testbench (src/testbench, docs/PAPER-VALIDATION.md): the visual test bench, a plain Wayland
+# client (test card, frame and presentation timing, every key, the pointer, the compositor's globals).
+# libwayland-client and libxkbcommon only; it reads no files.
+TESTBENCH_SRC := src/testbench/testbench.c src/testbench/card.c src/testbench/draw.c
+all: build/lordos-testbench
+build/lordos-testbench: $(TESTBENCH_SRC) $(wildcard src/testbench/*.h) $(CLIENT_GEN)
+ @mkdir -p build
+ $(CC) $(CPPFLAGS) $(CFLAGS) -Ibuild/gen $(WARN) -std=c11 -o $@ $(TESTBENCH_SRC) $(filter %.c,$(CLIENT_GEN)) -lwayland-client -lxkbcommon -lm
diff --git a/server/src/monitor/conn.c b/server/src/monitor/conn.c
index d10b5d1..32fd068 100644
--- a/server/src/monitor/conn.c
+++ b/server/src/monitor/conn.c
@@ -112,6 +112,50 @@ static int dump(int fd, int fam, int proto) {
}
}
+/* ICMP "ping" sockets (ping(8) without privileges): sock_diag has no dump for them, the kernel lists
+ * them in /proc/net/icmp and icmp6 (with uid and inode, like every socket of the network namespace).
+ * An unconnected ping socket has no destination: only its echo identifier, kept as the local port. */
+static void hex_addr(const char *h, int fam, uint8_t out[16]) {
+ memset(out, 0, 16);
+ int words = fam == 4 ? 1 : 4;
+ for (int w = 0; w < words; w++) {
+ unsigned long v = 0;
+ for (int k = 0; k < 8; k++) {
+ char c = h[w * 8 + k];
+ int d = c >= '0' && c <= '9' ? c - '0' : c >= 'A' && c <= 'F' ? c - 'A' + 10 : c >= 'a' && c <= 'f' ? c - 'a' + 10 : -1;
+ if (d < 0) return;
+ v = v << 4 | (unsigned long)d;
+ }
+ for (int k = 0; k < 4; k++) out[w * 4 + k] = (uint8_t)(v >> (8 * k)); /* each word in host (little-endian) order */
+ }
+}
+
+static void icmp_read(const char *path, int fam) {
+ FILE *f = fopen(path, "re");
+ if (!f) return;
+ char line[512], la[64], ra[64];
+ unsigned st, uid;
+ unsigned long inode;
+ if (!fgets(line, sizeof line, f)) { fclose(f); return; } /* the header */
+ while (nsock < MAX_SOCK && fgets(line, sizeof line, f)) {
+ if (sscanf(line, " %*s %63s %63s %x %*s %*s %*s %u %*s %lu", la, ra, &st, &uid, &inode) != 5 || !inode) continue;
+ char *lc = strchr(la, ':'), *rc = strchr(ra, ':');
+ if (!lc || !rc || (size_t)(lc - la) != (fam == 4 ? 8u : 32u)) continue;
+ Sock *k = &socks[nsock++];
+ memset(k, 0, sizeof *k);
+ k->inode = (uint32_t)inode;
+ k->uid = uid;
+ k->fam = (uint8_t)fam;
+ k->proto = fam == 4 ? IPPROTO_ICMP : IPPROTO_ICMPV6;
+ k->state = (uint8_t)st;
+ hex_addr(la, fam, k->src);
+ hex_addr(ra, fam, k->dst);
+ k->sport = (uint16_t)strtoul(lc + 1, NULL, 16);
+ k->dport = (uint16_t)strtoul(rc + 1, NULL, 16);
+ }
+ fclose(f);
+}
+
static int sock_dump(void) {
nsock = 0;
int fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_SOCK_DIAG);
@@ -121,6 +165,7 @@ static int sock_dump(void) {
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++) ok |= !dump(fd, fams[i], protos[j]);
close(fd);
+ if (ok) { icmp_read("/proc/net/icmp", 4); icmp_read("/proc/net/icmp6", 6); }
return ok ? 0 : -1;
}
@@ -250,6 +295,20 @@ static void scopes_scan(void) {
}
if (d) closedir(d);
if (dfd >= 0) close(dfd);
+ /* the remote desktop's bridge: forked by lord-sessiond after the sign-in, it runs as the user in
+ * lordos.service's root-owned `supervisor` group and isn't dumpable, so its sockets can't be traced to
+ * a pid; a socket of the user's in that group can only be the bridge's (its WebRTC UDP ports) */
+ char *up = strrchr(dir, '/');
+ if (up && nscopes < 256) {
+ *up = 0;
+ int pfd = open(dir, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ struct stat st;
+ if (pfd >= 0 && !fstatat(pfd, "supervisor", &st, AT_SYMLINK_NOFOLLOW) && S_ISDIR(st.st_mode) && st.st_uid == 0) {
+ uint64_t id = cg_id(pfd, "supervisor");
+ if (id) { scopes[nscopes].id = id; snprintf(scopes[nscopes].app, sizeof scopes[nscopes].app, "remote-desktop"); nscopes++; }
+ }
+ if (pfd >= 0) close(pfd);
+ }
}
static const char *scope_app_of(uint64_t cg) {
@@ -317,13 +376,14 @@ void conn_scan(Buf *b, const Mmdb *geo) {
char ls[INET6_ADDRSTRLEN], rs[INET6_ADDRSTRLEN];
inet_ntop(fam == 4 ? AF_INET : AF_INET6, src, ls, sizeof ls);
inet_ntop(fam == 4 ? AF_INET : AF_INET6, dst, rs, sizeof rs);
- int tcp = s->proto == IPPROTO_TCP;
+ int tcp = s->proto == IPPROTO_TCP, icmp = s->proto == IPPROTO_ICMP || s->proto == IPPROTO_ICMPV6;
const char *dir;
- if (tcp && s->state == 10) dir = "listen";
+ if (icmp) dir = "icmp"; /* a ping socket: no destination known */
+ else if (tcp && s->state == 10) dir = "listen";
else if (!tcp && !s->dport) dir = "listen"; /* UDP without a destination: listening */
else if (tcp && (listening_port[s->sport >> 3] & (1 << (s->sport & 7)))) dir = "in";
else dir = "out";
- int listening = !strcmp(dir, "listen");
+ int listening = !strcmp(dir, "listen") || icmp;
const char *sc = listening ? "local" : scope(fam, dst);
char cc[3] = "";
if (geo && !strcmp(sc, "internet")) mmdb_country(geo, dst, fam, cc);
@@ -331,7 +391,7 @@ void conn_scan(Buf *b, const Mmdb *geo) {
int pid = sl ? sl->pid : -1, pi = pid > 0 ? proc_info(pid) : -1;
mon_buf_printf(b, "%s{\"id\":%u,\"proto\":\"%s\",\"fam\":%d,\"state\":\"%s\",\"dir\":\"%s\",\"local\":\"%s\",\"lport\":%u,"
"\"remote\":\"%s\",\"rport\":%u,\"scope\":\"%s\",\"cc\":\"%s\",\"pid\":%d,\"self\":%s,\"name\":",
- n ? "," : "", s->inode, tcp ? "tcp" : "udp", fam, tcp && s->state < 13 ? TCP_STATE[s->state] : (s->dport ? "CONNECTED" : "UNCONN"),
+ n ? "," : "", s->inode, tcp ? "tcp" : icmp ? "icmp" : "udp", fam, tcp && s->state < 13 ? TCP_STATE[s->state] : (s->dport ? "CONNECTED" : "UNCONN"),
dir, ls, s->sport, listening ? "" : rs, s->dport, sc, cc, pid, pid == self ? "true" : "false");
mon_buf_str(b, pi >= 0 ? pinfo[pi].name : "");
mon_buf_printf(b, ",\"exe\":");
diff --git a/server/src/testbench/card.c b/server/src/testbench/card.c
new file mode 100644
index 0000000..bb46125
--- /dev/null
+++ b/server/src/testbench/card.c
@@ -0,0 +1,87 @@
+/* card.c — the test card: a TV test pattern in the spirit of the Philips PM5544, drawn in code.
+ * Ported from go-link-console's backend-device/pkg/testpattern (same author), from BT.601 YUV to
+ * 32-bit XRGB: the same grid, castellations, side columns, colour bars, center cross, frequency
+ * gratings, grey steps and the two black boxes (the clock on top, the input box below). */
+#include "card.h"
+
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define RGB(r, g, b) (0xff000000u | ((uint32_t)(r) << 16) | ((uint32_t)(g) << 8) | (uint32_t)(b))
+
+static const uint32_t BLACK = RGB(0, 0, 0), WHITE = RGB(235, 235, 235), GRID_GRAY = RGB(110, 110, 110),
+ LIGHT_GRAY = RGB(180, 180, 180);
+static const uint32_t BARS[6] = { RGB(190, 190, 40), RGB(0, 180, 180), RGB(0, 180, 50), RGB(190, 0, 190), RGB(190, 0, 20), RGB(20, 20, 170) };
+static const uint32_t GREYS[6] = { RGB(0, 0, 0), RGB(51, 51, 51), RGB(102, 102, 102), RGB(153, 153, 153), RGB(204, 204, 204), RGB(255, 255, 255) };
+static const uint32_t SIDE_TOP[2] = { RGB(19, 147, 112), RGB(65, 105, 225) }, SIDE_BOT[2] = { RGB(190, 82, 110), RGB(155, 105, 35) };
+static const uint32_t RIGHT_TOP[2] = { RGB(107, 142, 35), RGB(65, 105, 225) }, RIGHT_BOT[2] = { RGB(123, 95, 230), RGB(155, 105, 35) };
+
+static uint32_t outside(const Card *c, int x, int y, int cell, int line) {
+ int col = x / cell, row = y / cell, cols = c->w / cell, rows = c->h / cell, edge = cell / 5;
+ if (y < edge || y >= c->h - edge) return ((x / (cell / 2)) % 2 == 0) ? BLACK : WHITE; /* castellation */
+ if (x < edge || x >= c->w - edge) return (row % 2 == 0) ? BLACK : WHITE;
+ int in_top = row >= 1 && row <= rows / 2 - 1, in_bot = row >= rows / 2 && row <= rows - 2;
+ if (col == 1 && in_top) return SIDE_TOP[0];
+ if (col == 1 && in_bot) return SIDE_BOT[0];
+ if (col == 2 && row >= 1 && row <= 2) return SIDE_TOP[1];
+ if (col == 2 && row >= rows - 3 && row <= rows - 2) return SIDE_BOT[1];
+ if (col == cols - 2 && in_top) return RIGHT_TOP[0];
+ if (col == cols - 2 && in_bot) return RIGHT_BOT[0];
+ if (col == cols - 3 && row >= 1 && row <= 2) return RIGHT_TOP[1];
+ if (col == cols - 3 && row >= rows - 3 && row <= rows - 2) return RIGHT_BOT[1];
+ return (x % cell < line || y % cell < line) ? WHITE : GRID_GRAY;
+}
+
+static uint32_t inside(double fx, double fy, double cx, double cy, double r, double top, double d, int cell, int line) {
+ double t = (fy - top) / d, left = cx - r;
+ int band = (int)((fx - left) / (d / 6));
+ if (band < 0) band = 0;
+ if (band > 5) band = 5;
+ if (t < 0.12) return WHITE;
+ if (t < 0.19) return ((int)((fx - left) / (d / 16)) % 2 == 0) ? BLACK : LIGHT_GRAY;
+ if (t < 0.33) return BARS[band];
+ if (t < 0.40) { /* black band with the centre cross and grid lines */
+ if (fabs(fy - cy) < line || fabs(fx - cx) < line || (int)fx % cell < line) return WHITE;
+ return BLACK;
+ }
+ if (t < 0.52) { /* frequency gratings, coarse to fine */
+ static const double periods[6] = { 16, 10, 8, 6, 4, 3 };
+ if (fabs(fx - cx) < line) return WHITE;
+ int l = (int)(127.5 + 127.5 * sin(2 * M_PI * fx / periods[band]));
+ return RGB(l, l, l);
+ }
+ if (t < 0.60) return GREYS[band];
+ if (t < 0.885) return WHITE;
+ return fabs(fx - cx) < d * 0.05 ? BARS[4] : BARS[0];
+}
+
+int card_build(Card *c, int w, int h) {
+ w &= ~1;
+ h &= ~1;
+ if (w < 64 || h < 48) return -1;
+ uint32_t *px = realloc(c->px, (size_t)w * (size_t)h * 4);
+ if (!px) return -1;
+ c->px = px;
+ c->w = w;
+ c->h = h;
+ int cell = w / 16, line = w / 320 > 2 ? w / 320 : 2;
+ double cx = w / 2.0, cy = h / 2.0, r = h * 0.448, top = cy - r, d = 2 * r;
+ for (int y = 0; y < h; y++)
+ for (int x = 0; x < w; x++) {
+ double fx = x + 0.5, fy = y + 0.5;
+ px[(size_t)y * w + x] = ((fx - cx) * (fx - cx) + (fy - cy) * (fy - cy) <= r * r)
+ ? inside(fx, fy, cx, cy, r, top, d, cell, line) : outside(c, x, y, cell, line);
+ }
+ c->clock = (CardBox){ (int)(cx - r * 0.52), (int)(top + d * 0.03), (int)(r * 1.04), (int)(d * 0.085) };
+ c->pad = (CardBox){ (int)(cx - r * 0.74), (int)(top + d * 0.615), (int)(r * 1.48), (int)(d * 0.27) };
+ for (int y = 0; y < h; y++)
+ for (int x = 0; x < w; x++) {
+ int in_c = x >= c->clock.x && x < c->clock.x + c->clock.w && y >= c->clock.y && y < c->clock.y + c->clock.h;
+ int in_p = x >= c->pad.x && x < c->pad.x + c->pad.w && y >= c->pad.y && y < c->pad.y + c->pad.h;
+ if (in_c || in_p) px[(size_t)y * w + x] = BLACK;
+ }
+ return 0;
+}
+
+void card_free(Card *c) { free(c->px); memset(c, 0, sizeof *c); }
diff --git a/server/src/testbench/card.h b/server/src/testbench/card.h
new file mode 100644
index 0000000..ff17ce0
--- /dev/null
+++ b/server/src/testbench/card.h
@@ -0,0 +1,19 @@
+/* card.h — the test card of lordos-testbench (see card.c). */
+#ifndef LORD_TESTBENCH_CARD_H
+#define LORD_TESTBENCH_CARD_H
+
+#include <stdint.h>
+
+typedef struct { int x, y, w, h; } CardBox;
+
+typedef struct {
+ int w, h;
+ uint32_t *px; /* XRGB, w × h, the static card */
+ CardBox clock, pad; /* the black boxes: clock (top) and input (bottom) */
+} Card;
+
+/* (Re)draws the static card at w × h (made even). 0, or -1 if too small or out of memory. */
+int card_build(Card *c, int w, int h);
+void card_free(Card *c);
+
+#endif
diff --git a/server/src/testbench/draw.c b/server/src/testbench/draw.c
new file mode 100644
index 0000000..8f18960
--- /dev/null
+++ b/server/src/testbench/draw.c
@@ -0,0 +1,89 @@
+/* draw.c — lordos-testbench's pixel drawing: boxes, circles, outlines and a 5×7 bitmap font (no font
+ * files, so what it shows doesn't depend on anything the compositor renders). */
+#include "draw.h"
+
+#include <ctype.h>
+#include <string.h>
+
+/* 5×7 glyphs, bit 4 = left column; ASCII 32..95 (lowercase is drawn as uppercase). */
+static const uint8_t FONT[64][7] = {
+ [' ' - 32] = { 0, 0, 0, 0, 0, 0, 0 },
+ ['!' - 32] = { 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x04 }, ['"' - 32] = { 0x0A, 0x0A, 0x0A, 0, 0, 0, 0 },
+ ['#' - 32] = { 0x0A, 0x0A, 0x1F, 0x0A, 0x1F, 0x0A, 0x0A }, ['$' - 32] = { 0x04, 0x0F, 0x14, 0x0E, 0x05, 0x1E, 0x04 },
+ ['%' - 32] = { 0x18, 0x19, 0x02, 0x04, 0x08, 0x13, 0x03 }, ['&' - 32] = { 0x0C, 0x12, 0x14, 0x08, 0x15, 0x12, 0x0D },
+ ['\'' - 32] = { 0x0C, 0x04, 0x08, 0, 0, 0, 0 }, ['(' - 32] = { 0x02, 0x04, 0x08, 0x08, 0x08, 0x04, 0x02 },
+ [')' - 32] = { 0x08, 0x04, 0x02, 0x02, 0x02, 0x04, 0x08 }, ['*' - 32] = { 0x00, 0x04, 0x15, 0x0E, 0x15, 0x04, 0x00 },
+ ['+' - 32] = { 0x00, 0x04, 0x04, 0x1F, 0x04, 0x04, 0x00 }, [',' - 32] = { 0, 0, 0, 0, 0x0C, 0x04, 0x08 },
+ ['-' - 32] = { 0, 0, 0, 0x1F, 0, 0, 0 }, ['.' - 32] = { 0, 0, 0, 0, 0, 0x0C, 0x0C },
+ ['/' - 32] = { 0x01, 0x01, 0x02, 0x04, 0x08, 0x10, 0x10 },
+ ['0' - 32] = { 0x0E, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0E }, ['1' - 32] = { 0x04, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x0E },
+ ['2' - 32] = { 0x0E, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1F }, ['3' - 32] = { 0x1F, 0x02, 0x04, 0x02, 0x01, 0x11, 0x0E },
+ ['4' - 32] = { 0x02, 0x06, 0x0A, 0x12, 0x1F, 0x02, 0x02 }, ['5' - 32] = { 0x1F, 0x10, 0x1E, 0x01, 0x01, 0x11, 0x0E },
+ ['6' - 32] = { 0x06, 0x08, 0x10, 0x1E, 0x11, 0x11, 0x0E }, ['7' - 32] = { 0x1F, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08 },
+ ['8' - 32] = { 0x0E, 0x11, 0x11, 0x0E, 0x11, 0x11, 0x0E }, ['9' - 32] = { 0x0E, 0x11, 0x11, 0x0F, 0x01, 0x02, 0x0C },
+ [':' - 32] = { 0x00, 0x0C, 0x0C, 0x00, 0x0C, 0x0C, 0x00 }, [';' - 32] = { 0x00, 0x0C, 0x0C, 0x00, 0x0C, 0x04, 0x08 },
+ ['<' - 32] = { 0x02, 0x04, 0x08, 0x10, 0x08, 0x04, 0x02 }, ['=' - 32] = { 0x00, 0x00, 0x1F, 0x00, 0x1F, 0x00, 0x00 },
+ ['>' - 32] = { 0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08 }, ['?' - 32] = { 0x0E, 0x11, 0x01, 0x02, 0x04, 0x00, 0x04 },
+ ['@' - 32] = { 0x0E, 0x11, 0x17, 0x15, 0x17, 0x10, 0x0E },
+ ['A' - 32] = { 0x0E, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x11 }, ['B' - 32] = { 0x1E, 0x11, 0x11, 0x1E, 0x11, 0x11, 0x1E },
+ ['C' - 32] = { 0x0E, 0x11, 0x10, 0x10, 0x10, 0x11, 0x0E }, ['D' - 32] = { 0x1C, 0x12, 0x11, 0x11, 0x11, 0x12, 0x1C },
+ ['E' - 32] = { 0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x1F }, ['F' - 32] = { 0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x10 },
+ ['G' - 32] = { 0x0E, 0x11, 0x10, 0x17, 0x11, 0x11, 0x0F }, ['H' - 32] = { 0x11, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x11 },
+ ['I' - 32] = { 0x0E, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0E }, ['J' - 32] = { 0x07, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0C },
+ ['K' - 32] = { 0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11 }, ['L' - 32] = { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F },
+ ['M' - 32] = { 0x11, 0x1B, 0x15, 0x15, 0x11, 0x11, 0x11 }, ['N' - 32] = { 0x11, 0x11, 0x19, 0x15, 0x13, 0x11, 0x11 },
+ ['O' - 32] = { 0x0E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E }, ['P' - 32] = { 0x1E, 0x11, 0x11, 0x1E, 0x10, 0x10, 0x10 },
+ ['Q' - 32] = { 0x0E, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0D }, ['R' - 32] = { 0x1E, 0x11, 0x11, 0x1E, 0x14, 0x12, 0x11 },
+ ['S' - 32] = { 0x0F, 0x10, 0x10, 0x0E, 0x01, 0x01, 0x1E }, ['T' - 32] = { 0x1F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04 },
+ ['U' - 32] = { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E }, ['V' - 32] = { 0x11, 0x11, 0x11, 0x11, 0x11, 0x0A, 0x04 },
+ ['W' - 32] = { 0x11, 0x11, 0x11, 0x15, 0x15, 0x15, 0x0A }, ['X' - 32] = { 0x11, 0x11, 0x0A, 0x04, 0x0A, 0x11, 0x11 },
+ ['Y' - 32] = { 0x11, 0x11, 0x0A, 0x04, 0x04, 0x04, 0x04 }, ['Z' - 32] = { 0x1F, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1F },
+ ['[' - 32] = { 0x0E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0E }, ['\\' - 32] = { 0x10, 0x10, 0x08, 0x04, 0x02, 0x01, 0x01 },
+ [']' - 32] = { 0x0E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x0E }, ['^' - 32] = { 0x04, 0x0A, 0x11, 0, 0, 0, 0 },
+ ['_' - 32] = { 0, 0, 0, 0, 0, 0, 0x1F },
+};
+
+void d_fill(Surf *s, int x, int y, int w, int h, uint32_t c) {
+ int x0 = x < 0 ? 0 : x, y0 = y < 0 ? 0 : y, x1 = x + w > s->w ? s->w : x + w, y1 = y + h > s->h ? s->h : y + h;
+ for (int j = y0; j < y1; j++) {
+ uint32_t *row = s->px + (size_t)j * s->stride;
+ for (int i = x0; i < x1; i++) row[i] = c;
+ }
+}
+
+void d_frame(Surf *s, int x, int y, int w, int h, int t, uint32_t c) {
+ d_fill(s, x, y, w, t, c);
+ d_fill(s, x, y + h - t, w, t, c);
+ d_fill(s, x, y, t, h, c);
+ d_fill(s, x + w - t, y, t, h, c);
+}
+
+void d_circle(Surf *s, int cx, int cy, int r, uint32_t c) {
+ for (int y = -r; y <= r; y++)
+ for (int x = -r; x <= r; x++)
+ if (x * x + y * y <= r * r) {
+ int px = cx + x, py = cy + y;
+ if (px >= 0 && px < s->w && py >= 0 && py < s->h) s->px[(size_t)py * s->stride + px] = c;
+ }
+}
+
+int d_text(Surf *s, int x, int y, int scale, uint32_t c, const char *t) {
+ int x0 = x;
+ for (; *t; t++) {
+ int ch = toupper((unsigned char)*t);
+ if (ch == '`') ch = '\''; /* the grave accent: drawn as the apostrophe */
+ if (ch < 32 || ch > 95) ch = '?';
+ const uint8_t *g = FONT[ch - 32];
+ for (int row = 0; row < 7; row++)
+ for (int col = 0; col < 5; col++)
+ if (g[row] & (1 << (4 - col))) d_fill(s, x + col * scale, y + row * scale, scale, scale, c);
+ x += 6 * scale;
+ }
+ return x - x0;
+}
+
+int d_text_w(const char *t, int scale) { int n = (int)strlen(t); return n ? n * 6 * scale - scale : 0; }
+
+void d_text_c(Surf *s, int cx, int cy, int scale, uint32_t c, const char *t) {
+ d_text(s, cx - d_text_w(t, scale) / 2, cy - 7 * scale / 2, scale, c, t);
+}
diff --git a/server/src/testbench/draw.h b/server/src/testbench/draw.h
new file mode 100644
index 0000000..bd201ba
--- /dev/null
+++ b/server/src/testbench/draw.h
@@ -0,0 +1,18 @@
+/* draw.h — lordos-testbench's pixel drawing (see draw.c). */
+#ifndef LORD_TESTBENCH_DRAW_H
+#define LORD_TESTBENCH_DRAW_H
+
+#include <stdint.h>
+
+typedef struct { uint32_t *px; int w, h, stride; } Surf; /* XRGB; stride in pixels */
+
+#define TB_RGB(r, g, b) (0xff000000u | ((uint32_t)(r) << 16) | ((uint32_t)(g) << 8) | (uint32_t)(b))
+
+void d_fill(Surf *s, int x, int y, int w, int h, uint32_t c);
+void d_frame(Surf *s, int x, int y, int w, int h, int thick, uint32_t c);
+void d_circle(Surf *s, int cx, int cy, int r, uint32_t c);
+int d_text(Surf *s, int x, int y, int scale, uint32_t c, const char *t); /* returns the width drawn */
+int d_text_w(const char *t, int scale);
+void d_text_c(Surf *s, int cx, int cy, int scale, uint32_t c, const char *t);
+
+#endif
diff --git a/server/src/testbench/testbench.c b/server/src/testbench/testbench.c
new file mode 100644
index 0000000..268085d
--- /dev/null
+++ b/server/src/testbench/testbench.c
@@ -0,0 +1,643 @@
+/* testbench.c — lordos-testbench: LordOS's visual test bench (docs/PAPER-VALIDATION.md, "the visual test
+ * bench"). A plain Wayland client, so it tests the compositor from the outside like any app, and runs on
+ * any compositor for comparison. What it shows:
+ *
+ * - the test card (card.c), with a live clock and a marker that moves one step every frame, so a
+ * dropped or repeated frame is visible;
+ * - timing: frames a second, frame-to-frame time, and with wp_presentation when each frame really
+ * reached the screen, the display's refresh and the vblanks it skipped;
+ * - the keyboard: a full keyboard that lights each key while it is down and marks every key seen, the
+ * keysym from the keymap the compositor sent, modifiers, repeat rate and delay;
+ * - the pointer: a crosshair at the exact position, buttons, wheel (discrete and high resolution),
+ * axis source;
+ * - the Wayland globals the compositor advertises, with their versions.
+ *
+ * lordos-testbench interactive
+ * lordos-testbench --auto [seconds] runs for a while (default 5 s), prints a JSON report and exits
+ *
+ * It reads no files and talks to nothing but the compositor. */
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include "card.h"
+#include "draw.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/input-event-codes.h>
+#include <poll.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <time.h>
+#include <unistd.h>
+#include <wayland-client.h>
+#include <xkbcommon/xkbcommon.h>
+
+#include "client/xdg-shell-client-protocol.h"
+#include "client/xdg-decoration-unstable-v1-client-protocol.h"
+#include "client/presentation-time-client-protocol.h"
+
+/* ---- colours ---- */
+#define C_BG TB_RGB(18, 18, 26)
+#define C_PANEL TB_RGB(28, 28, 38)
+#define C_TEXT TB_RGB(225, 225, 235)
+#define C_DIM TB_RGB(140, 140, 160)
+#define C_HEAD TB_RGB(180, 150, 255)
+#define C_GOOD TB_RGB(120, 230, 150)
+#define C_WARN TB_RGB(255, 190, 70)
+#define C_BAD TB_RGB(255, 90, 80)
+#define C_LAMP_ON TB_RGB(242, 163, 58)
+#define C_LAMP_OFF TB_RGB(55, 55, 55)
+#define C_KEY TB_RGB(44, 44, 56)
+#define C_SEEN TB_RGB(30, 80, 50)
+#define C_CROSS TB_RGB(0, 230, 255)
+
+/* ---- Wayland ---- */
+static struct wl_display *dpy;
+static struct wl_compositor *comp;
+static struct wl_shm *shm;
+static struct xdg_wm_base *wm;
+static struct wl_seat *seat;
+static struct wl_pointer *pointer;
+static struct wl_keyboard *keyboard;
+static struct zxdg_decoration_manager_v1 *decoman;
+static struct wp_presentation *presentation;
+static struct wl_surface *surf;
+static struct xdg_surface *xsurf;
+static struct xdg_toplevel *top;
+
+typedef struct { uint32_t name, version; char iface[64]; } Global;
+static Global globals[96];
+static int nglobals;
+
+typedef struct { struct wl_buffer *b; uint32_t *px; size_t size; int w, h, busy; } Buf;
+static Buf bufs[2];
+static int win_w = 1280, win_h = 800, configured, closed, frame_pending;
+static Card card;
+static int card_x, card_y;
+
+/* ---- measurements ---- */
+static double now_ms(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return t.tv_sec * 1e3 + t.tv_nsec / 1e6; }
+static unsigned long frames, no_buffer;
+static double t_first, t_last;
+#define HIST 240
+static double intervals[HIST];
+static int nint;
+static unsigned long presented, discarded, vblank_skips, zero_copy;
+static uint32_t refresh_ns, clock_id;
+static double last_present_ms;
+static uint64_t last_msc;
+
+/* ---- input ---- */
+static struct xkb_context *xkb;
+static struct xkb_keymap *keymap;
+static struct xkb_state *kstate;
+static unsigned char down[KEY_MAX + 1], seen[KEY_MAX + 1];
+static int nseen, repeat_rate = -1, repeat_delay = -1, kb_focus;
+static char last_key[160] = "-", mods[64] = "-", other_keys[96] = "";
+static double ptr_x = -1, ptr_y = -1;
+static int ptr_in, btn_down[16], btn_seen[16];
+static long wheel_v, wheel_h, wheel120_v, wheel120_h;
+static char axis_src[16] = "-";
+
+/* ---- the keyboard drawn on screen: evdev codes, widths in quarter units ---- */
+typedef struct { int code, w; const char *label; } Key;
+#define GAP(w) { 0, w, NULL }
+static const Key ROWS[6][24] = {
+ { { KEY_ESC, 4, "ESC" }, GAP(4), { KEY_F1, 4, "F1" }, { KEY_F2, 4, "F2" }, { KEY_F3, 4, "F3" }, { KEY_F4, 4, "F4" }, GAP(2),
+ { KEY_F5, 4, "F5" }, { KEY_F6, 4, "F6" }, { KEY_F7, 4, "F7" }, { KEY_F8, 4, "F8" }, GAP(2), { KEY_F9, 4, "F9" }, { KEY_F10, 4, "F10" },
+ { KEY_F11, 4, "F11" }, { KEY_F12, 4, "F12" } },
+ { { KEY_GRAVE, 4, "`" }, { KEY_1, 4, "1" }, { KEY_2, 4, "2" }, { KEY_3, 4, "3" }, { KEY_4, 4, "4" }, { KEY_5, 4, "5" }, { KEY_6, 4, "6" },
+ { KEY_7, 4, "7" }, { KEY_8, 4, "8" }, { KEY_9, 4, "9" }, { KEY_0, 4, "0" }, { KEY_MINUS, 4, "-" }, { KEY_EQUAL, 4, "=" }, { KEY_BACKSPACE, 8, "BKSP" } },
+ { { KEY_TAB, 6, "TAB" }, { KEY_Q, 4, "Q" }, { KEY_W, 4, "W" }, { KEY_E, 4, "E" }, { KEY_R, 4, "R" }, { KEY_T, 4, "T" }, { KEY_Y, 4, "Y" },
+ { KEY_U, 4, "U" }, { KEY_I, 4, "I" }, { KEY_O, 4, "O" }, { KEY_P, 4, "P" }, { KEY_LEFTBRACE, 4, "[" }, { KEY_RIGHTBRACE, 4, "]" }, { KEY_BACKSLASH, 6, "\\" } },
+ { { KEY_CAPSLOCK, 7, "CAPS" }, { KEY_A, 4, "A" }, { KEY_S, 4, "S" }, { KEY_D, 4, "D" }, { KEY_F, 4, "F" }, { KEY_G, 4, "G" }, { KEY_H, 4, "H" },
+ { KEY_J, 4, "J" }, { KEY_K, 4, "K" }, { KEY_L, 4, "L" }, { KEY_SEMICOLON, 4, ";" }, { KEY_APOSTROPHE, 4, "'" }, { KEY_ENTER, 9, "ENTER" } },
+ { { KEY_LEFTSHIFT, 9, "SHIFT" }, { KEY_102ND, 0, NULL }, { KEY_Z, 4, "Z" }, { KEY_X, 4, "X" }, { KEY_C, 4, "C" }, { KEY_V, 4, "V" }, { KEY_B, 4, "B" },
+ { KEY_N, 4, "N" }, { KEY_M, 4, "M" }, { KEY_COMMA, 4, "," }, { KEY_DOT, 4, "." }, { KEY_SLASH, 4, "/" }, { KEY_RIGHTSHIFT, 11, "SHIFT" } },
+ { { KEY_LEFTCTRL, 5, "CTRL" }, { KEY_LEFTMETA, 5, "SUPER" }, { KEY_LEFTALT, 5, "ALT" }, { KEY_SPACE, 25, "SPACE" }, { KEY_RIGHTALT, 5, "ALTGR" },
+ { KEY_RIGHTMETA, 5, "SUPER" }, { KEY_COMPOSE, 5, "MENU" }, { KEY_RIGHTCTRL, 5, "CTRL" } },
+};
+static const Key NAV[6][4] = {
+ { { KEY_SYSRQ, 4, "PRT" }, { KEY_SCROLLLOCK, 4, "SCR" }, { KEY_PAUSE, 4, "PAU" } },
+ { { KEY_INSERT, 4, "INS" }, { KEY_HOME, 4, "HOME" }, { KEY_PAGEUP, 4, "PGUP" } },
+ { { KEY_DELETE, 4, "DEL" }, { KEY_END, 4, "END" }, { KEY_PAGEDOWN, 4, "PGDN" } },
+ { GAP(4) },
+ { GAP(4), { KEY_UP, 4, "^" } },
+ { { KEY_LEFT, 4, "<" }, { KEY_DOWN, 4, "V" }, { KEY_RIGHT, 4, ">" } },
+};
+static const Key PAD[6][4] = {
+ { GAP(4) },
+ { { KEY_NUMLOCK, 4, "NUM" }, { KEY_KPSLASH, 4, "/" }, { KEY_KPASTERISK, 4, "*" }, { KEY_KPMINUS, 4, "-" } },
+ { { KEY_KP7, 4, "7" }, { KEY_KP8, 4, "8" }, { KEY_KP9, 4, "9" }, { KEY_KPPLUS, 4, "+" } },
+ { { KEY_KP4, 4, "4" }, { KEY_KP5, 4, "5" }, { KEY_KP6, 4, "6" }, GAP(4) },
+ { { KEY_KP1, 4, "1" }, { KEY_KP2, 4, "2" }, { KEY_KP3, 4, "3" }, { KEY_KPENTER, 4, "ENT" } },
+ { { KEY_KP0, 8, "0" }, { KEY_KPDOT, 4, "." } },
+};
+
+/* every key on the drawn keyboard, for the "seen" count */
+static int on_map(int code) {
+ for (int r = 0; r < 6; r++) {
+ for (int i = 0; i < 24 && (ROWS[r][i].w || ROWS[r][i].code); i++) if (ROWS[r][i].w && ROWS[r][i].code == code) return 1;
+ for (int i = 0; i < 4; i++) if ((NAV[r][i].w && NAV[r][i].code == code) || (PAD[r][i].w && PAD[r][i].code == code)) return 1;
+ }
+ return 0;
+}
+static int map_total(void) {
+ int n = 0;
+ for (int c = 1; c <= KEY_MAX; c++) n += on_map(c);
+ return n;
+}
+
+/* ---- buffers ---- */
+static void buf_release(void *data, struct wl_buffer *b) { (void)b; ((Buf *)data)->busy = 0; }
+static const struct wl_buffer_listener buf_listener = { buf_release };
+
+static void buf_free(Buf *b) {
+ if (b->b) wl_buffer_destroy(b->b);
+ if (b->px) munmap(b->px, b->size);
+ memset(b, 0, sizeof *b);
+}
+
+static int buf_make(Buf *b, int w, int h) {
+ buf_free(b);
+ size_t stride = (size_t)w * 4, size = stride * (size_t)h;
+ int fd = memfd_create("lordos-testbench", MFD_CLOEXEC);
+ if (fd < 0 || ftruncate(fd, (off_t)size)) { if (fd >= 0) close(fd); return -1; }
+ void *p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (p == MAP_FAILED) { close(fd); return -1; }
+ struct wl_shm_pool *pool = wl_shm_create_pool(shm, fd, (int32_t)size);
+ b->b = wl_shm_pool_create_buffer(pool, 0, w, h, (int32_t)stride, WL_SHM_FORMAT_XRGB8888);
+ wl_shm_pool_destroy(pool);
+ close(fd);
+ wl_buffer_add_listener(b->b, &buf_listener, b);
+ b->px = p;
+ b->size = size;
+ b->w = w;
+ b->h = h;
+ return 0;
+}
+
+/* ---- drawing a frame ---- */
+static int panel_w(void) { return win_w >= 1100 ? 420 : 300; }
+static int kbd_h(void) { return 214; }
+
+static void draw_keys(Surf *s, const Key *row, int n, int x, int y, int unit, int kh) {
+ for (int i = 0; i < n; i++) {
+ const Key *k = &row[i];
+ if (!k->w) { if (!k->code) break; continue; }
+ int w = k->w * unit / 4 - 3;
+ if (k->code) {
+ uint32_t bg = down[k->code] ? C_LAMP_ON : seen[k->code] ? C_SEEN : C_KEY;
+ d_fill(s, x, y, w, kh, bg);
+ if (seen[k->code] && !down[k->code]) d_frame(s, x, y, w, kh, 1, C_GOOD);
+ d_text_c(s, x + w / 2, y + kh / 2, 1, down[k->code] ? TB_RGB(0, 0, 0) : C_TEXT, k->label);
+ }
+ x += k->w * unit / 4;
+ }
+}
+
+static void draw_keyboard(Surf *s, int y0) {
+ int total_units = 15 * 4 + 2 + 3 * 4 + 2 + 4 * 4; /* main block, gap, nav, gap, keypad (quarter units) */
+ int unit = (s->w - 24) * 4 / total_units;
+ if (unit > 52) unit = 52;
+ int kh = (kbd_h() - 40) / 6 - 3;
+ int x0 = 12, xn = x0 + (15 * 4 + 2) * unit / 4, xp = xn + (3 * 4 + 2) * unit / 4;
+ for (int r = 0; r < 6; r++) {
+ int y = y0 + 28 + r * (kh + 3);
+ draw_keys(s, ROWS[r], 24, x0, y, unit, kh);
+ draw_keys(s, NAV[r], 4, xn, y, unit, kh);
+ draw_keys(s, PAD[r], 4, xp, y, unit, kh);
+ }
+ char t[160];
+ snprintf(t, sizeof t, "KEYBOARD %d OF %d KEYS SEEN%s%s", nseen, map_total(), other_keys[0] ? " OTHER: " : "", other_keys);
+ d_text(s, 12, y0 + 10, 1, nseen == map_total() ? C_GOOD : C_HEAD, t);
+}
+
+static void stat_line(Surf *s, int x, int *y, const char *label, const char *value, uint32_t c) {
+ d_text(s, x, *y, 1, C_DIM, label);
+ d_text(s, x + 110, *y, 1, c, value);
+ *y += 12;
+}
+
+static void draw_panel(Surf *s, int x0) {
+ int pw = panel_w();
+ d_fill(s, x0, 0, pw, s->h - kbd_h(), C_PANEL);
+ int x = x0 + 14, y = 14;
+ d_text(s, x, y, 2, C_TEXT, "TEST BENCH");
+ y += 26;
+ char v[160];
+ /* timing */
+ d_text(s, x, y, 1, C_HEAD, "TIMING");
+ y += 14;
+ double span = t_last - t_first;
+ double fps = span > 0 && frames > 1 ? (frames - 1) * 1000.0 / span : 0;
+ double sum = 0, mx = 0;
+ for (int i = 0; i < nint; i++) { sum += intervals[i]; if (intervals[i] > mx) mx = intervals[i]; }
+ snprintf(v, sizeof v, "%.1f", fps);
+ stat_line(s, x, &y, "FRAMES/S", v, C_GOOD);
+ snprintf(v, sizeof v, "%.2f MS AVG %.2f MAX", nint ? sum / nint : 0, mx);
+ stat_line(s, x, &y, "FRAME TIME", v, mx > (refresh_ns ? refresh_ns / 1e6 * 1.5 : 25) ? C_WARN : C_TEXT);
+ snprintf(v, sizeof v, "%lu", frames);
+ stat_line(s, x, &y, "FRAMES", v, C_TEXT);
+ if (presentation) {
+ snprintf(v, sizeof v, "%lu SHOWN %lu DISCARDED", presented, discarded);
+ stat_line(s, x, &y, "PRESENTED", v, discarded ? C_WARN : C_GOOD);
+ snprintf(v, sizeof v, refresh_ns ? "%.2f HZ" : "UNKNOWN", refresh_ns ? 1e9 / refresh_ns : 0);
+ stat_line(s, x, &y, "REFRESH", v, C_TEXT);
+ snprintf(v, sizeof v, "%lu", vblank_skips);
+ stat_line(s, x, &y, "VBLANKS SKIPPED", v, vblank_skips ? C_WARN : C_GOOD);
+ snprintf(v, sizeof v, "%lu", zero_copy);
+ stat_line(s, x, &y, "ZERO-COPY", v, C_TEXT);
+ } else stat_line(s, x, &y, "PRESENTED", "NO WP_PRESENTATION", C_WARN);
+ snprintf(v, sizeof v, "%lu", no_buffer);
+ stat_line(s, x, &y, "NO FREE BUFFER", v, no_buffer ? C_WARN : C_TEXT);
+ snprintf(v, sizeof v, "%d X %d", win_w, win_h);
+ stat_line(s, x, &y, "WINDOW", v, C_TEXT);
+ y += 8;
+ /* pointer */
+ d_text(s, x, y, 1, C_HEAD, "POINTER");
+ y += 14;
+ if (ptr_in) snprintf(v, sizeof v, "%.2f, %.2f", ptr_x, ptr_y); else snprintf(v, sizeof v, "OUTSIDE");
+ stat_line(s, x, &y, "POSITION", v, ptr_in ? C_TEXT : C_DIM);
+ static const char *bn[8] = { "L", "R", "M", "SIDE", "EXTRA", "FWD", "BACK", "TASK" };
+ int bx = x + 110;
+ d_text(s, x, y, 1, C_DIM, "BUTTONS");
+ for (int i = 0; i < 8; i++) {
+ int w = d_text_w(bn[i], 1) + 8;
+ d_fill(s, bx, y - 2, w, 11, btn_down[i] ? C_LAMP_ON : btn_seen[i] ? C_SEEN : C_KEY);
+ d_text(s, bx + 4, y, 1, btn_down[i] ? TB_RGB(0, 0, 0) : C_TEXT, bn[i]);
+ bx += w + 3;
+ }
+ y += 14;
+ snprintf(v, sizeof v, "V %ld H %ld (120THS V %ld H %ld)", wheel_v, wheel_h, wheel120_v, wheel120_h);
+ stat_line(s, x, &y, "WHEEL", v, C_TEXT);
+ stat_line(s, x, &y, "AXIS SOURCE", axis_src, C_TEXT);
+ y += 8;
+ /* keyboard */
+ d_text(s, x, y, 1, C_HEAD, "KEYBOARD");
+ y += 14;
+ stat_line(s, x, &y, "FOCUS", kb_focus ? "YES" : "NO", kb_focus ? C_GOOD : C_DIM);
+ stat_line(s, x, &y, "LAST KEY", last_key, C_TEXT);
+ stat_line(s, x, &y, "MODIFIERS", mods, C_TEXT);
+ if (repeat_rate >= 0) snprintf(v, sizeof v, "%d/S AFTER %d MS", repeat_rate, repeat_delay); else snprintf(v, sizeof v, "NOT SENT");
+ stat_line(s, x, &y, "REPEAT", v, C_TEXT);
+ y += 8;
+ /* globals */
+ snprintf(v, sizeof v, "WAYLAND %d GLOBALS", nglobals);
+ d_text(s, x, y, 1, C_HEAD, v);
+ y += 14;
+ int col = 0, ystart = y, colw = (pw - 28) / 2;
+ for (int i = 0; i < nglobals; i++) {
+ if (y > s->h - kbd_h() - 14) {
+ if (col) break;
+ col = 1;
+ y = ystart;
+ }
+ char g[96], ver[16];
+ snprintf(ver, sizeof ver, " V%u", globals[i].version);
+ int room = colw / 6 - (int)strlen(ver) - 1; /* characters that fit the column */
+ if (room < 4) room = 4;
+ snprintf(g, sizeof g, "%.*s%s", room, globals[i].iface, ver);
+ d_text(s, x + col * colw, y, 1, C_TEXT, g);
+ y += 10;
+ }
+}
+
+/* the input box of the card: a pad lit by the keyboard (arrows, Z X A S, Q W, shift, enter), as in
+ * go-link-console's test pattern, and the frames per second */
+static void draw_pad(Surf *s) {
+ CardBox b = card.pad;
+ b.x += card_x;
+ b.y += card_y;
+ int u = b.h / 8 > 4 ? b.h / 8 : 4;
+#define AT(fx, fy, X, Y) int X = b.x + (int)((fx) * b.w), Y = b.y + (int)((fy) * b.h)
+#define LAMP(k) (down[k] ? C_LAMP_ON : C_LAMP_OFF)
+ AT(0.09, 0.08, l2x, l2y); d_fill(s, l2x - u, l2y, 2 * u, u, LAMP(KEY_Q)); d_text_c(s, l2x, l2y + u / 2, 1, C_TEXT, "ZL");
+ AT(0.91, 0.08, r2x, r2y); d_fill(s, r2x - u, r2y, 2 * u, u, LAMP(KEY_W)); d_text_c(s, r2x, r2y + u / 2, 1, C_TEXT, "ZR");
+ AT(0.17, 0.5, dx, dy);
+ int arm = u + u / 3;
+ d_fill(s, dx - arm / 2, dy - arm / 2, arm, arm, TB_RGB(120, 120, 120));
+ d_fill(s, dx - arm / 2, dy - arm * 3 / 2, arm, arm, LAMP(KEY_UP));
+ d_fill(s, dx - arm / 2, dy + arm / 2, arm, arm, LAMP(KEY_DOWN));
+ d_fill(s, dx - arm * 3 / 2, dy - arm / 2, arm, arm, LAMP(KEY_LEFT));
+ d_fill(s, dx + arm / 2, dy - arm / 2, arm, arm, LAMP(KEY_RIGHT));
+ AT(0.83, 0.5, fx, fy);
+ int fr = u * 2 / 3 + 1, off = u + u / 2;
+ d_circle(s, fx, fy - off, fr, LAMP(KEY_S)); d_text_c(s, fx + 1, fy - off, 1, C_TEXT, "X");
+ d_circle(s, fx - off, fy, fr, LAMP(KEY_A)); d_text_c(s, fx - off + 1, fy, 1, C_TEXT, "Y");
+ d_circle(s, fx + off, fy, fr, LAMP(KEY_X)); d_text_c(s, fx + off + 1, fy, 1, C_TEXT, "A");
+ d_circle(s, fx, fy + off, fr, LAMP(KEY_Z)); d_text_c(s, fx + 1, fy + off, 1, C_TEXT, "B");
+ AT(0.40, 0.36, mx, my); d_circle(s, mx, my, u / 2 + 1, LAMP(KEY_RIGHTSHIFT)); d_text_c(s, mx + 1, my, 1, C_TEXT, "-");
+ AT(0.60, 0.36, px, py); d_circle(s, px, py, u / 2 + 1, LAMP(KEY_ENTER)); d_text_c(s, px + 1, py, 1, C_TEXT, "+");
+ double span = t_last - t_first;
+ char t[48];
+ snprintf(t, sizeof t, "%.1f FPS", span > 0 && frames > 1 ? (frames - 1) * 1000.0 / span : 0.0);
+ AT(0.5, 0.82, tx, ty);
+ d_text_c(s, tx, ty, u / 6 > 1 ? u / 6 : 1, C_GOOD, t);
+#undef AT
+#undef LAMP
+}
+
+static void draw(Buf *b) {
+ Surf s = { b->px, b->w, b->h, b->w };
+ d_fill(&s, 0, 0, b->w, b->h, C_BG);
+ /* the card: 4:3 in the area left of the panel and above the keyboard */
+ int aw = b->w - panel_w(), ah = b->h - kbd_h();
+ int cw = aw, ch = cw * 3 / 4;
+ if (ch > ah) { ch = ah; cw = ch * 4 / 3; }
+ if (card.w != (cw & ~1) || card.h != (ch & ~1)) card_build(&card, cw, ch);
+ card_x = (aw - card.w) / 2;
+ card_y = (ah - card.h) / 2;
+ for (int y = 0; y < card.h; y++) memcpy(b->px + (size_t)(card_y + y) * b->w + card_x, card.px + (size_t)y * card.w, (size_t)card.w * 4);
+ /* clock and the per-frame marker in the top box */
+ CardBox c = card.clock;
+ time_t now = time(NULL);
+ struct tm tm;
+ localtime_r(&now, &tm);
+ char clk[16];
+ strftime(clk, sizeof clk, "%H:%M:%S", &tm);
+ int sc = c.h / 10 > 1 ? c.h / 10 : 1;
+ d_text_c(&s, card_x + c.x + c.w / 2, card_y + c.y + c.h / 2 - sc, sc, TB_RGB(235, 235, 235), clk);
+ int steps = 60, cell = c.w / steps;
+ d_fill(&s, card_x + c.x + (int)(frames % steps) * cell, card_y + c.y + c.h - 4, cell > 2 ? cell - 1 : 2, 3, C_LAMP_ON);
+ draw_pad(&s);
+ draw_panel(&s, b->w - panel_w());
+ draw_keyboard(&s, b->h - kbd_h());
+ /* the crosshair: the exact pointer position, on top of everything */
+ if (ptr_in) {
+ int px = (int)ptr_x, py = (int)ptr_y;
+ d_fill(&s, px, 0, 1, b->h, C_CROSS);
+ d_fill(&s, 0, py, b->w, 1, C_CROSS);
+ d_frame(&s, px - 6, py - 6, 13, 13, 1, C_CROSS);
+ }
+}
+
+/* ---- frames and presentation feedback ---- */
+static void fb_sync(void *d, struct wp_presentation_feedback *f, struct wl_output *o) { (void)d; (void)f; (void)o; }
+static void fb_presented(void *d, struct wp_presentation_feedback *f, uint32_t sec_hi, uint32_t sec_lo, uint32_t nsec,
+ uint32_t refresh, uint32_t seq_hi, uint32_t seq_lo, uint32_t flags) {
+ (void)d;
+ presented++;
+ if (refresh) refresh_ns = refresh;
+ if (flags & WP_PRESENTATION_FEEDBACK_KIND_ZERO_COPY) zero_copy++;
+ uint64_t msc = ((uint64_t)seq_hi << 32) | seq_lo;
+ double t = (((uint64_t)sec_hi << 32) | sec_lo) * 1e3 + nsec / 1e6;
+ if (last_msc && msc > last_msc + 1) vblank_skips += msc - last_msc - 1;
+ else if (!msc && last_present_ms > 0 && refresh_ns) { /* no counter: count from the times */
+ double gap = (t - last_present_ms) / (refresh_ns / 1e6);
+ if (gap > 1.5) vblank_skips += (unsigned long)(gap + 0.5) - 1;
+ }
+ last_msc = msc;
+ last_present_ms = t;
+ wp_presentation_feedback_destroy(f);
+}
+static void fb_discarded(void *d, struct wp_presentation_feedback *f) { (void)d; discarded++; wp_presentation_feedback_destroy(f); }
+static const struct wp_presentation_feedback_listener fb_listener = { fb_sync, fb_presented, fb_discarded };
+
+static void redraw(void);
+static void frame_done(void *d, struct wl_callback *cb, uint32_t t) { (void)d; (void)t; wl_callback_destroy(cb); frame_pending = 0; redraw(); }
+static const struct wl_callback_listener frame_listener = { frame_done };
+
+static void redraw(void) {
+ if (!configured || closed || frame_pending) return;
+ Buf *b = NULL;
+ for (int i = 0; i < 2; i++) if (!bufs[i].busy && bufs[i].b) { b = &bufs[i]; break; }
+ if (b && (b->w != win_w || b->h != win_h)) { if (buf_make(b, win_w, win_h)) return; }
+ if (!b) {
+ for (int i = 0; i < 2; i++) if (!bufs[i].b) { if (buf_make(&bufs[i], win_w, win_h)) return; b = &bufs[i]; break; }
+ if (!b) { no_buffer++; }
+ }
+ double t = now_ms();
+ if (frames) {
+ intervals[nint < HIST ? nint++ : (int)(frames % HIST)] = t - t_last;
+ } else t_first = t;
+ t_last = t;
+ if (b) {
+ draw(b);
+ frames++;
+ }
+ struct wl_callback *cb = wl_surface_frame(surf);
+ wl_callback_add_listener(cb, &frame_listener, NULL);
+ frame_pending = 1;
+ if (presentation) wp_presentation_feedback_add_listener(wp_presentation_feedback(presentation, surf), &fb_listener, NULL);
+ if (b) {
+ wl_surface_attach(surf, b->b, 0, 0);
+ wl_surface_damage_buffer(surf, 0, 0, b->w, b->h);
+ b->busy = 1;
+ }
+ wl_surface_commit(surf);
+}
+
+/* ---- xdg ---- */
+static void wm_ping(void *d, struct xdg_wm_base *w, uint32_t serial) { (void)d; xdg_wm_base_pong(w, serial); }
+static const struct xdg_wm_base_listener wm_listener = { wm_ping };
+static void xs_configure(void *d, struct xdg_surface *x, uint32_t serial) {
+ (void)d;
+ xdg_surface_ack_configure(x, serial);
+ int first = !configured;
+ configured = 1;
+ if (first || !frame_pending) { frame_pending = 0; redraw(); }
+}
+static const struct xdg_surface_listener xs_listener = { xs_configure };
+static void top_configure(void *d, struct xdg_toplevel *t, int32_t w, int32_t h, struct wl_array *states) {
+ (void)d; (void)t; (void)states;
+ if (w >= 640 && h >= 480) { win_w = w; win_h = h; }
+}
+static void top_close(void *d, struct xdg_toplevel *t) { (void)d; (void)t; closed = 1; }
+static void top_bounds(void *d, struct xdg_toplevel *t, int32_t w, int32_t h) { (void)d; (void)t; (void)w; (void)h; }
+static void top_caps(void *d, struct xdg_toplevel *t, struct wl_array *c) { (void)d; (void)t; (void)c; }
+static const struct xdg_toplevel_listener top_listener = { top_configure, top_close, top_bounds, top_caps };
+
+/* ---- keyboard ---- */
+static void kb_keymap(void *d, struct wl_keyboard *k, uint32_t fmt, int32_t fd, uint32_t size) {
+ (void)d; (void)k;
+ if (fmt != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) { close(fd); return; }
+ char *m = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
+ close(fd);
+ if (m == MAP_FAILED) return;
+ struct xkb_keymap *km = xkb_keymap_new_from_string(xkb, m, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
+ munmap(m, size);
+ if (!km) return;
+ if (kstate) xkb_state_unref(kstate);
+ if (keymap) xkb_keymap_unref(keymap);
+ keymap = km;
+ kstate = xkb_state_new(km);
+}
+static void kb_enter(void *d, struct wl_keyboard *k, uint32_t s, struct wl_surface *sf, struct wl_array *keys) { (void)d; (void)k; (void)s; (void)sf; (void)keys; kb_focus = 1; }
+static void kb_leave(void *d, struct wl_keyboard *k, uint32_t s, struct wl_surface *sf) {
+ (void)d; (void)k; (void)s; (void)sf;
+ kb_focus = 0;
+ memset(down, 0, sizeof down); /* keys still down when focus left aren't down for us */
+}
+static void kb_key(void *d, struct wl_keyboard *k, uint32_t serial, uint32_t t, uint32_t key, uint32_t state) {
+ (void)d; (void)k; (void)serial; (void)t;
+ if (key > KEY_MAX) return;
+ int pressed = state == WL_KEYBOARD_KEY_STATE_PRESSED;
+ down[key] = (unsigned char)pressed;
+ if (pressed && !seen[key]) {
+ seen[key] = 1;
+ if (on_map((int)key)) nseen++;
+ else { /* a key the drawn keyboard doesn't have: list its code */
+ size_t o = strlen(other_keys);
+ if (o + 8 < sizeof other_keys) snprintf(other_keys + o, sizeof other_keys - o, "%s%u", o ? " " : "", key);
+ }
+ }
+ if (pressed) {
+ char sym[64] = "?", utf[16] = "";
+ if (kstate) {
+ xkb_keysym_t ks = xkb_state_key_get_one_sym(kstate, key + 8);
+ xkb_keysym_get_name(ks, sym, sizeof sym);
+ xkb_state_key_get_utf8(kstate, key + 8, utf, sizeof utf);
+ for (char *q = utf; *q; q++) if ((unsigned char)*q < 0x20 || (unsigned char)*q > 0x7e) { utf[0] = 0; break; }
+ }
+ snprintf(last_key, sizeof last_key, "%u %.40s%s%s", key, sym, utf[0] ? " " : "", utf);
+ }
+}
+static void kb_mods(void *d, struct wl_keyboard *k, uint32_t s, uint32_t dep, uint32_t lat, uint32_t lock, uint32_t group) {
+ (void)d; (void)k; (void)s;
+ if (!kstate) return;
+ xkb_state_update_mask(kstate, dep, lat, lock, 0, 0, group);
+ static const char *names[] = { XKB_MOD_NAME_SHIFT, XKB_MOD_NAME_CTRL, XKB_MOD_NAME_ALT, XKB_MOD_NAME_LOGO, XKB_MOD_NAME_CAPS, XKB_MOD_NAME_NUM };
+ static const char *label[] = { "SHIFT", "CTRL", "ALT", "SUPER", "CAPS", "NUM" };
+ mods[0] = 0;
+ for (size_t i = 0; i < sizeof names / sizeof names[0]; i++)
+ if (xkb_state_mod_name_is_active(kstate, names[i], XKB_STATE_MODS_EFFECTIVE) > 0) {
+ size_t o = strlen(mods);
+ snprintf(mods + o, sizeof mods - o, "%s%s", o ? "+" : "", label[i]);
+ }
+ if (!mods[0]) snprintf(mods, sizeof mods, "-");
+ char g[24];
+ snprintf(g, sizeof g, " LAYOUT %u", group);
+ size_t o = strlen(mods);
+ snprintf(mods + o, sizeof mods - o, "%s", g);
+}
+static void kb_repeat(void *d, struct wl_keyboard *k, int32_t rate, int32_t delay) { (void)d; (void)k; repeat_rate = rate; repeat_delay = delay; }
+static const struct wl_keyboard_listener kb_listener = { kb_keymap, kb_enter, kb_leave, kb_key, kb_mods, kb_repeat };
+
+/* ---- pointer ---- */
+static void p_enter(void *d, struct wl_pointer *p, uint32_t s, struct wl_surface *sf, wl_fixed_t x, wl_fixed_t y) {
+ (void)d; (void)p; (void)s; (void)sf;
+ ptr_in = 1;
+ ptr_x = wl_fixed_to_double(x);
+ ptr_y = wl_fixed_to_double(y);
+}
+static void p_leave(void *d, struct wl_pointer *p, uint32_t s, struct wl_surface *sf) { (void)d; (void)p; (void)s; (void)sf; ptr_in = 0; memset(btn_down, 0, sizeof btn_down); }
+static void p_motion(void *d, struct wl_pointer *p, uint32_t t, wl_fixed_t x, wl_fixed_t y) { (void)d; (void)p; (void)t; ptr_x = wl_fixed_to_double(x); ptr_y = wl_fixed_to_double(y); }
+static void p_button(void *d, struct wl_pointer *p, uint32_t s, uint32_t t, uint32_t button, uint32_t state) {
+ (void)d; (void)p; (void)s; (void)t;
+ int i = (int)button - BTN_LEFT; /* BTN_LEFT, RIGHT, MIDDLE, SIDE, EXTRA, FORWARD, BACK, TASK */
+ if (i < 0 || i >= 8) return;
+ btn_down[i] = state == WL_POINTER_BUTTON_STATE_PRESSED;
+ if (btn_down[i]) btn_seen[i] = 1;
+}
+static void p_axis(void *d, struct wl_pointer *p, uint32_t t, uint32_t axis, wl_fixed_t v) {
+ (void)d; (void)p; (void)t;
+ long n = wl_fixed_to_int(v);
+ if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) wheel_v += n; else wheel_h += n;
+}
+static void p_frame(void *d, struct wl_pointer *p) { (void)d; (void)p; }
+static void p_source(void *d, struct wl_pointer *p, uint32_t src) {
+ (void)d; (void)p;
+ static const char *n[] = { "WHEEL", "FINGER", "CONTINUOUS", "WHEEL TILT" };
+ snprintf(axis_src, sizeof axis_src, "%s", src < 4 ? n[src] : "?");
+}
+static void p_stop(void *d, struct wl_pointer *p, uint32_t t, uint32_t axis) { (void)d; (void)p; (void)t; (void)axis; }
+static void p_discrete(void *d, struct wl_pointer *p, uint32_t axis, int32_t steps) { (void)d; (void)p; (void)axis; (void)steps; }
+static void p_value120(void *d, struct wl_pointer *p, uint32_t axis, int32_t v) {
+ (void)d; (void)p;
+ if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) wheel120_v += v; else wheel120_h += v;
+}
+static void p_reldir(void *d, struct wl_pointer *p, uint32_t axis, uint32_t dir) { (void)d; (void)p; (void)axis; (void)dir; }
+static const struct wl_pointer_listener p_listener = { p_enter, p_leave, p_motion, p_button, p_axis, p_frame, p_source, p_stop, p_discrete, p_value120, p_reldir };
+
+static void seat_caps(void *d, struct wl_seat *s, uint32_t caps) {
+ (void)d;
+ if ((caps & WL_SEAT_CAPABILITY_POINTER) && !pointer) { pointer = wl_seat_get_pointer(s); wl_pointer_add_listener(pointer, &p_listener, NULL); }
+ if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !keyboard) { keyboard = wl_seat_get_keyboard(s); wl_keyboard_add_listener(keyboard, &kb_listener, NULL); }
+}
+static void seat_name(void *d, struct wl_seat *s, const char *n) { (void)d; (void)s; (void)n; }
+static const struct wl_seat_listener seat_listener = { seat_caps, seat_name };
+
+/* ---- globals ---- */
+static uint32_t vmin(uint32_t a, uint32_t b) { return a < b ? a : b; }
+static void reg_global(void *d, struct wl_registry *r, uint32_t name, const char *iface, uint32_t version) {
+ (void)d;
+ if (nglobals < (int)(sizeof globals / sizeof globals[0])) {
+ Global *g = &globals[nglobals++];
+ g->name = name;
+ g->version = version;
+ snprintf(g->iface, sizeof g->iface, "%s", iface);
+ }
+ if (!strcmp(iface, wl_compositor_interface.name)) comp = wl_registry_bind(r, name, &wl_compositor_interface, vmin(version, 4));
+ else if (!strcmp(iface, wl_shm_interface.name)) shm = wl_registry_bind(r, name, &wl_shm_interface, 1);
+ else if (!strcmp(iface, xdg_wm_base_interface.name)) { wm = wl_registry_bind(r, name, &xdg_wm_base_interface, vmin(version, 5)); xdg_wm_base_add_listener(wm, &wm_listener, NULL); }
+ else if (!strcmp(iface, wl_seat_interface.name) && !seat) { seat = wl_registry_bind(r, name, &wl_seat_interface, vmin(version, 9)); wl_seat_add_listener(seat, &seat_listener, NULL); }
+ else if (!strcmp(iface, zxdg_decoration_manager_v1_interface.name)) decoman = wl_registry_bind(r, name, &zxdg_decoration_manager_v1_interface, 1);
+ else if (!strcmp(iface, wp_presentation_interface.name)) presentation = wl_registry_bind(r, name, &wp_presentation_interface, 1);
+}
+static void reg_remove(void *d, struct wl_registry *r, uint32_t name) { (void)d; (void)r; (void)name; }
+static const struct wl_registry_listener reg_listener = { reg_global, reg_remove };
+
+static void pres_clock(void *d, struct wp_presentation *p, uint32_t id) { (void)d; (void)p; clock_id = id; }
+static const struct wp_presentation_listener pres_listener = { pres_clock };
+
+/* ---- the --auto report ---- */
+static void report(FILE *o) {
+ double span = t_last - t_first, sum = 0, mx = 0;
+ for (int i = 0; i < nint; i++) { sum += intervals[i]; if (intervals[i] > mx) mx = intervals[i]; }
+ fprintf(o, "{\"tool\":\"lordos-testbench\",\"v\":1,\"window\":[%d,%d],\"frames\":%lu,\"fps\":%.2f,\"frameMsAvg\":%.3f,\"frameMsMax\":%.3f,"
+ "\"noFreeBuffer\":%lu,\"presentation\":%s,\"presented\":%lu,\"discarded\":%lu,\"refreshHz\":%.3f,\"vblankSkips\":%lu,\"zeroCopy\":%lu,"
+ "\"keyboard\":%s,\"pointer\":%s,\"repeat\":[%d,%d],\"globals\":[",
+ win_w, win_h, frames, span > 0 && frames > 1 ? (frames - 1) * 1000.0 / span : 0.0, nint ? sum / nint : 0, mx,
+ no_buffer, presentation ? "true" : "false", presented, discarded, refresh_ns ? 1e9 / refresh_ns : 0, vblank_skips, zero_copy,
+ keyboard ? "true" : "false", pointer ? "true" : "false", repeat_rate, repeat_delay);
+ for (int i = 0; i < nglobals; i++) fprintf(o, "%s{\"interface\":\"%s\",\"version\":%u}", i ? "," : "", globals[i].iface, globals[i].version);
+ fprintf(o, "]}\n");
+}
+
+int main(int argc, char **argv) {
+ double auto_s = 0;
+ for (int i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "--auto")) {
+ auto_s = 5;
+ if (i + 1 < argc && atof(argv[i + 1]) > 0) auto_s = atof(argv[++i]);
+ if (auto_s > 600) auto_s = 600;
+ } else {
+ fprintf(stderr, "usage: lordos-testbench [--auto [seconds]]\n");
+ return 2;
+ }
+ }
+ dpy = wl_display_connect(NULL);
+ if (!dpy) { fprintf(stderr, "lordos-testbench: no Wayland compositor (WAYLAND_DISPLAY)\n"); return 1; }
+ xkb = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
+ struct wl_registry *reg = wl_display_get_registry(dpy);
+ wl_registry_add_listener(reg, &reg_listener, NULL);
+ wl_display_roundtrip(dpy);
+ if (!comp || !shm || !wm) { fprintf(stderr, "lordos-testbench: the compositor lacks wl_compositor, wl_shm or xdg_wm_base\n"); return 1; }
+ if (presentation) wp_presentation_add_listener(presentation, &pres_listener, NULL);
+ surf = wl_compositor_create_surface(comp);
+ xsurf = xdg_wm_base_get_xdg_surface(wm, surf);
+ xdg_surface_add_listener(xsurf, &xs_listener, NULL);
+ top = xdg_surface_get_toplevel(xsurf);
+ xdg_toplevel_add_listener(top, &top_listener, NULL);
+ xdg_toplevel_set_title(top, "Test Bench");
+ xdg_toplevel_set_app_id(top, "lordos-testbench");
+ xdg_toplevel_set_min_size(top, 640, 480);
+ if (decoman) {
+ struct zxdg_toplevel_decoration_v1 *deco = zxdg_decoration_manager_v1_get_toplevel_decoration(decoman, top);
+ zxdg_toplevel_decoration_v1_set_mode(deco, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
+ }
+ wl_surface_commit(surf);
+ double start = now_ms();
+ while (!closed && wl_display_dispatch(dpy) != -1) {
+ if (auto_s > 0 && frames && now_ms() - start > auto_s * 1000) break;
+ }
+ if (auto_s > 0) report(stdout);
+ for (int i = 0; i < 2; i++) buf_free(&bufs[i]);
+ card_free(&card);
+ wl_display_disconnect(dpy);
+ return 0;
+}
diff --git a/tools/iso/mkdeb.sh b/tools/iso/mkdeb.sh
index e8e2b2b..6af891b 100755
--- a/tools/iso/mkdeb.sh
+++ b/tools/iso/mkdeb.sh
@@ -10,6 +10,8 @@
# /usr/lib/lordos/bin/lord-server each session's server (looks for ../themes and ../assets)
# /usr/bin/lordos-sysreport System Information's report as a command (user; docs/BENCHMARK.md)
# /usr/bin/lordos-fetch the crown and a summary of the computer (a link to lordos-sysreport)
+# /usr/bin/lordos-testbench the visual test bench (a Wayland client; docs/PAPER-VALIDATION.md), and
+# /usr/share/applications/lordos-testbench.desktop its launcher entry
# /usr/lib/lordos/themes/<theme>/ theme.json, theme.bundle.js and their resources (greeter: the
# login screen)
# /usr/lib/lordos/assets/ fonts, texts (locales), icons, shell integration
@@ -65,6 +67,13 @@ install -d "$PKG/usr/bin"
install -m 755 server/build/lordos-sysreport "$PKG/usr/bin/lordos-sysreport"
strip --strip-unneeded "$PKG/usr/bin/lordos-sysreport" 2>/dev/null || true
ln -s lordos-sysreport "$PKG/usr/bin/lordos-fetch"
+# the visual test bench: a plain Wayland client, launched like any Linux app
+[ -x server/build/lordos-testbench ] && {
+ install -m 755 server/build/lordos-testbench "$PKG/usr/bin/lordos-testbench"
+ strip --strip-unneeded "$PKG/usr/bin/lordos-testbench" 2>/dev/null || true
+ install -d "$PKG/usr/share/applications"
+ install -m 644 packaging/desktop/lordos-testbench.desktop "$PKG/usr/share/applications/lordos-testbench.desktop"
+}
# isolated PDF and archive helper (optional: make skips it without libpoppler-glib-dev/libarchive-dev);
# lord-server only launches the lord-doc in its own folder
[ -x server/build/lord-doc ] && install -m 755 server/build/lord-doc "$L/bin/lord-doc"