1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
Description: avoid polling, making docker much more power-saving-friendly
Author: Leandro Lucarella <llucax@gmail.com>
Bug-Debian: https://bugs.debian.org/501094
Index: docker-1.5/docker.c
===================================================================
--- docker-1.5.orig/docker.c
+++ docker-1.5/docker.c
@@ -5,6 +5,7 @@
#include "net.h"
#include <assert.h>
+#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
@@ -228,6 +229,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;
@@ -235,9 +266,7 @@ void event_loop()
GSList *it;
while (!exit_app) {
- while (XPending(display)) {
- XNextEvent(display, &e);
-
+ if (next_event(&e)) {
switch (e.type)
{
case PropertyNotify:
@@ -303,7 +332,6 @@ void event_loop()
break;
}
}
- usleep(500000);
}
/* remove/unparent all the icons */
|