Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Desktop Environments
  • Search

How to autostart anything in an X11 or Wayland session?

Problems with GUI applications? Questions about X, KDE, Gnome, Fluxbox, etc.? Come on in. NOTE: For multimedia, go up one forum
Post Reply
Advanced search
3 posts • Page 1 of 1
Author
Message
jamapii
l33t
l33t
User avatar
Posts: 637
Joined: Thu Sep 16, 2004 6:22 pm

How to autostart anything in an X11 or Wayland session?

  • Quote

Post by jamapii » Sat Jun 06, 2020 1:47 pm

Hello

I want to have some files in the home directory, that can cause applications to be started inside any X, Wayland, or similar session, automatically (with no user intervantion), at the beginning.

I have heard of some ways to do this, but only under very restricted conditions, or to do not quite this, but only something similar.

A few examples for other software that has autostart functions:

So bash has .bashrc, .bash_profile, etc, and all the shells have equivalent files. One or more of the files run at the beginning of bash, setting environment variables, run programs. Then, bash is ready to use.

There seems to be no such thing in X11. There are a lot of files - .xinitrc, .xsession, .Xclients, .xprofile, that have a similar function, but not the same. It usually, but not always, seems to be, for each file:
  • The "session" or whatever, may or may not look at the file.
  • The following steps may or may not apply, or something different may apply.
  • If the file is executable, the normal X session will not be started, but some files may be executed first.
  • If the file is executable, it will be started.
  • If (when) the execution of the file terminates, the X session terminates.
That means, if one thinks this works somewhat like .bashrc, and just start a few applications and xterms there, and then starts any X session, or Gnome, or fluxbox, you will just see a few windows flashing and then everything ends and the X display manager returns.

Instead, one is supposed to put something like gnome-session, or fluxbox, or twm, at the end of the script. Without an "&"! Then no matter what session is started (Gnome, KDE, fluxbox, ...), the named thing will not come up of course, but only the last line in the .xwhateverrc.

Also, everything is "may or may not". I didn't try most of these things recently, it's just a waste of time. I read some files instead:

/etc/X11/Sessions/Xsession handles .xsession and .Xclients in this way.

/etc/X11/Sessions/Gnome handles .gnomerc in this way.

/etc/gdm/Xsession handles .Xclients in this way, and mentions .xsession in comments, and handles .xprofile as a real "autostart inside X".

/etc/X11/Sessions/icewm does nothing of this - maybe the icewm-session command does.

It all depends on the specific display manager (xdm replacement) and on the chosen session. But for most files, if they are present, they can only replace the session altogether. .xprofile is an exception, and does what I want at least in some cases.

That means - if you would e.g. create a working .xsession or .Xclients, and make it work for Gnome, you can't run anything else (with exceptions). And after an update, the name of the command to call as the last line may change to gnome-future, and gnome-session will no longer work.

For .xprofile it may depend on the display manager/session combination. I don't know. One must adapt the file to the calling mode, which is unknown. If it is wrong, then nothing will run at all, or after logout a second session will run immediately.


I make sure no such files exist. Instead I have a script in ~/bin. Years ago, I could start it from a Gnome Autostart feature. But in the new Gnome, this is no more. Instead, for a long time, it was ... again ... a "may or may not" thing. So I found that in recent Gnome, it is not possible to autostart arbitrary scripts. There was a .desktop file in .config/autostart (I made that 2) which recently stopped working. There was even a .desktop file in .config/autostart-scripts/ which worked for a while, but does no more. Autostarting is now restricted to a list of preapproved applications (maybe with a .desktop file in nobody knows where).

So I developed a workaround. I added a new terminal to autostart, in this case "lxterminal" (just not Gnome Terminal). This does start an lxterminal in a new session. Then I manipulated its .desktop file in the autostart folder, to exec "lxterminal -e ~/bin/myscript". This never worked, because ~ would not be expanded. So I changed it to "lxterminal -e sh -c '~/bin/myscript'". Only this expands the ~.

The script itself is heavily guarded to not run recursively, not run concurrently, and run just once even if called many times.

I also noted that Gnome autostarts a lot of stuff that is not in autostart. It seems this includes stuff dropped in some "session" directory, and executable .desktop files in /etc/xdg/autostart/. (In other places, it does not matter whether .desktop files are executable). It actually resembles malware behaviour. (Start it once, and it never again goes away)

But, is there any kind of standard so I can improve this.

For example, is the calling mode of .xprofile and others standardized, so that it either always runs inside, and not instead of the session, or always instead of, and not inside the session?

And what mechanisms exist to autostart something inside a gnome session? I know there is more than .config/autostart and (possibly) .config/autostart-scripts/.

Are any mechanisms known for other DEs?
Top
eccerr0r
Watchman
Watchman
Posts: 10239
Joined: Thu Jul 01, 2004 6:51 pm
Location: almost Mile High in the USA
Contact:
Contact eccerr0r
Website

  • Quote

Post by eccerr0r » Sat Jun 06, 2020 3:41 pm

This is what happened: https://xkcd.com/927/

In the old ages when X was new, ~/.xinitrc was the standard - this would run everything that was in it after X starts. Once this script ends, X ends as well. Then some people decided to think xdm was a thing and it switched over to ~/.xsession and then people wonder how to add hooks to start things before the windowmanager starts, and sometimes after the windowmanager starts and designed all sorts of hooks that some people didn't add into their distribution. Then xdm (and all its replacements) had their own different methods of starting programs.

The XDG tried to "standardize" everything, but those windowmanagers that don't conform to these "standards" of course don't work. So unfortunately for the most part you have to target your specific environment or have to cover all bases... ugly...

It looks like XDG wants you to stick a .desktop file in ~/.config/autostart or /etc/xdg/autostart as you found, though not sure where in the process they're started now...

So I suspect what you "should" do is do what XDG wants. But if you don't run an XDG compliant DE, then you're on your own. There is no standard, and generally are expected to know how to modify your windowmanager/startup routines to add programs...

I dread Wayland. #16...
Intel Core i7 2700K/Radeon Firepro W2100/24GB DDR3/800GB SSD
What am I supposed watching?
Top
Ant P.
Watchman
Watchman
Posts: 6920
Joined: Sat Apr 18, 2009 7:18 pm
Contact:
Contact Ant P.
Website

  • Quote

Post by Ant P. » Sat Jun 06, 2020 9:35 pm

X11 doesn't have an equivalent to bashrc because it's a server, not a shell.

A "session" is an imaginary concept perpetuated by heavy desktop projects to disguise the fact that GUI applications are just long-running processes, and can be managed the same as non-GUI ones. All these Xdotfiles, xdg-desktop files etc. are just layers of cruft to pretend it's not actually glued together by 40-year-old shell scripts (try reading /etc/X11/Sessions/Xsession, /usr/bin/startx and /usr/bin/xdg-open some time). I ignore all that and run my desktop inside runit/runsvdir.
Top
Post Reply

3 posts • Page 1 of 1

Return to “Desktop Environments”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic