How to configure apps to autostart in a minimal WM?

Everything about X, Gnome, KDE, ... and everything running on it

How to configure apps to autostart in a minimal WM?

Postby bedtime » 2018-01-27 12:52

I've been playing around with Lwm, WindowLab, and Jwm (window managers), and I'm trying to get x programs to auto-start when the window manager loads up (i.e., xterm, xclock...). This was an easy task with LightDM, but I am not using a login manager; I am just logging straight in with a systemd command and exec <wm> in .xinitrc.

If there is a way that I could run a script upon the launch of those window managers, that would be great.

Any ideas?
bedtime
 
Posts: 81
Joined: 2012-12-16 19:34

Re: How to configure apps to autostart in a minimal WM?

Postby bedtime » 2018-01-27 13:07

Figured it out. It seems that programs can actually be run .xinitrc.
bedtime
 
Posts: 81
Joined: 2012-12-16 19:34

Re: How to configure apps to autostart in a minimal WM?

Postby bw123 » 2018-01-27 13:53

There are a lot of ways to configure the system. My favorite on debian is to use the debian alternatives system to set the x-window-manager shortcut. If you use a default method like xsession instead of .xinitrc then you can use several different window managers and switch between them easily, but keep the same startup commands no matter which you want to run.

This way, you just update the alternative, and run startx. Same apps start on all wm you use.

https://wiki.debian.org/xinit
https://wiki.debian.org/WindowManager
https://wiki.debian.org/Xsession
User avatar
bw123
 
Posts: 3186
Joined: 2011-05-09 06:02
Location: TN_USA

Re: How to configure apps to autostart in a minimal WM?

Postby debiman » 2018-01-27 15:35

i have this in my ~/.xinitrc:
Code: Select all
exec somewindowmanager
wm_pid=$!
{
 . $HOME/.config/autostart.sh
} &
wait $wm_pid
because some programs need to start after the window manager.
User avatar
debiman
 
Posts: 2597
Joined: 2013-03-12 07:18

Re: How to configure apps to autostart in a minimal WM?

Postby bw123 » 2018-01-27 16:57

debiman wrote:i have this in my ~/.xinitrc:
Code: Select all
exec somewindowmanager
wm_pid=$!
{
 . $HOME/.config/autostart.sh
} &
wait $wm_pid
because some programs need to start after the window manager.


exec works that way for you? on my system it forks and exits the current script.

hmmm now that i think about it, exec exits the entire shell. I use it in .profile sometimes to run a command and log out after.
User avatar
bw123
 
Posts: 3186
Joined: 2011-05-09 06:02
Location: TN_USA

Re: How to configure apps to autostart in a minimal WM?

Postby debiman » 2018-01-28 09:18

bw123 wrote:exec works that way for you?

it does.
and since i found that technique on the internet, it seems to work for others, too.
my .xinitrc uses '#!/bin/dash' - i will try with bash and sh and see if something changes.
i have noticed earlier that exec works differently for dash.

maybe the 'wait' command is special in that way.
User avatar
debiman
 
Posts: 2597
Joined: 2013-03-12 07:18

Re: How to configure apps to autostart in a minimal WM?

Postby reinob » 2018-01-28 09:45

debiman wrote:
bw123 wrote:exec works that way for you?

it does.
and since i found that technique on the internet, it seems to work for others, too.
my .xinitrc uses '#!/bin/dash' - i will try with bash and sh and see if something changes.
i have noticed earlier that exec works differently for dash.

maybe the 'wait' command is special in that way.


exec doesn't fork so once you exec your wm the script and the underlying (dash) shell ceases to exist.
I don't use dash but just tried:
Code: Select all
bash $ dash
dash $ exec echo hey
hey
bash $ _


so dash indeed does NOT survive the exec, which makes sense, because exec leaves no room for interpretation.

Probably the special case with the autostart is working because the window manager is actually the one executing autostart, not the snippet on .xinitrc.

Remove that from .xinitrc and you will not notice any difference.
reinob
 
Posts: 542
Joined: 2014-06-30 11:42

Re: How to configure apps to autostart in a minimal WM?

Postby debiman » 2018-01-28 09:54

reinob wrote:Probably the special case with the autostart is working because the window manager is actually the one executing autostart, not the snippet on .xinitrc.

Remove that from .xinitrc and you will not notice any difference.

sorry, but that isn't true. openbox does not look at that file, and neither do other wms.
i introduced that technique quite a while ago when i was trying out dozens of windowmanagers.
i'm not claiming to understand why, but it works.
and:
debiman wrote:i found that technique on the internet, it seems to work for others, too.
User avatar
debiman
 
Posts: 2597
Joined: 2013-03-12 07:18

Re: How to configure apps to autostart in a minimal WM?

Postby debiman » 2018-01-28 10:02

i tested with other wm's and shells, the behaviour is consistent.

the magic bit is the ampersand '&' at the end of the exec line. without it, it does not work.
User avatar
debiman
 
Posts: 2597
Joined: 2013-03-12 07:18

Re: How to configure apps to autostart in a minimal WM?

Postby bw123 » 2018-01-28 15:39

debiman wrote:my .xinitrc uses '#!/bin/dash' - i will try with bash and sh and see if something changes.
i have noticed earlier that exec works differently for dash.

maybe the 'wait' command is special in that way.


There are all kinds of ways to do things. I don't understand why anyone would use .xinitrc instead of the debian xsession or need #!/bin/dash in scripts.

