} else if (old_pointer == 2) {  return check_user_input_old(dt, cnt);
static int check_user_input(double dt, int tile_diffs, int *cnt) {	if (old_pointer == 1) {		/* every n-th drops thru to scan */		if ((got_user_input || ui_skip < 0) && *cnt % ui_skip != 0) {			*cnt++;			XFlush(dpy);			return 1;	/* short circuit watch_loop */		} else {			return 0;		}	} else if (old_pointer == 2) {		/* this older way is similar to the method below */		return check_user_input_old(dt, cnt);	}	if (got_keyboard_input) {		if (*cnt % ui_skip != 0) {			*cnt++;			return 1;	/* short circuit watch_loop */		}		/* otherwise continue with pointer input */	}	if (got_pointer_input) {		int spun_out, missed_out, allowed_misses, g, g_in;		double spin, spin_max, tm, to, dtm, rpe_last;		static int rfb_wait_ms = 2;		static double grind_spin_time = 0.30, dt_min = 0.15;		static double quick_spin_fac = 0.65, spin_max_fac = 2.0;		static double rpe_wait = 0.15;		int grinding, gcnt, ms, split = 200;		/*		 * Try for some "quick" pointer input processing.		 *		 * About as fast as we can, we try to process user input		 * calling rfbProcessEvents or rfbCheckFds.  We do this		 * for a time on order of the last scan_for_updates() time,		 * dt, but if we stop getting user input we break out.		 *		 * Note that rfbCheckFds() does not send any framebuffer		 * updates, so is more what we want here, although it is		 * likely they have all be sent already.		 *		 * After our first spin_out or missed_out, we decide if we		 * should continue, if we do so we say we are "grinding"		 */		if (dt < dt_min) {			dt = dt_min;	/* this is to try to avoid early exit */		}		/* max spin time in 1st pass, comparable to last dt */		spin_max = quick_spin_fac * dt;		grinding = 0;		/* 1st pass is "not grinding" */		spin = 0.0;		/* amount of time spinning */		spun_out = 0;		/* whether we spun out of time */		missed_out = 0;		/* whether we received no ptr input */		allowed_misses = 3;	/* number of ptr inputs we can miss */		gcnt = 0;		tm = 0.0;		/* timer variable */		dtime(&tm);		rpe_last = to = tm;	/* last time we did rfbPE() */		g = g_in = got_pointer_input;		while (1) {			int got_input = 0;			gcnt++;			if (grinding) {				if (gcnt >= split) {					break;				}				usleep(ms * 1000);			}			if (show_multiple_cursors && tm > rpe_last + rpe_wait) {				rfbPE(screen, rfb_wait_ms * 1000);				rpe_last = tm;			} else {				rfbCFD(screen, rfb_wait_ms * 1000);			}			dtm = dtime(&tm);			spin += dtm;			if (spin > spin_max) {				/* get out if spin time over limit */				spun_out = 1;			} else if (got_pointer_input > g) {				/* received some input, flush to display. */				got_input = 1;				g = got_pointer_input;				XFlush(dpy);			} else if (--allowed_misses <= 0) {				/* too many misses */				missed_out = 1;			} else {				/* these are misses */				int wms = 0;				if (! grinding && gcnt == 1 && button_mask) {					/*					 * missed our first input, wait					 * for a defer time. (e.g. on					 * slow link) hopefully client					 * will batch them.					 */					wms = 1000 * (0.5 * (spin_max - spin));				} else if (button_mask) {					wms = 10;				}				if (wms) {					usleep(wms * 1000);				}			}			if (spun_out && ! grinding) {				/* set parameters for grinding mode. */				grinding = 1;				if (spin > grind_spin_time || button_mask) {					spin_max = spin +					    grind_spin_time * spin_max_fac;				} else {					spin_max = spin + dt * spin_max_fac;				}				ms = (int) (1000 * ((spin_max - spin)/split));				if (ms < 1) {					ms = 1;				}				/* reset for second pass */				spun_out = 0;				missed_out = 0;				allowed_misses = 5;				g = got_pointer_input;				gcnt = 0;			} else if (spun_out && grinding) {				/* done in 2nd pass */				break;			} else if (missed_out) {				/* done in either pass */				break;			}		}	}	return 0;}