i3 - improved tiling WM


Created three individual Strings for each battery status (charging, dicharching, full)

Patch status: needinfo

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 can be set in i3status.conf.
e.g.
status_chr = "charging"

If any of the new status strings is omitted the standard strings
are used.

To apply this patch, use:
curl http://cr.i3wm.org/patch/645/raw.patch | git am

b/i3status.c

25
@@ -319,6 +319,9 @@ int main(int argc, char *argv[]) {
26
         cfg_opt_t battery_opts[] = {
27
                 CFG_STR("format", "%status %percentage %remaining", CFGF_NONE),
28
                 CFG_STR("format_down", "No battery", CFGF_NONE),
29
+                CFG_STR("status_chr", "CHR", CFGF_NONE),
30
+                CFG_STR("status_bat", "BAT", CFGF_NONE),
31
+                CFG_STR("status_full", "FULL", CFGF_NONE),
32
                 CFG_STR("path", "/sys/class/power_supply/BAT%d/uevent", CFGF_NONE),
33
                 CFG_INT("low_threshold", 30, CFGF_NONE),
34
                 CFG_STR("threshold_type", "time", CFGF_NONE),
35
@@ -585,7 +588,7 @@ int main(int argc, char *argv[]) {
36
 
37
                         CASE_SEC_TITLE("battery") {
38
                                 SEC_OPEN_MAP("battery");
39
-                                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"));
40
+                                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"));
41
                                 SEC_CLOSE_MAP;
42
                         }
43
 

b/i3status.conf

48
@@ -8,7 +8,7 @@
49
 
50
 general {
51
         colors = true
52
-        interval = 5
53
+        interval = 1
54
 }
55
 
56
 order += "ipv6"
57
@@ -34,6 +34,10 @@ ethernet eth0 {
58
 
59
 battery 0 {
60
         format = "%status %percentage %remaining"
61
+        status_bat = "BATTERY"
62
+        status_chr = "CHARGING"
63
+        status_full = "BATTERY FULL"
64
+        hide_seconds = true
65
 }
66
 
67
 run_watch DHCP {

b/include/i3status.h

72
@@ -172,7 +172,7 @@ void set_timezone(const char *tz);
73
 
74
 void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down);
75
 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);
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
 void print_time(yajl_gen json_gen, char *buffer, const char *format, const char *tz, time_t t);
79
 void print_ddate(yajl_gen json_gen, char *buffer, const char *format, time_t t);
80
 const char *get_ip_addr();

b/src/print_battery_info.c

85
@@ -27,16 +27,13 @@
86
 #include <sys/envsys.h>
87
 #endif
88
 
89
-#define BATT_STATUS_NAME(status) \
90
-    (status == CS_CHARGING ? "CHR" : \
91
-        (status == CS_DISCHARGING ? "BAT" : "FULL"))
92
 /*
93
  * Get battery information from /sys. Note that it uses the design capacity to
94
  * calculate the percentage, not the last full capacity, so you can see how
95
  * worn off your battery is.
96
  *
97
  */
98
-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) {
99
+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) {
100
         time_t empty_time;
101
         struct tm *empty_tm;
102
         char buf[1024];
103
@@ -65,6 +62,10 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
104
         sprintf(batpath, path, number);
105
         INSTANCE(batpath);
106
 
107
+#define BATT_STATUS_NAME(status) \
108
+    (status == CS_CHARGING ? status_chr : \
109
+        (status == CS_DISCHARGING ? status_bat : status_full))
110
+
111
 #if defined(LINUX)
112
         if (!slurp(batpath, buf, sizeof(buf))) {
113
                 OUTPUT_FULL_TEXT(format_down);