From 451e1b1ed16a7a53395c030598a83031e266f973 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 7 Jun 2009 13:50:20 +0100 Subject: [PATCH] wip finding window --- pctb/convert.c | 24 ++++++++--- pctb/convert.h | 2 + pctb/ocr.h | 19 +++++---- pctb/pages.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 137 insertions(+), 14 deletions(-) diff --git a/pctb/convert.c b/pctb/convert.c index cdd144a..b44c294 100644 --- a/pctb/convert.c +++ b/pctb/convert.c @@ -11,8 +11,18 @@ void debug_flush(void) { const char *get_vardir(void) { return "."; } -static enum { mode_all=03, mode_screenshot=01, mode_analyse=02 } - o_mode= mode_all; +static enum { + mf_findwindow= 01, + mf_screenshot= 02, + mf_analyse= 04, + + mode_findwindow= 01, + mode_screenshot= 03, + mode_analyse= 04, + + mode_all= 07, +} o_mode= mode_all; + static char *o_screenshots_fn; static int o_single_page; @@ -23,7 +33,9 @@ int main(int argc, char **argv) { int r; while ((arg=*++argv)) { - if (!strcmp(arg,"--screenshot-only")) + if (!strcmp(arg,"--find-window-only")) + o_mode= mode_findwindow; + else if (!strcmp(arg,"--screenshot-only")) o_mode= mode_screenshot; else if (!strcmp(arg,"--analyse-only")) o_mode= mode_analyse; @@ -51,9 +63,11 @@ int main(int argc, char **argv) { eassert(r>=0); eassert(o_screenshots_fn); } - if (o_mode & mode_screenshot) { + if (o_mode & mf_findwindow) { screenshot_startup(); find_yppclient_window(); + } + if (o_mode & mf_screenshot) { screenshots_file= fopen(o_screenshots_fn, "w"); eassert(screenshots_file); if (o_single_page) take_one_screenshot(); @@ -63,7 +77,7 @@ int main(int argc, char **argv) { screenshots_file= fopen(o_screenshots_fn, "r"); eassert(screenshots_file); read_screenshots(); } - if (o_mode & mode_analyse) { + if (o_mode & mf_analyse) { analyse(); //output_tsv(); } diff --git a/pctb/convert.h b/pctb/convert.h index d532c2b..5bb4707 100644 --- a/pctb/convert.h +++ b/pctb/convert.h @@ -34,5 +34,7 @@ void take_one_screenshot(void); extern CanonImage *page_images[MAX_PAGES]; extern int npages; +extern char *ocean, *pirate; + #endif /*CONVERT_H*/ diff --git a/pctb/ocr.h b/pctb/ocr.h index e8b5b1a..5b5f697 100644 --- a/pctb/ocr.h +++ b/pctb/ocr.h @@ -55,10 +55,11 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType, int w, Pixcol cols[]); /*----- debugging arrangements, rather contingent -----*/ #define DEBUG_FLAG_LIST \ - DF(ocr) \ + DF(findypp) \ + DF(pages) \ DF(rect) \ - DF(callout) \ - DF(pages) + DF(ocr) \ + DF(callout) enum { #define DF(f) dbg__shift_##f, @@ -82,13 +83,15 @@ void debug_flush(void); const char *get_vardir(void); -#define DEBUG_DEFINE_DEBUGF(f) \ - static void vdebugf(const char *fmt, va_list al) { \ - if (DEBUGP(f)) \ +#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 debugf(const char *fmt, ...) { \ - va_list al; va_start(al,fmt); vdebugf(fmt,al); va_end(al); \ + static void funcf(const char *fmt, ...) { \ + va_list al; va_start(al,fmt); v##funcf(fmt,al); va_end(al); \ } +#define DEBUG_DEFINE_DEBUGF(fl) DEBUG_DEFINE_SOME_DEBUGF(fl,debugf) + #endif /*OCR_H*/ diff --git a/pctb/pages.c b/pctb/pages.c index 2f4f669..b9e1ac1 100644 --- a/pctb/pages.c +++ b/pctb/pages.c @@ -11,6 +11,8 @@ CanonImage *page_images[MAX_PAGES]; int npages; +char *ocean, *pirate; + static XWindowAttributes attr; static Window id; static Display *disp; @@ -298,7 +300,109 @@ void set_yppclient_window(unsigned long wul) { id= wul; } +DEBUG_DEFINE_SOME_DEBUGF(findypp,debugfind) + void find_yppclient_window(void) { + Window root, gotroot, gotparent; + int screen, r; + int nfound=0; + if (id) return; - eassert(!"finding client window NYI"); + + static const char prefix[]= "Puzzle Pirates - "; + static const char onthe[]= " on the "; + static const char suffix[]= " ocean"; +#define S(x) (sizeof((x))-1) + + Atom wm_name= XInternAtom(disp,"WM_NAME",True); + eassert(wm_name != None); + + for (screen=0; screen=' ' && c<=126) fputc(c,debug); + else fprintf(debug,"\\x%02x",c & 0xff); + } + fputs("\": ",debug); + } + +#define REQUIRE(pred) \ + if (!(pred)) { debugfind(" failed test %s\n", #pred); continue; } \ + else + + REQUIRE( gottype!=None ); + REQUIRE( len ); + REQUIRE( gotfmt==8 ); + + REQUIRE( len >= S(prefix) + 1 + S(onthe) + 1 + S(suffix) ); + + char *spc1= strchr( title + S(prefix), ' '); REQUIRE(spc1); + char *spc2= strrchr((title + len) - S(suffix), ' '); REQUIRE(spc2); + + REQUIRE( (title + len) - spc1 >= S(onthe) + S(suffix) ); + REQUIRE( spc2 - title >= S(prefix) + S(onthe) ); + + REQUIRE( !memcmp(title, prefix, S(prefix)) ); + REQUIRE( !memcmp(title + len - S(suffix), suffix, S(suffix)) ); + REQUIRE( !memcmp(spc1, onthe, S(onthe)) ); + +#define ASSIGN(what, start, end) do { \ + r= asprintf(&what, "%.*s", end - start, start); eassert(r>0); \ + }while(0) + ASSIGN(ocean, title + S(prefix), spc1); + ASSIGN(pirate, spc1 + S(onthe), (title + len) - S(suffix)); + + debugfind(" YES!\n"); + id= w2; + nfound++; + } + if (children2) XFree(children2); + } + if (children1) XFree(children1); + } + eassert(nfound==1); } -- 2.30.2