diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-12-18 16:54:03 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-12-18 17:28:44 +0100 |
commit | 56985c505d4cbbf62825eafb16416f8d3c9ca6d1 (patch) | |
tree | 7e501ca3e89c3ff2bf2e2fcc0e152ba5340ad176 /src | |
parent | b5a8c05063fe1d7b8611f46da8716c321cf34c07 (diff) | |
download | pa-sink-ctl-56985c505d4cbbf62825eafb16416f8d3c9ca6d1.tar.gz pa-sink-ctl-56985c505d4cbbf62825eafb16416f8d3c9ca6d1.tar.bz2 pa-sink-ctl-56985c505d4cbbf62825eafb16416f8d3c9ca6d1.zip |
interface: Use printf precision and padding for volume bar printing
Diffstat (limited to 'src')
-rw-r--r-- | src/interface.c | 39 | ||||
-rw-r--r-- | src/pa-sink-ctl.h | 2 |
2 files changed, 27 insertions, 14 deletions
diff --git a/src/interface.c b/src/interface.c index fa0eee4..c16f83f 100644 --- a/src/interface.c +++ b/src/interface.c @@ -111,24 +111,31 @@ interface_resize(gpointer data) } static void -print_volume(struct context *ctx, struct vol_ctl *ctl) +allocate_volume_bar(struct context *ctx) { - gint x, y, max_x, max_y, volume_bar_len, vol; + gint x, y, max_x, max_y; + + if (ctx->volume_bar) + return; getyx(ctx->menu_win, y, x); getmaxyx(ctx->menu_win, max_y, max_x); - /* mute button + brackets + space */ - volume_bar_len = max_x - x - 8; - vol = (gint) (volume_bar_len * ctl->vol / PA_VOLUME_NORM); - - wprintw(ctx->menu_win, " [%c]", ctl->mute ? 'M' : ' '); - - wprintw(ctx->menu_win, "["); - for (gint i = 0; i < vol; ++i) - wprintw(ctx->menu_win, "="); - for (gint i = vol; i < volume_bar_len; ++i) - wprintw(ctx->menu_win, " "); - wprintw(ctx->menu_win, "]"); + ctx->volume_bar_len = max_x - x - 8; + ctx->volume_bar = g_new(char, ctx->volume_bar_len+1); + /* FIXME: if (ctx->volume_bar == NULL) */ + memset(ctx->volume_bar, '=', ctx->volume_bar_len); + ctx->volume_bar[ctx->volume_bar_len] = '\0'; +} + +static void +print_volume(struct context *ctx, struct vol_ctl *ctl) +{ + gint vol; + + allocate_volume_bar(ctx); + vol = (gint) (ctx->volume_bar_len * ctl->vol / PA_VOLUME_NORM); + wprintw(ctx->menu_win, " [%c][%-*.*s]", + ctl->mute ? 'M':' ', ctx->volume_bar_len, vol, ctx->volume_bar); } static void @@ -181,6 +188,10 @@ interface_redraw(struct context *ctx) wmove(ctx->menu_win, 2, 2); /* set initial cursor offset */ ctx->max_name_len = 0; + if (ctx->volume_bar) { + g_free(ctx->volume_bar); + ctx->volume_bar = NULL; + } g_list_foreach(ctx->sink_list, max_name_len_helper, ctx); g_list_foreach(ctx->sink_list, print_vol_ctl, ctx); diff --git a/src/pa-sink-ctl.h b/src/pa-sink-ctl.h index 97801d4..bc93ccb 100644 --- a/src/pa-sink-ctl.h +++ b/src/pa-sink-ctl.h @@ -33,6 +33,8 @@ struct context { WINDOW *menu_win; WINDOW *msg_win; + gint volume_bar_len; + gchar *volume_bar; guint resize_source_id; #ifdef HAVE_SIGNALFD |