[comp.windows.x] Busy question.

mrl@nerus.pfc.mit.edu (03/19/91)

I'm presently using the "Busy" code which I obtained from a friend, which I
believe appeared on comp.windows.x.  It works fine.  However, I would like to
be able to use it for a window that gets updated by an AST. The busy code I am
using is the code that follows this message.  The AST calls Busy, updates the
mainwidget, and then calls UnBusy before exiting. I've tried to use it, and it
works relatively fine as long as I am using only the mainwidget.  However it has
problems when the AST arrives, and I am managing or using a popup attached
dialog box that was created from the mainwidget.   After the AST finishes,
sometimes the box will no longer accept input.  If it was in the process of
being created, it will not finish doing so, and sometimes the program crashes
with a X server error.   Can anyone help?  Thanks.

(This message was also sent directly to the writers who were cited as being the
authors of the code).
							Mark

-------------------------------------------------------------------------------

static Window CreateBusyWindow(Widget toplevel)
{
     unsigned long valuemask;
     XSetWindowAttributes attributes;

     /* Ignore device events while the busy cursor is displayed. */
     valuemask = CWDontPropagate | CWCursor;
     attributes.do_not_propagate_mask =  (KeyPressMask | KeyReleaseMask |
         ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
     attributes.cursor = XCreateFontCursor(XtDisplay(toplevel), XC_watch);

     /* The window will be as big as the display screen, and clipped by
        its own parent window, so we never have to worry about resizing */
     return XCreateWindow(XtDisplay(toplevel), XtWindow(toplevel), 0, 0,
         WidthOfScreen(XtScreen(toplevel)), HeightOfScreen(XtScreen(toplevel)),
         (unsigned int) 0, CopyFromParent, InputOnly,
         CopyFromParent, valuemask, &attributes);
}
void Busy()
{
  if (BusyWindow) 
  {
    XMapRaised(XtDisplay(MainWidget),BusyWindow);
    while (XPending(XtDisplay(MainWidget)))
    {
      XEvent event;
      XtNextEvent(&event);
      XtDispatchEvent(&event);
    }
    XFlush(XtDisplay(MainWidget));
    if (LIB$AST_IN_PROG()) XSync(XtDisplay(MainWidget));
  }
}
void UnBusy()
{
  if (BusyWindow) XUnmapWindow(XtDisplay(MainWidget),BusyWindow);
  if (LIB$AST_IN_PROG()) XSync(XtDisplay(MainWidget));
}

mrl@nerus.pfc.mit.edu (03/19/91)

Oops.  I discovered the problem with my Busy code.  The XSync call was missing
the parameter "discard", so it was discarding all the events on the queue.
I'll have to chastise the person who gave that code to me.