X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=i3status.c;h=903ea922b1a8e0444d3500621adefdfe44dacb20;hb=09967274d72e4cb134b432da43511e8a96683855;hp=909ef88dbd29b94f13843b6380999b48cb4ceeac;hpb=ea236a90daf4b20b16eba2e9c121166b34fc5332;p=i3%2Fi3status diff --git a/i3status.c b/i3status.c index 909ef88..903ea92 100644 --- a/i3status.c +++ b/i3status.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include "i3status.h" @@ -45,7 +47,7 @@ void sigpipe(int signum) { * full path if so or NULL if there is no file. * */ -char *file_exists(const char *path) { +static char *file_exists(char *path) { static glob_t globbuf; struct stat buf; char *full_path = NULL; @@ -90,7 +92,8 @@ int main(int argc, char *argv[]) { }; cfg_opt_t ipv6_opts[] = { - CFG_STR("format", "%ip", CFGF_NONE), + CFG_STR("format_up", "%ip", CFGF_NONE), + CFG_STR("format_down", "no IPv6", CFGF_NONE), CFG_END() }; @@ -129,7 +132,7 @@ int main(int argc, char *argv[]) { CFG_SEC("battery", battery_opts, CFGF_TITLE | CFGF_MULTI), CFG_SEC("cpu_temperature", temp_opts, CFGF_TITLE | CFGF_MULTI), CFG_SEC("disk", disk_opts, CFGF_TITLE | CFGF_MULTI), - CFG_SEC("ipv6", ipv6_opts, CFGF_TITLE), + CFG_SEC("ipv6", ipv6_opts, CFGF_NONE), CFG_SEC("time", time_opts, CFGF_NONE), CFG_SEC("load", load_opts, CFGF_NONE), CFG_END() @@ -186,6 +189,8 @@ int main(int argc, char *argv[]) { if ((general_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1) die("Could not create socket\n"); + int interval = cfg_getint(cfg_general, "interval"); + while (1) { for (j = 0; j < cfg_size(cfg, "order"); j++) { if (j > 0) @@ -194,7 +199,7 @@ int main(int argc, char *argv[]) { const char *current = cfg_getnstr(cfg, "order", j); CASE_SEC("ipv6") - print_ipv6_info(cfg_getstr(sec, "format")); + print_ipv6_info(cfg_getstr(sec, "format_up"), cfg_getstr(sec, "format_down")); CASE_SEC_TITLE("wireless") print_wireless_info(title, cfg_getstr(sec, "format_up"), cfg_getstr(sec, "format_down")); @@ -223,6 +228,13 @@ int main(int argc, char *argv[]) { printf("\n"); fflush(stdout); - sleep(cfg_getint(cfg_general, "interval")); + /* To provide updates on every full second (as good as possible) + * we don’t use sleep(interval) but we sleep until the next + * second (with microsecond precision) plus (interval-1) + * seconds. */ + struct timeval current_time; + gettimeofday(¤t_time, NULL); + struct timespec ts = {interval - 1, (10e5 - current_time.tv_usec) * 1000}; + nanosleep(&ts, NULL); } }