From f0c47af02ead9a3cfd9952042e5334f52cff469f Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Mon, 5 Jul 2021 19:07:41 +0200 Subject: [PATCH] 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. --- bin/i3-companion | 15 +++++++++++++++ config | 1 + 2 files changed, 16 insertions(+) diff --git a/bin/i3-companion b/bin/i3-companion index b205833..7be8f22 100755 --- a/bin/i3-companion +++ b/bin/i3-companion @@ -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) diff --git a/config b/config index b275e0d..d97574e 100644 --- a/config +++ b/config @@ -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