--- ./Tekproc.c.org Sun Apr 17 17:23:23 1994 +++ ./Tekproc.c Tue Jan 24 19:17:23 1995 @@ -178,6 +178,8 @@ extern int Tpttable[]; extern int Tspttable[]; +extern XtAppContext app_con; + static int *curstate = Talptable; static int *Tparsestate = Talptable; @@ -633,7 +635,7 @@ TekGINoff(); TCursorDown(); if (!TekRefresh && - (QLength(screen->display) > 0 || + (XtAppPending(app_con) || GetBytesAvailable (ConnectionNumber(screen->display)) > 0)) xevents(); break; @@ -736,7 +738,7 @@ TCursorToggle(TOGGLE); Ttoggled = FALSE; } - if(QLength(screen->display)) + if(XtAppPending(app_con) & XtIMXEvent) Tselect_mask = X_mask; else { XFlush(screen->display); --- ./main.c.org Tue Jan 24 18:41:55 1995 +++ ./main.c Tue Jan 24 19:22:37 1995 @@ -248,6 +248,10 @@ #define ttyslot() 1 #endif /* apollo */ +#ifdef sun +#include +#endif + #ifdef linux #define ttyslot() 1 #endif /* linux */ @@ -3321,15 +3325,19 @@ int fd; { #ifdef FIONREAD - static long arg; + long arg; ioctl (fd, FIONREAD, (char *) &arg); return (int) arg; #else +#ifdef FIORDCK + return (ioctl (fd, FIORDCHK, NULL)); +#else struct pollfd pollfds[1]; pollfds[0].fd = fd; pollfds[0].events = POLLIN; return poll (pollfds, 1, 0); +#endif #endif } --- ./misc.c.org Tue Jan 24 18:41:55 1995 +++ ./misc.c Tue Jan 24 19:24:24 1995 @@ -60,21 +60,33 @@ static void DoSpecialEnterNotify(); static void DoSpecialLeaveNotify(); +extern XtAppContext app_con; + xevents() { XEvent event; + XtInputMask input_mask; register TScreen *screen = &term->screen; - extern XtAppContext app_con; if(screen->scroll_amt) FlushScroll(screen); - if (!XPending (screen->display)) - /* protect against events/errors being swallowed by us or Xlib */ - return; + /* + * process timeouts, relying on the fact that XtAppProcessEvent + * will process the timeout and return without blockng on the + * XEvent queue. Other sources i.e. the pty are handled elsewhere + * with select(). + */ + while ((input_mask = XtAppPending(app_con)) & XtIMTimer) + XtAppProcessEvent(app_con, XtIMTimer); + /* + * If there's no XEvents, don't wait around... + */ + if ((input_mask & XtIMXEvent) != XtIMXEvent) + return; do { if (waitingForTrackInfo) return; - XNextEvent (screen->display, &event); + XtAppNextEvent (app_con, &event); /* * Hack to get around problems with the toolkit throwing away * eventing during the exclusive grab of the menu popup. By @@ -100,7 +112,7 @@ (event.xany.type != ButtonPress) && (event.xany.type != ButtonRelease))) XtDispatchEvent(&event); - } while (QLength(screen->display) > 0); + } while ((input_mask = XtAppPending(app_con)) & XtIMXEvent); } @@ -318,7 +330,7 @@ the bell again? */ if(screen->bellSuppressTime) { if(screen->bellInProgress) { - if (QLength(screen->display) > 0 || + if (XtAppPending(app_con) || GetBytesAvailable (ConnectionNumber(screen->display)) > 0) xevents(); if(screen->bellInProgress) { /* even after new events? */ --- ./charproc.c.org Sat Jun 4 08:44:05 1994 +++ ./charproc.c Tue Jan 24 19:21:24 1995 @@ -90,6 +90,7 @@ extern jmp_buf VTend; +extern XtAppContext app_con; extern Widget toplevel; extern void exit(); extern char *malloc(); @@ -1221,7 +1222,7 @@ Index(screen, 1); if (term->flags & LINEFEED) CarriageReturn(screen); - if (QLength(screen->display) > 0 || + if (XtAppPending(app_con) || GetBytesAvailable (ConnectionNumber(screen->display)) > 0) xevents(); parsestate = groundtable; @@ -1729,7 +1730,7 @@ if (!screen->instatus) #endif /* STATUSLINE */ Index(screen, 1); - if (QLength(screen->display) > 0 || + if (XtAppPending(app_con) || GetBytesAvailable (ConnectionNumber(screen->display)) > 0) xevents(); parsestate = groundtable; @@ -1743,7 +1744,7 @@ Index(screen, 1); CarriageReturn(screen); - if (QLength(screen->display) > 0 || + if (XtAppPending(app_con) || GetBytesAvailable (ConnectionNumber(screen->display)) > 0) xevents(); parsestate = groundtable; @@ -2106,15 +2107,26 @@ XFlush(screen->display); /* always flush writes before waiting */ - /* Update the masks and, unless X events are already in the queue, - wait for I/O to be possible. */ + /* + * Update the masks and, unless X events are already in the + * queue, wait for I/O to be possible. + */ select_mask = Select_mask; write_mask = ptymask(); select_timeout.tv_sec = 0; - select_timeout.tv_usec = 0; - i = select(max_plus1, &select_mask, &write_mask, (int *)NULL, - QLength(screen->display) ? &select_timeout - : (struct timeval *) NULL); + /* + * if there's either an XEvent or an XtTimeout pending, just take + * a quick peek, i.e. timeout from the select() immediately. If + * there's nothing pending, let select() block a little while, but + * for a shorter interval than the arrow-style scrollbar timeout. + */ + if (XtAppPending(app_con)) + select_timeout.tv_usec = 0; + else + select_timeout.tv_usec = 50000; + i = select(max_plus1, + &select_mask, &write_mask, (int *)NULL, + &select_timeout); if (i < 0) { if (errno != EINTR) SysError(ERROR_SELECT); @@ -2128,7 +2140,7 @@ /* if there are X events already in our queue, it counts as being readable */ - if (QLength(screen->display) || (select_mask & X_mask)) { + if (XtAppPending(app_con) || (select_mask & X_mask)) { xevents(); } @@ -3256,7 +3268,6 @@ /* make sure that the resize gravity acceptable */ if ( new->misc.resizeGravity != NorthWestGravity && new->misc.resizeGravity != SouthWestGravity) { - extern XtAppContext app_con; Cardinal nparams = 1; XtAppWarningMsg(app_con, "rangeError", "resizeGravity", "XTermError", @@ -3900,7 +3911,7 @@ * (screen->max_row + 1) + 2 * screen->border, &junk, &junk); XSync(screen->display, FALSE); /* synchronize */ - if(QLength(screen->display) > 0) + if(XtAppPending(app_con)) xevents(); } CursorSet(screen, 0, 0, term->flags);