25 May 2011

Stupid Unix Tricks: Using the Gnome Screensaver with Xfce

I prefer to use the Xfce desktop instead of Gnome, though I use many Gnome applications from within Xfce. Unfortunately, Xfce (at least as distributed by Debian and Ubuntu) have hardcoded the use of xscreensaver. And as much as I respect JWZ's programming, the unlock screen looks like it's from the 1980s.

So I've hacked together the following workaround by creating wrappers for the xscreensaver commands:
  1. Create a file called /usr/local/bin/xscreensaver-command that contains the following:
    #!/bin/bash
    
    while [ "$1" != "" ]
    do
      arg=$1
      shift
    
      case "$arg" in
       -prefs)
         gnome-screensaver-preferences
       ;;
       -demo)
         if [[ "$1" =~ ^[0-9]+$ ]]; then
           num=$1
           shift
         else
           echo $1
         fi
         gnome-screensaver-preferences
       ;;
       -cycle)
         gnome-screensaver-command --cycle
       ;;
       -next)
         gnome-screensaver-command --cycle
       ;;
       -prev)
         gnome-screensaver-command --cycle
       ;;
       -lock)
         gnome-screensaver-command --lock
       ;;
       -activate)
         gnome-screensaver-command --activate
       ;;
       -deactivate)
         gnome-screensaver-command --deactivate
       ;;
       -time)
         gnome-screensaver-command --time
       ;;
       -exit)
         gnome-screensaver-command --exit
       ;;
       *)
         echo Unrecognized command: $arg
       ;;
      esac
    
    done
    
    
  2. Create a file called /usr/local/bin/xscreensaver-demo that contains the following:
    #!/bin/bash
    
    gnome-screensaver-preferences
    
    
  3. Create a file called /usr/local/share/applications/xscreensaver-properties.desktop that contains the following:
    [Desktop Entry]
    Exec=xscreensaver-demo
    Icon=Screensaver
    Terminal=false
    StartupNotify=true
    Name=Screensaver
    Comment=Change screensaver properties
    Type=Application
    Categories=Settings;DesktopSettings;Security;X-XFCE;
    
    
    Change the Icon entry to the name of a screensaver icon in /usr/share/icons or /usr/local/share/icons. (I downloaded a Gnome Screensaver.svg icon from here.)

I've been using this wrapper for over three years on Debian and Ubuntu distributions with no problems. (I should note, however, that Gnome Screensaver uses the Gnome Power Manager rather than Xfce Power Manager--- as I've been using the former, this has not been an issue for me.)