Using the X Window System

Rob Judd

rpjuddmath.utexas.edu

RLM 11.104, x212

September 17, 1996

Table of Contents

Introduction

The X Window System [X Window System is a trademark of the Massachusets Institute of Technology] is a program which allows a number of graphics based programs to be displayed on the screen simultaneously. Any program which is capable of running under X Windows is called an X client, and the program which is running X Windows is called an X server. Usually the client programs will be running on the same machine as the X server, but they may also be run from other machines.

For example you may be running the X server on the machine goldfish and be running the X clients xterm, emacs, xclock and netscape on goldfish, while running matlab on arthur. For details on how to do this, see Section 5.1.

There are two main ways of getting the X server and an initial set of client applications started. The method depends on the terminal you are using. On most terminals X Windows runs permanently via a program called xdm (X Display Manager). In this case you see a window telling you which machine is running the X server and asking for your username and password. Once you have logged in, xdm will start your X environment. Otherwise you may be sitting at a terminal which you think should be running X Windows, but all you can see after you have logged in is the standard prompt. In this case you may start X Windows with the command startx.

While you are using X Windows you don't communicate directly with the X server; instead this is done via a windows manager. The two most common ones are fvwm (the default) and twm. We recommend fvwm--it is more modern looking, uses less memory and is easier to use. These notes will concentrate on fvwm although most of the comments also apply to twm. Fvwm uses three main files: .fvwmrc, the file with the main settings for fvwm; .xsession, an executable shell script which starts fvwm and also any initial client programs (although fvwm can also do that); and .Xdefaults, which contains your personal default setting for certain applications. Section 4 discusses how to customize these files. When it starts up, fvwm will look for these files, and if it fails to find them use the system defaults. The first two may be found in the directory /usr/lib/X11/ under fvwm/system.fvwmrc and xdm/Xsession respectively.

Using the Windows Manager

Windows

[ Adapted from the manual pages for fvwm ] Fvwm puts a decorative border around most windows. This border consists of a bar on each side, and a small ``L'' shaped section on each corner. There is an additional top bar is called the title bar, and is used to display the name of the window. In addition, there are up to 10 title-bar buttons. The top, side and bottom bars are collectively known as the side-bars. The corner pieces are called the frame.

Unless the standard defaults files are modified, pressing mouse button 1 in the title or side-bars will begin a move operation on the window. Pressing button 1 in the corner frame pieces will begin a resize operation. Pressing button 2 anywhere in the border brings up an extensive list of window operations.

Up to ten title-bar buttons may exist. Their use is completely user definable. The default configuration has a single title-bar button on the left side of the title-bar and two on the right side. The one on the left is used to bring up a list of window options, regardless of which mouse button is used. The innermost one on the right is used to iconify the window, while the outer button attempts to resize the window to fill the screen vertically. This has unpredictable results, but the window usually gets bigger.

Desktops

A desktop is simply an organizational unit for the manager. The idea is that you can keep windows for different projects in different places. You might be writing a worksheet in LaTeX, and keep all associated windows on one desktop (eg emacs, xdvi and an xterm), while at the same time you might be using netscape and pine and keep those on another desktop. Fvwm starts with four desktops, but you can change this. It is also possible to have windows which follow you around on all desktops. Such windows are called sticky.

As well as real desktops fvwm has a virtual desktop feature. The idea of this is that the desktop is larger than the screen (usually twice as large) and you move to other parts of it by pushing the mouse pointer against the edge of the screen. I hate this feature, and turn it off (see Section 4). Others love it.

The Pager

The Pager resides in the bottom right hand corner of the screen and is a miniature view of all of your desktops. You can use the pager to move between the desktops by clicking on the relevant one with mouse button 1. You may move windows to a different desktop by dragging them across the Pager with button 2.

GoodStuff

This is a module of #1 which provides some useful buttons to start up different programs. By default it is combined with the pager. It is simple to use. The buttons are in a line along the top, and the pager is below it. To use a button you click on it with button 1. Clicking on the bomb button will bring up a skull and crossbones in place of the mouse pointer. You can position this over a window you want to get rid of, and click with button 1. Alternatively, clicking on the math button will bring up a list of math applications you can use; select one by clicking on it.

Menus

Most of the features of fvwm may be accessed via menus. There are several ways of viewing these menus. The standard method is to position the mouse cursor over the background and hold down one of the mouse buttons. You can then move the highlight to one of the selections, and release. Typically menu 1 (on button 1) brings up a list of applications which may be launched, menu 2 contains a list of window operations and menu 3 a list of programs which you are running. You can bring one to the foreground (and move to the right desktop if it is on a different one) by selecting it. Clicking on the left title button with any mouse key also brings up menu 2.

