1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-18 02:55:12 +00:00

battery_bar: convert to callbacks.barval

This commit is contained in:
Phil Sutter 2009-11-22 21:54:02 +01:00
parent a11a1a1253
commit 4e63422d10
5 changed files with 9 additions and 11 deletions

View File

@ -65,7 +65,7 @@ void get_acpi_ac_adapter(char *, size_t);
void get_acpi_fan(char *, size_t); void get_acpi_fan(char *, size_t);
void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item); 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(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 get_battery_short_status(char *buf, unsigned int n, const char *bat);
void scan_loadavg_arg(struct text_object *, const char *); void scan_loadavg_arg(struct text_object *, const char *);

View File

@ -860,9 +860,6 @@ void generate_text_internal(char *p, int p_max_size,
OBJ(battery_percent) { OBJ(battery_percent) {
percent_print(p, p_max_size, get_battery_perct(obj->data.s)); 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) { OBJ(battery_short) {
get_battery_short_status(p, p_max_size, obj->data.s); get_battery_short_status(p, p_max_size, obj->data.s);
} }

View File

@ -289,6 +289,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
strcpy(bat, "BAT0"); strcpy(bat, "BAT0");
} }
obj->data.s = strndup(bat, text_buffer_size); obj->data.s = strndup(bat, text_buffer_size);
obj->callbacks.barval = &get_battery_perct_bar;
obj->callbacks.free = &gen_free_opaque; obj->callbacks.free = &gen_free_opaque;
#endif /* !__OpenBSD__ */ #endif /* !__OpenBSD__ */

View File

@ -471,10 +471,10 @@ int get_battery_perct(const char *bat)
return batperct > 100 ? 100 : batperct; 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); int batperct = get_battery_perct(obj->data.s);
return (int)(batperct * 2.56 - 1); return round_to_int((double)batperct * 2.55);
} }
int open_acpi_temperature(const char *name) int open_acpi_temperature(const char *name)

View File

@ -2054,13 +2054,13 @@ int get_battery_perct(const char *bat)
return last_battery_perct[idx]; 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; int idx;
get_battery_perct(bar); get_battery_perct(obj->data.s);
idx = get_battery_idx(bar); idx = get_battery_idx(obj->data.s);
return (int) (last_battery_perct[idx] * 2.56 - 1); return round_to_int((double)last_battery_perct[idx] * 2.55);
} }
/* On Apple powerbook and ibook: /* On Apple powerbook and ibook: