slstatus-alsa-mute-1.0.diff (1451B)
1 From 8375f197e9af7d219abe65cf0311ea16dea852f1 Mon Sep 17 00:00:00 2001 2 From: sewn <sewn@disroot.org> 3 Date: Thu, 31 Aug 2023 15:01:07 +0300 4 Subject: [PATCH] volume: add mute support for ALSA 5 6 --- 7 components/volume.c | 10 ++++++++-- 8 1 file changed, 8 insertions(+), 2 deletions(-) 9 10 diff --git a/components/volume.c b/components/volume.c 11 index 15c5a39..8636f61 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,19 @@ 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 !(sw1 || sw2) ? "mute" : volume == -1 ? NULL : bprintf("%.0f", (volume-min)*100./(max-min)); 41 } 42 #else 43 #include <sys/soundcard.h> 44 -- 45 2.42.0 46