[an error occurred while processing this directive]

Writing an Xscreensaver Module using Xlib

The simplest way to write your own screensaver for Linux is by creating a new module for the program xscreensaver. This way, all is needed is a program that draws something, while all the rest (activating the screen saver when needed, locking the screen, checking passwords, etc) is done by xscreensaver itself.

I assume that xscreensaver is installed and running on your computer. The following pages tell how to write stand-alone programs that draw something in the root window. When used as modules of xscreensaver, they draw to the screen whenever the screen saver is activated. These programs use only calls to Xlib, and provide a sort of basic tutorial on Xlib.

The following is a list of pages, each containing the explanation of a module. The first one is very simple. The next ones introduce, one by one, the concepts that are needed to write more complex modules.

  1. The simplest screensaver
  2. Getting the screen size
  3. Using colors
  4. Drawing characters, using fonts, using font metrics.
  5. Images: reading from file, embedding in the program, transparency, deallocating (to finish).
  6. Animation
  7. Animation: double buffering
  8. Animation: clipping, clipping using a bitmap, clipping origin.
  9. Redrawing under other windows: redrawing, using the double buffer.
  10. Modules running in a window: creating a window, resizing, saving content.
  11. Permanently changing the background (to be finished).
Instructions for testing and installing a new module for xscreensaver.

The example modules are not very elaborated: they use Xlib alone (no toolkit and no resource managment); they can only draw in the root window (and not in a separate window); they determine the display to open using the environment variable $DISPLAY only. Some more tips can be found in the xscreensaver FAQ.

This is not an introduction to the X Window system programming, as it only covers what is needed for the purpose of writing a screensaver module. For more on Xlib alone, I suggest this page on Xlib. If you want to write a GUI, you should use some widget library, such as the Athena Widget or Motif. There is a good tutorial on Motif on the web. A good starting point about X Window in general is this list of X link.

I would like to hear what you think (comments/corrections are welcome). My email is liberato@dis.uniroma1.it.