[gnome-control-center/wip/every-detail-matters-round1: 1/2] sounds: Use correct mute icon in the input section



commit f0b9725173b5954e5b7dc53ac82212b229bc8515
Author: Jordan Petridis <jpetridis gnome org>
Date:   Fri Jun 14 18:07:45 2019 +0300

    sounds: Use correct mute icon in the input section
    
    The current code does not differenciate between input and
    output, and thus it shows the same icon for muting outputs
    and inputs. As per design suggesion [1], the input row
    should use the "microphone-sensitivity-muted-symbolic" icon.
    
    In order to achieve that, move the CcLevelBarStreamType enum
    to a separate header, and rename it to CcStreamType. And also
    pass the stream type to the volume slider.
    
    In CcVolumeSlider, update the code to switch to the correct
    mute icon depending on the stream type.
    
    [1] https://gitlab.gnome.org/GNOME/gnome-control-center/issues/539
    
    Fixes https://gitlab.gnome.org/GNOME/gnome-control-center/issues/539

 panels/sound/cc-level-bar.c       | 13 +++++++------
 panels/sound/cc-level-bar.h       | 14 +++++---------
 panels/sound/cc-sound-enums.h     | 30 ++++++++++++++++++++++++++++++
 panels/sound/cc-sound-panel.c     |  8 ++++----
 panels/sound/cc-stream-list-box.c | 12 +++++++++++-
 panels/sound/cc-stream-list-box.h |  5 +++++
 panels/sound/cc-stream-row.c      |  6 ++++--
 panels/sound/cc-stream-row.h      |  5 ++++-
 panels/sound/cc-volume-slider.c   | 24 +++++++++++++++++++++++-
 panels/sound/cc-volume-slider.h   |  5 ++++-
 panels/sound/cc-volume-slider.ui  |  2 +-
 11 files changed, 98 insertions(+), 26 deletions(-)
---
diff --git a/panels/sound/cc-level-bar.c b/panels/sound/cc-level-bar.c
index ee351383c..a37ce2ea1 100644
--- a/panels/sound/cc-level-bar.c
+++ b/panels/sound/cc-level-bar.c
@@ -17,13 +17,14 @@
  */
 
 #include "cc-level-bar.h"
