summaryrefslogtreecommitdiff
path: root/src/print_battery_info.c
diff options
context:
space:
mode:
authorgrmat <grmat@users.noreply.github.com>2019-11-16 16:26:26 +0100
committerMichael Stapelberg <stapelberg@users.noreply.github.com>2019-11-16 16:26:26 +0100
commitabfe05c8bd54cf25e3d705e4899e9e9c8a8ea9a7 (patch)
treeb87782eb302184d2c9bbe1d8e91577ea0a89bffd /src/print_battery_info.c
parentbadef18c2238ede87773398f2f945f3492b6f4c5 (diff)
Introduce format_percentage for battery (#371)
Allow custom output, backwards-compatible to integer_battery_capacity
Diffstat (limited to 'src/print_battery_info.c')
-rw-r--r--src/print_battery_info.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/print_battery_info.c b/src/print_battery_info.c
index c8a1d3d..1240626 100644
--- a/src/print_battery_info.c
+++ b/src/print_battery_info.c
@@ -570,7 +570,7 @@ static bool slurp_all_batteries(struct battery_info *batt_info, yajl_gen json_ge
return true;
}
-void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, const char *status_chr, const char *status_bat, const char *status_unk, const char *status_full, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity, bool hide_seconds) {
+void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, const char *status_chr, const char *status_bat, const char *status_unk, const char *status_full, int low_threshold, char *threshold_type, bool last_full_capacity, const char *format_percentage, bool hide_seconds) {
const char *walk;
char *outwalk = buffer;
struct battery_info batt_info = {
@@ -586,7 +586,9 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__OpenBSD__)
/* These OSes report battery stats in whole percent. */
- integer_battery_capacity = true;
+ if (strcmp("%.02f%s", format_percentage) == 0) {
+ format_percentage = "%.00f%s";
+ }
#endif
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__OpenBSD__)
/* These OSes report battery time in minutes. */
@@ -687,11 +689,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
walk += strlen("status");
} else if (BEGINS_WITH(walk + 1, "percentage")) {
- if (integer_battery_capacity) {
- outwalk += sprintf(outwalk, "%.00f%s", batt_info.percentage_remaining, pct_mark);
- } else {
- outwalk += sprintf(outwalk, "%.02f%s", batt_info.percentage_remaining, pct_mark);
- }
+ outwalk += sprintf(outwalk, format_percentage, batt_info.percentage_remaining, pct_mark);
walk += strlen("percentage");
} else if (BEGINS_WITH(walk + 1, "remaining")) {