i3-companion: add a command to open a new workspace

This is quite a generic idea: use tick to trigger some actions without
spawning a whole Python process.
This commit is contained in:
Vincent Bernat 2021-07-05 19:07:41 +02:00
parent 84db9ccb13
commit f0c47af02e
2 changed files with 16 additions and 0 deletions

View file

@ -112,6 +112,18 @@ def workspace_rename(i3, event):
i3.command(';'.join(commands))
def new_workspace(i3, event):
"""Create a new workspace."""
if event.payload != "new-workspace":
return
workspace_nums = {w.num for w in i3.get_workspaces()}
max_num = max(workspace_nums)
available = (set(range(1, max_num + 2)) - workspace_nums).pop()
logger.info(f'create new workspace number {available}')
i3.command(f'workspace number "{available}"')
if __name__ == "__main__":
options = parse_args()
setup_logging(options)
@ -125,6 +137,9 @@ if __name__ == "__main__":
Event.WINDOW_CLOSE}:
i3.on(event, workspace_rename)
# Create a new workspace
i3.on(Event.TICK, new_workspace)
i3.main()
except Exception as e:
logger.exception("%s", e)

1
config
View file

@ -121,6 +121,7 @@ bindsym $mod+8 workspace number $ws8
bindsym $mod+9 workspace number $ws9
bindsym $mod+0 workspace number $ws10
bindsym $mod+Tab workspace back_and_forth
bindsym $mod+n exec i3-msg -t send_tick new-workspace
# move focused container to workspace
bindsym $mod+Shift+1 move container to workspace number $ws1