if (db2) fprintf(stderr, "do_copyregion: %d %d %d %d  dx: %d  dy: %d dt: %.4f\n",
if (0 || db2) fprintf(stderr, "do_copyregion: %d %d %d %d  dx: %d  dy: %d dt: %.4f\n",
int try_copyrect(Window frame, int x, int y, int w, int h, int dx, int dy,    int *obscured, sraRegionPtr extra_clip, double max_wait) {	static int dt_bad = 0;	static time_t dt_bad_check = 0;	int x1, y1, x2, y2, sent_copyrect = 0;	int req, mod, cpy, ncli;	double tm, dt;	DB_SET	get_client_regions(&req, &mod, &cpy, &ncli);	if (cpy) {		/* one is still pending... try to force it out: */		fb_push_wait(max_wait, FB_COPY);		get_client_regions(&req, &mod, &cpy, &ncli);	}	if (cpy) {		return 0;	}	*obscured = 0;	/*	 * XXX KDE and xfce do some weird things with the 	 * stacking, it does not match XQueryTree.  Work around	 * it for now by CopyRect-ing the *whole* on-screen 	 * rectangle (whether obscured or not!)	 */	if (time(0) > dt_bad_check + 5) {		char *dt = guess_desktop();		if (!strcmp(dt, "kde")) {			dt_bad = 1;		} else if (!strcmp(dt, "xfce")) {			dt_bad = 1;		} else {			dt_bad = 0;		}		dt_bad_check = time(0);	}	if (0 && dt_bad) {		sraRegionPtr rect;		/* send the whole thing... */		x1 = crfix(nfix(x,   dpy_x), dx, dpy_x);		y1 = crfix(nfix(y,   dpy_y), dy, dpy_y);		x2 = crfix(nfix(x+w, dpy_x+1), dx, dpy_x+1);		y2 = crfix(nfix(y+h, dpy_y+1), dy, dpy_y+1);		rect = sraRgnCreateRect(x1, y1, x2, y2);		do_copyregion(rect, dx, dy);		sraRgnDestroy(rect);		sent_copyrect = 1;		*obscured = 1;	/* set to avoid an aggressive push */	} else if (stack_list_num || dt_bad) {		int k, tx1, tx2, ty1, ty2;		sraRegionPtr moved_win, tmp_win, whole;		sraRectangleIterator *iter;		sraRect rect;		int saw_me = 0;		int orig_x, orig_y;		XWindowAttributes attr;		orig_x = x - dx;		orig_y = y - dy;		tx1 = nfix(orig_x,   dpy_x);		ty1 = nfix(orig_y,   dpy_y);		tx2 = nfix(orig_x+w, dpy_x+1);		ty2 = nfix(orig_y+h, dpy_y+1);if (db2) fprintf(stderr, "moved_win: %4d %3d, %4d %3d  0x%lx ---\n",	tx1, ty1, tx2, ty2, frame);		moved_win = sraRgnCreateRect(tx1, ty1, tx2, ty2);		dtime0(&tm);		X_LOCK;		/*		 * loop over the stack, top to bottom until we		 * find our wm frame:		 */		for (k = stack_list_num - 1; k >= 0; k--) {			Window swin;			if (dt_bad) {				break;			}			swin = stack_list[k].win;			if (swin == frame) {if (db2) {saw_me = 1; fprintf(stderr, "  ----------\n");} else {				break;	}			}			/* skip some unwanted cases: */			if (swin == None) {				continue;			}			if (! stack_list[k].fetched ||			    stack_list[k].time > tm + 2.0) {				if (!valid_window(swin, &attr, 1)) {					stack_list[k].valid = 0;				} else {					stack_list[k].valid = 1;					stack_list[k].x = attr.x;					stack_list[k].y = attr.y;					stack_list[k].width = attr.width;					stack_list[k].height = attr.height;					stack_list[k].depth = attr.depth;					stack_list[k].class = attr.class;					stack_list[k].backing_store =					    attr.backing_store;					stack_list[k].map_state =					    attr.map_state;				}				stack_list[k].fetched = 1;				stack_list[k].time = tm;			}			if (!stack_list[k].valid) {				continue;			}			attr.x      = stack_list[k].x;			attr.y      = stack_list[k].y;			attr.depth  = stack_list[k].depth;			attr.width  = stack_list[k].width;			attr.height = stack_list[k].height;			attr.map_state = stack_list[k].map_state;			if (attr.map_state != IsViewable) {				continue;			}			/*			 * first subtract any overlap from the initial			 * window rectangle			 */			/* clip the window to the visible screen: */			tx1 = nfix(attr.x, dpy_x);			ty1 = nfix(attr.y, dpy_y);			tx2 = nfix(attr.x + attr.width,  dpy_x+1);			ty2 = nfix(attr.y + attr.height, dpy_y+1);if (db2) fprintf(stderr, "  tmp_win-1: %4d %3d, %4d %3d  0x%lx\n",	tx1, ty1, tx2, ty2, swin);if (db2 && saw_me) continue;			/* see if window clips us: */			tmp_win = sraRgnCreateRect(tx1, ty1, tx2, ty2);			if (sraRgnAnd(tmp_win, moved_win)) {				*obscured = 1;if (db2) fprintf(stderr, "         : clips it.\n");			}			sraRgnDestroy(tmp_win);			/* subtract it from our region: */			tmp_win = sraRgnCreateRect(tx1, ty1, tx2, ty2);			sraRgnSubtract(moved_win, tmp_win);			sraRgnDestroy(tmp_win);			/*			 * next, subtract from the initial window rectangle			 * anything that would clip it.			 */			/* clip the window to the visible screen: */			tx1 = nfix(attr.x - dx, dpy_x);			ty1 = nfix(attr.y - dy, dpy_y);			tx2 = nfix(attr.x - dx + attr.width,  dpy_x+1);			ty2 = nfix(attr.y - dy + attr.height, dpy_y+1);if (db2) fprintf(stderr, "  tmp_win-2: %4d %3d, %4d %3d  0x%lx\n",	tx1, ty1, tx2, ty2, swin);if (db2 && saw_me) continue;			/* subtract it from our region: */			tmp_win = sraRgnCreateRect(tx1, ty1, tx2, ty2);			sraRgnSubtract(moved_win, tmp_win);			sraRgnDestroy(tmp_win);		}		X_UNLOCK;		if (extra_clip && ! sraRgnEmpty(extra_clip)) {		    whole = sraRgnCreateRect(0, 0, dpy_x, dpy_y);		    iter = sraRgnGetIterator(extra_clip);		    while (sraRgnIteratorNext(iter, &rect)) {			/* clip the window to the visible screen: */			tx1 = rect.x1;			ty1 = rect.y1;			tx2 = rect.x2;			ty2 = rect.y2;			tmp_win = sraRgnCreateRect(tx1, ty1, tx2, ty2);			sraRgnAnd(tmp_win, whole);			/* see if window clips us: */			if (sraRgnAnd(tmp_win, moved_win)) {				*obscured = 1;			}			sraRgnDestroy(tmp_win);			/* subtract it from our region: */			tmp_win = sraRgnCreateRect(tx1, ty1, tx2, ty2);			sraRgnSubtract(moved_win, tmp_win);			sraRgnDestroy(tmp_win);			/*			 * next, subtract from the initial window rectangle			 * anything that would clip it.			 */			tmp_win = sraRgnCreateRect(tx1, ty1, tx2, ty2);			sraRgnOffset(tmp_win, -dx, -dy);			/* clip the window to the visible screen: */			sraRgnAnd(tmp_win, whole);			/* subtract it from our region: */			sraRgnSubtract(moved_win, tmp_win);			sraRgnDestroy(tmp_win);		    }		    sraRgnReleaseIterator(iter);		    sraRgnDestroy(whole);		}		dt = dtime(&tm);if (db2) fprintf(stderr, "  stack_work dt: %.4f\n", dt);		if (*obscured && !strcmp(wireframe_copyrect, "top")) {			;	/* cannot send CopyRegion */		} else if (! sraRgnEmpty(moved_win)) {			sraRegionPtr whole, shifted_region;			whole = sraRgnCreateRect(0, 0, dpy_x, dpy_y);			shifted_region = sraRgnCreateRgn(moved_win);			sraRgnOffset(shifted_region, dx, dy);			sraRgnAnd(shifted_region, whole);			sraRgnDestroy(whole);			/* now send the CopyRegion: */			if (! sraRgnEmpty(shifted_region)) {				dtime0(&tm);				do_copyregion(shifted_region, dx, dy);				dt = dtime(&tm);if (db2) fprintf(stderr, "do_copyregion: %d %d %d %d  dx: %d  dy: %d dt: %.4f\n",	tx1, ty1, tx2, ty2, dx, dy, dt);				sent_copyrect = 1;			}			sraRgnDestroy(shifted_region);		}		sraRgnDestroy(moved_win);	}	return sent_copyrect;}