Menus may also be bound to other objects, usually buttons on title bars of windows, buttons in the GoodStuff module or function keys.

The Mouse

We have already discussed how to use the mouse to move windows and bring up menus, and we have assumed without stating it, that button 1 refers to the left button, button 2 the middle, and button 3 the right. Another use is in copying and pasting text between certain applications. This is very easy with fvwm. You position the cursor at the start of the text, and hold down (not click) button 1. While holding down the button, move the cursor to the end of the text, and release the button. The text should then be highlighted. You can copy the text by clicking button 2.

This process is best understood by experimenting. However there is one thing to bear in mind: in an application where you cannot move the cursor with the mouse (such as pine or xterm) any text will be pasted to the text cursor, regardless of where the mouse pointer is.

Running Programs

Starting a new program

We have already discussed one method of starting a new program: bring up a menu with the desired program and click on it. Another method is to type the name of the program, followed by an ampersand (ie. netscape &) in a terminal window. The ampersand enables you to continue using the terminal window while the program is running. When the program starts it will either position itself automatically, or else you will see a frame with the top left corner at the mouse pointer. Move the frame as required and click with button 1.

Command line options

Many X clients allow you to specify X resources when you run them. An X resource is some setting which the X server controls, for example the positioning and size of a window, the font and the title. To start up netscape at the top right corner of you screen with size 760x800 you would type:
netscape -geometry 760x800-0+0 &
There are many X resources which may be specified; to find out what they are read in the manual pages of either X or the application. These are the same as the information in your .Xdefaults file.

Two more examples which I use a lot:

emacs -fn 9x15bold -T Emacs -geometry 80x40-0+0 &
xterm -T "Xterm" -geometry 80x25-10-10 -sb -sl 500 -j -ls -fn 10x20 -iconic &
The first starts up emacs in the top right corner of the screen, under the title, ``Emacs'' with the 9x15 bold font. The second starts a terminal window 10 pixels from the bottom and 10 pixels from the right of the screen with size 80 columns by 25 rows. The options after the geometry are in order: use a scroll bar; save the last 500 lines; use jump scrolling; start up with a login shell; use font 10x20 and the last option leaves the window as an icon until you click on it.

Starting a vt100 program

Many programs are not written for X but run in a terminal window. However you may want to have a new window for your program. This may be done with the -e option:
xterm -T Pine -e pine &
will start up pine in a new xterm window. There are two things to remember with this option. It must be the last option in the line, and when the program finishes the window will disappear.

Some useful programs

Xman
A man page browser; xman
Xcalc
A calculator; xcalc
Xbiff
A mail check widget. It lights up and beeps when you have new mail; xbiff
Xload
A graphical display of the load on your machine; xload
Top
A display of the top processes on your machine; xterm -e top
Xftp
An X front end for the ftp program; xftp or ftptool
Clock
Analogue clocks; xclock and oclock

Customizing the Windows Manager

As we have already mentioned, fvwm uses three files: .fvwmrc, .xsession, and .Xdefaults. This section will give some ideas about how to customize these for yourself.

The .Xdefaults file

This file contains information about your preferences for various applications. When you run a new application it looks in this file to see if there is anything it should use and then obeys it if possible. Each application has its own set of defaults and will use these if you don't set any. There is no single system wide .Xdefaults file so you need to create your own. The file is just a list of resources which are specified as strings of the form
appname*subname*subsubname...: value
By convention, the application name is the same as the program name, but with the first letter capitalized (e.g. Emacs). Here is a selection from mine:
Xterm*vt100*font: 10x20
Xterm*saveLines: 2000
Xterm*scrollBar: true

Emacs*Background:                       WhiteSmoke
Emacs*cursorColor:                      Red3
Emacs*menubar*Font:   -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso8859-1
Emacs*menu*Font:      -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso8859-1
Emacs*popup*Font:     -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso8859-1
Emacs*font:                             9x15bold
Emacs*geometry:                         80x35+180+0
Emacs*region*attributeBackground:       lavender

Netscape*Navigator*geometry:            760x860-0+0
Most of this is fairly easy to work out. The first three lines ensure that all my terminal windows use the 10x20 font, with 2000 lines saved and a scroll bar. Most of the other settings make sense, except for the last emacs one. This (together with a setting in my .emacs file) means that when I select a region it is colored lavender.

If you don't want to create your own then you can copy ones from various people in the department by typing for example:

cp ~rpjudd/.Xdefaults ~/.Xdefaults
You should take care that you don't put contradictory information in this file, although if you do it will just get ignored. Another thing which you need to bear in mind is that some applications are very picky about the way you specify the resources. Emacs is one of these. If you look in my defaults file you will see that in some places there are periods instead of asterisks:
emacs*menubar.foreground:       Lavender
emacs*menu*Foreground:          Lavender
These two lines control different resources and each one has to be in this form. Thus, if at first it seems the resource you specify doesn't take effect then it may not be in the correct format.

