[an error occurred while processing this directive] [an error occurred while processing this directive]


Using the X Window System

The X Window System forms the foundation for KDE, GNOME, and a variety of window managers that can be used in Linux and other UNIX systems. Red Hat has integrated window manager and desktop features so tightly together in Red Hat Linux that separating the components to, for example, pop in a different window manager or modify menus is difficult.

Despite the fact that so much is piled on X to form KDE and GNOME desktop environments, you can completely bypass those environments and choose your own look and feel. You can do this by starting X, your window manager of choice, and selected applications yourself.

The following sections describe how to use the X Window System directly to create your own sort of desktop environment.

Starting the GUI yourself

You can override the default behavior of the startx command (which usually launches KDE or GNOME, as you choose) by creating a $HOME/.xinitrc file and changing your system to boot to init level 3. The .xinitrc file can start up some client processes and run the window manager you choose. Here is an example of the contents of a $HOME/.xinitrc file:

xeyes &
xterm &
exec twm

NOTE: Before proceeding, make sure that your .xinitrc file is executable. To do this after the file is created, type the following: chmod 755 $HOME/.xinitrc. Also log in as root user and type init 3 so that the GUI login manager doesn't appear and force either KDE or GNOME on you. Change the initdefault line from 5 to 3 in the /etc/inittab file to make the change permanent.

In this example, the .xinitrc file tells startx to run the xeyes and xterm clients. Finally, the file starts up the twm window manager. After you exit your window manager, the X server is halted. You are then returned to your login shell. You can use applications or window managers other than those shown.

Understanding the X Window System

Regardless of which desktop environment or window manager you use, the common underlying software is the X Window System. Although you can quite happily use your desktop without ever directly accessing X, getting to know some of the features of X can help you to better understand how all GUI interfaces in Linux work.

You can change X resources that apply to your desktop in general, as well as specific X clients that you run. Most X clients use standard options to set background and foreground colors, window titles, and placement on-screen. This section describes how to set X resources that apply to the general desktop, as well as to X client programs.

The most common ways to set X resources are by using the following:

  • X Client Command-Line Options — Most X clients support standard command-line options (as well as some options specific to each client) that set resources. You can use the option -geometry, for example, to set the default size and position of most X client windows.
  • X Resource Files — System and user resource files can be loaded by the xrdb command at desktop startup time. After you start the X GUI, it loads resources from either the system-wide Xresources file or from your personal .Xresources file (if either exists). Default resources for many X clients are stored in files in the /usr/lib/X11/app-defaults directory. You can override any X client resources files in app-defaults by creating files of the same names in your home directory.

You can also run commands to change attributes related to general desktop, such as your keyboard mappings (xmodmap command). The following sections describe how to change X resources by using both X client command-line options and X resource files.

X client command-line options

If you run X client commands or put them in a configuration file to start automatically, you can add options that affect how the client looks and behaves. These options are part of the X toolkit, so they are available regardless of what window manager you are using. Table 1 describes options that can be used with many different X client commands.

Table 1 Command Options for Setting X Clients
Option Description
-bg color or -background color Set the background color of the window by replacing color with one you choose. See valid colors in the Colors section.
-fg color or -foreground color Set the window’s foreground color by replacing color with the color you choose. This color is used for text or graphics in the window.
-rv or -reverse Reverse the window’s background and foreground colors.
+rv Restore the window’s original background and foreground colors.
-bd color or -bordercolor color Set the color of the window border by replacing color with the color you choose. See the Colors section for a list of valid colors.
-bw pixels or -borderwidth pixels Set the window border width in terms of number of pixels.
-display display Set the client program to appear on a particular display. The display can be set as the display on the local system (:0.0) or to a display on a remote computer (host:0.0). See Chapter 5 for a more in-depth description of how to direct the output of an X client to a remote display.
-fn fontname or -font fontname Set the font used in the display text to fontname. See the Fonts section to find valid font names.
-geometry WidthxHeight+Xoff+Yoff Set the size and placement of the window on-screen. Width and Height are numbers indicating either pixels or characters. Xoff and Yoff set the offset of where on-screen the window begins. A plus sign (+) offsets the window from the left or top of the screen. A minus(-) sign offsets the window from the right or bottom of the screen. (See examples that follow.)
-iconic Start the application minimized (reduced to an icon). This is a nice option for running several clients at startup time so that they are immediately ready for use, but not cluttering up your screen.
-name “app name” Assign a name to the client (app name) that can be used to identify the application’s resources. This is useful if the client has been renamed or aliased but you still want it to use its resources. The app name that you assign appears on the icon representing the window if it is minimized and, possibly, in the window’s title bar. The name can be overridden in those locations by using the option -title.
-title “Window Name Set the title used in the window’s title bar and, possibly, the icon representing the window if it is minimized.
-xnllanguage lang[_terr][.codeset] Set the language, territory, and codeset used to resolve file names (such as resource files).
-xrm “resource:value” Set a resource to a particular value. This is useful for setting any X resource for the client that can’t be changed with a specific option. (Separate the resource and value with a colon and surround them with quotes to avoid special characters from being interpreted by the shell.)

