diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-12-13 08:22:26 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-12-13 08:22:26 +0100 |
commit | 462df78982f565f2304373de4858f0155ceb61b7 (patch) | |
tree | e873581560a8efa244d293c295b43acae5204cd9 | |
parent | 3c221589e0833a9865351b08fd9feab0200dc01a (diff) | |
download | pa-sink-ctl-462df78982f565f2304373de4858f0155ceb61b7.tar.gz pa-sink-ctl-462df78982f565f2304373de4858f0155ceb61b7.tar.bz2 pa-sink-ctl-462df78982f565f2304373de4858f0155ceb61b7.zip |
Add config property to select display name to use
-rw-r--r-- | src/config.c | 19 | ||||
-rw-r--r-- | src/config.h | 1 | ||||
-rw-r--r-- | src/config.ini | 3 | ||||
-rw-r--r-- | src/interface.c | 5 | ||||
-rw-r--r-- | src/pa-sink-ctl.c | 23 | ||||
-rw-r--r-- | src/sink.h | 1 |
6 files changed, 42 insertions, 10 deletions
diff --git a/src/config.c b/src/config.c index 73bebe2..b6b2c5d 100644 --- a/src/config.c +++ b/src/config.c @@ -61,6 +61,21 @@ destroy_priority(gpointer data) g_free(p); } +static int +read_settings(struct config *cfg) +{ + GError *error = NULL; + + cfg->name_props = + g_key_file_get_string_list(cfg->keyfile, "pa-sink-ctl", + "name-properties", NULL, &error); + /* Can be ignored if not found. */ + if (error) + error = NULL; + + return 0; +} + int config_init(struct config *cfg) { @@ -89,6 +104,9 @@ config_init(struct config *cfg) return -1; } + if (read_settings(cfg) < 0) + return -1; + if (parse_priorities(cfg) < 0) return -1; @@ -100,5 +118,6 @@ config_uninit(struct config *cfg) { g_list_free_full(cfg->priorities, destroy_priority); + g_strfreev(cfg->name_props); g_key_file_free(cfg->keyfile); } diff --git a/src/config.h b/src/config.h index 0bdbef2..9cf320e 100644 --- a/src/config.h +++ b/src/config.h @@ -5,6 +5,7 @@ struct config { GKeyFile *keyfile; GList *priorities; + gchar **name_props; }; struct priority { diff --git a/src/config.ini b/src/config.ini index 5abbb2a..ecedead 100644 --- a/src/config.ini +++ b/src/config.ini @@ -1,5 +1,8 @@ [pa-sink-ctl] +## List of properties to try to use as sink names, or sink name itself if empty. +name-properties = device.description; device.product.name + ## Priority groups can be used to set the display ## order for sinks. Priority groups start with "priority". ## "match": a pulseaudio property to match against (use pacmd list-sinks) diff --git a/src/interface.c b/src/interface.c index 60c4468..e2e8f48 100644 --- a/src/interface.c +++ b/src/interface.c @@ -163,7 +163,7 @@ set_max_name_len(struct context *ctx) for (l = ctx->sink_list; l; l = l->next) { sink_info *sink = l->data; - len = strlen(sink->device != NULL ? sink->device : sink->name); + len = strlen(sink->name); if (len > ctx->max_name_len) ctx->max_name_len = len; @@ -202,8 +202,7 @@ print_sink_list(struct context *ctx) wattron(ctx->menu_win, A_REVERSE); mvwprintw(ctx->menu_win, offset, x, "%2u %-*s", - sink->index, ctx->max_name_len, - sink->device != NULL ? sink->device : sink->name); + sink->index, ctx->max_name_len, sink->name); if (selected) wattroff(ctx->menu_win, A_REVERSE); diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c index 6cd5b88..e63da0a 100644 --- a/src/pa-sink-ctl.c +++ b/src/pa-sink-ctl.c @@ -124,6 +124,22 @@ compare_sink_priority(gconstpointer new_data, gconstpointer el_data) 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])) + return g_strdup(pa_proplist_gets(sink->proplist, + cfg->name_props[i])); + } + + return g_strdup(sink->name); +} + static void sink_info_cb(pa_context *c, const pa_sink_info *i, gint is_last, gpointer userdata) @@ -149,12 +165,7 @@ sink_info_cb(pa_context *c, const pa_sink_info *i, .mute = i->mute, .vol = pa_cvolume_avg(&i->volume), .channels = i->volume.channels, - .name = g_strdup(i->name), - .device = pa_proplist_contains(i->proplist, - "device.product.name") ? - g_strdup(pa_proplist_gets(i->proplist, - "device.product.name")) : - NULL, + .name = get_sink_name(ctx, i), .priority = get_sink_priority(ctx, i), }; @@ -26,7 +26,6 @@ typedef struct _sink_info { guint32 index; gchar* name; - gchar* device; gint mute; guint8 channels; pa_volume_t vol; |