spoon

set dwm status
git clone git://git.2f30.org/spoon
Log | Files | Refs | LICENSE

commit bd6425ea89b3da5f3f9da693110db6e891b3c474
parent 27087e9c6c2e404ad71a440f2ddf7c76b36831e5
Author: Svyatoslav Mishyn <juef@openmailbox.org>
Date:   Mon, 23 Oct 2017 23:37:12 +0300

mix: add TinyALSA support

Diffstat:
MMakefile | 5+++++
Mmix.c | 48+++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -25,7 +25,12 @@ LDLIBS = -lX11 # comment out the following sections. The stub implementations # from stub.c will be used instead. OBJ += mix.o +# if ALSA LDLIBS_Linux_mix = -lasound +CPPFLAGS += -DUSE_TINYALSA=0 +# else TinyALSA +#LDLIBS_Linux_mix = -ltinyalsa +#CPPFLAGS += -DUSE_TINYALSA=1 LDLIBS += $(LDLIBS_$(UNAME)_mix) OBJ += xkblayout.o diff --git a/mix.c b/mix.c @@ -66,7 +66,7 @@ out: close(fd); return ret; } -#elif __linux__ +#elif __linux__ && !USE_TINYALSA #include <alsa/asoundlib.h> static int master; @@ -166,4 +166,50 @@ out: mixerp = NULL; return -1; } +#elif __linux__ && USE_TINYALSA +#include <tinyalsa/asoundlib.h> + +int +mixread(void *arg, char *buf, size_t len) +{ + struct mixer *mixer; + struct mixer_ctl *ctl; + int vol, max; + int rc = 0; + (void)arg; + + if ((mixer = mixer_open(0)) == NULL) { + fprintf(stderr, "mixer_open() failed\n"); + return -1; + } + + /* Master Playback Switch, see `tinymix contents` */ + if ((ctl = mixer_get_ctl(mixer, 10)) == NULL) { + fprintf(stderr, "mixer_get_ctl_by_name() failed\n"); + rc = -1; + goto exit; + } + if (!mixer_ctl_get_value(ctl, 0)) { + snprintf(buf, len, "mute"); + goto exit; + } + + /* Master Playback Volume, see `tinymix contents` */ + if ((ctl = mixer_get_ctl(mixer, 9)) == NULL) { + fprintf(stderr, "mixer_get_ctl_by_name() failed\n"); + rc = -1; + goto exit; + } + if (!(vol = mixer_ctl_get_value(ctl, 0))) { + snprintf(buf, len, "0%%"); + goto exit; + } + + max = mixer_ctl_get_range_max(ctl); + snprintf(buf, len, "%d%%", vol * 100 / max); + +exit: + mixer_close(mixer); + return rc; +} #endif