chiark / gitweb /
Reorganise docs to include new howto material in intro etc.
[ypp-sc-tools.db-live.git] / yarrg / pages.c
index 2e3edde72d4b3fb68ecd48f20e430cac1739252b..28364a07381d0035b21b5907af7486bc7aaab53f 100644 (file)
@@ -154,28 +154,51 @@ static void check_not_disturbed(void) {
   }
 }      
 
+static void check_pointer_not_disturbed(void) {
+  Window got_root, got_child;
+  int got_root_x, got_root_y;
+  int got_win_x, got_win_y;
+  unsigned got_mask;
+
+  int r= XQueryPointer(disp,id, &got_root,&got_child,
+                      &got_root_x, &got_root_y,
+                      &got_win_x, &got_win_y,
+                      &got_mask);
+  if (!r ||
+      got_win_x!=commod_page_point.x ||
+      got_win_y!=commod_page_point.y) {
+    progress("");
+    fprintf(stderr,"\nunexpected mouse position:"
+           " samescreen=%d got=%dx%d want=%dx%d",
+           r, got_win_x,got_win_y,
+           commod_page_point.x,commod_page_point.y);
+    fatal("Mouse pointer moved.");
+  }
+}
+
 static void send_key(KeySym sym) {
   check_not_disturbed();
-  XTestFakeKeyEvent(disp, keycode(sym),1, 10);
-  XTestFakeKeyEvent(disp, keycode(sym),0, 10);
+  XTestFakeKeyEvent(disp, keycode(sym),1, 0);
+  XTestFakeKeyEvent(disp, keycode(sym),0, 0);
 }
-static void mouse_1_updown_here(void) {
+static void send_mouse_1_updown_here(void) {
   check_not_disturbed();
-  XTestFakeButtonEvent(disp,1,1, 10);
-  XTestFakeButtonEvent(disp,1,0, 10);
+  XTestFakeButtonEvent(disp,1,1, 0);
+  XTestFakeButtonEvent(disp,1,0, 0);
 }
-static void mouse_1_updown(int x, int y) {
+static void send_mouse_1_updown(int x, int y) {
   check_not_disturbed();
   int screen= XScreenNumberOfScreen(attr.screen);
   int xpos, ypos;
   translate_coords_toroot(x,y, &xpos,&ypos);
   XTestFakeMotionEvent(disp, screen, xpos,ypos, 0);
-  mouse_1_updown_here();
+  send_mouse_1_updown_here();
 }
 static void pgdown_by_mouse(void) {
   check_not_disturbed();
+  check_pointer_not_disturbed();
   debugf("PAGING   Mouse\n");
-  mouse_1_updown_here();
+  send_mouse_1_updown_here();
   sync_after_input();
 }
 
@@ -350,12 +373,14 @@ static void wait_for_stability(Snapshot **output,
          "  last_input=%f previously=%p `%s'\n",
          last_input, previously, doing);
 
-  double min_interval= 0.025;
+  double max_interval= 1.000;
+  double min_interval= 0.100;
   for (;;) {
     progress_spinner("%s",doing);
     
     double since_last_input= timestamp() - last_input;
     double this_interval= min_interval - since_last_input;
+    if (this_interval > max_interval) this_interval= max_interval;
 
     if (this_interval >= 0)
       delay(this_interval);
@@ -496,7 +521,7 @@ static void set_focus_commodity(void) {
 
   debugf("PAGING set_focus\n");
 
-  mouse_1_updown(commod_focus_point.x, commod_focus_point.y);
+  send_mouse_1_updown(commod_focus_point.x, commod_focus_point.y);
   sync_after_input();
 
   delay(0.5);
@@ -552,16 +577,17 @@ static void prepare_ypp_client(void) {
   Rect sunshine= find_sunshine_widget();
 
   progress("poking client...");
-  mouse_1_updown((sunshine.tl.x   + sunshine.br.x) / 2,
-                (sunshine.tl.y*9 + sunshine.br.y) / 10);
+  send_mouse_1_updown((sunshine.tl.x   + sunshine.br.x) / 2,
+                     (sunshine.tl.y*9 + sunshine.br.y) / 10);
+  sync_after_input();
 
   free(test);
 
   wait_for_stability(&current,0,0, "checking basic YPP client screen...");
-  mouse_1_updown(250, wheight-10);
-  mouse_1_updown_here();
-  mouse_1_updown_here();
-  XSync(disp,False);
+  send_mouse_1_updown(250, wheight-10);
+  send_mouse_1_updown_here();
+  send_mouse_1_updown_here();
+  sync_after_input();
   check_not_disturbed();
   send_key(XK_slash);
   send_key(XK_w);
@@ -602,37 +628,34 @@ void take_screenshots(void) {
   for (;;) {
     debugf("page %d paging\n",npages);
 
+    pgdown_by_mouse();
+
     if (!(npages < MAX_PAGES))
       fatal("Paging down seems to generate too many pages - max is %d.",
            MAX_PAGES);
 
     convert_store_page(current);
     free_snapshot(&last); last=current; current=0;
-
     debugf("PAGING page %d converted\n",npages);
+    npages++;
 
     wait_for_stability(&current,last, 0,
                       "page %d collecting    ...",
-                      npages+1);
-
-    if (npages &&  /* first pagedown doesn't do much */
-       identical(current,last)) {
-      npages++;
+                      npages);
+    if (identical(current,last)) {
       free_snapshot(&current);
       break;
     }
-
-    pgdown_by_mouse();
-    npages++;
   }
   progress("finishing with the YPP client...");
-  mouse_1_updown(commod_focuslast_point.x, commod_focuslast_point.y);
+  send_mouse_1_updown(commod_focuslast_point.x, commod_focuslast_point.y);
   sync_after_input();
   send_pgdown_torestore();
   sync_after_input();
 
   debugf("PAGING all done.\n");
   progress_log("collected %d screenshots.",npages);
+  check_pager_motion(0,npages);
 }    
 
 void take_one_screenshot(void) {