The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
0

insert new workspace

asked 2013-09-26 21:31:42 +0000

urban gravatar image

Hi all, I'm a new i3 user. I switched from fluxbox a couple of weeks ago and I'm really happy with i3!

My question: Is it possible to insert a new workspace between existing workspaces? Say I have stuff on workspaces 1, 2, 3 and 4. For some reason I'd like to push some window from workspace 2 to the workspace next to it, i.e. to workspace 3. However, I don't want my new window to be on workspace 3 mixed with all the other junk I had there. Rather I want my new window to be on a clean workspace 3, and the old workspaces 3 and 4 to be renumbered to 4 and 5.

Thanks!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2013-09-27 20:29:35 +0000

urban gravatar image

updated 2013-12-08 22:53:14 +0000

Ok! I'll give it a try and post here once I've sort of got it.

Update! (Dec 8 2013)

Hi again, today I looked into this and wrote the following code using i3-py. It does what I want, but I'm sure it can be done simpler. I haven't used python before why I am appreciating any comments for improving that.

import imp
i3=imp.load_source('i3','/home/urban/i3/i3-py/i3-py-master/i3.py')

# get current workspace no
workspaces = i3.get_workspaces()
for workspace in workspaces:
    if (workspace['visible']):
        currentno=workspace['num']

# next workspace no
nextno=currentno+1
exists=i3.filter(num=nextno)

# get focused windows
focused=i3.filter(nodes=[],focused=True)

# loop over all workspaces with higher number than the current one if
# nextno has windows
if exists
    for workspace in reversed(workspaces):
        if (workspace['num']>currentno):
            i3.command('workspace',str(workspace['num']))
            i3.command('rename','workspace','to',str(workspace['num']+1))

# move focused windows to next workspace
for window in focused:
    i3.focus(con_id=window['id'])
    i3.command('move','window','to','workspace',str(nextno))

# go to next (optional)
i3.command('workspace',str(nextno))
edit flag offensive delete link more
0

answered 2013-09-27 06:15:47 +0000

Michael gravatar image

You can do that using the IPC interface, for example with this sequence of commands:

i3-msg workspace 4
i3-msg rename workspace to 5
i3-msg workspace 3
i3-msg rename workspace to 4
i3-msg workspace 3

Of course you should add some sanity checking and edge case handling, this is only to give you a rough idea.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-09-26 21:31:42 +0000

Seen: 550 times

Last updated: Dec 08 '13