8

Is it possible in my i3 startup file to specifically configure a desktop on which to start a program, but only starting it there once without assigning that program to the desktop in general.

I am aware that a solution exists which involves changing to another workspace, but this leaves me with a major issue: As soon as I have a program with a 'non-instant' startup time, that program will appear on the last workspace that I switch to and not on the workspace where I want it to be.

In specific, this my current startup file where I did a workaround involving the assignment of atom (which is the program bothering me atm) to workspace 9, which is ok for now but is undesirable in the long run:

assign [class="Atom"] $workspace9
exec atom

exec --no-startup-id i3-msg 'workspace $workspace9; exec 
/usr/bin/urxvt'
#exec --no-startup-id i3-msg 'workspace $workspace9; exec /usr/bin/atom'
exec --no-startup-id i3-msg 'workspace $workspace1; exec /usr/bin/urxvt'

I would like to get the commented call for atom to execute in the desired way and ditch the assignment method alltogether.

I don't actually think that it is of relevance but just in case: I run Manjaro-Linux, which is based on Arch.

Edit: The following snippet of code works, but still leaves this question open, as it restricts me to open up atom at last and starting my session on that desktop:

#assign [class="Atom"] $workspace9
#exec atom

exec --no-startup-id i3-msg 'workspace $workspace9; exec 
/usr/bin/urxvt'
exec --no-startup-id i3-msg 'workspace $workspace1; exec /usr/bin/urxvt'
exec --no-startup-id i3-msg 'workspace $workspace9; exec /usr/bin/atom'

This also has the significant drawback that it does not allow for multiple programs starting on different workspaces, if they show the same behavior as atom does.

1
  • I run Kde (on debian Gnu/Linux), I have set up some application to display on certain desktops. They would do this no matter how long they took to start-up. May 4, 2017 at 16:40

3 Answers 3

2

Wait until the window appears and then send it to the original workspace:

#!/bin/bash

activeworkspace=$(i3-msg -t get_workspaces | jq -c '.[] | select(.focused) | .name' --raw-output)
atom &
windowname=atom
xprop -spy -root _NET_ACTIVE_WINDOW | \
  while read line ; do 
      if xprop WM_CLASS -id ${line##* } | grep -q $windowname ; then
          i3-msg move "[con_id=\"${line##* }\"]" $activeworkspace
          exit
      fi
  done
  • At first get the active workspace, use jq as an example
  • run your program in the background: atom &
  • Use xprop -spy to 'Examine window properties forever, looking for property change events.'
  • Act on all new active windows with while read line
  • Get WM_CLASS of them with xprop WM_CLASS, extract the windowid with bash ${line##* }
  • Filter with grep $windowname
  • Move the window to the original workspace with i3-msg move ..

You should stay on the active workspace and a window on this workspace should get focused.

It doesn't work when you have multiple atom windows which get focused between the start and the move of a new atom window. In this case you would have to look for the NET_WM_PID atom instead of WM_CLASS.

1

If you're looking to always have specific programs (e.g., Atom) open on particular workspaces, you can use the assign class functionality described in the i3 User Documentation

Run xprop from your terminal, and then click on the window (e.g., Firefox) to see what class it belongs to. Look for WM_CLASS(STRING).

Then, it's as simple as putting the following line in your .config file:

assign [class="Firefox"] 2 

Don't forget to restart your instance using (default) $Mod + Shift + r

Now, Firefox will always open on workspace 2, regardless of where or when I run it. You could do the same with Atom, and this would free you up to start you desktop wherever you wanted to.

0

Your commented out calls do work for applications that support startup notifcations - in fact, the "Start iceweasel on workspace 3 (once)" example in the user's guide has nearly the same exec command:

exec --no-startup-id i3-msg 'workspace 3; exec iceweasel; workspace 1'

Atom however doesn't seem to support startup notifications so you need to keep using the assign method.

1
  • Not quite sure if this is at the root of my problem, as commenting out the assignment and startup of atom, then switching to workspace 9 and starting atom there works, but then I do not have the freedom to start on any workspace I like (see edit above). But thanks for your answer (which unfortunately I cannot upvote right now) as it helped specifying the problem.
    – tifrel
    May 5, 2017 at 8:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .