XSelectInput(dpy, awin, 0);
static int ugly_accept_window(char *addr, char *userhost, int X, int Y,    int timeout, char *mode) {#define t2x2_width 16#define t2x2_height 16static char t2x2_bits[] = {   0xff, 0xff, 0xff, 0xff, 0x33, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff,   0x33, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0x33, 0x33, 0x33, 0x33,   0xff, 0xff, 0xff, 0xff, 0x33, 0x33, 0x33, 0x33};	Window awin;	GC gc;	XSizeHints hints;	XGCValues values;	static XFontStruct *font_info = NULL;	static Pixmap ico = 0;	unsigned long valuemask = 0;	static char dash_list[] = {20, 40};	int list_length = sizeof(dash_list);	Atom wm_protocols;	Atom wm_delete_window;	XEvent ev;	long evmask = ExposureMask | KeyPressMask | ButtonPressMask	    | StructureNotifyMask;	double waited = 0.0;	/* strings and geometries y/n */	KeyCode key_y, key_n, key_v;	char strh[100];	char stri[100];	char str1_b[] = "To accept: press \"y\" or click the \"Yes\" button";	char str2_b[] = "To reject: press \"n\" or click the \"No\" button";	char str3_b[] = "View only: press \"v\" or click the \"View\" button";	char str1_m[] = "To accept: click the \"Yes\" button";	char str2_m[] = "To reject: click the \"No\" button";	char str3_m[] = "View only: click the \"View\" button";	char str1_k[] = "To accept: press \"y\"";	char str2_k[] = "To reject: press \"n\"";	char str3_k[] = "View only: press \"v\"";	char *str1, *str2, *str3;	char str_y[] = "Yes";	char str_n[] = "No";	char str_v[] = "View";	int x, y, w = 345, h = 175, ret = 0;	int X_sh = 20, Y_sh = 30, dY = 20;	int Ye_x = 20,  Ye_y = 0, Ye_w = 45, Ye_h = 20;	int No_x = 75,  No_y = 0, No_w = 45, No_h = 20; 	int Vi_x = 130, Vi_y = 0, Vi_w = 45, Vi_h = 20; 	if (!strcmp(mode, "mouse_only")) {		str1 = str1_m;		str2 = str2_m;		str3 = str3_m;	} else if (!strcmp(mode, "key_only")) {		str1 = str1_k;		str2 = str2_k;		str3 = str3_k;		h -= dY;	} else {		str1 = str1_b;		str2 = str2_b;		str3 = str3_b;	}	if (view_only) {		h -= dY;	}	/* XXX handle coff_x/coff_y? */	if (X < -dpy_x) {		x = (dpy_x - w)/2;	/* large negative: center */		if (x < 0) x = 0;	} else if (X < 0) {		x = dpy_x + X - w;	/* from lower right */	} else {		x = X;			/* from upper left */	}		if (Y < -dpy_y) {		y = (dpy_y - h)/2;		if (y < 0) y = 0;	} else if (Y < 0) {		y = dpy_y + Y - h;	} else {		y = Y;	}	X_LOCK;	awin = XCreateSimpleWindow(dpy, window, x, y, w, h, 4,	    BlackPixel(dpy, scr), WhitePixel(dpy, scr));	wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False);	wm_delete_window = XInternAtom(dpy, "WM_DELETE_WINDOW", False);	XSetWMProtocols(dpy, awin, &wm_delete_window, 1);	if (! ico) {		ico = XCreateBitmapFromData(dpy, awin, t2x2_bits, t2x2_width,		    t2x2_height);	}	hints.flags = PPosition | PSize | PMinSize;	hints.x = x;	hints.y = y;	hints.width = w;	hints.height = h;	hints.min_width = w;	hints.min_height = h;	XSetStandardProperties(dpy, awin, "new x11vnc client", "x11vnc query",	    ico, NULL, 0, &hints);	XSelectInput(dpy, awin, evmask);	if (! font_info && (font_info = XLoadQueryFont(dpy, "fixed")) == NULL) {		rfbLog("ugly_accept_window: cannot locate font fixed.\n");		X_UNLOCK;		clean_up_exit(1);	}	gc = XCreateGC(dpy, awin, valuemask, &values);	XSetFont(dpy, gc, font_info->fid);	XSetForeground(dpy, gc, BlackPixel(dpy, scr));	XSetLineAttributes(dpy, gc, 1, LineSolid, CapButt, JoinMiter);	XSetDashes(dpy, gc, 0, dash_list, list_length);	XMapWindow(dpy, awin);	XFlush(dpy);	snprintf(strh, 100, "x11vnc: accept connection from %s?", addr);	snprintf(stri, 100, "        (%s)", userhost);	key_y = XKeysymToKeycode(dpy, XStringToKeysym("y"));	key_n = XKeysymToKeycode(dpy, XStringToKeysym("n"));	key_v = XKeysymToKeycode(dpy, XStringToKeysym("v"));	while (1) {		int out = -1, x, y, tw, k;		if (XCheckWindowEvent(dpy, awin, evmask, &ev)) {			;	/* proceed to handling */		} else if (XCheckTypedEvent(dpy, ClientMessage, &ev)) {			;	/* proceed to handling */		} else {			int ms = 100;	/* sleep a bit */			usleep(ms * 1000);			waited += ((double) ms)/1000.;			if (timeout && (int) waited >= timeout) {				rfbLog("accept_client: popup timed out after "				    "%d seconds.\n", timeout);				out = 0;				ev.type = 0;			} else {				continue;			}		}		switch(ev.type) {		case Expose:			while (XCheckTypedEvent(dpy, Expose, &ev)) {				;			}			k=0;			/* instructions */			XDrawString(dpy, awin, gc, X_sh, Y_sh+(k++)*dY,			    strh, strlen(strh));			XDrawString(dpy, awin, gc, X_sh, Y_sh+(k++)*dY,			    stri, strlen(stri));			XDrawString(dpy, awin, gc, X_sh, Y_sh+(k++)*dY,			    str1, strlen(str1));			XDrawString(dpy, awin, gc, X_sh, Y_sh+(k++)*dY,			    str2, strlen(str2));			if (! view_only) {				XDrawString(dpy, awin, gc, X_sh, Y_sh+(k++)*dY,				    str3, strlen(str3));			}			if (!strcmp(mode, "key_only")) {				break;			}			/* buttons */			Ye_y = Y_sh+k*dY;			No_y = Y_sh+k*dY;			Vi_y = Y_sh+k*dY;			XDrawRectangle(dpy, awin, gc, Ye_x, Ye_y, Ye_w, Ye_h);			XDrawRectangle(dpy, awin, gc, No_x, No_y, No_w, No_h);			if (! view_only) {				XDrawRectangle(dpy, awin, gc, Vi_x, Vi_y,				    Vi_w, Vi_h);			}			tw = XTextWidth(font_info, str_y, strlen(str_y));			tw = (Ye_w - tw)/2;			if (tw < 0) tw = 1;			XDrawString(dpy, awin, gc, Ye_x+tw, Ye_y+Ye_h-5,			    str_y, strlen(str_y));			tw = XTextWidth(font_info, str_n, strlen(str_n));			tw = (No_w - tw)/2;			if (tw < 0) tw = 1;			XDrawString(dpy, awin, gc, No_x+tw, No_y+No_h-5,			    str_n, strlen(str_n));			if (! view_only) {				tw = XTextWidth(font_info, str_v,				    strlen(str_v));				tw = (Vi_w - tw)/2;				if (tw < 0) tw = 1;				XDrawString(dpy, awin, gc, Vi_x+tw,				    Vi_y+Vi_h-5, str_v, strlen(str_v));			}			break;		case ClientMessage:			if (ev.xclient.message_type == wm_protocols &&			    ev.xclient.data.l[0] == wm_delete_window) {				out = 0;			}			break;		case ButtonPress:			x = ev.xbutton.x;			y = ev.xbutton.y;			if (!strcmp(mode, "key_only")) {				;			} else if (x > No_x && x < No_x+No_w && y > No_y			    && y < No_y+No_h) {				out = 0;			} else if (x > Ye_x && x < Ye_x+Ye_w && y > Ye_y			    && y < Ye_y+Ye_h) {				out = 1;			} else if (! view_only && x > Vi_x && x < Vi_x+Vi_w			    && y > Vi_y && y < Vi_y+Ye_h) {				out = 2;			}			break;		case KeyPress:			if (!strcmp(mode, "mouse_only")) {				;			} else if (ev.xkey.keycode == key_y) {				out = 1;			} else if (ev.xkey.keycode == key_n) {				out = 0;			} else if (! view_only && ev.xkey.keycode == key_v) {				out = 2;			}			break;		default:			break;		}		if (out != -1) {			ret = out;			XUnmapWindow(dpy, awin);			XFreeGC(dpy, gc);			XDestroyWindow(dpy, awin);			XFlush(dpy);			break;		}	}	X_UNLOCK;	return ret;}