summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/interface.c231
-rw-r--r--src/interface.h15
-rw-r--r--src/pa-sink-ctl.c69
-rw-r--r--src/pa-sink-ctl.h21
4 files changed, 172 insertions, 164 deletions
diff --git a/src/interface.c b/src/interface.c
index e4d7019..804106d 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -43,7 +43,7 @@ interface_resize(gpointer data)
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);
-
+
/* NULL := display old status */
interface_set_status(ctx, NULL);
print_sink_list(ctx);
@@ -114,10 +114,10 @@ set_max_name_len(struct context *ctx)
if (len > ctx->max_name_len)
ctx->max_name_len = len;
-
+
for (k = sink->input_list; k; k = k->next) {
sink_input_info *input = k->data;
-
+
len = strlen(input->name) + 1 /* indentation */;
if (len > ctx->max_name_len)
@@ -137,7 +137,7 @@ print_sink_list(struct context *ctx)
/* looking for the longest name for right indentation */
set_max_name_len(ctx);
-
+
werase(ctx->menu_win);
box(ctx->menu_win, 0, 0);
@@ -155,7 +155,7 @@ print_sink_list(struct context *ctx)
}
}
}
-
+
for (l = ctx->sink_list, i = 0; l; l = l->next,++i) {
sink_info *sink = l->data;
gboolean selected = (i == ctx->chooser_sink && ctx->chooser_input == SELECTED_SINK);
@@ -166,7 +166,7 @@ print_sink_list(struct context *ctx)
mvwprintw(ctx->menu_win, y+i+offset, x, "%2u %-*s",
sink->index, ctx->max_name_len,
sink->device != NULL ? sink->device : sink->name);
-
+
if (selected)
wattroff(ctx->menu_win, A_REVERSE);
print_volume(ctx, sink->vol, sink->mute, y+i+offset);
@@ -185,133 +185,128 @@ interface_get_input(GIOChannel *source, GIOCondition condition, gpointer data)
gint c;
gboolean volume_increment = TRUE;
sink_info *sink = NULL;
+ guint32 index;
if (!ctx->context_ready)
return TRUE;
c = wgetch(ctx->menu_win);
switch (c) {
- case 'k':
- case 'w':
- case KEY_UP:
- if (ctx->chooser_input == SELECTED_SINK && ctx->chooser_sink > 0) {
- sink = g_list_nth_data(ctx->sink_list, --ctx->chooser_sink);
- /* automatic SELECTED_SINK (=-1) assignment if length = 0 */
- ctx->chooser_input = (gint)g_list_length(sink->input_list) - 1;
- }
-
- else if (ctx->chooser_input >= 0)
- --ctx->chooser_input;
- print_sink_list(ctx);
- break;
+ case 'k':
+ case 'w':
+ case KEY_UP:
+ if (ctx->chooser_input == SELECTED_SINK && ctx->chooser_sink > 0) {
+ sink = g_list_nth_data(ctx->sink_list, --ctx->chooser_sink);
+ /* automatic SELECTED_SINK (=-1) assignment if length = 0 */
+ ctx->chooser_input = (gint)g_list_length(sink->input_list) - 1;
+ }
- case 'j':
- case 's':
- case KEY_DOWN:
- sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
- if (ctx->chooser_input == ((gint)g_list_length(sink->input_list) - 1) && ctx->chooser_sink < (gint)g_list_length(ctx->sink_list) - 1) {
- ++ctx->chooser_sink;
- ctx->chooser_input = SELECTED_SINK;
- }
- else if (ctx->chooser_input < ((gint)g_list_length(sink->input_list) - 1))
- ++ctx->chooser_input;
- print_sink_list(ctx);
+ else if (ctx->chooser_input >= 0)
+ --ctx->chooser_input;
+ print_sink_list(ctx);
+ break;
+
+ case 'j':
+ case 's':
+ case KEY_DOWN:
+ sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
+ if (ctx->chooser_input == ((gint)g_list_length(sink->input_list) - 1) && ctx->chooser_sink < (gint)g_list_length(ctx->sink_list) - 1) {
+ ++ctx->chooser_sink;
+ ctx->chooser_input = SELECTED_SINK;
+ }
+ else if (ctx->chooser_input < ((gint)g_list_length(sink->input_list) - 1))
+ ++ctx->chooser_input;
+ print_sink_list(ctx);
+ break;
+
+ case 'h':
+ case 'a':
+ case KEY_LEFT:
+ volume_increment = FALSE;
+ /* fall through */
+ case 'l':
+ case 'd':
+ case KEY_RIGHT:
+ sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
+ pa_cvolume volume;
+ pa_volume_t tmp_vol;
+ pa_operation* (*volume_set) (pa_context*, guint32, const pa_cvolume*, pa_context_success_cb_t, gpointer);
+
+ if (ctx->chooser_input >= 0) {
+ sink_input_info *input = g_list_nth_data(sink->input_list, ctx->chooser_input);
+ index = input->index;
+ volume = (pa_cvolume) {.channels = input->channels};
+ tmp_vol = input->vol;
+ volume_set = pa_context_set_sink_input_volume;
+ } else if (ctx->chooser_input == SELECTED_SINK) {
+ index = sink->index;
+ volume = (pa_cvolume) {.channels = sink->channels};
+ tmp_vol = sink->vol;
+ volume_set = pa_context_set_sink_volume_by_index;
+ } else
break;
- case 'h':
- case 'a':
- case KEY_LEFT:
- volume_increment = FALSE;
- /* fall through */
- case 'l':
- case 'd':
- case KEY_RIGHT: {
- guint32 index;
- pa_cvolume volume;
- pa_volume_t tmp_vol;
- pa_operation* (*volume_set) (pa_context*, guint32, const pa_cvolume*, pa_context_success_cb_t, gpointer);
-
- sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
- if (ctx->chooser_input >= 0) {
- sink_input_info *input = g_list_nth_data(sink->input_list, ctx->chooser_input);
- index = input->index;
- volume = (pa_cvolume) {.channels = input->channels};
- tmp_vol = input->vol;
- volume_set = pa_context_set_sink_input_volume;
- } else if (ctx->chooser_input == SELECTED_SINK) {
- index = sink->index;
- volume = (pa_cvolume) {.channels = sink->channels};
- tmp_vol = sink->vol;
- volume_set = pa_context_set_sink_volume_by_index;
- } else
- break;
-
- pa_cvolume_set(&volume, volume.channels, tmp_vol);
- pa_volume_t inc = 2 * PA_VOLUME_NORM / 100;
+ pa_cvolume_set(&volume, volume.channels, tmp_vol);
+ pa_volume_t inc = 2 * PA_VOLUME_NORM / 100;
- if (volume_increment)
- if (PA_VOLUME_NORM > tmp_vol && PA_VOLUME_NORM - tmp_vol > inc)
- pa_cvolume_inc(&volume, inc);
- else
- pa_cvolume_set(&volume, volume.channels, PA_VOLUME_NORM);
+ if (volume_increment)
+ if (PA_VOLUME_NORM > tmp_vol && PA_VOLUME_NORM - tmp_vol > inc)
+ pa_cvolume_inc(&volume, inc);
else
- pa_cvolume_dec(&volume, inc);
-
+ pa_cvolume_set(&volume, volume.channels, PA_VOLUME_NORM);
+ else
+ pa_cvolume_dec(&volume, inc);
- pa_operation_unref(volume_set(ctx->context, index, &volume, change_callback, ctx));
- break;
- }
-
-
- case 'm':
- case 'x':
- case 'M': {
- guint32 index;
- gint mute;
- pa_operation* (*mute_set) (pa_context*, guint32, int, pa_context_success_cb_t, void*);
-
- sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
- if (ctx->chooser_input >= 0) {
- sink_input_info *input = g_list_nth_data(sink->input_list, ctx->chooser_input);
- index = input->index;
- mute = !input->mute;
- mute_set = pa_context_set_sink_input_mute;
- } else if (ctx->chooser_input == SELECTED_SINK) {
- index = sink->index;
- mute = !sink->mute;
- mute_set = pa_context_set_sink_mute_by_index;
- } else
- break;
- pa_operation_unref(mute_set(ctx->context, index, mute, change_callback, ctx));
- break;
- }
+ pa_operation_unref(volume_set(ctx->context, index, &volume, change_callback, ctx));
+ break;
+ case 'm':
+ case 'x':
+ case 'M':
+ sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
+ gint mute;
+ pa_operation* (*mute_set) (pa_context*, guint32, int, pa_context_success_cb_t, void*);
- case '\n':
- case '\t':
- case ' ':
- if (ctx->chooser_input == SELECTED_SINK)
- break;
- sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
+ if (ctx->chooser_input >= 0) {
sink_input_info *input = g_list_nth_data(sink->input_list, ctx->chooser_input);
- ctx->selected_index = input->index;
- if (ctx->chooser_sink < (gint)g_list_length(ctx->sink_list) - 1)
- ctx->chooser_sink++;
- else
- ctx->chooser_sink = 0;
-
- sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
- /* ctx->chooser_input needs to be derived from $ctx->selected_index */
- ctx->chooser_input = SELECTED_UNKNOWN;
- pa_operation_unref(pa_context_move_sink_input_by_index(ctx->context, ctx->selected_index,
- sink->index,
- change_callback, NULL));
+ index = input->index;
+ mute = !input->mute;
+ mute_set = pa_context_set_sink_input_mute;
+ } else if (ctx->chooser_input == SELECTED_SINK) {
+ index = sink->index;
+ mute = !sink->mute;
+ mute_set = pa_context_set_sink_mute_by_index;
+ } else
break;
- case 'q':
- default:
- quit(ctx);
+ pa_operation_unref(mute_set(ctx->context, index, mute, change_callback, ctx));
+ break;
+
+ case '\n':
+ case '\t':
+ case ' ':
+ if (ctx->chooser_input == SELECTED_SINK)
break;
+ sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
+ sink_input_info *input = g_list_nth_data(sink->input_list, ctx->chooser_input);
+ ctx->selected_index = input->index;
+ if (ctx->chooser_sink < (gint)g_list_length(ctx->sink_list) - 1)
+ ctx->chooser_sink++;
+ else
+ ctx->chooser_sink = 0;
+
+ sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
+ /* ctx->chooser_input needs to be derived from $ctx->selected_index */
+ ctx->chooser_input = SELECTED_UNKNOWN;
+ pa_operation_unref(pa_context_move_sink_input_by_index(ctx->context, ctx->selected_index,
+ sink->index,
+ change_callback, NULL));
+ break;
+
+ case 'q':
+ default:
+ quit(ctx);
+ break;
}
return TRUE;
@@ -368,7 +363,7 @@ interface_init(struct context *ctx)
ctx->chooser_sink = 0; /* Selected sink-device. 0 is the first device */
ctx->chooser_input = SELECTED_SINK; /* Selected input of the current sink-device. */
- /* SELECTED_SINK refers to sink-device itself */
+ /* SELECTED_SINK refers to sink-device itself */
initscr();
clear();
@@ -381,7 +376,7 @@ interface_init(struct context *ctx)
/* 0,0,0,0 := fullscreen */
ctx->menu_win = newwin(0, 0, 0, 0);
ctx->msg_win = newwin(0, 0, 0, 0);
-
+
/* multichar keys are mapped to one char */
keypad(ctx->menu_win, TRUE);
@@ -413,6 +408,6 @@ interface_init(struct context *ctx)
ctx->input_source_id = g_io_add_watch(input_channel, G_IO_IN,
interface_get_input, ctx);
g_io_channel_unref(input_channel);
-
+
refresh();
}
diff --git a/src/interface.h b/src/interface.h
index e9e47eb..8b58621 100644
--- a/src/interface.h
+++ b/src/interface.h
@@ -7,9 +7,16 @@
struct context;
-void print_sink_list(struct context *ctx);
-void interface_init(struct context *ctx);
-void interface_clear(struct context *ctx);
-void interface_set_status(struct context *ctx, const gchar *);
+void
+print_sink_list(struct context *ctx);
+
+void
+interface_init(struct context *ctx);
+
+void
+interface_clear(struct context *ctx);
+
+void
+interface_set_status(struct context *ctx, const gchar *);
#endif
diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c
index 32d7873..f8a74b8 100644
--- a/src/pa-sink-ctl.c
+++ b/src/pa-sink-ctl.c
@@ -42,7 +42,7 @@ main(int argc, char** argv)
g_printerr("error: pa_context_new() failed.\n");
return -1;
}
-
+
// define callback for connection init
pa_context_set_state_callback(ctx->context, context_state_callback, ctx);
if (pa_context_connect(ctx->context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL)) {
@@ -82,40 +82,39 @@ context_state_callback(pa_context *c, gpointer userdata)
ctx->context_ready = FALSE;
switch (pa_context_get_state(c)) {
- case PA_CONTEXT_CONNECTING:
- interface_set_status(ctx, "connecting...");
- break;
- case PA_CONTEXT_AUTHORIZING:
- interface_set_status(ctx, "authorizing...");
- break;
- case PA_CONTEXT_SETTING_NAME:
- interface_set_status(ctx, "setting name...");
- break;
-
- case PA_CONTEXT_READY:
- collect_all_info(ctx);
- pa_context_set_subscribe_callback(c, subscribe_cb, ctx);
- g_assert((ctx->op = pa_context_subscribe(c, (pa_subscription_mask_t) (
- PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SINK_INPUT
- ), NULL, NULL)));
- ctx->context_ready = TRUE;
- interface_set_status(ctx, "ready to process events.");
- break;
- case PA_CONTEXT_FAILED:
- interface_set_status(ctx, "cannot connect!");
- break;
-
- case PA_CONTEXT_TERMINATED:
- g_assert(ctx->op != NULL);
- pa_operation_cancel(ctx->op);
- pa_operation_unref(ctx->op);
- ctx->op = NULL;
- interface_set_status(ctx, "connection terminated.");
- g_main_loop_quit(ctx->loop);
- break;
- default:
- interface_set_status(ctx, "unknown state");
- break;
+ case PA_CONTEXT_CONNECTING:
+ interface_set_status(ctx, "connecting...");
+ break;
+ case PA_CONTEXT_AUTHORIZING:
+ interface_set_status(ctx, "authorizing...");
+ break;
+ case PA_CONTEXT_SETTING_NAME:
+ interface_set_status(ctx, "setting name...");
+ break;
+
+ case PA_CONTEXT_READY:
+ collect_all_info(ctx);
+ pa_context_set_subscribe_callback(c, subscribe_cb, ctx);
+ pa_subscription_mask_t mask = PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SINK_INPUT;
+ g_assert((ctx->op = pa_context_subscribe(c, (pa_subscription_mask_t) (mask), NULL, NULL)));
+ ctx->context_ready = TRUE;
+ interface_set_status(ctx, "ready to process events.");
+ break;
+ case PA_CONTEXT_FAILED:
+ interface_set_status(ctx, "cannot connect!");
+ break;
+
+ case PA_CONTEXT_TERMINATED:
+ g_assert(ctx->op != NULL);
+ pa_operation_cancel(ctx->op);
+ pa_operation_unref(ctx->op);
+ ctx->op = NULL;
+ interface_set_status(ctx, "connection terminated.");
+ g_main_loop_quit(ctx->loop);
+ break;
+ default:
+ interface_set_status(ctx, "unknown state");
+ break;
}
}
diff --git a/src/pa-sink-ctl.h b/src/pa-sink-ctl.h
index 4358c56..c5bc473 100644
--- a/src/pa-sink-ctl.h
+++ b/src/pa-sink-ctl.h
@@ -35,12 +35,19 @@ struct context {
gchar *status;
};
-void collect_all_info(struct context *ctx);
-void quit(struct context *ctx);
-
-void context_state_callback(pa_context*, gpointer);
-void get_sink_info_callback(pa_context *, const pa_sink_info *, gint, gpointer);
-void get_sink_input_info_callback(pa_context *, const pa_sink_input_info*, gint, gpointer);
-void change_callback(pa_context* c, gint success, gpointer);
+void
+collect_all_info(struct context *ctx);
+
+void
+quit(struct context *ctx);
+
+void
+context_state_callback(pa_context*, gpointer);
+void
+get_sink_info_callback(pa_context *, const pa_sink_info *, gint, gpointer);
+void
+get_sink_input_info_callback(pa_context *, const pa_sink_input_info*, gint, gpointer);
+void
+change_callback(pa_context* c, gint success, gpointer);
#endif