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.)

5 comments:

  1. Thanks! I was just looking for this, just one note, I think that on Ubuntu 11.04 the correct path for xscreensaver scripts would be /usr/bin instead of /usr/local/bin, and /usr/share/applications/xscreensaver-properties.desktop for properties file.

    http://packages.ubuntu.com/natty/amd64/xscreensaver/filelist

    ReplyDelete
  2. Oh, and since i found out that gnome-screensaver started using gnome session for idle timeout, which is not present in xfce environment, I worked around it by putting xautolock to start up automatically and then use your script since it was already there: xautolock -time 5 -locker 'xscreensaver-command -lock' &

    ReplyDelete
  3. Works like a charm - thanks!

    ReplyDelete
  4. Thanks Robert and Ugljesa! I find gnome-screensaver-preferences is gone in GNOME 3, so I skipped the step 2 and modified xscreensaver-command to ignore -prefs and -demo option.

    ReplyDelete