diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-10-22 15:25:27 +0200 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-10-22 15:36:02 +0200 |
commit | 2c305d548bd069d84f864e6c3a91b1b8976d59e9 (patch) | |
tree | 3027c32a4298c1b87e7b94a1f10539c404bbdb84 | |
parent | 938c0600e591c42bdf4315059c6c07e61eacd50c (diff) | |
download | pa-sink-ctl-2c305d548bd069d84f864e6c3a91b1b8976d59e9.tar.gz pa-sink-ctl-2c305d548bd069d84f864e6c3a91b1b8976d59e9.tar.bz2 pa-sink-ctl-2c305d548bd069d84f864e6c3a91b1b8976d59e9.zip |
interface: Derive new chooser_input directly when moving
Dont schedule this until redraw, since this needed hacks
to ensure we got the update.
-rw-r--r-- | src/interface.c | 42 | ||||
-rw-r--r-- | src/pa-sink-ctl.c | 9 | ||||
-rw-r--r-- | src/pa-sink-ctl.h | 2 |
3 files changed, 18 insertions, 35 deletions
diff --git a/src/interface.c b/src/interface.c index 371de34..a90354f 100644 --- a/src/interface.c +++ b/src/interface.c @@ -38,7 +38,6 @@ #define H_MSG_BOX 3 -#define SELECTED_UNKNOWN -2 #define SELECTED_SINK -1 static int @@ -194,25 +193,6 @@ print_sink_list(struct context *ctx) werase(ctx->menu_win); box(ctx->menu_win, 0, 0); - /* derive chooser_input from selected_index (set when input is moved) */ - if (ctx->chooser_input == SELECTED_UNKNOWN) { - /* if index is will not be found, select sink as fallback */ - ctx->chooser_input = SELECTED_SINK; - /* step through inputs for current sink and find the selected */ - sink_info *sink = g_list_nth_data(ctx->sink_list, - ctx->chooser_sink); - for (l = ctx->input_list, i = -1; l; l = l->next) { - sink_input_info *input = l->data; - if (input->sink != sink->index) - continue; - ++i; - if (ctx->selected_index == input->index) { - ctx->chooser_input = i; - break; - } - } - } - for (l = ctx->sink_list, i = 0; l; l = l->next,++i) { sink_info *sink = l->data; gboolean selected = (i == ctx->chooser_sink && @@ -357,15 +337,13 @@ interface_get_input(GIOChannel *source, GIOCondition condition, gpointer data) case '\n': case '\t': case ' ': - if (ctx->chooser_input == SELECTED_SINK || - ctx->chooser_input == SELECTED_UNKNOWN) + if (ctx->chooser_input == SELECTED_SINK) break; sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink); sink_input_info *input = sink_get_nth_input(ctx, sink, ctx->chooser_input); if (g_list_length(ctx->sink_list) <= 1) break; - ctx->selected_index = input->index; if (ctx->chooser_sink < (gint)g_list_length(ctx->sink_list) - 1) ctx->chooser_sink++; else @@ -373,13 +351,25 @@ interface_get_input(GIOChannel *source, GIOCondition condition, gpointer data) sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink); /* chooser_input needs to be derived from $selected_index */ - ctx->chooser_input = SELECTED_UNKNOWN; - ctx->block_for_selected_index = TRUE; o = pa_context_move_sink_input_by_index(ctx->context, - ctx->selected_index, + input->index, sink->index, change_callback, NULL); pa_operation_unref(o); + + /* get new chooser_input, if non, select sink as fallback */ + ctx->chooser_input = SELECTED_SINK; + gint i = -1; + for (GList *l = ctx->input_list; l; l = l->next) { + sink_input_info *t = l->data; + + if (t->index == input->index) { + ctx->chooser_input = ++i; + break; + } + if (t->sink == sink->index) + ++i; + } break; case 'q': diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c index c7aa748..db38688 100644 --- a/src/pa-sink-ctl.c +++ b/src/pa-sink-ctl.c @@ -73,16 +73,12 @@ sink_input_info_cb(pa_context *c, const pa_sink_input_info *i, } if (is_last) { - if (!ctx->block_for_selected_index) - print_sink_list(ctx); + print_sink_list(ctx); return; } if (!(i->client != PA_INVALID_INDEX)) return; - if (ctx->block_for_selected_index && i->index == ctx->selected_index) - ctx->block_for_selected_index = FALSE; - sink_input_info sink_input = { .index = i->index, .sink = i->sink, @@ -117,8 +113,7 @@ sink_info_cb(pa_context *c, const pa_sink_info *i, } if (is_last) { - if (!ctx->block_for_selected_index) - print_sink_list(ctx); + print_sink_list(ctx); return; } diff --git a/src/pa-sink-ctl.h b/src/pa-sink-ctl.h index 443c432..d68401a 100644 --- a/src/pa-sink-ctl.h +++ b/src/pa-sink-ctl.h @@ -40,7 +40,6 @@ struct context { gint chooser_sink; gint chooser_input; - guint32 selected_index; guint max_name_len; @@ -50,7 +49,6 @@ struct context { GList *input_list; gchar *status; - gboolean block_for_selected_index; }; void |