summaryrefslogtreecommitdiff
path: root/src/print_volume.c
diff options
context:
space:
mode:
authorWatcom <watcom.hecht@gmail.com>2016-09-14 04:26:45 -0300
committerMichael Stapelberg <stapelberg@users.noreply.github.com>2016-09-14 09:26:45 +0200
commit8d2ef5f99b2ebc08a0a9d1f26492094692b1fc6b (patch)
treef264785b909bf2b1b9dc9c53f03dcd8126786920 /src/print_volume.c
parent48e10658b46e07b89ee7074af1a56bdc61656f05 (diff)
pulse device may be specified by name (#126) (#162)
Diffstat (limited to 'src/print_volume.c')
-rw-r--r--src/print_volume.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/print_volume.c b/src/print_volume.c
index 58cba2a..51e84f3 100644
--- a/src/print_volume.c
+++ b/src/print_volume.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <err.h>
+#include <ctype.h>
#include <yajl/yajl_gen.h>
#include <yajl/yajl_version.h>
@@ -67,9 +68,12 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
* index of the PulseAudio sink then force PulseAudio, optionally
* overriding the default sink */
if (!strncasecmp(device, "pulse", strlen("pulse"))) {
- uint32_t sink_idx = device[5] == ':' ? (uint32_t)atoi(device + 6)
- : DEFAULT_SINK_INDEX;
- int cvolume = pulse_initialize() ? volume_pulseaudio(sink_idx) : 0;
+ uint32_t sink_idx = device[strlen("pulse")] == ':' ? (uint32_t)atoi(device + strlen("pulse:")) : DEFAULT_SINK_INDEX;
+ const char *sink_name = device[strlen("pulse")] == ':' &&
+ !isdigit(device[strlen("pulse:")])
+ ? device + strlen("pulse:")
+ : NULL;
+ int cvolume = pulse_initialize() ? volume_pulseaudio(sink_idx, sink_name) : 0;
int ivolume = DECOMPOSE_VOLUME(cvolume);
bool muted = DECOMPOSE_MUTED(cvolume);
if (muted) {
@@ -85,7 +89,7 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
goto out;
} else if (!strcasecmp(device, "default") && pulse_initialize()) {
/* no device specified or "default" set */
- int cvolume = volume_pulseaudio(DEFAULT_SINK_INDEX);
+ int cvolume = volume_pulseaudio(DEFAULT_SINK_INDEX, NULL);
int ivolume = DECOMPOSE_VOLUME(cvolume);
bool muted = DECOMPOSE_MUTED(cvolume);
if (ivolume >= 0) {