+#include "cc-sound-enums.h"
 #include "gvc-mixer-stream-private.h"
 
 struct _CcLevelBar
 {
   GtkWidget             parent_instance;
 
-  CcLevelBarStreamType  type;
+  CcStreamType          type;
   pa_stream            *level_stream;
   gdouble               last_input_peak;
 
@@ -139,10 +140,10 @@ cc_level_bar_draw (GtkWidget *widget,
   switch (self->type)
   {
   default:
-  case CC_LEVEL_BAR_STREAM_TYPE_OUTPUT:
+  case CC_STREAM_TYPE_OUTPUT:
     gdk_rgba_parse (&active_color, "#4a90d9");
     break;
-  case CC_LEVEL_BAR_STREAM_TYPE_INPUT:
+  case CC_STREAM_TYPE_INPUT:
     gdk_rgba_parse (&active_color, "#ff0000");
     break;
   }
@@ -214,9 +215,9 @@ cc_level_bar_init (CcLevelBar *self)
 }
 
 void
-cc_level_bar_set_stream (CcLevelBar          *self,
-                         GvcMixerStream      *stream,
-                         CcLevelBarStreamType type)
+cc_level_bar_set_stream (CcLevelBar     *self,
+                         GvcMixerStream *stream,
+                         CcStreamType    type)
 {
   pa_context *context;
   pa_sample_spec sample_spec;
diff --git a/panels/sound/cc-level-bar.h b/panels/sound/cc-level-bar.h
index d30a3ad69..34ef1ea60 100644
--- a/panels/sound/cc-level-bar.h
+++ b/panels/sound/cc-level-bar.h
@@ -22,19 +22,15 @@
 #include <pulse/pulseaudio.h>
 #include <gvc-mixer-stream.h>
 
+#include "cc-sound-enums.h"
+
 G_BEGIN_DECLS
 
 #define CC_TYPE_LEVEL_BAR (cc_level_bar_get_type ())
 G_DECLARE_FINAL_TYPE (CcLevelBar, cc_level_bar, CC, LEVEL_BAR, GtkWidget)
 
-typedef enum
-{
-  CC_LEVEL_BAR_STREAM_TYPE_OUTPUT,
-  CC_LEVEL_BAR_STREAM_TYPE_INPUT
-} CcLevelBarStreamType;
-
-void cc_level_bar_set_stream (CcLevelBar          *bar,
-                              GvcMixerStream      *stream,
-                              CcLevelBarStreamType type);
+void cc_level_bar_set_stream (CcLevelBar     *bar,
+                              GvcMixerStream *stream,
+                              CcStreamType    type);
 
 G_END_DECLS
diff --git a/panels/sound/cc-sound-enums.h b/panels/sound/cc-sound-enums.h
new file mode 100644
index 000000000..bf29d274a
--- /dev/null
+++ b/panels/sound/cc-sound-enums.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2019 Jordan Petridis <jpetridis gnome org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef enum
+{
+  CC_STREAM_TYPE_OUTPUT,
+  CC_STREAM_TYPE_INPUT,
+} CcStreamType;
+
+G_END_DECLS
diff --git a/panels/sound/cc-sound-panel.c b/panels/sound/cc-sound-panel.c
index 072f49124..672b2b1ab 100644
--- a/panels/sound/cc-sound-panel.c
+++ b/panels/sound/cc-sound-panel.c
@@ -107,8 +107,8 @@ output_device_changed_cb (CcSoundPanel *self)
   if (device != NULL)
     stream = gvc_mixer_control_get_stream_from_device (self->mixer_control, device);
 
-  cc_volume_slider_set_stream (self->output_volume_slider, stream);
-  cc_level_bar_set_stream (self->output_level_bar, stream, CC_LEVEL_BAR_STREAM_TYPE_OUTPUT);
+  cc_volume_slider_set_stream (self->output_volume_slider, stream, CC_STREAM_TYPE_OUTPUT);
+  cc_level_bar_set_stream (self->output_level_bar, stream, CC_STREAM_TYPE_OUTPUT);
 
   if (stream != NULL)
     {
@@ -141,8 +141,8 @@ input_device_changed_cb (CcSoundPanel *self)
   if (device != NULL)
     stream = gvc_mixer_control_get_stream_from_device (self->mixer_control, device);
 
-  cc_volume_slider_set_stream (self->input_volume_slider, stream);
-  cc_level_bar_set_stream (self->input_level_bar, stream, CC_LEVEL_BAR_STREAM_TYPE_INPUT);
+  cc_volume_slider_set_stream (self->input_volume_slider, stream, CC_STREAM_TYPE_INPUT);
+  cc_level_bar_set_stream (self->input_level_bar, stream, CC_STREAM_TYPE_INPUT);
 
   if (device != NULL)
     gvc_mixer_control_change_input (self->mixer_control, device);
diff --git a/panels/sound/cc-stream-list-box.c b/panels/sound/cc-stream-list-box.c
index f11442ba2..fcc249a25 100644
--- a/panels/sound/cc-stream-list-box.c
+++ b/panels/sound/cc-stream-list-box.c
@@ -22,6 +22,7 @@
 
 #include "cc-stream-list-box.h"
 #include "cc-stream-row.h"
+#include "cc-sound-enums.h"
 
 struct _CcStreamListBox
 {
@@ -29,6 +30,7 @@ struct _CcStreamListBox
 
   GtkSizeGroup    *label_size_group;
   GvcMixerControl *mixer_control;
+  CcStreamType     stream_type;
   guint            stream_added_handler_id;
   guint            stream_removed_handler_id;
 };
@@ -97,7 +99,7 @@ stream_added_cb (CcStreamListBox *self,
       return;
     }
 
-  row = cc_stream_row_new (self->label_size_group, stream, id);
+  row = cc_stream_row_new (self->label_size_group, stream, id, self->stream_type);
   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));
@@ -230,3 +232,11 @@ cc_stream_list_box_set_mixer_control (CcStreamListBox *self,
                                                              G_CALLBACK (stream_removed_cb),
                                                              self, G_CONNECT_SWAPPED);
 }
