Computer Laboratory

1. Configuration of twm

Twm is a window manager for the X Window System. It provides titlebars, shaped windows, several forms of icon management, user-defined macro functions, click-to-type and pointer-driven keyboard focus, and user-specified key and pointer button bindings. twm is configured via a resource configuration file, .twmrc, which determines behaviour in response to key and button events, and general appearence. (The only resource - entry in a .Xresources file - used by twm is bitmapFilePath for a colon-separated list of directories to search when looking for bitmap files.)

See the twm man page for full details.

Twm startup files are logically broken up into three types of specifications: Variables, Bindings, Menus.

1.1 Variables

Many of the aspects of twm's user interface are controlled by variables that may be set in the user's .twmrc file. Some of the options are enabled or disabled simply by the presence of a particular keyword. Other options require keywords, numbers, strings, or lists of all of these.

The variables section must come first and is used to describe the fonts, colours, cursors, border widths, icon and window placement, highlighting, autoraising, layout of titles, warping, and use of the icon manager.

Lists are surrounded by braces and are usually separated by whitespace or a newline. For example:

AutoRaise { "emacs" "XTerm" "Xmh" }

There may be a section here to set colours, eg

Color
{
    BorderColor "slategrey"
    DefaultBackground "maroon"
    DefaultForeground "gray85"
    TitleBackground "maroon"
    TitleForeground "gray85"
    MenuBackground "maroon"
    MenuForeground "gray85"
    MenuTitleBackground "gray70"
    MenuTitleForeground "maroon"
    IconBackground "maroon"
    IconForeground "gray85"
    IconBorderColor "gray85"
    IconManagerBackground "maroon"
    IconManagerForeground "gray85"
}

1.2 Bindings

The bindings section usually comes second and is used to specify the functions that should be invoked when keyboard and pointer buttons are pressed in windows, icons, titles, and frames.

After the desired variables have been set, functions may be attached to title buttons and key and pointer buttons. Title buttons may be added from the left or right side and appear in the titlebar from left-to-right according to the order in which they are specified. Key and pointer button bindings may be given in any order.

Key and pointer button specifications must give the modifiers that must be pressed, over which parts of the screen the pointer must be, and what function is to be invoked. Keys are given as strings containing the appropriate keysym name; buttons are given as the keywords Button1-Button5, with this syntax:

button-or-key= modlist : context : function
The modlist is any combination of the modifier names shift, control, lock, meta, mod1, mod2, mod3, mod4, or mod5 (which may be abbreviated as s, c, l, m, m1, m2, m3, m4, m5, respectively) separated by a vertical bar. The context is any combination of window, title, icon, root, frame, iconmgr, their first letters (iconmgr abbreviation is m), or all, separated by a vertical bar. The function is any of the f. keywords described in the man page. For example:
Button1 = : root : f.menu "TwmWindows"
Button1 = :title|frame    : f.function "move-or-lower"
The second line is an example of a user-defined function. It is actually a call to a function f.function followed by a string name. The definition of the user-defined function must contain this name and a list of other functions to execute. For example:
Function "move-or-lower" { f.move f.deltastop f.lower }
The Menus section gives any user-defined menus (containing functions to be invoked or commands to be executed).

Functions may be grouped and interactively selected using pop-up (when bound to a pointer button) or pull-down (when associated with a title-button) menus. Each menu specification contains the name of the menu as it will be referred to by f.menu, optional default foreground and background colours, the list of item names and the functions they should invoke, and optional foreground and background colours for individual items. The syntax is as follows:

Menu "menuname" [ ("deffore":"defback") ]
{
 string1 [ ("fore1":"backn")] function1
                    .
                    .
                    .
 stringN [ ("foreN":"backN")]     functionN
}
For example:
menu "Preferences"
{
"Preferences"   f.title
"Bell Loud"     !"xset b 7&"
"Bell Normal"   !"xset b 3&"
"Bell Off"      !"xset b off&"
}
Here the optional colours have been left out. f.title simply specifies a text title for the menu. The expression !"xset b 7&" (ie ! followed by a string) is an abbreviation for f.exec "xset b 7&".

1.4 Icons

In the default interface, windows are iconified by clicking (pressing and then immediately releasing) the left titlebutton (which looks like a Dot). Conversely, windows are deiconified by clicking in the associated icon or entry in the icon manager, if present. An icon manager is a window that contains names of selected or all win- dows currently on the display. In addition to the window name, a small button using the default iconify symbol will be displayed to the left of the name when the window is iconified.

The ShowIconManager variable indicates that the icon manager window should be displayed when twm is started. It can always be brought up using the f.showiconmgr function.

The Icons variable specifies a list of window names and the bitmap filenames that should be used as their icons. For example:

Icons
{
 "XTerm""xterm.icon"
 "xfd" "xfd_icon"
}