summaryrefslogtreecommitdiff
path: root/src/interface.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/interface.c')
-rw-r--r--src/interface.c180
1 files changed, 92 insertions, 88 deletions
diff --git a/src/interface.c b/src/interface.c
index 7a3952d..d6fa085 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -55,22 +55,23 @@ sink_get_nth_input(struct context *ctx, struct sink_info *sink, int n)
}
struct vol_ctl *
-interface_get_current_ctl(struct context *ctx, struct vol_ctl **parent)
+interface_get_current_ctl(struct interface *ifc, struct vol_ctl **parent)
{
+ struct context *ctx = container_of(ifc, struct context, interface);
struct sink_info *sink;
struct sink_input_info *input;
if (parent)
*parent = NULL;
- sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
+ sink = g_list_nth_data(ctx->sink_list, ifc->chooser_sink);
if (sink == NULL)
return NULL;
- if (ctx->chooser_input == SELECTED_SINK)
+ if (ifc->chooser_input == SELECTED_SINK)
return &sink->base;
- else if (ctx->chooser_input >= 0) {
- input = sink_get_nth_input(ctx, sink, ctx->chooser_input);
+ else if (ifc->chooser_input >= 0) {
+ input = sink_get_nth_input(ctx, sink, ifc->chooser_input);
if (input == NULL)
return NULL;
if (parent)
@@ -83,102 +84,105 @@ interface_get_current_ctl(struct context *ctx, struct vol_ctl **parent)
}
static void
-allocate_volume_bar(struct context *ctx)
+allocate_volume_bar(struct interface *ifc)
{
gint x, y, max_x, max_y;
- if (ctx->volume_bar)
+ if (ifc->volume_bar)
return;
- getyx(ctx->menu_win, y, x);
- getmaxyx(ctx->menu_win, max_y, max_x);
- 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';
+ getyx(ifc->menu_win, y, x);
+ getmaxyx(ifc->menu_win, max_y, max_x);
+ ifc->volume_bar_len = max_x - x - 8;
+ ifc->volume_bar = g_new(char, ifc->volume_bar_len+1);
+ /* FIXME: if (ifc->volume_bar == NULL) */
+ memset(ifc->volume_bar, '=', ifc->volume_bar_len);
+ ifc->volume_bar[ifc->volume_bar_len] = '\0';
}
static void
-print_volume(struct context *ctx, struct vol_ctl *ctl)
+print_volume(struct interface *ifc, 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);
+ allocate_volume_bar(ifc);
+ vol = (gint) (ifc->volume_bar_len * ctl->vol / PA_VOLUME_NORM);
+ wprintw(ifc->menu_win, " [%c][%-*.*s]",
+ ctl->mute ? 'M':' ', ifc->volume_bar_len, vol, ifc->volume_bar);
}
static void
print_vol_ctl(gpointer data, gpointer user_data)
{
struct vol_ctl *ctl = data;
- struct context *ctx = user_data;
+ struct interface *ifc = user_data;
gint x, y;
- gboolean selected = (ctl == interface_get_current_ctl(ctx, NULL));
+ gboolean selected = (ctl == interface_get_current_ctl(ifc, NULL));
- getyx(ctx->menu_win, y, x);
+ getyx(ifc->menu_win, y, x);
if (selected)
- wattron(ctx->menu_win, A_REVERSE);
+ wattron(ifc->menu_win, A_REVERSE);
if (!ctl->hide_index)
- wprintw(ctx->menu_win, "%2u ", ctl->index);
- wprintw(ctx->menu_win, "%*s%-*s",
+ wprintw(ifc->menu_win, "%2u ", ctl->index);
+ wprintw(ifc->menu_win, "%*s%-*s",
ctl->indent + (ctl->hide_index ? 2+1 : 0), "",
- ctx->max_name_len - ctl->indent, ctl->name);
+ ifc->max_name_len - ctl->indent, ctl->name);
if (selected)
- wattroff(ctx->menu_win, A_REVERSE);
- print_volume(ctx, ctl);
- wmove(ctx->menu_win, y+1, x);
+ wattroff(ifc->menu_win, A_REVERSE);
+ print_volume(ifc, ctl);
+ wmove(ifc->menu_win, y+1, x);
if (ctl->childs_foreach)
- ctl->childs_foreach(ctl, print_vol_ctl, ctx);
+ ctl->childs_foreach(ctl, print_vol_ctl, ifc);
}
static void
max_name_len_helper(gpointer data, gpointer user_data)
{
struct vol_ctl *ctl = data;
- struct context *ctx = user_data;
+ struct interface *ifc = user_data;
guint len;
len = ctl->indent + strlen(ctl->name);
- if (len > ctx->max_name_len)
- ctx->max_name_len = len;
+ if (len > ifc->max_name_len)
+ ifc->max_name_len = len;
if (ctl->childs_foreach)
- ctl->childs_foreach(ctl, max_name_len_helper, ctx);
+ ctl->childs_foreach(ctl, max_name_len_helper, ifc);
}
void
-interface_redraw(struct context *ctx)
+interface_redraw(struct interface *ifc)
{
- werase(ctx->menu_win);
- box(ctx->menu_win, 0, 0);
-
- 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;
+ struct context *ctx = container_of(ifc, struct context, interface);
+
+ werase(ifc->menu_win);
+ box(ifc->menu_win, 0, 0);
+
+ wmove(ifc->menu_win, 2, 2); /* set initial cursor offset */
+ ifc->max_name_len = 0;
+ if (ifc->volume_bar) {
+ g_free(ifc->volume_bar);
+ ifc->volume_bar = NULL;
}
- g_list_foreach(ctx->sink_list, max_name_len_helper, ctx);
- g_list_foreach(ctx->sink_list, print_vol_ctl, ctx);
+ g_list_foreach(ctx->sink_list, max_name_len_helper, ifc);
+ g_list_foreach(ctx->sink_list, print_vol_ctl, ifc);
- wrefresh(ctx->menu_win);
+ wrefresh(ifc->menu_win);
}
static gboolean
interface_get_input(GIOChannel *source, GIOCondition condition, gpointer data)
{
- struct context *ctx = data;
+ struct interface *ifc = data;
+ struct context *ctx = container_of(ifc, struct context, interface);
struct command_cb_descriptor *cmd;
gint c;
- c = wgetch(ctx->menu_win);
+ c = wgetch(ifc->menu_win);
cmd = g_hash_table_lookup(ctx->config.keymap, GINT_TO_POINTER(c));
if (cmd)
@@ -188,28 +192,28 @@ interface_get_input(GIOChannel *source, GIOCondition condition, gpointer data)
}
void
-interface_set_status(struct context *ctx, const gchar *msg, ...)
+interface_set_status(struct interface *ifc, const gchar *msg, ...)
{
va_list ap;
if (msg != NULL) {
- g_free(ctx->status);
+ g_free(ifc->status);
va_start(ap, msg);
- ctx->status = g_strdup_vprintf(msg, ap);
+ ifc->status = g_strdup_vprintf(msg, ap);
va_end(ap);
}
- werase(ctx->msg_win);
- box(ctx->msg_win, 0, 0);
- if (ctx->status != NULL)
- mvwprintw(ctx->msg_win, 1, 1, ctx->status);
- wrefresh(ctx->msg_win);
+ werase(ifc->msg_win);
+ box(ifc->msg_win, 0, 0);
+ if (ifc->status != NULL)
+ mvwprintw(ifc->msg_win, 1, 1, ifc->status);
+ wrefresh(ifc->msg_win);
refresh();
}
static gboolean
interface_resize(gpointer data)
{
- struct context *ctx = data;
+ struct interface *ifc = data;
struct winsize wsize;
gint height = 80;
gint width = 24;
@@ -223,13 +227,13 @@ interface_resize(gpointer data)
clear();
refresh();
- wresize(ctx->menu_win, height - H_MSG_BOX, width);
- wresize(ctx->msg_win, H_MSG_BOX, width);
- mvwin(ctx->msg_win, height - H_MSG_BOX, 0);
+ wresize(ifc->menu_win, height - H_MSG_BOX, width);
+ wresize(ifc->msg_win, H_MSG_BOX, width);
+ mvwin(ifc->msg_win, height - H_MSG_BOX, 0);
/* NULL := display old status */
- interface_set_status(ctx, NULL);
- interface_redraw(ctx);
+ interface_set_status(ifc, NULL);
+ interface_redraw(ifc);
return TRUE;
}
@@ -238,30 +242,30 @@ interface_resize(gpointer data)
static gboolean
resize_gio(GIOChannel *source, GIOCondition condition, gpointer data)
{
- struct context *ctx = data;
+ struct interface *ifc = data;
struct signalfd_siginfo fdsi;
ssize_t s;
g_assert(condition & G_IO_IN);
- s = read(ctx->signal_fd, &fdsi, sizeof fdsi);
+ s = read(ifc->signal_fd, &fdsi, sizeof fdsi);
if (s != sizeof fdsi || fdsi.ssi_signo != SIGWINCH)
return FALSE;
- return interface_resize(ctx);
+ return interface_resize(ifc);
}
#endif
int
-interface_init(struct context *ctx)
+interface_init(struct interface *ifc)
{
GIOChannel *input_channel;
/* Selected sink-device. 0 is the first device */
- ctx->chooser_sink = 0;
+ ifc->chooser_sink = 0;
/* Selected input of the current sink-device. */
/* SELECTED_SINK refers to sink-device itself */
- ctx->chooser_input = SELECTED_SINK;
+ ifc->chooser_input = SELECTED_SINK;
initscr();
clear();
@@ -272,14 +276,14 @@ interface_init(struct context *ctx)
curs_set(0);
/* 0,0,0,0 := fullscreen */
- ctx->menu_win = newwin(0, 0, 0, 0);
- ctx->msg_win = newwin(0, 0, 0, 0);
+ ifc->menu_win = newwin(0, 0, 0, 0);
+ ifc->msg_win = newwin(0, 0, 0, 0);
/* multichar keys are mapped to one char */
- keypad(ctx->menu_win, TRUE);
+ keypad(ifc->menu_win, TRUE);
/* "resizing" here is for initial box positioning and layout */
- interface_resize(ctx);
+ interface_resize(ifc);
#ifdef HAVE_SIGNALFD
{
@@ -291,22 +295,22 @@ interface_init(struct context *ctx)
if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1)
return -1;
- ctx->signal_fd = signalfd(-1, &mask, 0);
- channel = g_io_channel_unix_new(ctx->signal_fd);
- ctx->resize_source_id =
- g_io_add_watch(channel, G_IO_IN, resize_gio, ctx);
+ ifc->signal_fd = signalfd(-1, &mask, 0);
+ channel = g_io_channel_unix_new(ifc->signal_fd);
+ ifc->resize_source_id =
+ g_io_add_watch(channel, G_IO_IN, resize_gio, ifc);
g_io_channel_unref(channel);
}
#else
/* register event handler for resize and input */
- ctx->resize_source_id = unix_signal_add(SIGWINCH,
- interface_resize, ctx);
+ ifc->resize_source_id = unix_signal_add(SIGWINCH,
+ interface_resize, ifc);
#endif
input_channel = g_io_channel_unix_new(STDIN_FILENO);
if (!input_channel)
return -1;
- ctx->input_source_id = g_io_add_watch(input_channel, G_IO_IN,
- interface_get_input, ctx);
+ ifc->input_source_id = g_io_add_watch(input_channel, G_IO_IN,
+ interface_get_input, ifc);
g_io_channel_unref(input_channel);
refresh();
@@ -315,19 +319,19 @@ interface_init(struct context *ctx)
}
void
-interface_clear(struct context *ctx)
+interface_clear(struct interface *ifc)
{
- g_source_remove(ctx->resize_source_id);
- g_source_remove(ctx->input_source_id);
+ g_source_remove(ifc->resize_source_id);
+ g_source_remove(ifc->input_source_id);
#ifdef HAVE_SIGNALFD
- close(ctx->signal_fd);
+ close(ifc->signal_fd);
#endif
clear();
refresh();
- delwin(ctx->menu_win);
- delwin(ctx->msg_win);
+ delwin(ifc->menu_win);
+ delwin(ifc->msg_win);
endwin();
delscreen(NULL);
- if (ctx->status)
- g_free(ctx->status);
+ if (ifc->status)
+ g_free(ifc->status);
}