Add workspace compacting script

shifts workspace numbers down to fill empty workspaces
This commit is contained in:
Adam Goldsmith 2017-08-14 02:04:39 -04:00
parent f63ffa5ad5
commit 68786a6d08
2 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,20 @@
#!/usr/bin/env python3
import subprocess
import json
workspaces = json.loads(subprocess.run(["i3-msg", "-t", "get_workspaces"], stdout=subprocess.PIPE).stdout)
numbered_workspaces = [ws for ws in workspaces if ws['num'] != -1]
#focused = next(ws for ws in workspaces if ws['focused'] == True)
maximum_ws = max(numbered_workspaces, key=lambda ws: ws['num'])
# loop through all possible workspace numbers
for ws_num in range(1, maximum_ws['num']):
# if workspace with current number doesn't exist
# TODO: handle multiple missing workspaces (consecutive or not)
if next((ws for ws in numbered_workspaces if ws['num'] == ws_num), None) is None:
# loop through all greater numbers and move down 1
for ws in [ws for ws in numbered_workspaces if ws['num'] > ws_num]:
new_name = ws['name'].split(":")
new_name[0] = str(int(new_name[0]) - 1) # subtract 1 from workspace number
subprocess.run(["i3-msg", "rename", "workspace",
ws['name'], "to", ":".join(new_name)])

View File

@ -241,6 +241,8 @@ mode "resize" {
bindsym l resize shrink height 10 px or 10 ppt bindsym l resize shrink height 10 px or 10 ppt
bindsym semicolon resize grow width 10 px or 10 ppt bindsym semicolon resize grow width 10 px or 10 ppt
bindsym c exec --no-startup-id /home/adam/.config/i3/compact_workspace_numbers.py
# same bindings, but for the arrow keys # same bindings, but for the arrow keys
bindsym Left resize shrink width 10 px or 10 ppt bindsym Left resize shrink width 10 px or 10 ppt
bindsym Down resize grow height 10 px or 10 ppt bindsym Down resize grow height 10 px or 10 ppt