HowTo: Install the XScreensaver packages on Ubuntu

The XScreensaver packages are a series of fancy alternate screensavers that have a popular history. They are much more enjoyable than the boring default Ubuntu screensaver which is just… a black screen.

The Hypertaurus XScreensaver

Unfortunately the XScreensavers package hasn’t really been updated in awhile and doesn’t integrate very nicely into the current flavours of Ubuntu without some manual tweaking, so that’s exactly what I’m going to cover right here.

Issues to deal with

This document will cover the following:

  • Installing the XScreensaver packages Configuring Ubuntu to use XScreensaver instead of the default gnome-screensaver
  • Configuring Ubuntu to lock the screen with the XScreensaver
  • Fixing the bad fonts issue in XScreensaver Setting a custom RSS feed for text-based XScreensaver packages

These instructions have been tested on Ubuntu 12.04 (Precise Pangolin) and 14.04 (Trusty Tahr).

Making it happen

  1. Open a terminal.
  2. Uninstall the boring default Ubuntu screensaver with:

    $ sudo apt-get remove gnome-screensaver
  3. Install the XScreensaver packages with:

    $ sudo apt-get install xscreensaver*

    (note the asterisk on the end to install all xscreensaver packages)
  4. Open the Dash (Ubuntu logo at the top-left of screen) and type in the word “start”. An icon will appear referring to “Startup Applications”. Click on it.
  5. The window that appears shows which applications will be started when you login to your machine. Click on the “Add” button.
  6. In the new window that appears, type “XScreensaver” into the Name field, then type in “xscreensaver -nosplash” into the Command field, then type in “Start the XScreensaver” into the Comment field.
StartupApps
  1. Click on the “Add” button and then click on the Close button on the previous window.
  2. That takes care of starting the XScreensaver, so now let’s fix the lock screen keyboard shortcut. Click on the Dash again and type in “keyboard” and then click on the “Keyboard” icon.
  3. In the window that appears, click on the “Shortcuts” tab.
  4. At the bottom of the left pane, click on “Custom Shortcuts”.
  5. Click on the “+” button to add a new custom shortcut.
  6. Give the shortcut a name, eg: “Enable the lockscreen”.
  7. In the Command field, type in “xscreensaver-command -lock” and then click on the Apply button.
  8. You will now see your new shortcut listed, but it doesn’t have a keyboard combo for it yet, so click on the word “Disabled” with your mouse and it will change to “New accelerator…”.
  9. Now using your keyboard, press the key combo you’d like to use to lock your PC and start the XScreensaver. The default combo is CTRL+ALT+L but you can use any combo you like. If you do use CTRL+ALT+L you will be told that it’s already in use by the Gnome-Screensaver (which you uninstalled earlier, remember?), so just tell it to reassign it to your shortcut.
LockScreenKeyboardCombo
  1. Close the keyboard settings window.
  2. Now we need to sort out the fonts. The way XScreensaver looks for fonts is not like any other application. It needs to have a predefined list of available fonts, so we need to provide that list. We will get the “Ubuntu Font Family” (that comes with current releases of Ubuntu) enabled for use in XScreensaver, but you can apply this to any of the font folders on your machine.
  3. In your terminal, type in the following:

    $ cd /usr/share/fonts/truetype/ubuntu-font-family
    $ sudo mkfontscale
    $ sudo mkfontdir

  4. Repeat the above for all the fonts you wish to add to your system, eg: substitute the path /usr/share/fonts/truetype/msttcorefonts for the Microsoft fonts from the ubuntu-restricted-packages meta-package or the ttf-mscorefonts-installer package.
  5. Create a new file (or edit any existing file) as follows:

    $ sudo nano /usr/share/X11/xorg.conf.d/50-fonts.conf
  6. Type/paste in the following into your new file:

    Section "Files"
        FontPath "/usr/share/fonts/truetype/ubuntu-font-family"
    EndSection

  7. Add as many FontPath entries you need between the Section/EndSection block for all the fonts you want available that you ran step 18 on.
  8. Save your changes with CTRL+X, then “Y” and then Enter.
  9. Now type in the following to enable the fonts now (or simply reboot):

    $ xset +fp /usr/share/fonts/truetype/ubuntu-font-family
    $ xset fp rehash

  10. Repeat the xset +fp <path> command as many times as required to add all the fonts you setup in Step 18 before the xset fp rehash command, or simply reboot to do them all in one hit from your X11 config file in step 21.
  11. Now we’re ready to fix the fonts in XScreensaver. In this example we’re going to fix the fonts in the StarWars screensaver. What exactly is wrong with the fonts in the StarWars screensaver I hear you ask?

    Simply this:
