Created three individual Strings for each battery status (charging, dicharching, full)
Patch status: merged
Patch by Cyril Andreatta
Long description:
Replaced hard coded status strings (CHR, BAT, FULL) in print_battery_info.c with user defined strings. The new strings are 'status_chr', 'status_bat' and 'status_full' and can be set in i3status.conf. e.g. status_chr = "⚡ CHR" If any of the new status strings is omitted the standard strings (CHR, BAT, FULL) are used.
To apply this patch, use:
curl http://cr.i3wm.org/patch/654/raw.patch | git am
b/i3status.c
27 |
@@ -319,6 +319,9 @@ int main(int argc, char *argv[]) { |
28 |
cfg_opt_t battery_opts[] = { |
29 |
CFG_STR("format", "%status %percentage %remaining", CFGF_NONE), |
30 |
CFG_STR("format_down", "No battery", CFGF_NONE), |
31 |
+ CFG_STR("status_chr", "CHR", CFGF_NONE), |
32 |
+ CFG_STR("status_bat", "BAT", CFGF_NONE), |
33 |
+ CFG_STR("status_full", "FULL", CFGF_NONE), |
34 |
CFG_STR("path", "/sys/class/power_supply/BAT%d/uevent", CFGF_NONE), |
35 |
CFG_INT("low_threshold", 30, CFGF_NONE), |
36 |
CFG_STR("threshold_type", "time", CFGF_NONE), |
37 |
@@ -585,7 +588,7 @@ int main(int argc, char *argv[]) { |
38 |
|
39 |
CASE_SEC_TITLE("battery") { |
40 |
SEC_OPEN_MAP("battery"); |
41 |
- print_battery_info(json_gen, buffer, atoi(title), cfg_getstr(sec, "path"), cfg_getstr(sec, "format"), cfg_getstr(sec, "format_down"), cfg_getint(sec, "low_threshold"), cfg_getstr(sec, "threshold_type"), cfg_getbool(sec, "last_full_capacity"), cfg_getbool(sec, "integer_battery_capacity"), cfg_getbool(sec, "hide_seconds")); |
42 |
+ print_battery_info(json_gen, buffer, atoi(title), cfg_getstr(sec, "path"), cfg_getstr(sec, "format"), cfg_getstr(sec, "format_down"), cfg_getstr(sec, "status_chr"), cfg_getstr(sec, "status_bat"), cfg_getstr(sec, "status_full"), cfg_getint(sec, "low_threshold"), cfg_getstr(sec, "threshold_type"), cfg_getbool(sec, "last_full_capacity"), cfg_getbool(sec, "integer_battery_capacity"), cfg_getbool(sec, "hide_seconds")); |
43 |
SEC_CLOSE_MAP; |
44 |
} |
45 |
|
b/include/i3status.h
50 |
@@ -172,7 +172,7 @@ void set_timezone(const char *tz); |
51 |
|
52 |
void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down); |
53 |
void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format, const char *prefix_type, const char *threshold_type, const double low_threshold); |
54 |
-void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity, bool hide_seconds); |
55 |
+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_full, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity, bool hide_seconds); |
56 |
void print_time(yajl_gen json_gen, char *buffer, const char *format, const char *tz, time_t t); |
57 |
void print_ddate(yajl_gen json_gen, char *buffer, const char *format, time_t t); |
58 |
const char *get_ip_addr(); |
b/src/print_battery_info.c
63 |
@@ -27,16 +27,13 @@ |
64 |
#include <sys/envsys.h> |
65 |
#endif |
66 |
|
67 |
-#define BATT_STATUS_NAME(status) \ |
68 |
- (status == CS_CHARGING ? "CHR" : \ |
69 |
- (status == CS_DISCHARGING ? "BAT" : "FULL")) |
70 |
/* |
71 |
* Get battery information from /sys. Note that it uses the design capacity to |
72 |
* calculate the percentage, not the last full capacity, so you can see how |
73 |
* worn off your battery is. |
74 |
* |
75 |
*/ |
76 |
-void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity, bool hide_seconds) { |
77 |
+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_full, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity, bool hide_seconds) { |
78 |
time_t empty_time; |
79 |
struct tm *empty_tm; |
80 |
char buf[1024]; |
81 |
@@ -65,6 +62,10 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char |
82 |
sprintf(batpath, path, number); |
83 |
INSTANCE(batpath); |
84 |
|
85 |
+#define BATT_STATUS_NAME(status) \ |
86 |
+ (status == CS_CHARGING ? status_chr : \ |
87 |
+ (status == CS_DISCHARGING ? status_bat : status_full)) |
88 |
+ |
89 |
#if defined(LINUX) |
90 |
if (!slurp(batpath, buf, sizeof(buf))) { |
91 |
OUTPUT_FULL_TEXT(format_down); |
92 |
-- |
93 |
2.1.2 |
94 | |
95 | |
96 |
From 843111861ebd6bc29caa09c26aa20dc37a29f05e Mon Sep 17 00:00:00 2001 |
97 |
From: Cyril Andreatta <cyril@andreatta.ch> |
98 |
Date: Tue, 7 Oct 2014 16:14:16 +0200 |
99 |
Subject: [PATCH 2/2] Updated the man page for i3status with information about |
100 |
the new individual strings that can be used for each battery status. |
101 | |
102 |
--- |
103 |
man/i3status.man | 16 ++++++++++++++++ |
104 |
1 file changed, 16 insertions(+) |
105 |
b/man/i3status.man
110 |
@@ -74,6 +74,9 @@ ethernet eth0 { |
111 |
battery 0 { |
112 |
format = "%status %percentage %remaining %emptytime" |
113 |
format_down = "No battery" |
114 |
+ status_chr = "⚇ CHR"" |
115 |
+ status_bat = "⚡ BAT" |
116 |
+ status_full = "☻ FULL" |
117 |
path = "/sys/class/power_supply/BAT%d/uevent" |
118 |
low_threshold = 10 |
119 |
} |
120 |
@@ -309,12 +312,25 @@ colored red. The low_threshold type can be of threshold_type "time" or |
121 |
"percentage". So, if you configure low_threshold to 10 and threshold_type to |
122 |
"time", and your battery lasts another 9 minutes, it will be colored red. |
123 |
|
124 |
+Optionally custom strings including any UTF-8 symbols can be used for different |
125 |
+battery states. This makes it possible to display individual symbols |
126 |
+for each state (charging, discharging, full) |
127 |
+Of course it will also work with special iconic fonts, such as FontAwesome. |
128 |
+If any of this special status strings is omitted, the default (CHR, BAT, FULL) |
129 |
+is used. |
130 |
+ |
131 |
*Example order*: +battery 0+ |
132 |
|
133 |
*Example format*: +%status %remaining (%emptytime %consumption)+ |
134 |
|
135 |
*Example format_down*: +No battery+ |
136 |
|
137 |
+*Example status_chr*: +⚇ CHR+ |
138 |
+ |
139 |
+*Example status_bat*: +⚡ BAT+ |
140 |
+ |
141 |
+*Example status_full*: +☻ FULL+ |
142 |
+ |
143 |
*Example low_threshold*: +30+ |
144 |
|
145 |
*Example threshold_type*: +time+ |