X Window System

From FarmShare

Revision as of 11:02, 21 February 2012 by Chekh (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This page is from like 10 years ago, you probably don't want to read it except to reminisce.

Contents

Introduction

The X Window System is an interactive graphical computing environment originally developed at MIT. This document describes how to use and customize the X Window System on Stanford's shared UNIX workstations. Some of the commands described here may work differently on some UNIX workstations.

You must have a SUNet ID to use Stanford's shared UNIX workstations. For more information about SUNet IDs, see the SUNetID web site. For more information about the centrally managed, shared UNIX workstation systems, see UNIX Computing Resources at Stanford.

To take advantage of the more advanced concepts in this document, you should be familiar with basic UNIX commands (e.g., cp and ls) and a UNIX text editor (e.g., pico or emacs).

Window systems

A window on a workstation is a visible entity for displaying interaction between the user and the workstation. For example, if you want to use a standard UNIX shell (command interpreter) on the workstation, you might create a window into which you can type shell commands, and in which shell responses are displayed. If you are developing software, you might create several shell and editor windows displayed side by side on the workstation to save time jumping from one point to another in your program. The typical application has a single rectangular window displayed on the screen. However, some applications open multiple windows and some window systems permit arbitrarily shaped windows (not just rectangles).

A window system is a collection of software that makes it easy for you to take full advantage of the graphics and windowing capabilities of a workstation. The window system keeps track of all the applications you are using, what windows are associated with them, and the status of input and output from those applications. Windows may overlap other windows; the window system manages all of this, making sure that the correct portions of window sare displayed and that their contents are redisplayed when they become unobstructed. Most window systems provide an easy way of manipulating windows (e.g., moving them around the screen, changing their sizes, redrawing them, etc.). Since window systems run on computers with graphics capabilities, they usually use icons (pictorial representations of objects) to make the environment easier to use.

The X Window System runs on a wide variety of computers and is available free of charge. It has an open architecture, meaning its internal design and implementation are available to the public. For these and other reasons, "X" is popular in both academia and industry.

Using the X Window system

Starting X

Find an available workstation displaying the login: prompt. If the screen is dark, press the space bar to activate it. Log in using your SUNet ID username and password. If the X Window System doesn't start up automatically, type the letter x (lower case) at the system prompt.

The X Window System can take a few seconds to start up, depending on the type of workstation you are using and how busy the network and file servers are. During this time, the screen will display a gray or blue background pattern. This background is known as the "root" window: the basic window upon which all other windows are displayed. One by one, the following rectangular windows will appear:

  • a digital clock (upper right-hand corner),
  • an email indicator (next to the clock), which indicates whether you have new email
  • a load monitor (next to the mail box), which displays a graph of the work load on your workstation,
  • a Console terminal emulator window (upper left),
  • a generic xterm terminal emulator window (the big one), and
  • an icon for each of the terminal emulator windows (upper left corner).

Getting around in X

Move the mouse around the desktop and watch the pointer move around the screen. Note that the pointer changes shape depending on where it is. Over the root (background) window, the pointer will be shaped like an arrow. Over xterm windows it will change to a vertical bar in order to facilitate mouse positioning when editing text. Other applications use different pointer shapes to suit their own purposes.

The mouse has three buttons: left, middle, and right. If you press a button, the resulting action usually occurs in the window that contains the pointer. See Using the twm Window Manager in X below for examples of mouse button use in X. Note: X has no standards for mouse button functionality. Therefore, each X application may assign completely arbitrary meaning to the mouse buttons when the pointer is within its window. Be cautious when using the mouse buttons!

To practice, move the pointer into the xterm window on the right half of the display. You don't need to press a mouse button before typing (as you would on a Macintosh), because X has a "point to type" interface. Type a simple UNIX command (e.g., ls or who) at the prompt. Your command appears in that window, followed by the UNIX response to it.

Using X termWindows

A terminal emulator (xterm) window acts as though it is a separate terminal with a separate connection to the computer. When you first started X, two xterm windows were created for you: a small console window, and a large generic xterm window. You can use the xterm program to create additional terminal emulator windows. Xterm windows typically run a standard UNIX shell so that you can type UNIX commands in them and get responses from the UNIX system running on your workstation. It is also possible to open a session on another remote computer in an xterm window by using the klogin or ssh commands. (Type man klogin or man ssh for more information about these programs.)

Leaving X

You can exit the X environment by moving the pointer into the Console window and typing exit to terminate the UNIX shell. Some window managers also provide a menu selection for leaving X. After you leave X, double check to make sure that you are logged out of the workstation also. If you are not logged out, type logout in response to the prompt that appears on the workstation screen.

Warning: All windows and their contents are irretrievably destroyed when you exit from the X environment. Be sure to save editor buffers and to logout from remote computer sessions before leaving X.

Using the twm Window Manager in X

About Window Managers

A window manager is a program that allows you to manipulate the windows on your screen. Most window managers also let you control other aspects of the environment and provide a convenient way to start applications. Within the XWindow System, you generally run one window manager at all times. Without a window manager, it can become very difficult to move from one window to another because they usually overlap one another.

The twm window manager is the default on the Leland workstations. It starts automatically when you invoke X. The mwm window manager is another common option.

Using the Main Menus

The twm window manager has three main menus, corresponding to the three mouse buttons. To display the menus, move the pointer to the root (background) window. Press and hold the left mouse button to display the Applications menu, the middle button to display the Window Manipulations menu, and the right button to display the Environment menu. To choose any of the options contained in these menus, move down the menu while still holding down the mouse button. Once your selection is highlighted, release the mouse button and the X environment will respond to your choice.

If there is a box to the right of a menu selection, it indicates that there is a submenu associated with it. To access a submenu, move the pointer to the right along the highlighted area until the submenu appears. Then move to the selection you desire within the submenu and release the mouse button.

Try the following exercises to learn the basics of using the twm window manager.

  1. Redraw the screen.
    Move the pointer into the root window and press and hold the right mouse button to see the Environment menu. Select Refresh Screen and release the button. The menu disappears and everything on the screen is redrawn.
  2. Create a new xterm window.
    Move the pointer into the root window and press and hold the left mouse button to see the Applications menu. Highlight Terminal and display its submenu. Select your favorite color from the submenu and release the mouse button. The menu disappears and a new xterm window appears on the screen. (You will use this window in the exercises in the next section.)

Manipulating Xterm Windows

You can change the physical characteristics of xterm windows to suit your needs at any time. Specifically, you can move them to another part of the screen, change their size, temporarily remove them from the screen by reducing them to an icon, and delete them altogether from the current X Windows session. These options are all available through the Window Manipulations menu, but it is faster to use the buttons on the title bar of each xterm window. Use the xterm window you created in the previous section to practice manipulating xterm windows in the following exercises.

  1. Move a window with the title bar.
    Move the pointer to the title bar (in this case, the rectangle containing the word "xterm") and press and hold the left mouse button. Move the pointer to another part of the screen and release the mouse button. The window is redrawn at the new location.
  2. Resize a window.
    Move the pointer to the button located at the far right of the title bar and press and hold any mouse button. A small box appears at the top left of the screen, displaying the current dimensions (width by height) of the window. Move the pointer past the edge of the window, then to any part of the screen. The numbers in the dimensions box change to indicate the new size of the window. Release the mouse button and the window is redrawn at the new size.
  3. Iconify a window.
    Move the pointer to the button located to the left of the title in the title bar and press and release any mouse button. In this case, the window disappears and an "x" appears in its icon, located at the top left of the screen with the icons for the other xterm windows. If the window were not an xterm window, a new icon would have been created and also placed near the top left of the screen. Click on the icon to restore the window.
  4. Maximize (zoom) a window.
    Move the pointer to the button located to the right of the title in the title bar and press and release any mouse button. The window is redrawn to fill the entire screen. Click on the button again to restore the window to its original size.
  5. Close a window.
    Move the pointer to the button located at the far left of the title bar and press and hold any mouse button. A small menu pops up, allowing you to pick one of two methods to close the window or to change your mind and not close the window at all. Select Close Window and release the mouse button. The window disappears permanently. Sometimes selecting Close Window will not close a window; in this case, select Force Quit. This should close any window, but it does not give the application a chance to clean up after itself. Use it only as a last resort.

    Warning: Closing a window will cause any unsaved work within it to be lost. Do not close a window unless you're sure you're finished with it. Remember also that closing the Console window will automatically close all other windows and end your X session.

The twm window manager can perform many more functions than this document describes. To learn more, practice using all of the functions available in the menus that appeared during the preceding exercises. For more information, see Customizing the twm Window Manager below, or type man twm at the UNIX prompt.

Using X Programs

How to Execute X Programs

There are many application programs written specifically to take advantage of the X Window System's capabilities. Some of these applications can be started simply by making selections from the window manager's menus. However, this is just a short-cut for a few selected applications. In general, you may start X applications just as you would execute any UNIX program: type the command in response to the standard UNIX command prompt. To do this, just move the pointer into an xterm window on your workstation and type the command.

For example, to create a new terminal emulator window, move the pointer into the Console window in the upper-left corner of the screen, type the following command in response to the shell prompt, and press the RETURN key:

xterm &

The ampersand (&) runs the program in the background; without it, the Console window would be "tied up" (unusable) until the newly-started xterm program had been terminated.

Useful X Programs

See the Index of Leland Software page for a list of the applications available through the X Window System.

Customizing your X Windows environment

How X Works

All X software falls into one of two groups: servers and clients. The clients are the applications, tools, and utilities that form the most visible part of the X Window System; this includes window managers, terminal emulators, editors, clocks, load monitors, games, etc.

The X server is the central brain of the X Window System. It controls the interaction between the X client applications and the available resources of the workstation (such as the sound, fonts, colors, and other software resources that the clients might use). Basically, X clients cannot display output on the screen or ring the bell independently; they must ask the server to do the settings for them. Likewise, all of your input, such as moving the mouse and typing on the keyboard, is received first by the X server and then interpreted to the appropriate client.

The server and the clients can be customized in a variety of ways. Server customizations tend to affect the overall workstation environment. Client customizations usually affect the behavior of specific applications and their windows.

What Happens at Start-up

Following is a step-by-step description of what happens when you start up the X Window System on a workstation that is part of the Leland Systems. Each of these steps provides opportunities for you to customize certain aspects of your X environment.

  • For SUN or HP, the xprogram lays the groundwork for starting the X Window System (looking fordisplay devices, checking your search paths, etc.), and then calls xinit.
  • The xinit program actually starts up the X Window System by first starting the X server and then running .xsession. The .xsession program begins by running xrdb, the X Resource Database Manager.
  • For SGI, the xrdb program reads the .xresources file to initialize the X Resource Database. This data base describes default settings for a wide range of X applications. For example, it can be used to define default fonts and colors for all X applications, aswell as define special settings for particular applications.
  • The remainder of the .xsession program starts the X client programs that you want running when you first enter the X environment; the default clients include the twm window manager, two xterm windows, the clock, and the load monitor.

How to change Window Managers

Window managers determine the basic look and feel of your X Windows desktop environment. There are multiple window managers installed in the Leland System environment. Some of the popular ones are:

  • twm (default window manager)
  • mwm (Motif window manager)
  • fvwm2 (multiple viewports)
  • fvwm95 (Windows95 look and feel)
  • afterstep (NeXTstep look and feel)

There are two ways to change your default window manager after you find one that you like. Use one or the other, but not both.

1. Add a line to the .cshrc or .login that sets your window manager. Just login to your account and launch pico or emacs or some other text editor to change the file. The line you add should look like this:

setenv WM window-manager

For example, if you would like fvwm2 as your default window manager, you would add:

setenv WM fvwm2

to the end of your .login file.

2. Create your own custom .xsession file. Start by copying the system default .xsession file to your home directory with this command:

cp /usr/pubsw/etc/conf/X/xsession ~/.xsession

then use a text editor to open the .xsession file. Look for this line:

${WM-twm} &

Change twm to whichever window manager you would like to use.

While you're there, you can also edit the .xsession file to change which X clients are started up whenever your begin an xsession.

Changing X Server Options

Type man Xserver to obtain a thorough explanation of the X server. You can use the xset program to change many server options, including bell volume, mouse sensitivity, and screen saving. Some of the more common options are included in the twm Environment menu; for the other options, you can issue xset commands to the shell prompt in an xtermwindow at any time. You can also include xset commands in the .xsession file so that they are executed each time you start up X. Type man xset to get complete documentation.

Changing the Initial Screen Layout

Many people prefer to have several applications started automatically everytime they enter X. This can be done by adding the start-up commands for the applications to the .xsession file. Because .xsession is a standard shell (Bourne shell) script, you can execute within it any shell commands you wish.

If you do not already have an .xsession file in your home directory, issue the following command to obtain a copy of the sample file:

cp /usr/pubsw/etc/conf/X/xsession ~/.xsession

Then use a text editor to edit this file. Be sure to read the comments throughout the sample file; they can help you make changes. Following are some important things to remember when editing your .xsession file:

Execute xrdb before starting the window manager and start the window manager before running any other X applications. The xrdb program affects the behavior of X applications, and the window manager is involved in the creation of windows.

When starting an application, append an ampersand ("&") to its command line. This lets the application run in the background so that the rest of the .xsession program can be executed without having to wait for the application to finish. But do not append an ampersand to the last command of .xsession. If you do, your XWindows session will end immediately.

Customizing X applications

There are several ways to customize X application programs. Most applications accept a variety of command line options when you invoke them. You can also gather option settings into a central resource database file. Some applications even accept option settings from their own specialized initialization files or environment variables. This section describes the most common options used by X applications and how to use them.

Common Options for X Applications

In addition to their own specialized options, most X applications accept a common set of options, including window geometry, fonts, and colors.

Geometry: A window's geometry specifies its size and/or position on the screen. For example, a specification of 100x50+0-0 indicates that the window should be 100 units wide, 50 units tall, and in the lower left corner of the screen (the unit of measurement depends on the application but is usually pixels or characters). Type man X and read the Geometry Specifications section for more information.

Fonts: A font in X is a collection of characters that typically share a common appearance (e.g., the same style, weight, and size). Hundreds of fonts are available; the xfontsel program is a convenient way to browse through them. In xfontsel, the second line below the buttons shows the currently selected set of fonts. Initially all fonts are selected (a "*" is a wildcard meaning that that part of the font name is unrestricted). The first line below the buttons is a set of menus that allows you to specify each part of the font name; this is how you see the different fonts. For example, here is the full font name for an "adobe courier" font withbold, oblique print in 18-point size:

-adobe-courier-bold-o-normal--18-180-75-75-m-110-iso8859-1

Full font names can be rather unwieldy. To relieve some of the hassle of entering the entire font descriptor, you can use wildcards to specify font names. This also saves you trouble if font names change slightly in the future. For example, a good abbreviation for the font shown above is:

  • -courier-bold-o-*--18-*

Type man X and read the Font Names section for more information.

Colors: Some workstations have monitors that can display a wide range of colors. You can specify colors by using common color names such as red, yellow, purple, magenta, and turquoise. There are also more unusual color names such as dark olive green, medium slate blue, and green yellow. The file /usr/pubsw/X/lib/X11/rgb.txt on your workstation contains a complete list of color names. (Color names are not case-sensitive, so red, Red, and RED all refer to the same color.) If you want to see which color actually goes with which color name, type xco to display them on your screen. Type man X and read the Color Names section for more information.

Note that if your work station does not support the exact color that you specify, it displays the color that it does support that is closest to the color you desire. In particular, if you are using a black and white X environment and you specify a particular color, then X uses either black or white in place of the color you specify, depending on the relative brightness of the color.

Changing Options from the Command Line

Most X applications accept a standard set of command line options in addition to their own specialized options. Following are descriptions of some of the more common command line options:

Specify which X server and screen the application should use.

-display display

Specify the size and location of the application's main window.

-geometry geometry

Specify the font to use in the application's window(s).

-fn font

Specify that the application should start up as an icon.

-iconic

Specify the instance name of the application.

-name instance

Specify the application's foreground and background colors.

-fg color, -bg color

Specify the color and width (in pixels) of the window's border.

-bd color, -bw width

For example, to create a new xterm window with a gray background, using a very large font, with 10 rows and 40 columns, placed 15 pixels from the lower left corner of the screen, type:

xterm -bg gray -fn"*-courier-bold-r-*--34-*" -geometry 40x10+15-15 &

For more information on standard options, refer to Common Options for X Applications above or type man X and read the Options section. Each application also has a man page describing the particular command line options that it accepts.

Changing Options Using X Resources

What are X Resources? A resource is simply an option that you can set for some application. Colors, fonts, geometries, and window titles are examples of resources. Resources are specified hierarchically as strings of the form:

name*subname*subsubname...: value

Program resources are organized into groups called classes, so that collections of individual resources (each of which are called instances) can be set all at once. For example, in the xterm program, the instance foreground refers to the color of the text, but the class Foreground also includes the colors of the text cursor and the mouse pointer as well. Each name in a resource specification can be either an instance name or a class name. By convention, class names are capitalized, and instance names begin with lower case letters. For more information about X resources, type man X and read the Resources section.

Specifying X Resources.

There are several ways you can specify resources to be used by X applications. The most common method is to use xrdb, the X Resource Database Manager. You can collect all of the resources you want X applications to use into a single file, and then have xrdb read resource information from this file.

To change the resources for programs you use, first obtain a copy of the sample resource file by typing the following command:

cp /usr/pubsw/etc/conf/X/Xresources~/.Xresources

Then use a text editor to modify .Xresources in your home directory. Read the comments in the file before making major changes. For example, to create a colorful xterm window, use the text editor to add these lines to the .Xresources file:

colorful*Background: black

colorful*Foreground: yellow

colorful*Border Color: plum

colorful*cursor Color: hotpink

colorful*mainMenu*Foreground:tomato

colorful*fontMenu*Foreground: royalblue

The first three resource specifications indicate the default background, foreground, and border colors for the whole application. Note that, while the Foreground class includes the color of the text cursor, the fourth line is also specifying a cursor color. Because the cursor Color instance is more specific than the Foreground class, cursor Color takes precedence. Thus the main window will have yellow text and a yellow pointer, but a pink cursor. Similarly, the last two lines also override the generic foreground specification, causing the text in the menus popped up by the left and right mouse buttons to be displayed in other colors. But since there is no corresponding specification for the menu popped up by the middle mouse button, the text there will still be yellow.

The specifications shown above indicate an application instance name of colorful, so to use these settings, you should exit the text editor and type the following lines at the command prompt:

xterm -name colorful &

Customizing the twm Window Manager

When the window manager program is started, it looks for a setup file that describes its menu layouts, mouse button behavior, etc. You can type man twm for details. Following is a brief introduction to some of the things you can change when you use the twm window manager.

If you do not already have a .twmrc file in your home directory, obtain a copy of the sample file by issuing the following command:

cp/usr/pubsw/X/lib/X11/twm/system.twmrc ~/.twmrc

Then use any text editor to look at and modify the copy of this file in your home directory. The basic settings such as menu fonts and colors should be self-explanatory. Beyond this, the main point of interest is how to change the contents of the window manager menus. Following is part of a sample menu definition similar to the "Window" menu that appears when you move the pointer to the root window and press the left mouse button.

menu "Window" {
  "Window"          f.title
  "Environment..."  f.menu "Environment"
  "Applications..." f.menu "Applications"
  ""                f.nop
  "Move"            f.move
  "Full Size"       f.fullzoom
  "Destroy"         f.destroy
}

menu "Applications" {
  "Applications"    f.title
  "Terminal"        f.exec "xterm &"
  "Mail"            f.exec "xmh &"
  "Emacs"           f.exec "emacs &"
  "Draw"            f.exec "xfig &"
{

Each menu selection consists of the selection name and an action associated with the selection. There are a variety of built-in functions; f.destroy (killwindow) is one example shown above. The f.exec function executes the following string as a shell command. These are enclosed in quotation marks, and have an ampersand (&) as the last part of the command so that the window manager can continue operation while the command is executing.

To add a selection to a menu, just add a line similar to the existing ones. After saving the file in your home directory, tell the window manager to restart itself so that it reads your new .twmrc. To do this, move the pointer to the root window; press and hold down the right mouse button to activate the Environment menu, and move the pointer down to Restart Window Manager. Release the mouse button.

You can be quite creative with window manager set-up files. Type man twm for more information. Also read comments in /usr/pubsw/X/lib/X11/twm/system.twmrc.

Getting help

Troubleshooting

If you type x and don't get a response that you would expect from the XWindow System, you might have some other program, command, or alias named x in your search path.

If you start up the X Window System but are then unable to execute X applications or read X manual pages, you probably have a non-standard .cshrc file that sets your PATH or MANPATH variables statically (i.e., without respect to the existing PATH or MANPATH settings). The problem is that typing x adds XWindow System directories to these variables. If your .cshrc file then overwrites PATH or MANPATH, you have lost access to X files. The solution is either of the following: set these variables in your .login file instead of in your .cshrc file or set these variables relative to their existing values(e.g., set path=($path ~/bin) ) so that you are only adding to the path value, not overwriting it.

If you cannot access any menus, you must restart the twm window manager from an xterm window. In the Console window, type twm & to restart the window manager.

Documentation

Most of the information available for the X Window System is in the form of online documentation. After starting X, just type man topic in an xterm window. Many topics are the names of X programs. In addition, you can type man X (that's an upper case X) to obtain a great deal of useful background information. Finally, each of the files mentioned in What Happens at Start-up above contain comments to help you modify them and learn more about X.

Personal tools
Toolbox
LANGUAGES