You are not logged in.

#1 2021-01-17 21:00:55

Komisch
Member
Registered: 2018-05-30
Posts: 44

i3wm autostart applications

Greetings community,

I am using Archlinux with i3wm and startx. Normally I just add my startup programs into ~/.xinitrc like this:

~/.autostart.sh &
exec i3

~/.autostart.sh (with execute rights of course):

~/.fehbg &
/usr/bin/prime-offload &
optimus-manager-qt &
netctl-tray-auto &
dropbox

The problem with the approach is. It only works the first time after reboot. When I stopped quit i3wm (with or without logout) it doesn't start the applications.

I know that in the guide of i3wm https://i3wm.org/docs/userguide.html#_a … i3_startup the following approach will be emphasized:

adding in .config/i3/config

exec_always --no-startup-id ~/.fehbg;
exec_always --no-startup-id /usr/bin/prime-offload;
exec_always --no-startup-id optimus-manager-qt;
exec_always --no-startup-id netctl-tray-auto;
exec_always --no-startup-id dropbox;

Or as in the example without semicolon. I also tried to add those in ~/.xinitrc this way and I tried all combinations without --no-startup-id . I furthermore tried in different ways adding them to the ~/.autostart.sh and using exec_always on the shell file or by calling the shell file and adding exec_always to each command inside it. Non of those approaches even worked the first time after startup.

I don't know any further approach (maybe I randomly missed on of the combinations). Could you tell me which one is the right one?

Thank you very much in advance!

Offline

#2 2021-01-18 07:10:47

Archlin
Member
Registered: 2018-05-09
Posts: 60

Re: i3wm autostart applications

np

Last edited by Archlin (2021-01-18 09:01:05)

Offline

#3 2021-01-18 08:54:54

seth
Member
Registered: 2012-09-03
Posts: 19,814

Re: i3wm autostart applications

When I stopped quit i3wm (with or without logout)

The actual meaning of this is important - the xinitrc (this is hopefully not all of it, see last link below) is parsed when running xinit or startx and also by XDM as session script.
So if you don't start X11 this way, it's probably not run at all and something™ else runs the autostart.sh

~/.fehbg &
/usr/bin/prime-offload &

Those two should™ better not be forked, so to clean up, remove the ampersand, for dropbox instead and instead of forking autostart.sh in the xinitrc, just source it there.

Offline

#4 2021-01-18 18:57:28

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,255

Re: i3wm autostart applications

Komisch wrote:

adding in .config/i3/config

exec_always --no-startup-id ~/.fehbg;
exec_always --no-startup-id /usr/bin/prime-offload;
exec_always --no-startup-id optimus-manager-qt;
exec_always --no-startup-id netctl-tray-auto;
exec_always --no-startup-id dropbox;

Or as in the example without semicolon. I also tried to add those in ~/.xinitrc this way and I tried all combinations without --no-startup-id . I furthermore tried in different ways adding them to the ~/.autostart.sh and using exec_always on the shell file or by calling the shell file and adding exec_always to each command inside it. Non of those approaches even worked the first time after startup.

This is probably not the right way to start these applications with i3 - you should remove 'always'.
What I mean is - started apps. will not be cancelled if you restart i3 they just keep running.
So, only if you have a specific reason for something to run on a restart of i3, maybe a script... don't use 'always'

I don't know any further approach (maybe I randomly missed on of the combinations). Could you tell me which one is the right one?

There's always the 'autostart' way, if you create a dir. like '~/.config/autostart' and place the F.I. 'netctl-tray-auto.desktop' in it, it will be started.

edit: Oh and remove the semicolon.. it's useless in this case, there's no chain like:
'exec --no-startup-id something ; workspace $space3'

Last edited by qinohe (2021-01-18 19:28:57)

Offline

#5 2021-01-18 20:04:14

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 25,182

Re: i3wm autostart applications

Komisch wrote:

or by calling the shell file and adding exec_always to each command inside it.

Well that'd be completely nonsense.  There is no shell command "exec_always", so that would have just resulted in a bunch of "command not found" errors.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2021-01-19 17:00:05

Komisch
Member
Registered: 2018-05-30
Posts: 44

Re: i3wm autostart applications

Thank you so far

@Seth
I am not 100% sure how to implement your proposed change correctly. My Guess:

# Part of my ~/.xinitrc:
source ~/.autostart.sh
exec i3
# autostart.sh
exec --no-startup-id ~/.fehbg
exec --no-startup-id /usr/bin/prime-offload
exec --no-startup-id optimus-manager-qt
exec --no-startup-id netctl-tray-auto
exec --no-startup-id dropbox

I would like to verify with you before I test this, could you tell me whether I interpret your proposal correct or make a correct proposal for both files?

