summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-12-12 23:03:38 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-12-12 23:03:38 +0100
commit3898263f329e877d9b6a997d7a92851908d19166 (patch)
treea0448881cda3314d3e59037320ee705f941e2a5a
parent83ac3b4673de071651c8b8c57095e4de6d229ef8 (diff)
downloadpa-sink-ctl-3898263f329e877d9b6a997d7a92851908d19166.tar.gz
pa-sink-ctl-3898263f329e877d9b6a997d7a92851908d19166.tar.bz2
pa-sink-ctl-3898263f329e877d9b6a997d7a92851908d19166.zip
Use g_list_find_custom to calculate sink position
The compare function matches against the configured sink priority.
-rw-r--r--src/pa-sink-ctl.c22
-rw-r--r--src/pa-sink-ctl.h9
2 files changed, 14 insertions, 17 deletions
diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c
index df51b5e..d1fb637 100644
--- a/src/pa-sink-ctl.c
+++ b/src/pa-sink-ctl.c
@@ -114,21 +114,13 @@ 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
+cmp_priority(gconstpointer list_data, gconstpointer b)
{
- GList *l, *pos = NULL;
-
- for (l = ctx->sink_list; l; l = l->next) {
- sink_info *sink = l->data;
+ const sink_info *sink_el = list_data;
+ const sink_info *sink = b;
- if (new->priority > sink->priority) {
- pos = l;
- break;
- }
- }
- ctx->sink_list = g_list_insert_before(ctx->sink_list, pos,
- g_memdup(new, sizeof *new));
+ return (sink->priority > sink_el->priority) ? 0 : -1;
}
static void
@@ -169,7 +161,9 @@ sink_info_cb(pa_context *c, const pa_sink_info *i,
if (inlist)
*inlist = sink;
else
- add_sink(ctx, &sink);
+ list_insert_struct(ctx->sink_list, sink,
+ g_list_find_custom(ctx->sink_list,
+ &sink, cmp_priority));
}
static void
diff --git a/src/pa-sink-ctl.h b/src/pa-sink-ctl.h
index d8cd5bb..ac5f476 100644
--- a/src/pa-sink-ctl.h
+++ b/src/pa-sink-ctl.h
@@ -61,10 +61,13 @@ quit(struct context *ctx);
void
change_callback(pa_context* c, gint success, gpointer);
-#define list_append_struct(list, data) \
+
+#define list_insert_struct(list, data, pos) \
do { \
- (list) = g_list_append((list), \
- g_memdup(&(data), sizeof(data))); \
+ (list) = g_list_insert_before((list), (pos), \
+ g_memdup(&(data), sizeof(data)));\
} while (0)
+#define list_append_struct(list, data) list_insert_struct((list), (data), NULL)
+
#endif