x_window_test C++ programs which demonstrate the use of the X Window system which allows the creation and control of windows on a remote computer terminal.

You might imagine that the X Window library is a simple set of routines that any user can call to set up interactive graphics. It isn't. The X Window library is complicated and cumbersome. The beginner is advised to take a working copy of an X Window program and proceed slowly and cautiously to try to understand how it works.

On the other hand, there are many useful programs available which use the X Window library. In that case, the user may only need to know a few facts about X Window programs in order to have a satisfactory experience.


If you do run an X windows program, it's often the case that the program is running on a "big" machine (the server) that you've logged into from your "home" machine (the client). The big machine is going to want to display graphics on your home machine, but this will not happen automatically! For this to actually happen properly, two things must be true:

  1. The "home" machine must give permission to the "big" machine to mess with its screen.
  2. The "big" machine must know where to send the graphics.

If you are lucky, your terminal software may automatically have set up the permissions and addresses for you. In particular, if you are using ssh, you should be able to get things to work nicely, once you enable X11 forwarding. Running ssh on a PC means you may have to go into a menu in order to enable this. On a Unix machine, you need to have an ssh config file; if it's not in the right place, you can get a copy and put it in the right place by the command:

        cp /etc/ssh/ssh_config $HOME/.ssh/config
and then make sure that your config file includes the line
        ForwardX11 yes

If your terminal software does not set up permissions for you, you may need to enter specific commands to make this happen.

  1. In order for your "home" machine to allow the "big" machine to send graphics to its screen, you may need to type the following command on your home machine:
    xhost + big_machine
    where big_machine is the Internet address of the big machine.
  2. To tell the "big" machine where to send the graphics, type a command like this on the big machine:
    setenv DISPLAY home_machine:0.0
    where, again, home_machine is the Internet address of your home machine, where you want the graphics to appear. If you don't know the Internet address of your home machine, you might try the command
    hostname --long

Assuming that you are able to figure out how get an X Window program to run, you may also be interested in being able to predefine certain properties of your X Window session. These can include preferred fonts, screen size, or the shape of the icon. Such attributes can be controlled by placing a file called .Xdefaults in your home directory. This file is automatically read by an X Window program, and the information found in there may be used to customize the program to your requests.


The computer code and data files made available on this web page are distributed under the GNU LGPL license.


x_window_test is available in a C version and a C++ version.

Related Data and Programs:

SHOWME, a C program which uses the X Window library to display triangulatons.

XBOIDS, a C program which simulates the behavior of a flying flock of animals, displaying the results using X Windows, by Conrad Parker.

XISING, a C program which simulates the variation in ferromagnetism in a material, displaying the results using X Windows.

XWAVES, a C program which simulates the behavior of solution of certain forms of the wave equation, displaying the results using X Windows.


  1. Paul Asente, Ralph Swick,
    X Window System Toolkit,
    Digital Press, 1990.
  2. Theo Pavlidis,
    Fundamentals of X Programming: Graphical User Interfaces and Beyond,
    Kluwer Academic/Plenum Publishers, 1999
  3. Robert Scheifler, James Gettys,
    X Window System, Complete Reference to Xlib and Protocol,
    Digital Press, 1990,
    ISBN: 0139720502,
    LC: QA76.76.W56.S345.
  4. Douglas Young,
    X Window Systems Programming and Applications with Xt,
    Prentice Hall, 1989.
  5. Douglas Young,
    Object Oriented Programming with C++ and OSF/Motif,
    Prentice Hall, 1995.

Examples and Tests:

FAREWELL makes a window with a text message, which is dismissed when the user clicks on the mouse.

HELLO prints out the string "Hello, world!" in a window.

GOODBYE makes a window with a pushbutton. When you push the button, it exits.

MEMO prints out its command line arguments in a text window.

You can go up one level to the C++ source codes.

Last revised on 12 May 2006.