From a2a2f9d982ee233f3d89fb7137f532c9eec3b97c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 7 Jun 2009 23:20:08 +0100 Subject: [PATCH] cope with the way the chat log scrolls too --- pctb/convert.h | 2 +- pctb/pages.c | 29 ++++++++++++++++++++++++++--- pctb/structure.c | 6 ++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/pctb/convert.h b/pctb/convert.h index e9d00b9..7a9e252 100644 --- a/pctb/convert.h +++ b/pctb/convert.h @@ -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); diff --git a/pctb/pages.c b/pctb/pages.c index 0484710..1abc5ed 100644 --- a/pctb/pages.c +++ b/pctb/pages.c @@ -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(¤t,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); } diff --git a/pctb/structure.c b/pctb/structure.c index 49385a2..8fabe18 100644 --- a/pctb/structure.c +++ b/pctb/structure.c @@ -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