In most cases, you can use several of these X options on the same command line. The following sections provide examples of X command options that are used with some common X clients.

NOTE: You can type these commands in a Terminal window in your GUI. The results should appear on your desktop. If the clients don’t appear, refer to Chapter 5 for information on running X applications.

Example one

The xeyes command opens a small window that contains a pair of eyes. Those eyes follow your mouse movements around the screen. Here is an example of the xeyes command with several options:

$ xeyes -fg red -center yellow &

This runs the xeyes command with the pupils (-fg) set to red and the whites of the eyes (-center) set to yellow. The -center option is specific to xeyes. The ampersand (&) runs the command in the background.

Example two

The xlogo command simply displays an X (representing the X Window System) on your display. Here is an example of the xlogo command with several options:

$ xlogo -geometry 300x300-0-0 -bg green -fg red &

This places an X logo in the lower right-hand corner of the screen (-0-0) at a size of 300 x 300 pixels. The background behind the X is green (-bg), whereas the X itself is red (-fg). If the location had been set to +0+0, the X would have been placed in the upper left-hand corner. The ampersand (&) runs the command in the background.

NOTE: For an xterm window, -geometry is interpreted in characters. So a geometry of 80x15 would result in the text area of the xterm window being 80 characters wide and 15 lines long.

Example three

The xterm command starts a Terminal window on your desktop. Here is an example of an xterm command with several options:

$ xterm -title “Login to Comp1” -e ssh comp1

This command opens an xterm window and tries to log in to a remote computer called comp1 (-e ssh comp1). The words Login to Comp1 appear in the xterm window’s title bar. To try this on your own computer, substitute comp1 with the name of a computer on your network.

This example represents a great way to start an application and identify the activity of that application in the title bar of the xterm window. (This is a particularly good technique if an xterm command is used to log in to another computer. The title reminds you that you are not working on your own computer within that window, because you’re logged in remotely.)

Example four

X resources can also be set on a command line. The following is an example of an -xrm option being used to set resources for an xterm window:

$ xterm -xrm “XTerm*cursorColor:Blue”

This command opens an xterm window with the color of the cursor set to blue. You can set any xterm resource using the -xrm option. Try a few others, such as -xrm XTerm*background:Red or -xrm XTerm*foreground:Yellow. You can have more than one resource set at a time, but each must be preceded with -xrm.

CAUTION: Be careful not to set background, foreground, and other adjacent items to the same color. If your text, cursor, or other items seem to have disappeared, they may just be set to the same color.

X resource files

Whenever you specify a resource for an X client, that resource follows a fairly simple form. It consists of class name, attribute, and a value. The class name is just the name of the application with the first letter capitalized. Some class names that begin with the letter x, however, capitalize the second letter as well (for example, the class name for xterm is XTerm). The attribute identifies the element in that application. The value is what that element is set to.

Here is an example of an X resource:

XTerm*background: Red

The object of this attribute is the xterm command. The attribute is the background. The value sets the background to red. X resources that are specific to a particular client are organized in a hierarchy, in what is called a widget class. To find this hierarchy for an X client, check its man page and look for a WIDGETS heading. (Not all man pages have this heading.)

TIP: To see the widget tree for an X client that is running, use the editres command. From editres, choose Commands -> Get Tree and then click the window of the client for which you want to see resources. To see an extensive list of resources, try clicking the editres window itself.

Because the hierarchy of resources can allow long names, you can use an asterisk in a resource name for what is called a loose binding. This means that any number of characters can be matched by the asterisk (as an asterisk is used as a wildcard in the shell). So, in the example, any resource that ends with the attribute background for the XTerm class is Red.

If you want to be more specific in how you match a resource name, use a period (.) to create a tight binding in a resource name. A tight binding enables you to be more specific about the resource you want. If you want all backgrounds in the xterm window to be Black and foregrounds to be White, for example, but you want the scrollbar background to be Red and the foreground to be Yellow, use the following resources:

