last_input= timestamp();
}
+static void translate_coords_toroot(int wx, int wy, int *rx, int *ry) {
+ int r;
+ Window dummy;
+ r= XTranslateCoordinates(disp, id,attr.root, wx,wy, rx,ry, &dummy);
+ eassert(r);
+}
+
+static void check_client_window_all_on_screen(void) {
+ int r;
+ int rxpos, rypos;
+ unsigned rwidth, rheight;
+ Window dummy;
+ unsigned bd, depth;
+
+ r= XGetGeometry(disp,attr.root, &dummy, &rxpos,&rypos,
+ &rwidth, &rheight,
+ &bd,&depth);
+
+ translate_coords_toroot(0,0, &rxpos,&rypos);
+ eassert(rxpos>=0 && rypos>=0);
+
+ translate_coords_toroot(wwidth-1,wheight-1, &rxpos,&rypos);
+ eassert(rxpos<rwidth && rypos<rheight);
+}
+
+static void check_not_disturbed(void) {
+ XEvent ev;
+ int r;
+
+ for (;;) {
+ r= XCheckMaskEvent(disp, ~0, &ev);
+ if (r==False) return;
+
+ switch (ev.type) {
+ case VisibilityNotify:
+ eassert(ev.xvisibility.state == VisibilityUnobscured);
+ break;
+ case ConfigureNotify:
+ check_client_window_all_on_screen();
+ break;
+ case FocusOut:
+ eassert(!"focus left YPP client window");
+ break;
+ case FocusIn:
+ warning("focus entered YPP client window ?!");
+ break;
+ default:
+ eassert(!"unexpected X11 event");
+ }
+ }
+}
+
static void send_key(KeySym sym) {
XTestFakeKeyEvent(disp, keycode(sym),1, 10);
XTestFakeKeyEvent(disp, keycode(sym),0, 10);
timestamp();
*output= XGetImage(disp,id, 0,0, wwidth,wheight, AllPlanes, ZPixmap);
timestamp();
-
+
+ check_not_disturbed();
+
debugf("PAGING snapshot done.\n");
}
return !memcmp(a->data, b->data, a->bytes_per_line * a->height);
}
+static void wait_for_stability(Snapshot **output,
+ const Snapshot *previously,
+ void (*with_keypress)(void),
+ const char *fmt, ...)
+ FMT(4,5);
+
static void wait_for_stability(Snapshot **output,
const Snapshot *previously,
void (*with_keypress)(void),
const char *fmt, ...) {
+ va_list al;
+ va_start(al,fmt);
+
Snapshot *last=0;
int r;
/* waits longer if we're going to return an image identical to previously
last_input, previously);
char *doing;
- va_list al;
- va_start(al,fmt);
- r= asprintf(&doing,fmt,al); eassert(r>=0);
- va_end(al);
+ r= vasprintf(&doing,fmt,al); eassert(r>=0);
- progress(doing);
+ progress("%s",doing);
for (;;) {
double at_snapshot= timestamp();
break;
}
- progress_spinner(doing);
+ progress_spinner("%s",doing);
debugf("PAGING wait_for_stability retry\n");
free_snapshot(&last);
free(doing);
debugf("PAGING wait_for_stability done.\n");
-}
-
-static void translate_coords_toroot(int wx, int wy, int *rx, int *ry) {
- int r;
- Window dummy;
- r= XTranslateCoordinates(disp, id,attr.root, wx,wy, rx,ry, &dummy);
- eassert(r);
+ va_end(al);
}
static void raise_and_get_details(void) {
int evbase,errbase,majver,minver;
int wxpos, wypos;
unsigned bd,depth;
- Window dummy;
progress("raising and checking YPP client window...");
eassert(wwidth >= 320 && wheight >= 320);
- int rxpos, rypos;
- unsigned rwidth, rheight;
- r= XGetGeometry(disp,attr.root, &dummy, &rxpos,&rypos,
- &rwidth, &rheight,
- &bd,&depth);
-
- translate_coords_toroot(0,0, &rxpos,&rypos);
- eassert(rxpos>=0 && rypos>=0);
-
- translate_coords_toroot(wwidth-1,wheight-1, &rxpos,&rypos);
- eassert(rxpos<rwidth && rypos<rheight);
+ check_client_window_all_on_screen();
}
static void set_focus(void) {
+ int r;
int screen= XScreenNumberOfScreen(attr.screen);
progress("taking control of YPP client window...");
sync_after_input();
+ delay(0.5);
+ r= XSelectInput(disp, id,
+ StructureNotifyMask|
+ VisibilityChangeMask|
+ FocusChangeMask
+ ); eassert(r);
+
translate_coords_toroot(10,10, &xpos,&ypos);
XTestFakeMotionEvent(disp,screen, xpos,ypos, 0);
debugf("PAGING page %d converted\n",npages);
wait_for_stability(¤t,last, 0,
- "collecting screenshot of page %d...",npages+1);
+ "collecting screenshot of page %d...",
+ npages+1);
if (npages && /* first pagedown doesn't do much */
identical(current,last)) {