X_WINDOW_DISPLAY contains a discussion and some examples of the use of the X Window DISPLAY variable.
This discussion is not for X Window Programmers, but for the unfortunate people who need to run a program that uses the X Window system so that a "remote" program can display graphics "locally".
We will take xeyes as our typical X Window program. This very silly program simply pops up an image of a pair of eyes, which follow the location of the mouse on the screen.
You should try to run this program locally, by typing
xeyes &The ampersand at the end of the command means that the terminal doesn't wait for xeyes to terminate, but gives you a new command prompt immediately.
Assuming this command worked, we will now try to make it a little mysterious. The xeyes command starts up on your local machine, but it then decides where to put the eyes, that is, whose computer is going to get the picture. This computer screen is the (server) display.
If we think of the display as a variable, X Window has a default setting for the display, namely, the screen on the computer where X Window is running. The user can change this by setting the evironment variable called DISPLAY.
The manner for interactively setting this variable depends on your shell. For the Bourne Shell, the Korn Shell, and BASH, the form of the command to set the variable might be:
export DISPLAY=joe.math.vt.edu:0while for the C and T shells, it would be
setenv DISPLAY joe.math.vt.edu:0
The value of DISPLAY has two parts, separated by a colon:
You can determine whether this environment variable has been set, and its current value, by typing
echo $DISPLAYIf nothing prints out, then you have not set the DISPLAY variable.
Now DISPLAY gets interesting when you use an xterm to log into another system where you want to run an X Window program. The remote X program needs to know that its output should be sent to the screen on your home machine. The program is going to find out where it should try to send the graphics information, perhaps by reading the value of the DISPLAY variable as it is set on this remote machine.
The user could try to set the value of DISPLAY on the remote machine, but there are better options. In particular, the ssh command allows a -X which tells the remote machine (the one you're logging into) where the DISPLAY is on the local machine. And if you do a second ssh from the remote machine to an even more remote machine, but again include the -X switch, even the very remote machine will know how to send X Window graphics data back to your local screen.
MDDISK is a C program which displays a molecular dynamics simulation of a fluid as a collection of soft disks, using X Windows and Motif.
PLTMG_SINGLE is a FORTRAN77 program which carries out a finite element calculation, and uses the X Window library for display.
SHOWME is a C program which uses the X Window library to display triangulatons.
XFIRES is a C program which simulates the occurrence of fires and regrowth in a forest, displaying the results using X Windows.
XGED is a C program which can edit graphs visually; it uses the X Window library to display the graph, and to detect the user's input.
XISING is a C program which simulates the variation in ferromagnetism in a material, displaying the results using X Windows.
XWAVES is a C program which simulates the behavior of solution of certain forms of the wave equation, displaying the results using X Windows.
X_WINDOW is a C++ example directory which demonstrates some simple uses of the X Window library.
You can go up one level to the EXAMPLES page.