diff options
Diffstat (limited to 'src/pa-sink-ctl.c')
-rw-r--r-- | src/pa-sink-ctl.c | 131 |
1 files changed, 63 insertions, 68 deletions
diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c index 2eb15da..ba59884 100644 --- a/src/pa-sink-ctl.c +++ b/src/pa-sink-ctl.c @@ -34,95 +34,43 @@ compare_idx_pntr(gconstpointer i1, gconstpointer i2) return *((const guint32 *) i1) == *((const guint32 *) i2) ? 0 : -1; } -static void -sink_input_info_cb(pa_context *c, const pa_sink_input_info *i, - gint is_last, gpointer userdata) -{ - g_assert(userdata != NULL); - struct context *ctx = userdata; - struct sink_input_info *sink_input; - GList *el; - - if (is_last < 0) { - if (pa_context_errno(c) == PA_ERR_NOENTITY) - return; - interface_set_status(ctx, - "Failed to get sink input info: %s\n", - pa_strerror(pa_context_errno(c))); - return; - } - - if (is_last) { - interface_redraw(ctx); - return; - } - - if (!(i->client != PA_INVALID_INDEX)) return; - - el = g_list_find_custom(ctx->input_list, &i->index, compare_idx_pntr); - if (el == NULL) { - sink_input = g_new(struct sink_input_info, 1); - if (sink_input == NULL) - return; - sink_input->index = i->index; - ctx->input_list = g_list_append(ctx->input_list, sink_input); - } else { - sink_input = el->data; - g_free(sink_input->name); - } - - sink_input->sink = i->sink; - sink_input->name = - pa_proplist_contains(i->proplist, "application.name") ? - g_strdup(pa_proplist_gets(i->proplist, "application.name")) : - g_strdup(i->name); - sink_input->mute = i->mute; - sink_input->channels = i->volume.channels; - sink_input->vol = pa_cvolume_avg(&i->volume); -} - static int get_sink_priority(struct context *ctx, const pa_sink_info *sink_info) { struct priority *p; - const char *value; - list_foreach(ctx->config.priorities, p) { - value = pa_proplist_gets(sink_info->proplist, p->match); - - if (g_strcmp0(value, p->value) == 0) + list_foreach(ctx->config.priorities, p) + if (g_strcmp0(pa_proplist_gets(sink_info->proplist, p->match), + p->value)) return p->priority; - } return 0; } -static gint -compare_sink_priority(gconstpointer new_data, gconstpointer el_data) -{ - const struct sink_info *new = new_data; - const struct sink_info *el = el_data; - - /* Add 1 to append at end of sinks if priority equals */ - return el->priority - new->priority + 1; -} - static gchar * get_sink_name(struct context *ctx, const pa_sink_info *sink) { struct config *cfg = &ctx->config; int i; - for (i = 0; cfg->name_props && cfg->name_props[i]; ++i) { - if (pa_proplist_contains(sink->proplist, - cfg->name_props[i])) + for (i = 0; cfg->name_props && cfg->name_props[i]; ++i) + if (pa_proplist_contains(sink->proplist, cfg->name_props[i])) return g_strdup(pa_proplist_gets(sink->proplist, cfg->name_props[i])); - } - + return g_strdup(sink->name); } +static gint +compare_sink_priority(gconstpointer new_data, gconstpointer el_data) +{ + const struct sink_info *new = new_data; + const struct sink_info *el = el_data; + + /* Add 1 to append at end of sinks if priority equals */ + return el->priority - new->priority + 1; +} + static void sink_info_cb(pa_context *c, const pa_sink_info *i, gint is_last, gpointer userdata) @@ -167,6 +115,53 @@ sink_info_cb(pa_context *c, const pa_sink_info *i, } static void +sink_input_info_cb(pa_context *c, const pa_sink_input_info *i, + gint is_last, gpointer userdata) +{ + g_assert(userdata != NULL); + struct context *ctx = userdata; + struct sink_input_info *sink_input; + GList *el; + + if (is_last < 0) { + if (pa_context_errno(c) == PA_ERR_NOENTITY) + return; + interface_set_status(ctx, + "Failed to get sink input info: %s\n", + pa_strerror(pa_context_errno(c))); + return; + } + + if (is_last) { + interface_redraw(ctx); + return; + } + + if (!(i->client != PA_INVALID_INDEX)) return; + + el = g_list_find_custom(ctx->input_list, &i->index, compare_idx_pntr); + if (el == NULL) { + sink_input = g_new(struct sink_input_info, 1); + if (sink_input == NULL) + return; + sink_input->index = i->index; + ctx->input_list = g_list_append(ctx->input_list, sink_input); + } else { + sink_input = el->data; + g_free(sink_input->name); + } + + sink_input->sink = i->sink; + sink_input->name = + pa_proplist_contains(i->proplist, "application.name") ? + g_strdup(pa_proplist_gets(i->proplist, "application.name")) : + g_strdup(i->name); + sink_input->mute = i->mute; + sink_input->channels = i->volume.channels; + sink_input->vol = pa_cvolume_avg(&i->volume); +} + +static void sink_free(gpointer data) { struct sink_info *sink = data; |