From b215b29ace8de9c44d87c113d976934909a3302a Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Sun, 18 Dec 2011 14:34:10 +0100 Subject: set_max_name_len: Simplify code to two calls to one helper function --- src/interface.c | 35 ++++++++++++++++++----------------- src/pa-sink-ctl.c | 2 ++ src/sink.h | 1 + 3 files changed, 21 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/interface.c b/src/interface.c index 10a16e3..d04f0de 100644 --- a/src/interface.c +++ b/src/interface.c @@ -150,8 +150,9 @@ print_input_list(struct context *ctx, struct sink_info *sink, wattron(ctx->menu_win, A_REVERSE); mvwprintw(ctx->menu_win, offset, 2, "%*s%-*s", - 2+1+1, "", /* space for index number + indentation*/ - ctx->max_name_len - 1, input->base.name); + 2+1+input->base.indent, "", /* space for index number */ + ctx->max_name_len - input->base.indent, + input->base.name); if (selected) wattroff(ctx->menu_win, A_REVERSE); @@ -162,27 +163,27 @@ print_input_list(struct context *ctx, struct sink_info *sink, *poffset = offset; } -/* looking for the longest name length of all SINK's and INPUT's */ -static void -set_max_name_len(struct context *ctx) +static inline void +max_name_len_helper(GList *list, guint *max_len) { struct vol_ctl *ctl; - guint len = 0; - ctx->max_name_len = len; + guint len; - list_foreach(ctx->sink_list, ctl) { - len = strlen(ctl->name); + list_foreach(list, ctl) { + len = ctl->indent + strlen(ctl->name); - if (len > ctx->max_name_len) - ctx->max_name_len = len; + if (len > *max_len) + *max_len= len; } +} - list_foreach(ctx->input_list, ctl) { - len = strlen(ctl->name) + 1 /* indentation */; - - if (len > ctx->max_name_len) - ctx->max_name_len = len; - } +/* looking for the longest name length of all SINK's and INPUT's */ +static void +set_max_name_len(struct context *ctx) +{ + ctx->max_name_len = 0; + max_name_len_helper(ctx->sink_list, &ctx->max_name_len); + max_name_len_helper(ctx->input_list, &ctx->max_name_len); } void diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c index adea0ee..a95eae9 100644 --- a/src/pa-sink-ctl.c +++ b/src/pa-sink-ctl.c @@ -99,6 +99,7 @@ sink_info_cb(pa_context *c, const pa_sink_info *i, if (sink == NULL) return; sink->base.index = i->index; + sink->base.indent = 0; sink->base.mute_set = pa_context_set_sink_mute_by_index; sink->base.volume_set = pa_context_set_sink_volume_by_index; @@ -146,6 +147,7 @@ sink_input_info_cb(pa_context *c, const pa_sink_input_info *i, if (sink_input == NULL) return; sink_input->base.index = i->index; + sink_input->base.indent = 1; sink_input->base.mute_set = pa_context_set_sink_input_mute; sink_input->base.volume_set = pa_context_set_sink_input_volume; ctx->input_list = g_list_append(ctx->input_list, sink_input); diff --git a/src/sink.h b/src/sink.h index 1d97752..26fe03a 100644 --- a/src/sink.h +++ b/src/sink.h @@ -32,6 +32,7 @@ struct vol_ctl { guint8 channels; gchar *name; /* displayed name */ + gint indent; /* indentation when displayed */ pa_operation *(*mute_set)(pa_context *, guint32, int, pa_context_success_cb_t, void *); -- cgit