typedef struct {
d_window_t *w;
- uint16_t start;
- uint16_t end;
- uint16_t current;
+ uint16_t start_alpha;
+ uint16_t end_alpha;
+ uint16_t current_alpha;
struct timeval start_time;
struct timeval end_time;
} fade_t;
static void fade_window_show(d_window_t *w);
static void fade_window_hide(d_window_t *w);
-static void start_fade(d_window_t *w, uint16_t start, uint16_t end);
+static void start_fade(d_window_t *w, uint16_t start_alpha, uint16_t end_alpha,
+ gboolean refalways);
void
fade_init(d_screen_t *sc, int id)
d->fades = list_new();
d->fade_step_time = 5000; /* 5 milliseconds */
- d->fade_total_time = 150000; /* 0.15 seconds */
+ d->fade_total_time = 180000; /* 0.18 seconds */
}
void
fade_window_show(d_window_t *w)
{
data_t *d;
-
- if (!window_is_input_only(w))
- start_fade(w, 0, 0xffff);
+ d_list_it_t *it;
d = screen_find_plugin_data(w->sc, plugin_id);
+
+ /* kill the zombies off cuz a new copy is being shown */
+ for (it = list_top(d->fades); it; it = it->next) {
+ fade_t *fade = it->data;
+ if (fade->w == w) {
+ window_zombie_unref(w);
+ window_unref(w);
+ break;
+ }
+ }
+
d->window_show(w);
+
+ if (!window_is_input_only(w))
+ start_fade(w, 0x2000, 0xffff, TRUE);
}
static void
data_t *d;
if (!window_is_input_only(w))
- start_fade(w, 0xffff, 0);
+ start_fade(w, 0xffff, 0x0002, FALSE);
d = screen_find_plugin_data(w->sc, plugin_id);
d->window_hide(w);
}
static void
-start_fade(d_window_t *w, uint16_t start, uint16_t end)
+start_fade(d_window_t *w, uint16_t start_alpha, uint16_t end_alpha,
+ gboolean refalways)
{
data_t *d;
d_list_it_t *it;
else
newfade = FALSE;
- fade->start = start;
- fade->end = end;
+ fade->start_alpha = start_alpha;
+ fade->end_alpha = end_alpha;
if (newfade) {
fade->start_time = now;
fade->end_time = now;
time_add(&fade->end_time, d->fade_total_time);
- fade->current = start;
-
- window_set_opacity(w, fade->current);
+ fade->current_alpha = start_alpha;
- window_ref(w);
- window_zombie_ref(w);
+ window_set_opacity(w, fade->current_alpha);
}
else {
/* figure out how far we have to go to finish the fade from where
long remain, total;
double percent;
- total = ABS(fade->end - fade->start);
- remain = ABS(fade->current - fade->end);
+ total = ABS(fade->end_alpha - fade->start_alpha);
+ remain = ABS(fade->current_alpha - fade->end_alpha);
percent = (double)remain / total;
//printf("start %d end %d current %d\n", fade->start, fade->end,
fade->end_time = now;
time_add(&fade->end_time, percent*d->fade_total_time);
}
+ if (newfade || refalways) {
+ window_zombie_ref(w);
+ window_ref(w);
+ }
}
int
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)
- fade->current = fade->end;
- else if (fade->end > fade->start)
- fade->current = fade->start + (fade->end - fade->start) * percent;
- else
- fade->current = fade->start - (fade->start - fade->end) * percent;
+ if (time_compare(&fade->end_time, now) <= 0) {
+ /* done */
+ fade->current_alpha = fade->end_alpha;
+ }
+ 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);
+ window_set_opacity(fade->w, fade->current_alpha);
- if (fade->current == fade->end) {
+ if (fade->current_alpha == fade->end_alpha) {
list_delete_link(d->fades, it);
window_zombie_unref(fade->w);
window_unref(fade->w);
g_free(fade);
}
}
+ d->next_timeout = *now;
time_add(&d->next_timeout, d->fade_step_time);
}