all repos — tint2 @ 146408655bd341b8fe84aab52b3abcd7a680d441

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

Merge branch 'master' into 'master'

update clock at the beginning of seconds

See merge request !27
o9000 mrovi9000@gmail.com
commit

146408655bd341b8fe84aab52b3abcd7a680d441

parent

3b7d583d8f2676cd178878e44df495c4319c3558

1 files changed, 18 insertions(+), 9 deletions(-)

jump to
M src/clock/clock.csrc/clock/clock.c

@@ -143,9 +143,18 @@ }

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 @@ // remember old_sec because after suspend/hibernate the clock should be updated directly, and not

// 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 @@ {

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 @@ if (time_tooltip_format) {

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()