Package: xwrits
Version: 2.21-5
Severity: important
Tags: patch

A couple of weeks ago I upgraded from xwrits 2.21-3 to 2.21-5.  Since
then my wrists have started hurting, and I've found it's because the
synthetic events patch added in that version is broken, so I haven't
been getting the right breaks.  Here's what I think is happening.

The main problem is that synthetic events are causing wait_x_loop()
to return TRAN_REST.  This tells the system that a break just happened,
so whenever there's a synthetic event the break timer is reset.  It should
be returning 0 instead.

Another problem is the fake XEvent used for mouse movement (with +mouse)
isn't being initialized, so it sometimes looks like a synthetic event.
Coupled with the first problem you can get your break timer reset even
if you don't really have any synthetic events.

Here's a fix for those things.

I'm also going to append a 2nd patch which adds some debugging output.
I used this when tracking down the problem.  I'm not suggesting you
apply this to the Debian package, but you might find it useful if you
want to check my work.

-- synthetic events fix -------------------------------------------------------

diff -ur xwrits-2.21-5/rest.c xwrits.fixed/rest.c
--- xwrits-2.21-5/rest.c        2005-06-23 10:05:59.000000000 -0400
+++ xwrits.fixed/rest.c 2005-06-23 12:08:05.000000000 -0400
@@ -12,15 +12,14 @@
 wait_x_loop(XEvent *e, const struct timeval *now)
 {
   struct timeval diff;
+
+  /* ignore synthetic events */
+  if (e->xany.send_event)
+    return 0;
   
   if (e->type == KeyPress || e->type == MotionNotify
       || e->type == ButtonPress) {
       
-    // patch to get xwrits to ignore all synthetic events, provided by
-    // James T Kirk March 2005.
-    if(e->xany.send_event) // this is a synthetic send_event
-    return(TRAN_REST); //whatever tran_rest means it ignores the event
-      
     xwSUBTIME(diff, *now, last_key_time);
     last_key_time = *now;
     
diff -ur xwrits-2.21-5/schedule.c xwrits.fixed/schedule.c
--- xwrits-2.21-5/schedule.c    2002-05-06 19:30:57.000000000 -0400
+++ xwrits.fixed/schedule.c     2005-06-23 12:08:34.000000000 -0400
@@ -273,6 +273,7 @@
               || root_y < ports[i]->last_mouse_y - mouse_sensitivity
               || root_y > ports[i]->last_mouse_y + mouse_sensitivity) {
             XEvent event;
+            memset(&event, 0, sizeof(event));
             event.type = MotionNotify; /* skeletal MotionNotify event */
             if (x_looper && ports[i]->last_mouse_root)
               ret_val = x_looper(&event, &now);

-- enhanced debugging ---------------------------------------------------------

diff -ur xwrits.fixed/main.c xwrits.full/main.c
--- xwrits.fixed/main.c 2002-05-06 20:42:30.000000000 -0400
+++ xwrits.full/main.c  2005-06-23 10:06:15.000000000 -0400
@@ -169,6 +169,28 @@
   va_end(val);
 }
 
+void
+debug(const char *format, ...)
+{
+  va_list val;
+  struct timeval tv;
+  struct tm *ltm;
+  char buf[256];
+
+  if (!verbose)
+    return;
+
+  xwGETTIMEOFDAY(&tv);
+  ltm = localtime(&tv.tv_sec);
+  strftime(buf, sizeof buf, "%H:%M:%S", ltm);
+  fprintf(stderr, "%s.%03d ", buf, tv.tv_usec / 1000);
+  
+  va_start(val, format);
+  vfprintf(stderr, format, val);
+  fprintf(stderr, "\n");
+  va_end(val);
+}
+
 
 
 /* ports and peers */
@@ -410,7 +432,7 @@
     port = find_port(display, e->xdestroywindow.window);
     unschedule_data(A_IDLE_SELECT, (void *)port,
                    (void *)e->xdestroywindow.window);
-    if (verbose)
+    if (0 && verbose)
        fprintf(stderr, "Window 0x%x: destroyed\n", 
(unsigned)e->xdestroywindow.window);
     break;
     
diff -ur xwrits.fixed/rest.c xwrits.full/rest.c
--- xwrits.fixed/rest.c 2005-06-23 12:08:05.000000000 -0400
+++ xwrits.full/rest.c  2005-06-23 12:14:48.000000000 -0400
@@ -13,6 +13,21 @@
 {
   struct timeval diff;
 
+  if (verbose) {
+    struct timeval diff_last_key, diff_wait_over;
+
+    xwSUBTIME(diff_last_key, *now, last_key_time);
+    xwSUBTIME(diff_wait_over, wait_over_time, *now);
+    debug("wait_x_loop diff %4d.%03d left %4d.%03d type %-6s synthetic %s",
+               diff_last_key.tv_sec, diff_last_key.tv_usec / 1000,
+               diff_wait_over.tv_sec, diff_wait_over.tv_usec / 1000,
+                 e->type == KeyPress           ? "key"
+               : e->type == MotionNotify       ? "motion"
+               : e->type == ButtonPress        ? "button"
+                                               : "other",
+             e->xany.send_event ? "yes" : "no");
+  }
+
   /* ignore synthetic events */
   if (e->xany.send_event)
     return 0;
@@ -82,6 +97,11 @@
   /* Schedule wait_over_time */
   xwGETTIME(wait_began_time);
   xwADDTIME(wait_over_time, wait_began_time, *type_time);
+  if (verbose) {
+    time_t o;
+    o = genesis_time.tv_sec + wait_over_time.tv_sec;
+    debug("wait duration %d ends %.24s", type_time->tv_sec, ctime(&o));
+  }
   if (check_quota)
     xwSETTIME(quota_allotment, 0, 0);
 
@@ -108,6 +128,12 @@
     
     /* Wait */
     val = loopmaster(0, wait_x_loop);
+    debug("loopmaster returned %s",
+           !val ? "0"
+           : val == TRAN_AWAKE ? "awake"
+           : val == TRAN_WARN ? "warn"
+           : val == TRAN_REST ? "rest"
+           : "?");
     if (val == TRAN_AWAKE) val = TRAN_WARN; /* patch A_AWAKE case */
     
     /* Adjust the wait time if necessary */
@@ -118,6 +144,8 @@
   
   unschedule(A_FLASH | A_AWAKE);
   assert(val == TRAN_WARN || val == TRAN_REST);
+  debug("wait_for_break ended state %i (%s)", val,
+           val == TRAN_WARN ? "warn" : val == TRAN_REST ? "rest" : "?");
   return val;
 }
 
diff -ur xwrits.fixed/schedule.c xwrits.full/schedule.c
--- xwrits.fixed/schedule.c     2005-06-23 12:08:34.000000000 -0400
+++ xwrits.full/schedule.c      2005-06-23 11:43:46.000000000 -0400
@@ -59,7 +59,7 @@
   
   XSelectInput(display, w, SubstructureNotifyMask);
   created_count++;
-  if (verbose)
+  if (0 && verbose)
       fprintf(stderr, "Window 0x%x: watching for subwindows\n", (unsigned)w);
   
   /* This code ensures that at least register_keystrokes_delay elapses before
@@ -106,9 +106,9 @@
          & (KeyPressMask | KeyReleaseMask))) {
     key_press_selected_count++;
     XSelectInput(port->display, w, SubstructureNotifyMask | KeyPressMask);
-    if (verbose)
+    if (0 && verbose)
       fprintf(stderr, "Window 0x%x: listening for keystrokes\n", (unsigned)w);
-  } else if (verbose)
+  } else if (0 && verbose)
     fprintf(stderr, "Window 0x%x: skipping keystrokes\n", (unsigned)w);
 }
 
diff -ur xwrits.fixed/xwrits.h xwrits.full/xwrits.h
--- xwrits.fixed/xwrits.h       2002-05-06 20:32:23.000000000 -0400
+++ xwrits.full/xwrits.h        2005-06-23 10:06:15.000000000 -0400
@@ -329,6 +329,7 @@
 void error(const char *, ...);
 void warning(const char *, ...);
 void message(const char *, ...);
+void debug(const char *, ...);
 
 #define TRAN_WARN      1
 #define TRAN_CANCEL    2

-------------------------------------------------------------------------------

-- 
Roderick Schertler
[EMAIL PROTECTED]


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to