]> git.sur5r.net Git - i3/i3status/commitdiff
Added different format string for volume in case it is muted.
authorGereon Kremer <gereon.kremer@rwth-aachen.de>
Thu, 14 Nov 2013 23:41:33 +0000 (00:41 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Mon, 18 Nov 2013 21:31:42 +0000 (22:31 +0100)
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).

i3status.c
include/i3status.h
src/print_volume.c

index e99e627be4557d386bd5de1c301c6e91596f7750..1b9c59502ece1c5394e97d6bd965813fc4d4bdac 100644 (file)
@@ -286,6 +286,7 @@ int main(int argc, char *argv[]) {
 
         cfg_opt_t volume_opts[] = {
                 CFG_STR("format", "♪: %volume", CFGF_NONE),
+                CFG_STR("format_muted", "♪: 0%%", CFGF_NONE),
                 CFG_STR("device", "default", CFGF_NONE),
                 CFG_STR("mixer", "Master", CFGF_NONE),
                 CFG_INT("mixer_idx", 0, CFGF_NONE),
@@ -513,6 +514,7 @@ int main(int argc, char *argv[]) {
                         CASE_SEC_TITLE("volume") {
                                 SEC_OPEN_MAP("volume");
                                 print_volume(json_gen, buffer, cfg_getstr(sec, "format"),
+                                             cfg_getstr(sec, "format_muted"),
                                              cfg_getstr(sec, "device"),
                                              cfg_getstr(sec, "mixer"),
                                              cfg_getint(sec, "mixer_idx"));
index d0361d1724014abadafb0b92d09e5de11d672734..64cd660150b5ac53ca8b9c605512b5d7e2a60f6f 100644 (file)
@@ -156,7 +156,7 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
 void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format);
 void print_eth_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down);
 void print_load(yajl_gen json_gen, char *buffer, const char *format, const float max_threshold);
-void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *device, const char *mixer, int mixer_idx);
+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);
 bool process_runs(const char *path);
 
 /* socket file descriptor for general purposes */
index d84b3ecd44549284a19a6bc0a1247f82395159fe..493167a7834d873186bbf22f04286b913771e9ef 100644 (file)
@@ -26,7 +26,7 @@
 #include "i3status.h"
 #include "queue.h"
 
-void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *device, const char *mixer, int mixer_idx) {
+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) {
         char *outwalk = buffer;
        int pbval = 1;
 
@@ -104,7 +104,7 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
                        fprintf (stderr, "i3status: ALSA: playback_switch: %s\n", snd_strerror(err));
                if (!pbval)  {
                        START_COLOR("color_degraded");
-                       avg = 0;
+                       fmt = fmt_muted;
                }
        }
 
@@ -117,6 +117,10 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
                         *(outwalk++) = *walk;
                        continue;
                }
+               if (BEGINS_WITH(walk+1, "%")) {
+                       outwalk += sprintf(outwalk, "%%");
+                       walk += strlen("%");
+               }
                if (BEGINS_WITH(walk+1, "volume")) {
                        outwalk += sprintf(outwalk, "%d%%", avg);
                        walk += strlen("volume");
@@ -156,6 +160,10 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
                         *(outwalk++) = *walk;
                         continue;
                 }
+                if (BEGINS_WITH(walk+1, "%")) {
+                        outwalk += sprintf(outwalk, "%%");
+                        walk += strlen("%");
+                }
                 if (BEGINS_WITH(walk+1, "volume")) {
                         outwalk += sprintf(outwalk, "%d%%", vol & 0x7f);
                         walk += strlen("volume");