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

How to launch an application on a different workspace with cwd preserved

asked 2013-06-18 12:56:25 +0000

kynan gravatar image

Assume the following situation (which is my normal way of working): 2 displays, a full screen terminal with tmux on workspace 1 on display 1. When launching a X application from that terminal it will open "in the background" of workspace 1 since the full screen terminal is always on top.

What I'm looking for is a convenient way (i.e. something I can bind to a shell alias/function) to launch an application on workspace N on display 2 instead. Ideally I'd also like to preserve my current working directory.

I got some of the way using:

i3 "workspace N; exec cd `pwd` && cmd"

This will however still launch a new workspace on the same display. Is there a more elegant way of doing this?

edit retag flag offensive close merge delete

Comments

There is a talk here on launching terminals on specific path: https://faq.i3wm.org/question/150/how-to-launch-a-terminal-from-here/

bruno.braga gravatar imagebruno.braga ( 2013-06-18 14:16:44 +0000 )edit

Thanks, I've seen that, but it only solves a small part of the problem.

kynan gravatar imagekynan ( 2013-06-18 15:01:53 +0000 )edit

You could try to explicitly bind some workspaces to the second display in your config file using "workspace <n> output <output>" where <n> is the number and <output> is the display name (you get it e.g. via xrandr). However, maybe not the solution you are looking for...

mschaefer gravatar imagemschaefer ( 2013-06-20 09:59:34 +0000 )edit

why not? If you can preserve the cwd location, then you can just define the i3 config to react when your terminal window is created, such as moving to a specific workspace...

bruno.braga gravatar imagebruno.braga ( 2013-06-20 22:37:09 +0000 )edit

but if you want different behavior (this time move to w1, now w3, and so on), the only way would be to bind different terminal launch keys with named windows (urxvt), running the script to preserve the cwd, and then assigning the particular window to a specific workspace in i3 config.

bruno.braga gravatar imagebruno.braga ( 2013-06-20 22:39:55 +0000 )edit

2 answers

Sort by » oldest newest most voted
1

answered 2014-11-30 21:15:40 +0000

Michael Rose gravatar image

you could do i3-msg focus output foo; i3-msg workspace bar which will create a workspace bar on the desired outout. You could also simply cause certain programs to be assigned to start on certain workspaces and assign certain workspaces to be on certain monitors.

If its not desirable to do so as you want to start a certain app on multiple workspaces you could write a function to start a program on a particular ws.

Example in fish shell function starton set ws $argv[1] set program $argv[2..-1] & set num (instances-of $program) ws $ws eval $program while test (instances-of $program) -le $num sleep 0.25 end end

function instances-of count (wmctrl -lxp | grep -i $argv) end

instances-of is using wmctrl to count the number of windows present of the given program.

starton switches to the desired workspace, evals the program and doesn't terminate until wmctrl reports that the number of instances of said program is greater. This is so you can starton foo someprogram; starton bar someotherprogram wherein program takes some time to startup without ending up with all windows stuck on the last ws. May need some work.

edit flag offensive delete link more
0

answered 2014-12-06 22:28:32 +0000

Michael gravatar image

If you always use only precisely two outputs, this should work:

i3 "focus output right; workspace N; exec cd `pwd` && cmd"

If you’re using more than two outputs, you’ll need to specify the output name and have some custom script around that i3 command which figures out the topology.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-06-18 12:56:25 +0000

Seen: 1,173 times

Last updated: Dec 06 '14