+
+void cc_stream_list_box_set_stream_type   (CcStreamListBox *self,
+                                           CcStreamType     stream_type)
+{
+  g_return_if_fail (CC_IS_STREAM_LIST_BOX (self));
+
+  self->stream_type = stream_type;
+}
diff --git a/panels/sound/cc-stream-list-box.h b/panels/sound/cc-stream-list-box.h
index 374ecaf55..8a46fd7c9 100644
--- a/panels/sound/cc-stream-list-box.h
+++ b/panels/sound/cc-stream-list-box.h
@@ -22,6 +22,8 @@
 #include <pulse/pulseaudio.h>
 #include <gvc-mixer-control.h>
 
+#include "cc-sound-enums.h"
+
 G_BEGIN_DECLS
 
 #define CC_TYPE_STREAM_LIST_BOX (cc_stream_list_box_get_type ())
@@ -30,4 +32,7 @@ G_DECLARE_FINAL_TYPE (CcStreamListBox, cc_stream_list_box, CC, STREAM_LIST_BOX,
 void cc_stream_list_box_set_mixer_control (CcStreamListBox *combo_box,
                                            GvcMixerControl *mixer_control);
 
+void cc_stream_list_box_set_stream_type   (CcStreamListBox *combo_box,
+                                           CcStreamType     type);
+
 G_END_DECLS
diff --git a/panels/sound/cc-stream-row.c b/panels/sound/cc-stream-row.c
index 62bac6943..31d6be79e 100644
--- a/panels/sound/cc-stream-row.c
+++ b/panels/sound/cc-stream-row.c
@@ -19,6 +19,7 @@
 #include "cc-sound-resources.h"
 #include "cc-stream-row.h"
 #include "cc-volume-slider.h"
+#include "cc-sound-enums.h"
 
 #define SPEECH_DISPATCHER_PREFIX "speech-dispatcher-"
 
@@ -74,7 +75,8 @@ cc_stream_row_init (CcStreamRow *self)
 CcStreamRow *
 cc_stream_row_new (GtkSizeGroup   *size_group,
                    GvcMixerStream *stream,
-                   guint           id)
+                   guint           id,
+                   CcStreamType    stream_type)
 {
   CcStreamRow *self;
   g_autoptr(GtkIconInfo) icon_info = NULL;
@@ -107,7 +109,7 @@ cc_stream_row_new (GtkSizeGroup   *size_group,
   gtk_image_set_from_gicon (self->icon_image, gicon, GTK_ICON_SIZE_LARGE_TOOLBAR);
 
   gtk_label_set_label (self->name_label, gvc_mixer_stream_get_name (stream));
-  cc_volume_slider_set_stream (self->volume_slider, stream);
+  cc_volume_slider_set_stream (self->volume_slider, stream, stream_type);
 
   gtk_size_group_add_widget (size_group, GTK_WIDGET (self->label_box));
 
diff --git a/panels/sound/cc-stream-row.h b/panels/sound/cc-stream-row.h
index 9d9440e58..3819eef18 100644
--- a/panels/sound/cc-stream-row.h
+++ b/panels/sound/cc-stream-row.h
@@ -22,6 +22,8 @@
 #include <pulse/pulseaudio.h>
 #include <gvc-mixer-stream.h>
 
+#include "cc-sound-enums.h"
+
 G_BEGIN_DECLS
 
 #define CC_TYPE_STREAM_ROW (cc_stream_row_get_type ())
@@ -29,7 +31,8 @@ G_DECLARE_FINAL_TYPE (CcStreamRow, cc_stream_row, CC, STREAM_ROW, GtkListBoxRow)
 
 CcStreamRow     *cc_stream_row_new       (GtkSizeGroup   *size_group,
                                           GvcMixerStream *stream,
-                                          guint           id);
+                                          guint           id,
+                                          CcStreamType    stream_type);
 
 GvcMixerStream *cc_stream_row_get_stream (CcStreamRow    *row);
 
diff --git a/panels/sound/cc-volume-slider.c b/panels/sound/cc-volume-slider.c
index 8f58f656b..ca2f70b90 100644
--- a/panels/sound/cc-volume-slider.c
+++ b/panels/sound/cc-volume-slider.c
@@ -30,6 +30,7 @@ struct _CcVolumeSlider
   GtkBox           parent_instance;
 
   GtkToggleButton *mute_button;
+  GtkImage        *stream_type_icon;
   GtkAdjustment   *volume_adjustment;
   GtkScale        *volume_scale;
 
@@ -109,6 +110,7 @@ cc_volume_slider_class_init (CcVolumeSliderClass *klass)
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/control-center/sound/cc-volume-slider.ui");
 
   gtk_widget_class_bind_template_child (widget_class, CcVolumeSlider, mute_button);
+  gtk_widget_class_bind_template_child (widget_class, CcVolumeSlider, stream_type_icon);
   gtk_widget_class_bind_template_child (widget_class, CcVolumeSlider, volume_adjustment);
   gtk_widget_class_bind_template_child (widget_class, CcVolumeSlider, volume_scale);
 
@@ -132,7 +134,8 @@ cc_volume_slider_init (CcVolumeSlider *self)
 
 void
 cc_volume_slider_set_stream (CcVolumeSlider *self,
-                             GvcMixerStream *stream)
+                             GvcMixerStream *stream,
+                             CcStreamType    type)
 {
   g_return_if_fail (CC_IS_VOLUME_SLIDER (self));
 
@@ -145,6 +148,25 @@ cc_volume_slider_set_stream (CcVolumeSlider *self,
     }
   g_clear_object (&self->stream);
 
+  switch (type)
+    {
+    case CC_STREAM_TYPE_INPUT:
+      gtk_image_set_from_icon_name (self->stream_type_icon,
+                                    "microphone-sensitivity-muted-symbolic",
+                                    GTK_ICON_SIZE_BUTTON);
+      break;
+
+    case CC_STREAM_TYPE_OUTPUT:
+      gtk_image_set_from_icon_name (self->stream_type_icon,
+                                    "audio-volume-muted-symbolic",
+                                    GTK_ICON_SIZE_BUTTON);
+      break;
+
+    default:
+      g_assert_not_reached ();
+      break;
+    }
+
   if (stream != NULL)
     {
       self->stream = g_object_ref (stream);
diff --git a/panels/sound/cc-volume-slider.h b/panels/sound/cc-volume-slider.h
index 079354d66..68b5dc1d2 100644
--- a/panels/sound/cc-volume-slider.h
+++ b/panels/sound/cc-volume-slider.h
@@ -22,13 +22,16 @@
 #include <pulse/pulseaudio.h>
 #include <gvc-mixer-stream.h>
 
+#include "cc-sound-enums.h"
+
 G_BEGIN_DECLS
 
 #define CC_TYPE_VOLUME_SLIDER (cc_volume_slider_get_type ())
 G_DECLARE_FINAL_TYPE (CcVolumeSlider, cc_volume_slider, CC, VOLUME_SLIDER, GtkBox)
 
 void cc_volume_slider_set_stream       (CcVolumeSlider *slider,
-                                        GvcMixerStream *stream);
+                                        GvcMixerStream *stream,
+                                        CcStreamType    type);
 
 void cc_volume_slider_set_is_amplified (CcVolumeSlider *slider,
                                         gboolean        is_amplified);
diff --git a/panels/sound/cc-volume-slider.ui b/panels/sound/cc-volume-slider.ui
index 7ab849caf..4fb054027 100644
--- a/panels/sound/cc-volume-slider.ui
+++ b/panels/sound/cc-volume-slider.ui
@@ -17,7 +17,7 @@
         <property name="relief">none</property>
         <signal name="toggled" handler="mute_button_toggled_cb" object="CcVolumeSlider" swapped="yes"/>
         <child>
-          <object class="GtkImage">
+          <object class="GtkImage" id="stream_type_icon">
             <property name="visible">True</property>
             <property name="icon_name">audio-volume-muted-symbolic</property>
           </object>


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