diff --git a/src/battery/battery.c b/src/battery/battery.c index 09c2486..2dff910 100644 --- a/src/battery/battery.c +++ b/src/battery/battery.c @@ -226,8 +226,7 @@ void init_battery() battery_found = battery_os_init(); - if (!battery_timeout) - battery_timeout = add_timeout(10, 30000, update_battery_tick, 0, &battery_timeout); + battery_timeout = add_timeout(10, 30000, update_battery_tick, 0, &battery_timeout); update_battery(); } diff --git a/src/clock/clock.c b/src/clock/clock.c index d40e913..705d6dc 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -154,8 +154,8 @@ int ms_until_second_change(struct timeval* tm) void update_clocks_sec(void *arg) { gettimeofday(&time_clock, 0); - clock_timeout = add_timeout(ms_until_second_change(&time_clock), 0, update_clocks_sec, 0, NULL); update_clocks(); + clock_timeout = add_timeout(ms_until_second_change(&time_clock), 0, update_clocks_sec, 0, &clock_timeout); } void update_clocks_min(void *arg) @@ -164,10 +164,10 @@ void update_clocks_min(void *arg) // on next minute change static time_t old_sec = 0; gettimeofday(&time_clock, 0); - clock_timeout = add_timeout(ms_until_second_change(&time_clock), 0, update_clocks_min, 0, NULL); if (time_clock.tv_sec % 60 == 0 || time_clock.tv_sec - old_sec > 60) update_clocks(); old_sec = time_clock.tv_sec; + clock_timeout = add_timeout(ms_until_second_change(&time_clock), 0, update_clocks_min, 0, &clock_timeout); } gboolean time_format_needs_sec_ticks(char *time_format) diff --git a/src/execplugin/execplugin.c b/src/execplugin/execplugin.c index 7b79406..719efd6 100644 --- a/src/execplugin/execplugin.c +++ b/src/execplugin/execplugin.c @@ -196,8 +196,7 @@ void init_execp_panel(void *p) execp->area.on_screen = TRUE; instantiate_area_gradients(&execp->area); - if (!execp->backend->timer) - execp->backend->timer = add_timeout(10, 0, execp_timer_callback, execp, &execp->backend->timer); + execp->backend->timer = add_timeout(10, 0, execp_timer_callback, execp, &execp->backend->timer); execp_update_post_read(execp); } diff --git a/src/systray/systraybar.c b/src/systray/systraybar.c index 9a7dee4..2e3b229 100644 --- a/src/systray/systraybar.c +++ b/src/systray/systraybar.c @@ -1498,7 +1498,7 @@ void systray_render_icon(void *t) Window root; if (!XGetGeometry(server.display, traywin->win, &root, &xpos, &ypos, &width, &height, &border_width, &depth)) { stop_timeout(traywin->render_timeout); - if (!traywin->resize_timeout) + if (!traywin->render_timeout) traywin->render_timeout = add_timeout(min_refresh_period, 0, systray_render_icon, traywin, &traywin->render_timeout); systray_render_icon_from_image(traywin); @@ -1507,7 +1507,7 @@ void systray_render_icon(void *t) } else { if (xpos != 0 || ypos != 0 || width != traywin->width || height != traywin->height) { stop_timeout(traywin->render_timeout); - if (!traywin->resize_timeout) + if (!traywin->render_timeout) traywin->render_timeout = add_timeout(min_refresh_period, 0, systray_render_icon, traywin, &traywin->render_timeout); systray_render_icon_from_image(traywin); diff --git a/src/util/timer.c b/src/util/timer.c index a4452b5..26d41ef 100644 --- a/src/util/timer.c +++ b/src/util/timer.c @@ -44,6 +44,7 @@ struct _timeout { void *arg; multi_timeout *multi_timeout; timeout **self; + gboolean expired; }; void add_timeout_intern(int value_msec, int interval_msec, void (*_callback)(void *), void *arg, timeout *t); @@ -106,7 +107,7 @@ int gettime(struct timespec *tp) timeout *add_timeout(int value_msec, int interval_msec, void (*_callback)(void *), void *arg, timeout **self) { - if (self && *self) + if (self && *self && !(*self)->expired) return *self; timeout *t = calloc(1, sizeof(timeout)); t->self = self; @@ -155,6 +156,7 @@ void callback_timeout_expired() t = timeout_list->data; if (compare_timespecs(&t->timeout_expires, &cur_time) <= 0) { // it's time for the callback function + t->expired = t->interval_msec == 0; t->_callback(t->arg); // If _callback() calls stop_timeout(t) the timer 't' was freed and is not in the timeout_list if (g_slist_find(timeout_list, t)) {