@qinohe
Thank you, in case none of the other solutions work I will try to create .desktop files for the applications I'd like to start. (Are you sure I shoudn't atleast ensure that exec --no-startup-id /usr/bin/prime-offload will be run always?)

@Trilby
the i3wm guide that I linked explicitly proposes the exec_always command - I also wasn't sure about it since this command seemed not to exist but I thought maybe i3wm interprets the string in some way.

https://i3wm.org/docs/userguide.html#_a … i3_startup :

exec [--no-startup-id] <command>
exec_always [--no-startup-id] <command>


Thanks so far - would be very happy to hear from seth whether I did interpret his proposed change and if not, I would like to see how it should have looked.

Offline

#7 2021-01-19 17:42:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 25,182

Re: i3wm autostart applications

That autostart.sh file is gibberish for reasons already noted - the end result will be nothing, even your WM, will be started.

Komisch wrote:

@Trilby
the i3wm guide that I linked explicitly proposes the exec_always command...

The i3wm guide gives instructions on how to format the i3 config file.  The i3 config is not a shell script, and a shell script cannot use i3 config syntax.

Last edited by Trilby (2021-01-19 17:43:38)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2021-01-19 19:29:28

Komisch
Member
Registered: 2018-05-30
Posts: 44

Re: i3wm autostart applications

@Trilby

I hope by continuing this thread my post won't be missed by @Seth but as I wrote in the initial post I also experimented with my .config/i3/config in which I added the exec_always to test whether it works (and I found it doesn't). Because some people on the internet recommand (as for example the given guide) to add autostart programs to this file.

@Trilby in case you like you can also tell me whether my approach to change the setup in the previous post will work or not and in case it wouldn't how to change it to a proper working approach (preferably with an example so that I end up with a working approach)

Offline

#9 2021-01-19 19:52:08

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,255

Re: i3wm autostart applications

Trilby is quite right about that autostart.sh, you should ad that rules to your i3 config. The autostart dir. with a '*.desktop' file is something different all together.. read about auto-starting,there are various ways; https://wiki.archlinux.org/index.php/Autostarting
Yes, I'm quite sure when you restart your i3 'exec --no-startup-id /usr/bin/prime-offload' will still run or there must be a reason why it would be cancelled when you restart i3 in the first place. I don't run prime, have no idea what it is.

If you read carefully through the part about 'exec' in the i3wm guide you see there are conditions when you NEED 'exec_always' a script maybe.. I don't even have an explecit example where I would need one...

Offline

#10 2021-01-19 20:58:46

seth
Member
Registered: 2012-09-03
Posts: 19,814

Re: i3wm autostart applications

exec in the i3 config has a different meaning than in a shell script.
No line in xinitrc after the first "exec" line (in autostart.sh) will be excuted and "--no-startup-id" is not a valid parameter in this context.
"Forking" is when you put an ampersand ("&") at the end, what makes the process run in background.

Whether you run stuff from the i3 session or the xinitrc depends mostly on whether they relate to your i3 session or graphical  sessions in general (eg. if you want this to happen as well when switching to openbox or so) and in some cases (typically all xrandr calls, maybe feh) it's simply better/more efficient to complete those calls before starting the WM.
There's typically no need to outsource parts of the xinitrc unless unless for a group of calls you want to make at different times (after starting the session or when starting the session w/ a DM that doesn't utilize the xinitrc - which is most of them)

Offline

#11 2021-01-20 13:21:44

Komisch
Member
Registered: 2018-05-30
Posts: 44

Re: i3wm autostart applications

Thanks for all your words

but I still don't know how to write a proper startup file and how to decide for certain applications which startup methods to use.

