A few days ago I posted a question about trying to call a function which set
up an X app multiple times.  It was pointed out that XtAppInitialize() should
never be called more than once.  This helped.  However, I am still having
some problems.  Below is a new little test program that more closely models
my real program.  In the actual program, I am writing a library, callable
from any other program.  This means that the first time the lib function is
called, it must initialize things, and after that, it should just use the
old stuff (still around because of static variables).  In the demo below,
main() represents the main program calling my library and doit() represents
the interface to the library function.

#include <X11/Xlib.h>
#include <Xm/Xm.h>
#include <Xm/PushB.h>
#include <stdio.h>
#include <stdlib.h>

void bla(XtAppContext app, Widget top)
{
        Widget topone = top;		// in real prog, these are member vars
        XtAppContext theapp = app;	// of a class
        int junk = 0;
        Display *dis = XtOpenDisplay(theapp, NULL, NULL, NULL, NULL, 0, &junk,
                                        NULL);

        Widget box = XtVaCreateManagedWidget("blaaa", xmPushButtonWidgetClass,
                        topone,
                        XmNheight, 50,
                        XmNwidth, 50,
                        NULL);

        XtRealizeWidget(topone);
        for (int i=0;i<=25;i++)	// real prog returns when "Exit" button clicked
        {
                XEvent event;
                XtAppNextEvent(theapp, &event);
                XtDispatchEvent(&event);
        }
        XtDestroyWidget(box);
        XtCloseDisplay(dis);
}

// SetItUp - should be called once only
void SetItUp(XtAppContext *app, Widget *top)
{
        int junk = 0;
        (*top)=XtAppInitialize (app, "test", NULL, 0, &junk, NULL,
                NULL, NULL, 0);
}

// doit - some library function callable from the outside
void doit()
{
        static XtAppContext app;	// use these every time called
        static Widget top;

        static int setup = 0;

        if (!setup)
        {
                SetItUp(&app, &top);
                setup = 1;
        }
        bla(app, top);
}

// main - program which links to my library
main()
{
        for (int i=0;i<=20;i++)
        {
                doit();
                printf("sleeping...\n");//widget still on screen at this point
                sleep(5);
        }
}


The problem is that the widget does not go away until the new one is created.
(It is still on the screen -- unusuable -- during the "sleep" in the main prog,
despite the XtDestroyWidget call).

Anyone see something I'm missing?

Thanks very much.

(Please respond via email)
-- 
-------------------------------------------------------------------------------
David Rex Wood -- davewood@cs.colorado.edu -- University of Colorado at Boulder