i3status/src
johcgt d5c69a9d60 Treat zero battery capacity as "not available" (#259)
`print_battery_info` computes `batt_info.percentage_remaining` by
dividing batt_info.remaining by `full`. If `full` is `0` then the
battery remaining will be reported as "inf".

Before this, it tries to set `full` to either the design capacity or to
the last known good charge. It determines if these values are available
by checking whether their fields in `batt_info` are non-negative. As it
initialized `batt_info` with values of `-1`, a non-negative value
implies that something has provided a value.

`slurp_all_batteries` and `add_battery_info` however initialize these
fields to zero, so if these functions are called then
`batt_info.full_design` will always be used.

This means that on systems that don't provide a value for design
capacity the percentage remaining will be reported as "inf", unless the
user has set `last_full_capacity` to `true` in their `i3status.conf`.

This patch changes `print_battery_info` to expect values for the battery
capacity to be strictly greater than zero. This seems reasonable as a
battery with a capacity of zero isn't useful.

An alternative solution would be to change `slurp_all_batteries` and
`add_battery_info` to initialize `batt_info` with `-1`, as
`print_battery_info` does. This is less appealing as `add_battery_info`
is accumulating the values, so using `-1` would introduce off-by-one
errors without additional code to avoid them.
2018-01-28 15:37:51 +01:00
..
auto_detect_format.c format detection: recognise swaybar 2015-12-27 15:59:32 +11:00
first_network_device.c Added braces 2017-04-13 12:51:29 +02:00
general.c clang-format-3.5 -i **/*.[ch], update modeline 2015-03-16 10:01:07 +01:00
output.c remove useless checks (we use char, not unsigned char) 2017-03-08 19:24:09 +01:00
print_battery_info.c Treat zero battery capacity as "not available" (#259) 2018-01-28 15:37:51 +01:00
print_cpu_temperature.c Fix the deciKelvin to Celsius conversion on FreeBSD (#195) 2017-02-01 11:28:01 -08:00
print_cpu_usage.c Multiple CPU support for cpu_usage (#209) 2017-03-26 06:54:07 -04:00
print_ddate.c clang-format-3.5 -i **/*.[ch], update modeline 2015-03-16 10:01:07 +01:00
print_disk_info.c disk: don't remove trailing slash if path is a single character 2017-03-10 11:24:56 -08:00
print_eth_info.c Add IPv6 address when IPv4 isn't available (#247) 2017-12-11 11:38:31 +01:00
print_ip_addr.c Add IPv6 address when IPv4 isn't available (#247) 2017-12-11 11:38:31 +01:00
print_ipv6_addr.c clang-format-3.5 -i **/*.[ch], update modeline 2015-03-16 10:01:07 +01:00
print_load.c Add 'format_below_threshold' option for 'disk' module 2016-11-15 01:09:05 +02:00
print_path_exists.c Adding the option "format_down" to path_exists and run_watch. 2015-04-02 22:31:06 +02:00
print_run_watch.c Adding the option "format_down" to path_exists and run_watch. 2015-04-02 22:31:06 +02:00
print_time.c Call tzset at each time print 2017-12-09 15:48:18 +01:00
print_volume.c pulse device may be specified by name (#126) (#162) 2016-09-14 09:26:45 +02:00
print_wireless_info.c Update comment as in #247 (#254) 2017-12-11 12:16:00 +01:00
process_runs.c clang-format-3.5 -i **/*.[ch], update modeline 2015-03-16 10:01:07 +01:00
pulse.c pulse device may be specified by name (#126) (#162) 2016-09-14 09:26:45 +02:00