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).
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),
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"));
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 */
#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;
fprintf (stderr, "i3status: ALSA: playback_switch: %s\n", snd_strerror(err));
if (!pbval) {
START_COLOR("color_degraded");
- avg = 0;
+ fmt = fmt_muted;
}
}
*(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");
*(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");