XTerm*background: Black
XTerm*foreground: White
XTerm*scrollbar.background: Red
XTerm*scrollbar.foreground: Yellow

Most X apps accept these attributes: background, foreground, borderwidth, and bordercolor. Many also accept title (to change the name in the title bar), geometry (to set window size and location), and font (to change the font used in the window).

Remember that you can add resources in several ways: .Xdefaults, .Xresources, application-specific resource files in your home directory (such as XTerm), or by using the -xrmresource” option on an X client’s command line. Here are a few X resource examples to get a feel for:

xfontsel*MenuButton.background: Red
XClock*geometry: +0-0
XTerm*font: 9x15bold

In these examples, the first line shows buttons on the xfontsel window in red. The second line places the xclock utility in the lower-left corner of the screen. The third line sets the fonts used in an xterm window to be the 9x15bold font.

X colors

Whenever you define X resources, you have several ways to refer to colors. One way that is easy to understand is to use common names: red, blue, and so on. However, you can also use hexadecimal notation or specific numeric red, green, and blue values to refer to more subtle colors.

The table of colors that are supported by X are contained in /usr/lib/X11/rgb.txt file. Each entry in this file consists of three numbers and a name. The three numbers represent the intensity of red, green, and blue, respectively. A zero (0) represents no trace of the color, whereas 255 represents full intensity. Here are some examples of colors in this file:

250 235 215 AntiqueWhite
230 230 250 lavender
255 228 225 misty rose
255 255 255 white
0 0 0 black
47 79 79 DarkSlateGray
190 190 190 gray
0 0 128 navy
0 0 255 blue
135 206 235 sky blue
175 238 238 PaleTurquoise
0 255 255 cyan
0 255 0 green
255 255 0 yellow
165 42 42 brown
255 165 0 orange
255 0 0 red
255 0 255 magenta
160 32 240 purple

You can use any of these names as arguments to color resource options. (Remember to put multiword colors in quotes.) Another way to refer to a color is with hexadecimal notation. In this form, there are six integers, each representing a number from 0 to 16. The first two integers refer to red, the next two refer to blue, and the final two refer to green. So, in the first two integers, ff is 255 (all red) and 00 is zero (no red). The same is true for setting the amounts of blue and green used. Here are some common colors in hexadecimal notation:

black #000000
blue #0000ff
cyan #00ffff
green #00ff00
magenta #ff00ff
red #ff0000
white #ffffff
yellow #ffff00

Depending on where you enter colors in hexadecimal notation, you may need to put the numbers in quotes. To set the background color to green for an xterm window, for example, you would type xterm -bg “#00ff00” at the command line.

X fonts

To see the fonts that are available to X on your computer, use the xlsfonts command. The xlsfonts command just dumps a listing of fonts to your screen. So to view the contents, you should either pipe the output to the more command or direct the output to a file. Here are two ways to run the command:

$ xlsfonts | more
$ xlsfonts > /tmp/allfonts

Use the command xterm -fn “font” to try some of these fonts:

12x24romankana
-adobe-utopia-bold*
lucidasanstypewriter-bold-18

The X server maintains a list of font locations in what is called the font path. Whenever you display a list of fonts or choose particular fonts to assign as resources, the font path is checked to determine whether the font exists. Font path is similar to the shell PATH, which searches for commands by checking a list of directories, using the order in which they appear in the PATH. Similarly, X checks for a font by using the order set by font path. To see the current font path, type xset -q| grep -i font.

Changing X display resources

Resources associated with your X server display affect the behavior of the mouse and keyboard and can modify such things as the sounds and background of your desktop. There are several commands to change and view the resources that are set for your display:

  • xset — Sets and displays a variety of resources associated with your X display. It can control sounds from the desktop, set the font path, change mouse parameters, change the screen saver, and set background color of the desktop.
  • xmodmap — Modifies how the keys on your keyboard and pointer buttons are mapped. It can also display existing key map and pointer map tables.
  • xv — Although xv can be used to capture and display images in a variety of formats, it can also be used to show an image as a background for your display. (The xv command does not come with the Red Hat Linux distribution, though it is available from Red Hat FTP sites as shareware.)

Typically, you would try different values with these commands to find settings that look and behave the way that you want. Then you could add these commands, with options, to your .xinitrc or .xsession files so that they are in effect each time you start the desktop.

