diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/command.c | 6 | ||||
-rw-r--r-- | src/interface.c | 60 | ||||
-rw-r--r-- | src/pa-sink-ctl.c | 54 | ||||
-rw-r--r-- | src/sink.h | 25 |
4 files changed, 39 insertions, 106 deletions
diff --git a/src/command.c b/src/command.c index a883685..c410832 100644 --- a/src/command.c +++ b/src/command.c @@ -41,7 +41,7 @@ static void up(struct context *ctx, int key) { struct interface *ifc = &ctx->interface; - struct sink *sink = NULL; + struct main_ctl *sink = NULL; if (!ctx->context_ready) return; @@ -153,7 +153,7 @@ static void switch_sink(struct context *ctx, int key) { struct interface *ifc = &ctx->interface; - struct sink_input *t; + struct slave_ctl *t; struct vol_ctl *input, *sink; pa_operation *o; gint i; @@ -189,7 +189,7 @@ switch_sink(struct context *ctx, int key) ifc->chooser_input = ++i; break; } - if (t->sink == sink->index) + if (t->parent_index == sink->index) ++i; } } diff --git a/src/interface.c b/src/interface.c index 3247aaa..0246222 100644 --- a/src/interface.c +++ b/src/interface.c @@ -38,33 +38,16 @@ #include "unix_signal.h" #endif -static struct sink_input * -sink_get_nth_input(struct context *ctx, struct sink *sink, int n) +static struct slave_ctl * +main_ctl_get_nth_child(struct context *ctx, struct main_ctl *ctl, int n) { - struct sink_input *input; + struct slave_ctl *sctl; int i = 0; - list_foreach(ctx->input_list, input) { - if (input->sink != sink->base.index) - continue; - if (i++ == n) - return input; - } - - return NULL; -} - -static struct source_output * -source_get_nth_output(struct context *ctx, struct source *source, int n) -{ - struct source_output *output; - int i = 0; - - list_foreach(ctx->output_list, output) { - if (output->source != source->base.index) - continue; - if (i++ == n) - return output; + list_foreach(*ctl->childs_list, sctl) { + if (sctl->parent_index == ctl->base.index) + if (i++ == n) + return sctl; } return NULL; @@ -74,10 +57,8 @@ struct vol_ctl * interface_get_current_ctl(struct interface *ifc, struct vol_ctl **parent) { struct context *ctx = container_of(ifc, struct context, interface); - struct vol_ctl *main_ctl, *ctl; - struct sink_input *input; - struct source_output *output; - int is_sink = 1; + struct main_ctl *main_ctl; + struct slave_ctl *sctl; if (parent) *parent = NULL; @@ -85,29 +66,20 @@ interface_get_current_ctl(struct interface *ifc, struct vol_ctl **parent) main_ctl = g_list_nth_data(ctx->sink_list, ifc->chooser_sink); if (main_ctl == NULL) { main_ctl = g_list_nth_data(ctx->source_list, - ifc->chooser_sink - g_list_length(ctx->sink_list)); - is_sink = 0; + ifc->chooser_sink - g_list_length(ctx->sink_list)); if (main_ctl == NULL) return NULL; } if (ifc->chooser_input == SELECTED_SINK) - return main_ctl; + return &main_ctl->base; else if (ifc->chooser_input >= 0) { - if (is_sink) { - input = sink_get_nth_input(ctx, (struct sink *) main_ctl, ifc->chooser_input); - if (input == NULL) - return NULL; - ctl = &input->base; - } else { - output = source_get_nth_output(ctx, (struct source *) main_ctl, ifc->chooser_input); - if (output == NULL) - return NULL; - ctl = &output->base; - } + sctl = main_ctl_get_nth_child(ctx, (struct main_ctl *) main_ctl, ifc->chooser_input); + if (sctl == NULL) + return NULL; if (parent) - *parent = main_ctl; - return ctl; + *parent = &main_ctl->base; + return &sctl->base; } g_assert(0); diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c index 38a5913..2bad8bd 100644 --- a/src/pa-sink-ctl.c +++ b/src/pa-sink-ctl.c @@ -63,22 +63,22 @@ get_name(struct context *ctx, pa_proplist *props, const char * const fallback) static gint compare_sink_priority(gconstpointer new_data, gconstpointer el_data) { - const struct sink *new = new_data; - const struct sink *el = el_data; + const struct main_ctl *new = new_data; + const struct main_ctl *el = el_data; /* Add 1 to append at end of sinks if priority equals */ return el->priority - new->priority + 1; } static void -sink_childs_foreach(struct vol_ctl *ctl, GFunc func, gpointer user_data) +main_ctl_childs_foreach(struct vol_ctl *ctl, GFunc func, gpointer user_data) { - struct sink *sink = (struct sink *) ctl; - struct sink_input *input; + struct main_ctl *mctl = (struct main_ctl *) ctl; + struct slave_ctl *sctl; - list_foreach(sink->ctx->input_list, input) - if (input->sink == sink->base.index) - func(&input->base, user_data); + list_foreach(*mctl->childs_list, sctl) + if (sctl->parent_index == mctl->base.index) + func(&sctl->base, user_data); } static void @@ -86,7 +86,7 @@ sink_info_cb(pa_context *c, const pa_sink_info *i, gint is_last, gpointer userdata) { struct context *ctx = userdata; - struct sink *sink; + struct main_ctl *sink; GList *el; if (is_last < 0) { @@ -105,14 +105,13 @@ sink_info_cb(pa_context *c, const pa_sink_info *i, el = g_list_find_custom(ctx->sink_list, &i->index, compare_idx_pntr); if (el == NULL) { - sink = g_new0(struct sink, 1); + sink = g_new0(struct main_ctl, 1); if (sink == NULL) return; sink->base.index = i->index; sink->base.mute_set = pa_context_set_sink_mute_by_index; sink->base.volume_set = pa_context_set_sink_volume_by_index; - sink->base.childs_foreach = sink_childs_foreach; - sink->ctx = ctx; + sink->base.childs_foreach = main_ctl_childs_foreach; sink->childs_list = &ctx->input_list; sink->priority = get_priority(ctx, i->proplist); @@ -130,23 +129,11 @@ sink_info_cb(pa_context *c, const pa_sink_info *i, } static void -source_childs_foreach(struct vol_ctl *ctl, GFunc func, gpointer user_data) -{ - struct source *source = (struct source *) ctl; - struct source_output *output; - - list_foreach(source->ctx->output_list, output) - if (output->source == source->base.index) - func(&output->base, user_data); -} - - -static void source_info_cb(pa_context *c, const pa_source_info *i, gint is_last, gpointer userdata) { struct context *ctx = userdata; - struct source *source; + struct main_ctl *source; GList *el; if (is_last < 0) { @@ -165,14 +152,13 @@ source_info_cb(pa_context *c, const pa_source_info *i, el = g_list_find_custom(ctx->source_list, &i->index, compare_idx_pntr); if (el == NULL) { - source = g_new0(struct source, 1); + source = g_new0(struct main_ctl, 1); if (source == NULL) return; source->base.index = i->index; source->base.mute_set = pa_context_set_source_mute_by_index; source->base.volume_set = pa_context_set_source_volume_by_index; - source->base.childs_foreach = source_childs_foreach; - source->ctx = ctx; + source->base.childs_foreach = main_ctl_childs_foreach; source->childs_list = &ctx->output_list; source->priority = get_priority(ctx, i->proplist); @@ -195,7 +181,7 @@ sink_input_info_cb(pa_context *c, const pa_sink_input_info *i, gint is_last, gpointer userdata) { struct context *ctx = userdata; - struct sink_input *sink_input; + struct slave_ctl *sink_input; GList *el; if (is_last < 0) { @@ -216,7 +202,7 @@ sink_input_info_cb(pa_context *c, const pa_sink_input_info *i, el = g_list_find_custom(ctx->input_list, &i->index, compare_idx_pntr); if (el == NULL) { - sink_input = g_new0(struct sink_input, 1); + sink_input = g_new0(struct slave_ctl, 1); if (sink_input == NULL) return; sink_input->base.index = i->index; @@ -230,7 +216,7 @@ sink_input_info_cb(pa_context *c, const pa_sink_input_info *i, g_free(sink_input->base.name); } - sink_input->sink = i->sink; + sink_input->parent_index = i->sink; sink_input->base.name = pa_proplist_contains(i->proplist, "application.name") ? g_strdup(pa_proplist_gets(i->proplist, "application.name")) : @@ -245,7 +231,7 @@ source_output_info_cb(pa_context *c, const pa_source_output_info *i, gint is_last, gpointer userdata) { struct context *ctx = userdata; - struct source_output *source_output; + struct slave_ctl *source_output; GList *el; if (is_last < 0) { @@ -266,7 +252,7 @@ source_output_info_cb(pa_context *c, const pa_source_output_info *i, el = g_list_find_custom(ctx->output_list, &i->index, compare_idx_pntr); if (el == NULL) { - source_output = g_new0(struct source_output, 1); + source_output = g_new0(struct slave_ctl, 1); if (source_output == NULL) return; source_output->base.index = i->index; @@ -279,7 +265,7 @@ source_output_info_cb(pa_context *c, const pa_source_output_info *i, g_free(source_output->base.name); } - source_output->source = i->source; + source_output->parent_index = i->source; source_output->base.name = pa_proplist_contains(i->proplist, "application.name") ? g_strdup(pa_proplist_gets(i->proplist, "application.name")) : @@ -47,38 +47,13 @@ struct vol_ctl { struct main_ctl { struct vol_ctl base; gint priority; - struct context *ctx; GList **childs_list; }; -struct sink { - struct vol_ctl base; - gint priority; - struct context *ctx; - GList **childs_list; -}; - -struct sink_input { - struct vol_ctl base; - guint32 sink; -}; - struct slave_ctl { struct vol_ctl base; guint32 parent_index; }; -struct source_output { - struct vol_ctl base; - guint32 source; -}; - -struct source { - struct vol_ctl base; - gint priority; - struct context *ctx; - GList **childs_list; -}; - #endif |