[wiki] [sites] [slstatus] Add alsa patch from mailing list || drkhsh

From: <git_AT_suckless.org>
Date: Wed, 23 Nov 2022 22:23:25 +0100

commit c08ac370c650625fc389040c822dccf0afc86876
Author: drkhsh <me_AT_drkhsh.at>
Date: Wed Nov 23 22:17:46 2022 +0100

    [slstatus] Add alsa patch from mailing list
    
    This patch adds ALSA volume support. slstatus on-purpose makes use of
    `/dev/mixer` per default because it is a much simpler interface and
    all distributions still support it.
    
    Anyone refusing to use it may use this patch.
    
    Credits to: Ivan Krylov <krylov.r00t_AT_gmail.com>

diff --git a/tools.suckless.org/slstatus/patches/alsa/index.md b/tools.suckless.org/slstatus/patches/alsa/index.md
new file mode 100644
index 00000000..3d91c524
--- /dev/null
+++ b/tools.suckless.org/slstatus/patches/alsa/index.md
_AT_@ -0,0 +1,21 @@
+alsa
+====
+
+Description
+-----------
+This patch adds ALSA volume support. slstatus on-purpose makes use of
+`/dev/mixer` per default because it is a much simpler interface and
+all distributions still support it. Anyone refusing to use it may use
+this patch.
+
+To use, add `-DALSA` to `CPPFLAGS`, `-lasound` to `LDFLAGS` and pass the
+control name (e.g. Master) as argument to `vol_perc` in config.h.
+
+Download
+--------
+* [slstatus-alsa-4bd78c9.patch](slstatus-alsa-4bd78c9.patch)
+
+Authors
+-------
+* Ivan Krylov <krylov.r00t_AT_gmail.com>
+* drkhsh <me_AT_drkhsh.at>
diff --git a/tools.suckless.org/slstatus/patches/alsa/slstatus-alsa-4bd78c9.patch b/tools.suckless.org/slstatus/patches/alsa/slstatus-alsa-4bd78c9.patch
new file mode 100644
index 00000000..c3384b1f
--- /dev/null
+++ b/tools.suckless.org/slstatus/patches/alsa/slstatus-alsa-4bd78c9.patch
_AT_@ -0,0 +1,74 @@
+Author: Ivan Krylov <krylov.r00t_AT_gmail.com>
+Date: Sat May 4 11:59:58 2019 +0300
+
+ Add ALSA volume support
+
+ To use, add -DALSA to CPPFLAGS, -lasound to LDFLAGS and pass the
+ control name (e.g. Master) as argument to vol_perc in config.h.
+
+diff --git a/components/volume.c b/components/volume.c
+index 6cec556..15c5a39 100644
+--- a/components/volume.c
++++ b/components/volume.c
+_AT_@ -182,6 +182,61 @@
+
+ return bprintf("%d", value);
+ }
++#elif defined(ALSA)
++ #include <alsa/asoundlib.h>
++
++ static const char *devname = "default";
++ const char *
++ vol_perc(const char *mixname)
++ {
++ snd_mixer_t *mixer = NULL;
++ snd_mixer_selem_id_t *mixid = NULL;
++ snd_mixer_elem_t *elem = NULL;
++ long min = 0, max = 0, volume = -1;
++ int err;
++
++ if ((err = snd_mixer_open(&mixer, 0))) {
++ warn("snd_mixer_open: %d", err);
++ return NULL;
++ }
++ if ((err = snd_mixer_attach(mixer, devname))) {
++ warn("snd_mixer_attach(mixer, \"%s\"): %d", devname, err);
++ goto cleanup;
++ }
++ if ((err = snd_mixer_selem_register(mixer, NULL, NULL))) {
++ warn("snd_mixer_selem_register(mixer, NULL, NULL): %d", err);
++ goto cleanup;
++ }
++ if ((err = snd_mixer_load(mixer))) {
++ warn("snd_mixer_load(mixer): %d", err);
++ goto cleanup;
++ }
++
++ snd_mixer_selem_id_alloca(&mixid);
++ snd_mixer_selem_id_set_name(mixid, mixname);
++ snd_mixer_selem_id_set_index(mixid, 0);
++
++ elem = snd_mixer_find_selem(mixer, mixid);
++ if (!elem) {
++ warn("snd_mixer_find_selem(mixer, \"%s\") == NULL", mixname);
++ goto cleanup;
++ }
++
++ if ((err = snd_mixer_selem_get_playback_volume_range(elem, &min, &max))) {
++ warn("snd_mixer_selem_get_playback_volume_range(): %d", err);
++ goto cleanup;
++ }
++ if ((err = snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_MONO, &volume))) {
++ warn("snd_mixer_selem_get_playback_volume(): %d", err);
++ }
++
++ cleanup:
++ snd_mixer_free(mixer);
++ snd_mixer_detach(mixer, devname);
++ snd_mixer_close(mixer);
++
++ return volume == -1 ? NULL : bprintf("%.0f", (volume-min)*100./(max-min));
++ }
+ #else
+ #include <sys/soundcard.h>
+
Received on Wed Nov 23 2022 - 22:23:25 CET

This archive was generated by hypermail 2.3.0 : Wed Nov 23 2022 - 22:24:40 CET