]> git.sur5r.net Git - i3/i3status/commitdiff
Add simple volume support on FreeBSD
authorBaptiste Daroussin <bapt@FreeBSD.org>
Sun, 24 Jul 2011 02:03:59 +0000 (02:03 +0000)
committerMichael Stapelberg <michael@stapelberg.de>
Sun, 24 Jul 2011 00:12:23 +0000 (02:12 +0200)
src/print_volume.c

index 2945b1ec060314f8cc257d91a28219fafd9b5f40..c13cb1761f4a206e9d2c999cef6c888c9563e153 100644 (file)
@@ -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
 }