chiark / gitweb /
page with the mouse to avoid the silly page-back-to-top effect 1.9.4
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 5 Jul 2009 23:51:21 +0000 (00:51 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 5 Jul 2009 23:51:21 +0000 (00:51 +0100)
pctb/convert.h
pctb/pages.c
pctb/structure.c

index 44784ea..ffa80eb 100644 (file)
@@ -70,7 +70,9 @@ static inline Rgb ri_rgb(const RgbImage *ri, int x, int y) {
 /*----- from structure.c -----*/
 
 void find_structure(CanonImage *im, int *max_relevant_y_r,
 /*----- from structure.c -----*/
 
 void find_structure(CanonImage *im, int *max_relevant_y_r,
-                   Point *commod_focus_point_r);
+                   Point *commod_focus_point_r,
+                   Point *commod_page_point_r,
+                   Point *commod_focuslast_point_r);
 Rect find_sunshine_widget(void);
 
 void canon_colour_prepare(void);
 Rect find_sunshine_widget(void);
 
 void canon_colour_prepare(void);
index ecec334..72f9bb4 100644 (file)
@@ -52,7 +52,7 @@ static Display *disp;
 static struct timeval tv_startup;
 static unsigned wwidth, wheight;
 static int max_relevant_y= -1;
 static struct timeval tv_startup;
 static unsigned wwidth, wheight;
 static int max_relevant_y= -1;
-static Point commod_focus_point;
+static Point commod_focus_point, commod_page_point, commod_focuslast_point;
 
 static XImage *shmim;
 static XShmSegmentInfo shminfo;
 
 static XImage *shmim;
 static XShmSegmentInfo shminfo;
@@ -105,6 +105,9 @@ static void translate_coords_toroot(int wx, int wy, int *rx, int *ry) {
   Window dummy;
   xassert( XTranslateCoordinates(disp, id,attr.root, wx,wy, rx,ry, &dummy) );
 }
   Window dummy;
   xassert( XTranslateCoordinates(disp, id,attr.root, wx,wy, rx,ry, &dummy) );
 }
+static void translate_coords_toroot_p(Point w, int *rx, int *ry) {
+  translate_coords_toroot(w.x, w.y, rx, ry);
+}
 
 static void check_client_window_all_on_screen(void) {
   Rect onroot;
 
 static void check_client_window_all_on_screen(void) {
   Rect onroot;
@@ -161,8 +164,8 @@ static void send_key(KeySym sym) {
 }
 static void mouse_1_updown_here(void) {
   check_not_disturbed();
 }
 static void mouse_1_updown_here(void) {
   check_not_disturbed();
-  XTestFakeButtonEvent(disp,1,1, 50);
-  XTestFakeButtonEvent(disp,1,0, 50);
+  XTestFakeButtonEvent(disp,1,1, 10);
+  XTestFakeButtonEvent(disp,1,0, 10);
 }
 static void mouse_1_updown(int x, int y) {
   check_not_disturbed();
 }
 static void mouse_1_updown(int x, int y) {
   check_not_disturbed();
@@ -172,6 +175,12 @@ static void mouse_1_updown(int x, int y) {
   XTestFakeMotionEvent(disp, screen, xpos,ypos, 0);
   mouse_1_updown_here();
 }
   XTestFakeMotionEvent(disp, screen, xpos,ypos, 0);
   mouse_1_updown_here();
 }
+static void pgdown_by_mouse(void) {
+  check_not_disturbed();
+  debugf("PAGING   Mouse\n");
+  mouse_1_updown_here();
+  sync_after_input();
+}
 
 static int pgupdown;
 
 
 static int pgupdown;
 
@@ -184,12 +193,6 @@ static void send_pgup_many(void) {
   debugf("PAGING   PageUp x %d\n",i);
   sync_after_input();
 }
   debugf("PAGING   PageUp x %d\n",i);
   sync_after_input();
 }
-static void send_pgdown(void) {
-  send_key(XK_Next);
-  pgupdown++;
-  debugf("PAGING   PageDown\n");
-  sync_after_input();
-}
 static void send_pgdown_torestore(void) {
   debugf("PAGING   PageDown x %d\n", -pgupdown);
   while (pgupdown < 0) {
 static void send_pgdown_torestore(void) {
   debugf("PAGING   PageDown x %d\n", -pgupdown);
   while (pgupdown < 0) {
@@ -509,8 +512,8 @@ static void set_focus_commodity(void) {
                        ) );
 
   int xpos,ypos;
                        ) );
 
   int xpos,ypos;
-  translate_coords_toroot(10,10, &xpos,&ypos);
-  XTestFakeMotionEvent(disp,screen, xpos,ypos, 0);
+  translate_coords_toroot_p(commod_page_point, &xpos,&ypos);
+  XTestFakeMotionEvent(disp, screen, xpos,ypos, 0);
 
   sync_after_input();
 
 
   sync_after_input();
 
@@ -544,7 +547,10 @@ static void prepare_ypp_client(void) {
   wait_for_stability(&current,0,0, "checking current YPP client screen...");
 
   test= convert_page(current);
   wait_for_stability(&current,0,0, "checking current YPP client screen...");
 
   test= convert_page(current);
-  find_structure(test, &max_relevant_y, &commod_focus_point);
+  find_structure(test, &max_relevant_y,
+                &commod_focus_point,
+                &commod_page_point,
+                &commod_focuslast_point);
   check_correct_commodities();
   Rect sunshine= find_sunshine_widget();
 
   check_correct_commodities();
   Rect sunshine= find_sunshine_widget();
 
@@ -604,11 +610,14 @@ void take_screenshots(void) {
       break;
     }
 
       break;
     }
 
-    send_pgdown();
+    pgdown_by_mouse();
     npages++;
   }
   progress("finishing with the YPP client...");
     npages++;
   }
   progress("finishing with the YPP client...");
+  mouse_1_updown(commod_focuslast_point.x, commod_focuslast_point.y);
+  sync_after_input();
   send_pgdown_torestore();
   send_pgdown_torestore();
+  sync_after_input();
 
   debugf("PAGING all done.\n");
   progress_log("collected %d screenshots.",npages);
 
   debugf("PAGING all done.\n");
   progress_log("collected %d screenshots.",npages);
index 85b8f86..ad95cb5 100644 (file)
@@ -256,7 +256,9 @@ static int commod_selector_matches(Rect search, const char *const *all,
   }
 
 void find_structure(CanonImage *im, int *max_relevant_y_r,
   }
 
 void find_structure(CanonImage *im, int *max_relevant_y_r,
-                   Point *commod_focus_point_r) {
+                   Point *commod_focus_point_r,
+                   Point *commod_page_point_r,
+                   Point *commod_focuslast_point_r) {
   cim= im;
   
   Rect whole = { {0,0}, {cim->w-1,cim->h-1} };
   cim= im;
   
   Rect whole = { {0,0}, {cim->w-1,cim->h-1} };
@@ -293,6 +295,7 @@ void find_structure(CanonImage *im, int *max_relevant_y_r,
     Point csb_p;                                       \
     Rect csb_r;                                                \
     csb_p= mainr.tl;                                   \
     Point csb_p;                                       \
     Rect csb_r;                                                \
     csb_p= mainr.tl;                                   \
+    csb_p.x++; csb_p.y++;                              \
     csb_p.xy= mainr.tlbr.xy;                           \
     if (get_p(csb_p)=='+') {                           \
       csb_r= mainr;                                    \
     csb_p.xy= mainr.tlbr.xy;                           \
     if (get_p(csb_p)=='+') {                           \
       csb_r= mainr;                                    \
@@ -355,6 +358,23 @@ void find_structure(CanonImage *im, int *max_relevant_y_r,
   }
   MUST( colno >= MIN_COLUMNS, MI(colno);MR(mainr);MR(across); );
 
   }
   MUST( colno >= MIN_COLUMNS, MI(colno);MR(mainr);MR(across); );
 
+  const int pagerh= 6;
+  Rect pager= {{ mainr.br.x,     mainr.br.y - (pagerh-1) },
+              { mainr.br.x + 1, mainr.br.y              }};
+
+  debug_rect("pager",__LINE__,pager);
+  ADJUST_BOX(pager, "o",>=,pagerh-2, whole.br.x,MUST, br,x,+1);
+  debug_rect("pager",__LINE__,pager);
+
+  pager.tl.x= pager.br.x;
+  pager.br.x= pager.br.x + 1;
+  debug_rect("pager",__LINE__,pager);
+  ADJUST_BOX(pager, "o",>=,pagerh-2, whole.br.x,MUST, br,x,+1);
+  debug_rect("pager",__LINE__,pager);
+
+  ADJUST_BOX(pager, "o",>=,RECT_W(pager)-2, mainr.tl.y,LIMIT_QUITEQ, tl,y,-1);
+  debug_rect("pager",__LINE__,pager);
+
 #define SET_ONCE(var,val) do{                                          \
     int v= (val);                                                      \
     if ((var)==-1) (var)= v;                                           \
 #define SET_ONCE(var,val) do{                                          \
     int v= (val);                                                      \
     if ((var)==-1) (var)= v;                                           \
@@ -371,6 +391,15 @@ void find_structure(CanonImage *im, int *max_relevant_y_r,
     commod_focus_point_r->x += 10;
     commod_focus_point_r->y += comminty/3;
   }
     commod_focus_point_r->x += 10;
     commod_focus_point_r->y += comminty/3;
   }
+  if (commod_focuslast_point_r) {
+    *commod_focuslast_point_r= mainr.br;
+    commod_focuslast_point_r->x -= 10;
+    commod_focuslast_point_r->y -= comminty/3;
+  }
+  if (commod_page_point_r) {
+    commod_page_point_r->x= (pager.tl.x + pager.br.x) / 2;
+    commod_page_point_r->y=  pager.tl.y - 1;
+  }
 
   MUST( text_h <= OCR_MAX_H, MI(text_h) );
 }                  
 
   MUST( text_h <= OCR_MAX_H, MI(text_h) );
 }                  
@@ -639,7 +668,7 @@ void analyse(FILE *tsv_output) {
   int page, tryrect, colno;
 
   for (page=0; page<npages; page++) {
   int page, tryrect, colno;
 
   for (page=0; page<npages; page++) {
-    find_structure(page_images[page], 0, 0);
+    find_structure(page_images[page], 0,0,0,0);
 
     if (!page)
       check_correct_commodities();
 
     if (!page)
       check_correct_commodities();
@@ -700,7 +729,7 @@ Rect find_sunshine_widget(void) {
 }
 
 void find_islandname(void) {
 }
 
 void find_islandname(void) {
-  find_structure(page_images[0], 0, 0);
+  find_structure(page_images[0], 0,0,0,0);
 
   RgbImage *ri= alloc_rgb_image(page_images[0]->rgb->w,
                                page_images[0]->rgb->h);
 
   RgbImage *ri= alloc_rgb_image(page_images[0]->rgb->w,
                                page_images[0]->rgb->h);