COMP111 Lab Session 2
Configuring X Windows

Overview

In this lab session, the following will be covered:

Playing with some X programs

Try some programs that use the X display. When you type the command, put an ampersand (&) after it :

  1. xeyes
  2. xterm
  3. xclock
  4. xmag
  5. xcalc
  6. xfontsel
  7. xman

Executing X applications on another display

Through the X protocol, X applications can be run on one machine and displayed to another machine by setting up parameters in both of them.

Suppose you are using machine B and you want to run xeyes on machine A and display the xeyes window on your own machine (machine B), you need to:

  1. Use the xhost command in machine B to include machine A into the access list. For example, if machine A is csl3su1, the following command should be used in machine B
    xhost +csl3su1
    Note that each machine in CS lab has been assigned a hostname in the form of cslXsuXX.
  2. You can then telnet into machine A and execute xeyes on machine A by the following command (assume that machine B is csl3su2):
    xeyes -display csl3su2:0.0
    The xeyes window should then appear on the display of machine B.
  3. Alternatively, you could do the following in machine A instead of the above
    setenv DISPLAY csl3su2:0.0
    xeyes
    The difference is that not only xeyes but all X applications executed after the command setenv will be displayed on csl3su2, i.e. machine B.

Using command line options of X applications

Command line options are options which are provided to set the behaviour of the application being invoked. Let's take xterm as an example, if you don't like a white background, you could change it to black by typing

xterm -background black

A black xterm will then appear. However, you discover that the foreground and background are the same in color. You could then type

xterm -background black -foreground white

to change the background and foreground colors simultaneously.

You could also use command line options to set the following properties:

The complete list of options available can be retrieved from the manpage of the corresponding application (in this case, `xterm').

Setting default behaviour by .Xdefaults

It would be troublesome if one had to specify a list of command line options everytime. Therefore, a file called .Xdefaults is used to set up default behaviours of your X applications.

The common format of lines in .Xdefaults is like the following:
<application name>*<resource name>: <required value>

For example, if you want to have your xterm opened as
xterm -title "Hello" -geometry 80x25 -foreground white -background black
everytime, then your .Xdefaults will look like this:

xterm*title: Hello
xterm*geometry: 80x25
xterm*foreground: white
xterm*background: black

You could see the manpages for lists of available resources.

Customizing fvwm95 by .fvwm2rc95

This section deals with changing the attributes of the window manager called fvwm.

Each time you want to see the result of an alteration, you will need to stop the window manager and start it again. To do this, log out and then log in again.

To have the ability to change the appearance and functions of your fvwm, you should first create a file called .fvwm2rc95 in your home directory.

To do this, an easy way is to copy the file which is already available, and then alter it. So first you need to copy

/usr/local/software/fvwm95/lib/system.fvwm2rc95

to

~/.fvwm2rc95

by typing

cp /usr/local/software/fvwm95/lib/system.fvwm2rc95 .fvwm2rc95
chmod u+rw .fvwm2rc95

Starting X window with other window managers

There are many window managers which can be used with X windows, such as twm and mwm. The following steps explain how to start a window manager from your CS account.

  1. Copy the file xinitrc to your home directory by
    cp /usr/lib/X11/xinit/xinitrc ~/.xinitrc
  2. Edit the file .xinitrc with pico and change the last few lines from

    # start some nice programs

    xclock -geometry 50x50-1+1 &
    xterm -geometry 80x50+494+51 &
    xterm -geometry 80x20+494-0 &
    xterm -geometry 80x66+0+0 -name login &
    exec twm

    to

    # start some nice programs

    xclock -geometry 50x50-1+1 &
    xterm -geometry 80x50+494+51 &
    xterm -geometry 80x20+494-0 &
    xterm -geometry 80x66+0+0 -name login &
    exec <your window manager>

    The first four applications correspond to the xterms and xclock on your display. You may also change these applications to anything you want, e.g. xeyes, xload, etc.. The window manager would be any one of these: twm, mwm and fvwm.
  3. Copy the corresponding rc file as follows:

    twm: /usr/lib/X11/twm/system.twmrc -> ~/.twmrc
    mwm: /usr/lib/X11/system.mwmrc -> ~/.mwmrc
    fvwm: /usr/local/share/X11R5/virtual_desktop/system.fvwmrc -> ~/.fvwmrc
    and edit them just like when customizing your twm.

    Note that the formats of these rc files are different for different window managers. You should consult the manpages of these window managers on how to customize them.
  4. Restart your window manager by logging out and logging in again.


Setting up chinese xterm

Each chinese character uses 2 bytes for its representation, which is different from the English character (uses 1 byte only for each letter). For example, the following are six Chinese characters which show the Chinese name of our university:

        ­»´ä¬ì§Þ¤j¾Ç

When you do not use a Chinese window, you will just see some funny characters instead of the actual Chinese ones.

Following are the steps on how to set up cxterm. Cxterm is the chinese version of xterm, which can display and input chinese character so that you can read chinese emails and news. After setting up the chinese xfonts, you would be able to browse chinese homepages as well.

  1. Add these lines to your .cshrc_user just before starting up X window, i.e. the line "Start X11 if login at sun console".
    Your .cshrc_user must be altered to include the following :
    ...
    setenv MANPATH "/usr/openwin/share/man:${MANPATH}:/usr/local/share/man"

    ### cxterm (chinese xterm) and other utility
    # for cxterm
    setenv ChinDir /usr/local/CHINESE
    setenv HZINPUTDIR ${ChinDir}/Dict
    # for hz2ps (hanzi to PostScript converter)
    setenv HZDIR ${ChinDir}/hz2ps
    setenv HZFONTDIR ${ChinDir}/hz2ps
    #
    setenv PATH "${ChinDir}/bin:${PATH}"
    setenv MANPATH ${MANPATH}:${ChinDir}/man
    ### various alias for cxterm and hz2ps

    "Start X11 if login at sun console"
    ...
  2. Add this line to the end of your .Xdefaults if it exists. Otherwise, create .Xdefaults and enter the line.
    #include "/usr/local/CHINESE/SETUP/CXterm.ad"
  3. Finally, add these lines to your .xinitrc before the line "# start some nice programs"
    ### Add font path for cxterm
    /usr/bin/X11/xset fp+ $ChinDir/xfonts
    /usr/bin/X11/xset fp rehash
  4. Restart your X window by logging out and logging in again.

Run your cxterm by the command cxterm-b5


Click here to go back to the COMP111 main lab page.


Page prepared by Gibson Lam, modified by Cyril Kwok.