From 4bd0ba88c896d1ad9beba2eaadc01f1f2d172b5b Mon Sep 17 00:00:00 2001 From: Gereon Kremer Date: Fri, 15 Nov 2013 00:41:33 +0100 Subject: Added different format string for volume in case it is muted. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- src/print_volume.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/print_volume.c b/src/print_volume.c index d84b3ec..493167a 100644 --- a/src/print_volume.c +++ b/src/print_volume.c @@ -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"); -- cgit v1.2.3