From f7307f3ef217b29e225f53c0ec0e099d32a4c1f4 Mon Sep 17 00:00:00 2001 From: fdev31 Date: Thu, 27 Apr 2023 23:24:03 +0200 Subject: [PATCH] allow batch commands --- pyprland/ipc.py | 7 ++++++- pyprland/plugins/workspaces_follow_focus.py | 10 +++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pyprland/ipc.py b/pyprland/ipc.py index 0a24c6b..e1ee7ee 100644 --- a/pyprland/ipc.py +++ b/pyprland/ipc.py @@ -31,7 +31,12 @@ async def hyprctl(command): if DEBUG: print(">>>", command) ctl_reader, ctl_writer = await asyncio.open_unix_connection(HYPRCTL) - ctl_writer.write(f"/dispatch {command}".encode()) + if isinstance(command, list): + ctl_writer.write( + f"[[BATCH]] {' ; '.join('dispatch ' + c for c in command)}".encode() + ) + else: + ctl_writer.write(f"/dispatch {command}".encode()) await ctl_writer.drain() resp = await ctl_reader.read(100) ctl_writer.close() diff --git a/pyprland/plugins/workspaces_follow_focus.py b/pyprland/plugins/workspaces_follow_focus.py index 739f016..ed56de2 100644 --- a/pyprland/plugins/workspaces_follow_focus.py +++ b/pyprland/plugins/workspaces_follow_focus.py @@ -17,12 +17,16 @@ class Extension(Plugin): for mon in await hyprctlJSON("monitors") if mon["name"] != monitor_id ) + workspaces = [w["id"] for w in await hyprctlJSON("workspaces") if w["id"] > 0] - for n in self.workspace_list: + batch: list[str] = [] + for n in workspaces: if n in busy_workspaces or n == workspace_id: continue - await hyprctl(f"moveworkspacetomonitor {n} {monitor_id}") - await hyprctl(f"workspace {workspace_id}") + batch.append(f"moveworkspacetomonitor {n} {monitor_id}") + batch.append(f"workspace {workspace_id}") + + await hyprctl(batch) async def run_change_workspace(self, direction: str): increment = int(direction)