update clock at the beginning of seconds
This commit is contained in:
parent
491a56db10
commit
fcbdd00bce
1 changed files with 18 additions and 9 deletions
|
@ -143,9 +143,18 @@ void update_clocks()
|
|||
schedule_panel_redraw();
|
||||
}
|
||||
|
||||
int ms_until_second_change(struct timeval* tm)
|
||||
{
|
||||
long us_until_change = 1000000 - tm->tv_usec;
|
||||
// compute ms, rounding up so we don't ask to wait too short
|
||||
int ms = (us_until_change+999)/1000;
|
||||
return ms;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -155,6 +164,7 @@ 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;
|
||||
|
@ -178,14 +188,6 @@ void init_clock_panel(void *p)
|
|||
Panel *panel = (Panel *)p;
|
||||
Clock *clock = &panel->clock;
|
||||
|
||||
if (!clock_timeout) {
|
||||
if (time_format_needs_sec_ticks(time1_format) || time_format_needs_sec_ticks(time2_format)) {
|
||||
clock_timeout = add_timeout(10, 1000, update_clocks_sec, 0, &clock_timeout);
|
||||
} else {
|
||||
clock_timeout = add_timeout(10, 1000, update_clocks_min, 0, &clock_timeout);
|
||||
}
|
||||
}
|
||||
|
||||
if (!clock->area.bg)
|
||||
clock->area.bg = &g_array_index(backgrounds, Background, 0);
|
||||
clock_init_fonts();
|
||||
|
@ -213,7 +215,14 @@ void init_clock_panel(void *p)
|
|||
clock->area._get_tooltip_text = clock_get_tooltip;
|
||||
strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, clock_gettime_for_tz(time_tooltip_timezone));
|
||||
}
|
||||
update_clocks_sec(NULL);
|
||||
|
||||
if (!clock_timeout) {
|
||||
if (time_format_needs_sec_ticks(time1_format) || time_format_needs_sec_ticks(time2_format)) {
|
||||
update_clocks_sec(NULL);
|
||||
} else {
|
||||
update_clocks_min(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clock_init_fonts()
|
||||
|
|
Loading…
Reference in a new issue