diff --git a/pyprland/command.py b/pyprland/command.py index ad20d9f..59aa7df 100755 --- a/pyprland/command.py +++ b/pyprland/command.py @@ -65,7 +65,7 @@ class Pyprland: print(f"EVT {full_name}({params.strip()})") await self._callHandler(full_name, params) - async def read_command(self, reader, writer): + async def read_command(self, reader, writer) -> None: data = (await reader.readline()).decode() if not data: print("Server starved") diff --git a/pyprland/ipc.py b/pyprland/ipc.py index 0243e62..1ddb300 100644 --- a/pyprland/ipc.py +++ b/pyprland/ipc.py @@ -16,6 +16,7 @@ async def get_event_stream(): async def hyprctlJSON(command) -> list[dict[str, Any]] | dict[str, Any]: + """Run an IPC command and return the JSON output.""" if DEBUG: print("(JS)>>>", command) ctl_reader, ctl_writer = await asyncio.open_unix_connection(HYPRCTL) @@ -29,7 +30,8 @@ async def hyprctlJSON(command) -> list[dict[str, Any]] | dict[str, Any]: return ret -async def hyprctl(command, base_command="dispatch"): +async def hyprctl(command, base_command="dispatch") -> bool: + """Run an IPC command. Returns success value.""" if DEBUG: print(">>>", command) ctl_reader, ctl_writer = await asyncio.open_unix_connection(HYPRCTL) @@ -45,13 +47,13 @@ async def hyprctl(command, base_command="dispatch"): await ctl_writer.wait_closed() if DEBUG: print("<<<", resp) - r = resp == b"ok" * (len(resp) // 2) + r: bool = resp == b"ok" * (len(resp) // 2) if DEBUG and not r: print(f"FAILED {resp}") return r -async def get_focused_monitor_props(): +async def get_focused_monitor_props() -> dict[str, Any]: for monitor in await hyprctlJSON("monitors"): assert isinstance(monitor, dict) if monitor.get("focused") == True: diff --git a/pyprland/plugins/scratchpads.py b/pyprland/plugins/scratchpads.py index dc8dbf7..1e4e28b 100644 --- a/pyprland/plugins/scratchpads.py +++ b/pyprland/plugins/scratchpads.py @@ -14,10 +14,60 @@ DEFAULT_MARGIN = 60 async def get_client_props_by_pid(pid: int): for client in await hyprctlJSON("clients"): + assert isinstance(client, dict) if client.get("pid") == pid: return client +class Animations: + @classmethod + async def fromtop(cls, monitor, client, client_uid, margin): + mon_x = monitor["x"] + mon_y = monitor["y"] + mon_width = monitor["width"] + + client_width = client["size"][0] + margin_x = int((mon_width - client_width) / 2) + mon_x + await hyprctl(f"movewindowpixel exact {margin_x} {mon_y + margin},{client_uid}") + + @classmethod + async def frombottom(cls, monitor, client, client_uid, margin): + mon_x = monitor["x"] + mon_y = monitor["y"] + mon_width = monitor["width"] + mon_height = monitor["height"] + + client_width = client["size"][0] + client_height = client["size"][1] + margin_x = int((mon_width - client_width) / 2) + mon_x + await hyprctl( + f"movewindowpixel exact {margin_x} {mon_y + mon_height - client_height - margin},{client_uid}" + ) + + @classmethod + async def fromleft(cls, monitor, client, client_uid, margin): + mon_y = monitor["y"] + mon_height = monitor["height"] + + client_height = client["size"][1] + margin_y = int((mon_height - client_height) / 2) + mon_y + + await hyprctl(f"movewindowpixel exact {margin} {margin_y},{client_uid}") + + @classmethod + async def fromright(cls, monitor, client, client_uid, margin): + mon_y = monitor["y"] + mon_width = monitor["width"] + mon_height = monitor["height"] + + client_width = client["size"][0] + client_height = client["size"][1] + margin_y = int((mon_height - client_height) / 2) + mon_y + await hyprctl( + f"movewindowpixel exact {mon_width - client_width - margin} {margin_y},{client_uid}" + ) + + class Scratch: def __init__(self, uid, opts): self.uid = uid @@ -210,49 +260,6 @@ class Extension(Plugin): if uid not in self.transitioning_scratches: await hyprctl(f"movetoworkspacesilent special:scratch,{pid}") - async def _animation_fromtop(self, monitor, client, client_uid, margin): - mon_x = monitor["x"] - mon_y = monitor["y"] - mon_width = monitor["width"] - - client_width = client["size"][0] - margin_x = int((mon_width - client_width) / 2) + mon_x - await hyprctl(f"movewindowpixel exact {margin_x} {mon_y + margin},{client_uid}") - - async def _animation_frombottom(self, monitor, client, client_uid, margin): - mon_x = monitor["x"] - mon_y = monitor["y"] - mon_width = monitor["width"] - mon_height = monitor["height"] - - client_width = client["size"][0] - client_height = client["size"][1] - margin_x = int((mon_width - client_width) / 2) + mon_x - await hyprctl( - f"movewindowpixel exact {margin_x} {mon_y + mon_height - client_height - margin},{client_uid}" - ) - - async def _animation_fromleft(self, monitor, client, client_uid, margin): - mon_y = monitor["y"] - mon_height = monitor["height"] - - client_height = client["size"][1] - margin_y = int((mon_height - client_height) / 2) + mon_y - - await hyprctl(f"movewindowpixel exact {margin} {margin_y},{client_uid}") - - async def _animation_fromright(self, monitor, client, client_uid, margin): - mon_y = monitor["y"] - mon_width = monitor["width"] - mon_height = monitor["height"] - - client_width = client["size"][0] - client_height = client["size"][1] - margin_y = int((mon_height - client_height) / 2) + mon_y - await hyprctl( - f"movewindowpixel exact {mon_width - client_width - margin} {margin_y},{client_uid}" - ) - async def run_show(self, uid, force=False): uid = uid.strip() item = self.scratches.get(uid) @@ -287,7 +294,7 @@ class Extension(Plugin): await hyprctl(f"movetoworkspacesilent {wrkspc},{pid}") if animation_type: margin = item.conf.get("margin", DEFAULT_MARGIN) - fn = getattr(self, "_animation_%s" % animation_type) + fn = getattr(Animations, animation_type) await fn(monitor, item.clientInfo, pid, margin) await hyprctl(f"focuswindow {pid}")