From f663e6f6908a9dfb05ac22e867e726c1bf6f0960 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Wed, 11 Jun 2025 00:41:05 +1000 Subject: internal: refactor for packaging Package using python-build, python-installer and hatch --- src/caelestia/utils/hypr.py | 27 +++++++++++++++++++++++++++ src/caelestia/utils/scheme.py | 0 2 files changed, 27 insertions(+) create mode 100644 src/caelestia/utils/hypr.py create mode 100644 src/caelestia/utils/scheme.py (limited to 'src/caelestia/utils') diff --git a/src/caelestia/utils/hypr.py b/src/caelestia/utils/hypr.py new file mode 100644 index 0000000..d829f22 --- /dev/null +++ b/src/caelestia/utils/hypr.py @@ -0,0 +1,27 @@ +import json as j +import os +import socket + +socket_path = f"{os.getenv('XDG_RUNTIME_DIR')}/hypr/{os.getenv('HYPRLAND_INSTANCE_SIGNATURE')}/.socket.sock" + + +def message(msg: str, json: bool = True) -> str or dict[str, any]: + with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock: + sock.connect(socket_path) + + if json: + msg = f"j/{msg}" + sock.send(msg.encode()) + + resp = sock.recv(8192).decode() + while True: + new_resp = sock.recv(8192) + if not new_resp: + break + resp += new_resp.decode() + + return j.loads(resp) if json else resp + + +def dispatch(dispatcher: str, *args: list[any]) -> bool: + return message(f"dispatch {dispatcher} {' '.join(str(a) for a in args)}".rstrip(), json=False) == "ok" diff --git a/src/caelestia/utils/scheme.py b/src/caelestia/utils/scheme.py new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3-freya