sway: Update compact script to take screens into account

This commit is contained in:
Sijmen 2020-08-07 16:42:56 +02:00
parent 127d16e54f
commit 32ca185cd3
Signed by: vijfhoek
GPG key ID: DAF7821E067D9C48

View file

@ -1,11 +1,28 @@
import i3ipc import i3ipc
import sys import sys
from itertools import zip_longest, count from itertools import zip_longest, count
from beeprint import pp
i3 = i3ipc.Connection() 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): def workspace_key(workspace):
name = workspace.split(":", 1)[-1] try:
i3.command(f"rename workspace '{workspace}' to '{i}:{name}'") output_rank = outputs.index(workspace.output)
print(i, name, file=sys.stderr) 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)