v3.1 10 October 2002
The X Window System is an advanced, graphical computing and network environment that was designed from the ground up as a multi-user system. X was first released in 1984. If you are not familiar with the basic concepts surrounding X and it's related components, you should first read the X Window System Architecture Overview HOWTO, http://linuxdoc.org/HOWTO/XWindow-Overview-HOWTO/index.html, to get an idea of how the various pieces fit together. There is also an attempt to define to various X related terminology in the Appendix, if concepts such as "displays" and "X clients" in this context are confusing to you.
This document will address basic X Window configuration and usage on Linux. We will also look at how X is commonly started in Linux, and how the start up can be configured, and related issues. We will not examine Window Manager (e.g. fvwm), or Desktop Environment (KDE and GNOME) configuration. There are just too many variables there, and the pace of change moves too quickly. Of course, to a large extent the user interacts more directly with these components than the X server itself, so additional reading would be worthwhile. Check your locally installed documentation, and the respective home pages for more information.
Some other important points to remember here:
The discussion here will be limited to X as implemented by The XFree86 Project, Inc. on Linux. There are other implementations, including commercial ones. XFree86 v4.x has been out for some time now, so we will be assuming that version. Much of the discussion applies to the previous 3.x version as well, but there are some occasional differences.
It is also worth noting that there are conceivably many ways to start X, and to set up a Linux system. We will focus on the common methods found in Linux distributions. Also, vendors may vary on where they put configuration files, and how they name them. Keep this in mind if you see such discrepancies in this document. If this is a problem, your vendor surely has their own documentation. And as always, hopefully the man pages will conform to your installation.
Also, we will look at various configuration files in the following sections. These are all plain text files, and can be edited with your favorite editor. Always make a backup copy before editing important files, in case Murphy pays a visit (e.g. "cp /etc/X11/XF86Config-4 /etc/X11/XF86Config-4.bak").
The current official version of this HOWTO may be found at the Linux Documentation Project, http://www.linuxdoc.org/HOWTO/XWindow-User-HOWTO.html. Pre-release versions may be periodically posted to http://feenix.burgiss.net/ldp/x-user/.
v3.1: This is just some small, minor updates. Include link to http://www.plig.org/xwinman/ as a good resource for shopping Window Managers. Add link for fluxbox, a Window Manager with Tabbed windows. And add a brief section on improving network performance. Verify links all work.
v3.0: This is a major rewrite with several new sections. Some sections were removed, with the focus more now on just X itself (and not clients like Window Managers). New maintainer too :-)
v2.0: includes corrections from Guus Bosch, Brian J. Miller, and myself, as well as lots of new updates and info.
v1.4: include corrections and additions from Anthony J., and some very good security tips from Tomasz Motylewski.
A rudimentary troubleshooting section. Probably for v3.2.
If you have questions or comments about this document, please feel free to email me, Hal Burgiss at <email@example.com>. I welcome any suggestions, corrections, or additions. If you have information you would like to see in future revisions, or you would like to contribute to a future revision, please drop me a note.
I have assumed maintainership of this document because it was abandoned, and I had wanted to offer a suggested change. Well, to make a long story short, this led to a major re-write. You can help make this a better document by correcting inaccuracies, clarifying the unclear, and suggesting improvements. There is much about this topic I may not know, or not have explained well. Your help will improve this document and help other users. This document needs your help!
Thanks to the XFree86 development team for their efforts in providing a robust and flexible GUI. And to the whole GNU/Linux and Open Source community for making it all possible.
Also, the original author, Ray Brigleb.
Various users on comp.os.linux.x that have helped in one way or another, whether they know it or not.
Lastly, http://google.com/linux, who saved me much time with their incredible repository of information. Use it to answer questions not answered here!
Copyright © 2002, Hal Burgiss.
Unless otherwise stated, Linux HOWTO documents are copyrighted by their respective authors. Linux HOWTO documents may be reproduced and distributed in whole or in part, in any medium physical or electronic, as long as this copyright notice is retained on all copies. Commercial redistribution is allowed and encouraged; however, the author would like to be notified of any such distributions.
All translations, derivative works, or aggregate works incorporating any Linux HOWTO documents must be covered under this copyright notice. That is, you may not produce a derivative work from a HOWTO and impose additional restrictions on its distribution. Exceptions to these rules may be granted under certain conditions; please contact the Linux HOWTO coordinator for more information.
In short, we wish to promote dissemination of this information through as many channels as possible. However, we do wish to retain copyright on the HOWTO documents, and would very much like to be notified of any plans to redistribute the HOWTOs, this one in particular!
Some of the terms mentioned in this document are trade names. Unless otherwise stated, all trademarks are property of their respective owners.
"X Window System" is a trademark of the X Consortium, Inc [now the OpenGroup?].
"XFree86" is a trademark of The XFree86 Project, Inc.
"Linux" is a Registered Trademark of Linus Torvalds.
The information and examples given here are for illustrative purposes. Use at your own risk. Every attempt has been made to insure that the content of this document was accurate when written. If you find inaccuracies, please send me clarifications.
References to any particular company, product or brand name should not be construed as an endorsement.
Virtually every Linux distribution comes with XFree86's X Window System implementation. This project, of course, provides us the X server, but also includes an extensive suite of utilities and applications to help implement a fully functional GUI environment.
In fact, the list would be just too long to list everything that comes with XFree86. In addition to the X server itself, here are a few of the noteworthy utilities:
There are many more. We'll just touch on a few of these utilities here. But feel free to explore the others. Most should have their own man pages.
The X server controls both input (keyboard, mouse, etc) and output (display, monitor) devices.
Compatible hardware is a tough topic, since it is very much a moving target. We are forced here to avoid specifics, since this would surely change by the time you read this. And would be tediously lengthy anyway.
So let's settle for some generalities. Most PC type hardware is supported to one degree or another. Big help ;-)
Rule of thumb: if it is a device that uses a long-standing, commonplace protocol (e.g. PS/2), it should be well supported. Conversely, if it is something relatively new, with ground-breaking technology, the odds are not as good. This is just the nature of the beast with open source development versus manufacturers that cater more to the most popular platforms. Some manufacturers are more co-operative than others too.
Now, some general guidelines:
You can check the "hardware compatibility list" at your distribution's web site too. This should give a very good idea of what should work with your release.
Newer versions of XFree86 obviously will have better hardware support. If you are using an older Linux version and don't have full hardware support, see about upgrading XFree86. Check first to see if your distribution has updates for your release.
The primary configuration file for XFree86 is XF86Config, which may exist on your system as XF86Config-4 for XFree86 v4.x, or possibly other variations (see man page). It is typically located as /etc/X11/XF86Config, though again, there may be variations in the path. If both a XF86Config-4 and XF86Config exist, XFree86 v4.x will use the former. This is a required file.
XF86Config file defines hardware devices, and other critical components of the X server environment.
While this is a plain text file, and is editable, it is most often created during installation by whatever utility your vendor uses for this purpose. XFree86 also includes the xf86config utility for this, but many distributions have their own such utilities. These utilities can be run after installation if need be, to alter the configuration, or if new hardware is installed. Read your locally installed documentation first. If you attempt to hand edit this file, be sure to make a backup copy first since X won't start if this file is not to its liking ;-)
This file contains various "sections". Each section defines some fundamental aspect of XFree86, such as "InputDevice" (mouse, keyboard, joystick, etc), "monitor", or "screen". The XF86Config man page describes the sections and common values for each. Note that the values listed in the man page is not a comprehensive listing. There are many device specific "options". Check http://xfree86.org for notes and tips on your hardware.
The author's current XF86Config-4, as generated by Red Hat's installer for XFree86 4.1:
Yours may look quite different. This is just one possible configuration with gratuitous comments from Red Hat (and me), and is for a fairly ordinary set up. There is nothing exotic here like multiple screens or displays.
It is beyond the scope of this document to explain this in detail. See the XF86Config man page. Also, consider visiting xfree86.org and look for specific options that might apply to your card or other hardware.
Just one quick note on the "Screen" section above. Notice there are three sub-sections, identified as "Display". Each sub-section has a different "Depth" specified, (a.k.a. ColorDepth). The "Modes" also vary somewhat according to the respective "Depth" setting. The active "Display" sub-section that will be used, is determined by the "DefaultDepth" setting (unless over-ridden by command line options). The default in this example is defined as "24", so the first sub-section will be used. Also, the highest "Mode" listed in this sub-section will be the default mode (resolution), which here is the first one listed. The first listed mode also determines the viewable screen area, which can be smaller than the mode (resolution) itself. In which case, you would have a virtual desktop that is larger than the viewable screen. To have the viewable screen, and resolution match, have the largest value as the first value listed for each "Mode".
Another note on the "Modes" here: what you see is the result of my choices during Red Hat's Xconfigurator's configuration. These are standard resolutions, but do not have to be! This is only limited by what your hardware can support. And you don't have to use standard width x height ratios either. Something like 1355x1112 is a valid setting (if your hardware supports it and it floats your boat!).
The X server will reject any "Modes" it thinks are invalid. You can cycle through valid modes to change screen resolution with Ctrl-Alt-+ and Ctrl-Alt-- (that's the keypad plus and minus keys).
In versions prior to v4.x, you would also see many "Modeline" statements that attempted to define the monitor's capabilities. These statements would look something like:
Explicit "Modeline" definitions are not required as of 4.x ;-) This sometimes required hand editing to get optimal values in earlier versions of XFree86, though is generally not necessary with v4.x. The XFree86 Video Timings HOWTO, http://www.linuxdoc.org/HOWTO/XFree86-Video-Timings-HOWTO/index.html has a nice, but rather technical, explanation of this.
If whatever configuration utility you are using, does not automatically recognize your video card or monitor specifications correctly, you are unlikely to get an optimal configuration. In such cases, you may have to manually supply the correct values. This should be available from your owner's manual (you kept that, right?). Or, check the manufacturer's web site.
Again, hand editing of this file is generally unnecessary. Should you decide this is indeed necessary, be careful. One small error may cause X to fail. Any changes to this file will require restarting X for the changes to take effect.
Using somebody else's XF86Config file, is generally a bad idea since they are unlikely to have identical hardware.
You probably want to get the most out of your hardware. If X isn't configured optimally, consider re-running your vendor's X configuration utility and try to get better results. It is highly unlikely that you could hurt anything by experimenting. Most modern monitors now have safeguards that prevent a meltdown ;-)
If you over-do it though X may not be able to start. For this reason, I prefer to use the "startx" way of starting X (see below) while "experimenting". This way if X crashes, the display manager (GUI login) will not loop and cause you severe headaches. startx just gracefully goes back to a text console screen, where an error message may be visible.
Another way of tweaking monitor related settings is with XFree86's xvidtune program. This is run interactively and can be used to adjust various settings (see man page). The simple dialog box has sliders and buttons that allow user input and adjustment. The top part has horizontal monitor settings on the left, and vertical settings on the right. The buttons just below the sliders can be used to adjust each.
This is sometimes used to adjust the viewable screen area, such as to center it, or increase its size to fill the monitor's viewport. When xvidtune is launched, it defaults to the current settings.
The bottom left corner has buttons that can "Apply" new settings, "Test" new settings, or "Show" current settings (i.e. dump to screen), among other things. Any changes made here are not saved. If new settings are "Applied", it is just for the current session. Example output of xvidtune "Show":
The last line is the "Modeline" being used to drive the current screen. See The XFree86 Video Timings HOWTO, http://www.linuxdoc.org/HOWTO/XFree86-Video-Timings-HOWTO/index.html, for more on "Modelines".
You can test modifications, and apply them to the current session. For changes to be made permanent, they will have to be added manually to the "Monitor" section of XF86Config (or XF86Config-4 for v.4.x) with a text editor.
xvidtune will dutifully warn of you of the hazards of playing with the monitor settings. It is unlikely you can hurt anything with modern monitors. But it is best used to make minor adjustments. Use at your own risk!
Starting an X session is typically done in one of two ways: the X session is started via a display manager (like xdm), and the user logs in at a GUI screen. Or, the user starts X manually after logging in to a text console. The latter is typically done with the startx command, which is a simple shell script wrapper for xinit. X runs with root privileges in either case, since it needs raw access to hardware devices.
Typically, which method is used, is determined by the system "runlevel". The default runlevel to launch at boot is generally set in /etc/inittab on Linux:
That would start xdm, and thus X, at runlevel 5. It will "respawn", if it dies or is stopped for any reason. You can also use the "init" command to change runlevels without rebooting (see man page).
Let's look briefly at both approaches, and then some additional configuration to set up the user's working environment.
startx will start X by first invoking xinit. By itself, this would put you at a blank, fuzzy looking, bare-bones desktop with no Window Manager loaded. xinit basically takes two sets of command line arguments: client specifications (programs to run, etc), and server specifications (X server options), separated by "--". If no client program is specified on the command line, xinit will look for a .xinitrc file in the user's home directory, to run as a shell script. If found, this then would in turn run whatever user specified commands to set up the environment, or launch programs that the file contained. If this file does not exist, xinit will use the following initial command:
If no .xserverrc is found in the user's home directory, X itself will be started with the following command:
As you see, this is not overly helpful as it just launches one xterm. The startx shell wrapper provides additional functionality and flexibility to xinit. startx will invoke xinit for us, and provide some simple configuration options as well. You can also issue commands such as the following, for instance:
Anything after the double dashes are passed as arguments directly to the X server via xinit. In this example, you can force X to the resolution of your preference, and still have it use the configuration files we will cover later in this document. See the Xserver man page for more command line options.
Instead of issuing the same command line every time, it is easier to use the configuration files to store this type of information for us.
If you take a look at the startx script (/usr/X11R6/bin/startx on my system), you see it uses two default configuration files to help set up the X environment: xinitrc and xserverrc. It looks first in /etc/X11/xinit/, for the system wide files. It then checks the user's home directory for similar files, which will take precedence if found. Note that the latter are Unix style "dot" files (e.g. ~/.xinitrc), and are executable shell scripts.
You normally would not want to edit the system wide files, but you can freely copy these to your home directory as a starting point, or just start from scratch. As you can tell by the names, one helps set up the X server, and one sets up xinit by executing commands, preparing the environment and possibly starting client programs like xterm or a Window Manager (yes, it's a client too).
As with all XFree86 configuration files, this is a plain text file, and is usually a simple, one line statement to start the X server. It can include any valid command line options supported by your X installation. If you always start X with your own options, this should be easier than typing the options each time. One possible ~/.xserverrc:
This will start X on display :0, the first "display", at a dots-per-inch resolution of 100, and disables TCP connections. See the Xserver man page for other valid options. This is just an example.
xinitrc is used to set up a suitable X environment, and to launch other programs, a.k.a "clients" that we may want available as soon as X is started. You likely have a system wide xinitrc to start a predefined set off programs. To customize this, create your own in your home directory. Name it .xinitrc, make sure it is an executable script, and chmod +x. An example (slightly modified from the original on my system):
Briefly, what this script does, is set up our working environment, with xmodmap (keyboard) and xrdb (application resource settings). More on these below. Then the shell variable $BROWSER is set for a GUI environment (Netscape in this example) so that any applications that might expect this, have a reasonable choice available. Then the presence of the file Xclients is checked, both as a system wide file and in the user's home directory. In this particular example, this is where any client applications are to be started, including a Window Manager (see below). These could just have as easily been started here if we had wanted to. If an Xclients file can't be found, then a Window Manager is started for us. Either fvwm, if available, or XFree86's minimalist twm if not. If for some reason, neither of these can be started, the script would exit, and X would fail to start.
Everything up to this point has followed pretty much a standard and predictable sequence of events. To summarize, we have invoked startx, which in turn invoked xinit, which has parsed xinitrc for initial settings. Most Linuxes should follow this same sequence, though the various values and settings may differ.
We now are at the last link in the chain where the user normally would specify his or her preferences, including the Window Manager and/or desktop environment to be used. The system will provide sane, though possibly uninteresting, defaults if the user has not done so. Presumably, this is why you are here ;-)
The Window Manager, or desktop environment, is typically the last application started. If you want other programs (like xterm) started, they should be started before the Window Manager and "backgrounded" with an "&". This can all be done in the user's ~/.xinitrc. Or as in the above example, the actual applications are started from yet another script. Let's look at one short, hypothetical such script, .Xclients:
This really isn't so different than what xinitrc was doing at all. We added a few wrinkles, including starting a screen saver, a different terminal emulator that this user prefers (rxvt), with even more setting up of the environment (monitor, mouse and keyboard) using xset this time, and a different Window Manager than was available with the system defaults. This is in the user's home directory, so it won't be overwritten during upgrades too.
Actually, X has already started at this point, and we are just putting the finishing touches on the configuration. Notice the Window Managers are not "backgrounded" with "&" here. This is important! Something has to run in the foreground, or X will exit. We didn't start a desktop environment in this example, like KDE or GNOME, but if we did, this final application would have to be gnome-session or startkde instead. Since we are rolling our own here, if we wanted to change Window Managers, all we have to do is edit this file, and restart X. Vendor supplied configurations may be more complex than this, but the same principles apply.
As an afterword, do not think that any initial client applications must be started as we've done here. This is how it has been traditionally done, and some may prefer this approach. Most window managers have their own built-in ways to start initial programs, as do KDE and GNOME. See the respective documentation.
The other, more common, approach is the "GUI log-in", where X is running before log-in. This is done with the help of a "display manager", of which there are various implementations. XFree86 includes xdm (X Display Manager) for this purpose, though your distribution may use one of the others such as gdm (GNOME) or kdm (KDE).
Display managers really do much more than enable GUI style log-ins. They are also used to manage local as well as remote "displays" on a network. We won't get into details on this here, but it is nicely covered in the Remote X Apps Mini HOWTO and the XDMCP HOWTO (see the links section). For our purposes here, they provide similar services to getty and login, which allow users to log into a system and start their default shell, but in a GUI environment.
Here is an example of a more advanced usage of what else a display manager might be used for, from Diego Zamboni:
Note the use of "Identifiers" here. Diego is starting two separate "displays" here. Then he can choose which one he wants when he logs in.
Most display managers are derived from XFree86's venerable xdm, and add their own enhancements. Let's look at the most popular ones briefly.
xdm can be configured with configuration files located in /etc/X11/xdm/, /usr/X11R6/lib/X11/xdm, or similar locations depending on your system. These are system wide files. The file xdm-config is the main configuration file, and mostly describes where to find secondary configuration files:
The "!" denotes comments. The command that starts the X server is in /etc/X11/xdm/Xservers in this particular example as defined by "DisplayManager.servers", and is the equivalent to xserverrc that was used for startx X server start up commands, but the syntax is slightly different here. The contents of /etc/X11/xdm/Xservers on my system are simply:
This starts X on the first local display (designated by 0). Any special command line arguments that you want to add go here at the end.
Below is a sample /etc/X11/xdm/Xsetup_0 which is used to configure the log-in screen only. Notice that we're using a shell script here, and it's calling xv (a graphics display program) to set the background to a nice image (instead of the boring black and white background pattern), and if that fails, xsetroot is then invoked to at least try to set the background to a nicer blue color. This does not configure the login widget itself -- just other things that might be wanted on the screen during login.
/etc/X11/xdm/Xresources controls the X "resources" used during log in. In this context, "resources" are user preferences for such items as fonts and colors (described in more detail below). Below is a snippet that sets up fonts for the log-in widget:
As you can see this is using helvetica as the preferred font, with different point sizes and dots per inch depending on the screen size. This is customizable to suit individual needs. (See below for more on understanding X font naming conventions.) Various other aspects can similarly be configured.
/etc/X11/xdm/Xsession is the rough equivalent to xinitrc for startx. It will similarly set up a default environment for keyboard, etc. And can also start either KDE or GNOME, and other X client programs. This is the system wide configuration file. It should also check the user's home directory for ~/.xsession, and possibly ~/.Xclients, which would contain the user's preferred environment and start up programs, just as ~/.xinitrc did with startx. Again, the files in a user's home directory may be created or modified by the user any time and must be executable shell scripts.
We won't include an ~/.xsession example here, since it would be very similar to the ~/.xinitrc and ~/.Xclients examples above.
We've looked only briefly at the main xdm configuration files. Be sure to read the man page, and look at what is installed locally, for more information. Let's look now at gdm and kdm. We'll just highlight significant differences, since they essentially provide the same functionality.
gdm is the default display manager for GNOME. gdm was written from scratch, but functions similarly to xdm. The main configuration file is gdm.conf, typically located as /etc/X11/gdm/gdm.conf. This is quite different looking than xdm-config. Comments are denoted with a "#", and the file has sections, with section headers enclosed in square brackets. The command to start X is in the "[servers]" section:
Notice this has potentially two displays set up, but the second one is commented out. Add any additional X startup options here, e.g. "-dpi 100". The log-in screen and log-in widget are configured in the "[greeter]" section.
Start up clients and programs are determined by the "SessionDir" statement in the "[daemon]" section. On my installation, this points to /etc/X11/gdm/Sessions/, which contains several short scripts. If I look at my Default script, it actually executes /etc/X11/xdm/Xsession, which in turn would execute ~/.xsession, if present. So at this final stage, gdm acts very much like xdm.
GNOME includes the gdmconfig utility to control many aspects of gdm behavior.
kdm is the display manager from KDE. The main configuration file for kdm is kdmrc and is typically installed as /etc/kde/kdm/kdmrc. As is the case with gdm.conf, kdmrc uses "#" for comments, and has sections with section headers in similar square brackets. kdm configuration can also be edited with the kcontrol utility.
The visible desktop is configured in the "[Desktop*]" section(s), and by the "Setup" directive which should point to a file like /usr/share/config/kdm/Xsetup or /etc/X11/xdm/Xsetup_0. This will accomplish the same thing as xdm's Xsetup_0 does: namely running any programs the user might want such as xconsole.
The command to launch the X server is the "Xservers" directive in the "[General]". Again, this should point to a file such as /etc/X11/xdm/Xservers, and uses the same syntax as xdm:
Any command line options for the X server, go here.
The login widget itself is configured in the "[X-*-Greeter]" section(s). Compiled in defaults are used if the user does not specify any.
KDE includes the kdmdesktop utility to control some aspects of kdm behavior, mostly just the login background.
Before taking a look at various configuration mechanisms for X servers and clients, it should be noted that the advent of Desktop Environments like KDE have become popular in part because they can control much of the user interaction configuration themselves with nice, "user friendly" GUI controls. And in fact, the compliant applications that are part of the respective Desktops will be best configured through the Desktop's configuration tools, or the application's own GUI configuration methods. So, for instance, gtop, a GNOME client application, is best configured via GNOME or gtop's own menus. But this is not true of all X applications.
The X server can store various configuration values for client programs so they are readily available when needed. If the application supports this, it will use these as defaults whenever that program is invoked. These are known as "Resources", and are often used to define user preferences on a per application basis for fonts, colors, screen placement (geometry) and various other attributes. This makes it easy to customize applications.
Resources are specified as text strings (e.g. Netscape*blinkingEnabled: False) that can be read from disk in various places when X is starting, or even interactively defined on the command line. 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. Typically, the class name of the application is the same as the program name, but with the first letter capitalized (e.g. Vim or Emacs) although some programs that begin with the letter "X" also capitalize the second letter for historical reasons (e.g. XTerm). Each definition will specify a class (or instance), with corresponding resource and value. Below this in the hierarchy are the various attributes that make up the definable aspects of the application.
Traditionally, most X programs were configured this way. This is not as true today with the advent of Desktop Environments which often have their own configuration mechanisms.
As an example, say we prefer to run xterm with a blue background. So if we run it from the command line, we would run it as:
If this is our preference, it would be easier to put this preference in a file somewhere, and have the system use our preference. That way whenever we started xterm, it would use our preferred value, and we wouldn't need the command line options (unless as an override).
The basic X resource syntax is expressed like:
Which, in real life, typically looks something like:
It should be obvious what this does. The use of "*" in the definition, is called a "loose binding" and acts as a wild-card. Meaning there may be gaps in the widget hierarchy. For instance:
This would also give a dark blue background for the xterm fontMenu, but also any other xterm properties that also have a "background" attribute (e.g. window background, etc), no matter where they may be in the widget hierarchy. Similarly:
This would define the background for any and all programs that support it -- not just xterm. Using a "." in place of a "*" would be more precise, and will not allow for wild-card gaps in the hierarchy. Also, the application must support the particular widget attribute. "Background" is a fairly safe bet, but many applications will have more specialized resources that are not so obvious. It is best to check local documentation (man pages, etc), or see if an application has an included examples. For instance, Netscape generally comes with an Netscape.ad file that has an extensive set of resource definitions that can be customized.
X resources are typically stored in more than one place (see below) and are processed by the xrdb command (see man page).
One way of storing preferred application resources is via files named for the application in an "app-defaults" directory. For instance, on my system, these are in /usr/X11R6/lib/X11/app-defaults/, though this may vary according to options your vendor has chosen. This directory contains a number of files for such well known X applications as xterm, xclock, xcalc, xload, and so on. All in all, it is a relatively small number of applications in the overall scheme of things. So not all applications use this scheme. In fact, most do not.
Each file will contain resource definitions for that application. The X server loads these by itself during start up. A brief example from XTerm-color:
This is mostly various color definitions. The application classname is not explicitly stated, and is assumed from the filename. So think of each line as starting: XTerm-color*. Also, notice at the top, the #include "XTerm" line, which "includes" the resource definitions for XTerm, a much longer file with a more diverse set of definitions. (Not included due to length, but worth looking at.) These files provide system wide defaults, and generally speaking, would not normally be edited by the user.
Another common method of reading in resource preferences, is with an Xdefaults file. Or, sometimes the naming scheme may be Xresources instead. This may exist as a system wide file, such as /etc/X11/Xresources. Of course, the user is free to create a personal version in his home directory, e.g. ~/.Xdefaults. The user's version will over-ride any system wide settings, and will remain after system upgrades. Obviously, this is the place to put your own preferences.
Xresources files are read into the resource database with the xrdb command. Example:
This can be done interactively at the command line, or placed in a script and run automatically as the X session is started. In the case of system wide files, this should be taken care of by the vendor supplied start up scripts. Generally, such scripts will also check the user's home directory as well (see the xinitrc example above). So probably all that need be done, is to create the file with a text editor.
Here's an example to illustrate a very few of the many things that might be done with an .Xdefaults file:
Hopefully, these few examples will give you some ideas to build on. X does not need to be restarted if xrdb is used interactively from the command line after making changes. The effects are immediate.
Resources are sometimes available also as command line options. See below. Command line options will over-ride any existing resource definitions.
The keyboard and mouse, as well as other possible input devices, are defined in XF86Config (or XF86Config-4). There is a keyboard layout that is defined based on the preferred language:
This gives us our default keyboard layout. Valid layout labels are listed in /usr/X11R6/lib/X11/xkb/symbols. Also, the setxkbmap utility can be used to change this interactively.
X is highly customizable, and we can modify the keyboard and mouse pointer mappings to suit our own preferences. The utility to do this is xmodmap (see man page). You don't like where the capslock key is? So move it ;-)
Like xrdb, xmodmap can be run from the command line. Or, preferred settings can be stored in a file. Typically this is ~/.Xmodmap, or similar. If your X start up files don't parse this, then edit as appropriate so that they do (probably from ~/.xinitrc or ~/.xsession).
You can view your current key and mouse mappings with: xmodmap -pk -pp |less. This will print out all active "keycode" values, with corresponding "keysym" values, and any keysym names that xmodmap knows about (e.g. "BackSpace"). And should also give you an idea of how xmodmap understands key and mouse events. There are two keysyms per keycode. The second is the shifted value. XFree86's xev utility can be used to dump a lot of information on key-presses and mouse events interactively. Pay attention to the "keycode" value. That is what you will need to know in order to re-map.
xmodmap is often used to make minor keyboard adjustments, like proper Backspace/Delete mapping. Or can be used make major adjustments such as for international mappings. You can only re-map keys and mouse events -- you cannot assign macros to key events (your Window Manager or Desktop might have some of this functionality).
Setting up international keyboards in nicely discussed in http://www.linuxdoc.org/HOWTO/mini/Intkeyb/index.html. Also, a search of http://google.com/linux will turn up many creative examples.
The man page has many brief examples of various usages. Here is what an one hypothetical ~/.Xmodmap might look like:
As with many XFree86 files, the "!" represents a comment. Another possible use, is to redefine those annoying "Windows" keys to something useful. Hopefully this gives an idea of some things one might want to do to make the keyboard more agreeable to us.
Speaking of the Numlock key, X will typically disable this when it starts up. No matter how you have the BIOS set up, or Linux set up before X starts. So the trick above is one way. There is also a utility available as either numlockx, or setnumlock, that can be found on the 'Net, if your distribution does not include one or the other. This can be put in a start up file to turn Numlock on automatically if you'd prefer.
Window Managers and Desktop Environments will also allow customization of the keyboard and mouse (as long as it is recognized correctly by X). This may be an easier way to configure certain customizations.
There are several special key mappings traditionally used in XFree86.
It's possible your Window Manager, Desktop Environment or other system component may trap these, and alter the standard behavior. In addition, the Ctrl-Alt-Delete may be trapped as well. This should shut X (and the system) down orderly, if it is available.
As mentioned, Linux and Unix make heavy use of three mouse buttons. If a mouse only has two buttons, then the third (i.e. the middle) button can be simulated by pressing both buttons simultaneously. This is a configuration option set in XF86Config as the "Emulate3Buttons" directive:
When all is said and done, a third button is quite handy and I would personally recommend having one. On wheeled mice, the "wheel" acts as the third button, if pressed. Many standard wheel mice seem to work with the "IMPS/2" protocol option.
Specifically, the third button (middle) is the "paste" button in virtually all Linux applications. Copy and paste works a little different in Linux. The left button is the copy button. Just hold it down, and drag over text. It is automatically copied to the X "clipboard". Then, the middle button will paste from there. A very simple process. A double-click should copy individual words, and a triple-click individual lines of text. If for some reason, this does not work, it is either a poorly implemented application, or a bug of some kind. Some older versions of Netscape were not consistent about this, for instance. To paste from the keyboard, this should be shift+insert.
"Drag and Drop" is not natively supported by X itself. But, is implemented by some toolkits and Desktop Environments. One should not expect this to work with non-compliant applications (i.e non-KDE aware applications in KDE for example).
xset is yet another XFree86 utility to set user preferences. xset is a bit of a catch-all and is used to change various, unrelated X server settings. Mostly this is a command line way of configuring some of the same things that are defined in XF86Config (but not everything!).
Common usages of xset are to set DPMS on or off and preferred intervals, to dynamically change the FontPath or re-read it, to control keyboard LEDs, to adjust mouse (or other pointer) movement speed, set keyboard "autorepeat" and "repeat" rates, and to control X's built in screen blanking. See the man page, of course, for detailed explanations, and other xset usages.
Again, xset can be used interactively from the command line. But most often preferred settings are stored in one of the start up configuration files, like .xinitrc or .xsession. A very brief example:
Your desktop may have a GUI front-end for xset.
Understanding fonts and colors can be more complex in X than on other platforms.
X knows about various font types, including bitmaps, Type 1, and as of v4.x, TrueType. The X server can either handle fonts itself, or sometimes this duty is forked to a font server (of which there are several). xfs (X Font Server) is the most common font server in use on Linux.
A font server is not required, as X can handle most font rendering itself. Font servers are traditionally used for serving fonts to multiple hosts on a network, but sometimes are also used to provide enhanced functionality. Additionally, a font server may provide a modest performance boost by off-loading font rendering to a separate process.
X knows about fonts according to fonts that are in the "FontPath". This is set initially in XF86Config. If the X server is handling font duties itself (i.e. no font server), this will be a list of directories that contain font files, like:
If a font server is being used, the "FontPath" will point to the socket where the font server is serving (this is just one possible example):
In this latter case, the actual font directories that are available will be configured with the font server (see local documentation), which will use a similar directory type scheme as shown for XF86Config.
Once suitable fonts have been installed, they must be "prepared". For most fonts, this means running the mkfontdir utility (see man page) in the directory where the fonts are (as root). Type 1 and TrueType require additional steps (see below). Your vendor has done this for any fonts that were included with your distribution. So, this will only need to be done for fonts that you add. For newly added fonts to become visible to X, you will need to run the appropriate xset commands to either modify the existing FontPath, or re-read it (see man page). Or, re-initialize your font server.
Example: Preparing fonts, and re-initializing font server after adding new fonts:
The first command may not be necessary on newer distros (since it's done by the init script in some cases). And the font server configuration would need to be modified, if this is a new directory. Example: re-initializing with no font server:
The "xset +fp" would not be necessary if the directory is already part of the FontPath.
xlsfonts | less can be used to list what fonts are known, and thus available, to X and its clients. Run xlsfonts | less, and you also can get an idea of the font definition as understood by X. Font resources are specified quite explicitly, and it may seem complex at first. The X Logical Font Description ("XLFD") is the full description for any given font. The XLFD looks like:
Where each field, left to right is:
The "*" acts as a wild-card character. In fact, if not every field is specified, the X server will take the first match it finds in the FontPath. This is why it is best to order the FontPath with preferred fonts coming first since some programs will deliberately specify fonts "loosely" so that your system has some discretion.
The program xfontsel (X Font Selector) may be useful. Try launching it now. You will see nothing helpful in the main window at first, but try holding the left button down on the fndry button. If all your fonts are in order, you will see a menu of selections such as adobe and b&h and bitstream and so forth. Select one such as b&h and you will notice that the font in the lower window changes to something intelligible. This is the way fonts are selected with this program; starting from the left, which is the most general selection, and moving toward the right, to the more specific options. Selecting an option toward the rightmost end will not make much sense before the foundry, for instance, is selected, because the options are generally ordered by their dependence on each other.
When you select from the fmly selection, you will see most of the options grayed out, and only three remaining. That means that these three are the only families of font made by this foundry. Some families appear under more than one foundry, for instance, both Adobe and Bitstream make a variation of the Courier font. Now you can select the wght, and so forth. After you get far enough you will have narrowed it down to the font that you want. You don't necessarily have to fill in all the options to choose a single font, there's not that many fonts on your system! The options that you do not select will be represented by a * indicating that any option will do in that spot, and gives X some leeway.
When you are satisfied with your font selection, hit the select button, and your selection will be placed in the X clipboard, ready to be pasted into your document or whatever you are working on. For example, open an xterm window and type in something like xterm -font followed by an opening quotation mark. Then point to that spot on your screen, and click your middle mouse button (or click both the left and right, if you're middle-button impaired). This will paste the selection from the clipboard, which should be the font you just selected. Then enter the closing quote, and hit Enter. For instance, a nice big xterm with a Courier font specified would look like this: xterm -font "-adobe-courier-medium-r-*-*-14-*-*-*-*-*-*-*".
If you've found a font you prefer, this can permanently be used by placing the font definition in the appropriate configuration file (see above).
Note that you can also limit the number of fonts that you want xfontsel to display with the command line option -pattern, followed by a quoted font specification, as discussed above.
The xfd utility is also helpful for examining individual fonts. If launched with a command line such as xfd -fn fixed, it will show you the complete character set for that font.
KDE and GNOME have their own utilities that are not quite as obtuse ;-)
The fonts provided with XFree86 are of limited use for many of us, considering that about the only place you'll find fonts of that kind, are used in the X Window System itself for the most part. Unfortunately many media junkies, web designers and fontaholics work in operating systems that rely on other formats. And then, there often does not seem to be much emphasis by some distributions on making the best of the default fonts either.
Type 1 fonts, most commonly used in conjunction with PostScript document formats, are the traditional standard in Unix and Linux environments. You should have a reasonably good starter selection installed already. Or, more can be found for free on the Internet with considerable ease, and Try ftp://ftp.cdrom.com/pub/os2/fonts/ for starters. Type 1 are scalable fonts, and have many of the same benefits of the better known TrueType fonts. If you don't have a good selection of TrueType fonts installed, then Type 1 is what you want for most GUI applications. But again, this is not standard on other platforms, and can present problems when viewing documents (e.g. web pages) that are designed with "other platforms" in mind.
TrueType fonts started with Apple, and later were licensed by Microsoft. So people migrating from non-Unix platforms are already familiar with these high quality fonts. Unfortunately, there are not many quality TrueType fonts under a suitable license, and thus there are not many included with Linux distributions. And the ones that are, often are not as high quality. Also unfortunately, TrueType has become somewhat of a standard on the Web and in other venues, and not having good TrueType fonts can be a detriment. XFree86 also seems to render TrueType a little better than Type1.
That's the bad news. The good news is that any TrueType font included with any version of Windows, or any Windows applications, should work on Linux. Though you will have to take some additional steps to integrate them. This particularly helps web browsing where X's bitmapped fonts just don't scale well.
We won't go into detail on installing and configuring these fonts here, as it is addressed in depth in other documents. See The Font HOWTO , http://www.linuxdoc.org/HOWTO/Font-HOWTO.html, for general font information, and Type 1 tips. See The Font De-Uglification Mini HOWTO, http://www.linuxdoc.org/HOWTO/mini/FDU/index.html, for various X related font tips, especially TrueType.
Let's go back to our terminal window and try something. Open an xterm with a command line like the following:
Ouch! While that may not be pretty, and you may not do much of your best work in it, it demonstrates one interesting aspect of X configuration -- color names. While not particularly precise, this is a nice way to remember a variety of colors. Note that color names are never case-sensitive.
The X server will actually deal with color values as a hexadecimal Red-Green-Blue (RGB) color notation. This would look something like "#0aff0a" in hex. Not so easy to remember. But X gives a more mnemonic way of remembering valid color definitions. These are stored in a text table, typically as /usr/X11R6/lib/X11/rgb.txt, and is defined in XF86Config in the "Files" section.
If you are interested, have a look with a text editor. There are many, many shades defined. I count eighty-three shades of blue in mine, for instance. Brief snip:
This file can be customized should you desire, but this is rarely needed for most of us. It is important to have though, since some applications depend on it.
Desktop Environments will have a GUI utility for selecting colors.
We won't delve into configuring Window Manager's and Desktop Environments. There is just too much to try to cover in one document. It is important to realize that the two are not the same. There are many, many Window Managers available.
Window Managers are highly configurable. Many aspects of user interaction can be controlled by the Window Manager.
Some of the most popular Window Managers:
GNOME and KDE both have their default Window Manager, but support other, compliant Window Managers as well. Your distribution probably has included at least several. Try them all if you don't already have a favorite. Your distribution probably also has a method of switching dynamically between Window Managers (and Desktop Environments too).
Desktop Environments are not really new, but their popularity has increased with advent of the two big names: KDE and GNOME. To a certain extent, the Desktop Environment functionality overlaps the Window Manager's. They both can be responsible for the root window background, root window menu, icons, taskbars, etc. Generally speaking, if a Desktop Environment is running, it is controlling these aspects. That is the main idea behind them -- to integrate the various components into a cohesive, consistent whole. Desktop Environments also add some interoperability and ease-of-use features that a simple Window Manager cannot.
Oh, another point: Desktop Environments also try to do as much X session configuration as possible. Any of their compliant clients will more than likely be configured by the Desktop, or have it's own configuration that conforms to the Desktop's style. This is at least partly to avoid much of the seemingly helter-skelter text file configuration we looked at in the above sections, and make life a little easier for the user.
There is a trade-off in this additional functionality, and that is that it takes memory and system resources to oversee all this. If you have plenty of memory and a fast computer, this is no problem. But in low memory situations, this can cause a slowdown (see the performance section below). 64M of RAM is probably borderline with either KDE or GNOME.
So do you need a Desktop Environment? That is up to the user. They are certainly not required to run X, but do add features that many users want or expect in a GUI. Which one is better? Ah, but that is up to you to decide!
KDE has been around longer than GNOME, and some would say maybe a little more mature. KDE is based on the QT widget toolkit. A quote from the KDE home page:
GNOME is based on the GTK+ toolkit. And a quote from the GNOME home page:
XFce is a lighter weight, less featureful Desktop Environment that does not get as much attention as the others. XFce is also based on the GTK+ toolkit. And a quote from the XFce home page:
All these have their own extensive documentation. If you can't find what you need installed on your system, check the respective home pages.
What would a Unix-like operating system be without a command line interface? The command line can be useful, and is readily available with X. In fact, for many it is an integral part of their X working environment.
Any X program can be started directly from the command line just by typing the program name at a shell prompt in an xterm, or other terminal window. Most applications will have a very rich set of command line "options", such as background color, font, geometry (screen placement), etc, etc. Command line options over-ride compiled in defaults, or other system enabled "resources".
Many traditional X programs will use the same basic names for command line options. All applications written using the MIT X Toolkit Intrinsics (Xt) (such as those included with XFree86) automatically accept the following options. Some non-Xt applications also use these, or something similar. For instance, "geometry" is close to a universally accepted option.
These are the most noteworthy. There are others. Many programs will have their own additional options that are application specific. Many newer applications today don't necessarily adhere to the Xt standards, and will use their own options, or those provided by their respective toolkit. If nothing else, man pages are a good reference for command syntax, and are your friends here. Or, the application will have a "--usage" or "--help" command line switch to list available options:
Sooner or later, most of us need to access the "command line" for one reason or another. For some, this might even be a common way of working in X. In addition to being able to launch X applications from the command prompt, there is also a wealth of programs that run in "text mode" for Linux.
This is possible via "terminal emulators" such as xterm. The closest counterpart from Microsoft is the so-called DOS-box, which is child's play by comparison. Linux terminals support color, full mouse copy/paste (and some wheeled mice), pseudo-transparency and pixmap backgrounds, scrollbars, menus and generally a slew of other features. While xterm is the best known such terminal emulator, there are many similar programs. To name a few: Eterm, rxvt, aterm, konsole (KDE) and gnome-terminal.
In typical usage, when a terminal emulator window is opened, a shell is started for the user to interact with. The default for essentially all Linuxes, is the bash shell. So when all is said and done, the user is interacting with X, the terminal, and the shell all at once. Each may have it's own influence. For example, how keystrokes are handled since they move from hardware to X server to terminal to the shell and finally echoed back to the user.
Quick and easy terminal configuration is done via the "$TERM" variable, which is typically set in one of the user's shell configuration files. Or the terminal itself will have a compiled in default. The default value for this is most often "xterm":
Normally this is sufficient, as your vendor has already set this up in a reasonable way. The "$TERM" variable is actually a reference to an entry in the "termcap" database (man termcap), which is typically installed as /etc/termcap. Unless you are doing something really unusual, you probably won't need to change this. Some additional terminal configuration can be done with the stty command (see man page). Terminal configuration is really beyond the scope of this document.
The terminal application itself (e.g. xterm) will also have various configuration options. Permanent settings are best stored in a ~/.Xdefaults or similar file for those applications that support this. Generally speaking, applications with a GUI configuration (such as gnome-terminal), will be configured by their own menu driven configuration instead.
Also, you are interacting with the shell too, which can have it's own impact, particularly on how keystrokes are handled at the shell prompt. For bash, this can be adjusted in ~/.inputrc. Again, this is beyond the scope of this document, but check with either local or on-line bash (or other shell) references.
Terminal emulators like xterm require a monospaced font. So forget about TrueType or Type 1 fonts.
As mentioned, X is essentially a networking protocol with graphical displaying capabilities. This makes for some interesting usage possibilities. And also means there are inherent security considerations, as there is with any networking environment. And if you ever connect to the Internet, you are in the midst of one very large, hostile network ;-)
X clients connect to X servers via various networking protocols, including TCP/IP. Even with just local connections. Possible usages here are to run an application on one computer, and display it on another. Or, to actually log in to a remote system, and have it display to your local screen, with the client apps using the remote system's CPU and RAM.
Without any precautions, this can leave you wide open to various types of mischief and abuse. For instance, anyone logged into to your system can access your "display", meaning they can see what you are doing if they want to. Thankfully, most recent Linux releases come with some default security precautions enabled. But it is best to make sure for yourself that you are protected.
Both X networking and security are nicely covered in The Remote X Apps Mini HOWTO, http://www.linuxdoc.org/HOWTO/mini/Remote-X-Apps.html, so we won't need to try to rehash it here. Recommended reading. See other references in the Links section of the Appendix below.
A few recommended precautions:
As has been discussed, what we call X, is actually a convergence of various components: X server, Window Manager, Desktop, etc. With MS Windows, the GUI desktop is tightly integrated with the operating system itself. This is not the case in Linux which follows the Unix tradition of combining various independent components to achieve some end result. So we have choices with each component and it's attendant configuration and implementation. In short, much flexibility. This is where you come in. You can try various possibilities and decide what you gives you the most bang for the buck.
On low end hardware, this gives us much latitude to decrease the demand on available system resources. This is good because, if given the opportunity, X can be quite greedy with system resources. If you've recently installed a new Linux distribution, you've probably been given a default Desktop with many bells and whistles. And something that will probably need a fair amount of memory and CPU to achieve a reasonable level of performance. If you have the horse power, this should not be a problem.
It is often said that Linux functions very well with relatively little memory. This is true to a point. It does not mean though that every possible configuration will run with low memory. So if you want to use memory hungry applications, then you will have to have the memory. Or you will have to make sacrifices to achieve a satisfactory level of performance. It is quite possible to run X with reasonable performance on 16 Meg of RAM, and even less if you really want to push it. But you would have to live with some real limitations.
Let's look at some of the components and ways to decrease the demand on system resources, in case you are at the low end on hardware, or performance is not up to expectations.
The more memory, the better. X will do a lot caching to help performance. But caching requires memory, and if there isn't much to start with, then we would need to reduce memory requirements. Some tips for those with low memory or performance problems:
X is not particularly network friendly. In other words, it is a bandwidth hog. This should not be a problem in LAN situations, but may be if trying to use X over the Internet.
Other tips to eek out better performance:
There are a few basic concepts and terminologies you should be familiar with. These terms will appear here, in the manual pages, and in other help files and documentation.