Setting Up Xscreensaver

Created: July 8, 1998
Last updated: July 9, 1998
Development stage: Beta

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:

  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.

Choosing Screensaver Graphics

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:

xscreensaver.programs:  \
                        rocks -root     \n\
			hopalong -root \n\
                        flame -root \n
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 -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.

Getting the Screensaver to Start

If you want the screensaver ready to go all the time when you're in X, put this in your .Xclients file:

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.

Controlling Xscreensaver's Behavior

By default, xscreensaver will start if the user is inactive for ten minutes. At that time it will randomly pick one of the graphics hacks in your .Xdefaults file. Ten minutes later it will randomly select another one. You can change all of this in your .Xdefaults file.

For instance, if I put this in my .Xdefaults:

xscreensaver.timeout: 2
xscreensaver.cycle: 1
...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.

Tweaking the Screensaver Graphics

We haven't mentioned this yet, but the graphics hacks that the screensaver runs are actually completely separate X programs, and they all have command-line options that change the way they look and behave. For instance, run flame. With no arguments, a new window is created and the "Flame" graphics hack runs in it. If you instead type flame -help, you'll get a listing of the options flame can take. These are described in the flame man page (yes, man flame). For instance, if we do flame -delay 100 -delay2 10000, it runs a lot faster.

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:

                   kaleidescope -root -nsegments 5 -ntrails 50 \n\
...which looks a bit different than the default kaleidescope.

Locking the Screensaver

You can easily set up xscreensaver to "lock" ... that is, it won't let you back in to your system without your password. This could be useful if you have stuff on your system you want to keep private from anyone who might wander by, like at work or something I guess. In the demo, you can turn it on by clicking "Edit Parameters" and then "Require Password." Then type xscreensaver-command -activate to turn the screensaver on, and you'll notice that it asks for your password when you try to do anything.

If you like this feature, put this line in your .Xdefaults file:

xscreensaver.lock: True

One More Cool Trick

This one is guaranteed to SURPRISE and AMUSE YOUR FRIENDS!TM

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!

Send comments and corrections to Paul Winkler.
© 1998 Paul M. Winkler. All rights reserved. Permission is hereby granted to use, distribute, and copy this document for non-profit purposes only. You may modify this document as long as credit to me is given. Any unauthorized commercial useage of this document is expressly forbidden. Just ask nicely. ______________________________________________________ Get Your Private, Free Email at