---
components/volume.c | 23 +++++++++++++++++++++++
config.mk | 1 +
2 files changed, 24 insertions(+)
diff --git a/components/volume.c b/components/volume.c
index b6665da..45bbc09 100644
--- a/components/volume.c
+++ b/components/volume.c
_AT_@ -2,6 +2,7 @@
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
+#include <sys/param.h> /* for __FreeBSD_version */
#include <sys/ioctl.h>
#include <unistd.h>
_AT_@ -180,6 +181,28 @@
return bprintf("%d", value);
}
+#elif defined(__FreeBSD__) && (__FreeBSD_version >= 1400000)
+ #include <mixer.h>
+
+ const char *
+ vol_perc(const char *card)
+ {
+ struct mixer *m;
+ float v;
+ int n = 0;
+
+ if ((m = mixer_open(card)) == NULL) {
+ warn("mixer_open: %s", card);
+ return NULL;
+ }
+ if (!MIX_ISMUTE(m, m->dev->devno)) {
+ v = (m->dev->vol.left + m->dev->vol.right) / 2.0f;
+ n = MIX_VOLDENORM(v);
+ }
+ (void)mixer_close(m);
+
+ return bprintf("%d", n);
+ }
#else
#include <sys/soundcard.h>
diff --git a/config.mk b/config.mk
index 2516e6e..617afe6 100644
--- a/config.mk
+++ b/config.mk
_AT_@ -16,6 +16,7 @@ CFLAGS = -std=c99 -pedantic -Wall -Wextra -Os
LDFLAGS = -L$(X11LIB) -s
# OpenBSD: add -lsndio
# FreeBSD: add -lkvm
+# if >= 14.0 also -lmixer
LDLIBS = -lX11
# compiler and linker
--
2.32.0
Received on Fri Oct 15 2021 - 01:57:19 CEST
This archive was generated by hypermail 2.3.0 : Fri Oct 15 2021 - 03:00:33 CEST