diff options
Diffstat (limited to 'pavolctld.c')
-rw-r--r-- | pavolctld.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/pavolctld.c b/pavolctld.c index c8a4c5a..6504f74 100644 --- a/pavolctld.c +++ b/pavolctld.c @@ -16,6 +16,7 @@ static int command_sink_index = -1; // commands will modify this sink /* output callbacks */ static void sink_info_volume_callback(pa_context *c, const pa_sink_info *i, int eol, void *userdata) { pa_volume_t vol; + if (eol) return; vol = pa_cvolume_avg(&i->volume); @@ -25,12 +26,14 @@ static void sink_info_volume_callback(pa_context *c, const pa_sink_info *i, int static void sink_info_sink_desc_callback(pa_context *c, const pa_sink_info *i, int eol, void *userdata) { if (eol) return; + printf("s%d,%s,%s\n", i->index, i->name, i->description); fflush(stdout); } static void sink_info_default_index_callback(pa_context *c, const pa_sink_info *i, int eol, void *userdata) { if (eol) return; + default_sink_index = i->index; // set command sink equal to the default sink on startup if (command_sink_index == -1) @@ -91,6 +94,7 @@ static void context_state_callback(pa_context *c, void *userdata) { /* stdin commands */ static void sink_info_change_command_sink_callback(pa_context *c, const pa_sink_info *i, int eol, void *userdata) { int useridx = *(int *)userdata; + if (eol) { // callbacks are called twice if successful, with eol set the 2nd time // so this is the easiest way to check if cmd was successful @@ -122,6 +126,7 @@ static void change_command_sink(pa_context *c, char *cmd) { static void sink_info_change_default_sink_callback(pa_context *c, const pa_sink_info *i, int eol, void *userdata) { int useridx = *(int *)userdata; + if (eol) { if (useridx != default_sink_index) { printf("e3,sink %d does not exist\n", useridx); // same as sink_info_change_command_sink_callback @@ -146,6 +151,7 @@ static void sink_info_set_volume_callback(pa_context *c, const pa_sink_info *i, char *cmd = (char *)userdata; pa_cvolume *cvol; pa_volume_t vol; + if (eol) return; if (cmd[1] == '\n') { @@ -170,8 +176,8 @@ static void sink_info_set_volume_callback(pa_context *c, const pa_sink_info *i, static void sink_info_set_mute_callback(pa_context *c, const pa_sink_info *i, int eol, void *userdata) { char *cmd = (char *)userdata; - if (eol) return; + if (eol) return; if (cmd[1] == '\n') { pa_context_set_sink_mute_by_index(c, i->index, !i->mute, NULL, NULL); @@ -184,6 +190,7 @@ static void sink_info_set_mute_callback(pa_context *c, const pa_sink_info *i, in /* handle stdin commands */ static char *no_newline(char *s) { uint8_t i; // stdin buffer is 256 char long at most so this is sufficient + for(i = 0; s[i] != '\n' && s[i] != '\0'; i++); s[i] = '\0'; return s; @@ -218,7 +225,6 @@ int main() { char stdin_buffer[256]; // don't change buf len unless you change the no_newline func pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL); - pa_context_set_state_callback(context, context_state_callback, NULL); // main loop |