[comp.windows.x] Extra Expose event from Window Manager

levi@kodak.com (Ilia Levi) (01/24/91)

I have a problem with a simple program using Xlib. After setting up the
window, I issue XMapRaised and Xflush. Then I wait for the Expose event with
XNextEvent, and then
use XFillPolygon to draw a rectangle. It works fine if I don't run a window
manager, however with olwm or twm the rectangle does not appear in the window.
If no WM is running, the rectangle is displayed.

However, if using a window manager, I issue another XNextEvent I get another
Expose event, and the rectangle is displayed. Sleep for 1 second instead
of the second XNextEvent also works.

What's going on??? How do I know how many events to wait for? We checked the
count field in the XExpose Event structure, and in every case it is 0.
 
 
Thanks for any clues, Ilia.

lrul00@dixel.Kodak.COM (Richard C. Dempsey) (01/25/91)

In summary: an Xlib program depends on receiving precisely one expose
event to know that the window has been successfully created.  olwm and
twm deliver an extra expose event and break it.  mwm swallows all
expose events and break it.  What's the best way for an Xlib program to
know that its window has been successfully created, under a variety of
window managers?

Let's be more specific about the problem that Ilia Levi and I have.  We
are trying to run PLTMG [1] on a variety of platforms.  The X11 driver
is written using Xlib calls only.  It works on the Silicon Graphics
Personal Iris using Foresight (SG's version of NeWS, which includes an
X server without a window manager) but breaks under the Open Look
Window Manager, the Motif Window Manager, and twm (BTW, what's the full
name of twm?).

    dpy= XOpenDisplay("");
    scr = DefaultScreenOfDisplay(dpy);
    winX = XWidthOfScreen(scr);
    winY = XHeightOfScreen(scr);
    scale_xy =((( winX*2 < winY*3 ) ? (winX*2)/3 : winY )*95)/100 ;
    winW = (scale_xy*3)/2 ;
    winH = scale_xy ;
    winX = (winX - winW) / 2 ;
    winY = (winY - winH) / 2 ;
    bwidth=5;
    xswa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask;
    xswa.backing_store = Always;
    xswa.background_pixel = WhitePixelOfScreen(scr);
    win = XCreateWindow(dpy, RootWindowOfScreen(scr),
                    winX, winY, winW, winH, bwidth,
                    DefaultDepthOfScreen(scr), InputOutput,
                    DefaultVisualOfScreen(scr),
                    CWBackingStore | CWBackPixel | CWEventMask , &xswa);
/*
 * ... deleted code that set's the window name, allocates color cells
 * and stores colors in them ...
 */
    XMapRaised(dpy, win);
    XFlush(dpy);
    do {
	XNextEvent(dpy, &xev);
    } while (xev.type != Expose);
    XSetForeground(dpy, DefaultGCOfScreen(scr), ( status = 0  ) ?
            WhitePixelOfScreen(scr) : pixels[ *icolor - 1 ] );
    XFillPolygon( dpy, win, DefaultGCOfScreen(scr),
             pts, *np, Nonconvex, CoordModeOrigin );

If no expose event is ever delivered (Motif case on AIX 3.1, 3002),
then we never get to XSetForeground().  If an extra expose event is
delivered (olwm and twm on SunOS 4.1.1), then XSetForeground seems to
block.  When an extra call to XNextEvent is inserted after the do -
while, then the code will work on olwm and twm, but not, of course, on
mwm. What's the correct way to do this for maximum portability?  I don't
want to write a new driver for each window manager.

[1] PLTMG: A Software Package for Solving Elliptic Partial Differential
Equations: User's Guide 6.0. by Randolph E. Bank, (Frontiers in Applied
Mathematics, vol. 7), SIAM, 1990.  ISBN 0-89871-255-6

Source code (about 1/2 MB) is available by anonymous ftp from
research.att.com and from the netlib mail servers: netlib@ornl.gov or
netlib@research.att.com.  This is considered large by netlib
standards.  Please do not fetch it unless you need it.  If you want
full copies of the routines involved in this problem (a very minor part
of PLTMG), send email and I will forward them to you.

Thanks!
--
Richard C. Dempsey, Computational Science Lab	| dempsey@Kodak.COM
10th Floor, Bldg 83, RL				| KODAKR(DEMPSEY)
Eastman Kodak Company				| (716) 477-3457
Rochester, NY 14650-2205			|