This little tutorial is intended to help a Linux newbie to do something fun and hopefully learn some useful Linux commands and concepts along the way. Those more experienced with Linux may find the amount of hand-holding here to be irritating. Well, let me say right off the bat that there's nothing here you couldn't find out from the xscreensaver man page, but for the novice user, this tutorial should be a little easier to follow.
First of all, you should be running X now.
Now check to see if the screensaver is already running. Some Linux distributions may have already put it in one of the files that starts up client applications for X. (These are /etc/xinit/xinitrc, /etc/xinit/Xclients, ~/.xinitrc, and ~/.Xclients.) To see if xscreensaver is already running, do ps af and look at the result. (ps is a command that lists the running processes on the system... very handy.)
For instance, part of the output of ps af looks like this
for me:
PID TTY STAT TIME COMMAND
...
252 1 S 0:00 /bin/login -- pw
260 1 S 0:00 \_ -bash
271 1 S 0:00 \_ sh /usr/X11R6/bin/startx
272 1 S 0:00 \_ xinit /usr/X11R6/lib/X11/xinit/xinitrc
--
276 1 S 0:01 \_ wmaker
280 1 S 0:00 \_ xscreensaver
281 1 S 0:00 \_ nxterm
286 p0 S 0:00 | \_ bash
293 p0 R 0:00 | \_ ps af
284 1 S 0:00 \_ asclock -shape
Every process is listed with a Process ID number. Look at PID 280 ... there you see that xscreensaver is running on my system.
If you don't see xscreensaver listed, it's not running. To start it up, type this in an xterm: xscreensaver &. If you get an error message, you may not have xscreensaver installed on your system. Try locate xscreensaver or find / -name "*xscreensaver*" and see if that turns anything up. If not, you need to get it... it may be on your distribution CD-ROMs (it comes with RedHat, for example), or look at the Xscreensaver home page.
Anyway, now you've got xscreensaver running, but it probably isn't doing anything yet. The next thing you want to do is type xscreensaver-command -demo . This puts xscreensaver into an interactive demo mode, so you can see which screensavers you like.
Also at this time, you should use your favorite text editor to open the .Xdefaults file in your home directory. If you don't have one yet, go ahead and create the file. .Xdefaults is a file that contains default options for many programs that run in X. Nearly any X application will have a man page or other documentation that describes its "X resources"... that is, the options that can be set in a user's .Xdefaults file. What we're going to do now is add some entries to .Xdefaults that tells xscreensaver which graphics program(s) to run.
The xscreensaver demo is pretty easy to figure out. It blackens the
screen and pops up a little window where you can select which graphics
program (which are generally referred to as "hacks") to run. When you
select one, it starts running and the window
gets hidden. To bring back the demo dialog window, just right-click
the mouse. You can scroll through the list, jump to the next or
previous graphics hack, etc. When you find a graphics hack you like,
add it to your .Xdefaults file. Here's what you want to put in:
This is just an example; I like these three graphics hacks. The
backslashes are necessary so that all of this is read as one line. Each
graphics hack listed must have the
xscreensaver.programs: \
rocks -root \n\
hopalong -root \n\
flame -root \n
-root
flag, to tell it
to draw on the "root" window (i.e. the whole screen), and each hack
entry must end with \n\, except the last one which must end with \n ...
it looks weird to the uninitiated, but that's just how it works.
Do xscreensaver-command -demo again, and try all the graphics hacks, adding each one you really like to your .Xdefaults file. When you're done, save .Xdefaults, and click the "Reinitialize" button in the xscreensaver demo. Now only the hacks listed in your .Xdefaults are listed by the demo, and only these will be run when the screensaver starts.
xscreensaver &
As with anything you put in .xinitrc or .Xclients, the command shouldn't be the last thing in the file. Usually your window manager is the last thing started. (On RedHat systems, /etc/xinit/xinitrc does some auto-detect things and starts the window manager; probably everything you personally want to start should go in ~/.Xclients.) The command you add must end with an ampersand to put that process in the background; otherwise, X will exit if the process is killed, and you don't want that behavior from anything but the window manager.
You can manually start the screensaver at any time by typing xscreensaver &, and then if you want to test it out quickly, you can make it immediately take over the screen by typing xscreensaver-command -active. If the screensaver is already running and you want it to load some new resources you've just added to ~/.Xdefaults, simply type xscreensaver-command -reset.
For instance, if I put this in my .Xdefaults:
...Xscreensaver will now start after 2 minutes of inactivity, and will
switch to another graphics hack every 1 minute after that. If
xscreensaver.cycle is set to 0, then no cycling will take
place. All of these options can also be set by the command line that
starts xscreensaver. There's many other options. man
xscreensaver for details.
xscreensaver.timeout: 2
xscreensaver.cycle: 1
You can play around with command-line options for all your favorite
graphics hacks, and when you've got one you like, put the same command
line flags into the appropriate entry in your .Xdefaults file. For
instance, I've got this line:
...which looks a bit different than the default kaleidescope.
kaleidescope -root -nsegments 5 -ntrails 50 \n\
If you like this feature, put this line in your .Xdefaults file:
xscreensaver.lock: True
This isn't really part of xscreensaver, but it's fun anyway. You can run any of the graphics hacks on your root window all the time, and it will just stay there merrily animating away behind all the stuff you work on. For instance, put this line in your .Xclients or .xinitrc if you really like to get dizzy and distracted while you work:
kaleidescope -root -nsegments 5 -ntrails 50 &
Of course, you can use any of the hacks you like instead of kaleidescope. You could even pick one that doesn't give you motion-sickness, but where's the fun in that?
That's all!