chiark / gitweb /
cope with the way the chat log scrolls too
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 7 Jun 2009 22:20:08 +0000 (23:20 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 7 Jun 2009 22:20:08 +0000 (23:20 +0100)
pctb/convert.h
pctb/pages.c
pctb/structure.c

index e9d00b97de35b8c9cdc4005dfe8351bd766fa01d..7a9e252511942ff899afafce277877f786b4477f 100644 (file)
@@ -40,7 +40,7 @@
 
 /*----- from structure.c -----*/
 
-void find_structure(CanonImage *im);
+void find_structure(CanonImage *im, int *max_relevant_y_r);
 void read_screenshots(void);
 void read_one_screenshot(void);
 void analyse(FILE *tsv_output);
index 04847107dde3f599473befe8f18c20ca0999d520..1abc5ed63528e4fbc1881f05b88e04bddb08fdec 100644 (file)
@@ -47,6 +47,7 @@ static Window id;
 static Display *disp;
 static struct timeval tv_startup;
 static unsigned wwidth, wheight;
+static int max_relevant_y= -1;
 
 DEBUG_DEFINE_DEBUGF(pages)
 
@@ -146,22 +147,36 @@ static void check_not_disturbed(void) {
 }      
 
 static void send_key(KeySym sym) {
+  check_not_disturbed();
   XTestFakeKeyEvent(disp, keycode(sym),1, 10);
   XTestFakeKeyEvent(disp, keycode(sym),0, 10);
 }
 
+static int pgupdown;
+
 static void send_pgup_many(void) {
   int i;
-  for (i=0; i<25; i++)
+  for (i=0; i<25; i++) {
     send_key(XK_Prior);
+    pgupdown--;
+  }
   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) {
+    send_key(XK_Next);
+    pgupdown++;
+  }
+  sync_after_input();
+}
 
 static void free_snapshot(Snapshot **io) {
   if (*io) XDestroyImage(*io);
@@ -188,7 +203,12 @@ static int identical(const Snapshot *a, const Snapshot *b) {
        a->bytes_per_line == b->bytes_per_line &&
        a->format == b->format))
     return 0;
-  return !memcmp(a->data, b->data, a->bytes_per_line * a->height);
+
+  int compare_to= a->height;
+  if (max_relevant_y && compare_to > max_relevant_y)
+    compare_to= max_relevant_y;
+  
+  return !memcmp(a->data, b->data, a->bytes_per_line * compare_to);
 }
 
 static void wait_for_stability(Snapshot **output,
@@ -387,7 +407,7 @@ void take_screenshots(void) {
   raise_and_get_details();
   wait_for_stability(&current,0,0, "checking current YPP client screen...");
   test= convert_page(current);
-  find_structure(test);
+  find_structure(test, &max_relevant_y);
   free(test);
 
   /* page to the top - keep pressing page up until the image stops changing */
@@ -421,6 +441,9 @@ void take_screenshots(void) {
     send_pgdown();
     npages++;
   }
+  progress("finishing with the YPP client...");
+  send_pgdown_torestore();
+
   debugf("PAGING all done.\n");
   progress_log("collected %d screenshots.",npages);
 }    
index 49385a2fb8b89e822562ea7408118aeafc892a82..8fabe1887b9063b12715843046afe9ef72556110 100644 (file)
@@ -161,7 +161,7 @@ static void debug_rect(const char *what, int whati, Rect rr) {
          );                                            \
   }while(0)
 
-void find_structure(CanonImage *im) {
+void find_structure(CanonImage *im, int *max_relevant_y_r) {
   cim= im;
   
   Rect whole = { {0,0}, {cim->w-1,cim->h-1} };
@@ -252,6 +252,8 @@ void find_structure(CanonImage *im) {
 
   SET_ONCE(columns, colno);
   SET_ONCE(text_h, comminty - 1);
+  if (max_relevant_y_r)
+    SET_ONCE(*max_relevant_y_r, mainr.br.y + 10);
 }                  
 
 CanonImage *alloc_canon_image(int w, int h) {
@@ -376,7 +378,7 @@ void analyse(FILE *tsv_output) {
   int page, tryrect, colno;
 
   for (page=0; page<npages; page++) {
-    find_structure(page_images[page]);
+    find_structure(page_images[page], 0);
 
     if (!rd)
       rd= ocr_init(text_h);