From b516e1944055bb679e6dcafb4a386bc41b6e2cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Swo=C3=B6g?= Date: Tue, 17 Feb 2009 21:49:45 -0700 Subject: [PATCH] Patch to add $battery_short variable. --- ChangeLog | 3 +++ README | 8 ++++++++ doc/conky.1 | 5 +++++ doc/variables.xml | 43 +++++++++++++++++++++++++++---------------- src/common.h | 1 + src/conky.c | 15 +++++++++++++++ src/linux.c | 12 ++++++++++++ src/text_object.h | 1 + 8 files changed, 72 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 57935c3f..6d40de05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2009-02-17 + * Added $battery_short patch, sf.net id #2300911 (thanks Swoog) + 2009-02-15 * Added out_to_x diff --git a/README b/README index ced8c369..c88a01cc 100644 --- a/README +++ b/README @@ -583,6 +583,14 @@ conky(1) conky(1) is BAT0). + 1mbattery_short (num)0m + Battery status and remaining percentage capacity of ACPI or APM + battery. ACPI battery number can be given as argument (default + is BAT0). This mode display a short status, which means that C + is displayed instead of charging and D is displayed instead of + discharging. + + 1mbattery_bar (height),(width) (num)0m Battery percentage remaining of ACPI battery in a bar. ACPI bat‐ tery number can be given as argument (default is BAT0). diff --git a/doc/conky.1 b/doc/conky.1 index 0add2ee2..7902dc93 100644 --- a/doc/conky.1 +++ b/doc/conky.1 @@ -529,6 +529,11 @@ The current volume fetched from Audacious \fB\*(T<\fBbattery\fR\*(T>\fR \*(T<\fB(num)\fR\*(T> Battery status and remaining percentage capacity of ACPI or APM battery. ACPI battery number can be given as argument (default is BAT0). +.TP +\fB\*(T<\fBbattery_short\fR\*(T>\fR \*(T<\fB(num)\fR\*(T> +Battery status and remaining percentage capacity of ACPI or APM battery. ACPI battery number can be given as argument (default is BAT0). +This mode display a short status, which means that C is displayed instead of charging and D is displayed instead of discharging. + .TP \fB\*(T<\fBbattery_bar\fR\*(T>\fR \*(T<\fB(height),(width) (num)\fR\*(T> Battery percentage remaining of ACPI battery in a bar. ACPI battery number can be given as argument (default is BAT0). diff --git a/doc/variables.xml b/doc/variables.xml index 2c523faf..05a8eeb5 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -251,6 +251,17 @@ + + + + + + + Battery status and remaining percentage capacity of ACPI or APM battery. ACPI battery number can be given as argument (default is BAT0). + This mode display a short status, which means that C is displayed instead of charging and D is displayed instead of discharging. + + + @@ -2026,19 +2037,19 @@ The following list shows sample usage of the templates defined above, with the equivalent syntax when not using any template at all: - - - using templatesame without template - - - ${template0 node name}$nodename - ${template1 root /}root: ${fs_free /} / ${fs_size /} - - ${template1 ${template2\ disk\ root} /} - disk root: ${fs_free /} / ${fs_size /} - - - + + + using templatesame without template + + + ${template0 node name}$nodename + ${template1 root /}root: ${fs_free /} / ${fs_size /} + + ${template1 ${template2\ disk\ root} /} + disk root: ${fs_free /} / ${fs_size /} + + +
@@ -2503,8 +2514,8 @@ Prints the song name in either the form "artist - title" or file name, depending on whats available - - + + @@ -2518,7 +2529,7 @@ - Fetches your currently training skill from the Eve Online API servers (http://www.eve-online.com/) and displays the skill along with the remaining training time. + Fetches your currently training skill from the Eve Online API servers (http://www.eve-online.com/) and displays the skill along with the remaining training time. diff --git a/src/common.h b/src/common.h index 09e9fbed..057cab0f 100644 --- a/src/common.h +++ b/src/common.h @@ -92,5 +92,6 @@ 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); +void get_battery_short_status(char *buf, unsigned int n, const char *bat); #endif /* _COMMON_H */ diff --git a/src/conky.c b/src/conky.c index 85affa81..37594552 100644 --- a/src/conky.c +++ b/src/conky.c @@ -1438,6 +1438,9 @@ static void free_text_objects(struct text_object *root) case OBJ_battery: free(data.s); break; + case OBJ_battery_short: + free(data.s); + break; case OBJ_battery_time: free(data.s); break; @@ -1733,6 +1736,15 @@ static struct text_object *construct_text_object(const char *s, END OBJ(battery, 0) char bat[64]; + if (arg) { + sscanf(arg, "%63s", bat); + } else { + strcpy(bat, "BAT0"); + } + obj->data.s = strndup(bat, text_buffer_size); + END OBJ(battery_short, 0) + char bat[64]; + if (arg) { sscanf(arg, "%63s", bat); } else { @@ -3834,6 +3846,9 @@ static void generate_text_internal(char *p, int p_max_size, OBJ(battery_bar) { new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s)); } + OBJ(battery_short) { + get_battery_short_status(p, p_max_size, obj->data.s); + } #endif /* __OpenBSD__ */ OBJ(buffers) { diff --git a/src/linux.c b/src/linux.c index f3a8ef9b..41d7bd1c 100644 --- a/src/linux.c +++ b/src/linux.c @@ -1842,6 +1842,18 @@ void set_return_value(char *buffer, unsigned int n, int item, int idx) } } +void get_battery_short_status(char *buffer, unsigned int n, const char *bat) +{ + get_battery_stuff(buffer, n, bat, BATTERY_STATUS); + if (0 == strncmp("charging", buffer, 8)) { + buffer[0] = 'C'; + memmove(buffer + 1, buffer + 8, n - 8); + } else if (0 == strncmp("discharging", buffer, 11)) { + buffer[0] = 'D'; + memmove(buffer + 1, buffer + 11, n - 11); + } +} + int get_battery_perct(const char *bat) { static int rep = 0; diff --git a/src/text_object.h b/src/text_object.h index 687647d3..60c5a70d 100644 --- a/src/text_object.h +++ b/src/text_object.h @@ -56,6 +56,7 @@ enum text_object_type { OBJ_battery_time, OBJ_battery_percent, OBJ_battery_bar, + OBJ_battery_short, #endif /* !__OpenBSD__ */ OBJ_buffers, OBJ_cached,