aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--deckit/modules/windows.py2
-rw-r--r--tests/test_windows.py15
2 files changed, 16 insertions, 1 deletions
diff --git a/deckit/modules/windows.py b/deckit/modules/windows.py
index edca5b5..343daad 100644
--- a/deckit/modules/windows.py
+++ b/deckit/modules/windows.py
@@ -143,7 +143,7 @@ def _state(run):
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"]["id"] > 0),
+ for c in clients if c.get("mapped", True) and c["workspace"].get("id", 0) > 0),
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/tests/test_windows.py b/tests/test_windows.py
index 6950152..f05e546 100644
--- a/tests/test_windows.py
+++ b/tests/test_windows.py
@@ -93,6 +93,21 @@ class Commands(unittest.TestCase):
st = windows._state(lambda cmd: responses[tuple(cmd)])
self.assertEqual(st["workspaces"], [1, 2, 5])
+ def test_state_skips_a_special_workspace_without_id(self):
+ # Hyprland lists a special workspace with no "id"; one such window
+ # used to raise KeyError on every poll and freeze the tab.
+ special = {"address": "0x2", "class": "conky", "title": "c", "mapped": True,
+ "workspace": {"name": "special:dash"}}
+ normal = {"address": "0x1", "class": "kitty", "title": "t", "mapped": True,
+ "workspace": {"id": 1}}
+ responses = {
+ ("hyprctl", "clients", "-j"): json.dumps([special, normal]),
+ ("hyprctl", "activewindow", "-j"): "{}",
+ ("hyprctl", "workspaces", "-j"): '[{"id": 1}]',
+ }
+ st = windows._state(lambda cmd: responses[tuple(cmd)])
+ self.assertEqual([w["address"] for w in st["windows"]], ["0x1"])
+
def test_state_includes_empty_workspaces_and_launch_icons(self):
responses = {
("hyprctl", "clients", "-j"): "[]",