You can change several attributes of your mouse, cursor, and keyboard mappings. You can speed your mouse motion. You can change what each mouse button does. You can assign a different cursor to the mouse pointer. You can modify annoying sounds. You can set the background of your display. You can set the idle time of your screen saver.

Mouse speed

To change the speed that your mouse cursor travels in proportion to how far you move the mouse, change the acceleration value by using the xset command. To set the m option to xset, enter a number to represent acceleration. You can also add a number, following the first one that represents a threshold. The movement of the cursor is the first number (acceleration) times the movement of the mouse (the distance the mouse is moved) after it passes the set threshold of pixels. (The reason for waiting for the threshold to be reached is so that you can move the cursor in a refined way for short distances.) Here is an example:

$ xset m 5 10

This example sets the mouse to move five times as fast as it would normally move for the amount that you move the mouse. Acceleration begins after the mouse moves 10 pixels. If you try this option, you see that the mouse cursor starts out moving slowly for a short distance and then begins moving quickly.

Mouse buttons

If you are left-handed, you can use the xmodmap command to change the arrangement of the mouse buttons. To have the mouse button that you most often use to select items under your index finger, reverse the order of the three mouse buttons. First, use the following command to check the current arrangement of your mouse buttons:

$ xmodmap -pp
There are 5 pointer buttons defined.
Physical
Button
Button
Code
1
1
2
2
3
3
4
4
5
5

This output shows that the five mouse buttons are assigned in order. The code for the first button is assigned to button one and so on. To change the order (for a left-handed person), type the following:

$ xmodmap -e “pointer = 3 2 1 4 5”

TIP: If your mouse isn’t working, you may have a problem in your mouse configuration. Try running mouseconfig. Mouse information in your /etc/X11/XF86Config file may be wrong. If you are careful, you can manually edit mouse information in that file.

Mouse cursor

By default, the cursor representing the location of the mouse pointer whenever it is over the root window is an X. If you like, you can change the cursor to a different representation by using the xsetroot command. The full list of cursors is available in the X Windows include file (/usr/X11R6/include/X11/cursorfont.h). Here is an example of how you can change the mouse cursor to a different icon:

$ xsetroot -cursor_name draped_box

This example changes the X cursor to a box with a small mosaic pattern in it. You can also change the cursor to any of the following values:

hand1
hand2
iron_cross
left_ptr
plus
top_left_arrow
watch
Sounds

You can modify the annoying sounds that your computer makes by using the xset command. You can turn off the beep your computer makes if you make a mistake by typing the following:

$ xset b off

You can turn the beep back on as follows:

$ xset b on

You can change how loud your computer beeps by using a numeric value after the b option. The number represents a percentage of the maximum loudness (from 1 to 100). The following, for example, sets the bell to 90 percent of its maximum loudness:

$ xset b 90

X-application resources

Most X applications support some of, or all, the standard X options (geometry, foreground, background, and so on), as well as some options that are specific to the application. Many of them start with a set of default options defined. You can override these default options in several different ways.

You have separate resource files for each X application (that chooses to create one) in the /usr/lib/X11/app-defaults directory. Each file is named after the X client that it represents, with the exception that the first one or two characters are capitalized. Although I do not recommend it, you could edit these files and change the resources. That way, everyone who starts X on your system starts with the same set of resources set for the applications.

The preferred way to change resources for your X clients is to copy the resource file that you want to change to your home directory. Then make changes and additions to it. After you start the X client that is associated with that file, the resources are incorporated into the client. Even if no default resource file exists for an X client, you can create one. For example, I created a $HOME/XEyes file and added the following lines to it:

XEyes*title: My Eyes
XEyes*foreground: Red
XEyes*background: Yellow

After I ran the xeyes command, the title My Eyes appeared on the taskbar for the application. The eyeballs were colored yellow and the pupils were red.

Instead of using individual files, you can add X resources associated with any client into your .Xresources or .Xdefaults file. If you make a change to those files, you can immediately merge those changes into the current desktop as follows:

$ xrdb -merge $HOME/.Xresources

 



Cover

ISBN 0-7645-5745-9

Wiley Technology Publishing
Timely. Practical. Reliable.

[ Home ]

[ PLIP ]

[ Proxy firewall ]

[ News Server ]

[ "r" Commands ]

[ Majordomo ]

[ ipchains ]

[ Xawtv ]

[ sendmail.cf ]

[ wuFTPd ]

[ Crack ]

[ Tripwire ]

[ Chage ]

[ X ]

[ linuxconf ]