Chapter 15. X

Table of Contents
15.1. What is X?
15.2. Configuration
15.3. The mouse
15.4. The keyboard
15.5. The monitor
15.6. Video card and X server
15.7. Starting X
15.8. Customizing X
15.9. Other window managers
15.10. Graphical login with xdm

15.1. What is X?

The X Window System is a graphical environment available for NetBSD and many Unix (and non Unix) systems. In fact it is much more than that: thanks to the usage of the X protocol, the X Window System is "network transparent" and can run distributed applications (client-server). This means, roughly, that you can run an application on one host (client) and transparently display the graphical output on another host (server); transparently means that you don't have to modify the application to achieve this result. The X Window System is produced and mantained by the X Consortium and the current release is X11R6. The flavour of X used by NetBSD is XFree86, a freely redistributable open source implementation of the X Window System.

When you start using X you'll find many new terms which you'll probably find confusing, at first. The basic elements to use X are:

To summarize, in order to use a graphical environment you need:

Normally, you can run at most one window manager at any given time on a given X server. (But you can run multiple X servers on a single computer.) If you are not running a window manager of your choosing, and start KDE/GNOME, then that desktop environment will run a window manager for you.

15.2. Configuration

If you haven't chosen a minimal configuration during installation, X is already installed and ready to run on your computer; you only have to create the menacing /etc/XF86Config file. To get an idea of what this file looks like, examine the /usr/X11R6/lib/X11/XF86Config.eg file. The structure of the configuration file is described formally in XF86Config(4/5), which can be examined with the following command:

# man XF86Config    

Before configuring the system it is advisable to carefully read the documentation found in /usr/X11R6/lib/X11/doc: there are various README's for the video cards, for the mouse and even a NetBSD specific one (README.NetBSD.) I suggest to start by reading QuickStart.doc. You might have the feeling that other systems let you start more quickly and with less effort, but the time spent reading this documentation is not wasted: the knowledge of X and of your configuration that you gain will turn out very useful on many future occasions and you'll be able to get the most from your hardware (and software too.)

You can create the /etc/XF86Config file manually with an editor or you can generate it automatically with an interactive configuration program. The best known programs are xf86config and XF86Setup. The former is a text mode program and is installed by default with X; the latter is a graphics program which can be installed from the package collection.

You may find that a mixed approach is better: first create the XF86Config with one of the two programs and then check it and tune it manually with an editor.

The interface of the two programs is different but they both require the same set of information:

Before configuring the system you should collect the required information.

15.3. The mouse

The first thing to check is the type of mouse you are using (for example, serial or PS/2, ...) and the mouse device (for example, wsmouse requires a different protocol.) If you are using a serial mouse, choose the required protocol and specify the serial port to which it is connected. For example, for a serial mouse on the first serial port:

Section "Pointer"
  Protocol    "Microsoft"
  Device      "/dev/tty00"
EndSection    

For a mouse using the wsmouse device you might have:

Section "Pointer"
  Protocol    "wsmouse"
  Device      "/dev/wsmouse0"
EndSection    

In the "Device" field you can also specify /dev/mouse provided that you have created the correct link in the filesystem. For example:

# ln -sf /dev/wsmouse0 /dev/mouse    

15.4. The keyboard

Even if you have already configured your keyboard for wscons, you need to configure it for X too, in order to get a non US layout.

An easy solution is to use the XKB protocol, specifying the keyboard type and layout.

This is one area in which that configuration programs are weak and you may want to choose the standard layout and modify the generated configuration file manually.

# XkbDisable
# XkbKeymap   "xfree86(us)"

XkbModel        "pc102"
XkbLayout       "de"
XkbVariant      "nodeadkeys"    

If you want to use the "Windows" keys on your keyboard, use pc105 instead of pc102 for XkbModel.

15.5. The monitor

It is very important to correctly specify the values of the horizontal and vertical frequency of the monitor: a correct definition shields the monitor from damages deriving from an incompatible setup of the video card. This information can be found in the monitor's manual. In the X documentation directory there is a file containing the settings of many monitors; it can be used as a starting point to customize your own settings.

15.6. Video card and X server

The video card can be chosen from the database of the automatic configuration programs; the program will take care of all the needed setups.

When you have selected the correct video card you must choose the X server for the card. Usually, the configuration programs can automatically determine the correct server, but some video cards can be driven by more than one server (for example, S3 Virge is supported by the SVGA and S3V servers); in this case, study the documentation of the servers to decide which one you need: different servers usualy have different capabilities and a different degree of support for the video cards.

