]> Dogcows Code - chaz/openbox/blobdiff - otk/timer.cc
don't wait for x events if any timers fired
[chaz/openbox] / otk / timer.cc
index 755096b84cf9c564460fc368b4a3b96604e0c7a8..4f993616b1ac0a6df3af1b1ad69be8a73a6c5f44 100644 (file)
@@ -7,6 +7,7 @@
 #include "timer.hh"
 #include "display.hh"
 
+extern "C" {
 #ifdef    HAVE_SYS_SELECT_H
 #  include <sys/select.h>
 #else
@@ -15,6 +16,7 @@
 #    include <unistd.h>
 #  endif // HAVE_UNISTD_H
 #endif // HAVE_SYS_SELECT_H
+}
 
 namespace otk {
 
@@ -61,8 +63,9 @@ void Timer::dispatchTimers(bool wait)
 
   while (!_q.empty()) {
     curr = _q.top();
-    /* since we overload the destructor to keep from removing from the middle of 
-       the priority queue, set _del_me, we have to do our real delete in here.
+    /* since we overload the destructor to keep from removing from the middle
+       of the priority queue, set _del_me, we have to do our real delete in
+       here.
     */
     if (curr->_del_me) {
       _q.pop();
@@ -75,15 +78,20 @@ void Timer::dispatchTimers(bool wait)
     if (!timercmp(&_now, &_nearest_timeout, >))
       break;
 
-    /* we set the last fired time to delay msec after the previous firing, then 
-       re-insert.  timers maintain their order and may trigger more than once if 
-       they've waited more than one delay's worth of time.
+    /* we set the last fired time to delay msec after the previous firing, then
+       re-insert.  timers maintain their order and may trigger more than once
+       if they've waited more than one delay's worth of time.
     */
     _q.pop();
     timevalAdd(curr->_last, curr->_delay);
     curr->_action(curr->_data);
     timevalAdd(curr->_timeout, curr->_delay);
     _q.push(curr);
+
+    /* if at least one timer fires, then don't wait on X events, as there may
+       already be some in the queue from the timer callbacks.
+    */
+    wait = false;
   }
 
   if (wait) {
@@ -91,9 +99,9 @@ void Timer::dispatchTimers(bool wait)
     fd = ConnectionNumber(**display);
     FD_ZERO(&selset);
     FD_SET(fd, &selset);
-    if (nearestTimeout(next))
+    if (nearestTimeout(next)) {
       select(fd + 1, &selset, NULL, NULL, &next);
-    else
+    else
       select(fd + 1, &selset, NULL, NULL, NULL);
   }
 }
This page took 0.021631 seconds and 4 git commands to generate.