[comp.windows.x] Processing events "normally" outside XtMainLoop

mwolf@pws.bull.com (Mary-Anne Wolf) (09/12/90)

I am trying to do something and have not quite figured out how.
I had not expected it to be so hard.  I'd appreciate help.

I have a program written in C and UIL on Motif 1.0 on X11R3 on SCO running
with mwm.  I have a function which takes a long time to run, and
originally, my program's window was unresponsive while the function was
running.  This was unacceptable because I need the user to be able to push
a button to make this long function abort.  I prefer to avoid the overhead
of forking processes, because it's too slow, and to avoid writing my own
event handler, because handling the UIL callbacks is probably difficult.

The best solution seemed to be to insert event-handling code in my function
every so often that just calls the "normal" event handler.  I tried lots of
things, and the closest to something that works is:

event_return->type = -1;
while(XtPeekEvent(event_return) != 0) && (event_return->type != FocusOut))
{
        XtProcessEvent(XtIMALL);
}
if (event_return->type == FocusOut)
{
        XtProcessEvent(XtAllEvents);
}

but this causes my function to suspend when it loses the focus (when I move
the mouse out of the window) and to continue running when it regains the
focus, and I want it to keep running whether it has the focus or not, but
I also want to be able to do things in other windows while it is running.

Anyone know the right way to do this?

Thanks,

Mary-Anne Wolf
Bull
mwolf@pws.bull.com or mwolf@granite.cr.bull.com
"There is ALWAYS one more bug."

klee@wsl.dec.com (Ken Lee) (09/12/90)

In article <15762@know.pws.bull.com>, mwolf@pws.bull.com (Mary-Anne Wolf) writes:
|> I also want to be able to do things in other windows while it is running.

Sounds like you want to context switch in and out of your long-running
function.  One easy way to do this is to put it in a separate UNIX
process (or the equivalent in your OS) and let the OS do the
switching.  Alternatively, if you have support for it, you can use two
threads within the same process, but you have to make sure your
libraries support multiple threads.

-- 
Ken Lee
DEC Western Software Laboratory, Palo Alto, Calif.
Internet: klee@wsl.dec.com
uucp: uunet!decwrl!klee