diff options
-rw-r--r-- | src/interface.c | 111 | ||||
-rw-r--r-- | src/pa-sink-ctl.c | 19 | ||||
-rw-r--r-- | src/pa-sink-ctl.h | 1 | ||||
-rw-r--r-- | src/sink.h | 4 |
4 files changed, 60 insertions, 75 deletions
diff --git a/src/interface.c b/src/interface.c index f904407..fe3dbc3 100644 --- a/src/interface.c +++ b/src/interface.c @@ -111,7 +111,7 @@ interface_resize(gpointer data) } static void -print_volume(struct context *ctx, struct vol_ctl *ctl, int y) +print_volume(struct context *ctx, struct vol_ctl *ctl) { gint x = 2 /* left */ + 2 /* index num width */ + 1 /* space */ + 1 /* space */ + ctx->max_name_len; @@ -120,103 +120,70 @@ print_volume(struct context *ctx, struct vol_ctl *ctl, int y) int volume_bar_len = getmaxx(ctx->menu_win) - x - 7; gint vol = (gint) (volume_bar_len * ctl->vol / PA_VOLUME_NORM); - mvwprintw(ctx->menu_win, y, x - 1, " [%c]", ctl->mute ? 'M' : ' '); + mvwprintw(ctx->menu_win, ctx->y, x - 1, " [%c]", ctl->mute ? 'M' : ' '); x += 4; - mvwprintw(ctx->menu_win, y, x - 1 , "["); + mvwprintw(ctx->menu_win, ctx->y, x - 1 , "["); for (gint i = 0; i < vol; ++i) - mvwprintw(ctx->menu_win, y, x + i, "="); + mvwprintw(ctx->menu_win, ctx->y, x + i, "="); for (gint i = vol; i < volume_bar_len; ++i) - mvwprintw(ctx->menu_win, y, x + i, " "); - mvwprintw(ctx->menu_win, y, x + volume_bar_len, "]"); + mvwprintw(ctx->menu_win, ctx->y, x + i, " "); + mvwprintw(ctx->menu_win, ctx->y, x + volume_bar_len, "]"); } static void -print_input_list(struct context *ctx, struct sink_info *sink, - gint sink_num, gint *poffset) +print_vol_ctl(gpointer data, gpointer user_data) { - struct sink_input_info *input; - gint offset = *poffset; - gboolean selected; - gint i = -1; - - list_foreach(ctx->input_list, input) { - if (input->sink != sink->base.index) - continue; - selected = (ctx->chooser_sink == sink_num && - ctx->chooser_input == ++i); - - if (selected) - wattron(ctx->menu_win, A_REVERSE); - - mvwprintw(ctx->menu_win, offset, 2, "%*s%-*s", - 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); + struct vol_ctl *ctl = data; + struct context *ctx = user_data; + gint x = 2; + gboolean selected = (ctl == interface_get_current_ctl(ctx, NULL)); - print_volume(ctx, &input->base, offset); - offset++; + if (selected) + wattron(ctx->menu_win, A_REVERSE); + if (!ctl->hide_index) { + mvwprintw(ctx->menu_win, ctx->y, x, "%2u ", ctl->index); + x += 3; } - *poffset = offset; + mvwprintw(ctx->menu_win, ctx->y, x, "%*s%-*s", + ctl->indent + (ctl->hide_index ? 2+1 : 0), "", + ctx->max_name_len - ctl->indent, ctl->name); + if (selected) + wattroff(ctx->menu_win, A_REVERSE); + print_volume(ctx, ctl); + ctx->y++; + + if (ctl->childs_foreach) + ctl->childs_foreach(ctl, print_vol_ctl, ctx); } -static inline void -max_name_len_helper(GList *list, guint *max_len) +static void +max_name_len_helper(gpointer data, gpointer user_data) { - struct vol_ctl *ctl; + struct vol_ctl *ctl = data; + struct context *ctx = user_data; guint len; - list_foreach(list, ctl) { - len = ctl->indent + strlen(ctl->name); - - if (len > *max_len) - *max_len= len; - } -} + len = ctl->indent + strlen(ctl->name); + 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); + if (ctl->childs_foreach) + ctl->childs_foreach(ctl, max_name_len_helper, ctx); } void interface_redraw(struct context *ctx) { - struct sink_info *sink; - gint i = -1; - gint x = 2; - gint offset = 2; /* top border + 1 empty line */ - - /* looking for the longest name for right indentation */ - set_max_name_len(ctx); - werase(ctx->menu_win); box(ctx->menu_win, 0, 0); - list_foreach(ctx->sink_list, sink) { - gboolean selected = (++i == ctx->chooser_sink && - ctx->chooser_input == SELECTED_SINK); - - if (selected) - wattron(ctx->menu_win, A_REVERSE); - - mvwprintw(ctx->menu_win, offset, x, "%2u %-*s", - sink->base.index, ctx->max_name_len, sink->base.name); + ctx->y = 2; /* top border + 1 empty line */ + ctx->max_name_len = 0; - if (selected) - wattroff(ctx->menu_win, A_REVERSE); - print_volume(ctx, &sink->base, offset); + g_list_foreach(ctx->sink_list, max_name_len_helper, ctx); + g_list_foreach(ctx->sink_list, print_vol_ctl, ctx); - offset++; - print_input_list(ctx, sink, i, &offset); - } wrefresh(ctx->menu_win); } diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c index a95eae9..b22230b 100644 --- a/src/pa-sink-ctl.c +++ b/src/pa-sink-ctl.c @@ -72,6 +72,17 @@ compare_sink_priority(gconstpointer new_data, gconstpointer el_data) } static void +sink_childs_foreach(struct vol_ctl *ctl, GFunc func, gpointer user_data) +{ + struct sink_info *sink = (struct sink_info *) ctl; + struct sink_input_info *input; + + list_foreach(sink->ctx->input_list, input) + if (input->sink == sink->base.index) + func(&input->base, user_data); +} + +static void sink_info_cb(pa_context *c, const pa_sink_info *i, gint is_last, gpointer userdata) { @@ -95,13 +106,14 @@ sink_info_cb(pa_context *c, const pa_sink_info *i, el = g_list_find_custom(ctx->sink_list, &i->index, compare_idx_pntr); if (el == NULL) { - sink = g_new(struct sink_info, 1); + sink = g_new0(struct sink_info, 1); 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; + sink->base.childs_foreach = sink_childs_foreach; + sink->ctx = ctx; sink->priority = get_sink_priority(ctx, i); ctx->sink_list = g_list_insert_sorted(ctx->sink_list, sink, @@ -143,11 +155,12 @@ sink_input_info_cb(pa_context *c, const pa_sink_input_info *i, el = g_list_find_custom(ctx->input_list, &i->index, compare_idx_pntr); if (el == NULL) { - sink_input = g_new(struct sink_input_info, 1); + sink_input = g_new0(struct sink_input_info, 1); if (sink_input == NULL) return; sink_input->base.index = i->index; sink_input->base.indent = 1; + sink_input->base.hide_index = TRUE; 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/pa-sink-ctl.h b/src/pa-sink-ctl.h index 97801d4..01fd3e8 100644 --- a/src/pa-sink-ctl.h +++ b/src/pa-sink-ctl.h @@ -33,6 +33,7 @@ struct context { WINDOW *menu_win; WINDOW *msg_win; + gint y; guint resize_source_id; #ifdef HAVE_SIGNALFD @@ -33,17 +33,21 @@ struct vol_ctl { gchar *name; /* displayed name */ gint indent; /* indentation when displayed */ + gboolean hide_index; pa_operation *(*mute_set)(pa_context *, guint32, int, pa_context_success_cb_t, void *); pa_operation *(*volume_set)(pa_context *, guint32, const pa_cvolume *, pa_context_success_cb_t, gpointer); + + void (*childs_foreach)(struct vol_ctl *ctx, GFunc func, gpointer udata); }; struct sink_info { struct vol_ctl base; gint priority; + struct context *ctx; }; struct sink_input_info { |