Once you have created your defaults, you need to tell the X server about them. You can do this by either logging out and back in again, or with the command:

xrdb -load ~/.Xdefaults

For further information on which resources may be specified look in the man pages for X (towards the end) for general resources. For a particular application look in its man pages, and also in the defaults file (if it exists) for the application. These files are in the /usr/lib/X11/app-defaults/ directory.

The .xsession file

This is the first file the X server looks at when starting your X environment. Its main job is some bookkeeping and to tell the server which windows manager to run. A typical .xsession file might look like
#!/bin/sh

if [ -f $HOME/.Xdefaults ]; then
  xrdb -load $HOME/.Xdefaults
fi

# Put other commands here, eg xclock, xterm etc.
       xclock -geometry +0+0 &
       xterm -geometry +0-0 &
       xterm -geometry 80x5+0+0 -C -ls &
       fvwm
The first line says that this is a shell script to be executed by the shell. The if ... fi statement checks to see if you have a defaults file, and if you do it loads it, just as we saw above. The next lines start up some initial applications, and then run fvwm. Pay careful attention to the ampersands. Every line containing an application to be run, except the last, must end with an ampersand; the last line cannot end with one. This is so that all but one application runs in the background, while fvwm runs in the foreground. Thus to log out from your X Windows session you need to end fvwm with the exit command in the menu on button 1.

If you would rather end your X session by typing control-D or logout in a terminal window then swap the last two lines:

# Put other commands here, eg xclock, xterm etc.
       xclock -geometry +0+0 &
       xterm -geometry +0-0 &
       fvwm &
       xterm -T Logout -geometry 80x5+0+0 -C -ls
To log out you would use the window titled ``Logout''.

The .fvwmrc file

The system default file for this is /usr/lib/X11/fvwm/system.fvwmrc. It is a very long and at times complicated file, and there isn't enough space to go into it in detail here. Do not despair, however. The file itself contains copious comments explaining what is going on. If you want to customize it then copy it to your home directory:
cp /usr/lib/X11/fvwm/system.fvwmrc ~/.fvwmrc
and then open the file in a text editor. Then read through the comments and experiment with changing things. Once you have made some changes, save the file and then restart fvwm to make the changes take effect. Rather than logging out and back in again, select the Exit Fvwm option in the menu on button 1. This will bring up a submenu; select Restart Fvwm. If the manager doesn't like the changes you made it will probably just ignore them.

We will discuss some parts of this file, to give you an idea. The first thing I changed were the fonts. I was going blind trying to read the menus so I changed the lines:

# Now the fonts - one for menus, another for window titles, another for icons
#Font                   -adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*
Font                    -*-times-medium-i-*-*-*-120-*-*-*-*-*-*
WindowFont              -adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*
#IconFont               -adobe-helvetica-medium-r-*-*-11-*-*-*-*-*-*-*
IconFont                fixed
to give me larger fonts:
# Now the fonts - one for menus, another for window titles, another for icons
Font                    -adobe-helvetica-medium-r-*-*-18-*-*-*-*-*-*-*
WindowFont              -adobe-helvetica-bold-r-normal--14-*-*-*-*-*-*-*
IconFont                -adobe-helvetica-bold-r-normal--18-*-*-*-*-*-*-*
Note that the # symbol means that a comment follows. Everything after will be ignored.

For a (more than) complete list of fonts type the command xlsfonts | less in a terminal window.

The virtual desktop feature is controlled in these lines:

###########################################################################
# Set up the virtual desktop and pager

#set the desk top size in units of physical screen size
DeskTopSize 2x2
To make the desktop the same size as the screen change the last line to:
DeskTopSize 1x1
Obviously you may also increase the size of the desktop.

The next important item is the start up function. This is a list of applications to run when fvwm starts. You can put them all here instead of in your .xsession file if you want. The system file has everything commented out except for:

Function "InitFunction"
        Module  "I"     GoodStuff
EndFunction
This line runs the GoodStuff module which we discussed in Section 2.4. The settings for this are lower down in the file. You can put anything you like at this point. Here is mine:
# Stuff to do at start-up

Function "InitFunction"
  Exec    "I"   xsetroot -bitmap misc/comet3.xbm &
  Exec    "I"   exec emacs -geometry 90x49-0+0 -fn 9x15bold -iconic&
  Exec    "I"   exec xclock -geometry 100x100+7+0 &
  Exec    "I"   exec xload  -geometry 100x100+7+110 &
  Exec    "I"   exec xbiff  -geometry +7+220 &
  Exec    "I"   exec xterm -fn 10x20 -geometry 80x30-10-10 -T Pine -e pine &
  Module  "I"   FvwmWinList
  Module  "I"   FvwmPager 0 3
