i3 - improved tiling WM


Added format_down option for battery if no battery is available.

Patch status: merged

Patch by Christoph Göttschkes

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

b/i3status.c

17
@@ -230,6 +230,7 @@ int main(int argc, char *argv[]) {
18
 
19
         cfg_opt_t battery_opts[] = {
20
                 CFG_STR("format", "%status %percentage %remaining", CFGF_NONE),
21
+                CFG_STR("format_down", "No battery", CFGF_NONE),
22
                 CFG_STR("path", "/sys/class/power_supply/BAT%d/uevent", CFGF_NONE),
23
                 CFG_INT("low_threshold", 30, CFGF_NONE),
24
                 CFG_STR("threshold_type", "time", CFGF_NONE),
25
@@ -444,7 +445,7 @@ int main(int argc, char *argv[]) {
26
 
27
                         CASE_SEC_TITLE("battery") {
28
                                 SEC_OPEN_MAP("battery");
29
-                                print_battery_info(json_gen, buffer, atoi(title), cfg_getstr(sec, "path"), cfg_getstr(sec, "format"), cfg_getint(sec, "low_threshold"), cfg_getstr(sec, "threshold_type"), cfg_getbool(sec, "last_full_capacity"), cfg_getbool(sec, "integer_battery_capacity"));
30
+                                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"));
31
                                 SEC_CLOSE_MAP;
32
                         }
33
 

b/include/i3status.h

38
@@ -142,7 +142,7 @@ void set_timezone(const char *tz);
39
 
40
 void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down);
41
 void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format);
42
-void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity);
43
+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);
44
 void print_time(yajl_gen json_gen, char *buffer, const char *format, const char *tz, time_t t);
45
 void print_ddate(yajl_gen json_gen, char *buffer, const char *format, time_t t);
46
 const char *get_ip_addr();

b/man/i3status.man

51
@@ -72,6 +72,7 @@ ethernet eth0 {
52
 
53
 battery 0 {
54
         format = "%status %percentage %remaining %emptytime"
55
+        format_down = "No battery"
56
         path = "/sys/class/power_supply/BAT%d/uevent"
57
         low_threshold = 10
58
 }

b/src/print_battery_info.c

63
@@ -30,7 +30,7 @@
64
  * worn off your battery is.
65
  *
66
  */
67
-void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity) {
68
+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) {
69
         time_t empty_time;
70
         struct tm *empty_tm;
71
         char buf[1024];
72
@@ -61,7 +61,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
73
         static char batpath[512];
74
         sprintf(batpath, path, number);
75
         if (!slurp(batpath, buf, sizeof(buf))) {
76
-                OUTPUT_FULL_TEXT("No battery");
77
+                OUTPUT_FULL_TEXT(format_down);
78
                 return;
79
         }
80
 
81
@@ -123,7 +123,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
82
         }
83
 
84
         if ((full_design == -1) || (remaining == -1)) {
85
-                OUTPUT_FULL_TEXT("No battery");
86
+                OUTPUT_FULL_TEXT(format_down);
87
                 return;
88
         }
89
 
90
@@ -196,19 +196,19 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
91
         size_t sysctl_size = sizeof(sysctl_rslt);
92
 
93
         if (sysctlbyname(BATT_LIFE, &sysctl_rslt, &sysctl_size, NULL, 0) != 0) {
94
-                OUTPUT_FULL_TEXT("No battery");
95
+                OUTPUT_FULL_TEXT(format_down);
96
                 return;
97
         }
98
 
99
         present_rate = sysctl_rslt;
100
         if (sysctlbyname(BATT_TIME, &sysctl_rslt, &sysctl_size, NULL, 0) != 0) {
101
-                OUTPUT_FULL_TEXT("No battery");
102
+                OUTPUT_FULL_TEXT(format_down);
103
                 return;
104
         }
105
 
106
         remaining = sysctl_rslt;
107
         if (sysctlbyname(BATT_STATE, &sysctl_rslt, &sysctl_size, NULL,0) != 0) {
108
-                OUTPUT_FULL_TEXT("No battery");
109
+                OUTPUT_FULL_TEXT(format_down);
110
                 return;
111
         }
112
 
113
@@ -257,7 +257,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
114
 	/* Don't bother to go further if there's no battery present. */
115
 	if ((apm_info.battery_state == APM_BATTERY_ABSENT) ||
116
 	    (apm_info.battery_state == APM_BATT_UNKNOWN)) {
117
-		OUTPUT_FULL_TEXT("No battery");
118
+		OUTPUT_FULL_TEXT(format_down);
119
 		return;
120
 	}
121