diff options
-rw-r--r-- | mate-volume-control/src/gvc-applet.c | 6 | ||||
-rw-r--r-- | mate-volume-control/src/gvc-mixer-dialog.c | 189 |
2 files changed, 130 insertions, 65 deletions
diff --git a/mate-volume-control/src/gvc-applet.c b/mate-volume-control/src/gvc-applet.c index fd5affc..ab2d2cc 100644 --- a/mate-volume-control/src/gvc-applet.c +++ b/mate-volume-control/src/gvc-applet.c @@ -98,7 +98,7 @@ update_icon_input (GvcApplet *applet) if G_UNLIKELY (control == NULL) { /* In the unlikely case when there is no - * default output control, use the application + * default input control, use the application * control for the icon */ control = input; } @@ -165,7 +165,7 @@ on_input_stream_control_added (MateMixerStream *stream, mate_mixer_stream_control_get_role (control); /* Non-application input control doesn't affect the icon */ - if (role == MATE_MIXER_STREAM_CONTROL_ROLE_APPLICATION) + if (role != MATE_MIXER_STREAM_CONTROL_ROLE_APPLICATION) return; } @@ -201,7 +201,7 @@ update_default_input_stream (GvcApplet *applet) g_object_unref (applet->priv->input); } - applet->priv->input = mate_mixer_context_get_default_input_stream (applet->priv->context); + applet->priv->input = g_object_ref (stream); if (applet->priv->input != NULL) { g_signal_connect (G_OBJECT (applet->priv->input), "control-added", diff --git a/mate-volume-control/src/gvc-mixer-dialog.c b/mate-volume-control/src/gvc-mixer-dialog.c index b56dad9..2ddc5ea 100644 --- a/mate-volume-control/src/gvc-mixer-dialog.c +++ b/mate-volume-control/src/gvc-mixer-dialog.c @@ -111,13 +111,28 @@ static const guint tab_accel_keys[] = { GDK_KEY_1, GDK_KEY_2, GDK_KEY_3, GDK_KEY_4, GDK_KEY_5 }; -static void gvc_mixer_dialog_class_init (GvcMixerDialogClass *klass); -static void gvc_mixer_dialog_init (GvcMixerDialog *dialog); -static void gvc_mixer_dialog_finalize (GObject *object); - -static void bar_set_stream (GvcMixerDialog *dialog, - GtkWidget *bar, - MateMixerStream *stream); +static void gvc_mixer_dialog_class_init (GvcMixerDialogClass *klass); +static void gvc_mixer_dialog_init (GvcMixerDialog *dialog); +static void gvc_mixer_dialog_finalize (GObject *object); + +static void add_stream (GvcMixerDialog *dialog, + MateMixerStream *stream); +static void add_application_control (GvcMixerDialog *dialog, + MateMixerStreamControl *control); +static void add_effects_control (GvcMixerDialog *dialog, + MateMixerStreamControl *control); + +static void remove_stream (GvcMixerDialog *dialog, + const gchar *name); +static void remove_application_control (GvcMixerDialog *dialog, + const gchar *name); + +static void bar_set_stream (GvcMixerDialog *dialog, + GtkWidget *bar, + MateMixerStream *stream); +static void bar_set_stream_control (GvcMixerDialog *dialog, + GtkWidget *bar, + MateMixerStreamControl *control); G_DEFINE_TYPE (GvcMixerDialog, gvc_mixer_dialog, GTK_TYPE_DIALOG) @@ -760,6 +775,28 @@ bar_set_stream (GvcMixerDialog *dialog, MateMixerStream *stream) { MateMixerStreamControl *control = NULL; + + if (stream != NULL) { + MateMixerSwitch *port_switch; + + control = mate_mixer_stream_get_default_control (stream); + + port_switch = find_stream_port_switch (stream); + if (port_switch != NULL) + g_signal_connect (G_OBJECT (port_switch), + "notify::active-option", + G_CALLBACK (on_switch_option_notify), + dialog); + } + + bar_set_stream_control (dialog, bar, control); +} + +static void +bar_set_stream_control (GvcMixerDialog *dialog, + GtkWidget *bar, + MateMixerStreamControl *control) +{ MateMixerStreamControl *previous; previous = gvc_channel_bar_get_control (GVC_CHANNEL_BAR (bar)); @@ -778,27 +815,18 @@ bar_set_stream (GvcMixerDialog *dialog, g_hash_table_remove (dialog->priv->bars, name); } - if (stream != NULL) { - MateMixerSwitch *port_switch; - - control = mate_mixer_stream_get_default_control (stream); - - port_switch = find_stream_port_switch (stream); - if (port_switch != NULL) - g_signal_connect (G_OBJECT (port_switch), - "notify::active-option", - G_CALLBACK (on_switch_option_notify), - dialog); + gvc_channel_bar_set_control (GVC_CHANNEL_BAR (bar), control); - if (G_LIKELY (control != NULL)) - g_hash_table_insert (dialog->priv->bars, - (gpointer) mate_mixer_stream_control_get_name (control), - bar); - } + if (control != NULL) { + const gchar *name = mate_mixer_stream_control_get_name (control); - gvc_channel_bar_set_control (GVC_CHANNEL_BAR (bar), control); + g_hash_table_insert (dialog->priv->bars, + (gpointer) name, + bar); - gtk_widget_set_sensitive (GTK_WIDGET (bar), (stream != NULL)); + gtk_widget_set_sensitive (GTK_WIDGET (bar), TRUE); + } else + gtk_widget_set_sensitive (GTK_WIDGET (bar), TRUE); } static void @@ -879,7 +907,7 @@ add_application_control (GvcMixerDialog *dialog, MateMixerStreamControl *control bar, FALSE, FALSE, 12); - bar_set_stream (dialog, bar, stream); + bar_set_stream_control (dialog, bar, control); dialog->priv->num_apps++; gtk_widget_hide (dialog->priv->no_apps_label); @@ -918,6 +946,56 @@ add_effects_control (GvcMixerDialog *dialog, MateMixerStreamControl *control) } static void +on_stream_control_added (MateMixerStream *stream, + const gchar *name, + GvcMixerDialog *dialog) +{ + MateMixerStreamControl *control; + MateMixerStreamControlRole role; + + control = mate_mixer_stream_get_control (stream, name); + if G_UNLIKELY (control == NULL) + return; + + role = mate_mixer_stream_control_get_role (control); + + if (role == MATE_MIXER_STREAM_CONTROL_ROLE_APPLICATION) + add_application_control (dialog, control); +} + +static void +on_stream_control_removed (MateMixerStream *stream, + const gchar *name, + GvcMixerDialog *dialog) +{ + MateMixerStreamControl *control; + + control = gvc_channel_bar_get_control (GVC_CHANNEL_BAR (dialog->priv->input_bar)); + if (control != NULL) { + const gchar *input_name = mate_mixer_stream_control_get_name (control); + + if (strcmp (name, input_name) == 0) { + // XXX probably can't even happen, but handle it somehow + return; + } + } + + control = gvc_channel_bar_get_control (GVC_CHANNEL_BAR (dialog->priv->output_bar)); + if (control != NULL) { + const gchar *input_name = mate_mixer_stream_control_get_name (control); + + if (strcmp (name, input_name) == 0) { + // XXX probably can't even happen, but handle it somehow + return; + } + } + + /* No way to be sure that it is an application control, but we don't have + * any other than application bars that could match the name */ + remove_application_control (dialog, name); +} + +static void add_stream (GvcMixerDialog *dialog, MateMixerStream *stream) { GtkTreeModel *model = NULL; @@ -988,6 +1066,16 @@ add_stream (GvcMixerDialog *dialog, MateMixerStream *stream) SPEAKERS_COLUMN, speakers, -1); } + + // XXX find a way to disconnect when removed + g_signal_connect (G_OBJECT (stream), + "control-added", + G_CALLBACK (on_stream_control_added), + dialog); + g_signal_connect (G_OBJECT (stream), + "control-removed", + G_CALLBACK (on_stream_control_removed), + dialog); } static void @@ -1009,31 +1097,6 @@ update_device_test_visibility (GvcMixerDialog *dialog) } static void -on_stream_control_added (MateMixerStream *stream, - const gchar *name, - GvcMixerDialog *dialog) -{ - MateMixerStreamControl *control; - MateMixerStreamControlRole role; - - control = mate_mixer_stream_get_control (stream, name); - if G_UNLIKELY (control == NULL) - return; - - role = mate_mixer_stream_control_get_role (control); - - if (role == MATE_MIXER_STREAM_CONTROL_ROLE_APPLICATION) - add_application_control (dialog, control); -} - -static void -on_stream_control_removed (MateMixerStream *stream, - const gchar *name, - GvcMixerDialog *dialog) -{ -} - -static void on_context_stream_added (MateMixerContext *context, const gchar *name, GvcMixerDialog *dialog) @@ -1076,16 +1139,6 @@ on_context_stream_added (MateMixerContext *context, return; add_stream (dialog, stream); - - // XXX broken in libmatemixer? - g_signal_connect (G_OBJECT (stream), - "control-added", - G_CALLBACK (on_stream_control_added), - dialog); - g_signal_connect (G_OBJECT (stream), - "control-removed", - G_CALLBACK (on_stream_control_removed), - dialog); } static void @@ -1127,10 +1180,15 @@ remove_application_control (GvcMixerDialog *dialog, const gchar *name) GtkWidget *bar; bar = g_hash_table_lookup (dialog->priv->bars, name); + if (G_UNLIKELY (bar == NULL)) + return; g_debug ("Removing application stream %s", name); + /* We could call bar_set_stream_control here, but that would pointlessly + * invalidate the channel bar, so just remove it ourselves */ g_hash_table_remove (dialog->priv->bars, name); + gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (bar)), bar); if (G_UNLIKELY (dialog->priv->num_apps <= 0)) { @@ -1138,7 +1196,9 @@ remove_application_control (GvcMixerDialog *dialog, const gchar *name) dialog->priv->num_apps = 1; } - if (--dialog->priv->num_apps == 0) + dialog->priv->num_apps--; + + if (dialog->priv->num_apps == 0) gtk_widget_show (dialog->priv->no_apps_label); } @@ -1779,6 +1839,11 @@ on_device_selection_changed (GtkTreeSelection *selection, GvcMixerDialog *dialog options, active_name); + g_object_set_data_full (G_OBJECT (dialog->priv->hw_profile_combo), + "device", + g_object_ref (device), + g_object_unref); + gtk_box_pack_start (GTK_BOX (dialog->priv->hw_settings_box), dialog->priv->hw_profile_combo, TRUE, TRUE, 6); |