dwmstatus: only show UPS load above some threshold

This commit is contained in:
Přemysl Eric Janouch 2016-01-15 21:24:15 +01:00
parent e01a0f2abf
commit 959040d174
1 changed files with 12 additions and 4 deletions

View File

@ -1,7 +1,7 @@
/* /*
* dwmstatus.c: simple PulseAudio-enabled dwmstatus * dwmstatus.c: simple PulseAudio-enabled dwmstatus
* *
* Copyright (c) 2015, Přemysl Janouch <p.janouch@gmail.com> * Copyright (c) 2015 - 2016, Přemysl Janouch <p.janouch@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -1669,6 +1669,7 @@ static struct simple_config_item g_config_table[] =
{ "mpd_password", NULL, "MPD password" }, { "mpd_password", NULL, "MPD password" },
{ "nut_enabled", "off", "NUT UPS status reading enabled" }, { "nut_enabled", "off", "NUT UPS status reading enabled" },
{ "nut_load_thld", "50", "NUT threshold for load display" },
{ NULL, NULL, NULL } { NULL, NULL, NULL }
}; };
@ -2215,7 +2216,7 @@ interval_string (unsigned long seconds)
} }
static void static void
nut_process_ups (struct str_vector *ups_list, nut_process_ups (struct app_context *ctx, struct str_vector *ups_list,
const char *ups_name, struct str_map *dict) const char *ups_name, struct str_map *dict)
{ {
// Not currently interested in this kind of information; // Not currently interested in this kind of information;
@ -2257,7 +2258,14 @@ nut_process_ups (struct str_vector *ups_list,
str_vector_add_owned (&items, xstrdup_printf ("%s%%", charge)); str_vector_add_owned (&items, xstrdup_printf ("%s%%", charge));
if (running_on_batteries) if (running_on_batteries)
str_vector_add_owned (&items, interval_string (runtime_sec)); str_vector_add_owned (&items, interval_string (runtime_sec));
if (load)
// Only show load if it's higher than the threshold so as to not distract
const char *threshold = str_map_find (&ctx->config, "nut_load_thld");
unsigned long load_n, threshold_n;
if (load
&& xstrtoul (&load_n, load, 10)
&& xstrtoul (&threshold_n, threshold, 10)
&& load_n >= threshold_n)
str_vector_add_owned (&items, xstrdup_printf ("load %s%%", load)); str_vector_add_owned (&items, xstrdup_printf ("load %s%%", load));
struct str result; struct str result;
@ -2287,7 +2295,7 @@ nut_on_logout_response (const struct nut_response *response, void *user_data)
str_map_iter_init (&iter, &ctx->nut_ups_info); str_map_iter_init (&iter, &ctx->nut_ups_info);
struct str_map *dict; struct str_map *dict;
while ((dict = str_map_iter_next (&iter))) while ((dict = str_map_iter_next (&iter)))
nut_process_ups (&ups_list, iter.link->key, dict); nut_process_ups (ctx, &ups_list, iter.link->key, dict);
free (ctx->nut_status); free (ctx->nut_status);
ctx->nut_status = NULL; ctx->nut_status = NULL;