Appendix A. Setting up .xinitrc/.xsession

Contributed by Verin.

The place of xinit in things

A window manager is just one more application for X11, like netscape or gimp or xterm. Many people new to X11 come to believe that X11 runs the window manager and the window manager runs programs. But that's not true. If configured right, you can run all your applications under X11, kill the window manager, and start another window manager up.

The real program that X11 runs, that runs other programs, is your .xinitrc or .xsession script. When X11 is started, your .xinitrc or .xsession script is run, and when the script is done, X11 comes down. Let me repeat that, its important: when .xinitrc is finished, that is when X ends. It isn't when your window manager exits.

Script layout

Well, first realize something you already know. When you type a command in a shell, you can't do anything else until that command is done, when it exits. Your .xinitrc or .xsession script is just the same. When it starts going through it, if it hits any program that takes a long time to run (like most X11 programs), it stops right there until that program is finished.

Ideally, you should only have one place where the script 'hangs'. And usually you want this to be at the end. So, if you have any programs you want to run under X11 before you get to this 'hang' spot, you should background them. You put an & at the end of the line. So, say you want xclock to run in addition to other things, put this line before your 'hang' spot:

    xclock &

Now, the next thing is the exec thing you see, where lots of sources recommend how to add your window manager to your script. But honestly, its not really necessary, if you put your window manager on the last line of your script, it will hang there just fine without the exec.

So why the exec? Well, lets say you want to put lots of window manager start lines in your script, and you want only one to work. Well, with exec you can put your chosen start-line at the top. Because this is what exec means:

"Replace myself with this program, i.e. start it and terminate myself immediately when it finishes. "

So if you put an exec wmaker line atop of a exec enlightenment line, when wmaker is done, so is the script, it never gets to the next line.

See what I mean by being unnecessary? You could just put a bunch of commented-out window manager lines, and it would work just the same.

Another way to do things

As an alternative, you could start up your window manager first, and store the process ID in a environment variable:

        wmaker & wmpid=$!

that puts it in the background (&) and puts the process id ($!) in a variable (wmpid). Then, to make your hang point, you can wait:

    wait $wmpid

or you could hang on a program you always want to use, like maybe gkrellm, by just not backgrounding it. But remember that as soon as you terminate it, so will your X11 session.

Now, I use the wait method, because I like picking my window manager before I launch my dockapps and stuff. Also, before doing anything else, I like to change the settings on my X11 server, like the dpms, the screen saver, and even add some directories to my font path (fonts I don't want to install universally). And then after everything is done, I like to clean up my fontpath, mainly because if I ran a display manager, its not good at resetting the font path all the time.

Example A-1. .xinitrc

    # turn off screen blanking and turn on energy star features
    xset s off
    xset dpms 600 60 60

    # add my optional fonts to the font path
    xset +fp "$X_FONTPATH"
    xset fp rehash

    # export the current environment, in case it needs to be debugged
    env > ~/.xenv

    # window manager
    fluxbox & wmpid=$!

    bbrun &
    wmCalClock &
    wmxmms &

    # HANG POINT - wait for window manager to exit
    wait $wmpid

    # restore the x fontpath
    xset fp default