X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Ftimer.cc;h=0a0083146afee234012a7e30796f33d4bd60b393;hb=dca8c61a91cab29128a72f252b70f4bd9f7786ff;hp=2fbeaf858f276277dafcce49e0710281f7721690;hpb=53bed5e59a802f527a22d940d830543726403f1e;p=chaz%2Fopenbox diff --git a/otk/timer.cc b/otk/timer.cc index 2fbeaf85..0a008314 100644 --- a/otk/timer.cc +++ b/otk/timer.cc @@ -1,8 +1,6 @@ // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif // HAVE_CONFIG_H +#include "config.h" #include "timer.hh" #include "display.hh" @@ -10,12 +8,11 @@ extern "C" { #ifdef HAVE_SYS_SELECT_H # include -#else -# ifdef HAVE_UNISTD_H -# include -# include -# endif // HAVE_UNISTD_H #endif // HAVE_SYS_SELECT_H + +#ifdef HAVE_SYS_TIME_H +# include +#endif } namespace otk { @@ -63,8 +60,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(); @@ -86,6 +84,11 @@ void Timer::dispatchTimers(bool wait) 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) { @@ -93,9 +96,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); } }