So let us assume I would like to use only the ~/.xinitrc (in case this is possible, which I don't know yet) - since you told me that there are applications I want to start before  my window manager starts and some which I would like to get started later on. But I don't know what I want in this regards. Lets start all the applications as early as possible. Tray applications for example seem to have a graphical component so I would consider those applications graphical applications and would assume I need an graphical session running but as some of you said, I don't. So I am back at the beginning and start throwing coins in the air and waiting for the outcome.

I understand that forking is done using the ampersand and sourcing can be done either with the command source or with a dot in front of a script. Furthermore I know that the source command can execute command from files but I mostly know it to be used to load configuration files. Depending on the definition you could maybe create some interpretation that everything can be called a "configuration file". I just tried to source all applications at startup since I yet don't know which applications are sourceable and which are not and why. When I did so, startx left me with a black screen.

So basically I tried:

# .xinitrc
source ~/.autostart.sh
exec i3

with autostart.sh like this:

~/.fehbg &
/usr/bin/prime-offload &
optimus-manager-qt &
netctl-tray-auto &
dropbox

and alternatively with this (looks horrible but since there is no (to me) known reason not to do it like this why not)

source ~/.fehbg
source /usr/bin/prime-offload
source optimus-manager-qt
source netctl-tray-auto
source dropbox

Seth also said that there are applications that should better not be forked but he missed the why. Why shouldn't I fork dropbox or prime-offload? When I shouldn't fork them, should I fork netctl-tray-auto? If not, why not? In case I should why should I fork it? I understand that fork creates a child process of a process so that when the parent process or whatever you call it dies the child process should also (maybe there are rare exceptions I don't know). But this would bring us to the beginning which graphical processes depend on the graphical environment which do not?
Since I am only able to run one exec command in .xinitrc how would I configure .xinitrc correctly to be able to startup applications?

@qinohe when I kill my i3wm it kills also all startup applications which could be related to the way I start them (forking) - still I need a way so that they either still run or will always be started

-------------
The most reasonable approach (from my point of view) I was able to come up with is changing .xinitrc and .autostart.sh the following way:
This left me with i3wm trying to start but only printing the ~/.fehbg screen and didn't react to any inputs (not even a mouse pointer) and didn't showed my status bar

~/.xinitrc

source ~/.autostart.sh
exec i3

~/.autostart.sh

/usr/bin/prime-offload

~/.fehbg

optimus-manager-qt

netctl-tray-auto

dropbox

Last edited by Komisch (2021-01-20 13:29:23)

Offline

#12 2021-01-20 14:55:34

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 12,528

Re: i3wm autostart applications

In simplified terms, you background applications that expect to be running  for a long time (i.e. they should keep running in the background for as long as i3/the session is alive) and you do not background commands that run quickly and only do one small thing then exit (there are not as black and white corner cases like always but for what you intend to do this explains it relevantly).

So in your example you'd not background the first two but background the last 3 so

/usr/bin/prime-offload
~/.fehbg
optimus-manager-qt &
netctl-tray-auto &
dropbox &

Also in general "sourcing" means that your current script reads the script you pass as an argument and executes the relevant instructions within (... and you only need read and not execute perms on the script in question) . This isn't going to work for non-script files and binaries, so no you won't be able to do that with your other applications.

This does not fix the inherent issue you seem to be having and you should answer seths initial question, by which means do you start X?

Last edited by V1del (2021-01-20 14:58:17)

Online

#13 2021-01-20 15:38:02

Komisch
Member
Registered: 2018-05-30
Posts: 44

Re: i3wm autostart applications

Ah, thank you that helps a lot - so first of all I have the additional information now, that I shouldn't fork programs that exit after executing a short task (I still can't tell why it is a problem - since as long as those programs don't fork further stuff, then exit and kill it, even so this stuff is supposed to run still afterwards I don't see the actual problem.) BUT your approach seems to work.

I source the ~/.autostart.sh script and this script follows your proposal and that at least starts the programs after boot, still not when I exit i3wm (with meta-key + shift + e)and then reexecute startx from tty (the same way I start i3wm after reboot and login).

I guess with the initial question you refer to the following statement by Seth

The actual meaning of this is important - the xinitrc (this is hopefully not all of it, see last link below) is parsed when running xinit or startx and also by XDM as session script.
So if you don't start X11 this way, it's probably not run at all and something™ else runs the autostart.sh

I always start my i3wm using the command startx which should as far as I know always run the ~/.xinitrc file.

Offline

#14 2021-01-20 15:41:31

seth
Member
Registered: 2012-09-03
Posts: 19,814

Re: i3wm autostart applications

I still can't tell why it is a problem

You're running things parallel what causes nodeterministic behavior.
This does not *have* to be a problem, but if the starting WM misses randr  or keyboard events because of  this, it'll misbehave.

How do you determine the failing 2nd invocation?
What if you add a command to the xinitrc that does "touch /tmp/test.file" - does the timestamp on that file update w/ every invocation?

Offline

#15 2021-01-20 16:50:00

Komisch
Member
Registered: 2018-05-30
Posts: 44

Re: i3wm autostart applications

I have to correct the last information I gave. After a reboot the new approach seems to work in all scenarios.

Thank you very much!

Offline

#16 2021-01-20 17:36:46

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,255

Re: i3wm autostart applications

Komisch wrote:

@qinohe when I kill my i3wm it kills also all startup applications which could be related to the way I start them (forking) - still I need a way so that they either still run or will always be started

Yeah, well if you ask about restart - which you did multiple times - you won't get an answer about killing that's not strange is it..?
The rest is already answered, try to be clear;-)

Offline

Board footer

Powered by FluxBB