One thing that new users of Linux may find frustrating is that they can't do some familiar, simple things easily. For instance: You've installed Linux, you've started X, and you've decided all the default colors are no good, so now you want to change them. How do you do it?
Unfortunately the answer is a bit complex, so this document is a bit long. If you're totally new to X, you may benefit from reading this whole page. If you've already had some success playing with colors in X, go on and skim through this. First I'll describe how colors are specified in X and how to change things by hand. At the end, I will describe a few utilities that can make your life a lot easer.
Some modern X applications, such as Netscape Navigator, have their own interactive color-customization menus or dialog boxes. But for many applications, such as the many variants of Xterm, colors and many other default characteristics (fonts, window size, etc.) are traditionally set by writing an appropriate statement in a text file. Usually the file in question is called .Xdefaults, and it resides in your home directory. (If it doesn't, go ahead and make one! Look for a file called /etc/skel/.Xdefaults , which you can copy and use as a template for your ~/.Xdefaults, and modify however you like.)
By the way, remember that files that start with a dot, aka "dotfiles", are normally hidden: that is, ls won't show them unless you give the -a ("list all") flag. Configuration files are usually hidden this way because you don't want to bother with them very often, and it also provides a bit of protection against carelessly deleting them, because rm * will only delete "visible" files.
The characteristics that are controlled by the .Xdefaults file are
called "Resources." The man page or other documentation that comes
with the application should tell you what resources are available for
that app. Or you can get a list of the resources with the
appres command. For instance, appres xterm will
show you all the resources for xterm with their current
settings. Sometimes the resource names have obvious meanings. For
instance, xterm*cursorColor: Green is easy to
read. Otherwise, you can find out what the resource does by reading
the man page.
You can usually, if you prefer, specify the colors at the
command line. For example, xterm -bg blue is the same as putting
xterm*background: blue in .Xdefaults. Again, the man page
for the application in question will tell you what command line
options are available. This method is probably quicker for trying out
changes. The disadvantage is that if you try to control a bunch
of things, you end up with a very long command line. That's not such a
problem if you set up the long command as an alias, but .Xdefaults is
probably easier to read and modify.
A notable exception to controlling things with .Xdefaults is your window manager. Whichever window manager you run - Gnome, KDE, FVWM, Blackbox, AfterStep, WindowMaker, Enlightenment, TWM, etc etc etc - it probably has a separate file, or a whole separate directory, where its configuration is stored. And the resource variables that set colors are named something different in each window manager. Great. Fortunately, many modern window managers, such as WindowMaker, are adding on-the-fly configuration tools that can make it a lot easier.
app-defaults directory (which is
/usr/X11R6/lib/X11/app-defaults/ on my RedHat
system). These files set default resources for all users on your
system. Usually you will ignore this file and instead edit the
.Xresources file your own home directory. Even so, the app-defaults
file can be useful if you're not sure what resources you can edit, or
want to see what they're set to normally.
In X, colors can be specified in two ways: by giving an
RGB values will seem strange to those not familiar with them. An RGB value is really three values: one for red, one for green, one for blue. Just to make things confusing, the numbers are usually hexadecimal, where the letters A - F are used to represent the numbers 10 through 16. And since we're in base 16 rather than base 10, the number "10" now represents one more than F, which means hexadecimal 10 = decimal 17.
As an example, rgb:00/00/00 means "black", and rgb:FF/FF/FF means
"white." What about something like rgb:FF/00/45? This means red =
FF (the highest possible value, equal to 255 in decimal notation);
green = 00 (the lowest possible value); blue = 45 (a medium-low value,
equal to 68 in decimal notation if I did the conversion
correctly). Lots of red, no green, a little blue... probably this is a nasty
brilliant magenta color.
There's an alternative notation, too:
#ff0045 is the same as rgb:FF/00/45. You may
have seen this notation used in web page design.
Or you could just specify the color as "IckyBrightRed" and leave it at that. Seems simpler. But there's a snag ... is IckyBrightRed a valid color name? And if so, what's it look like? Keep reading.
Let's try a concrete example. In an xterm, type this:
xterm -bg rgb:20/A9/25 -fg black -ms Goldenrod
This starts a new xterm. As you can see, the cursor is a
nice golden color, the text is black, and the background is a bit
heavy on the green side. Maybe try something less bright than A9 for
the green value. Usually it's easiest to change in big steps first, then
fine-tune. So next we might try something like
rgb:20/80/25.
How did I know what flags to set? I typed xterm -h, of course.
Once you have something you like enough to use all the time, put it in your .Xdefaults file. For example:
xterm*background: rgb:20/A9/25
xterm*cursorColor: Goldenrod
There's a catch: Your window manager probably has its own commands to set the root window color, and those will take over when the window manager starts. So you will probably have to learn how to do it for your own specific window manager anyway.
But xsetroot is still a reasonably quick way to try out different colors, since you can use bash's command-line editing and just keep repeating the same xsetroot command with slightly different colors, and you'll see each one instantly. Then you can just use the mouse to select the last color you typed, and use the standard X-windows "paste" function (the middle mouse button) to paste this color into the appropriate place in the configuration file for your window manager.
There are other command-line X-background tools: for instance, if
you do this:
bggen blue magenta | xv -root -quit
... you will see a background that fades from blue to
magenta. Read man bggen for details. This method, unlike
xsetroot, seems to work fine for me when started from the .Xclients
file, so hopefully it will work with your window manager.
There are two problems with abstract color names: First of all, you don't know if there is such a color until you find a list of abstract color names your system can display. Secondly, you don't really know how icky, how bright, or how red "IckyBrightRed" is until you actually see it... the names are pretty subjective.
There is a partial answer to these problems: a list of rgb values for the abstract colors exists in /usr/X11R6/lib/X11/rgb.txt (some systems may put the file in a different place). Actually, you can get the same list by typing showrgb, and the list scrolls by. There's about 700 color names in there. Problem is, the values are given in decimal (e.g. 255 instead of FF), which is not what .Xdefaults wants. The other problem is, there's no way to perfectly organize a three-dimensional color map in a two-dimensional text file. So if you want something "Like Goldenrod, but a little greener"... how do you know what that's called? You don't.
The rgb hexadecimal method is at least quite tweakable: if you
want "a tiny bit less red" than rgb:FA/B2/38, try
rgb:F9/B2/38. (That will be such a slight difference you
may not even notice it, so try EA/B2/38 and see if that's
not too drastic.) The big problem is, hexadecimal numbers take a
little getting used to (remember in school when they taught you that A
is one more than 9, but one more than F is 10? No? Me neither). And
you will still find yourself typing a number in .Xdefaults, starting
the app in question, re-typing the number, re-starting the app, over
and over and over until like it. Or you give up and stare at something
that hurts your eyes every time you work.
By now you're thinking, "There must be a better way."
When started in X, GNU Emacs has an option in Edit => Text Properties => Display Color that will show and list 64 "abstract" color names, so you can see, for instance, what SpringGreen looks like. The problem is that only 64 colors are listed, and if you have a monitor made since the stone ages, you can probably use a lot more colors than that. But this is better than nothing.
One thing I do like about RedHat's default window manager (AnotherLevel, a heavily-tweaked FVWM2) is that if you go into the Preferences menu, you can choose Background and get a nice little utility onscreen. Windows95 people will like this; it has sliders you can use to adjust Red, Green, and Blue levels. You can apply the result directly to the screen's background, or you can choose a pixmap for an image to display. There's a little box that displays the color as you adjust it, and right under that you can see the value of the color you've currently chosen as a 24-bit RGB color like rgb:003E2A
A nice thing about this is that you can, of course, write that color value anywhere it can be used, for instance I've done this to choose colors to put in my .Xdefaults file, like so:
nedit*text.foreground: rgb:AB/D9/8A
nedit*text.cursorForeground: rgb:FF/69/00
The only problem here is that this doesn't seem to be an independent application; I can't find a way to start it when using any other window manager, and lately I prefer WindowMaker. WindowMaker does have its own menu-based background selection, but there is a very limited set of background colors in the menu.
I actually downloaded five apps from sunsite, but three of the five wouldn't compile and/or run on my system, so I tossed 'em. Here's a comparison of the two I did get.
xcolsel by Markus Koelblin,
available as xcolsel-1.0.tar.gz. A nice simple app with a well-written man page.
There are sliders for adjusting red, green, and
blue. There's a little "lookup" feature which will search the
rgb.txt database for a near match, and will give you the closest abstract
color name. If none is found, there's a beep. There's a command-line flag
that controls how close matches must be (I found this handy, since nearly
every color I tried to get a name for beeped at me. xcolsel -near 30
beeped less, but returns some pretty inexact matches. Take your
pick). You can also browse through the rgb database and see what all
those weird names look like.
Then there's xcolorsel by Michael Weller (not to be confused with
XColorSel by Jon Steiger). Look for xcolorsel-1.1a.tar.gz . The disadvantage compared to xcolsel is
that there's no interactive color editing. The big advantage is that you
can "grab" any color displayed anywhere on your monitor and find out
what it is!
It has a scrollable list of colors with their names and rgb values, and each has a little swatch of the color displayed next to it. You can also quickly and easily try out a pair of colors for foreground (text) and background, which is really useful for setting up any text-based application's default colors.
Both xcolsel and xcolorsel are handy in slightly different ways; I recommend that you get both. If I should find out about a more comprehensive single solution, I'll post it here.
Now type this:
xv -root -quit filename
Note that your window manager may have its own way of doing this without using xv. For instance, as of version 0.17, WindowMaker can do it with one line in the GNUstep/Defaults/Windowmaker file.
How do you make your own nicely tileable images? With the Gimp, of course. Josh Go has written a nice tutorial on this very subject at http://jgo.local.net/GimpGuide/desktop.html. He also describes how to make the "tiles" that icons sit on top of in, for instance, WindowMaker or Afterstep.
Send me some mail slinkP home page ![]()