The defaults on debian have always worked fine for me.

Code: Select all
$ which sh
/bin/sh
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Jan 24  2017 /bin/sh -> dash


https://wiki.debian.org/xinit > https://wiki.debian.org/Xinitrc
Note that ~/.xinitrc is only for configuring the initialization of xinit. If you want the script to be called when ever an X Session is started, then you should instead use ~/.xsession. Most WindowManagers also have a method of starting programs when they first startup.
User avatar
bw123
 
Posts: 3186
Joined: 2011-05-09 06:02
Location: TN_USA

Re: How to configure apps to autostart in a minimal WM?

Postby bedtime » 2018-01-28 17:12

bw123 wrote:There are a lot of ways to configure the system. My favorite on debian is to use the debian alternatives system to set the x-window-manager shortcut. If you use a default method like xsession instead of .xinitrc then you can use several different window managers and switch between them easily, but keep the same startup commands no matter which you want to run.

This way, you just update the alternative, and run startx. Same apps start on all wm you use.

https://wiki.debian.org/xinit
https://wiki.debian.org/WindowManager
https://wiki.debian.org/Xsession

I'm only using one WM at the moment, but this does sound like a good alternative for later if I choose to add another. Thank you for the links. They were helpful! :D

bw123 wrote:
debiman wrote:https://wiki.debian.org/xinit > https://wiki.debian.org/Xinitrc
Note that ~/.xinitrc is only for configuring the initialization of xinit. If you want the script to be called when ever an X Session is started, then you should instead use ~/.xsession. Most WindowManagers also have a method of starting programs when they first startup.

I linked .xsession to .xinitrc; is this this right thing to do?
bedtime
 
Posts: 81
Joined: 2012-12-16 19:34

Re: How to configure apps to autostart in a minimal WM?

Postby bw123 » 2018-01-28 17:22

bedtime wrote:I linked .xsession to .xinitrc; is this this right thing to do?


I don't think I'd say there was a "right" or wrong way, if it works for you, then use it. I think the "debian way" to do it would be remove the .xinitrc and use only .xsession if you really need to, and hang on exec x-window-manager as the last line.

Another way would be to copy some of the script from /etc/X11/Xsession.d/50x11-common_determine-startup
into your .xsession and try all the x-* alternatives and then exec $STARTUP

I think this is a really nice way of doing things! I really like this script a lot, it shows an effort to be flexible that other solutions don't.

Code: Select all
# If there is still nothing to use for a startup program, try the system
# default session manager, window manager, and terminal emulator.
if [ -z "$STARTUP" ]; then
  if [ -x /usr/bin/x-session-manager ]; then
    STARTUP=x-session-manager
  elif [ -x /usr/bin/x-window-manager ]; then
    STARTUP=x-window-manager
  elif [ -x /usr/bin/x-terminal-emulator ]; then
    STARTUP=x-terminal-emulator
  fi
fi

Last edited by bw123 on 2018-01-28 18:22, edited 2 times in total.
User avatar
bw123
 
Posts: 3186
Joined: 2011-05-09 06:02
Location: TN_USA

Re: How to configure apps to autostart in a minimal WM?

Postby oswaldkelso » 2018-01-28 17:23

That wiki post is a wee bit lacking in the full story.

xsession is used if you start via a display manager like wdm, slim, GDM etc and I believe overrides xinit. Should you chose not to run a dispay manager xint works fine.

xinit is called by startx. But you can have several xinitrc files depending on your setup.

On my main Dragora system they are 15 files including a default, stored in /etc/X11/xinit/

If I want to start a different window manager. I run wmconfig after login and select say windowlab.

This points back to /etc/X11/xinit/xintirc.windowlab and when I run startx I'm running windowlab and what ever else is listed to start by that file.

No need to keep editing your single .xinitrc file when you swap WM

wmconfig doesn't seem to be available in Debian but you can get the source here https://www.arrishq.net/
Ash init durbatulûk, ash init gimbatul,
Ash init thrakatulûk agh burzum-ishi krimpatul.
User avatar
oswaldkelso
 
Posts: 1128
Joined: 2005-07-26 23:20
Location: UK

Re: How to configure apps to autostart in a minimal WM?

Postby bw123 » 2018-01-28 17:32

People who actually run debian can look in /etc/X11/xinit/xinitrc and the other files around /etc/X11 to find out how it works. There are a lot of people on here that ran debian but moved on. Some others use it heavily modified.

For answering new users who have complicated questions, I appreciate it when the "debian default" way of doing things is at least mentioned.
User avatar
bw123
 
Posts: 3186
Joined: 2011-05-09 06:02
Location: TN_USA

Re: How to configure apps to autostart in a minimal WM?

Postby Head_on_a_Stick » 2018-01-29 07:56

oswaldkelso wrote:.xinitrc file

As bw123 notes, the use of ~/.xinitrc is actually discouraged in Debian systems, see startx(1) for the details.

bw123 wrote:People who actually run debian can look in /etc/X11/xinit/xinitrc and the other files around /etc/X11 to find out how it works.

We have a detailed breakdown of the whole `startx` process over at forums.bunsenlabs.org:

https://forums.bunsenlabs.org/viewtopic.php?id=3774

For the curious :)
E Pluribus Unix
User avatar
Head_on_a_Stick
 
Posts: 7774
Joined: 2014-06-01 17:46
Location: /dev/chair

Next

Return to Desktop & Multimedia

Who is online

Users browsing this forum: No registered users and 6 guests

fashionable