From: Gereon Kremer Date: Thu, 14 Nov 2013 23:41:33 +0000 (+0100) Subject: Added different format string for volume in case it is muted. X-Git-Tag: 2.8~5 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4bd0ba88c896d1ad9beba2eaadc01f1f2d172b5b;p=i3%2Fi3status Added different format string for volume in case it is muted. 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). --- diff --git a/i3status.c b/i3status.c index e99e627..1b9c595 100644 --- a/i3status.c +++ b/i3status.c @@ -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")); diff --git a/include/i3status.h b/include/i3status.h index d0361d1..64cd660 100644 --- a/include/i3status.h +++ b/include/i3status.h @@ -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 */ 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");