summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/caelestia/subcommands/pip.py35
-rw-r--r--src/caelestia/utils/hypr.py4
2 files changed, 37 insertions, 2 deletions
diff --git a/src/caelestia/subcommands/pip.py b/src/caelestia/subcommands/pip.py
index 37f9a2b..5f1b5fa 100644
--- a/src/caelestia/subcommands/pip.py
+++ b/src/caelestia/subcommands/pip.py
@@ -1,5 +1,9 @@
+import re
+import socket
from argparse import Namespace
+from caelestia.utils import hypr
+
class Command:
args: Namespace
@@ -8,4 +12,33 @@ class Command:
self.args = args
def run(self) -> None:
- pass
+ if self.args.daemon:
+ self.daemon()
+ else:
+ win = hypr.message("activewindow")
+ if win["floating"]:
+ self.handle_window(win["address"], win["workspace"]["name"])
+
+ def handle_window(self, address: str, ws: str) -> None:
+ mon_id = next(w for w in hypr.message("workspaces") if w["name"] == ws)["monitorID"]
+ mon = next(m for m in hypr.message("monitors") if m["id"] == mon_id)
+ width, height = next(c for c in hypr.message("clients") if c["address"] == address)["size"]
+
+ scale_factor = mon["height"] / 4 / height
+ scaled_win_size = f"{int(width * scale_factor)} {int(height * scale_factor)}"
+ off = min(mon["width"], mon["height"]) * 0.03
+ move_to = f"{int(mon['width'] - off - width * scale_factor)} {int(mon['height'] - off - height * scale_factor)}"
+
+ hypr.dispatch("resizewindowpixel", "exact", f"{scaled_win_size},address:{address}")
+ hypr.dispatch("movewindowpixel", "exact", f"{move_to},address:{address}")
+
+ def daemon(self) -> None:
+ with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
+ sock.connect(hypr.socket2_path)
+
+ while True:
+ data = sock.recv(4096).decode()
+ if data.startswith("openwindow>>"):
+ address, ws, cls, title = data[12:].split(",")
+ if re.match(r"^[Pp]icture(-| )in(-| )[Pp]icture$", title):
+ self.handle_window(f"0x{address}", ws)
diff --git a/src/caelestia/utils/hypr.py b/src/caelestia/utils/hypr.py
index 3ba89cf..f89cd98 100644
--- a/src/caelestia/utils/hypr.py
+++ b/src/caelestia/utils/hypr.py
@@ -2,7 +2,9 @@ import json as j
import os
import socket
-socket_path = f"{os.getenv('XDG_RUNTIME_DIR')}/hypr/{os.getenv('HYPRLAND_INSTANCE_SIGNATURE')}/.socket.sock"
+socket_base = f"{os.getenv('XDG_RUNTIME_DIR')}/hypr/{os.getenv('HYPRLAND_INSTANCE_SIGNATURE')}"
+socket_path = f"{socket_base}/.socket.sock"
+socket2_path = f"{socket_base}/.socket2.sock"
def message(msg: str, json: bool = True) -> str | dict[str, any]: