mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-06-30 05:14:22 +02:00
i3-companion: improve a bit code for new workspaces
This commit is contained in:
parent
c5b2baca1e
commit
b8bfc9d586
1 changed files with 6 additions and 1 deletions
|
@ -113,19 +113,24 @@ def workspace_rename(i3, event):
|
|||
|
||||
|
||||
def new_workspace(i3, event):
|
||||
"""Create a new workspace."""
|
||||
"""Create a new workspace and optionally move a window to it."""
|
||||
if event.payload not in {"new-workspace", "move-to-new-workspace"}:
|
||||
return
|
||||
|
||||
# Get the currently focused window
|
||||
if event.payload == "move-to-new-workspace":
|
||||
current = i3.get_tree().find_focused()
|
||||
if not current:
|
||||
return
|
||||
|
||||
# Create a new workspace
|
||||
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}"')
|
||||
|
||||
# Move the window to this workspace
|
||||
if event.payload == "move-to-new-workspace":
|
||||
current.command(f'move container to workspace number "{available}"')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue