const char *get_vardir(void) { return "."; }
-
static enum {
mf_findwindow= 01,
mf_screenshot= 02,
} o_mode= mode_all;
static char *o_screenshots_fn;
-static int o_single_page;
+static int o_single_page, o_quiet;
FILE *screenshots_file;
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) \
}
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);
+}
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)
static Display *disp;
static struct timeval tv_startup;
static unsigned wwidth, wheight;
-static int wxpos, wypos;
DEBUG_DEFINE_DEBUGF(pages)
void screenshot_startup(void) {
int r;
+ progress("starting...");
disp= XOpenDisplay(0); eassert(disp);
r= gettimeofday(&tv_startup,0); eassert(!r);
}
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<rwidth && rypos<rheight);
}
static void set_focus(void) {
int screen= XScreenNumberOfScreen(attr.screen);
+ progress("taking control of YPP client window ...\n");
+
debugf("PAGING set_focus\n");
- XTestFakeMotionEvent(disp,screen, wxpos,wypos, 0);
+ int xpos, ypos;
+ translate_coords_toroot(160,160, &xpos,&ypos);
+ XTestFakeMotionEvent(disp,screen, xpos,ypos, 0);
XTestFakeButtonEvent(disp,1,1, 50);
XTestFakeButtonEvent(disp,1,0, 50);
sync_after_input();
+
+ translate_coords_toroot(10,10, &xpos,&ypos);
+ XTestFakeMotionEvent(disp,screen, xpos,ypos, 0);
+
+ sync_after_input();
+
debugf("PAGING raise_and_set_focus done.\n");
}
debugfind(" YES!\n");
id= w2;
nfound++;
+ progress_log("found YPP client window 0x%lx: %s on the %s ocean\n",
+ (unsigned long)id, pirate, ocean);
}
if (children2) XFree(children2);
}