VTWM Tutorial

Created by Ian Kelly and Nate Sommer

Return to contents


Part 3 - Advanced VTWM concepts


1) Restoring Corrupted Configuration Files

The rest of this section will teach you how to edit your configuration files to customize your VTWM desktop. Some of these files can be temperamental, and if an error is made in one it may prevent you from logging in to VTWM, so first we're going to learn how to repair errors.

First, before editing one of these files, you should always back it up first. This can be accomplished with a command like cp .foo .foo.bak, where .foo is the config file you want to edit, and .foo.bak is the name of the file you want to back it up in. To restore your file, you would then type into the shell cp .foo.bak .foo. In the event that you don't back-up your configuration files before editing them and then have problems, you can always find copies of the default files in the /etc/skel directory on Quark.

In the event that you can't log in to VTWM, you may have a difficult time restoring your configuration files, however. To fix this, sit at any of the computers in the ACL lab, and instead of logging in at the graphical prompt, press Alt-Ctrl-F1. This keystroke will take you out of X windows to a text-based "pseudo-terminal", where you should be able to log in without a problem. Once logged in, restore your config files as described above, then log out. Finally, press Alt-F7. This will return you to the graphical login prompt, so that you can log in normally again.

2) Editing Your .xsession

There exists a file in your home directory named .xsession. Because the name of this file begins with a period, it will normally only be displayed in the output of the ls command when you specify the -a flag, as in ls -a. This file is a shell script that is executed every time you log in to X windows. This means that it can be used to customize settings such as what programs run automatically at startup, what your background looks like, and the keyboard repeat rate. By default, your .xsession looks something like this:

#!/bin/bash
#
# .xsession - startup script
#  Default version for ACL users
#  Written Aug/2002 --- jrogers
#

xsetroot -solid "#356390"

# xscreensaver
xscreensaver-command -exit
xscreensaver -nosplash &

#xclock -digital -geometry 282x46+996+0 &
xclock -digital -geometry 282x46-0+0 &

MANPATH=${MANPATH:-/usr/man:/usr/local/man:/usr/share/man:/usr/X11R6/man} xman -geometry 172x77-161+58 &

NO_XTERM_PROMPT=1 xterm -geometry 80x24+9+40 -sb -n "Little Shell" -title "Little Shell"  &
NO_XTERM_PROMPT=1 xterm -icon -geometry 80x56-0+24 -sb -n "Big Shell" -title "Big Shell"  &

exec vtwm

Lines beginning with a # character are comments. This .xsession starts four programs automatically: xclock, xman, and two xterms, one little and one big. The portions of the lines that read NO_XTERM_PROMPT=1 and MANPATH=${MANPATH:...} specify environment variables to be passed on to the following program. For most purposes, these can be safely ignored. However, notice that each of these lines also contains a & character at the end. The & is very important: without it, the script will wait for the program to end before continuing, and your desktop will fail to load properly.

You can add a program by adding a line for it in the script. However, be aware that the exec vtwm line must be the last line in the script. Try adding this line to your .xsession:

emacs &

This will cause emacs to start automatically each time you login to VTWM. You can often configure the placement of individual windows, as well, using the -geometry argument. For example, notice that the xclock line of the default .xsession include -geometry 282x46-0+0. This tells X11 that the xclock window should initially be sized at 282 pixels wide and 46 pixels high, and that it should be placed 0 pixels from the right side of the screen and 0 pixels from the top of the screen. Try adding a -geometry argument to the emacs line, and fiddle with the numbers to see what kind of results you get.