Ugly fonts in the StarWars screensaver
Yuck
  1. Click on the Dash and then type in “screensaver”. An icon called “Screensaver” will appear below it. Click on it.
  2. In the Screensaver Preferences window that appears, scroll down the list of available screensavers to find “StarWars”. Click on it to highlight it.
The XScreensaver Preferences Tool
  1. A preview of the screensaver will appear in the pane on the right. You will notice that the font in the screensaver looks awful as in the above image.
  2. Click on the “Settings…” button. A new window will appear.
  3. In the Settings window, click on the “Advanced>>” button at the bottom. The window content will change.
Star Wars Preferences Advanced Settings
  1. You will see the command line that starts the screensaver. Modify the line so that it looks like:

    starwars -root -font "-misc-ubuntu-bold-r-normal--180-0-0-0-p-0-iso8859-1"
  2. Click OK and repeat this modification to any other screensaver that uses a proportional font in its text, for example the FlipText screensaver.
  3. Finally, let’s set a custom RSS feed for the screensavers that use text so that they show something useful. Click on the “Advanced” tab in the Screensaver Preferences window.
Setting the RSS Feed for the XScreensaver
  1. At the bottom-left in the “Text Manipulation” section, make sure “URL” is selected and change the URL text to your favourite RSS feed’s URL, for example ITNews’ RSS feed for “all content” is:

    http://www.itnews.com.au/RSS/rss.ashx
  2. Test the StarWars screensaver now by clicking on the “Display Modes” tab and then select “StarWars” from the left pane to make it appear in the preview window. The time the fonts should look much nicer as follows:
Much nicer
Much nicer!
  1. Now go through the list of screensavers, enabling and disabling those that you want to use. As you click each one, its preview will appear on the right.
  2. Set the Blank After, Cycle After and Lock Screen After values accordingly, eg: 10 minutes a piece.
  3. Close the Screensaver Preferences window and test locking your PC by pressing CTRL+ALT+L or whatever combo you set in step 15, and your screen should fade out and start displaying a random screensaver from your list of enabled screensavers. When you move the mouse or press a key, a login prompt should appear.
  4. Pat yourself on the back. You are done.

Choosing your own font to use instead of the Ubuntu Font Family fonts

  1. Choosing your own font is simple. For each set of fonts that you processed in Step 18, type in the following, using the Ubuntu Font Family as this example:

    $ cat /usr/share/fonts/truetype/ubuntu-font-family/fonts.dir
  2. This lists all the possible fonts available for that family. Copy to the clipboard the font description you wish to use.
  3. Paste the description as the font argument in the command line of the screensaver you wish to modify.Note that you will need to adjust the font size/quality value in your command line because they are rendered as scaled bitmaps, not outlines. For example, in Step 32 we specify the font size to be “180” so that the fonts appear smooth and clean when scaled. If you don’t specify this, then the font will be generated into a bitmap using the smallest size before being scaled up in the screensaver, resulting in pixelated fonts.

    SPECIAL NOTE: Some screensavers require proportional fonts to be used and others require fixed-width fonts. If you try to use the wrong type of font, the screensaver will likely crash.
  4. Choose the appropriate font type from the list of available fonts.
  5. Preview your screensaver and make adjustments as required. If you’d like to test the screensaver directly without running up the Preferences tool, launch the screensaver binary in a terminal with the font description as an argument.

    For example, for the StarWars screensaver, you can run it in a window as follows:

    /usr/lib/xscreensaver/starwars -font "-misc-ubuntu-bold-r-normal--180-0-0-0-p-0-iso8859-1"
  6. Pat yourself on the back again. You are done.