dotfiles/config/i3/compact.py

28 lines
761 B
Python

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")
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)