}
static void
-timeouts(d_display_t *dpy)
+timeouts(d_display_t *dpy, const struct timeval *now)
{
d_list_it_t *it;
- struct timeval now;
- gettimeofday(&now, NULL);
-
for (it = list_top(dpy->screens); it; it = it->next) {
d_screen_t *sc = it->data;
+ struct timeval tv;
- render_timeout(sc, &now);
- fade_timeout(sc, &now);
+ if (render_next_timeout(sc, &tv) && time_compare(&tv, now) <= 0)
+ render_timeout(sc, now);
+ if (fade_next_timeout(sc, &tv) && time_compare(&tv, now) <= 0)
+ fade_timeout(sc, now);
}
}
paint(d_display_t *dpy)
{
d_list_it_t *it;
- struct timeval now;
- gettimeofday(&now, NULL);
-
for (it = list_top(dpy->screens); it; it = it->next) {
d_screen_t *sc = it->data;
-
- if (time_compare(&sc->next_repaint, &now) <= 0)
+ if (sc->need_repaint)
sc->screen_paint(sc);
}
}
static void
run(d_display_t *dpy)
{
+ struct timeval now, next_repaint;
+
+ gettimeofday(&now, NULL);
+ next_repaint = now;
+
while (!quit) {
- struct timeval next, now, *wait;
+ struct timeval next, *wait;
int r, npaint, ntime;
d_list_it_t *it;
fd_set fds;
struct timeval next_timeout;
if (render_next_timeout(sc, &next_timeout)) {
- if ((!npaint && !ntime) ||
- time_compare(&next_timeout, &next) < 0)
- {
+ if (!ntime || time_compare(&next_timeout, &next) < 0) {
next = next_timeout;
++ntime;
}
}
if (fade_next_timeout(sc, &next_timeout)) {
- if ((!npaint && !ntime) ||
- time_compare(&next_timeout, &next) < 0)
- {
+ if (!ntime || time_compare(&next_timeout, &next) < 0) {
next = next_timeout;
++ntime;
}
}
- if (sc->need_repaint &&
- ((!npaint && !ntime) ||
- time_compare(&sc->next_repaint, &next) < 0))
- {
- next = sc->next_repaint;
+ if (sc->need_repaint)
++npaint;
- }
}
- gettimeofday(&now, 0);
+ if (npaint) {
+ if (!ntime || time_compare(&next_repaint, &next) < 0) {
+ next = next_repaint;
+ }
+ }
if (!npaint && !ntime)
/* wait forever, there is nothing that needs drawing */
else {
/* don't wait cuz a timer is due now already */
next.tv_sec = 0;
- next.tv_usec = 0;
+ next.tv_usec = 1;
wait = &next;
}
//printf("select %d\n", npaint);
r = select(dpy->fd+1, &fds, NULL, NULL, wait);
+
+ gettimeofday(&now, NULL);
if (r == 0) {
//printf("select timeout\n");
- timeouts(dpy);
- paint(dpy);
+ timeouts(dpy, &now);
+ if (time_compare(&next_repaint, &now) <= 0) {
+ paint(dpy);
+ next_repaint = now;
+ time_add(&next_repaint, 1000000/90); /* 60hz */
+ }
xcb_flush(dpy->conn);
}