Index: /trunk/Ohana/src/kapa/event/Refresh.c
===================================================================
--- /trunk/Ohana/src/kapa/event/Refresh.c	(revision 5353)
+++ /trunk/Ohana/src/kapa/event/Refresh.c	(revision 5354)
@@ -4,6 +4,7 @@
 
   int i;
+  
+  if (HAVE_BACKING) return;
 
-  
   /* XClearWindow   (graphic.display, graphic.window); */
   XSetForeground (graphic.display, graphic.gc, graphic.back);
Index: /trunk/Ohana/src/kapa/graph/cursor.c
===================================================================
--- /trunk/Ohana/src/kapa/graph/cursor.c	(revision 5353)
+++ /trunk/Ohana/src/kapa/graph/cursor.c	(revision 5354)
@@ -1,7 +1,11 @@
 # include "Ximage.h"
-# define EventMask (long) (KeyPressMask | ExposureMask | StructureNotifyMask | ButtonPressMask)
+
+# define IgnoreMask (long) (ClientMessage | ButtonReleaseMask | PointerMotionMask)
+
+int LastEvent (Display *display, int type, XEvent *event);
 
 int cursor () {
 
+  Display        *display;
   XEvent          event;
   KeySym          keysym;
@@ -22,94 +26,77 @@
     buffer[4] = 0;
     
-    switch (status) {
-      case -1:
-	/* no input from pipe: continue */
-	break;
-      
-      case 0:
-	fprintf (stderr, "pipe has died!\n");
-	return (FALSE);
-	break;
+    if (status == -1) goto events;
+    if (status ==  0) return (FALSE);
+    if (status ==  4) {
+      if (!strcmp (buffer, "NCUR")) return (TRUE);
+      goto events;
+    }
+    fprintf (stderr, "weird signal: too many or few bytes!  %d\n", status);
+    return (TRUE);
 
-      case 4:
-	if (!strcmp (buffer, "NCUR")) {  /* stop reading cursor */
-	  return (TRUE);
-	}
-	break;
-
-      default:
-	fprintf (stderr, "weird signal: too many or few bytes!  %d\n", status);
-	return (TRUE);
-	break;
-    }
-
+  events:
     if (XEventsQueued (graphic.display, QueuedAfterFlush) < 1){
-      usleep (10000);
+      usleep (50000);
       continue;
     }
 
     /* check for x events */
-    if (XCheckMaskEvent (graphic.display, EVENT_MASK, &event)) {
-      
-      switch (event.type)  {
+    display = graphic.display;
 
-	case MotionNotify:
-	  break;
+    /* grab the last entry for these events */
+    if (LastEvent (display, ConfigureNotify, &event)) Reconfig (&event);
+    if (LastEvent (display, CirculateNotify, &event)) Reconfig (&event);
+    if (LastEvent (display, Expose,          &event)) Refresh (1);
 
-	case Expose:
-	  if (HAVE_BACKING) {
-	    continue;
-	  }
-	  if (XEventsQueued (graphic.display, QueuedAlready) < 2) {
-	    Refresh (1);
-	  }
-	  break;
+    if (LastEvent (display, MappingNotify,   &event)) XRefreshKeyboardMapping ((XMappingEvent *) &event);
 	
-	case ConfigureNotify:
-	  status = Reconfig (&event);
-	  break;
-	
-	case MappingNotify:
-	  XRefreshKeyboardMapping ((XMappingEvent *) &event);
-	  break;
-	
-	case ButtonPress:
-	  mouse_event = (XButtonEvent *) &event;
-	  sprintf (string, "Button%d", mouse_event[0].button);
-	  x = (mouse_event[0].x - layout[0].axis[0].fx)*(layout[0].axis[0].max - layout[0].axis[0].min)/layout[0].axis[0].dfx + layout[0].axis[0].min;
-	  y = (mouse_event[0].y - layout[0].axis[1].fy)*(layout[0].axis[1].max - layout[0].axis[1].min)/layout[0].axis[1].dfy + layout[0].axis[1].min;
-	  snprintf (line, 40, "%12s %12.6f %12.6f ", string, x, y);
-	  write (sock, line, 40);
-	  break;
+    /* drop and ignore the following StructureNotifyMask events */
+    LastEvent (display, GravityNotify, &event);
+    LastEvent (display, ReparentNotify, &event);
+    LastEvent (display, MapNotify, &event);
+    LastEvent (display, UnmapNotify, &event);
 
-	case KeyPress:
-	  value = XLookupString ((XKeyEvent *) &event, string, 9, &keysym, &composestatus);
-	  name = XKeysymToString (keysym);
+    /* handle button presses */
+    if (LastEvent (display, ButtonPress,     &event)) {
+      mouse_event = (XButtonEvent *) &event;
+      sprintf (string, "Button%d", mouse_event[0].button);
+      x = (mouse_event[0].x - layout[0].axis[0].fx)*(layout[0].axis[0].max - layout[0].axis[0].min)/layout[0].axis[0].dfx + layout[0].axis[0].min;
+      y = (mouse_event[0].y - layout[0].axis[1].fy)*(layout[0].axis[1].max - layout[0].axis[1].min)/layout[0].axis[1].dfy + layout[0].axis[1].min;
+      snprintf (line, 40, "%12s %12.6f %12.6f ", string, x, y);
+      write (sock, line, 40);
+    }
 
-	  x = (event.xkey.x - layout[0].axis[0].fx)*(layout[0].axis[0].max - layout[0].axis[0].min)/layout[0].axis[0].dfx + layout[0].axis[0].min;
-	  y = (event.xkey.y - layout[0].axis[1].fy)*(layout[0].axis[1].max - layout[0].axis[1].min)/layout[0].axis[1].dfy + layout[0].axis[1].min;
+    /* handle key presses */
+    if (LastEvent (display, KeyPress,        &event)) {
+      value = XLookupString ((XKeyEvent *) &event, string, 9, &keysym, &composestatus);
+      name = XKeysymToString (keysym);
 
-	  // skip the following keys: 
-	  if (!strcmp (name, "Shift_L")) break;
-	  if (!strcmp (name, "Shift_R")) break;
-	  if (!strcmp (name, "Control_L")) break;
-	  if (!strcmp (name, "Control_R")) break;
-	  if (!strcmp (name, "Alt_L")) break;
-	  if (!strcmp (name, "Alt_R")) break;
-	  if (!strcmp (name, "Super_L")) break;
-	  if (!strcmp (name, "Super_R")) break;
-	  if (!strcmp (name, "Caps_Lock")) break;
-	  if (!strcmp (name, "Pause")) break;
-	  if (!strcmp (name, "Break")) break;
-	  if (!strcmp (name, "Num_Lock")) break;
-	  if (!strcmp (name, "Scroll_Lock")) break;
-	  if (!strcmp (name, "Print")) break;
-	  if (!strcmp (name, "(null)")) break;
+      x = (event.xkey.x - layout[0].axis[0].fx)*(layout[0].axis[0].max - layout[0].axis[0].min)/layout[0].axis[0].dfx + layout[0].axis[0].min;
+      y = (event.xkey.y - layout[0].axis[1].fy)*(layout[0].axis[1].max - layout[0].axis[1].min)/layout[0].axis[1].dfy + layout[0].axis[1].min;
 
-	  snprintf (line, 40, "%12s %12.6f %12.6f ", name, x, y);
-	  write (sock, line, 40);
-	  break;
-      }
+      // skip the following keys: 
+      if (!strcmp (name, "Shift_L")) continue;
+      if (!strcmp (name, "Shift_R")) continue;
+      if (!strcmp (name, "Control_L")) continue;
+      if (!strcmp (name, "Control_R")) continue;
+      if (!strcmp (name, "Alt_L")) continue;
+      if (!strcmp (name, "Alt_R")) continue;
+      if (!strcmp (name, "Super_L")) continue;
+      if (!strcmp (name, "Super_R")) continue;
+      if (!strcmp (name, "Caps_Lock")) continue;
+      if (!strcmp (name, "Pause")) continue;
+      if (!strcmp (name, "Continue")) continue;
+      if (!strcmp (name, "Num_Lock")) continue;
+      if (!strcmp (name, "Scroll_Lock")) continue;
+      if (!strcmp (name, "Print")) continue;
+      if (!strcmp (name, "(null)")) continue;
+
+      snprintf (line, 40, "%12s %12.6f %12.6f ", name, x, y);
+      write (sock, line, 40);
     }
+
+    /* remove those events we will ignore */
+    while (XCheckMaskEvent (display, IgnoreMask, &event)) continue;
   }
+  return (FALSE);
 }
