Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

How to configure apps to autostart in a minimal WM?

Graphical Environments, Managers, Multimedia & Desktop questions.
Post Reply
Message
Author
bedtime
Posts: 146
Joined: 2012-12-16 19:34
Has thanked: 1 time
Been thanked: 6 times

How to configure apps to autostart in a minimal WM?

#1 Post by bedtime »

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: 146
Joined: 2012-12-16 19:34
Has thanked: 1 time
Been thanked: 6 times

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

#2 Post by bedtime »

Figured it out. It seems that programs can actually be run .xinitrc.

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

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

#3 Post by bw123 »

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
resigned by AI ChatGPT

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

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

#4 Post by debiman »

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
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

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

#5 Post by bw123 »

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.
resigned by AI ChatGPT

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

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

#6 Post by debiman »

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.

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 47 times

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

#7 Post by reinob »

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.

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

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

#8 Post by debiman »

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: 3063
Joined: 2013-03-12 07:18

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

#9 Post by debiman »

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
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

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

#10 Post by bw123 »

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.
resigned by AI ChatGPT

bedtime
Posts: 146
Joined: 2012-12-16 19:34
Has thanked: 1 time
Been thanked: 6 times

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

#11 Post by bedtime »

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?

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

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

#12 Post by bw123 »

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.
resigned by AI ChatGPT

User avatar
oswaldkelso
df -h | grep > 20TiB
df -h | grep > 20TiB
Posts: 1490
Joined: 2005-07-26 23:20
Location: UK
Has thanked: 1 time
Been thanked: 58 times

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

#13 Post by oswaldkelso »

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/
Free Software Matters
Ash init durbatulûk, ash init gimbatul,
Ash init thrakatulûk agh burzum-ishi krimpatul.
My oldest used PC: 1999 imac 333Mhz 256MB PPC abandoned by Debian

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

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

#14 Post by bw123 »

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.
resigned by AI ChatGPT

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

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

#15 Post by Head_on_a_Stick »

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 :)
deadbang

User avatar
None1975
df -h | participant
df -h | participant
Posts: 1389
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 45 times
Been thanked: 66 times

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

#16 Post by None1975 »

Here mine .xsessionrc

Code: Select all

#!/bin/bash

# Load resources

xrdb -merge .Xresources

export GTK_OVERLAY_SCROLLING=0
# Fire up apps
xautolock -time 10 -locker 'slock' &
setxkbmap -layout "us,lt,ru" -option "grp:alt_shift_toggle" &
nitrogen --restore &
compton -b &

if [ -x /usr/bin/nm-applet ] ; then
   nm-applet --sm-disable &
fi

exec herbstluftwm --locked
OS: Debian 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

bedtime
Posts: 146
Joined: 2012-12-16 19:34
Has thanked: 1 time
Been thanked: 6 times

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

#17 Post by bedtime »

I can't attest to understanding all of what this article said, but what I did understand, was useful.

Thank you guys for posting your configs. :)

* EDIT *

Might as well post mine since I finally got it working:

~.xsession:

Code: Select all

# Statusbar loop
while true; do
xsetroot -name \
"$(date +"%a, %b %d, %H.%M.%S") \
Vol: $(amixer get Master | awk '$0~/%/{print $4}' | tr -d '[]') \
Mem: $(free -m | grep Mem | awk '{print $3"mb"}') \
CPU: $[100 - $(vmstat 1 2 | tail -1 | awk '{print $15}')]%"

#vmstat is set to wait 1 second to take its cpu reading
done &

#Rearrange moniters so they make sense
xrandr --output LVDS-1 --auto --output VGA-1 --auto --left-of LVDS-1

#Allow to copy in st term
xclip -in &

#Check email
st -g 54x10 -e ./email_check.sh &

#A script to start dwm (can be seen below)
exec startdwm
Status bar will look something like:

Wed, Jan 31, 12.48.11 Vol: 70% Mem: 100mb CPU: 0%

~/bin/startdwm:

Code: Select all

#!/bin/bash
# dwm can now be restarted without destroying other X windows by pressing the usual Mod-Shift-Q com$
# It is a good idea to place the above startup script into a separate file, ~/bin/startdwm for inst$

while true;
do
    # Log stderror to a file
    #dwm 2> ~/.dwm.log

    # No error logging
    dwm >/dev/null 2>&1
done

Post Reply