From 57fdd4f6367a0a885fc5fc8971f86ba073359e17 Mon Sep 17 00:00:00 2001 From: Hermenix Date: Sat, 3 Oct 2026 04:51:07 +0000 Subject: [PATCH] ipc: Monitor gains the id that CONTRACT-sessions v2 promised The contract bump added Monitor.id and nobody implemented it: slice B predates v2, so the integration slice had to join a client to its output through Workspace.monitor instead. Field added, parsed from `monitors -j`, and -1 when a reply omits it -- a missing id must not default to 0, which would silently bind every such client to the first output. Two tests: the id is parsed, and omitting it yields -1. --- src/hhstreamd/ipc.py | 8 ++++++++ tests/ipc/test_requests.py | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/hhstreamd/ipc.py b/src/hhstreamd/ipc.py index 45cae3d..ba39d48 100644 --- a/src/hhstreamd/ipc.py +++ b/src/hhstreamd/ipc.py @@ -95,6 +95,7 @@ class CompositorUnavailable(Exception): @dataclass(frozen=True) class Monitor: + id: int name: str x: int y: int @@ -237,6 +238,13 @@ def _monitor(raw: dict) -> Monitor: if not isinstance(name, str) or not name: raise CompositorUnavailable("monitors: an entry has no name") return Monitor( + # `monitors -j` reports the id that `clients -j` refers to as a client's + # `monitor`. Joining through it is how a client is tied to the output it + # is on -- `Client.monitor` is that same number rendered as text, while + # `Workspace.monitor` is a name. CONTRACT-sessions v2 added this field; + # `-1` is the honest value when a reply omits it, because no compositor + # numbers a monitor negative. + id=_as_int(raw.get("id"), -1), name=name, x=_as_int(raw.get("x"), 0), y=_as_int(raw.get("y"), 0), diff --git a/tests/ipc/test_requests.py b/tests/ipc/test_requests.py index 3354631..168c2fb 100644 --- a/tests/ipc/test_requests.py +++ b/tests/ipc/test_requests.py @@ -37,6 +37,9 @@ def test_monitors(servers, good_handler, ipc): request, _ = servers(good_handler) monitors = ipc.monitors() assert [m.name for m in monitors] == ["HEADLESS-2", "HEADLESS-3"] + # The id is what ties a client to the output it is on: `clients -j` reports + # a client's monitor as this same number, while workspaces report a name. + assert [m.id for m in monitors] == [0, 1] first = monitors[0] assert (first.x, first.y, first.width, first.height) == (0, 0, 1280, 720) assert first.scale == 1.0 @@ -47,6 +50,24 @@ def test_monitors(servers, good_handler, ipc): assert request.requests == [("j", "monitors")] +def test_monitors_without_an_id_is_minus_one(servers, ipc): + """A reply that omits the id must not join to a real output. + + `Monitor.id` is the join key for a client's output, so a missing id has to be + a value no compositor can use -- `-1` -- rather than a plausible-looking `0` + that would silently bind every such client to the first output. + """ + + def handler(flags, command): + return ('[{"name": "HEADLESS-9", "x": 0, "y": 0, "width": 100, ' + '"height": 50, "scale": 1.0}]') + + servers(handler) + monitors = ipc.monitors() + assert [m.id for m in monitors] == [-1] + assert monitors[0].name == "HEADLESS-9" + + def test_workspaces(servers, good_handler, ipc): servers(good_handler) workspaces = ipc.workspaces()