How applications autostart on modern Linux desktops
A while back I mentioned that part of Microsoft Teams' misbehavior was autostarting when you logged in; recently, because I was testing some things on my laptop with alternate desktops, that behavior led to me uninstalling Teams. So all in all, it seemed like a good time to read up on how applications get automatically started when you log in (if they do) on modern Linux desktops like Gnome and Cinnamon.
(This is not normally an issue for me in my desktop environment, because everything in it is explicitly started by hand in a shell script.)
Unsurprisingly, there's a freedesktop.org
standard on this, the Desktop Application Autostart Specification,
which builds on the
.desktop file specification.
The simple version is that you set applications to autostart by
installing an appropriate .desktop file for them into either
/etc/xdg/autostart (for a system-wide autostart on login) or
~/.config/autostart (for an autostart for an individual user).
There are a number of special settings keys that can be in these
.desktop files. First, you can have a
key that controls which desktops should autostart this or not
autostart it (the specification misspells these keys in some mentions
of them). Second, you can have a
Hidden=true key, in which case
the application should not autostart (in any desktop). For obvious
reasons, the latter key is most useful in your personal autostart
Some desktops have custom keys of their own, and even custom locations for additional .desktop files to autostart; for example KDE before KDE 5 apparently also used ~/.kde/Autostart (see here). An important and common property is X-GNOME-Autostart-enabled, which is (still) in wide use despite apparently being deprecated. In particular, Cinnamon appears to implement disabling of standard autostart things by copying their .desktop file to your ~/.config/autostart directory and adding a line to the end with 'X-GNOME-Autostart-enabled=false'.
Some desktops have their own custom locations for various special things, or have had in the past (eg, also, and for LXDE). However, desktops don't necessarily use custom locations and settings. I know that with Cinnamon, if you add a new thing to be done on startup, Cinnamon puts a new .desktop file in your ~/.config/autostart.
More minimal 'desktops' may or may not automatically support .desktop autostarts. However, according to the Arch wiki's page on XDG Autostart, there are standalone programs that will do this for you if you want them to. On my normal machines, my own window manager environment is so divergent that I don't think autostarting .desktop files is of any use to me, so I'm not planning to try any of them.
(My work laptop runs a more or less
standard Cinnamon environment, which automatically handles autostarting
things. I believe that Cinnamon considers itself a form of GNOME
NotShowIn and so on .desktop keys. Cinnamon
certainly disables autostarted things using a GNOME specific key.)
Applications can arrange to autostart in at least two ways, the
honest way and the sneaky way. The honest way is to put a copy of
their .desktop file into
/etc/xdg/autostart. The sneaky way is
to wait until you run them once, then copy their .desktop file into
your ~/.config/autostart directory (re-copying this file every time
they're run is optional). Based on poking through the RPM package
for Microsoft Teams (and also how they apparently have a preferences
setting about this), Teams
appears to do this the sneaky way.