X Window System Components

User Notes: http://wiki.linuxfromscratch.org/blfs/wiki/XWindowSystemComponents

Creating an X11R6 Compatibility Symlink

Until recently (relatively speaking) almost every X Window installation you performed or came across was installed in the /usr/X11R6 directory. That was the standard for years. Developers picked up on this and wrote their package installation scripts looking for X in the standard location. Things have changed and the trend is to now install X in /usr. Some people want to install it in a custom location.

Many package developers have not caught up to the change and their packages are still trying to find X in /usr/X11R6 and subsequently fail when you try to build the package. Though for most packages it is not difficult to 'hack' the installation script to fix the problem, that is not the long term solution to the problem. Upstream developers need to modernize their installation scripts and eliminate the problem altogether.

Until then, you can create a symbolic link to satisfy the /usr/X11R6 requirement so that you won't be inconvenienced with a package build failure due to this known issue. If you wish to create the symlink, issue the following command as the root user (ensure you modify <$XORG_PREFIX> appropriately):

ln -vsf <$XORG_PREFIX> /usr/X11R6

Configuring The X Window System

If you've installed the X Window System in any prefix other than /usr, become the root user and update the library linker's cache by adding /usr/X11R6/lib to /etc/ld.so.conf and running ldconfig.

Additionally, while still the root user, ensure /usr/X11R6/bin and /usr/X11R6/lib/pkgconfig are added to the PATH and PKG_CONFIG_PATH environment variables, respectively. Instructions for doing this are described in the section The Bash Shell Startup Files.

Ensure you replace /usr/X11R6 with $XORG_PREFIX in the previous two paragraphs if you did not create the compatibility symlink in the previous step.

As the root user create a basic X Window System configuration file with the following command:

cd ~ &&
Xorg -configure

The screen will go black and you may hear some clicking of the monitor. This command will create a file in your home directory, xorg.conf.new for Xorg, or XF86Config.new for XFree86.

Edit the newly created configuration file to suit your system. The details of the files are located in the xorg.conf.5x man page. Some things you may want to do are:

  • Section "Files". Change the order of the font paths searched. You may want to put 100dpi fonts ahead of 75dpi fonts if your system normally comes up closer to 100 dots per inch. You may want to remove some font directories completely.

  • Section "Module". If you are going to install NVIDIA drivers, remove the "dri" line.

  • Sections "InputDevice". You may want to change the keyboard autorepeat rate by adding Option "Autorepeat" "250 30".

  • Section "Monitor". Specify the VertRefresh and HorizSync values if the system does not automatically detect the monitor and its values.

  • Section "Device". You may want to set some of the options available for your selected video driver. A description of the driver parameters is in the man page for your driver.

  • Section "Screen". Add a DefaultDepth statement such as: DefaultDepth 24. In the SubSection for your default depth, add a modes line such as: Modes "1600x1200" "1280x1024" "1024x768". The first mode listed will normally be the starting resolution.

Test the system with the following command:

X -config ~/xorg.conf.new

You will only get a gray background with an X-shaped mouse cursor, but it confirms the system is working. Exit with Control+Alt+Backspace. If the system does not work, take a look at /var/log/Xorg.0.log to see what went wrong.

As the root user, create the configuration directory and move the configuration file to the new directory:

install -v -m644 -D ~/xorg.conf.new /etc/X11/xorg.conf

As the root user, create .xinitrc:

cat > ~/.xinitrc << "EOF"
# Begin .xinitrc file
xterm  -g 80x40+0+0   &
xclock -g 100x100-0+0 &

This provides an initial screen with a small clock that is managed by a simple window manager, Tab Window Manager. For details of twm, see the man page.



Both the default, and the BLFS configuration for Xorg include xterm. Xorg's modular distribution no longer includes xterm, and as a result, the startx command will fail if you have not installed xterm-231 when using the modular X Window System. You can remove the xterm line in the above config file to test the xserver, or install one of the other terminal emulators and make appropriate changes.

When needed, the X Window System creates the directory /tmp/.ICE-unix if it does not exist. If this directory is not owned by root, the X Window System delays startup by a few seconds and also appends a warning to the logfile. This also affects startup of other applications. To improve performance, it is advisable to manually create the directory before the X Window System uses it. Add the file creation to /etc/sysconfig/createfiles that is sourced by the /etc/rc.d/init.d/cleanfs startup script.

cat >> /etc/sysconfig/createfiles << "EOF"
/tmp/.ICE-unix dir 1777 root root

Start X with:


and a basic functional X Window System should be displayed.

Checking Direct Rendering Infrastructure (DRI) Installation

