changeset 350:892f4efe2e48

Prevent applications from hanging by massive mouse motion events. - When massive motion events are send by mouse, the application will busy for processing events. - The motion events are aggregated to prevent applicatin from hanging for massive mouse motion events.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 08 Mar 2009 23:08:51 +0800
parents 700954870cee
children 92e8f9965f9a
files src/X_supp.c
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/X_supp.c	Sun Mar 08 22:45:14 2009 +0800
+++ b/src/X_supp.c	Sun Mar 08 23:08:51 2009 +0800
@@ -177,7 +177,7 @@
 static void handle_x_event(X_MB_runtime_t *rt) {
     Display *display = rt->display;
     redraw_man_t *rdman = rt->rdman;
-    XEvent evt;
+    XEvent evt, peek_evt;
     XMotionEvent *mevt;
     XButtonEvent *bevt;
     XExposeEvent *eevt;
@@ -231,6 +231,17 @@
 	    break;
 
 	case MotionNotify:
+	    while(XEventsQueued(display, QueuedAfterReading) > 0) {
+		r = XPeekEvent(display, &peek_evt);
+		if(r == -1)
+		    break;
+		if(peek_evt.type != MotionNotify)
+		    break;
+		XNextEvent(display, &evt);
+	    }
+	    if(r == -1)
+		break;
+	    
 	    mevt = (XMotionEvent *)&evt;
 	    x = mevt->x;
 	    y = mevt->y;