}
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);
}
sc->window_hide = fade_window_hide;
d->fades = list_new();
- d->fade_step_time = 5000; /* 5 milliseconds */
- d->fade_total_time = 150000; /* 0.15 seconds */
+ d->fade_step_time = 10000; /* 5 milliseconds */
+ d->fade_total_time = 200000; /* 0.15 seconds */
}
void
data_t *d;
if (!window_is_input_only(w))
- start_fade(w, 0, 0xffff);
+ start_fade(w, 0x0000, 0xffff);
d = screen_find_plugin_data(w->sc, plugin_id);
d->window_show(w);
data_t *d;
if (!window_is_input_only(w))
- start_fade(w, 0xffff, 0);
+ start_fade(w, 0xffff, 0x0000);
d = screen_find_plugin_data(w->sc, plugin_id);
d->window_hide(w);
for (it = list_top(d->fades); it; it = next) {
fade_t *fade = it->data;
- struct timeval time_done, total_time;
- unsigned long done, total;
- double percent;
next = it->next;
- time_difference(now, &fade->start_time, &time_done);
- time_difference(&fade->end_time, &fade->start_time, &total_time);
-
- /* count milliseconds */
- done = time_done.tv_sec * 1000 + time_done.tv_usec / 1000;
- total = total_time.tv_sec * 1000 + total_time.tv_usec / 1000;
- percent = (double)done / total;
-
- //printf("done %lu total %lu percent %f\n", done, total, percent);
-
- if (percent >= 1)
+ if (time_compare(&fade->end_time, now) <= 0) {
+ /* done */
fade->current_alpha = fade->end_alpha;
- else if (fade->end_alpha > fade->start_alpha)
- fade->current_alpha = fade->start_alpha +
- (fade->end_alpha - fade->start_alpha) * percent;
- else
- fade->current_alpha = fade->start_alpha -
- (fade->start_alpha - fade->end_alpha) * percent;
+ }
+ else {
+ struct timeval total_time, time_left;
+ unsigned long remain, total;
+ double percent;
+
+ time_difference(&fade->end_time, now, &time_left);
+ time_difference(&fade->end_time, &fade->start_time, &total_time);
+
+
+ /* count milliseconds */
+ remain = time_left.tv_sec * 1000 + time_left.tv_usec / 1000;
+ total = total_time.tv_sec * 1000 + total_time.tv_usec / 1000;
+ percent = (double)remain / total;
+
+ //printf("done %lu total %lu percent %f\n", done, total, percent);
+
+ if (fade->end_alpha > fade->start_alpha)
+ /* increasing */
+ fade->current_alpha = fade->end_alpha -
+ (fade->end_alpha - fade->start_alpha) * percent;
+ else
+ /* decreasing */
+ fade->current_alpha = fade->end_alpha +
+ (fade->start_alpha - fade->end_alpha) * percent;
+ }
window_set_opacity(fade->w, fade->current_alpha);
g_free(fade);
}
}
+ d->next_timeout = *now;
time_add(&d->next_timeout, d->fade_step_time);
}
static gboolean screen_init(d_screen_t *sc);
static xcb_timestamp_t screen_timestamp(d_screen_t *sc);
static void screen_add_existing_windows(d_screen_t *sc);
-static void screen_set_next_repaint(d_screen_t *sc);
static guint
xcb_window_hash(xcb_window_t *w) { return *w; }
sc->dpy = dpy;
sc->num = num;
- gettimeofday(&sc->next_repaint, NULL);
sc->need_repaint = TRUE;
sc->winhash = g_hash_table_new((GHashFunc)xcb_window_hash,
}
static void
-screen_set_next_repaint(d_screen_t *sc)
+screen_set_need_repaint(d_screen_t *sc)
{
- gettimeofday(&sc->next_repaint, NULL);
- /* add time for the refresh rate (60 hz) */
- time_add(&sc->next_repaint, 1000000/60);
sc->need_repaint = FALSE;
}
void
screen_setup_default_functions(d_screen_t *sc)
{
- sc->screen_paint = screen_set_next_repaint;
+ sc->screen_paint = screen_set_need_repaint;
sc->window_show = window_show;
sc->window_hide = window_hide;
sc->window_become_zombie = window_become_zombie;