Another command used in the sample .xsession is xsetroot -solid "#356390". xsetroot is a simple command that is used to change the background of your desktop. It can be used to set solid colors, as in the sample .xsession, tiling bitmaps, or plaid patterns. As an example, try typing into your shell xsetroot -mod 5 5 -fg "#ff0000" -bg "#00ff00" for a red-on-green plaid pattern. You may have figured out by now that the string in quotes is a color code. Each digit of the code (apart from the required #) is a hexadecimal digit that can fall in the range of 0-9 or a-f. The first two digits indicate the intensity of the red component of the color, the second two indicate the intensity of the green component, and the last two represent the blue component. Try playing with different colors and see what you can come up with. For more information on xsetroot, type man xsetroot into the shell to read the manual page. More complicated backgrounds using more than two colors can be set using the xsri command. For more information, try typing xsri --help into the shell.

Another setting that you may want to adjust in your .xsession is the autorepeat rate of your keyboard. The command for this is xset r rate 660 25. The first number specifies the delay in milliseconds before autorepeat begins, and the second number specifies the number of repeats per second. Therefore, the example command would cause the keyboard to autorepeat 25 times per second after delaying for roughly two thirds of a second. Try playing with these numbers until you come up with something you like (although be careful not to set the delay so low that you can't type single characters!), then add the command to your .xsession to make the change permanent.

3) Editing Your .vtwmrc

Another file in your home directory that can be customized is .vtwmrc. This file contains resources that are used specifically by VTWM. A great number of settings can be changed here, and complete documentation can be found at the VTWM home page, but we will only cover some basic adjustments here. First, take a look at the part of the file that reads:

Color
{
        DefaultBackground               "#356390"
        DefaultForeground               "gray85"
        BorderColor                     "grey70"
        BorderTileBackground            "gray60"
        BorderTileForeground            "gray60"
        DoorBackground                  "#590000"
        DoorForeground                  "gray85"
        TitleBackground                 "#590000"
        TitleForeground                 "gray85"
        MenuBackground                  "#590000"
        MenuForeground                  "gray85"
        MenuTitleBackground             "gray70"
        MenuTitleForeground             "#590000"
        IconBackground                  "#590000"
        IconForeground                  "gray85"
        IconBorderColor                 "gray85"
        IconManagerBackground           "#590000"
        IconManagerForeground           "gray85"
        VirtualBackground               "#590000"
        VirtualForeground               "black"
        DesktopDisplayBackground        "grey60"
        DesktopDisplayForeground        "grey85"
}

We showed you earlier how to change the background of your desktop using xsetroot. Now we can see how to change the colors of other elements of your desktop. For example, the background color used in the menu system can be changed by modifying the color value associated with MenuBackground. Try playing around with these values to set your desktop colors as you please. In order to test a change, you do not need to log out and then back in. Instead, save the .vtwmrc file, then select the "Operations" submenu from the VTWM main menu, and choose "Restart .vtwmrc", which is located at the end of the menu. This will cause VTWM to reread the .vtwmrc file and apply any changes.

Now let's take a look at editing menus. The .vtwmrc file contains several menu definitions, each starting with the set phrase menu "menuname", followed by a definition block. Find the definition for the menu named "apps", which is listed below.

menu "apps"
{
        "  Applications  "      f.title
        "emacs"                 f.exec "emacs &"
        "xterm"                 f.exec "xterm &"
        "gdb"                   f.exec "xterm -n gdb -title Gdb -sb -sf -e gdb &"
        ""                      f.separator
        "Calculator"            f.exec "xcalc &"
        "RPN Calculator"        f.exec "xcalc -rpn&"
        "Xfig"                  f.exec "xfig &"
        ""                      f.separator
        "Netscape"              f.exec "netscape http://www.cs.earlham.edu &"
        ""                      f.separator
        "Man browser"           f.exec "xman &"
        "Digital clock"         f.exec "xclock -digital&"
        "Analog clock"          f.exec "xclock -analog &"
        "Fancy clock"           f.exec "xdaliclock &"
        "Load monitor"          f.exec "xload &"
}

You may recognize this as being the definition for the menu you get when you select "Applications" in the main menu. This shows you how you can add arbitrary programs to your menus. For example, the second line of the menu adds an entry named "emacs" which, when selected, executes the command "emacs &", effectively launching emacs. Note again the & character at the end of the command, which again is not optional. Try adding an option to start Maple in the calculator section of the menu. The entry for this should read "Maple" f.exec "xmaple &".

Your .vtwmrc file has a plethora of other options that can be changed. Try changing others to observe the results, and be sure to read the full documentation at the VTWM home page!

Return to contents


© 2002-2004 Earlham College Computer Science Department
Last updated: