Creating animated backgrounds for the KDM login screen

Whereas GDM makes it easy for the user to use an arbitrary application that can draw to the root X window for drawing the background of the login screen (e.g. in order to create an animation in the background), KDM requires a few tricks to make this possible.

KDM's configuration is stored in <KDE_base_dir>/share/config/kdm. Following configuration files can be found there (files not described here are insignificant for the purpose of modifying the login manager screen background):

  • kdmrc — main configuration file, describes the look and feel of the login window as well as login options and permissions
  • backgroundrc — stores the configuration of the login screen background, which is drawn by kdesktop
  • Xsetup — shell script which is run as root just before the login window appears
  • Xstartup — shell script which is run as root after the user has been authenticated and before his or her session starts

KDesktop does not work with just any program that draws to the root window and can only use specially written applications (e.g. kworldclock) to draw an animated background. Thus, in order to animate the background using an application which was not designed to work together with KDM, it is necessary to first turn off kdesktop which draws on top of the root window and covers it. This is accomplished by setting UseBackground=false in kdmrc.

Some old versions of KDM seem to not support this — in such case it is necessary to kill the kdesktop process in Xsetup using killall kdesktop. If this solution is used, the background set in backgroundrc should be similar to the background of the animation started later on in order to avoid screen flicker at the moment kdesktop is killed.

We can then use Xsetup script to start an animation. Any program that can draw to the root window of the X server can be used. Each xscreensaver screen hack can draw to the root window and the over 100 screensavers available in most distributions are a good place to start. Also, MPlayer can play movies in the root window when used with the appropriate command-line switch (however, this only works with some mplayer video drivers — see mplayer's man page for details). If the animation needn't fill the whole background, any application can be run, not only those that draw to the root X window.

However, using interactive apps can be tricky. One major problem is security — Xsetup is run by root and as such, any applications that it runs have full access priviledges to all resources of the whole system. This is a big threat to security and can lead to compromising the machine. Any software that reads input from the keyboard or mouse, from the network etc., especially any software that runs interactively, can potentially be a security risk. Such software should never be started by Xsetup, unless the administrators really know what they're doing. Another concern is that since no window manager is running while the KDM login window is visible, one should manually set each window's position and size using command line parameters (also, it may be impossible to switch between open windows — this has the positive side effect of potentially making exploiting an interactive app running as root a little bit harder). Note that the animation or any other app started in Xsetup needs to be started in the background, otherwise the script won't be able to exit normally and users won't be able to log in at all.

The animation started by Xsetup should be killed in Xstartup in order to avoid wasting CPU time and possibly thrashing users' desktops (depending on the Desktop Environment used). This can be easily accomplished by saving the animation application's PID to a file when it is started and retrieving it from that file when it is needed to make killing the right process possible.

The example below creates a KDM login screen which uses the animation of glmatrix X ScreenSaver as a background and displays a round clock in the upper left corner of the screen (using oclock).

Contents of kdmrc (relevant part only):


Contents of Xsetup:

#! /bin/sh
# Xsetup - run as root before the login dialog appears
#xconsole -geometry 480x130-0-0 -notify -verbose -fn fixed -exitOnFail -file /dev/xconsole &
# Start clock, write PID to file in order to be able to kill it later
oclock -transparent -fg "${clockcolor}" -bd "${clockcolor}" -geometry 150x150+20+20 &
echo $! > /var/run/
# Use glmatrix xscreensaver to draw the background, save PID to file
/usr/X11/lib/xscreensaver/glmatrix -root &
echo $! > /var/run/

Contents of Xstartup:

#! /bin/sh
# Xstartup - run as root before session starts
# Kill oclock
if [ -f /var/run/ ]; then
&nbsp;&nbsp;&nbsp;&nbsp;kill `cat /var/run/`
&nbsp;&nbsp;&nbsp;&nbsp;rm -f /var/run/
# Kill glmatrix animation
if [ -f /var/run/ ]; then
&nbsp;&nbsp;&nbsp;&nbsp;kill `cat /var/run/`
&nbsp;&nbsp;&nbsp;&nbsp;rm -f /var/run/
# Default contents of Xstartup - important
exec sessreg -a -l $DISPLAY $USER
Ten serwis używa plików cookies. Możesz określić warunki przechowywania i dostępu do plików cookies lub całkowicie zablokować ich wykorzystywanie w ustawieniach Twojej przeglądarki. Pliki cookies są używane wyłącznie w celu zapamiętania stanu rozwinięcia elementów bocznego menu oraz niniejszego komunikatu.