chiark / gitweb /
progress printing and bugfixing and build system improvements
[ypp-sc-tools.db-test.git] / pctb / pages.c
index fbf33171bd3a90182cc7e650361654767f0181d6..ffd0ba6e4c8c9c8a39d4268291f65638030d0f87 100644 (file)
@@ -61,6 +61,58 @@ static void sync_after_input(void) {
   last_input= timestamp();
 }
 
   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);
 static void send_key(KeySym sym) {
   XTestFakeKeyEvent(disp, keycode(sym),1, 10);
   XTestFakeKeyEvent(disp, keycode(sym),0, 10);
@@ -92,7 +144,9 @@ static void snapshot(Snapshot **output) {
   timestamp();
   *output= XGetImage(disp,id, 0,0, wwidth,wheight, AllPlanes, ZPixmap);
   timestamp();
   timestamp();
   *output= XGetImage(disp,id, 0,0, wwidth,wheight, AllPlanes, ZPixmap);
   timestamp();
-  
+
+  check_not_disturbed();
+
   debugf("PAGING   snapshot done.\n");
 }
 
   debugf("PAGING   snapshot done.\n");
 }
 
@@ -105,10 +159,19 @@ static int identical(const Snapshot *a, const Snapshot *b) {
   return !memcmp(a->data, b->data, a->bytes_per_line * a->height);
 }
 
   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, ...) {
 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
   Snapshot *last=0;
   int r;
   /* waits longer if we're going to return an image identical to previously
@@ -119,12 +182,9 @@ static void wait_for_stability(Snapshot **output,
          last_input, previously);
 
   char *doing;
          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();
 
   for (;;) {
     double at_snapshot= timestamp();
@@ -144,7 +204,7 @@ static void wait_for_stability(Snapshot **output,
       break;
     }
     
       break;
     }
     
-    progress_spinner(doing);
+    progress_spinner("%s",doing);
 
     debugf("PAGING  wait_for_stability  retry\n");
 
 
     debugf("PAGING  wait_for_stability  retry\n");
 
@@ -159,13 +219,7 @@ static void wait_for_stability(Snapshot **output,
   free_snapshot(&last);
   free(doing);
   debugf("PAGING  wait_for_stability done.\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) {
 }
 
 static void raise_and_get_details(void) {
@@ -173,7 +227,6 @@ static void raise_and_get_details(void) {
   int evbase,errbase,majver,minver;
   int wxpos, wypos;
   unsigned bd,depth;
   int evbase,errbase,majver,minver;
   int wxpos, wypos;
   unsigned bd,depth;
-  Window dummy;
 
   progress("raising and checking YPP client window...");
 
 
   progress("raising and checking YPP client window...");
 
@@ -202,20 +255,11 @@ static void raise_and_get_details(void) {
 
   eassert(wwidth >= 320 && wheight >= 320);
 
 
   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) {
 }
 
 static void set_focus(void) {
+  int r;
   int screen= XScreenNumberOfScreen(attr.screen);
 
   progress("taking control of YPP client window...");
   int screen= XScreenNumberOfScreen(attr.screen);
 
   progress("taking control of YPP client window...");
@@ -231,6 +275,13 @@ static void set_focus(void) {
 
   sync_after_input();
 
 
   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);
 
   translate_coords_toroot(10,10, &xpos,&ypos);
   XTestFakeMotionEvent(disp,screen, xpos,ypos, 0);
 
@@ -324,7 +375,8 @@ void take_screenshots(void) {
     debugf("PAGING page %d converted\n",npages);
 
     wait_for_stability(&current,last, 0,
     debugf("PAGING page %d converted\n",npages);
 
     wait_for_stability(&current,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)) {
 
     if (npages &&  /* first pagedown doesn't do much */
        identical(current,last)) {