Index: /trunk/Ohana/src/kii/event/EventLoop.c
===================================================================
--- /trunk/Ohana/src/kii/event/EventLoop.c	(revision 2891)
+++ /trunk/Ohana/src/kii/event/EventLoop.c	(revision 2892)
@@ -1,12 +1,14 @@
 # include "Ximage.h"
-# define MAX_STRING 100
-/* WARNING: this is defined because the HP UX installation i have does not
-seem to know this structure, though it should */
-# ifdef DUMMY
-struct Ktimeval {
-  unsigned long tv_sec;         /* seconds */
-  long          tv_usec;        /* and microseconds */
-};
-# endif
+
+int LastEvent (Display *display, int type, XEvent *event) {
+
+  int found;
+
+  found = FALSE;
+  while (XCheckTypedEvent (display, type, event)) {
+    found = TRUE;
+  }
+  return (found);
+}
 
 int EventLoop (Graphic *graphic, Layout *layout) {
@@ -14,7 +16,6 @@
   XEvent          event;
   int             status;
+  Display        *display;
   
-  /* gettimeofday (&then, (struct timeval *) NULL); */
-
   Refresh (graphic, layout, 1);
 
@@ -30,65 +31,25 @@
     }
 
-    if (XCheckMaskEvent (graphic[0].display, EVENT_MASK, &event)) {
+    display = graphic[0].display;
 
-      switch (event.type)  {
-	
-      case MotionNotify:
-	if (XEventsQueued (graphic[0].display, QueuedAlready) < 2) {
-	  UpdatePointer (graphic, layout, (XMotionEvent *) &event);
-	}
-	break;
-      case ButtonPress:
-	status = InterpretPresses (graphic, layout, (XButtonEvent *) &event);
-	break;
-	
-      case Expose:
-	if (XEventsQueued (graphic[0].display, QueuedAlready) < 2) {
-	  Refresh (graphic, layout, 1);
-	}
-	break;
-	/* if (event.xexpose.count == 0) */
-	
-      case ConfigureNotify:
-	status = Reconfig (graphic, layout, &event);
-	/*
-	if (XEventsQueued (graphic[0].display, QueuedAlready) < 2) {
-	  status = Reconfig (graphic, layout, &event);
-	}
-	*/
-	break;
-	
-      case KeyPress:
-	status = InterpretKeys (graphic, layout, &event);
-	break;
-	
-      case MappingNotify:
-	if (XEventsQueued (graphic[0].display, QueuedAlready) < 2) {
-	  XRefreshKeyboardMapping ((XMappingEvent *) &event);
-	}
-	break;
-	
-      }
-    }
+    /* 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)) InterpretKeys (graphic, layout, &event);
   }
   return (status);
 }
 
-/*     
-while (XPending (graphic[0].display) {
-if (readfds && display_mask) { 
-*/
-/*
-  while (1) {
-    fprintf (stderr, "window in EventLoop: %x  %d\n", graphic[0].display, graphic[0].window);
-    XNextEvent (graphic[0].display, &event);
-    if (event.type == ClientMessage) {
-      fprintf (stderr, "choice 1\n");
-    }
-    
-    if (event.xclient.send_event) {
-      fprintf (stderr, "choice 2\n");
-    }
-  }
-*/
-  
+# if (0)
+/* WARNING: this is defined because the HP UX installation i have does not
+seem to know this structure, though it should.  Clearly a need for autoconf.. */
+struct Ktimeval {
+  unsigned long tv_sec;         /* seconds */
+  long          tv_usec;        /* and microseconds */
+};
+# endif
+
