Index: trunk/Ohana/src/kii/picture/cursor.c
===================================================================
--- trunk/Ohana/src/kii/picture/cursor.c	(revision 2888)
+++ trunk/Ohana/src/kii/picture/cursor.c	(revision 2889)
@@ -1,86 +1,57 @@
 # include "Ximage.h"
+
+int LastEvent (Display *display, int type, XEvent *event);
 
 int cursor (Graphic *graphic, Layout *layout) {
 
+  Display        *display;
   XEvent          event;
   KeySym          keysym;
-  int             status, xstatus, value;
+  int             status, value;
   XComposeStatus  composestatus;
   char            string[10], line[500];
   double          x, y;
-  char            buffer[1024];
   
   while (1) {
     
-    status = read (layout[0].Ximage, buffer, 4);
-    buffer[4] = 0;
-    
-    switch (status) {
-    case -1:
-      /* no input from pipe: continue */
-      break;
-      
-    case 0:
-      fprintf (stderr, "pipe has died!\n");
-      return (FALSE);
-      break;
+    status = CheckPipe (graphic, layout);
+    if (status == 0) return (FALSE);
+    if (status == 2) return (TRUE);
+    if (status == 1) goto events;
 
-    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[0].display, QueuedAfterFlush) < 1) {
+      usleep (10000);
+      continue;
     }
 
-    if ((xstatus = XCheckMaskEvent (graphic[0].display, EVENT_MASK, &event))) {
+    display = graphic[0].display;
+
+    /* only do the last entry for these events */
+    /* this ignores the return status from these functions */
+    if (LastEvent (display, ConfigureNotify, &event)) Reconfig (graphic, layout, &event);
+    if (LastEvent (display, Expose,          &event)) Refresh (graphic, layout, 1);
+    if (LastEvent (display, MappingNotify,   &event)) XRefreshKeyboardMapping ((XMappingEvent *) &event);
+    if (LastEvent (display, MotionNotify,    &event)) UpdatePointer (graphic, layout, (XMotionEvent *) &event);
+    if (LastEvent (display, ButtonPress,     &event)) InterpretPresses (graphic, layout, (XButtonEvent *) &event);
+
+    if (LastEvent (display, KeyPress,        &event)) {
+      value = XLookupString ((XKeyEvent *) &event, string, 9, &keysym, &composestatus);
       
-      switch (event.type)  {
+      if ((event.xkey.x >= layout[0].picture.x) && (event.xkey.x <= layout[0].picture.x + layout[0].picture.dx) &&
+	  (event.xkey.y >= layout[0].picture.y) && (event.xkey.y <= layout[0].picture.y + layout[0].picture.dy)) {
 	
-      case ButtonPress:
-	status = InterpretPresses (graphic, layout, (XButtonEvent *) &event);
-	break;
-	
-      case Expose:
-	if (event.xexpose.count == 0)
-	  Refresh (graphic, layout, 1);
-	break;
-	
-      case ConfigureNotify:
-	status =  Reconfig (graphic, layout, &event);
-	break;
-	
-      case MappingNotify:
-	XRefreshKeyboardMapping ((XMappingEvent *) &event);
-	break;
-	
-      case MotionNotify:
-	if (XPending (graphic[0].display) < 2) {
-	  UpdatePointer (graphic, layout, (XMotionEvent *) &event);
+	Screen_to_Image (&x, &y, (double)event.xkey.x, (double)event.xkey.y, layout);
+
+	if (isprint(string[0]))
+	  sprintf (line, "%c %6.1f %6.1f ", string[0], x, y);
+	else {
+	  sprintf (line, "X %6.1f %6.1f ", x, y);
+	  break;
 	}
-	break;
-
-      case KeyPress:
-	value = XLookupString ((XKeyEvent *) &event, string, 9, &keysym, &composestatus);
-
-	if ((event.xkey.x >= layout[0].picture.x) && (event.xkey.x <= layout[0].picture.x + layout[0].picture.dx) &&
-	    (event.xkey.y >= layout[0].picture.y) && (event.xkey.y <= layout[0].picture.y + layout[0].picture.dy)) {
-
-	  Screen_to_Image (&x, &y, (double)event.xkey.x, (double)event.xkey.y, layout);
-
-	  if (isprint(string[0]))
-	    sprintf (line, "%c %6.1f %6.1f ", string[0], x, y);
-	  else {
-	    sprintf (line, "X %6.1f %6.1f ", x, y);
-	    break;
-	  }
-	  write (layout[0].Ximage, line, 16);
-	}
+	write (layout[0].Ximage, line, 16);
       }
     }
   }
+  return (FALSE);
 }
