Skip to content

Starting WMFS with startx

linkdd edited this page Apr 19, 2012 · 1 revision

This tutorial will help you to start WMFS with startx, and automatilly run some programs at start.

What do we want ?

  • Start WMFS
  • Start some tools (like background command)

Two ways

The first, the easier

In your $HOME/.xinitrc :

feh --bg-scale /path/to/my/background
# or : nitrogen --restore
pcmanfm --desktop
# and some other command

# ck-launch-session : Start ConsoleKit, will make you able to mount drives without being root
# in your file manager (pcmanfm, nautilus, thunar, ...), or halt/reboot your computer without
# being root.
# dbus-launch : Is used by some desktop applications, maybe useful.
exec ck-launch-session dbus-launch wmfs

# If you don't need/want that, just use :
# exec wmfs

The second way, better, not so hard

Here, we will start WMFS before applications ! Because some applications need WMFS to be started (for example : your status program/script).

Here is the content of your $HOME/.xinitrc now :

exec ck-launch-session dbus-launch wmfs &
wmpid=$! # Here, we save the PID of wmfs

feh --bg-scale /path/to/your/wallpaper
pcmanfm --desktop
$HOME/.local/bin/status.sh

wait $wmpid # Here we are waiting the end of WMFS, when the user will do : wmfs -c quit :(

Bonus : With more configuration, we can do better

Here, we will do the following :

  • Put autostart commands in $HOME/.config/xorg/session.env
  • Put the WM to run in $HOME/.config/xorg/session.wm
  • Log everything in $HOME/.config/xorg/session.log
  • Write a script startwm which will read that configuration and run it.

First, our $HOME/.xinitrc will look like this :

exec ck-launch-session dbus-launch $HOME/.local/bin/startwm
# NB: Put your script where you want, just set the absolute path here

Our $HOME/.config/xorg/session.wm will look like this :

wmfs

NB: To change your window manager, you will have to change only that file :)

Our $HOME/.config/xorg/session.env will look like this :

pcmanfm --desktop
/home/linkdd/.local/bin/status.sh

NB: This file isn't a script ! Each line describe ONE command

Now, we have to write our script startwm :

LOG="$HOME/.config/xorg/session.log"

# Check which WM we have to run :
WINDOWMANAGER="`cat $HOME/.config/xorg/session.wm`"

# Run WM in background and get its PID.
# Redirect the standard output to the log file
# Redirect the error output to the standard output (so to the log file)
$WINDOWMANAGER >> $LOG 2>&1 &
wmpid=$!

cat $HOME/.config/xorg/session.env | while read cmd
do
     # Run each commands in background
     $cmd >> $LOG 2>&1 &
done

# Wait the end of our WM
wait $wmpid

BONUS : Automatic startx

At the start of your shell, your profile file is executed, with bash it's $HOME/.bash_profile, with zsh it's ``$HOME/.zprofile`.

Add this into your profile file :

# If the variable DISPLAY is empty (so we're not in a X)
# And the return of 'tty' is '/dev/tty1' (first tty, CTRL+ALT+F1)
if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]
then
     # Run startx in background
     ssh-agent startx > $HOME/.config/xorg/session.log 2>&1 &
     # And lock the terminal
     vlock # vlock is the same as slock (or other), but for a terminal
     # You may need to install it
     # On debian : apt-get install vlock
fi
Clone this wiki locally