Random backgrounds for the desktop

Picture Changer


A new background image is the quickest way to liven up your desktop. Tools such as Zufall and genbg help you change your wallpaper automatically.

By Andrea Müller

Ne¸a Cerin

Most people don't like eating their favorite food every day, and for the same reason, many users don't like always looking at the same wallpaper. If you prefer to change your wallpaper at regular intervals, you could set up a cronjob, but programs such as Zufall [1] and genbg [2] save you a step by automatically switching the desktop background image. Zufall changes the wallpaper at predefined intervals, and genbg changes the background when you launch the X server.

Working with Zufall

Zufall, which was written by Moritz Orbach, is available the project homepage. To build the tool, you need the imlib2 graphics library and the package with the header files. Follow standard procedure, configure, make, and make install. You can leave out the last step if you like. After completing the build, you should be able to run Zufall directly from the source code directory.

Zufall supports a wide range of image file formats and has no trouble handling JPEG, PNG, BMP, GIF, XPM, and TIFF files. But to avoid wasting memory, you might prefer to restrict the selection to the compressed formats, JPEG and PNG. The simplest way of running Zufall is with the following command:

zufall /path/to/graphics_folder

When launched in this way, Zufall loads a different image file from the /path/to/graphics_folder directory every 10 minutes and installs the file as a background image. The program is not restricted to the root level of the directory; it also searches subdirectories for image files. If you point Zufall at a directory with a large collection of photos and would like to know the file name of the current image, just check the terminal window where you launch the application. Each time Zufall swaps the background image, it prints so ein zufall! (what a coincidence!) followed by the absolute path to the image in the terminal window.

If your favorite images are distributed across a number of folders, don't worry. You can pass multiple directories to Zufall as command line parameters, as in:

zufall /path/to/folder1 /path/to/folder2

The -d (for delay) parameter followed by a value in seconds specifies the interval between wallpaper changes. For example, calling zufall -d 3600 would change the image once per hour. If the display time is too long, or if you don't like the current image, you can send a HUP signal to the program's active process to tell it to swap the wallpaper immediately:

killall -HUP zufall

will give you new wallpaper right now. Zufall also reacts to the TERM signal, which quits the program. You can also talk Zufall into giving you a status display that tells you how long the wait until the next image is: killall -USR1 zufall does this for you. Note that the output goes to the terminal window where you launched Zufall and not to the window where you entered the command (Figure 1).

Figure 1: Send the "USR1" signal to a Zufall process and the tool will tell you the time until the next image change.

If one of the images is smaller than the resolution you have set, the tool draws a frame around the graphic. The frame color is based on the mean value of the colors in two corners of the image. In most cases the resulting color matches the background image quite well (see Figure 2).

Figure 2: If the image is smaller than your current resolution, Zufall draws a frame with a matching color around the background image.

Introducing genbg

If you prefer not to change the wallpaper at fixed intervals, and are happy with a new wallpaper each time you launch the X server, genbg is a good choice. genbg does not set the background image itself; instead it uses wmsetbg, a WindowMaker component. The README file in the source code directory is out of date. The README tells users to edit the src/main.c file to replace wmsetbg with another application, although the program's author has since moved the definition to the src/tools.c file. It is now possible to pass the desired wallpaper swapper, such as Esetroot [3], to a genbg build via the ~/.genbgrc configuration file.

If you prefer to change the default in the source code, just look for each instance of wmsetbg in the src/tools.c file, and replace it with the name of the desired application. After doing so, create a new configure script by running ./autogen.sh in the source directory. Then type ./configure, make, and make install to build and install genbg.

To make sure that the program automatically does what you expect it to do, you might like to create the ~/.genbgrc file first by typing genbg -config. The tool first asks you for the path to the directories with the images. Enter each folder and press [Enter] to confirm when you are finished. The next two questions prompt you to decide whether to run genbg in debug mode; again you can press [Enter] to accept the defaults. The next thing the program wants to know is which graphics formats it should use to play wallpaper roulette. The default is .jpg, and this is a good choice for photos. Of course you could enter .png if your images are in this format.

genbg then goes on to ask which tool it should use to load the backgrond image. You can press [Enter] again to accept the default, or you can enter the name of another application. The next step gives you the option of setting command line parameters for the external tool. This option makes sense if you would like the program to tile the images or scale the images to fill the screen. genbg acquires the necessary information and completes the configuration (Figure 3.) To give the random selector new directories to search, launch the tool once more with the --config option, or simply add a new directory to the ~/genbgrc file.

Figure 3: When launched with the --config option, genbg prompts you for a few details and then generates a configuration file to match.

All you have to do now is ensure that genbg is launched automatically whenever you launch X. If you log on in text mode, the easiest way to do this is to add a line that calls the program to your ~/.xinitrc. As an alternative, you could modify your window manager's autostart option. If you have WindowMaker, for example, you could add a call to genbg to your ~/GNUstep/Library/WindowMaker/autostart file.

Not for Big-Gun Desktops

Although both Zufall and genbg are very flexible, both have the same restriction: you can't use the wallpaper swappers in the KDE or Gnome environment. Both of the major desktop environments overlay the root window with a window of their own - KDE uses a Kdesktop process, and Nautilus handles the Gnome wallpaper - so both KDE and Gnome would hide anything that Zufall or genbg gave you. But those who have more simple window managers will definitely appreciate the way both tools can liven up the desktop.

INFO
[1] Zufall: http://apfelboymchen.homeunix.net/gnu/C/zufall/
[2] genbg: http://pcpool.mathematik.uni-freiburg.de/~pabloy/genbg/
[3] Esetroot article: Andrea Müller, "Background View," Linux Magazine #53/ April 2005, p. 80.