[gnome-control-center/wip/laney/sound-volume-slider-set-mixer: 2/2] sound: Pass a GvcMixerControl to the stream volume sliders



commit 6310ea493d28482c7aab043a8196ebb2289d4993
Author: Iain Lane <iainl gnome org>
Date:   Mon Sep 2 15:38:10 2019 +0100

    sound: Pass a GvcMixerControl to the stream volume sliders
    
    Since 9d612ff1c7e2d58211e25e8584bc86c5d2598eac this is required,
    otherwise we never set up the GtkAdjustment and so the scales don't
    display any values or widget to make adjustments, meaning they can't be
    used.
    
    Also call `notify_volume_cb()` from `update_ranges()` to initialise the
    adjustment, since when we set the mixer control we now might not have
    set the value.
    
    Closes #652

 panels/sound/cc-stream-list-box.c | 14 ++++++++-
 panels/sound/cc-stream-row.c      | 19 +++++++++---
 panels/sound/cc-stream-row.h      | 17 +++++++----
 panels/sound/cc-volume-slider.c   | 62 +++++++++++++++++++++------------------
 4 files changed, 72 insertions(+), 40 deletions(-)
---
diff --git a/panels/sound/cc-stream-list-box.c b/panels/sound/cc-stream-list-box.c
index fcc249a25..113ad7158 100644
--- a/panels/sound/cc-stream-list-box.c
+++ b/panels/sound/cc-stream-list-box.c
@@ -99,7 +99,7 @@ stream_added_cb (CcStreamListBox *self,
       return;
     }
 
-  row = cc_stream_row_new (self->label_size_group, stream, id, self->stream_type);
+  row = cc_stream_row_new (self->label_size_group, stream, id, self->stream_type, self->mixer_control);
   gtk_widget_show (GTK_WIDGET (row));
   gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
   gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (row));
@@ -206,6 +206,16 @@ cc_stream_list_box_init (CcStreamListBox *self)
   gtk_list_box_set_sort_func (GTK_LIST_BOX (self), sort_cb, self, NULL);
 }
 
+static void
+update_mixer_control (GtkWidget *widget,
+                      gpointer   user_data)
+{
+    CcStreamRow *row = CC_STREAM_ROW (widget);
+    GvcMixerControl *mixer_control = GVC_MIXER_CONTROL (user_data);
+
+    cc_stream_row_set_mixer_control (row, mixer_control);
+}
+
 void
 cc_stream_list_box_set_mixer_control (CcStreamListBox *self,
                                       GvcMixerControl *mixer_control)
@@ -231,6 +241,8 @@ cc_stream_list_box_set_mixer_control (CcStreamListBox *self,
                                                              "stream-removed",
                                                              G_CALLBACK (stream_removed_cb),
                                                              self, G_CONNECT_SWAPPED);
+
+  gtk_container_foreach (GTK_CONTAINER (self), update_mixer_control, self->mixer_control);
 }
 
 void cc_stream_list_box_set_stream_type   (CcStreamListBox *self,
diff --git a/panels/sound/cc-stream-row.c b/panels/sound/cc-stream-row.c
index 31d6be79e..1f7bf7e3b 100644
--- a/panels/sound/cc-stream-row.c
+++ b/panels/sound/cc-stream-row.c
@@ -73,10 +73,11 @@ cc_stream_row_init (CcStreamRow *self)
 }
 
 CcStreamRow *
