The i3 FAQ has migrated to https://www.reddit.com/r/i3wm/. All content here is read-only.
Ask Your Question
1

Open new window in specific workspace and focus

asked 2013-07-04 11:49:55 +0000

Tom Francart gravatar image

Hello,

How can I open a new window in a specific workspace? My use case is that I'd my pdf viewer to always open in workspace 5, switch to that workspace, and focus the window.

I've tried the following solutions:

  • assign [class="^Evince$"] "5: doc"

This works, but does not switch to workspace 5, nor focusses the new window. My workspace 5 is in tabbed layout, and new windows tend to open underneath the currently selected tab.

  • write a script that starts the pdf viewer, then runs

i3-msg move container to workspace "5: doc"

i3-msg workspace "5: doc"

The trouble here is that depending on the currently focussed window and how long the pdf viewer takes to start, the wrong window is moved to workspace 5. I.e., there is no control over which window the i3-msg commands operate on. Note that there may be multiple instances with [class="^Evince$"], so I cannot simply use that.

best regards, Tom

edit retag flag offensive close merge delete

3 answers

Sort by » oldest newest most voted
1

answered 2013-11-17 15:23:12 +0000

Adaephon gravatar image

A script is not needed when you know beforehand what the window class is going to be. Just add the following to your configuration:

assign [class="^Evince$"] 5: doc
for_window [class="^Evince$"] focus

for_window acts on any new window with matching criteria and will not affect already existing windows.

edit flag offensive delete link more

Comments

Well how do you use assign with i3-msg? Because putting i3-msg in front of that assign command doesn't seem to work from the CLI.

paramnesioid gravatar imageparamnesioid ( 2013-11-18 01:34:21 +0000 )edit

Okay, just to answer my own question: i3-msg [class="xyz"] move to workspace abc

paramnesioid gravatar imageparamnesioid ( 2013-12-25 01:39:03 +0000 )edit
0

answered 2013-07-13 14:03:08 +0000

ack006 gravatar image

updated 2013-07-15 16:07:47 +0000

I've a solution which works precisely as asked (using i3 version 4.5.1-87-g8677936, YMMV):

In ${HOME}/.i3/config, add

for_window [class="Evince"] rename workspace 5 to "5: doc", move container to workspace "5: doc", workspace "5: doc", focus

This uses ',' to create a command list (remove the rename if that isn't what you need). As far as I can tell, the scope for the entire command list is set by the for_window directive, so the commands in the list are only executed when for_window actually matches something.

I've tested it by:

  • starting 'gedit' in workspace 5 (obviously an unrelated application meant for illustration)
  • switching that workspace to tabbed mode to make the focus more obvious
  • switching to workspace 1
  • starting evince

My screen switched to workspace "5: doc" showing evince focussed in its tab, just as you asked. Note that gedit, which was on workspace 5 before it got renamed, now is also on workspace "5: doc" but doesn't have focus.

edit flag offensive delete link more

Comments

The `focus` is possibly redundant, as it appears that i3 focusses any newly moved window in a workspace when you switch to that workspace.

ack006 gravatar imageack006 ( 2013-07-13 14:08:07 +0000 )edit
1

Note that you should use comma (,) instead of semicolon (;) here. With semicolon, the criterion is lost, i.e. the commands will be executed for the active window instead of the matched window. It won’t really matter, but to make it perfect, comma is the better choice.

Michael gravatar imageMichael ( 2013-07-14 13:21:48 +0000 )edit

Thanks for the tip! I've edite my answer accordingly.

ack006 gravatar imageack006 ( 2013-07-15 16:02:13 +0000 )edit
0

answered 2013-07-04 12:17:40 +0000

V0id gravatar image

updated 2013-07-04 12:18:03 +0000

Keep your assignment:

assign [class="^Evince$"] "5: doc"

And use a similar script (you may want to give it some arguments):

#!/bin/sh
i3-msg 'exec evince'
# sleep time depends on the application you launch
sleep 1
# will focus the most recent window of that class
i3-msg '[class="^Evince$"] focus'
edit flag offensive delete link more

Comments

Thank you, works fine!

Tom Francart gravatar imageTom Francart ( 2013-07-04 12:39:56 +0000 )edit

Question Tools

Stats

Asked: 2013-07-04 11:49:55 +0000

Seen: 5,425 times

Last updated: Nov 17 '13