rfbLogEnable(1);
int pick_windowid(unsigned long *num) {	char line[512];	int ok = 0, n = 0, msec = 10, secmax = 15;	FILE *p;	if (use_dpy) {		set_env("DISPLAY", use_dpy);	}	if (no_external_cmds) {		rfbLog("cannot run external commands in -nocmds mode:\n");		rfbLog("   \"%s\"\n", "xwininfo");		rfbLog("   exiting.\n");		clean_up_exit(1);	}	p = popen("xwininfo", "r");	if (! p) {		return 0;	}	fprintf(stderr, "\n");	fprintf(stderr, "  Please select the window for x11vnc to poll\n");	fprintf(stderr, "  by clicking the mouse in that window.\n");	fprintf(stderr, "\n");	while (msec * n++ < 1000 * secmax) {		unsigned long tmp;		char *q;		fd_set set;		struct timeval tv;		if (screen && screen->clientHead) {			/* they may be doing the pointer-pick thru vnc: */			int nfds;			tv.tv_sec = 0;			tv.tv_usec = msec * 1000;			FD_ZERO(&set);			FD_SET(fileno(p), &set);			nfds = select(fileno(p)+1, &set, NULL, NULL, &tv);						if (nfds == 0 || nfds < 0) {				/* 				 * select timedout or error.				 * note this rfbPE takes about 30ms too:				 */				rfbPE(-1);				XFlush(dpy);				continue;			}		}				if (fgets(line, 512, p) == NULL) {			break;		}		q = strstr(line, " id: 0x"); 		if (q) {			q += 5;			if (sscanf(q, "0x%lx ", &tmp) == 1) {				ok = 1;				*num = tmp;				fprintf(stderr, "  Picked: 0x%lx\n\n", tmp);				break;			}		}	}	pclose(p);	return ok;}