[comp.windows.x] Reading ahead for events using Xt

dheller@cory.Berkeley.EDU (Dan Heller) (09/28/88)

I realize this has come up before in discussion about Xlib, but
I don't recall anything discussed with respect to the toolkit.

The topic question is, how can I get as up to date as possible on
the event queue using the toolkit?

My scnario is this -- my application is reading keyboard events
one by one and for each char typed, it' "processes" it (guess
what kind of application I'm doing).  One way to improve performance
is to check the input queue for more keyboard events, and if there
are some, append the chars to a string which will get processed at
once..

I'm currently doing something of this nature in the callback routine
which notifies me that a char has been typed (a "core" widget is used):

    char buf[SIZE], *p = buf;
    int next_event = TRUE;
    while (isprint(ch)) { /* assume to be true on at least the first case */
	*p++ = ch;
	if (XtPending()) {
	    XtNextEvent(&newevent);
	    ch = convert_event_to_char(&event);
	} else {
	    next_event = FALSE;
	    break;
	}
    }
    if (next_event)
	XtDispatchEvent(&event);

If next_event is true and the loop was broken, it assumes that the
event gotten was not an ascii char that was typed.  So, it dispatches
the event so that appropriate routine will be called.

The question is, is it kosher to call XtNextEvent() all the time
without calling XtDispatch() event for each one?  I'm emptying out
the event queue without letting XtDispatchEvent do whatever type of
cleanup that it might want to do (if it does any).

I've tried the code both ways and there doesn't seem to be any difference
in either performance or results.  As far as the performance issue is
concerned, I'm rarely reading any chars ahead.  Even holding down a key
results in many single calls to this routine and the XtPending is hardly
ever returning true.  Event when I'm done typing, the program is sitting
back as if I'm typing at 300 baud or something.
Dan Heller	<island!argv@sun.com>