Longstanding bug in ... XtAppMainLoop?

Jordan Hayes jordan at bitway.com
Wed Feb 23 15:09:48 PST 2011


The manual page for XtAppMainLoop says that it's just a simple loop that 
calls

XEvent event;
XtAppNextEvent(app, &event);
XtDispatchEvent(&event);

... until XtAppGetExitFlag() returns true.

And looking at the code in libXt-1.0.9/src/Event.c seems to show that to 
be the case.

But: XtAppNextEvent() doesn't return until there's an actual XEvent to 
be handled; it handles Xt-internal events (inputs, timers, signals) 
itself, but doesn't return (because of course, those aren't XEvents). 
Which means that the exit flag doesn't get a chance to break the loop 
until/unless there's an actual XEvent.

If you're not using a Display at all in your app, you lose: timers or 
input sources can't signal the main loop to exit using this mechanism.

A workaround -- and what I would suggest XtAppMainLoop be fixed to do 
instead -- is code that looks more like this:

    for (;;) {
        XtAppProcessEvent(app, XtIMAll);
        if (XtAppGetExitFlag(app))
            break;
    }

XtAppProcessEvent() returns when *any* event has been dispatched, not 
just ones that involve a Display.  For the source tree, it would look 
something like this:

void XtAppMainLoop(XtAppContext app) {
    LOCK_APP(app);
    do {
        XtAppProcessEvent(app, XtIMAll);
    } while (! app->exit_flag);
    UNLOCK_APP(app);
}

I guess I'm the only one who uses Xt this way?

Thanks,

/jordan 




More information about the xorg mailing list