X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Ftimer.c;h=33f4bab73e74d934e8259f9a3182515b40e9ddb4;hb=3cbe368018ed5a2198e9e314bdd7338e4864886d;hp=b6a82cd37fe7eba1443f3268265d70d6ffe0d4fc;hpb=0a69cfc6d2cf672634e95d5eb2015434dd924abc;p=chaz%2Fopenbox diff --git a/openbox/timer.c b/openbox/timer.c index b6a82cd3..33f4bab7 100644 --- a/openbox/timer.c +++ b/openbox/timer.c @@ -8,22 +8,22 @@ static GTimeVal now; static GTimeVal ret_wait; static GSList *timers; /* nearest timer is at the top */ -#define NEAREST_TIMEOUT (((Timer*)timers->data)->timeout) +#define NEAREST_TIMEOUT (((ObTimer*)timers->data)->timeout) static long timecompare(GTimeVal *a, GTimeVal *b) { long r; if ((r = b->tv_sec - a->tv_sec)) return r; - return b->tv_usec - a->tv_sec; + return b->tv_usec - a->tv_usec; } -static void insert_timer(Timer *self) +static void insert_timer(ObTimer *self) { GSList *it; for (it = timers; it != NULL; it = it->next) { - Timer *t = it->data; + ObTimer *t = it->data; if (timecompare(&self->timeout, &t->timeout) <= 0) { timers = g_slist_insert_before(timers, it, self); break; @@ -49,13 +49,14 @@ void timer_shutdown() timers = NULL; } -Timer *timer_start(long delay, TimeoutHandler cb, void *data) +ObTimer *timer_start(long delay, ObTimeoutHandler cb, void *data) { - Timer *self = g_new(Timer, 1); + ObTimer *self = g_new(ObTimer, 1); self->delay = delay; self->action = cb; self->data = data; self->del_me = FALSE; + g_get_current_time(&now); self->last = self->timeout = now; g_time_val_add(&self->timeout, delay); @@ -64,7 +65,7 @@ Timer *timer_start(long delay, TimeoutHandler cb, void *data) return self; } -void timer_stop(Timer *self) +void timer_stop(ObTimer *self) { self->del_me = TRUE; } @@ -96,7 +97,7 @@ void timer_dispatch(GTimeVal **wait) g_get_current_time(&now); while (timers != NULL) { - Timer *curr = timers->data; /* get the top element */ + ObTimer *curr = timers->data; /* get the top element */ /* since timer_stop doesn't actually free the timer, we have to do our real freeing in here. */ @@ -108,7 +109,7 @@ void timer_dispatch(GTimeVal **wait) /* the queue is sorted, so if this timer shouldn't fire, none are ready */ - if (timecompare(&now, &NEAREST_TIMEOUT) <= 0) + if (timecompare(&NEAREST_TIMEOUT, &now) <= 0) break; /* we set the last fired time to delay msec after the previous firing, @@ -117,7 +118,7 @@ void timer_dispatch(GTimeVal **wait) */ timers = g_slist_delete_link(timers, timers); g_time_val_add(&curr->last, curr->delay); - curr->action(curr->data); + curr->action(curr, curr->data); g_time_val_add(&curr->timeout, curr->delay); insert_timer(curr);