]> git.sur5r.net Git - i3/i3status/blobdiff - src/print_volume.c
Error handling: Never output null as full_text (JSON), prefix messages with i3status...
[i3/i3status] / src / print_volume.c
index 5c34c3e6d16e0e5ef72b5bc7c5e91ec9381550a3..dbf5e1ff02022f521f05c3cc4dd428911593fb07 100644 (file)
@@ -3,6 +3,8 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <yajl/yajl_gen.h>
+#include <yajl/yajl_version.h>
 
 #ifdef LINUX
 #include <alsa/asoundlib.h>
 #include <sys/soundcard.h>
 #endif
 
+#ifdef __OpenBSD__
+#include <fcntl.h>
+#include <unistd.h>
+#include <soundcard.h>
+#endif
+
 #include "i3status.h"
 #include "queue.h"
 
@@ -89,14 +97,14 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
                }
 
                if ((err = snd_mixer_open(&(hdl->m), 0)) < 0) {
-                       fprintf(stderr, "ALSA: Cannot open mixer: %s\n", snd_strerror(err));
+                       fprintf(stderr, "i3status: ALSA: Cannot open mixer: %s\n", snd_strerror(err));
                        free_hdl(hdl);
                        return;
                }
 
                /* Attach this mixer handle to the given device */
                if ((err = snd_mixer_attach(hdl->m, device)) < 0) {
-                       fprintf(stderr, "ALSA: Cannot attach mixer to device: %s\n", snd_strerror(err));
+                       fprintf(stderr, "i3status: ALSA: Cannot attach mixer to device: %s\n", snd_strerror(err));
                        snd_mixer_close(hdl->m);
                        free_hdl(hdl);
                        return;
@@ -104,14 +112,14 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
 
                /* Register this mixer */
                if ((err = snd_mixer_selem_register(hdl->m, NULL, NULL)) < 0) {
-                       fprintf(stderr, "ALSA: snd_mixer_selem_register: %s\n", snd_strerror(err));
+                       fprintf(stderr, "i3status: ALSA: snd_mixer_selem_register: %s\n", snd_strerror(err));
                        snd_mixer_close(hdl->m);
                        free_hdl(hdl);
                        return;
                }
 
                if ((err = snd_mixer_load(hdl->m)) < 0) {
-                       fprintf(stderr, "ALSA: snd_mixer_load: %s\n", snd_strerror(err));
+                       fprintf(stderr, "i3status: ALSA: snd_mixer_load: %s\n", snd_strerror(err));
                        snd_mixer_close(hdl->m);
                        free_hdl(hdl);
                        return;
@@ -121,7 +129,7 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
                snd_mixer_selem_id_set_index(hdl->sid, mixer_idx);
                snd_mixer_selem_id_set_name(hdl->sid, mixer);
                if (!(hdl->elem = snd_mixer_find_selem(hdl->m, hdl->sid))) {
-                       fprintf(stderr, "ALSA: Cannot find mixer %s (index %i)\n",
+                       fprintf(stderr, "i3status: ALSA: Cannot find mixer %s (index %i)\n",
                                snd_mixer_selem_id_get_name(hdl->sid), snd_mixer_selem_id_get_index(hdl->sid));
                        snd_mixer_close(hdl->m);
                        free_hdl(hdl);
@@ -147,7 +155,7 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
        if (snd_mixer_selem_has_playback_switch(hdl->elem)) {
                int pbval;
                if ((err = snd_mixer_selem_get_playback_switch(hdl->elem, 0, &pbval)) < 0)
-                       fprintf (stderr, "ALSA: playback_switch: %s\n", snd_strerror(err));
+                       fprintf (stderr, "i3status: ALSA: playback_switch: %s\n", snd_strerror(err));
                if (!pbval)
                        avg = 0;
        }
@@ -164,7 +172,7 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
                }
        }
 #endif
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__OpenBSD__)
         char mixerpath[] = "/dev/mixer";
         int mixfd, vol, devmask = 0;