summaryrefslogtreecommitdiff
path: root/src/print_volume.c
diff options
context:
space:
mode:
authorEugene Dzhurinsky <jdevelop@gmail.com>2018-12-28 12:17:53 -0500
committerEugene Dzhurinsky <jdevelop@gmail.com>2019-01-03 21:59:33 -0500
commit696ddf461fd4fd665bdf46bf1dd26a3210236cff (patch)
tree735dd106abf65772b90617e3c61a44d9743212fe /src/print_volume.c
parenta84ad18fbfe2fa8d9280ca0ad3d131d9fd067afb (diff)
Fixed ALSA capture device monitoring.
When using ALSA, the "Capture" mixer doesn't have the playback channel, instead "capture"-related methods should be used to get information about the current volume / state of the mixer.
Diffstat (limited to 'src/print_volume.c')
-rw-r--r--src/print_volume.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/print_volume.c b/src/print_volume.c
index c3180fe..aa739a1 100644
--- a/src/print_volume.c
+++ b/src/print_volume.c
@@ -30,6 +30,23 @@
#include "i3status.h"
#include "queue.h"
+#define ALSA_VOLUME(channel) \
+ err = snd_mixer_selem_get_##channel##_dB_range(elem, &min, &max) || \
+ snd_mixer_selem_get_##channel##_dB(elem, 0, &val); \
+ if (err != 0 || min >= max) { \
+ err = snd_mixer_selem_get_##channel##_volume_range(elem, &min, &max) || \
+ snd_mixer_selem_get_##channel##_volume(elem, 0, &val); \
+ force_linear = true; \
+ }
+
+#define ALSA_MUTE_SWITCH(channel) \
+ if ((err = snd_mixer_selem_get_##channel##_switch(elem, 0, &pbval)) < 0) \
+ fprintf(stderr, "i3status: ALSA: " #channel "_switch: %s\n", snd_strerror(err)); \
+ if (!pbval) { \
+ START_COLOR("color_degraded"); \
+ fmt = fmt_muted; \
+ }
+
static char *apply_volume_format(const char *fmt, char *outwalk, int ivolume) {
const char *walk = fmt;
@@ -165,12 +182,10 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
/* Get the volume range to convert the volume later */
snd_mixer_handle_events(m);
- err = snd_mixer_selem_get_playback_dB_range(elem, &min, &max) ||
- snd_mixer_selem_get_playback_dB(elem, 0, &val);
- if (err != 0 || min >= max) {
- err = snd_mixer_selem_get_playback_volume_range(elem, &min, &max) ||
- snd_mixer_selem_get_playback_volume(elem, 0, &val);
- force_linear = true;
+ if (!strncasecmp(mixer, "capture", strlen("capture"))) {
+ ALSA_VOLUME(capture)
+ } else {
+ ALSA_VOLUME(playback)
}
if (err != 0) {
@@ -195,12 +210,9 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
/* Check for mute */
if (snd_mixer_selem_has_playback_switch(elem)) {
- if ((err = snd_mixer_selem_get_playback_switch(elem, 0, &pbval)) < 0)
- fprintf(stderr, "i3status: ALSA: playback_switch: %s\n", snd_strerror(err));
- if (!pbval) {
- START_COLOR("color_degraded");
- fmt = fmt_muted;
- }
+ ALSA_MUTE_SWITCH(playback)
+ } else if (snd_mixer_selem_has_capture_switch(elem)) {
+ ALSA_MUTE_SWITCH(capture)
}
snd_mixer_close(m);