-cc_stream_row_new (GtkSizeGroup   *size_group,
-                   GvcMixerStream *stream,
-                   guint           id,
-                   CcStreamType    stream_type)
+cc_stream_row_new (GtkSizeGroup    *size_group,
+                   GvcMixerStream  *stream,
+                   guint            id,
+                   CcStreamType     stream_type,
+                   GvcMixerControl *mixer_control)
 {
   CcStreamRow *self;
   g_autoptr(GtkIconInfo) icon_info = NULL;
@@ -110,6 +111,7 @@ cc_stream_row_new (GtkSizeGroup   *size_group,
 
   gtk_label_set_label (self->name_label, gvc_mixer_stream_get_name (stream));
   cc_volume_slider_set_stream (self->volume_slider, stream, stream_type);
+  cc_volume_slider_set_mixer_control (self->volume_slider, mixer_control);
 
   gtk_size_group_add_widget (size_group, GTK_WIDGET (self->label_box));
 
@@ -129,3 +131,12 @@ cc_stream_row_get_id (CcStreamRow *self)
   g_return_val_if_fail (CC_IS_STREAM_ROW (self), 0);
   return self->id;
 }
+
+void
+cc_stream_row_set_mixer_control (CcStreamRow     *self,
+                                 GvcMixerControl *mixer_control)
+{
+  g_return_if_fail (CC_IS_STREAM_ROW (self));
+
+  cc_volume_slider_set_mixer_control (self->volume_slider, mixer_control);
+}
diff --git a/panels/sound/cc-stream-row.h b/panels/sound/cc-stream-row.h
index 3819eef18..5a502459d 100644
--- a/panels/sound/cc-stream-row.h
+++ b/panels/sound/cc-stream-row.h
@@ -20,6 +20,7 @@
 
 #include <gtk/gtk.h>
 #include <pulse/pulseaudio.h>
+#include <gvc-mixer-control.h>
 #include <gvc-mixer-stream.h>
 
 #include "cc-sound-enums.h"
@@ -29,13 +30,17 @@ G_BEGIN_DECLS
 #define CC_TYPE_STREAM_ROW (cc_stream_row_get_type ())
 G_DECLARE_FINAL_TYPE (CcStreamRow, cc_stream_row, CC, STREAM_ROW, GtkListBoxRow)
 
-CcStreamRow     *cc_stream_row_new       (GtkSizeGroup   *size_group,
-                                          GvcMixerStream *stream,
-                                          guint           id,
-                                          CcStreamType    stream_type);
+CcStreamRow     *cc_stream_row_new              (GtkSizeGroup    *size_group,
+                                                 GvcMixerStream  *stream,
+                                                 guint            id,
+                                                 CcStreamType     stream_type,
+                                                 GvcMixerControl *mixer_control);
 
-GvcMixerStream *cc_stream_row_get_stream (CcStreamRow    *row);
+GvcMixerStream *cc_stream_row_get_stream        (CcStreamRow    *row);
 
-guint           cc_stream_row_get_id     (CcStreamRow    *row);
+guint           cc_stream_row_get_id            (CcStreamRow    *row);
+
+void            cc_stream_row_set_mixer_control (CcStreamRow     *row,
+                                                 GvcMixerControl *mixer_control);
 
 G_END_DECLS
diff --git a/panels/sound/cc-volume-slider.c b/panels/sound/cc-volume-slider.c
index 7e061e540..0bed33a9e 100644
--- a/panels/sound/cc-volume-slider.c
+++ b/panels/sound/cc-volume-slider.c
@@ -43,6 +43,37 @@ struct _CcVolumeSlider
 
 G_DEFINE_TYPE (CcVolumeSlider, cc_volume_slider, GTK_TYPE_BOX)
 
+static void
+volume_changed_cb (CcVolumeSlider *self)
+{
+  gdouble volume, rounded;
+
+  if (self->stream == NULL)
+    return;
+
+  volume = gtk_adjustment_get_value (self->volume_adjustment);
+  rounded = round (volume);
+
+  gtk_toggle_button_set_active (self->mute_button, volume == 0.0);
+  if (gvc_mixer_stream_set_volume (self->stream,
+                                   (pa_volume_t) rounded))
+    {
+      gvc_mixer_stream_push_volume (self->stream);
+    }
+}
+
+static void
+notify_volume_cb (CcVolumeSlider *self)
+{
+  g_signal_handlers_block_by_func (self->volume_adjustment, volume_changed_cb, self);
+  if (gtk_toggle_button_get_active (self->mute_button)) {
+    gtk_adjustment_set_value (self->volume_adjustment, 0.0);
+  } else {
+    gtk_adjustment_set_value (self->volume_adjustment, gvc_mixer_stream_get_volume (self->stream));
+  }
+  g_signal_handlers_unblock_by_func (self->volume_adjustment, volume_changed_cb, self);
+}
+
 static void
 update_ranges (CcVolumeSlider *self)
 {
@@ -67,25 +98,9 @@ update_ranges (CcVolumeSlider *self)
       gtk_adjustment_set_upper (self->volume_adjustment, vol_max_norm);
     }
   gtk_adjustment_set_page_increment (self->volume_adjustment, vol_max_norm / 100.0);
-}
 
-static void
-volume_changed_cb (CcVolumeSlider *self)
-{
-  gdouble volume, rounded;
-
-  if (self->stream == NULL)
-    return;
-
-  volume = gtk_adjustment_get_value (self->volume_adjustment);
-  rounded = round (volume);
-
-  gtk_toggle_button_set_active (self->mute_button, volume == 0.0);
-  if (gvc_mixer_stream_set_volume (self->stream,
-                                   (pa_volume_t) rounded))
-    {
-      gvc_mixer_stream_push_volume (self->stream);
-    }
+  if (self->stream != NULL)
+    notify_volume_cb (self);
 }
 
 static void
@@ -97,17 +112,6 @@ mute_button_toggled_cb (CcVolumeSlider *self)
   gvc_mixer_stream_change_is_muted (self->stream, gtk_toggle_button_get_active (self->mute_button));
 }
 
-static void
-notify_volume_cb (CcVolumeSlider *self)
-{
-  g_signal_handlers_block_by_func (self->volume_adjustment, volume_changed_cb, self);
-  if (gtk_toggle_button_get_active (self->mute_button))
-    gtk_adjustment_set_value (self->volume_adjustment, 0.0);
-  else
-    gtk_adjustment_set_value (self->volume_adjustment, gvc_mixer_stream_get_volume (self->stream));
-  g_signal_handlers_unblock_by_func (self->volume_adjustment, volume_changed_cb, self);
-}
-
 static void
 notify_is_muted_cb (CcVolumeSlider *self)
 {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]