diff --git a/src/common.h b/src/common.h index a9df8641..c8a36759 100644 --- a/src/common.h +++ b/src/common.h @@ -65,7 +65,7 @@ void get_acpi_ac_adapter(char *, size_t); void get_acpi_fan(char *, size_t); void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item); int get_battery_perct(const char *bat); -int get_battery_perct_bar(const char *bat); +uint8_t get_battery_perct_bar(struct text_object *); void get_battery_short_status(char *buf, unsigned int n, const char *bat); void scan_loadavg_arg(struct text_object *, const char *); diff --git a/src/conky.c b/src/conky.c index 740fe8d7..58162091 100644 --- a/src/conky.c +++ b/src/conky.c @@ -860,9 +860,6 @@ void generate_text_internal(char *p, int p_max_size, OBJ(battery_percent) { percent_print(p, p_max_size, get_battery_perct(obj->data.s)); } - OBJ(battery_bar) { - new_bar(obj, p, p_max_size, get_battery_perct_bar(obj->data.s)); - } OBJ(battery_short) { get_battery_short_status(p, p_max_size, obj->data.s); } diff --git a/src/core.c b/src/core.c index a9295b68..2378bc21 100644 --- a/src/core.c +++ b/src/core.c @@ -289,6 +289,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long strcpy(bat, "BAT0"); } obj->data.s = strndup(bat, text_buffer_size); + obj->callbacks.barval = &get_battery_perct_bar; obj->callbacks.free = &gen_free_opaque; #endif /* !__OpenBSD__ */ diff --git a/src/freebsd.c b/src/freebsd.c index 76f35d23..02cfdad3 100644 --- a/src/freebsd.c +++ b/src/freebsd.c @@ -471,10 +471,10 @@ int get_battery_perct(const char *bat) return batperct > 100 ? 100 : batperct; } -int get_battery_perct_bar(const char *bar) +uint8_t get_battery_perct_bar(struct text_object *obj) { - int batperct = get_battery_perct(bar); - return (int)(batperct * 2.56 - 1); + int batperct = get_battery_perct(obj->data.s); + return round_to_int((double)batperct * 2.55); } int open_acpi_temperature(const char *name) diff --git a/src/linux.c b/src/linux.c index 7d31a14d..3e272302 100644 --- a/src/linux.c +++ b/src/linux.c @@ -2054,13 +2054,13 @@ int get_battery_perct(const char *bat) return last_battery_perct[idx]; } -int get_battery_perct_bar(const char *bar) +uint8_t get_battery_perct_bar(struct text_object *obj) { int idx; - get_battery_perct(bar); - idx = get_battery_idx(bar); - return (int) (last_battery_perct[idx] * 2.56 - 1); + get_battery_perct(obj->data.s); + idx = get_battery_idx(obj->data.s); + return round_to_int((double)last_battery_perct[idx] * 2.55); } /* On Apple powerbook and ibook: