s i s t e m a o p e r a c i o n a l m a g n u x l i n u x | ~/ · documentação · suporte · sobre |
Next
Previous
Contents
8. The X ResourcesWe will at this point consider some finer modifications to your system. Configuring the window manager only gets you so far. The window manager lets you customize everything that happens outside the windows, the frames, the borders, the buttons, the desktop... but what about making the inside of the windows pretty? The only way to do this is by modifying the X Resources for your system. X Resources provide a mechanism for storing default values for program resources and tailoring your windowing environment to your favored look and feel. Resources are specified as text strings that are read in from various places when an application is run. Program components are named in a hierarchical fashion, with each object in the hierarchy identified by a class as well as an instance name. At the top level of the hierarchy is the class and instance name of the application itself. By convention, the class name of the application is the same as the program name, but with the first letter capitalized (e.g. Bitmap or Emacs) although some programs that begin with the letter ``X'' also capitalize the second letter for historical reasons (e.g. XTerm).
8.1 X Resources: The BasicsLet's try a few examples to ease you into the world of resources. Start by opening an xterm window. Most likely you have one open already, can open one with a menu selection, or may wish to backtrack a bit in this document to get your bearings! Type something like this into the xterm window:
This command should have resulted in another xterm window popping up on your screen, but this time with a blue background. ``Wow,'' you say, ``that's amazing!'' Yes, indeed it is. We'll need a little more background for our next example. Type exit in that xterm (which will close that window) and go back to the original window that you typed that command in. Try this: hold the Ctrl key and then hold the left mouse button. Now try that with the middle mouse button. Now the right. All xterm windows give you options to try while they are running. With the right button, for instance, you can change the font of the window. Notice the color of these menus. Now try this example:
This time, it just looks like a normal xterm window. But if you try holding Ctrl and the right mouse button in that window, you will see that this menu (the ``fontMenu'' mentioned in the above example) is green. What just happened? If you look at the man page for xterm, you will see many command-line options, such as -background or -font, that you can set when you launch any given window in X, listed after the options just for xterm windows. These particular options are called X Toolkit Options, and they apply to just about anything in X.
8.2 Inside The X Resource Database With editresTo really get inside the resources of X, we need to run editres. Go ahead and launch it (and a sample program to play with) now:
Probably you will see a simple clock, and the rather innocent looking,
mostly-blank window of editres. The main window is showing us
the resource tree of any given window on our desktop, and upon program
launch, there is none. So let's give it one. Hold down the left button
on
the Commands menu, and select Get Tree. In the top of the window will
appear For this example, let's first click on the xclock. You will see a couple things appear in the editres window. These are the configurable branches that the toolkit sees. Click on the bottom right one (clock). It should invert. Now select ``Show Resource Box'' from the ``Commands'' menu. You will see another window pop up, with the heading ".xclock.clock.unknown". Bingo! >From here you can toy with the configuration options of the main xclock window. First, click on ``Set Save File'' at the bottom, and put in a filename such as /home/yourname/resources, to indicate that you're testing some of the resources here. Now click on ``foreground'' and put in ``blue'' next to the ``Enter Resource Value:'' prompt. Then hit ``Apply'' at the bottom. The minute notches around the clock should turn blue. Go to ``background'' and enter ``navajowhite'' (or whatever color you prefer). Then apply that. As you can see, we can configure the whole window just fine this way. But if you were to try launching another xclock, it would appear just as this one appeared before any changes. We need to save these changes. Click ``Save'' and then ``Popdown Resource Box'' (a fancy name indeed for the ``Close'' function!). If you view the file you just created (cat /home/yourname/resources perhaps) you will see all those resources spelled out, in correct X Toolkit format, for your convenience. But that does us little good, for if you try launching another xclock, it will still look Plain Jane. So here is the last and final step in loading in your resources:
This command merges the resources we just wrote into the X
Resource Database (xrdb) for your session of X Window.
That
means that for all future invocations of the X applications we
modified,
our changes will take place, and remain binding. So if you run another
xclock, it will look as nice as you have just now set it up,
every time you run it. Mind you, xrdb is a complex program,
and
you may want to have a look at the man page before moving on, or
playing
around with it some more. If you added the modification to
8.3 The Anatomy of X ResourcesAs you can see we have stumbled across a plethora of configuration options here. This method of configuring X, as has been stated, offers nearly limitless possibilities, and an equivalent amount of confusion. To get some picture of the scope of the resources in just the X Toolkit Intrinsics alone, run the program viewres, and play around with it a bit. This program graphically displays the tree of resources in the Xt Library. If you read the manual page for X, you will find a rather obscure definition of the exact syntax for defining resources it understands. We can simplify this quite a bit and break it down into this essential syntax definition: <program><binding><widget><binding><widget><...><resource>:<value> That doesn't really seem that simple, actually. Well, let's define some things about what has just been said, and it will all start to make sense after all. You can peek ahead to the examples in the next section as you read along, if you wish. The program in this definition is the invocation of an
application in the resource database. This would be The binding can be one of two characters to separate the
widgets and such. If you use a The widget entries are items in the widget tree, in order of
most-specific to least-specific, that they appear in the widget tree,
visible with editres. Any single widget entry can also be
replaced with a The resource item must be specified, and cannot be replaced
with
the Following the colon is the value entry. This entry defines what the resource will be set to, such as a font name or color value. The value can be specified (depending on context) as a boolean, numeric, or text data type. The value entry, also, cannot be omitted in a valid resource definition.
8.4 Making Your Changes Last With .XdefaultsThere is a magic file you can put in your home directory called .Xdefaults. If you copy the lines in the resources file from the last example into the .Xdefaults in your home directory, you will never have to configure xclock again! While this might not be the finest example of its utility, it makes its point. This file can be crammed full of every option you prefer for every type of program you run in X, and if you take proper care of it, you can still easily go back and make slight changes when you need to. But making lots of changes, and hunting down lots of subtle resources using editres can be an extremely tiring and painstaking procedure. Indeed, sometimes that's too much work, and most of these resources are already waiting for you, neat and orderly, grouped by program, on your system. In the directory /var/X11R6/lib/app-defaults you will find a great many files, all named after an X Toolkit program. If you examine these files you will find that they contain a great many configuration options for each one, and I do mean a great many! You would not want all of these options from all of these files in your .Xdefaults file, that would be quite tiresome to deal with. These are the defaults, and it is from these that you can decide what you would like to see changed for your particular configuration. The following are some samples from my .Xdefaults file. Notice
a
few things we have not yet mentioned about the resource definition
files. If a line begins with
One word of warning with regard to X resources, for KDE users. There's a setting in the control panel which will cause all your X Resources to be overwritten in your applications. This can be a really nice feature, but it can also be an annoyance if you have painstakingly configured your resources. Open the control panel and find the ``Fonts etc.'' section. There's an option to ``Apply style to non-KDE apps''. If you turn this on, all your programs will adopt the look and feel configured by KDE (you may need to restart X to notice this). If you leave this option turned off, your resources will remain as you have configured them.
8.5 Your Own User Resource DirectoryYou can also create a directory of resource files, just like the
system-wide app-defaults directory mentioned above, with one
file
per program. Just create the directory (for our example we'll use
app-defaults under your home directory,) and then set the environment
variable Now, whenever you start an X program, this directory will be searched
for
a file with the same name as the resource name of the program, just
like
the system-wide directory. This is the client name that you
used in For example, a file called XTerm could contain the line
Next Previous Contents |