Dotfiles/desktopenvs/hyprdrive/horizon-dock/windows.py

28 lines
1.1 KiB
Python

"""Open-window data source — synchronous `hyprctl clients -j`, same pattern as
orbit-menu/menu_tree.py's _hyprctl_json (a local unix-socket round trip, cheap
enough to call straight from the UI thread; refreshed each time the dock is
revealed, not polled continuously)."""
from __future__ import annotations
import json
import subprocess
def open_windows() -> list[dict]:
try:
out = subprocess.run(["hyprctl", "clients", "-j"], capture_output=True,
text=True, timeout=1.5, check=True).stdout
clients = json.loads(out)
except (subprocess.SubprocessError, json.JSONDecodeError, OSError):
return []
wins = [w for w in clients if w.get("mapped", True) and w.get("class")]
wins.sort(key=lambda w: (w.get("workspace", {}).get("id", 0),
(w.get("title") or w.get("class") or "").lower()))
return wins
def focus_window(address: str) -> None:
subprocess.Popen(["hyprctl", "dispatch", f'hl.dsp.focus({{ window = "address:{address}" }})'],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)