summaryrefslogtreecommitdiffstats
path: root/hyprsunset_qt/daemon.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-07-17 10:34:54 +0200
committerDanilo M. <danix@danix.xyz>2026-07-17 10:34:54 +0200
commitebdf809e0723ba3d32794278c72e4cd844cea498 (patch)
tree38433f3f7f1b092f698814ecf195bff4c61083f5 /hyprsunset_qt/daemon.py
parentfc4b8ae587fa5a26648c2bb94e61141d2954f9aa (diff)
downloadhyprsunset-qt-ebdf809e0723ba3d32794278c72e4cd844cea498.tar.gz
hyprsunset-qt-ebdf809e0723ba3d32794278c72e4cd844cea498.zip
feat: daemon status, restart, live preview
Add daemon.py module to control hyprsunset daemon via subprocess: - is_running() checks daemon status using pgrep - live_preview() pushes temperature/gamma/identity to running daemon via hyprctl - restart() kills existing daemon and launches new detached process All subprocess calls are mocked in tests; no real processes are touched. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'hyprsunset_qt/daemon.py')
-rw-r--r--hyprsunset_qt/daemon.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/hyprsunset_qt/daemon.py b/hyprsunset_qt/daemon.py
new file mode 100644
index 0000000..7bf0e47
--- /dev/null
+++ b/hyprsunset_qt/daemon.py
@@ -0,0 +1,45 @@
+"""Control the hyprsunset daemon: status, restart, live preview via hyprctl."""
+
+from __future__ import annotations
+
+import shlex
+import subprocess
+from typing import Optional
+
+
+def is_running() -> bool:
+ return subprocess.run(
+ ["pgrep", "-x", "hyprsunset"],
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ ).returncode == 0
+
+
+def live_preview(
+ temperature: Optional[int] = None,
+ gamma: Optional[float] = None,
+ identity: bool = False,
+) -> None:
+ """Push values to the running daemon over IPC. No file write, no restart."""
+ if identity:
+ subprocess.run(["hyprctl", "hyprsunset", "identity"], check=False)
+ return
+ if temperature is not None:
+ subprocess.run(
+ ["hyprctl", "hyprsunset", "temperature", str(temperature)],
+ check=False,
+ )
+ if gamma is not None:
+ # IPC gamma is integer percent; profile gamma is a 0-2 float.
+ pct = str(round(gamma * 100))
+ subprocess.run(["hyprctl", "hyprsunset", "gamma", pct], check=False)
+
+
+def restart(command: str = "hyprsunset") -> None:
+ subprocess.run(["pkill", "hyprsunset"], check=False)
+ subprocess.Popen(
+ shlex.split(command),
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ start_new_session=True,
+ )