summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-10-22 08:48:27 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-10-22 08:49:53 +0200
commit2fced182b9479d777ac3ab7c87424d3c57ced565 (patch)
treefe9cf59fe4671fa445020be3edaa11fa83ba87bc
parent7f3831b86ab19512fab51a4c7ca5bcffdde7ce03 (diff)
downloadpa-sink-ctl-2fced182b9479d777ac3ab7c87424d3c57ced565.tar.gz
pa-sink-ctl-2fced182b9479d777ac3ab7c87424d3c57ced565.tar.bz2
pa-sink-ctl-2fced182b9479d777ac3ab7c87424d3c57ced565.zip
Fix 80 column width
-rw-r--r--src/interface.c81
-rw-r--r--src/pa-sink-ctl.c54
-rw-r--r--src/unix_signal.c9
3 files changed, 97 insertions, 47 deletions
diff --git a/src/interface.c b/src/interface.c
index f48363b..cdf01e1 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -88,8 +88,8 @@ print_volume(struct context *ctx, pa_volume_t volume, int mute, int y)
gint x = 2 /* left */ + 2 /* index num width */ + 1 /* space */ +
1 /* space */ + ctx->max_name_len + 1 /* space */;
- //gint vol = (gint) (VOLUME_BAR_LEN * volume / PA_VOLUME_NORM);
- int volume_bar_len = getmaxx(ctx->menu_win) - x - 6 /* mute button + brackets + space */;
+ /* mute button + brackets + space */
+ int volume_bar_len = getmaxx(ctx->menu_win) - x - 6;
gint vol = (gint) (volume_bar_len * volume / PA_VOLUME_NORM);
mvwprintw(ctx->menu_win, y, x - 1, "[%c]", mute ? 'M' : ' ');
@@ -104,7 +104,8 @@ print_volume(struct context *ctx, pa_volume_t volume, int mute, int y)
}
static void
-print_input_list(struct context *ctx, sink_info *sink, gint sink_num, gint *poffset)
+print_input_list(struct context *ctx, sink_info *sink,
+ gint sink_num, gint *poffset)
{
GList *l;
gint offset = *poffset;
@@ -114,7 +115,8 @@ print_input_list(struct context *ctx, sink_info *sink, gint sink_num, gint *poff
sink_input_info *input = l->data;
if (input->sink != sink->index)
continue;
- gboolean selected = (ctx->chooser_sink == sink_num && ctx->chooser_input == ++i);
+ gboolean selected = (ctx->chooser_sink == sink_num &&
+ ctx->chooser_input == ++i);
if (selected)
wattron(ctx->menu_win, A_REVERSE);
@@ -173,12 +175,13 @@ print_sink_list(struct context *ctx)
werase(ctx->menu_win);
box(ctx->menu_win, 0, 0);
- /* derive ctx->chooser_input from ctx->selected_index (this is set when input is moved) */
+ /* derive chooser_input from selected_index (set when input is moved) */
if (ctx->chooser_input == SELECTED_UNKNOWN) {
- /* if index is will not be found (in the loop), select the sink itself */
+ /* if index is will not be found, select sink as fallback */
ctx->chooser_input = SELECTED_SINK;
/* step through inputs for current sink and find the selected */
- sink_info *sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
+ sink_info *sink = g_list_nth_data(ctx->sink_list,
+ ctx->chooser_sink);
for (l = ctx->input_list, i = -1; l; l = l->next) {
sink_input_info *input = l->data;
if (input->sink != sink->index)
@@ -193,7 +196,8 @@ 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);
+ gboolean selected = (i == ctx->chooser_sink &&
+ ctx->chooser_input == SELECTED_SINK);
if (selected)
wattron(ctx->menu_win, A_REVERSE);
@@ -220,6 +224,7 @@ interface_get_input(GIOChannel *source, GIOCondition condition, gpointer data)
gboolean volume_increment = TRUE;
sink_info *sink = NULL;
guint32 index;
+ pa_operation *o;
if (!ctx->context_ready)
return TRUE;
@@ -229,9 +234,11 @@ interface_get_input(GIOChannel *source, GIOCondition condition, gpointer data)
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 */
+ if (ctx->chooser_input == SELECTED_SINK &&
+ ctx->chooser_sink > 0) {
+ sink = g_list_nth_data(ctx->sink_list,
+ --ctx->chooser_sink);
+ /* autoassigment to SELECTED_SINK (=-1) if length = 0 */
ctx->chooser_input = sink_input_len(ctx, sink) - 1;
}
@@ -244,7 +251,8 @@ interface_get_input(GIOChannel *source, GIOCondition condition, gpointer data)
case 's':
case KEY_DOWN:
sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
- if (ctx->chooser_input == (sink_input_len(ctx, sink) - 1) && ctx->chooser_sink < (gint)g_list_length(ctx->sink_list) - 1) {
+ if (ctx->chooser_input == (sink_input_len(ctx, sink) - 1) &&
+ ctx->chooser_sink < (gint)g_list_length(ctx->sink_list)-1) {
++ctx->chooser_sink;
ctx->chooser_input = SELECTED_SINK;
}
@@ -264,10 +272,14 @@ interface_get_input(GIOChannel *source, GIOCondition condition, gpointer data)
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);
+ 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 = sink_get_nth_input(ctx, sink, ctx->chooser_input);
+ sink_input_info *input =
+ sink_get_nth_input(ctx, sink,
+ ctx->chooser_input);
index = input->index;
volume = (pa_cvolume) {.channels = input->channels};
tmp_vol = input->vol;
@@ -284,25 +296,31 @@ interface_get_input(GIOChannel *source, GIOCondition condition, gpointer data)
pa_volume_t inc = 2 * PA_VOLUME_NORM / 100;
if (volume_increment)
- if (PA_VOLUME_NORM > tmp_vol && PA_VOLUME_NORM - tmp_vol > inc)
+ 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);
+ 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));
+ 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*);
+ pa_operation* (*mute_set) (pa_context*, guint32, int,
+ pa_context_success_cb_t, void*);
if (ctx->chooser_input >= 0) {
- sink_input_info *input = sink_get_nth_input(ctx, sink, ctx->chooser_input);
+ sink_input_info *input =
+ sink_get_nth_input(ctx, sink,
+ ctx->chooser_input);
index = input->index;
mute = !input->mute;
mute_set = pa_context_set_sink_input_mute;
@@ -313,7 +331,8 @@ interface_get_input(GIOChannel *source, GIOCondition condition, gpointer data)
} else
break;
- pa_operation_unref(mute_set(ctx->context, index, mute, change_callback, ctx));
+ pa_operation_unref(mute_set(ctx->context, index, mute,
+ change_callback, ctx));
break;
case '\n':
@@ -322,7 +341,8 @@ interface_get_input(GIOChannel *source, GIOCondition condition, gpointer data)
if (ctx->chooser_input == SELECTED_SINK)
break;
sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
- sink_input_info *input = sink_get_nth_input(ctx, sink, ctx->chooser_input);
+ sink_input_info *input = sink_get_nth_input(ctx, sink,
+ ctx->chooser_input);
ctx->selected_index = input->index;
if (ctx->chooser_sink < (gint)g_list_length(ctx->sink_list) - 1)
ctx->chooser_sink++;
@@ -330,12 +350,14 @@ interface_get_input(GIOChannel *source, GIOCondition condition, gpointer data)
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 */
+ /* chooser_input needs to be derived from $selected_index */
ctx->chooser_input = SELECTED_UNKNOWN;
ctx->block_for_selected_index = TRUE;
- pa_operation_unref(pa_context_move_sink_input_by_index(ctx->context, ctx->selected_index,
- sink->index,
- change_callback, NULL));
+ o = pa_context_move_sink_input_by_index(ctx->context,
+ ctx->selected_index,
+ sink->index,
+ change_callback, NULL);
+ pa_operation_unref(o);
break;
case 'q':
@@ -396,9 +418,11 @@ interface_init(struct context *ctx)
{
GIOChannel *input_channel;
- 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-device. 0 is the first device */
+ ctx->chooser_sink = 0;
+ /* Selected input of the current sink-device. */
/* SELECTED_SINK refers to sink-device itself */
+ ctx->chooser_input = SELECTED_SINK;
initscr();
clear();
@@ -435,7 +459,8 @@ interface_init(struct context *ctx)
}
#else
/* register event handler for resize and input */
- ctx->resize_source_id = unix_signal_add(SIGWINCH, interface_resize, ctx);
+ ctx->resize_source_id = unix_signal_add(SIGWINCH,
+ interface_resize, ctx);
#endif
input_channel = g_io_channel_unix_new(STDIN_FILENO);
if (!input_channel)
diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c
index 8e0be30..bda5052 100644
--- a/src/pa-sink-ctl.c
+++ b/src/pa-sink-ctl.c
@@ -44,13 +44,15 @@ find_sink_by_idx(struct context *ctx, gint idx)
* is called after sink-input
*/
static void
-get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, gint is_last, gpointer userdata)
+sink_input_info_cb(pa_context *c, const pa_sink_input_info *i,
+ gint is_last, gpointer userdata)
{
g_assert(userdata != NULL);
struct context *ctx = userdata;
if (is_last < 0) {
- g_printerr("Failed to get sink input information: %s\n", pa_strerror(pa_context_errno(c)));
+ g_printerr("Failed to get sink input information: %s\n",
+ pa_strerror(pa_context_errno(c)));
return;
}
@@ -69,7 +71,8 @@ get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, gint is
.index = i->index,
.sink = i->sink,
.name = pa_proplist_contains(i->proplist, "application.name") ?
- g_strdup(pa_proplist_gets(i->proplist, "application.name")):
+ g_strdup(pa_proplist_gets(i->proplist,
+ "application.name")):
g_strdup(i->name),
.mute = i->mute,
.channels = i->volume.channels,
@@ -88,13 +91,15 @@ get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, gint is
* the begin of the callback loops
*/
static void
-get_sink_info_callback(pa_context *c, const pa_sink_info *i, gint is_last, gpointer userdata)
+sink_info_cb(pa_context *c, const pa_sink_info *i,
+ gint is_last, gpointer userdata)
{
g_assert(userdata != NULL);
struct context *ctx = userdata;
if (is_last < 0) {
- g_printerr("Failed to get sink information: %s\n", pa_strerror(pa_context_errno(c)));
+ g_printerr("Failed to get sink information: %s\n",
+ pa_strerror(pa_context_errno(c)));
quit(ctx);
}
@@ -110,8 +115,11 @@ get_sink_info_callback(pa_context *c, const pa_sink_info *i, gint is_last, gpoin
.vol = pa_cvolume_avg(&i->volume),
.channels = i->volume.channels,
.name = g_strdup(i->name),
- .device = pa_proplist_contains(i->proplist, "device.product.name") ?
- g_strdup(pa_proplist_gets(i->proplist, "device.product.name")) : NULL,
+ .device = pa_proplist_contains(i->proplist,
+ "device.product.name") ?
+ g_strdup(pa_proplist_gets(i->proplist,
+ "device.product.name")) :
+ NULL,
};
sink_info *inlist = find_sink_by_idx(ctx, i->index);
@@ -122,7 +130,8 @@ get_sink_info_callback(pa_context *c, const pa_sink_info *i, gint is_last, gpoin
}
static void
-subscribe_cb(pa_context *c, pa_subscription_event_type_t t, guint32 idx, gpointer userdata)
+subscribe_cb(pa_context *c, pa_subscription_event_type_t t,
+ guint32 idx, gpointer userdata)
{
struct context *ctx = userdata;
pa_operation *op;
@@ -133,11 +142,15 @@ subscribe_cb(pa_context *c, pa_subscription_event_type_t t, guint32 idx, gpointe
case PA_SUBSCRIPTION_EVENT_CHANGE:
switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {
case PA_SUBSCRIPTION_EVENT_SINK:
- op = pa_context_get_sink_info_by_index(c, idx, get_sink_info_callback, ctx);
+ op = pa_context_get_sink_info_by_index(c, idx,
+ sink_info_cb,
+ ctx);
pa_operation_unref(op);
break;
case PA_SUBSCRIPTION_EVENT_SINK_INPUT:
- op = pa_context_get_sink_input_info(c, idx, get_sink_input_info_callback, ctx);
+ op = pa_context_get_sink_input_info(c, idx,
+ sink_input_info_cb,
+ ctx);
pa_operation_unref(op);
break;
}
@@ -151,7 +164,8 @@ subscribe_cb(pa_context *c, pa_subscription_event_type_t t, guint32 idx, gpointe
break;
case PA_SUBSCRIPTION_EVENT_SINK_INPUT:
object = find_sink_input_by_idx(ctx, idx);
- ctx->input_list = g_list_remove(ctx->input_list, object);
+ ctx->input_list = g_list_remove(ctx->input_list,
+ object);
g_free(object);
break;
default:
@@ -171,6 +185,7 @@ static void
context_state_callback(pa_context *c, gpointer userdata)
{
struct context *ctx = userdata;
+ pa_operation *op;
ctx->context_ready = FALSE;
switch (pa_context_get_state(c)) {
@@ -185,11 +200,16 @@ context_state_callback(pa_context *c, gpointer userdata)
break;
case PA_CONTEXT_READY:
- pa_operation_unref(pa_context_get_sink_info_list(c, get_sink_info_callback, ctx));
- pa_operation_unref(pa_context_get_sink_input_info_list(c, get_sink_input_info_callback, ctx));
+ op = pa_context_get_sink_info_list(c, sink_info_cb, ctx);
+ pa_operation_unref(op);
+ op = pa_context_get_sink_input_info_list(c, sink_input_info_cb,
+ ctx);
+ pa_operation_unref(op);
pa_context_set_subscribe_callback(c, subscribe_cb, ctx);
- pa_subscription_mask_t mask = PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SINK_INPUT;
+ pa_subscription_mask_t mask =
+ PA_SUBSCRIPTION_MASK_SINK |
+ PA_SUBSCRIPTION_MASK_SINK_INPUT;
g_assert((ctx->op = pa_context_subscribe(c, mask, NULL, NULL)));
ctx->context_ready = TRUE;
interface_set_status(ctx, "ready to process events.");
@@ -261,8 +281,10 @@ main(int argc, char** argv)
}
// 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)) {
+ pa_context_set_state_callback(ctx->context,
+ context_state_callback, ctx);
+ if (pa_context_connect(ctx->context, NULL,
+ PA_CONTEXT_NOAUTOSPAWN, NULL)) {
interface_clear(ctx);
g_printerr("error: pa_context_connect() failed.\n");
}
diff --git a/src/unix_signal.c b/src/unix_signal.c
index 894b6d9..6d458d6 100644
--- a/src/unix_signal.c
+++ b/src/unix_signal.c
@@ -46,7 +46,8 @@ prepare(GSource *source, gint *timeout_)
UnixSignalSource *signal_source = (UnixSignalSource*) source;
if (signal_source->data->context == NULL) {
- g_main_context_ref(signal_source->data->context = g_source_get_context(source));
+ g_main_context_ref(signal_source->data->context =
+ g_source_get_context(source));
signal_source->data->source_id = g_source_get_id(source);
}
@@ -114,7 +115,8 @@ unix_signal_source_new(gint signum)
}
guint
-unix_signal_add_full(gint priority, gint signum, GSourceFunc function, gpointer data, GDestroyNotify notify)
+unix_signal_add_full(gint priority, gint signum, GSourceFunc function,
+ gpointer data, GDestroyNotify notify)
{
g_return_val_if_fail(function != NULL, 0);
GSource *source = unix_signal_source_new(signum);
@@ -131,5 +133,6 @@ unix_signal_add_full(gint priority, gint signum, GSourceFunc function, gpointer
guint unix_signal_add(gint signum, GSourceFunc function, gpointer data)
{
- return unix_signal_add_full(G_PRIORITY_DEFAULT, signum, function, data, NULL);
+ return unix_signal_add_full(G_PRIORITY_DEFAULT, signum,
+ function, data, NULL);
}