.xinitrc

From Fluxbox-wiki
Jump to: navigation, search


Contents

What is xinit

From man xinit:

The xinit program is used to start the X Window System server and a first client program on systems that cannot start X directly from /etc/init or in environments that use multiple window systems. When this first client exits, xinit will kill the X server and then terminate.

The place of .xinit in things

You have to understand that a window manager is just one more application for X, like netscape or gimp or xterm. Many people new to X come to believe that X 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 X, kill the window manager, and start another window manager up.

The *real* program that X runs, that runs other programs, is your .xinitrc or .xsession script. When X is started, your .xinitrc or .xsession script is run, and when the script is done, X comes down. Let me repeat that, it's important: WHEN .xinitrc IS FINISHED, *THAT* IS WHEN X ENDS. It isn't when your window manager exits.

What is startx

The startx script is a front end to xinit that provides a somewhat nicer user interface for running a single session of the X Window System. It is often run with no arguments. (taken directly from man startx)

What is this (dot)xinitrc files

The .xinitrc is typically a shell script which starts many clients according to the user's preference. When this shell script exits, startx kills the server and performs any other session shutdown needed. Most of the clients started by .xinitrc should be run in the background. The last client should run in the foreground; when it exits, the session will exit. People often choose a session manager, window manager, or xterm as the magic client.

All right, so how do I lay out my script?

Well, first you should 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 X 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 X 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 windowmanager to your script. But honestly, it's 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, let's say you want to put lots of windowmanager 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: When this program is finished, finish myself right here.

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 windowmanager lines, and it would work just the same.

Is there another way to do things

As an alternative, you could start up your windowmanager 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.

Now, I use the wait thingie, because I like picking my window manager before I launch my dockapps and stuff. Also, before everything, I like to change the settings on my X 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.

Can I see some example (dot)xinitrc files

Sure. Some people have very small files that might only do one thing, that thing is typically starting a window manager like so

 exec startfluxbox

This example will execute the startup script for fluxbox which at the end starts fluxbox

The next example might work best for people who use multiple window managers.

 #log files we like to watch
 logfile1="/var/log/messages,white"
 logfile2="/var/log/kern.log,green"
 logfile3="/var/log/auth.log,red,'LOGIN'"
 logfile4="/var/log/secure,red,'ALERT!!'"
 #the font we want our log to show
 logfont="-rolibue-matto-bold-r-normal--14-14-75-75-m-90-iso8859-1"
 #the dimensions of our log area
 geom="800x350+10+40"
 exec gkrellm2 -w &
 exec root-tail -g ${geom} -fn ${logfont} ${log1} ${log2} ${log3} ${log4}"
 klipper
 xset r rate 195 35
 #load our custom keymaps for special keys to work in X
 xmodmap ~/.Xmodmap
 #load our custom settings for terminal and other stuff
 xrdb -load ~/.Xdefaults
 #start a window manager
 exec fluxbox
 #can only execute one this time we use fluxbox
 #exec openbox
 #exec wmaker

The above file is handy when somoene switches between window managers and wants some of the same things to start in all places. Just keep in mind you only have 1 window manager start, so be sure to comment out the ones you are not using.

Another .xinitrc file example:

# LICQ is very badly designed.  clean up before it.
rm .licq/licq.pid

# 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 &
wmnet -x 70000 -d 300000 -L cablemodem -w &
wmxmms &

# HANG POINT - wait for windowmanager to exit
wait $wmpid

# restore the X fontpath
xset fp default