docker (1.4-5) 02_no-poll.patch

Summary

 docker.c |   36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)

    
download this patch

Patch contents

Index: docker-1.4/docker.c
===================================================================
--- docker-1.4.orig/docker.c
+++ docker-1.4/docker.c
@@ -12,6 +12,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <errno.h>
 
 int argc;
 char **argv;
@@ -257,6 +258,36 @@ void fix_geometry()
 }
 
 
+gboolean next_event(XEvent *event)
+{
+  int fd;
+  fd_set rfds;
+
+  if (XPending(display)) {
+    XNextEvent(display, event);
+    return TRUE;
+  }
+
+  fd = ConnectionNumber(display);
+  FD_ZERO(&rfds);
+  FD_SET(fd, &rfds);
+
+  if (select(fd + 1, &rfds, NULL, NULL, NULL) == -1) {
+    if (errno != EINTR) {
+      g_printerr("Error waiting for events (%s)", strerror(errno));
+      exit(1);
+    }
+    return FALSE; /* interrupted by a signal */
+  }
+
+  if (!FD_ISSET(fd, &rfds) || !XPending(display))
+    return FALSE; /* false positive */
+
+  XNextEvent(display, event);
+  return TRUE;
+}
+
+
 void event_loop()
 {
   XEvent e;
@@ -264,9 +295,7 @@ void event_loop()
   GSList *it;
   
   while (!exit_app) {
-    while (XPending(display)) {
-      XNextEvent(display, &e);
-
+    if (next_event(&e)) {
       switch (e.type)
       {
       case PropertyNotify:
@@ -332,7 +361,6 @@ void event_loop()
         break;
       }
     }
-    usleep(500000);
   }
 
   /* remove/unparent all the icons */