X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.main.git;a=blobdiff_plain;f=pctb%2Fpages.c;h=482c959c24261cf541ca0ea4e99b63ddf7e51e4e;hp=d298ac4597cd7096e7f733b65d97228fdc25a52a;hb=f2358d0ea7b40ba405621947513f48108ca93504;hpb=dac0bb3ca1c725ef968a07bb89fa96ebdc7fb0b9 diff --git a/pctb/pages.c b/pctb/pages.c index d298ac4..482c959 100644 --- a/pctb/pages.c +++ b/pctb/pages.c @@ -553,6 +553,7 @@ static void prepare_ypp_client(void) { void take_screenshots(void) { Snapshot *current=0, *last=0; + RgbImage *page0_store; prepare_ypp_client(); @@ -561,6 +562,8 @@ void take_screenshots(void) { wait_for_stability(¤t,0, send_pgup_many, "paging up to top of commodity list..."); + page0_rgbimage= page0_store= alloc_rgb_image(current->w, current->h); + /* now to actually page down */ for (;;) { debugf("paging page %d\n",npages); @@ -569,8 +572,8 @@ void take_screenshots(void) { fatal("Paging down seems to generate too many pages - max is %d.", MAX_PAGES); - page_images[npages]= convert_page(current, 0); - free_snapshot(&last); last=current; current=0; + page_images[npages]= convert_page(current, page0_store); + free_snapshot(&last); last=current; current=0; page0_store=0; debugf("PAGING page %d converted\n",npages); @@ -592,6 +595,7 @@ void take_screenshots(void) { debugf("PAGING all done.\n"); progress_log("collected %d screenshots.",npages); + assert(!page0_store); } void take_one_screenshot(void) { @@ -611,112 +615,116 @@ void set_yppclient_window(unsigned long wul) { DEBUG_DEFINE_SOME_DEBUGF(findypp,debugfind) +static int nfound; +static Atom wm_name; +static int screen; + +static void findypp_recurse(int depth, int targetdepth, Window w) { + unsigned int nchildren; + int i; + Window *children=0; + Window gotroot, gotparent; + + static const char prefix[]= "Puzzle Pirates - "; + static const char onthe[]= " on the "; + static const char suffix[]= " ocean"; +#define S(x) (sizeof((x))-1) + + debugfind("FINDYPP %d/%d screen %d %*s %lx", + depth,targetdepth,screen, + depth,"",(unsigned long)w); + + if (depth!=targetdepth) { + xassert( XQueryTree(disp,w, + &gotroot,&gotparent, + &children,&nchildren) ); + debugfind(" nchildren=%d\n",nchildren); + + for (i=0; i=' ' && 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); return; } \ + 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) \ + what= masprintf("%.*s", (end)-(start), start); \ + if (o_##what) REQUIRE( !strcasecmp(o_##what, what) ); \ + else + + ASSIGN(ocean, spc1 + S(onthe), (title + len) - S(suffix)); + ASSIGN(pirate, title + S(prefix), spc1); + + debugfind(" YES!\n"); + id= w; + nfound++; + progress_log("found YPP client (0x%lx):" + " %s ocean - %s.", + (unsigned long)id, ocean, pirate); +} + void find_yppclient_window(void) { - Window root, gotroot, gotparent; - int screen; - int nfound=0; + int targetdepth; + + nfound=0; if (id) return; progress("looking for YPP client window..."); - static const char prefix[]= "Puzzle Pirates - "; - static const char onthe[]= " on the "; - static const char suffix[]= " ocean"; -#define S(x) (sizeof((x))-1) + xassert( (wm_name= XInternAtom(disp,"WM_NAME",True)) != None); - Atom wm_name= XInternAtom(disp,"WM_NAME",True); - xassert(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) \ - what= masprintf("%.*s", (end)-(start), start); \ - if (o_##what) REQUIRE( !strcasecmp(o_##what, what) ); \ - else - - ASSIGN(ocean, spc1 + S(onthe), (title + len) - S(suffix)); - ASSIGN(pirate, title + S(prefix), spc1); - - debugfind(" YES!\n"); - id= w2; - nfound++; - progress_log("found YPP client (0x%lx):" - " %s ocean - %s.", - (unsigned long)id, ocean, pirate); - } - if (children2) XFree(children2); + for (targetdepth=1; targetdepth<4; targetdepth++) { + for (screen=0; screen1) fatal("Found several possible YPP clients. Close one,\n" " disambiguate with --pirate or --ocean,"