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

Race condition for startup applications?

asked 2014-02-27 04:03:56 +0000

Pinyaka gravatar image

I am using i3 version 4.7.2 (Debian Jessie) and am having problems getting programs to start up on appropriate workspaces. For the life of me, it looks like any program which has a delay between execution and start will end up on whatever workspace is selected when the window finally gets drawn. For instance, if I drop to the cli and run

i3-msg 'workspace number 1; exec google-chrome; workspace number 11; exec google-chrome'

I end up with workspaces 1 and 11 open, but 11 contains both instances of google-chrome (this works with other sets of programs too, like virtualbox and libreoffice).

The relevant parts of my actual config looks like this:

workspace 1 output VGA1
workspace 2 output VGA1
workspace 9 output VGA1
workspace 10 output VGA1
workspace 11 output HDMI1
workspace 19 output HDMI1
workspace 20 output HDMI1
exec i3-msg 'workspace number 1 "Chrome"; exec google-chrome'
exec i3-msg 'workspace number 2 "Chrome 2"; exec google-chrome'
exec i3-msg 'workspace number 11 "Chrome 3"; exec google-chrome'
exec i3-msg 'workspace number 9 "virtualbox"; exec virtualbox'
exec i3-msg 'workspace number 10 "log"; exec libreoffice --calc -o ~/Documents/Log.ods'
exec i3-msg 'workspace number 19 "banshee"; exec banshee'
exec i3-msg 'workspace number 20 "pidgin"; exec pidgin'
exec i3-msg 'workspace number 11; workspace number 1;

What I actually get is

Workspace 10 "log" is open on VGA1, but empty
Workspace 2 is open on HDMI1 and contains 3 google-chrome windows
Workspace 19 "banshee" is open on HDMI1 and contains virtualbox, libreoffice, banshee
Workspace 20 "pidgin" is open on HDMI1 and contains pidgin
Workspaces 1,9,11 are not present (presumably created and destroyed when switched away with nothing in).

I have tried using exec --no-startup-id i3-msg on each line containg i3-msg above, but it just rearranges the jumble rather than sorting it out. I tried running multiple shell commands in just a few i3-msg commands, but again it just rearranges the jumble rather than sorting correctly.

It's worth noting that after i3 loads, if I drop to a command line and enter i3-msg 'workspace 5; exec google-chrome' the new window opens in workspace 5, whereas if I enter i3-msg 'workspace 5; exec google-chrome; workspace number 2', I get the new chrome window in workspace 2.

Am I missing something? Is there some way to insert a pause between lines in the config file to give time for everything to load?

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
2

answered 2014-02-27 11:24:52 +0000

Adaephon gravatar image

Chrome is a bit of a special case:

Use for_window to move your Chrome windows to the correct workspace:

for_window [title="this_is_chrome_window_number_1"] move workspace number 
for_window [title="this_is_chrome_window_number_2"] move workspace number 2
for_window [title="this_is_chrome_window_number_3"] move workspace number 3

exec google_chrome file:///this_is_chrome_window_number_1
exec google_chrome file:///this_is_chrome_window_number_2
exec google_chrome file:///this_is_chrome_window_number_3

As long as the file does not exist Chrome will show the name of the file in the title bar along with an error message. If the file (or any URL) does exist, you have to take care that for_window matches to whatever the title is set. You could use this to set up different start pages for the different workspaces.


Why does it not work as you expected?

There is a delay between exec starting the program and the actual creation of the window. Some applications are able to handle startup notifications which allows for the window to be opened on the workspace that was focused when exec was called. (--no-startup-id explicitly disables this feature, so you do not want it here. ).

Applications that do not handle startup notifications will just open on whichever workspace is focused when the window is created.


Why does assign not help here?

Usually you can use assign to put applications on specific workspaces. But as you are trying to open multiple windows of the same application on different workspaces there may be some difficulties in differentiating between the different windows.

It is possible to change the window class of GTK programs with --class='NewClassName'. But this will not work with Chrome: While the first window (google-chrome --class=chrome_1) gets he wanted class chrome_1, subsequent calls of google-chrome --class_chrome_2 do not create their own window but cause the first instance (chrome_1) to open additional windows for the original session. So the class for these windows is also chrome_1 and not chrome_2.

Although there is a way to force Chrome to open a new session, it only works with different configuration directories for each session.

edit flag offensive delete link more

Comments

Thanks, very informative!

cee gravatar imagecee ( 2014-02-27 16:03:25 +0000 )edit
2

answered 2014-02-27 09:13:13 +0000

cee gravatar image

Try to use assign command. Maybe also take a look at this thread

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-02-27 04:03:56 +0000

Seen: 1,308 times

Last updated: Feb 27 '14