diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-12-12 23:30:25 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-12-12 23:40:57 +0100 |
commit | 3c221589e0833a9865351b08fd9feab0200dc01a (patch) | |
tree | b0fb13b86e3d4604dbabc1d54af094148b39d7eb | |
parent | a76d55f553341b46c5b3bd4218df5aff3365433a (diff) | |
download | pa-sink-ctl-3c221589e0833a9865351b08fd9feab0200dc01a.tar.gz pa-sink-ctl-3c221589e0833a9865351b08fd9feab0200dc01a.tar.bz2 pa-sink-ctl-3c221589e0833a9865351b08fd9feab0200dc01a.zip |
Use g_list_insert_sorted for sink priority
-rw-r--r-- | src/pa-sink-ctl.c | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c index df51b5e..6cd5b88 100644 --- a/src/pa-sink-ctl.c +++ b/src/pa-sink-ctl.c @@ -114,21 +114,14 @@ get_sink_priority(struct context *ctx, const pa_sink_info *sink_info) return 0; } -static void -add_sink(struct context *ctx, sink_info *new) +static gint +compare_sink_priority(gconstpointer new_data, gconstpointer el_data) { - GList *l, *pos = NULL; - - for (l = ctx->sink_list; l; l = l->next) { - sink_info *sink = l->data; + const sink_info *new = new_data; + const sink_info *el = el_data; - if (new->priority > sink->priority) { - pos = l; - break; - } - } - ctx->sink_list = g_list_insert_before(ctx->sink_list, pos, - g_memdup(new, sizeof *new)); + /* Add 1 to append at end of sinks if priority equals */ + return el->priority - new->priority + 1; } static void @@ -169,7 +162,10 @@ sink_info_cb(pa_context *c, const pa_sink_info *i, if (inlist) *inlist = sink; else - add_sink(ctx, &sink); + ctx->sink_list = + g_list_insert_sorted(ctx->sink_list, + g_memdup(&sink, sizeof sink), + compare_sink_priority); } static void |