Getting the Most Out of X Resources
Several times, you've been told to add or modify a resource. How is this accomplished? The X distribution provides several programs you can use to add, modify, and view resources. The most simple method (but perhaps the most difficult) is to specify the resource for a program as an argument when the program is started. Most well-behaved X programs accept the xrm command line option for adding or modifying a single resource. The format works like this:
-xrm "resource"
Specifying resources on the command line can become tedious, to say the least. X provides considerably more sophisticated mechanisms to modify and examine resources. The most simple of these is xrdb. Xrdb is a command line utility that can load, query, and merge resources. Here are some of the common command line options:
-load filename Load the resources contained in filename into the resource database. Replaces any resources currently in the database with new values if they are specified in the file.
-merge filename Performs much like the load option, but only loads those resources which are not already modified. Nothing currently in the resource database that is encountered in the file will be loaded.
-query Show the resource database that is currently in use. Only those resources that have been modified are displayed. If all resources were displayed (including defaults), then you would probably have much more information than you expected.
Another very useful program that comes with the X distribution is editres. Editres can be used to interactively modify the resources of a particular program. After starting editres, pull down the “Commands” menu, select “Get Widget Tree”, and then click on the application you want to examine or modify. Now you should see something like what is pictured in Figure 1 (the actual hierarchy pictured is for xedit). Note that it won't look exactly like Figure 1, because I've modified my resources for editres.
Figure 1. editres, an interactive X resource editor
All widgets are laid out in a tree-like fashion, with the parent widgets on the left, and their children progressing to the right. Lines connect children to parents. You can use the box in the upper-left corner of editres to move the display around if the widget tree is larger than the window itself.
Using the “Tree” menu, you can switch between class and instance names and select certain widgets in particular. If you want to modify the resources of one particular widget, select it by clicking on it once with the left mouse button, and then, from the “Commands” menu, choose “Show Resource Box”. A popup box with all the available resources for the widget selected will be displayed, as shown in Figure 2. In the Resource Box, select a resource with the mouse, and then enter a value for the resource in the text field below. This is perhaps the easiest way to both find the names of the resources and experiment with setting them to different values.
Figure 2. Ascreen from editres showing the resource display screen
You can also make the resource string more loosely or tightly bound by adjusting which fields are highlighted at the top of the popup window. When you are ready to see the results of your changes, push the “Apply” button at the bottom of the window.
More detailed help with editres can be found on the editres manual page.
No article on X resources would be complete without detailed examples of how they can be used. To do this, we'll take a look at one simple X client—xclock—and then at a whole widget set—the Athena widgets (which are a stock part of any X11 distribution).
Let's try a couple of things with xclock. You can either make these changes with editres, so you can view them interactively, or you can add them to your .Xresources file, which you'll need to merge with xrdb. Remember, whenever you make changes to the resource database, the clients affected need to be restarted in order for the changes to take effect. If you think the normal black and white scheme of the clock is too dull, consider the following:
*xclock.foreground: steelblue*xclock.hands: steelblue *xclock.background: ivory
That should give you some ideas for starters. For a more extensive change in appearance, try:
*xclock.analog: 0
This will make the clock display in a digital fashion. Specifying 1 as the value for this resource will reset it to the normal analog display.
Let's go a step further. In the July, 1995 issue of Linux Journal, the Xaw3D widgets were introduced. The purpose of these widgets is to give the default Athena widgets a more three-dimensional look and feel. However, with no default resources, programs still can look washed out and dull. This is because no default colors have been specified for the widgets, so programs that don't change these resources explicitly will display them in black and white with unattractive, dithered shadowing. See Figure 3 for an example of this.
Figure 3. A “vanilla” xmailtool
A set of resources which make the Xaw3D widgets appear more like the popular Motif widgets appear in Listing 1.
Listing 1
! Good Xaw3d Defaults*customization: -color *shadowWidth: 3 *Form.background: gray75 *MenuButton.background: gray75 *SimpleMenu.background: gray70 *TransientShell*Dialog.background: gray70 *Command.background: gray75 *Label.background: gray75 *ScrollbarBackground: grey39 *Scrollbar*background: gray75 *Scrollbar*width: 15 *Scrollbar*height: 15 *Scrollbar*shadowWidth: 2 *Scrollbar*cursorName: top_left_arrow *Scrollbar*pushThumb: false *shapeStyle: Rectangle *beNiceToColormap: False *SmeBSB*shadowWidth: 3 *highlightThickness: 0 *topShadowContrast: 40 *bottomShadowContrast: 60 ! fix up a few of the default X clients who ! now look silly *xclock*shadowWidth: 0 *xload*shadowWidth: 0 *xcalc*shadowWidth: 0
The first resource tells all programs that color is available and should be used. Then, the shadow width for all Athena widgets is set to 3 (which looks like Motif). Default colors are then selected for most of the common widgets (buttons, scrollbars, and the like), and shadow contrast levels are set. Finally, shadows on a few X clients is a bit overkill, so shadowWidth is reduced to 0 for these. Figure 4 shows how the program now looks more aesthetically pleasing as a result of these modifications.
Figure 4. xmailtool after resource changes
This should get you started. X resources are one of the most important aspects of X programs in general, so a basic understanding of them is essential—not only for using and customizing X programs, but also writing them. You should now be able to discover the resources hiding behind your own favorite programs, and it would be good practice for you to apply the techniques in this article to a different program of your own choosing right now. Remember this while you are tinkering with X resources: X may not be as simple to configure as MS Windows, but it is much more powerful.
Enjoy!
Preston Brown is a sophomore Computer Science student at Yale University in New Haven, CT. He discovered Linux with the earliest TAMU release in late 1992. You can reach him by e-mail at preston.brown@yale.edu.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
| Dart: a New Web Programming Experience | May 07, 2013 |
- RSS Feeds
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Home, My Backup Data Center
- A Topic for Discussion - Open Source Feature-Richness?
- What's the tweeting protocol?
- Dart: a New Web Programming Experience
- Developer Poll
- Trying to Tame the Tablet
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.








1 hour 43 min ago
4 hours 16 min ago
5 hours 33 min ago
6 hours 8 min ago
6 hours 30 min ago
11 hours 19 min ago
12 hours 6 min ago
13 hours 40 min ago
15 hours 16 min ago
17 hours 14 min ago