Displaying a Window on the Screen

First, let's put up a window. Type the command, 'prolog', into a shell window running under the X window system, and load the ProXL library:

     % prolog
     Quintus Prolog Release 3.5 (Sun 4, SunOS 5.5)
     | ?- [library(proxl)].

You will be greeted with many messages about files being loaded, and finally will get another Prolog prompt. Now let's create a window:

     | ?- create_window(Window, [mapped(true)]),
     Window = window(2376568)

After a few moments, a window should appear on your screen. Some window managers may require you to choose a position for the window.

That's all there is to putting a window on the screen. You will notice that we didn't specify very much. We didn't say how big to make the window, nor where on the screen to put it, nor what color to make it, etc. All these parameters, and many more, are defaulted for us by ProXL. The only thing we did specify was mapped(true). In X, mapping a window makes it visible if its parent window is visible. Since we didn't specify a parent window for the window we're creating, the root window of the default screen is its parent, and the root window is always mapped. So by specifying the attribute mapped(true), we make the new window visible.

The second argument of create_window/2 is a list; this is called an attribute list. We could have put many different attributes in this list, to specify any of the attributes of the window mentioned above as having been defaulted. A complete list of the attributes supported by windows can be found in pxl-win, but for this example we won't need to use very many of them.

We use assert/1 to remember the window we've created so that we can use it later. This is a good idea while you are experimenting with ProXL, but isn't usually necessary in actual programs. Using retractall/1 to initialize the table first is just standard Prolog wisdom, avoiding any problems if this tutorial is run more than once.

Notice that this window is quite small; the default window size is 100 by 100 pixels. If we're going to display a message in this window, we'll need it to be bigger.

     | ?- win(Window),
          put_window_attributes(Window, [size(250,100)]).
     Window = window(2376568)

This makes the window 250 by 100 pixels, more than big enough for our purposes. The call to win/1 gets back the window we just created, and put_window_attributes/2 changes the window's size.

put_window_attributes/2 is much like create_window/2, except that it allows you to specify new attributes for an existing window, and create_window/2 lets you specify attributes for a window to be newly created. We could have specified size(250,100) in the call to create_window/2, if we had thought of it then.

If you try this, one of two things may happen: the window may be changed to the right size, or it may not. The reason is that X allows the window manager to have control over top level window sizes and positions. An application can try to change these things, but the window manager decides whether to allow it or not. The theory behind this is that the user should be in control of his windows, and the window manager is his tool in implementing his wishes. If this last goal didn't work for you, don't worry. Try to get your window manager to give the test window enough space for the message, and ignore the fact that the message isn't centered. The final version of this program will center the message.