[comp.windows.x] Need HELP grabbing bitmap of newly created window

loganj@yvax.byu.edu (02/20/91)

We want to create a widget, wait for it to appear on the screen, and then
grab an image of it.  We are using Motif 1.03, and an X11R3.5 server (the
one that comes with Ultrix 3.1 on the DECstation 3100), although the
problems we are having appear unrelated to Motif or even Xt.

First we create the widget (a DialogShell with a few children) and realize
it.  At this point we would like to grab the image, but of course the
widgets have not hit the screen yet because the expose events generated
by their creation have not yet been serviced.  We don't want to give up
control, so we take over the event loop thus:

void ProcessPendingEvents ()
{
  int numEvents, i;
  XEvent event;

  do {
    XSync (dpy, False);
    numEvents = XEventsQueued (dpy, QueuedAfterFlush);
    for (i = 0; i < numEvents; i++) {
      XtAppNextEvent (appContext, &event);
      XtDispatchEvent (&event);
    }
  } while (numEvents > 0);
}

Just to be safe, we call ProcessPendingEvents twice.  Then we get the
window of the DialogShell widget and do an XGetImage.

This procedure often works.  However, just as often, the application dies
with the error:

X Protocol error detected by server:  parameter mismatch
  Failed request major op code 73 X_GetImage
  ...

We think the problem is that the window has not yet been mapped.  When we
get this error the window has sometimes not appeared on the screen.

What are we doing wrong?  Is there a better way to do what we want to do?

Thanks and Regards,
Jim Logan
loganj@yvax.byu.edu
loganj@byuvax.bitnet