summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-12-18 13:12:50 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-12-18 13:34:26 +0100
commit89b9e7e17893ceff2b8a238258d27c184ed07c64 (patch)
tree22e3ecc7a3c3e7e6e1dacd6653adbe9f991eda73 /src
parent9e48ce1c7b87157921ce9dd695866073a8401899 (diff)
downloadpa-sink-ctl-89b9e7e17893ceff2b8a238258d27c184ed07c64.tar.gz
pa-sink-ctl-89b9e7e17893ceff2b8a238258d27c184ed07c64.tar.bz2
pa-sink-ctl-89b9e7e17893ceff2b8a238258d27c184ed07c64.zip
Unify common sink(_input) properties to a base object
Diffstat (limited to 'src')
-rw-r--r--src/command.c31
-rw-r--r--src/interface.c21
-rw-r--r--src/pa-sink-ctl.c28
-rw-r--r--src/sink.h19
4 files changed, 51 insertions, 48 deletions
diff --git a/src/command.c b/src/command.c
index 04fadf0..562e358 100644
--- a/src/command.c
+++ b/src/command.c
@@ -31,7 +31,7 @@ sink_input_len(struct context *ctx, struct sink_info *sink)
int len = 0;
list_foreach(ctx->input_list, input)
- if (input->sink == sink->index)
+ if (input->sink == sink->base.index)
len++;
return len;
@@ -44,7 +44,7 @@ sink_get_nth_input(struct context *ctx, struct sink_info *sink, int n)
int i = 0;
list_foreach(ctx->input_list, input) {
- if (input->sink != sink->index)
+ if (input->sink != sink->base.index)
continue;
if (i++ == n)
return input;
@@ -108,14 +108,14 @@ volume_change(struct context *ctx, gboolean volume_increment)
sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
if (ctx->chooser_input >= 0) {
input = sink_get_nth_input(ctx, sink, ctx->chooser_input);
- index = input->index;
- volume = (pa_cvolume) { .channels = input->channels };
- tmp_vol = input->vol;
+ index = input->base.index;
+ volume = (pa_cvolume) { .channels = input->base.channels };
+ tmp_vol = input->base.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;
+ index = sink->base.index;
+ volume = (pa_cvolume) { .channels = sink->base.channels };
+ tmp_vol = sink->base.vol;
volume_set = pa_context_set_sink_volume_by_index;
} else {
g_assert(0);
@@ -168,12 +168,12 @@ do_mute(struct context *ctx, int key)
if (ctx->chooser_input >= 0) {
input = sink_get_nth_input(ctx, sink, ctx->chooser_input);
- index = input->index;
- mute = !input->mute;
+ index = input->base.index;
+ mute = !input->base.mute;
mute_set = pa_context_set_sink_input_mute;
} else if (ctx->chooser_input == SELECTED_SINK) {
- index = sink->index;
- mute = !sink->mute;
+ index = sink->base.index;
+ mute = !sink->base.mute;
mute_set = pa_context_set_sink_mute_by_index;
} else {
g_assert(0);
@@ -208,7 +208,8 @@ switch_sink(struct context *ctx, int key)
sink = g_list_nth_data(ctx->sink_list, ctx->chooser_sink);
/* chooser_input needs to be derived from $selected_index */
o = pa_context_move_sink_input_by_index(ctx->context,
- input->index, sink->index,
+ input->base.index,
+ sink->base.index,
NULL, NULL);
pa_operation_unref(o);
@@ -216,11 +217,11 @@ switch_sink(struct context *ctx, int key)
ctx->chooser_input = SELECTED_SINK;
i = -1;
list_foreach(ctx->input_list, t) {
- if (t->index == input->index) {
+ if (t->base.index == input->base.index) {
ctx->chooser_input = ++i;
break;
}
- if (t->sink == sink->index)
+ if (t->sink == sink->base.index)
++i;
}
}
diff --git a/src/interface.c b/src/interface.c
index 57891b9..be332ba 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -97,7 +97,7 @@ print_input_list(struct context *ctx, struct sink_info *sink,
gint i = -1;
list_foreach(ctx->input_list, input) {
- if (input->sink != sink->index)
+ if (input->sink != sink->base.index)
continue;
selected = (ctx->chooser_sink == sink_num &&
ctx->chooser_input == ++i);
@@ -107,12 +107,12 @@ print_input_list(struct context *ctx, struct sink_info *sink,
mvwprintw(ctx->menu_win, offset, 2, "%*s%-*s",
2+1+1, "", /* space for index number + indentation*/
- ctx->max_name_len - 1, input->name);
+ ctx->max_name_len - 1, input->base.name);
if (selected)
wattroff(ctx->menu_win, A_REVERSE);
- print_volume(ctx, input->vol, input->mute, offset);
+ print_volume(ctx, input->base.vol, input->base.mute, offset);
offset++;
}
*poffset = offset;
@@ -122,20 +122,19 @@ print_input_list(struct context *ctx, struct sink_info *sink,
static void
set_max_name_len(struct context *ctx)
{
- struct sink_info *sink;
- struct sink_input_info *input;
+ struct vol_ctl_object *ctl;
guint len = 0;
ctx->max_name_len = len;
- list_foreach(ctx->sink_list, sink) {
- len = strlen(sink->name);
+ list_foreach(ctx->sink_list, ctl) {
+ len = strlen(ctl->name);
if (len > ctx->max_name_len)
ctx->max_name_len = len;
}
- list_foreach(ctx->input_list, input) {
- len = strlen(input->name) + 1 /* indentation */;
+ list_foreach(ctx->input_list, ctl) {
+ len = strlen(ctl->name) + 1 /* indentation */;
if (len > ctx->max_name_len)
ctx->max_name_len = len;
@@ -164,11 +163,11 @@ interface_redraw(struct context *ctx)
wattron(ctx->menu_win, A_REVERSE);
mvwprintw(ctx->menu_win, offset, x, "%2u %-*s",
- sink->index, ctx->max_name_len, sink->name);
+ sink->base.index, ctx->max_name_len, sink->base.name);
if (selected)
wattroff(ctx->menu_win, A_REVERSE);
- print_volume(ctx, sink->vol, sink->mute, offset);
+ print_volume(ctx, sink->base.vol, sink->base.mute, offset);
offset++;
print_input_list(ctx, sink, i, &offset);
diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c
index 0ec72ab..0ff6ee8 100644
--- a/src/pa-sink-ctl.c
+++ b/src/pa-sink-ctl.c
@@ -98,19 +98,19 @@ sink_info_cb(pa_context *c, const pa_sink_info *i,
sink = g_new(struct sink_info, 1);
if (sink == NULL)
return;
- sink->index = i->index;
+ sink->base.index = i->index;
sink->priority = get_sink_priority(ctx, i);
ctx->sink_list = g_list_insert_sorted(ctx->sink_list, sink,
compare_sink_priority);
} else {
sink = el->data;
- g_free(sink->name);
+ g_free(sink->base.name);
}
- sink->mute = i->mute;
- sink->vol = pa_cvolume_avg(&i->volume);
- sink->channels = i->volume.channels;
- sink->name = get_sink_name(ctx, i);
+ sink->base.mute = i->mute;
+ sink->base.vol = pa_cvolume_avg(&i->volume);
+ sink->base.channels = i->volume.channels;
+ sink->base.name = get_sink_name(ctx, i);
}
static void
@@ -142,21 +142,21 @@ sink_input_info_cb(pa_context *c, const pa_sink_input_info *i,
sink_input = g_new(struct sink_input_info, 1);
if (sink_input == NULL)
return;
- sink_input->index = i->index;
+ sink_input->base.index = i->index;
ctx->input_list = g_list_append(ctx->input_list, sink_input);
} else {
sink_input = el->data;
- g_free(sink_input->name);
+ g_free(sink_input->base.name);
}
sink_input->sink = i->sink;
- sink_input->name =
+ sink_input->base.name =
pa_proplist_contains(i->proplist, "application.name") ?
g_strdup(pa_proplist_gets(i->proplist, "application.name")) :
g_strdup(i->name);
- sink_input->mute = i->mute;
- sink_input->channels = i->volume.channels;
- sink_input->vol = pa_cvolume_avg(&i->volume);
+ sink_input->base.mute = i->mute;
+ sink_input->base.channels = i->volume.channels;
+ sink_input->base.vol = pa_cvolume_avg(&i->volume);
}
static void
@@ -164,7 +164,7 @@ sink_free(gpointer data)
{
struct sink_info *sink = data;
- g_free(sink->name);
+ g_free(sink->base.name);
g_free(sink);
}
@@ -173,7 +173,7 @@ sink_input_free(gpointer data)
{
struct sink_input_info *input = data;
- g_free(input->name);
+ g_free(input->base.name);
g_free(input);
}
diff --git a/src/sink.h b/src/sink.h
index 304e3fc..8c0c33d 100644
--- a/src/sink.h
+++ b/src/sink.h
@@ -23,22 +23,25 @@
#include <glib.h>
#include <pulse/pulseaudio.h>
-struct sink_info {
+struct context;
+
+struct vol_ctl_object {
guint32 index;
- gchar* name;
+ pa_volume_t vol; // TOTO: exchange with the channel-list
gint mute;
guint8 channels;
- pa_volume_t vol;
+
+ gchar *name; /* displayed name */
+};
+
+struct sink_info {
+ struct vol_ctl_object base;
gint priority;
};
struct sink_input_info {
- guint32 index;
+ struct vol_ctl_object base;
guint32 sink;
- gchar *name;
- gint mute;
- guint8 channels;
- pa_volume_t vol; // TOTO: exchange with the channel-list
};
#endif