15.7. Starting X

When you exit the configuration program, it creates the file /etc/XF86Config, which can be further examined and modified by hand.

Before starting X you should:

Now you can start X with the following command:

# startx    

If X doesn't fire up there is probably some error in the configuration file.

If X starts but doesn't work as expected (for example, you can't move the mouse pointer) you can exit quickly with the Ctrl-Alt-Backspace key combination (not available on all ports.) If everything worked correctly you are left in the X environment with the default window manager (twm): although it is a simple window manager many users feel that it is enough for their needs. If you want a highly configurable window manager with many bells and whistles, you have many choices in the package collection.

To start customizing X, try giving the following command in an xterm to change the background color:

# xsetroot -solid DarkSeaGreen    

15.8. Customizing X

The look of the X environment can be customized in several ways. The easiest method is to copy the default .xinitrc file in your home directory and modify it. For example:

# cp /usr/X11R6/lib/X11/xinit/xinitrc ~/.xinitrc
# vi .xinitrc
    

The following example shows how to start the window manager (twm), open an instance of the xclock program in the lower right part of the screen and two xterm windows. The "Bisque4" color is used for the background.

the first part of the file is the same
...
# start some nice programs
twm &
xclock -geometry 50x50-1-1 &
xterm -geometry 80x34-1+1 -bg OldLace &
xsetroot -solid Bisque4 &
exec xterm -geometry 80x44+0+0 -bg AntiqueWhite -name login    

With this type of setup, to exit X you must close the last xterm (the one with the "login" title.)

Even with this simple configuration X has a considerably nicer look. To give an even better look to the environment you can install some utility program from the package collection. For example:

15.9. Other window managers

In the package collection you can find a variety of window managers which you can use in place of twm, some with a limited set of features but a very small memory footprint, others with many fancy features (eg. virtual desktops, dithered window colors, etc.) Some of the most popular are: fvwm2, olwm/olvwm (Open Look Window Manager), WindowMaker, Enlightenment, AfterStep.

In the rest of this section the installation of WindowMaker is described as an example. WindowMaker is a very nice looking and highly configurable window manager. To add the program the windowmaker-0.60.tgz precompiled package will be used, which depends on some other packages which must be installed. As usual, both pkg_add and make install will fetch the needed packages automatically, so there is no need to go through the dependencies manually.

# cd /usr/pkgsrc/x11/windowmaker
# make depends-list
xpm-3.4k
jpeg-6b
pkglibtool-1.2p2
giflib-3.0
libproplist-0.9.1
tiff-3.5.2    

After adding the required packages, WindowMaker and some preconfigured themes can be added:

# pkg_add windowmaker-0.61.0.tgz wmthemes-0.6x.tgz      

WindowMaker is now installed; to start it you must modify your .xinitrc and/or .xsession: substitute the line which calls twm with a line which calls wmaker. For example:

# start some nice programs
# start WindowMaker
wmaker &
xclock -geometry 50x50-1-1 &
xdaemon2 -geometry +0-70 &
...      
In this example the xdaemon program is also started automatically.

Before starting WindowMaker the configuration program must be run:

$ wmaker.inst
$ startx
    

15.10. Graphical login with xdm

If you always use X for your work and the first thing you do after you log in is run startx, you can set up a graphical login for your workstation which does this automatically. It is very easy:

The configuration files for xdm are in the /usr/X11R6/lib/X11/xdm directory. In the Xservers file X is started by default on the vt05 virtual terminal; if you want to use another terminal instead, this is the right place to modify the setting. In order to avoid keyboard contention between getty and xdm it is advisable to start xdm on a virtual terminal where getty is disabled. For example if in Xservers you have:

:0 local /usr/X11R6/bin/X :0 vt04    

in /etc/ttys you should have

ttyE3   "/usr/libexec/getty Pc"         vt220   off secure    

(please note that vt04 corresponds to ttyE3 because vt start at 1 and ttyE start at 0.)

If you want a nice look for your xdm login screen, you can modify the xdm configuration file. For example, to change the background color you can add the following line the the Xsetup_0 file:

xsetroot -solid SeaGreen    

Instead of setting a color, you can put an image on the background using the xpmroot program: For example:

xpmroot /path_to_xpm/netbsd.xpm    

If you experiment a little with the configuration file you can achieve many nice looking effects and build a pleasing login screen.