[Xfce4-commits] [panel-plugins/xfce4-pulseaudio-plugin] 01/21: Start adding device support. Can select default audio output device, but this does not currently propogate to active streams.
noreply at xfce.org
noreply at xfce.org
Sat Sep 23 21:27:27 CEST 2017
This is an automated email from the git hooks/post-receive script.
b l u e s a b r e p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository panel-plugins/xfce4-pulseaudio-plugin.
commit 6e118bf57859821a3e93fd225e0e64c217488bc7
Author: Sean Davis <smd.seandavis at gmail.com>
Date: Sat Sep 9 07:04:39 2017 -0400
Start adding device support. Can select default audio output device, but this does not currently propogate to active streams.
---
panel-plugin/pulseaudio-menu.c | 49 ++++++++++
panel-plugin/pulseaudio-volume.c | 195 +++++++++++++++++++++++++++++++++++++++
panel-plugin/pulseaudio-volume.h | 12 +++
3 files changed, 256 insertions(+)
diff --git a/panel-plugin/pulseaudio-menu.c b/panel-plugin/pulseaudio-menu.c
index d988f72..395e2fd 100644
--- a/panel-plugin/pulseaudio-menu.c
+++ b/panel-plugin/pulseaudio-menu.c
@@ -172,6 +172,20 @@ pulseaudio_menu_mute_output_item_toggled (PulseaudioMenu *menu,
static void
+pulseaudio_menu_default_output_item_toggled (PulseaudioMenu *menu,
+ GtkCheckMenuItem *menu_item)
+{
+ g_return_if_fail (IS_PULSEAUDIO_MENU (menu));
+
+ if (gtk_check_menu_item_get_active (menu_item))
+ {
+ pulseaudio_volume_set_default_output (menu->volume, (gchar *)g_object_get_data (G_OBJECT(menu_item), "name"));
+ }
+}
+
+
+
+static void
pulseaudio_menu_input_range_scroll (GtkWidget *widget,
GdkEvent *event,
PulseaudioMenu *menu)
@@ -378,6 +392,10 @@ pulseaudio_menu_new (PulseaudioVolume *volume,
GtkWidget *mi;
gdouble volume_max;
+ GtkWidget *submenu;
+ GList *sources = NULL;
+ GSList *group = NULL;
+
#ifdef HAVE_MPRIS2
gchar **players;
gchar *title = NULL;
@@ -436,6 +454,37 @@ pulseaudio_menu_new (PulseaudioVolume *volume,
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu->mute_output_item);
g_signal_connect_swapped (G_OBJECT (menu->mute_output_item), "toggled", G_CALLBACK (pulseaudio_menu_mute_output_item_toggled), menu);
+ sources = pulseaudio_volume_get_output_list (menu->volume);
+ if (g_list_length (sources) > 1) {
+ submenu = gtk_menu_new ();
+
+ for (GList *list = sources; list != NULL; list = g_list_next (list)) {
+ mi = gtk_radio_menu_item_new_with_label (group, pulseaudio_volume_get_output_by_name (menu->volume, list->data));
+ g_object_set_data (G_OBJECT (mi), "name", g_strdup ((gchar *)list->data));
+
+ group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (mi));
+ if (g_strcmp0 (list->data, pulseaudio_volume_get_default_output (menu->volume)) == 0)
+ {
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), TRUE);
+ }
+ else
+ {
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), FALSE);
+ }
+ gtk_widget_show (mi);
+ gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mi);
+
+ g_signal_connect_swapped (G_OBJECT (mi), "toggled", G_CALLBACK (pulseaudio_menu_default_output_item_toggled), menu);
+ }
+
+ mi = gtk_menu_item_new_with_label ("Output Device");
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), submenu);
+ gtk_widget_show (mi);
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+ }
+ g_list_free (sources);
+
/* separator */
mi = gtk_separator_menu_item_new ();
gtk_widget_show (mi);
diff --git a/panel-plugin/pulseaudio-volume.c b/panel-plugin/pulseaudio-volume.c
index 02adb66..aae6955 100644
--- a/panel-plugin/pulseaudio-volume.c
+++ b/panel-plugin/pulseaudio-volume.c
@@ -64,6 +64,16 @@ struct _PulseaudioVolume
gboolean muted_mic;
guint reconnect_timer_id;
+
+ /* Device management */
+ GHashTable *sinks;
+ GHashTable *sources;
+
+ guint sink_index;
+ guint source_index;
+
+ gchar *default_sink_name;
+ gchar *default_source_name;
};
struct _PulseaudioVolumeClass
@@ -125,8 +135,14 @@ pulseaudio_volume_init (PulseaudioVolume *volume)
volume->muted_mic = FALSE;
volume->reconnect_timer_id = 0;
+ volume->default_sink_name = NULL;
+ volume->default_source_name = NULL;
+
volume->pa_mainloop = pa_glib_mainloop_new (NULL);
+ volume->sinks = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free);
+ volume->sources = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free);
+
pulseaudio_volume_connect (volume);
}
@@ -139,6 +155,15 @@ pulseaudio_volume_finalize (GObject *object)
volume->config = NULL;
+ if (volume->default_sink_name)
+ g_free (volume->default_sink_name);
+
+ if (volume->default_source_name)
+ g_free (volume->default_source_name);
+
+ g_hash_table_destroy (volume->sinks);
+ g_hash_table_destroy (volume->sources);
+
pa_glib_mainloop_free (volume->pa_mainloop);
(*G_OBJECT_CLASS (pulseaudio_volume_parent_class)->finalize) (object);
@@ -161,6 +186,8 @@ pulseaudio_volume_sink_info_cb (pa_context *context,
if (i == NULL) return;
pulseaudio_debug ("sink info: %s, %s", i->name, i->description);
+ volume->sink_index = (guint)i->index;
+
muted = !!(i->mute);
vol = pulseaudio_volume_v2d (volume, i->volume.values[0]);
@@ -283,6 +310,69 @@ pulseaudio_volume_subscribe_cb (pa_context *context,
+
+
+static void
+pulseaudio_volume_get_sink_list_cb (pa_context *context,
+ const pa_sink_info *i,
+ int eol,
+ void *userdata)
+{
+ gchar *name = NULL;
+ gchar *description = NULL;
+
+ PulseaudioVolume *volume = PULSEAUDIO_VOLUME (userdata);
+ if (i == NULL) return;
+
+ if (eol > 0) return;
+
+ name = g_strdup (i->name);
+ description = g_strdup (i->description);
+
+ g_hash_table_insert (volume->sinks, name, description);
+}
+
+
+
+static void
+pulseaudio_volume_get_source_list_cb (pa_context *context,
+ const pa_source_info *i,
+ int eol,
+ void *userdata)
+{
+ gchar *name = NULL;
+ gchar *description = NULL;
+
+ PulseaudioVolume *volume = PULSEAUDIO_VOLUME (userdata);
+ if (i == NULL) return;
+
+ if (eol > 0) return;
+
+ name = g_strdup (i->name);
+ description = g_strdup (i->description);
+
+ g_hash_table_insert (volume->sources, name, description);
+}
+
+
+
+static void
+pulseaudio_volume_get_server_info_cb (pa_context *context,
+ const pa_server_info *i,
+ void *userdata)
+{
+ PulseaudioVolume *volume = PULSEAUDIO_VOLUME (userdata);
+ if (i == NULL) return;
+
+ g_free (volume->default_sink_name);
+ g_free (volume->default_source_name);
+
+ volume->default_sink_name = g_strdup (i->default_sink_name);
+ volume->default_source_name = g_strdup (i->default_source_name);
+}
+
+
+
static void
pulseaudio_volume_context_state_cb (pa_context *context,
void *userdata)
@@ -299,8 +389,14 @@ pulseaudio_volume_context_state_cb (pa_context *context,
volume->connected = TRUE;
// Check current sink and source volume manually. PA sink events usually not emitted.
pulseaudio_volume_sink_source_check (volume, context);
+
g_signal_emit (G_OBJECT (volume), pulseaudio_volume_signals [VOLUME_CHANGED], 0, FALSE);
g_signal_emit (G_OBJECT (volume), pulseaudio_volume_signals [VOLUME_MIC_CHANGED], 0, FALSE);
+
+ pa_context_get_sink_info_list (volume->pa_context, pulseaudio_volume_get_sink_list_cb, volume);
+ pa_context_get_source_info_list (volume->pa_context, pulseaudio_volume_get_source_list_cb, volume);
+ pa_context_get_server_info (volume->pa_context, pulseaudio_volume_get_server_info_cb, volume);
+
break;
case PA_CONTEXT_FAILED :
@@ -312,8 +408,13 @@ pulseaudio_volume_context_state_cb (pa_context *context,
volume->muted = FALSE;
volume->volume_mic = 0.0;
volume->muted_mic = FALSE;
+
g_signal_emit (G_OBJECT (volume), pulseaudio_volume_signals [VOLUME_CHANGED], 0, FALSE);
g_signal_emit (G_OBJECT (volume), pulseaudio_volume_signals [VOLUME_MIC_CHANGED], 0, FALSE);
+
+ g_hash_table_remove_all (volume->sinks);
+ g_hash_table_remove_all (volume->sources);
+
if (volume->reconnect_timer_id == 0)
volume->reconnect_timer_id = g_timeout_add_seconds
(5, pulseaudio_volume_reconnect_timeout, volume);
@@ -699,6 +800,100 @@ pulseaudio_volume_set_volume_mic (PulseaudioVolume *volume,
+GList *
+pulseaudio_volume_get_output_list (PulseaudioVolume *volume)
+{
+ g_return_if_fail (IS_PULSEAUDIO_VOLUME (volume));
+ return g_hash_table_get_keys (volume->sinks);
+}
+
+
+
+gchar *
+pulseaudio_volume_get_output_by_name (PulseaudioVolume *volume,
+ gchar *name)
+{
+ g_return_if_fail (IS_PULSEAUDIO_VOLUME (volume));
+ return (gchar *) g_hash_table_lookup (volume->sinks, name);
+}
+
+
+
+GList *
+pulseaudio_volume_get_input_list (PulseaudioVolume *volume)
+{
+ g_return_if_fail (IS_PULSEAUDIO_VOLUME (volume));
+ return g_hash_table_get_keys (volume->sources);
+}
+
+
+
+gchar *
+pulseaudio_volume_get_input_by_name (PulseaudioVolume *volume,
+ gchar *name)
+{
+ g_return_if_fail (IS_PULSEAUDIO_VOLUME (volume));
+ return (gchar *) g_hash_table_lookup (volume->sources, name);
+}
+
+
+
+const gchar *
+pulseaudio_volume_get_default_output (PulseaudioVolume *volume)
+{
+ return volume->default_sink_name;
+}
+
+
+
+static void
+pulseaudio_volume_default_sink_changed_info_cb (pa_context *context,
+ const pa_sink_info *i,
+ int eol,
+ void *userdata)
+{
+ PulseaudioVolume *volume = PULSEAUDIO_VOLUME (userdata);
+ if (i == NULL) return;
+
+ pa_context_move_sink_input_by_index (context, volume->sink_index, i->index, NULL, NULL);
+ volume->sink_index = (guint)i->index;
+}
+
+
+
+static void
+pulseaudio_volume_default_sink_changed (pa_context *context,
+ int success,
+ void *userdata)
+{
+ PulseaudioVolume *volume = PULSEAUDIO_VOLUME (userdata);
+
+ if (success)
+ pa_context_get_sink_info_by_name (volume->pa_context, volume->default_sink_name, pulseaudio_volume_default_sink_changed_info_cb, volume);
+}
+
+
+
+void
+pulseaudio_volume_set_default_output (PulseaudioVolume *volume,
+ gchar *name)
+{
+ g_free (volume->default_sink_name);
+ volume->default_sink_name = g_strdup (name);
+
+ pa_context_set_default_sink (volume->pa_context, name, pulseaudio_volume_default_sink_changed, volume);
+}
+
+
+
+const gchar *
+pulseaudio_volume_get_default_input (PulseaudioVolume *volume)
+{
+ return volume->default_source_name;
+}
+
+
+
PulseaudioVolume *
pulseaudio_volume_new (PulseaudioConfig *config)
{
diff --git a/panel-plugin/pulseaudio-volume.h b/panel-plugin/pulseaudio-volume.h
index 9ae0296..7acaa79 100644
--- a/panel-plugin/pulseaudio-volume.h
+++ b/panel-plugin/pulseaudio-volume.h
@@ -58,6 +58,18 @@ void pulseaudio_volume_set_muted_mic (PulseaudioVol
gboolean mic_muted);
void pulseaudio_volume_toggle_muted_mic (PulseaudioVolume *volume);
+GList *pulseaudio_volume_get_output_list (PulseaudioVolume *volume);
+gchar *pulseaudio_volume_get_output_by_name (PulseaudioVolume *volume,
+ gchar *name);
+const gchar *pulseaudio_volume_get_default_output (PulseaudioVolume *volume);
+void pulseaudio_volume_set_default_output (PulseaudioVolume *volume,
+ gchar *name);
+
+GList *pulseaudio_volume_get_input_list (PulseaudioVolume *volume);
+gchar *pulseaudio_volume_get_input_by_name (PulseaudioVolume *volume,
+ gchar *name);
+const gchar *pulseaudio_volume_get_default_input (PulseaudioVolume *volume);
+
G_END_DECLS
#endif /* !__PULSEAUDIO_VOLUME_H__ */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list