DRI is a framework for allowing software to access graphics hardware in a safe and efficient manner. It is installed in X by default if you have a supported video card. To enable direct rendering using the OpenGL implementation from MesaLib-6.5.2 (built separately with Xorg-7.2 ), the "glx" and "dri" modules must be loaded. Additionally, the created device nodes in /dev/dri must have proper permissions for your users. A sample xorg.conf file might look like this:

Section "Module"
    Load  "glx"
    Load  "dri"
Section "DRI"
    Group "video"
    Mode  0660

The DRI devices are not accessible for any user except root and members of the video group. Add any users that might use X to that group:

usermod -a -G video <username>


DRI configuration may differ if you are using alternate drivers, such as those from NVIDIA or ATI.

To check if DRI is installed properly, check the log file /var/log/Xorg.0.log for statements like:

(II) R128(0): Direct rendering enabled

If you elected to install the Mesa-Demos package when installing MesaLib-6.5.2, from an xterm, run glxinfo and look for the phrase:

direct rendering: Yes

If direct rendering is not enabled, you can add verbosity by running LIBGL_DEBUG=verbose glxinfo. This will show the drivers, device nodes and files used by the DRI system.

Again, if you have added the Mesa-Demos package, you can also run the test program glxgears. This program brings up a window with three gears turning. The xterm will display how many frames were drawn every five seconds, so this is a reasonable benchmark. The window is scalable, and the frames drawn per second is highly dependent on the size of the window.

For troubleshooting problems, check the DRI Users Guide at http://dri.sourceforge.net/doc/DRIuserguide.html.

Setting up Fonts

There are two font systems in the X Window System. The first is the core X font protocol, and the second is Xft. Toolkits that use the core X font protocol include Xt, Xaw, Motif clones and GTK+-1.2. Toolkits that use Xft include GTK+-2 and Qt and use Fontconfig for control. Both font systems should be configured for proper font coverage in the X Window System.

Core X Font Protocol

The core X font protocol finds fonts from the server configuration file (xorg.conf). If no font paths exist in the configuration file, the server will fall back to an internal hard-coded path. Assuming the prefix for your X installation is /usr/X11R6, the core fonts will reside in subdirectories of /usr/X11R6/lib/X11/fonts. For each directory in the path, the server reads three files:

  • fonts.dir - maps font files to font names; updated with mkfontdir

  • fonts.alias - defines aliases (such as "9x18") for existing fonts

  • fonts.scale - lists scalable fonts; updated with mkfontscale

The core X fonts protocol uses names such as -misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-1. These fonts are rendered by the X server without antialiasing. The server itself uses the "cursor" font for painting the mouse cursor, and the protocol specification requires the font "fixed" to be available.

Scalable fonts, such as Type1 and TrueType, are read from fonts.scale files by the server. The core X font system uses the "freetype" module for non-antialiased rendering of these fonts. Ensure that the "freetype" module is loaded in the xorg.conf file by adding it to the "Module" section:

Section "Module"
    Load  "freetype"

The character set used is part of the font name, e.g. "-iso8859-1". It is important that applications which support a non-English interface specify the character set correctly so that the proper glyphs are used. This can be controlled through the X resources, which will be described later.

In some cases, applications rely upon the fonts named "fixed" or something like "9x18". In these cases, it is important that the fonts.alias file specifies the correct character set. Users of ISO-8859-X encodings where X != 1 should modify the /usr/lib/X11/fonts/misc/fonts.alias file by replacing the "iso8859-1" string with the proper encoding name. This is accomplished by running the following command as the root user, substituting the proper value for <X>:

sed -i 's,iso8859-1\( \|$\),iso8859-<X>\1,g' \

Users of Cyrillic fonts have properly defined aliases in /usr/lib/X11/fonts/cyrillic/fonts.alias. However, this file will not be used unless the /usr/lib/X11/fonts/cyrillic directory is first in the font search path. Otherwise, the /usr/lib/X11/fonts/misc/fonts.alias file will be used.

Xft Font Protocol

Xft provides antialiased font rendering through Freetype, and fonts are controlled from the client side using Fontconfig. The default search path is /usr/share/fonts and ~/.fonts. Fontconfig searches directories in its path recursively and maintains a cache of the font characteristics in fonts.cache-1 files in each directory. If the cache appears to be out of date, it is ignored, and information is (slowly) fetched from the fonts themselves. This cache can be regenerated using the fc-cache command at any time. You can see the list of fonts known by Fontconfig by running the command fc-list.

The X fonts were not installed in a location known to Fontconfig. This prevents Fontconfig from using the poorly rendered Type 1 fonts or the non-scalable bitmapped fonts. Symlinks were created from the OTF and TTF X font directories to /usr/share/fonts/X11-{OTF,TTF}. This allows Fontconfig to use the OpenType and TrueType fonts provided by X (which are scalable and of higher quality).

