chiark / gitweb /
progress displaying; some client window geometry checking
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 7 Jun 2009 14:49:31 +0000 (15:49 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 7 Jun 2009 14:49:31 +0000 (15:49 +0100)
pctb/convert.c
pctb/convert.h
pctb/ocr.h
pctb/pages.c

index b44c294bd212a7072afa7ffabee6905350d10223..d0c113cbcdcadc2c033b567c3a7f93f69ec8cefd 100644 (file)
@@ -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);
+}
index 5bb4707b50d4fdfbf21e8b834572cf69f97e19df..853fef50639427c291de89444795393855bf7a98 100644 (file)
@@ -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);
index 5b5f697dbd88603a37dd8f518f91308c39192dfb..5371c75b631ac61ea29db285d883ffc99c416875 100644 (file)
@@ -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)
 
index b9e1ac1649dc2c5aa8a57997e58cabba430b54f1..99f4af2adb562be8e340981f78f5b0416b0e17b3 100644 (file)
@@ -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<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");
 }
 
@@ -399,6 +439,8 @@ void find_yppclient_window(void) {
        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);
     }