slstatus-alsa-mute-1.0.diff (1464B)
1 From 36f56dcdccdf986dd9ddf090a5ae16165b3b23e0 Mon Sep 17 00:00:00 2001 2 From: sewn <sewn@disroot.org> 3 Date: Sat, 12 Oct 2024 18:58:05 +0300 4 Subject: [PATCH] volume: add mute support for ALSA 5 6 --- 7 components/volume.c | 11 +++++++++-- 8 1 file changed, 9 insertions(+), 2 deletions(-) 9 10 diff --git a/components/volume.c b/components/volume.c 11 index 15c5a39..eb56c47 100644 12 --- a/components/volume.c 13 +++ b/components/volume.c 14 @@ -193,7 +193,7 @@ 15 snd_mixer_selem_id_t *mixid = NULL; 16 snd_mixer_elem_t *elem = NULL; 17 long min = 0, max = 0, volume = -1; 18 - int err; 19 + int err, sw1, sw2; 20 21 if ((err = snd_mixer_open(&mixer, 0))) { 22 warn("snd_mixer_open: %d", err); 23 @@ -229,13 +229,20 @@ 24 if ((err = snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_MONO, &volume))) { 25 warn("snd_mixer_selem_get_playback_volume(): %d", err); 26 } 27 + if ((err = snd_mixer_selem_get_playback_switch(elem, 0, &sw1))) { 28 + warn("snd_mixer_selem_get_playback_switch(): %d", err); 29 + } 30 + if ((err = snd_mixer_selem_get_playback_switch(elem, 1, &sw2))) { 31 + warn("snd_mixer_selem_get_playback_switch(): %d", err); 32 + } 33 34 cleanup: 35 snd_mixer_free(mixer); 36 snd_mixer_detach(mixer, devname); 37 snd_mixer_close(mixer); 38 39 - return volume == -1 ? NULL : bprintf("%.0f", (volume-min)*100./(max-min)); 40 + return volume == -1 ? NULL : bprintf("%s%.0f", 41 + !(sw1 || sw2) ? "muted " : "", (volume-min)*100./(max-min)); 42 } 43 #else 44 #include <sys/soundcard.h> 45 -- 46 2.46.2 47