Wednesday, May 30, 2012

How to replace screensaver in XFCE

Intro: XFCE's default screensaver

By default XFCE is shipped with a quite ascetic xscreensaver. Some people ma find it not attractive. So I do also. For example, if you install an alternative screen locking application called i3lock there are about no chances that it will be used by XFCE. Even there are no other alternatives installed. Because XFCE knows nothing about it. But user definitely knows and wants to replace the default screensaver with a preferred one.

The entry point for XFCE to screen lockers is a script called xflock{4}. All XFCE applications which need to start a screensaver or to lock the screen run it. (Note: Since version 4.10 it is shipped as a part of xfce4-session package.) E.g., XFCE's power manager will call xflock{4} when an action "Lock Screen" is specified for several ACPI events like "LID closed"; or when system goes suspend. The script itself launches only a default screensaver.

Possible alternatives

The ugly thing about this script is that it contains hardcoded list of screensavers. So if yours favorite screensaver is not listed there it won't be launched. The priority of these locking applications is:
  1. xscreensaver
  2. GNOME Screensaver
  3. xlock
  4. slock
And nothing else!

Solution

The straight way is to add an alternative screensaver is to hack xflock{4}'s contents. Replace:

for lock_cmd in \
  "xlock -mode blank" \
  "slock"
  do

with:

for lock_cmd in \
  "my-favorite-screensaver" \ # e.g. i3lock
  "xlock -mode blank" \
  "slock"
  do

But on the system's next update these changes more likely will be overrided with the default ones and yours screensaver will stop launching.
The best way of course is to extend xflock{4} and send the patch to upstream; but not this time :).
Another way is to pretend like we have a one of the above-mentioned screensavers which XFCE is familiar with:
  1. Create a script which launches your screensaver. For example, with the following contents:
    #!/bin/sh
    if ! pidof i3lock > /dev/null 2>&1; then # launch once only
      /usr/bin/i3lock --dpms -c 000000
    fi
    
  2. Make a symbolic link /usr/bin/slock to the newly created script;
After these steps there will be a new system's default screen locker.

Note: Do not forget to uninstall xscreensaver, gnome-screensaver, xlock from the system if there are any to prevent using of them because of their's higher priority.

Note: Please keep in mind about created symlink if once you decide to install an application with the same name.

3 comments:

  1. Thank you, actually my problem was that I wanted to use the same gnome uses to lock the screen because xscreensaver did not show caps lock status and keyboard layout which was very annoying (besides xscreensaver is very ugly).

    Your post helped me find out how xfce4 locking works. In addition to having gnome-screensaver installed I had to have it *running* before locking started to work. Adding it to session autostart was what I needed.

    Thanks!

    ReplyDelete
  2. Thank you! Great solution for Mint :)

    ReplyDelete
  3. many thanks! Though it would be good to mention where to find the xflock4 for noobz like me, it took me some time to find out how to how to use locate

    ReplyDelete