summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2011-07-24 02:03:59 +0000
committerMichael Stapelberg <michael@stapelberg.de>2011-07-24 02:12:23 +0200
commitd87a735be568a144fd1ccd5628ef2a40fe094b07 (patch)
tree24f9da5e3b9da3292d68b7447102c81c6d5c0a0f /src
parentf288fd2e4fb2c2861d6d417fb8bfff5f0a297749 (diff)
Add simple volume support on FreeBSD
Diffstat (limited to 'src')
-rw-r--r--src/print_volume.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/print_volume.c b/src/print_volume.c
index 2945b1e..c13cb17 100644
--- a/src/print_volume.c
+++ b/src/print_volume.c
@@ -9,6 +9,12 @@
#include <alloca.h>
#endif
+#ifdef __FreeBSD__
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/soundcard.h>
+#endif
+
#include "i3status.h"
#include "queue.h"
@@ -150,4 +156,28 @@ void print_volume(const char *fmt, const char *device, const char *mixer, int mi
}
}
#endif
+#ifdef __FreeBSD__
+ char mixerpath[] = "/dev/mixer";
+ int mixfd, vol, devmask = 0;
+
+ if ((mixfd = open(mixerpath, O_RDWR)) < 0)
+ return;
+ if (ioctl(mixfd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1)
+ return;
+ if (ioctl(mixfd, MIXER_READ(0),&vol) == -1)
+ return;
+
+ const char *walk = fmt;
+ for (; *walk != '\0'; walk++) {
+ if (*walk != '%') {
+ putchar(*walk);
+ continue;
+ }
+ if (BEGINS_WITH(walk+1, "volume")) {
+ printf("%d%%", vol & 0x7f);
+ walk += strlen("volume");
+ }
+ }
+ close(mixfd);
+#endif
}