i3-companion: also offer possibility to move a window to a new workspace

This commit is contained in:
Vincent Bernat 2021-07-05 19:52:25 +02:00
parent 334f77449c
commit c5b2baca1e
2 changed files with 9 additions and 2 deletions

View file

@ -114,15 +114,21 @@ def workspace_rename(i3, event):
def new_workspace(i3, event):
"""Create a new workspace."""
if event.payload != "new-workspace":
if event.payload not in {"new-workspace", "move-to-new-workspace"}:
return
if event.payload == "move-to-new-workspace":
current = i3.get_tree().find_focused()
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 event.payload == "move-to-new-workspace":
current.command(f'move container to workspace number "{available}"')
if __name__ == "__main__":
options = parse_args()
@ -137,7 +143,7 @@ if __name__ == "__main__":
Event.WINDOW_CLOSE}:
i3.on(event, workspace_rename)
# Create a new workspace
# Create a new workspace or move to a new workspace
i3.on(Event.TICK, new_workspace)
i3.main()

1
config
View file

@ -135,6 +135,7 @@ bindsym $mod+Shift+8 move container to workspace number $ws8
bindsym $mod+Shift+9 move container to workspace number $ws9
bindsym $mod+Shift+0 move container to workspace number $ws10
bindsym $mod+Shift+o move workspace to output right
bindsym $mod+Shift+n exec i3-msg -t send_tick move-to-new-workspace
# reload/restart
bindsym $mod+Shift+c reload