Reinitialize timers correctly when created from their own callbacks
This commit is contained in:
@@ -226,7 +226,6 @@ void init_battery()
|
|||||||
|
|
||||||
battery_found = battery_os_init();
|
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();
|
update_battery();
|
||||||
|
|||||||
@@ -154,8 +154,8 @@ int ms_until_second_change(struct timeval* tm)
|
|||||||
void update_clocks_sec(void *arg)
|
void update_clocks_sec(void *arg)
|
||||||
{
|
{
|
||||||
gettimeofday(&time_clock, 0);
|
gettimeofday(&time_clock, 0);
|
||||||
clock_timeout = add_timeout(ms_until_second_change(&time_clock), 0, update_clocks_sec, 0, NULL);
|
|
||||||
update_clocks();
|
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)
|
void update_clocks_min(void *arg)
|
||||||
@@ -164,10 +164,10 @@ void update_clocks_min(void *arg)
|
|||||||
// on next minute change
|
// on next minute change
|
||||||
static time_t old_sec = 0;
|
static time_t old_sec = 0;
|
||||||
gettimeofday(&time_clock, 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)
|
if (time_clock.tv_sec % 60 == 0 || time_clock.tv_sec - old_sec > 60)
|
||||||
update_clocks();
|
update_clocks();
|
||||||
old_sec = time_clock.tv_sec;
|
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)
|
gboolean time_format_needs_sec_ticks(char *time_format)
|
||||||
|
|||||||
@@ -196,7 +196,6 @@ void init_execp_panel(void *p)
|
|||||||
execp->area.on_screen = TRUE;
|
execp->area.on_screen = TRUE;
|
||||||
instantiate_area_gradients(&execp->area);
|
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);
|
execp_update_post_read(execp);
|
||||||
|
|||||||
@@ -1498,7 +1498,7 @@ void systray_render_icon(void *t)
|
|||||||
Window root;
|
Window root;
|
||||||
if (!XGetGeometry(server.display, traywin->win, &root, &xpos, &ypos, &width, &height, &border_width, &depth)) {
|
if (!XGetGeometry(server.display, traywin->win, &root, &xpos, &ypos, &width, &height, &border_width, &depth)) {
|
||||||
stop_timeout(traywin->render_timeout);
|
stop_timeout(traywin->render_timeout);
|
||||||
if (!traywin->resize_timeout)
|
if (!traywin->render_timeout)
|
||||||
traywin->render_timeout =
|
traywin->render_timeout =
|
||||||
add_timeout(min_refresh_period, 0, systray_render_icon, traywin, &traywin->render_timeout);
|
add_timeout(min_refresh_period, 0, systray_render_icon, traywin, &traywin->render_timeout);
|
||||||
systray_render_icon_from_image(traywin);
|
systray_render_icon_from_image(traywin);
|
||||||
@@ -1507,7 +1507,7 @@ void systray_render_icon(void *t)
|
|||||||
} else {
|
} else {
|
||||||
if (xpos != 0 || ypos != 0 || width != traywin->width || height != traywin->height) {
|
if (xpos != 0 || ypos != 0 || width != traywin->width || height != traywin->height) {
|
||||||
stop_timeout(traywin->render_timeout);
|
stop_timeout(traywin->render_timeout);
|
||||||
if (!traywin->resize_timeout)
|
if (!traywin->render_timeout)
|
||||||
traywin->render_timeout =
|
traywin->render_timeout =
|
||||||
add_timeout(min_refresh_period, 0, systray_render_icon, traywin, &traywin->render_timeout);
|
add_timeout(min_refresh_period, 0, systray_render_icon, traywin, &traywin->render_timeout);
|
||||||
systray_render_icon_from_image(traywin);
|
systray_render_icon_from_image(traywin);
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ struct _timeout {
|
|||||||
void *arg;
|
void *arg;
|
||||||
multi_timeout *multi_timeout;
|
multi_timeout *multi_timeout;
|
||||||
timeout **self;
|
timeout **self;
|
||||||
|
gboolean expired;
|
||||||
};
|
};
|
||||||
|
|
||||||
void add_timeout_intern(int value_msec, int interval_msec, void (*_callback)(void *), void *arg, timeout *t);
|
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)
|
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;
|
return *self;
|
||||||
timeout *t = calloc(1, sizeof(timeout));
|
timeout *t = calloc(1, sizeof(timeout));
|
||||||
t->self = self;
|
t->self = self;
|
||||||
@@ -155,6 +156,7 @@ void callback_timeout_expired()
|
|||||||
t = timeout_list->data;
|
t = timeout_list->data;
|
||||||
if (compare_timespecs(&t->timeout_expires, &cur_time) <= 0) {
|
if (compare_timespecs(&t->timeout_expires, &cur_time) <= 0) {
|
||||||
// it's time for the callback function
|
// it's time for the callback function
|
||||||
|
t->expired = t->interval_msec == 0;
|
||||||
t->_callback(t->arg);
|
t->_callback(t->arg);
|
||||||
// If _callback() calls stop_timeout(t) the timer 't' was freed and is not in the timeout_list
|
// 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)) {
|
if (g_slist_find(timeout_list, t)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user