From 4bc6d69fc0fbfc3de5fb84874985a26deb79fdb5 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 13 Nov 2026 16:39:49 +0100 Subject: fix(windows): no peek for a dialog A transient dialog brought the Windows tab forward like any new window. Hyprland's clients JSON has no parent field, so a window counts as a dialog when it floats and its pid already has another window; peek() skips those. They are still listed in the grid. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 3 ++- deckit/modules/windows.py | 9 +++++++-- static/modules/windows.js | 4 ++-- tests/test_windows.mjs | 1 + tests/test_windows.py | 14 ++++++++++++++ 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index c577643..b88fcd5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -105,7 +105,8 @@ Keep the server dependency-free apart from that one package. - A panel may export `peek(state)`; when it returns seconds > 0 `app.js` shows that tab that long and then goes back, unless the page is touched or the tab changed meanwhile. `windows.js` peeks on a window id the last poll - lacked, for `[windows] peek` seconds (0 off). + lacked, for `[windows] peek` seconds (0 off), unless it is a dialog + (floating, its pid already has a window; Hyprland gives no parent). - `music` drives any MPRIS player through `playerctl` (playerctld picks the last active one). A `data:` cover, or a local video with no cover (Haruna sends none), is served at `/api/music/image/`, a video as an `ffmpeg` diff --git a/deckit/modules/windows.py b/deckit/modules/windows.py index 343daad..7df1f8e 100644 --- a/deckit/modules/windows.py +++ b/deckit/modules/windows.py @@ -140,10 +140,15 @@ def _state(run): workspaces = json.loads(run(["hyprctl", "workspaces", "-j"]) or "[]") except json.JSONDecodeError: return {"windows": [], "workspaces": [], "activeClass": None} + clients = [c for c in clients if c.get("mapped", True) and c["workspace"].get("id", 0) > 0] + # ponytail: Hyprland exposes no transient parent, so a dialog is a + # floating window whose process already has another window open. + pids = [c.get("pid") for c in clients] wins = sorted( ({"address": c["address"], "id": c.get("stableId", ""), "class": c["class"], "title": c["title"], - "workspace": c["workspace"]["id"], "active": c["address"] == active} - for c in clients if c.get("mapped", True) and c["workspace"].get("id", 0) > 0), + "workspace": c["workspace"]["id"], "active": c["address"] == active, + "dialog": bool(c.get("floating")) and pids.count(c.get("pid")) > 1} + for c in clients), key=lambda w: (w["workspace"], w["class"])) active_class = next((w["class"] for w in wins if w["active"]), None) return {"windows": wins, diff --git a/static/modules/windows.js b/static/modules/windows.js index d9f388e..0657a16 100644 --- a/static/modules/windows.js +++ b/static/modules/windows.js @@ -166,11 +166,11 @@ export default { }, // A window that was not there on the last poll brings the tab forward for - // [windows] peek seconds. + // [windows] peek seconds; a dialog of an app already open does not. peek(st) { if (!st.windows) return false; const ids = new Set(st.windows.map((w) => w.id)); - const fresh = this._ids != null && [...ids].some((id) => !this._ids.has(id)); + const fresh = this._ids != null && st.windows.some((w) => !w.dialog && !this._ids.has(w.id)); this._ids = ids; return fresh ? st.peek ?? 8 : 0; }, diff --git a/tests/test_windows.mjs b/tests/test_windows.mjs index 534fd45..b985d65 100644 --- a/tests/test_windows.mjs +++ b/tests/test_windows.mjs @@ -25,3 +25,4 @@ assert.equal(windows.peek(st("a")), 0); // a close is not news assert.equal(windows.peek(st("a", "c")), 5); // a new window is, for [windows] peek seconds assert.equal(windows.peek({ error: "x" }), false); // an error keeps what it knew assert.equal(windows.peek(st("a", "c")), 0); +assert.equal(windows.peek({ windows: [{ id: "a" }, { id: "c" }, { id: "d", dialog: true }], peek: 5 }), 0); diff --git a/tests/test_windows.py b/tests/test_windows.py index f05e546..a2a1ff6 100644 --- a/tests/test_windows.py +++ b/tests/test_windows.py @@ -108,6 +108,20 @@ class Commands(unittest.TestCase): st = windows._state(lambda cmd: responses[tuple(cmd)]) self.assertEqual([w["address"] for w in st["windows"]], ["0x1"]) + def test_state_marks_a_floating_window_of_an_open_app_as_dialog(self): + def c(addr, pid, floating): + return {"address": addr, "class": "x", "title": "t", "mapped": True, + "workspace": {"id": 1}, "pid": pid, "floating": floating} + responses = { + ("hyprctl", "clients", "-j"): json.dumps( + [c("0x1", 10, False), c("0x2", 10, True), c("0x3", 20, True)]), + ("hyprctl", "activewindow", "-j"): "{}", + ("hyprctl", "workspaces", "-j"): '[{"id": 1}]', + } + st = windows._state(lambda cmd: responses[tuple(cmd)]) + self.assertEqual({w["address"]: w["dialog"] for w in st["windows"]}, + {"0x1": False, "0x2": True, "0x3": False}) + def test_state_includes_empty_workspaces_and_launch_icons(self): responses = { ("hyprctl", "clients", "-j"): "[]", -- cgit v1.2.3