5.3. Displaying the Window   

After the previous section we now know how to create a window, but alas, we still do not have anything on our screen. However, before we can display the window we need to provide some hints about it to the window manager. These are defined in the following structure

   typedef struct {

long flags;
int x, y; /* Obsolete in rel 4 */
int width, height; /* Obsolete in rel 4 */
int min_width, min_height;
int max_width, max_height;
int width_inc, height_inc;
struct {
int x; /* Numerator */
int y; /* Denominator */
} min_aspect, max_aspect;
int base_width, base_height; /* New in rel 4 */
int win_gravity; /* New in rel 4 */
} XSizeHints;

There is a marked change in the definition between release 4 and release 5. If you have a release 4 or later version of X it is still recommended that you fill the fields x, y, width and height for compatibility with older window managers. For simplicity, we will proceed with the assumption that we are working with an older version of X.

As with XSetAttributes there is a mask, this time stored inside the structure in the field flags. Some of the more interesting flags and there meaning are listed below.


USPosition - user specified x, y
USSize - user specified width, height
PPosition - program specified position
PSize - program specified size
PMinSize - min size
PMaxSize - max size
PAspect - min and max aspect ratios

Once the size hints have been set up they are passed to the window manager using the XSetWMNormalHints function. Normal Size refers to the normal open window size, that is as opposed to iconic. The function is given below

     Display        * display;

Window window;
XSizeHints hints;
XSetWMNormalHints(display, window, &hints);

We could also set two additional sets of hints. X Window System Manager Hints (XWMHints) allows you to set up an icon for the program and its initial state (full screen or iconic). X Class Hints (XClassHint) is available to provide clues to other applications as to what kind of class your application is. This is getting beyond the scope of our course however.

The only other thing we may wish to initialise before we actually display the window is the window's name. This name may be displayed by the window manager in the windows title bar. To set the window name we use the XStoreName function

     Display        * display;

Window window;
char window_name [ ];
XStoreName (display, window, window_name);

We are now ready to display the window. We can use one of two functions.

     Display        * display;

Window window;
XMapWindow(display, window);
XMapRaised(display,window);

Very often the two will have the same result. Both will cause the window to be drawn on the screen, but XMapRaised explicitly asks for it to appear over all other windows.

As X caches everything for us, to be sure that the window is displayed we must flush the cache. We do this with a call to XFlush(display);