mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-06-28 12:30:01 +02:00
i3-companion: move create_new_workspace into helper section
This commit is contained in:
parent
cc07dc35b4
commit
b6ab2d3c12
1 changed files with 13 additions and 12 deletions
|
@ -262,6 +262,17 @@ def polybar(module, content):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
async def create_new_workspace(i3):
|
||||||
|
"""Create a new workspace and returns its number."""
|
||||||
|
workspaces = await i3.get_workspaces()
|
||||||
|
workspace_nums = {w.num for w in workspaces}
|
||||||
|
max_num = max(workspace_nums)
|
||||||
|
available = (set(range(1, max_num + 2)) - workspace_nums).pop()
|
||||||
|
logger.info(f"create new workspace number {available}")
|
||||||
|
await i3.command(f'workspace number "{available}"')
|
||||||
|
return available
|
||||||
|
|
||||||
|
|
||||||
# Event handlers
|
# Event handlers
|
||||||
|
|
||||||
|
|
||||||
|
@ -293,16 +304,6 @@ async def workspace_rename(i3, event):
|
||||||
await i3.command(";".join(commands))
|
await i3.command(";".join(commands))
|
||||||
|
|
||||||
|
|
||||||
async def _new_workspace(i3):
|
|
||||||
workspaces = await i3.get_workspaces()
|
|
||||||
workspace_nums = {w.num for w in workspaces}
|
|
||||||
max_num = max(workspace_nums)
|
|
||||||
available = (set(range(1, max_num + 2)) - workspace_nums).pop()
|
|
||||||
logger.info(f"create new workspace number {available}")
|
|
||||||
await i3.command(f'workspace number "{available}"')
|
|
||||||
return available
|
|
||||||
|
|
||||||
|
|
||||||
@on(CommandEvent("new-workspace"), CommandEvent("move-to-new-workspace"))
|
@on(CommandEvent("new-workspace"), CommandEvent("move-to-new-workspace"))
|
||||||
async def new_workspace(i3, event):
|
async def new_workspace(i3, event):
|
||||||
"""Create a new workspace and optionally move a window to it."""
|
"""Create a new workspace and optionally move a window to it."""
|
||||||
|
@ -313,7 +314,7 @@ async def new_workspace(i3, event):
|
||||||
if not current:
|
if not current:
|
||||||
return
|
return
|
||||||
|
|
||||||
num = await _new_workspace(i3)
|
num = await create_new_workspace(i3)
|
||||||
|
|
||||||
# Move the window to this workspace
|
# Move the window to this workspace
|
||||||
if event == "move-to-new-workspace":
|
if event == "move-to-new-workspace":
|
||||||
|
@ -377,7 +378,7 @@ async def workspace_exclusive(i3, event):
|
||||||
num = next(iter(candidate_workspaces))
|
num = next(iter(candidate_workspaces))
|
||||||
else:
|
else:
|
||||||
# Create a new workspace
|
# Create a new workspace
|
||||||
num = await _new_workspace(i3)
|
num = await create_new_workspace(i3)
|
||||||
|
|
||||||
logger.info(f"move window {w.window_class} to workspace {num}")
|
logger.info(f"move window {w.window_class} to workspace {num}")
|
||||||
await w.command(f'move container to workspace number "{num}", focus')
|
await w.command(f'move container to workspace number "{num}", focus')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue