From b8bfc9d586041bc87fb9d8469b4e6f8673882b1a Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Mon, 5 Jul 2021 19:54:21 +0200 Subject: [PATCH] i3-companion: improve a bit code for new workspaces --- bin/i3-companion | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/i3-companion b/bin/i3-companion index 8e126a6..42098d1 100755 --- a/bin/i3-companion +++ b/bin/i3-companion @@ -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}"')