set_xdamage_mark(0, 0, dpy_x, dpy_y);
int choose_delay(double dt) {	static double t0 = 0.0, t1 = 0.0, t2 = 0.0, now; 	static int x0, y0, x1, y1, x2, y2, first = 1;	int dx0, dy0, dx1, dy1, dm, i, msec = waitms;	double cut1 = 0.15, cut2 = 0.075, cut3 = 0.25;	double bogdown_time = 0.25, bave = 0.0;	int bogdown = 1, bcnt = 0;	int ndt = 8, nave = 3;	double fac = 1.0;	int db = 0;	static double dts[8];	if (waitms == 0) {		return waitms;	}	if (nofb) {		return waitms;	}	if (first) {		for(i=0; i<ndt; i++) {			dts[i] = 0.0;		}		first = 0;	}	now = dnow();	/*	 * first check for bogdown, e.g. lots of activity, scrolling text	 * from command output, etc.	 */	if (nap_ok) {		dt = 0.0;	}	if (! wait_bog) {		bogdown = 0;	} else if (button_mask || now < last_keyboard_time + 2*bogdown_time) {		/*		 * let scrolls & keyboard input through the normal way		 * otherwise, it will likely just annoy them.		 */		bogdown = 0;	} else if (dt > 0.0) {		/*		 * inspect recent dt's:		 * 0 1 2 3 4 5 6 7 dt		 *             ^ ^ ^		 */		for (i = ndt - (nave - 1); i < ndt; i++) {			bave += dts[i];			bcnt++;			if (dts[i] < bogdown_time) {				bogdown = 0;				break;			}		}		bave += dt;		bcnt++;		bave = bave / bcnt;		if (dt < bogdown_time) {			bogdown = 0;		}	} else {		bogdown = 0;	}	/* shift for next time */	for (i = 0; i < ndt-1; i++) {		dts[i] = dts[i+1];	}	dts[ndt-1] = dt;if (0 && dt > 0.0) fprintf(stderr, "dt: %.5f %.4f\n", dt, dnow() - x11vnc_start);	if (bogdown) {		if (use_xdamage) {			/* DAMAGE can queue ~1000 rectangles for a scroll */			clear_xdamage_mark_region(NULL, 0);		}		msec = (int) (1000 * 1.75 * bave);		if (dts[ndt - nave - 1] > 0.75 * bave) {			msec = 1.5 * msec;		}		if (msec > 1500) {			msec = 1500;		}		if (msec < waitms) {			msec = waitms;		}		db = (db || debug_tiles);		if (db) fprintf(stderr, "bogg[%d] %.3f %.3f %.3f %.3f\n",		    msec, dts[ndt-4], dts[ndt-3], dts[ndt-2], dts[ndt-1]);		return msec;	}	/* next check for pointer motion, keystrokes, to speed up */	t2 = dnow();	x2 = cursor_x;	y2 = cursor_y;	dx0 = nabs(x1 - x0);	dy0 = nabs(y1 - y0);	dx1 = nabs(x2 - x1);	dy1 = nabs(y2 - y1);	if (dx1 > dy1) {		dm = dx1;	} else {		dm = dy1;	}	if ((dx0 || dy0) && (dx1 || dy1)) {		if (t2 < t0 + cut1 || t2 < t1 + cut2 || dm > 20) {			fac = wait_ui * 1.25;		}	} else if ((dx1 || dy1) && dm > 40) {		fac = wait_ui;	}	if (fac == 1 && t2 < last_keyboard_time + cut3) {		fac = wait_ui;	}	msec = (int) ((double) waitms / fac);	if (msec == 0) {		msec = 1;	}	x0 = x1;	y0 = y1;	t0 = t1;	x1 = x2;	y1 = y2;	t1 = t2;	return msec;}