]> Dogcows Code - chaz/tint2/blobdiff - src/tint.c
*fix* use another timer implementation, coz *BSD does not support timerfd :(
[chaz/tint2] / src / tint.c
index 9e64ed37ac3c54e03a7077b1814d02ab9355cd67..a91f8cc38267d1110376dfd61f3ed30b596fb20b 100644 (file)
@@ -635,8 +635,7 @@ int main (int argc, char *argv[])
        int x11_fd, i;
        Panel *panel;
        GSList *it;
-       GSList* timer_iter;
-       struct timer* timer;
+       const struct timespec* timeout;
 
        init (argc, argv);
 
@@ -695,33 +694,17 @@ int main (int argc, char *argv[])
                }
 
                // thanks to AngryLlama for the timer
-               // Create a File Description Set containing x11_fd, and every timer_fd
+               // Create a File Description Set containing x11_fd
                FD_ZERO (&fdset);
                FD_SET (x11_fd, &fdset);
-               int max_fd = x11_fd;
-               timer_iter = timer_list;
-               while (timer_iter) {
-                       timer = timer_iter->data;
-                       max_fd = timer->id > max_fd ? timer->id : max_fd;
-                       FD_SET(timer->id, &fdset);
-                       timer_iter = timer_iter->next;
-               }
+               update_next_timeout();
+               if (next_timeout.tv_sec >= 0 && next_timeout.tv_nsec >= 0)
+                       timeout = &next_timeout;
+               else
+                       timeout = 0;
 
                // Wait for X Event or a Timer
-               if (pselect(max_fd+1, &fdset, 0, 0, 0, &empty_mask) > 0) {
-                       // we need to iterate over the whole timer list, since fd_set can only be checked with the
-                       // brute force method FD_ISSET for every possible timer
-                       timer_iter = timer_list;
-                       while (timer_iter) {
-                               timer = timer_iter->data;
-                               if (FD_ISSET(timer->id, &fdset)) {
-                                       uint64_t dummy;
-                                       if ( -1  != read(timer->id, &dummy, sizeof(uint64_t)) )
-                                               timer->_callback();
-                               }
-                               timer_iter = timer_iter->next;
-                       }
-
+               if (pselect(x11_fd+1, &fdset, 0, 0, timeout, &empty_mask) > 0) {
                        while (XPending (server.dsp)) {
                                XNextEvent(server.dsp, &e);
 
@@ -800,6 +783,8 @@ int main (int argc, char *argv[])
                        }
                }
 
+               callback_timeout_expired();
+
                switch (signal_pending) {
                case SIGUSR1: // reload config file
                        signal_pending = 0;
This page took 0.0261 seconds and 4 git commands to generate.