EndFunction
The first line changes my background to a pretty picture, the next five lines we have already discussed what they do, although the format is different here. When you add things you must take care to follow the same format. The last two lines start up a list of windows and the Pager, respectively. The window list is what I use instead of icons. It is simply a list which I can click on to switch to an application. The same list appears in the menu in button 3.

The last thing I will mention is how to write the menus which are bound to the mouse buttons. This is what the default looks like:

# This menu will fire up some very common utilities
Popup "Utilities"
        Title   "Utilities"
        Exec    "GNU Emacs"     exec emacs &
        Exec    "Xterm"         exec xterm  &
        Exec    "Netscape"      exec netscape  &
        Exec    "Xfig"          exec xfig &
        Exec    "Top"           exec rxvt -T Top -n Top -e top &
        Exec    "Xman"          exec xman &
        Exec    "Xmag"          exec xmag &
        Nop     ""
        Popup   "Modules"       Module-Popup
        Nop     ""
        Popup   "Exit"  Quit-Verify
EndPopup
The format is similar to the start up function. Anything you add must follow this. Compare this with the menu on button 1. The option starting with Exec will run programs, while the Popup options bring up submenus. You can write your own submenus similarly. The Nop command just gives you a horizontal line.

Lower down in the file you will find the sections on binding commands and menus to the mouse, the function keys, and the title buttons, and on the defaults for the modules such as the Pager and GoodStuff.

I recommend that you copy the system file and then compare it with other people's. However this file is quite complicated and there are a lot of dependencies within it which are not obvious. You should not just copy someone else's file and use it, because it will probably not work. Mine, for instance, is set up for a particular screen size, and bits of it are incompatible with the standard one. Instead you should make small changes and see what effect they have, then keep going.

Miscellaneous

Remote display

Sometimes we need to use an X client which needs to be run from another machine. For example you may be logged in to marie and want to run xmaple from arthur. If you just try to rlogin to arthur and then type xmaple then most likely the command will fail with the message
Error: Can't open display:
This happens because xmaple is trying to open a window on arthur but you are not on that machine. To fix this you must do two things:
  1. Tell arthur to display to your display
  2. Ask marie to accept input from arthur
This is accomplished with the following:
  1. First find out the name of your display (that is the name of the terminal that marie is sending the display to). In a terminal window of marie type echo $DISPLAY. You should get a response like bw3.ma.utexas.edu:0.0; if you just get a blank line then type who and look for your username:
    rpjudd      ttyqa   Sep 17 13:16   (bw3.ma.utexas.ed)
    The last item will be your display (hopefully). It may get truncated, but the important part is bw3. In arthur type
    export DISPLAY=bw3:0.0
    or
    setenv DISPLAY bw3:0.0
    depending on whether your shell is Bash or C-shell respectively. To find out which you have type echo $SHELL. If the answer is /bin/bash then you have the Bash shell, while /bin/csh and /bin/tcsh are versions of the C-shell which work the same in this regard.
  2. In marie type
     
    xhost arthur
    to which marie will reply
    arthur being added to access control list.
You may then run any X client from arthur and display it on your monitor.

The only tricky part of this is working out your display. If you are at the console of a computer such as marie (ie. the computer itself is in front of you) then the display is called marie:0.0 (this also applies to the PCs). Otherwise, you are probably using an NCD xterminal, and you need to know its name. This will either be bwnn.ma.utexas.edu or colornn.ma.utexas.edu where nn is some number.

Running Emacs

Emacs is a very large program; it is slow to start up and takes up a lot of memory. This is deliberate, a feature of emacs rather than a bug. However to prevent this from becoming a problem emacs must be used correctly. The idea is that you run emacs only once, when you first start your windows session. Once started, if you are not using it then leave it in the background. This is much more efficient than closing emacs and then starting it up again.

When you want to edit a different file you have two options. You can either use the same buffer and just open the file with the commands C-x C-f and then swap between files (buffers, actually) with C-x b. The other option is to create a new frame. This will bring up a new emacs window, but it will be the same copy of emacs and thus will take a lot less memory and start faster. You can then open the file in the new frame. To get the frame either use the Make New Frame option in the Files menu in emacs or use the command C-x 5 2.

About this document ...

Using the X Window System

This document was generated using the LaTeX2HTML translator Version 96.1 (Feb 5, 1996) Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.

The command line arguments were:
latex2html -split 0 xwindows.tex.

The translation was initiated by Robert P. Judd on Tue Sep 17 15:31:33 CDT 1996



©1996 Robert P. Judd
Tue Sep 17 15:31:33 CDT 1996