From 32ca185cd39f2caa5aa875a84629cf7a9c23a39d Mon Sep 17 00:00:00 2001 From: Sijmen Schoon Date: Fri, 7 Aug 2020 16:42:56 +0200 Subject: [PATCH] sway: Update compact script to take screens into account --- config/i3/compact.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/config/i3/compact.py b/config/i3/compact.py index 160ac16..4d4ecd2 100644 --- a/config/i3/compact.py +++ b/config/i3/compact.py @@ -1,11 +1,28 @@ import i3ipc import sys from itertools import zip_longest, count +from beeprint import pp i3 = i3ipc.Connection() +outputs = ("DP-2", "HDMI-A-1", "DP-3") -workspaces = (w.name for w in i3.get_workspaces()) -for i, workspace in zip(count(1), workspaces): - name = workspace.split(":", 1)[-1] - i3.command(f"rename workspace '{workspace}' to '{i}:{name}'") - print(i, name, file=sys.stderr) + +def workspace_key(workspace): + try: + output_rank = outputs.index(workspace.output) + except ValueError: + output_rank = 1000 + + return (output_rank, workspace.name) + + +workspaces = sorted(i3.get_workspaces(), key=workspace_key) +number = 0 +for i, workspace in enumerate(workspaces): + number += 1 + if i > 0 and workspaces[i - 1].output != workspaces[i].output: + number += 1 + + name = (":" + workspace.name.split(":", 1)[-1]) if ":" in workspace.name else "" + i3.command(f"rename workspace '{workspace.name}' to '{number}{name}'") + print(number, name, file=sys.stderr)