Hack 23. Spice Up Your Desktop with Creative Mouse Cursors
Replace the boring default mouse pointer, resize cursor, wait cursor, and the rest with colorful custom animated cursors.
Microsoft Windows lets you change cursor themes easily. Linux doesn't make it quite as easy (although the KDE desktop environment comes close). This hack explores how to check if your distribution of Linux supports cursor themes, how to find, download, and install new cursor themes, and how to set up your desktop to use them. A wide variety of custom cursor themes are available, ranging from the subtle (cursors decorated with a red dot) to the outrageous (a Tux penguin grabbing windows to resize them!).
4.3.1. Does Your Desktop Support Cursor Themes?
You need XFree86 4.3 or later or Xorg (a fork of the XFree86 project) for custom cursors to work. All recently released Linux distributions include one or the other, so it is unlikely that your Linux desktop cannot support custom cursors, but you need to be sure. Type this command to see which version of X you have installed:
# X -version
If your Linux distribution installed XFree86, all you have to do is make sure the version is 4.3 or higher. For example, look for a string something like the following in the output of the X -version command:
XFree86 Version 4.3.0 (or higher)
If your Linux distribution is using the Xorg branch of X11, you should see something like this in the output:
X Protocol Version 11, Revision 0, Release 6.7 (or higher)
If you see anything like either of these strings, it means your version of X supports custom cursor themes.
4.3.2. What Themes Are Available by Default?
Unfortunately, Linux distributions vary considerably as to where they store the default cursor themes. If the documentation for your Linux distribution doesn't tell you where to find these themes, you can use a trick to find out where your particular distribution looks for cursor themes. Generally, the file you want to examine is /usr/X11R6/lib/X11/config/Imake.tmpl. Check to see if the file exists with the ls command:
# ls /usr/X11R6/lib/X11/config/Imake.tmpl
If the response is "No such file or directory," you might be able to find the file with the following command:
# locate Imake.tmpl
If this file does not exist on your system, you're going to have to find another way to locate where your distribution stores globally available cursor themes. A Google search or browsing online forums specific to your distribution are good places to start.
If this file does exist on your system, this command should help you determine the default locations where your distribution stores cursor themes:
$ grep XcursorPath /usr/X11R6/lib/X11/config/Imake.tmpl # ifndef XcursorPath # define XcursorPath "~/.cursors:~/.icons:/usr/local/share/cursors/xorg-x11:/usr/ share/cursors/xorg-x11:/usr/share/pixmaps/xorg-x11" #ifndef XcursorPath # define XcursorPath Concat(~/.cursors:~/.icons:/usr/local/share/cursors/xorg-x11:/ usr/share/cursors/xorg-x11:/usr/share/pixmaps/xorg-x11:,IconDir) XCURSORPATH = XcursorPath /* Xcursor cursors path */
The useful information is the first line that includes define XcursorPath. Notice that this particular distribution (Gentoo) defines the XcursorPath to search the following directories:
~/.cursors ~/.icons /usr/local/share/cursors/xorg-x11 /usr/share/cursors/xorg-x11 /usr/share/pixmaps/xorg-x11
Check all these directories to see if any theme files exist. The first two directories are below your home directory, and few, if any, distributions install alternate cursor themes there by default. So, you're more likely to find alternate themes in one of the last three directories in the list. Because I'm "in the know" about Gentoo and therefore have an unfair advantage, I would check the /usr/share/cursors/xorg-x11 path first:
# ls /usr/share/cursors/xorg-x11 Blue Silver default gentoo-blue handhelds whiteglass Gold blueglass gentoo gentoo-silver redglass
There they are. I can choose between any of these cursor themes by referencing the name of the directory that holds the theme.
4.3.3. Set a Personal Default Theme
Each user can set his own default cursor theme by creating or modifying a file called ~/.icons/default/index.theme (recall that the ~ represents your home directory). This index.theme file is the one that tells your system which cursor theme to use. Create the directories you need with the following command:
$ mkdir ~/.icons ~/.icons/default
Now use your favorite editor to create the index.theme file in the ~/.icons/default directory. Place the following two lines in the file:
[Icon Theme] Inherits=whiteglass
This example assumes you have a cursor theme called Whiteglass installed on your system (the earlier example showed that it exists on my system, because the directory name whiteglass appears in the /usr/share/cursors/xorg-x11 directory that contains all the globally available cursor themes). Obviously, if you don't have the Whiteglass theme on your system, this setting won't do you any good. The next time you start your desktop, you'll see only the default cursor theme, because Whiteglass doesn't exist. If you don't have Whiteglass, substitute a theme name that you do have installed.
Start up your favorite desktop window manager, and voilà, you should see a new set of mouse pointers.
4.3.4. Tips for Users of NVIDIA Display Cards
It is not uncommon for people with NVIDIA display cards (such as the GeForce series) to use the accelerated NVIDIA driver available from the NVIDIA web site. If you're using the accelerated driver, not the default driver that comes with X11, your mouse cursors can tend to flicker.
Here's how to fix that problem. Find the Device section for your NVIDIA card in your X11 configuration file. This file is called XF86Config, XF86Config-4, or xorg.conf, depending on the X server you are using, and it is usually found in the /etc/X11 directory. Look for the Device section where you define the video card driver. It should contain these lines, although not necessarily exactly as they appear here:
Section "Device" Driver "NVIDIA" Option "HWCursor" "On"
Turn off the HWCursor option so that it looks like the following:
Option "HWCursor" "off"
The next time you start up your desktop, the flicker problem should be gone.
4.3.5. Get Custom Cursor Themes, Example 1
One popular source of custom cursor themes and other eye candy is a site called KDE-Look (http://www.kde-look.org). The URL for cursor themes is http://www.kde-look.org/index.php?xcontentmode=36. Find a cursor theme you like and download it. Though this web site is KDE-focused, the cursor themes work on any X server that meets the earlier criteria.
Unfortunately, there's no standard way to package a cursor theme. Different people package their cursor themes in different ways, and not everyone includes a README file to tell you how to unpack and install their cursor themes. This makes it impossible to provide you with one set of instructions on how to unpack and install a cursor theme, and to expect those instructions to work for every theme you download.
But there are some simple patterns to look for that make it easy to adapt how you unpack and install cursor themes. For this example, download the Red Dot cursor theme from the KDE-Look site. The URL for this cursor theme is http://www.kde-look.org/content/show.php?content=4805 and the file (at the time of this printing) is called 4805-RedDot.tar.gz. Find or create a work directory where you can unpack the file and change to that directory. For example:
$ mkdir ~/temp $ cd ~/temp
After you install the cursor theme, you can delete the contents of this work directory. Decompress the file with the following command:
$ tar zxvf 4805-RedDot.tar.gz
In general, once you unpack a cursor theme, the directories that matter are the ones that contain a single subdirectory below them called cursors. In this case, the RedDot directory has a subdirectory called cursors. That tells you which directory you want to install. (For the curious, the RedDotSource directory contains all the files the author of the theme used to create the Red Dot theme.)
You can install the Red Dot cursor theme simply by copying the RedDot directory and its contents to ~/.icons (the .icons directory in your home directory):
$ cp -a RedDot ~/.icons
If you want the Red Dot cursor theme to be available to all users, copy RedDot to one of the shared directories instead. (Given the previous example of how this Linux distribution is configured, the shared directories are /usr/local/share/cursors/xorg-x11, /usr/share/cursors/xorg-x11, and /usr/share/pixmaps/xorg-x11. They might be different for your system.) You need to log in as root to do this; otherwise, you won't have the privileges necessary to write to these directories.
Now edit the ~/.icons/default/index.theme file to contain the following two lines:
[Icon Theme] Inherits=RedDot
Start up your favorite window manager or desktop environment (or restart the one you're using), and you should see the Red Dot mouse cursors.
4.3.6. Get Custom Cursor Themes, Example 2
As I mentioned before, there's no standard way to package a cursor theme. So, here's another example of how to install a cursor theme that should illustrate that the principles are the same, even if the package is different.
In this case, download the Golden XCursors 3D theme, which (at the time of this writing) is at http://www.kde-look.org/content/show.php?content=5507 and is located in a file called 5507-Golden-XCursors-3D-0.8.tar.bz2. Unpack the file with the following command:
$ cd ~/temp $ tar jxvf 5507-Golden-XCursors-3D-0.8.tar.bz2
This creates a subdirectory called Golden-XCursors-3D-0.8. (If the version of Golden Cursors has changed since the publishing of this book, the filename will be different. Follow these instructions using the new filename.) Change to this subdirectory with the following command, and list that directory's contents:
$ cd Golden-XCursors-3D-0.8 $ ls COPYING Gold README default
In this case, the author created a README file, but let's ignore it for a moment and use the same reasoning used earlier to identify the relevant directory. Look in the directory called Gold by issuing the following command:
$ ls Gold cursors
There's the cursors subdirectory that we're looking for. So, Gold is the directory we want. Copy the Gold directory to the ~/.icons directory:
$ cp -a Gold ~/.icons
Again, if you want the Gold cursor theme to be available to all users, copy Gold to one of the shared directories instead. (Given the previous example of how this Linux distribution is configured, the shared directories are /usr/local/share/cursors/xorg-x11, /usr/share/cursors/xorg-x11, and /usr/share/pixmaps/xorg-x11. They might be different for your system.) You need to log in as root to do this; otherwise, you won't have the privileges necessary to write to these directories.
Edit the ~/.icons/default/index.theme file to contain these two lines:
[Icon Theme] Inherits=Gold
Start up your favorite window manager or desktop environment (or restart the one you're using), and you should see the Gold mouse cursors.