summaryrefslogtreecommitdiff
path: root/src/caelestia/utils
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-06-11 00:41:05 +1000
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-06-11 00:41:05 +1000
commitf663e6f6908a9dfb05ac22e867e726c1bf6f0960 (patch)
tree4e9a8eaf275a2e145c6384964cdc5f351b49b924 /src/caelestia/utils
parentfeat: impl workspace-action command (diff)
downloadcaelestia-cli-f663e6f6908a9dfb05ac22e867e726c1bf6f0960.tar.gz
caelestia-cli-f663e6f6908a9dfb05ac22e867e726c1bf6f0960.tar.bz2
caelestia-cli-f663e6f6908a9dfb05ac22e867e726c1bf6f0960.zip
internal: refactor for packaging
Package using python-build, python-installer and hatch
Diffstat (limited to 'src/caelestia/utils')
-rw-r--r--src/caelestia/utils/hypr.py27
-rw-r--r--src/caelestia/utils/scheme.py0
2 files changed, 27 insertions, 0 deletions
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
--- /dev/null
+++ b/src/caelestia/utils/scheme.py