From: Ian Jackson Date: Sun, 7 Jun 2009 14:49:31 +0000 (+0100) Subject: progress displaying; some client window geometry checking X-Git-Tag: 1.9.2~155 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-test.git;a=commitdiff_plain;h=4903e3f2fbd534bde1bc3ebc4d84328297e0b388 progress displaying; some client window geometry checking --- diff --git a/pctb/convert.c b/pctb/convert.c index b44c294..d0c113c 100644 --- a/pctb/convert.c +++ b/pctb/convert.c @@ -10,7 +10,6 @@ void debug_flush(void) { const char *get_vardir(void) { return "."; } - static enum { mf_findwindow= 01, mf_screenshot= 02, @@ -24,7 +23,7 @@ static enum { } o_mode= mode_all; static char *o_screenshots_fn; -static int o_single_page; +static int o_single_page, o_quiet; FILE *screenshots_file; @@ -41,6 +40,8 @@ int main(int argc, char **argv) { o_mode= mode_analyse; else if (!strcmp(arg,"--single-page")) o_single_page= 1; + else if (!strcmp(arg,"--quiet")) + o_quiet= 1; else if (!strcmp(arg,"--screenshots-file")) eassert( o_screenshots_fn= *++argv ); #define DF(f) \ @@ -83,3 +84,41 @@ int main(int argc, char **argv) { } return 0; } + + + + +DEFINE_VWRAPPERF(, progress) +DEFINE_VWRAPPERF(, progress_log) + +static int last_progress_len; + +void vprogress(const char *fmt, va_list al) { + int r; + + if (o_quiet) return; + if (!isatty(2)) return; + + if (last_progress_len) + putc('\r',stderr); + + r= vfprintf(stderr,fmt,al); + eassert(r>=0); + + if (r < last_progress_len) { + fprintf(stderr,"%*s", last_progress_len - r, ""); + if (!r) putc('\r', stderr); + else while (last_progress_len-- > r) putc('\b',stderr); + } + last_progress_len= r; + fflush(stderr); +} + +void vprogress_log(const char *fmt, va_list al) { + if (o_quiet) return; + + progress(""); + vfprintf(stderr,fmt,al); + putc('\n',stderr); + fflush(stderr); +} diff --git a/pctb/convert.h b/pctb/convert.h index 5bb4707..853fef5 100644 --- a/pctb/convert.h +++ b/pctb/convert.h @@ -22,6 +22,12 @@ void analyse(void); extern FILE *screenshots_file; +void vprogress(const char *fmt, va_list); +void progress(const char *fmt, ...); + +void vprogress_log(const char *fmt, va_list); +void progress_log(const char *fmt, ...); + /*----- from pages.c -----*/ void screenshot_startup(void); diff --git a/pctb/ocr.h b/pctb/ocr.h index 5b5f697..5371c75 100644 --- a/pctb/ocr.h +++ b/pctb/ocr.h @@ -83,14 +83,17 @@ void debug_flush(void); const char *get_vardir(void); +#define DEFINE_VWRAPPERF(decls, funcf) \ + decls void funcf(const char *fmt, ...) { \ + va_list al; va_start(al,fmt); v##funcf(fmt,al); va_end(al); \ + } + #define DEBUG_DEFINE_SOME_DEBUGF(fl,funcf) \ static void v##funcf(const char *fmt, va_list al) { \ if (DEBUGP(fl)) \ vfprintf(debug,fmt,al); \ } \ - static void funcf(const char *fmt, ...) { \ - va_list al; va_start(al,fmt); v##funcf(fmt,al); va_end(al); \ - } + DEFINE_VWRAPPERF(static, funcf) #define DEBUG_DEFINE_DEBUGF(fl) DEBUG_DEFINE_SOME_DEBUGF(fl,debugf) diff --git a/pctb/pages.c b/pctb/pages.c index b9e1ac1..99f4af2 100644 --- a/pctb/pages.c +++ b/pctb/pages.c @@ -18,7 +18,6 @@ static Window id; static Display *disp; static struct timeval tv_startup; static unsigned wwidth, wheight; -static int wxpos, wypos; DEBUG_DEFINE_DEBUGF(pages) @@ -28,6 +27,7 @@ static KeyCode keycode(KeySym sym) { void screenshot_startup(void) { int r; + progress("starting..."); disp= XOpenDisplay(0); eassert(disp); r= gettimeofday(&tv_startup,0); eassert(!r); } @@ -152,41 +152,81 @@ static void wait_for_stability(Snapshot **output, 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); +} + static void raise_and_get_details(void) { int r; int evbase,errbase,majver,minver; + int wxpos, wypos; unsigned bd,depth; Window dummy; - + + progress("raising and checking YPP client window ...\n"); + debugf("PAGING raise_and_get_details\n"); r= XTestQueryExtension(disp, &evbase,&errbase,&majver,&minver); eassert(r==True); r= XRaiseWindow(disp, id); eassert(r); + /* in case VisibilityNotify triggers right away before we have had a + * change to raise; to avoid falsely detecting lowering in that case */ + + r= XSelectInput(disp, id, + StructureNotifyMask| + VisibilityChangeMask + ); eassert(r); + + r= XRaiseWindow(disp, id); eassert(r); + /* in case the window was lowered between our Raise and our SelectInput; + * to avoid failing to detect that lowering */ r= XGetWindowAttributes(disp, id, &attr); eassert(r); r= XGetGeometry(disp,id, &attr.root, &wxpos,&wypos, &wwidth,&wheight, &bd,&depth); - eassert(r); - r= XTranslateCoordinates(disp, id,attr.root, 160,160, &wxpos,&wypos, - &dummy); - eassert(r); + 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