i3 - improved tiling WM


Added different format string for volume in case it is muted.

Patch status: merged

Patch by Gereon Kremer

Long description:

If the volume is muted, the volume level would simply be displayed as zero and the color changed to color_degraded.
This patch lets the user define a custom format string for when the volume is muted.
The default value is "♪: 0%" ("♪: %volume" being the usual format).

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

b/i3status.c

21
@@ -286,6 +286,7 @@ int main(int argc, char *argv[]) {
22
 
23
         cfg_opt_t volume_opts[] = {
24
                 CFG_STR("format", "♪: %volume", CFGF_NONE),
25
+                CFG_STR("format_muted", "♪: 0%%", CFGF_NONE),
26
                 CFG_STR("device", "default", CFGF_NONE),
27
                 CFG_STR("mixer", "Master", CFGF_NONE),
28
                 CFG_INT("mixer_idx", 0, CFGF_NONE),
29
@@ -513,6 +514,7 @@ int main(int argc, char *argv[]) {
30
                         CASE_SEC_TITLE("volume") {
31
                                 SEC_OPEN_MAP("volume");
32
                                 print_volume(json_gen, buffer, cfg_getstr(sec, "format"),
33
+                                             cfg_getstr(sec, "format_muted"),
34
                                              cfg_getstr(sec, "device"),
35
                                              cfg_getstr(sec, "mixer"),
36
                                              cfg_getint(sec, "mixer_idx"));

b/include/i3status.h

41
@@ -156,7 +156,7 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
42
 void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format);
43
 void print_eth_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down);
44
 void print_load(yajl_gen json_gen, char *buffer, const char *format, const float max_threshold);
45
-void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *device, const char *mixer, int mixer_idx);
46
+void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *fmt_muted, const char *device, const char *mixer, int mixer_idx);
47
 bool process_runs(const char *path);
48
 
49
 /* socket file descriptor for general purposes */

b/src/print_volume.c

54
@@ -26,7 +26,7 @@
55
 #include "i3status.h"
56
 #include "queue.h"
57
 
58
-void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *device, const char *mixer, int mixer_idx) {
59
+void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *fmt_muted, const char *device, const char *mixer, int mixer_idx) {
60
         char *outwalk = buffer;
61
 	int pbval = 1;
62
 
63
@@ -104,7 +104,7 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
64
 			fprintf (stderr, "i3status: ALSA: playback_switch: %s\n", snd_strerror(err));
65
 		if (!pbval)  {
66
 			START_COLOR("color_degraded");
67
-			avg = 0;
68
+			fmt = fmt_muted;
69
 		}
70
 	}
71
 
72
@@ -117,6 +117,10 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
73
                         *(outwalk++) = *walk;
74
 			continue;
75
 		}
76
+		if (BEGINS_WITH(walk+1, "%")) {
77
+			outwalk += sprintf(outwalk, "%%");
78
+			walk += strlen("%");
79
+		}
80
 		if (BEGINS_WITH(walk+1, "volume")) {
81
 			outwalk += sprintf(outwalk, "%d%%", avg);
82
 			walk += strlen("volume");
83
@@ -156,6 +160,10 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
84
                         *(outwalk++) = *walk;
85
                         continue;
86
                 }
87
+                if (BEGINS_WITH(walk+1, "%")) {
88
+                    outwalk += sprintf(outwalk, "%%");
89
+                    walk += strlen("%");
90
+                }
91
                 if (BEGINS_WITH(walk+1, "volume")) {
92
                         outwalk += sprintf(outwalk, "%d%%", vol & 0x7f);
93
                         walk += strlen("volume");