Fontconfig uses names such as "Monospace 12" to define fonts. Applications generally use generic font names such as "Monospace", "Sans" and "Serif". Fontconfig resolves these names to a font that has all characters that cover the orthography of the language indicated by the locale settings. Knowledge of these font names is included in /etc/fonts/fonts.conf. Fonts that are not listed in this file are still usable by Fontconfig, but they will not be accessible by the generic family names.

Standard scalable fonts that come with X provide very poor Unicode coverage. You may notice in applications that use Xft that some characters appear as a box with four binary digits inside. In this case, a font set with the available glyphs has not been found. Other times, applications that don't use other font families by default and don't accept substitutions from Fontconfig will display blank lines when the default font doesn't cover the orthography of the user's language. This happens, e.g., with Fluxbox in the ru_RU.KOI8-R locale.

In order to provide greater Unicode coverage, it is recommended that you install these fonts:

  • DejaVu fonts - These fonts are replacements for the Bitstream Vera fonts and provide Latin-based scripts with accents and Cyrillic glyphs. The DejaVu fonts by are not aliased to the generic family names by default, so /etc/fonts/fonts.conf will have to be edited for it to be recognized by the generic names such as "Sans". This will be described below.

  • FreeFont - This set of fonts covers nearly every non-CJK character, but is not visually pleasing. Fontconfig will use it as a last resort to substitute generic font family names.

  • Microsoft Core fonts - These fonts provide slightly worse Unicode coverage than FreeFont, but are better hinted. Be sure to read the license before using them. These fonts are listed in the /etc/fonts/fonts.conf aliases by default.

  • Firefly New Sung font - This font provides Chinese coverage. This font is not listed in the /etc/fonts/fonts.conf aliases by default.

  • Arphic fonts - A similar set of Chinese fonts to the Firefly New Sung font. These fonts are listed in the /etc/fonts/fonts.conf aliases by default.

  • Kochi fonts - These provide Japanese characters, and they are listed in the aliases in /etc/fonts/fonts.conf by default.

  • Baekmuk fonts - These fonts provide Korean coverage, and they are listed in the aliases in /etc/fonts/fonts.conf by default.

The list above will not provide complete Unicode coverage. For more information, please visit the Unicode Font Guide.

As an example, consider the installation of the DejaVu fonts. From the unpacked source directory, run the following commands as the root user:

install -v -d -m755 /usr/share/fonts/dejavu &&
install -v -m644 *.ttf /usr/share/fonts/dejavu &&
fc-cache -v /usr/share/fonts/dejavu

Setting up Keyboards

In this version of X, non-Latin keyboard layouts do not include Latin configurations as was previous practice. To set up a keyboard for Latin and non-Latin input, change the XkbLayout keyboard driver option in the InputDevice section of the xorg.conf file. For example:

Section "InputDevice"
    Identifier          "Keyboard0"
    Driver              "kbd"
    Option "XkbModel"   "pc105"
    Option "XkbLayout"  "en_US,ru"
    Option "XkbOptions" "grp:switch,grp:alt_shift_toggle,grp_led:scroll"

In this example, you can use the Alt+Shift combination to switch between keyboard layouts and use the Scroll Lock LED to indicate when the second layout is active.

Setting up XDM

xdm provides a graphical logon capability and is normally set up in /etc/inittab. Most of the information you need to customize xdm is found in its man page. To execute xdm during bootup, change the initdefault level to 5 and add the following lines to /etc/inittab:

# Run xdm as a separate service
x:5:respawn:/usr/X11R6/bin/xdm -nodaemon

If Linux-PAM is installed on your system, you should create a PAM entry for xdm by duplicating the login entry using the following command:

cp -v /etc/pam.d/login /etc/pam.d/xdm

Using X Resources

There are many options that can be set in X and X clients via resources. Typically resources are set in the ~/.Xresources file.

The layout of the ~/.Xresources file consists of a list of specifications in the form of

object.subobject[.subobject...].attribute: value

Components of a resource specification are linked together by either tight, represented by a dot (.), or loose, represented by an asterisk (*), bindings. A tight binding indicates that the components on either side of the dot must be directly next to each other as defined in a specific implementation. An asterisk is a wildcard character that means that any number of levels in a defined hierarchy can be between the components. For example, X offers two special cursors: redglass and whiteglass. To use one of these resources, you need to add the following line:

Xcursor.theme: whiteglass

However, you can specify the background for all clients with:

*background: blue

More specific resource variables will override less specific names.

Resource definitions can be found in the man pages for each respective client.

In order to load your resources, the xrdb program must be called with the appropriate parameters. Typically, the first time resources are loaded, you use:

xrdb -load <filename>

To add resources to X's database in memory, use:

xrdb -merge <filename>

The xrdb instruction is usually placed in ~/.xinitrc or ~/.xsession. To get more information, see the xrdb man page.

Last updated on 2008-05-09 08:00:42 -0500