[gnome-control-center/gbsneto/gtk4: 24/53] sound: Port to GTK4




commit a719008403bda190cfed22937e190195d5fce564
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Oct 20 00:24:41 2021 -0300

    sound: Port to GTK4

 panels/meson.build                     |   2 +-
 panels/sound/cc-level-bar.c            |  70 +++++++++++---------
 panels/sound/cc-output-test-dialog.c   |   4 +-
 panels/sound/cc-output-test-dialog.ui  | 114 +++++++++++++++++----------------
 panels/sound/cc-sound-panel.c          |  11 ++--
 panels/sound/cc-sound-panel.ui         | 108 +++++++++++--------------------
 panels/sound/cc-speaker-test-button.c  |   4 +-
 panels/sound/cc-speaker-test-button.ui |   6 +-
 panels/sound/cc-stream-list-box.c      |  44 +++++++------
 panels/sound/cc-stream-list-box.h      |   2 +-
 panels/sound/cc-stream-list-box.ui     |  15 +++++
 panels/sound/cc-stream-row.c           |  19 +++---
 panels/sound/cc-stream-row.ui          |  13 ++--
 panels/sound/cc-volume-slider.c        |   8 +--
 panels/sound/cc-volume-slider.ui       |   4 +-
 panels/sound/sound.gresource.xml       |   1 +
 shell/cc-panel-loader.c                |   4 +-
 17 files changed, 218 insertions(+), 211 deletions(-)
---
diff --git a/panels/meson.build b/panels/meson.build
index e25f7a549..741bec97e 100644
--- a/panels/meson.build
+++ b/panels/meson.build
@@ -24,7 +24,7 @@ panels = [
 #  'removable-media',
 #  'search',
 #  'sharing',
-#  'sound',
+  'sound',
 #  'universal-access',
 #  'usage',
 #  'user-accounts',
diff --git a/panels/sound/cc-level-bar.c b/panels/sound/cc-level-bar.c
index 8d8b2c9c9..afecff53e 100644
--- a/panels/sound/cc-level-bar.c
+++ b/panels/sound/cc-level-bar.c
@@ -103,37 +103,42 @@ suspended_cb (pa_stream *stream,
 }
 
 static void
-cc_level_bar_get_preferred_height (GtkWidget *widget,
-                                   gint      *minimum,
-                                   gint      *natural)
+cc_level_bar_measure (GtkWidget      *widget,
+                      GtkOrientation  orientation,
+                      int             for_size,
+                      int            *minimum,
+                      int            *natural,
+                      int            *minimum_baseline,
+                      int            *natural_baseline)
 {
-  *minimum = *natural = LED_HEIGHT;
+  if (orientation == GTK_ORIENTATION_VERTICAL)
+    {
+      *minimum = *natural = LED_HEIGHT;
+    }
+  else
+    {
+      GTK_WIDGET_CLASS (cc_level_bar_parent_class)->measure (widget,
+                                                             orientation,
+                                                             for_size,
+                                                             minimum,
+                                                             natural,
+                                                             minimum_baseline,
+                                                             natural_baseline);
+    }
 }
 
 static void
-set_source_blend (cairo_t *cr, GdkRGBA *a, GdkRGBA *b, gdouble f)
-{
-  cairo_set_source_rgb (cr,
-                        (1.0 - f) * a->red   + f * b->red,
-                        (1.0 - f) * a->green + f * b->green,
-                        (1.0 - f) * a->blue  + f * b->blue);
-}
-
-static gboolean
-cc_level_bar_draw (GtkWidget *widget,
-                   cairo_t   *cr)
+cc_level_bar_snapshot (GtkWidget   *widget,
+                       GtkSnapshot *snapshot)
 {
   CcLevelBar *self = CC_LEVEL_BAR (widget);
-  GtkAllocation allocation;
   GdkRGBA inactive_color, active_color;
   int i, n_leds;
   double level;
   double spacing, x_offset = 0.0;
 
-  gtk_widget_get_allocation (widget, &allocation);
-
-  n_leds = allocation.width / (LED_WIDTH + LED_SPACING);
-  spacing = (double) (allocation.width - (n_leds * LED_WIDTH)) / (n_leds - 1);
+  n_leds = gtk_widget_get_width (widget) / (LED_WIDTH + LED_SPACING);
+  spacing = (double) (gtk_widget_get_width (widget) - (n_leds * LED_WIDTH)) / (n_leds - 1);
   level = self->value * n_leds;
 
   gdk_rgba_parse (&inactive_color, "#C0C0C0");
@@ -150,6 +155,7 @@ cc_level_bar_draw (GtkWidget *widget,
 
   for (i = 0; i < n_leds; i++)
   {
+    GdkRGBA blended_color;
     double led_level;
 
     led_level = level - i;
@@ -158,15 +164,20 @@ cc_level_bar_draw (GtkWidget *widget,
     else if (led_level > 1.0)
       led_level = 1.0;
 
-    cairo_rectangle (cr,
-                     x_offset, 0,
-                     LED_WIDTH, allocation.height);
-    set_source_blend (cr, &inactive_color, &active_color, led_level);
-    cairo_fill (cr);
+    blended_color = (GdkRGBA) {
+      .red = (1.0 - led_level) * inactive_color.red + led_level * active_color.red,
+      .green = (1.0 - led_level) * inactive_color.green + led_level * active_color.green,
+      .blue = (1.0 - led_level) * inactive_color.blue + led_level * active_color.blue,
+      .alpha = 1.0,
+    };
+
+    gtk_snapshot_append_color (snapshot,
+                               &blended_color,
+                               &GRAPHENE_RECT_INIT (x_offset, 0,
+                                                    LED_WIDTH,
+                                                    gtk_widget_get_height (widget)));
     x_offset += LED_WIDTH + spacing;
   }
-
-  return FALSE;
 }
 
 static void
@@ -202,14 +213,13 @@ cc_level_bar_class_init (CcLevelBarClass *klass)
 
   object_class->dispose = cc_level_bar_dispose;
 
-  widget_class->get_preferred_height = cc_level_bar_get_preferred_height;
-  widget_class->draw = cc_level_bar_draw;
+  widget_class->measure = cc_level_bar_measure;
+  widget_class->snapshot = cc_level_bar_snapshot;
 }
 
 void
 cc_level_bar_init (CcLevelBar *self)
 {
-  gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
 }
 
 void
diff --git a/panels/sound/cc-output-test-dialog.c b/panels/sound/cc-output-test-dialog.c
index 67c0a2795..b8a518e39 100644
--- a/panels/sound/cc-output-test-dialog.c
+++ b/panels/sound/cc-output-test-dialog.c
@@ -96,7 +96,7 @@ cc_output_test_dialog_init (CcOutputTestDialog *self)
   gsound_context_set_attributes (self->context, NULL,
                                  GSOUND_ATTR_APPLICATION_ID, "org.gnome.VolumeControl",
                                  NULL);
-  settings = gtk_settings_get_for_screen (gdk_screen_get_default ());
+  settings = gtk_settings_get_for_display (gdk_display_get_default ());
   g_object_get (G_OBJECT (settings),
                 "gtk-sound-theme-name", &theme_name,
                 NULL);
@@ -132,7 +132,7 @@ cc_output_test_dialog_new (GvcMixerUIDevice *device,
   self->device = g_object_ref (device);
 
   title = g_strdup_printf (_("Testing %s"), gvc_mixer_ui_device_get_description (device));
-  gtk_header_bar_set_title (GTK_HEADER_BAR (gtk_dialog_get_header_bar (GTK_DIALOG (self))), title);
+  gtk_window_set_title (GTK_WINDOW (self), title);
 
   map = gvc_mixer_stream_get_channel_map (stream);
   gtk_widget_set_visible (GTK_WIDGET (self->front_left_speaker_button), gvc_channel_map_has_position (map, 
PA_CHANNEL_POSITION_FRONT_LEFT));
diff --git a/panels/sound/cc-output-test-dialog.ui b/panels/sound/cc-output-test-dialog.ui
index 8d84e275e..7ec5b7be9 100644
--- a/panels/sound/cc-output-test-dialog.ui
+++ b/panels/sound/cc-output-test-dialog.ui
@@ -2,124 +2,128 @@
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
   <template class="CcOutputTestDialog" parent="GtkDialog">
+    <property name="modal">True</property>
     <property name="resizable">False</property>
-    <child internal-child="vbox">
+    <child>
       <object class="GtkBox">
         <child>
           <object class="GtkGrid">
             <property name="visible">True</property>
             <property name="row_spacing">30</property>
             <property name="column_spacing">30</property>
-            <property name="margin">30</property>
+            <property name="margin-top">30</property>
+            <property name="margin-bottom">30</property>
+            <property name="margin-start">30</property>
+            <property name="margin-end">30</property>
             <child>
               <object class="CcSpeakerTestButton" id="front_left_speaker_button">
                 <property name="visible">True</property>
+                <layout>
+                  <property name="column">0</property>
+                  <property name="row">0</property>
+                </layout>
               </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">0</property>
-              </packing>
             </child>
             <child>
               <object class="CcSpeakerTestButton" id="front_left_of_center_speaker_button">
                 <property name="visible">True</property>
+                <layout>
+                  <property name="column">1</property>
+                  <property name="row">0</property>
+                </layout>
               </object>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="top_attach">0</property>
-              </packing>
             </child>
             <child>
               <object class="CcSpeakerTestButton" id="front_center_speaker_button">
                 <property name="visible">True</property>
+                <layout>
+                  <property name="column">2</property>
+                  <property name="row">0</property>
+                </layout>
               </object>
-              <packing>
-                <property name="left_attach">2</property>
-                <property name="top_attach">0</property>
-              </packing>
             </child>
             <child>
               <object class="CcSpeakerTestButton" id="front_right_of_center_speaker_button">
                 <property name="visible">True</property>
+                <layout>
+                  <property name="column">3</property>
+                  <property name="row">0</property>
+                </layout>
               </object>
-              <packing>
-                <property name="left_attach">3</property>
-                <property name="top_attach">0</property>
-              </packing>
             </child>
             <child>
               <object class="CcSpeakerTestButton" id="front_right_speaker_button">
                 <property name="visible">True</property>
+                <layout>
+                  <property name="column">4</property>
+                  <property name="row">0</property>
+                </layout>
               </object>
-              <packing>
-                <property name="left_attach">4</property>
-                <property name="top_attach">0</property>
-              </packing>
             </child>
             <child>
               <object class="CcSpeakerTestButton" id="side_left_speaker_button">
                 <property name="visible">True</property>
+                <layout>
+                  <property name="column">0</property>
+                  <property name="row">1</property>
+                </layout>
               </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">1</property>
-              </packing>
             </child>
             <child>
               <object class="GtkImage">
                 <property name="visible">True</property>
                 <property name="icon_name">avatar-default-symbolic</property>
                 <property name="pixel_size">64</property>
+                <layout>
+                  <property name="column">2</property>
+                  <property name="row">1</property>
+                </layout>
               </object>
-              <packing>
-                <property name="left_attach">2</property>
-                <property name="top_attach">1</property>
-              </packing>
             </child>
             <child>
               <object class="CcSpeakerTestButton" id="side_right_speaker_button">
                 <property name="visible">True</property>
+                <layout>
+                  <property name="column">4</property>
+                  <property name="row">1</property>
+                </layout>
               </object>
-              <packing>
-                <property name="left_attach">4</property>
-                <property name="top_attach">1</property>
-              </packing>
             </child>
             <child>
               <object class="CcSpeakerTestButton" id="rear_left_speaker_button">
                 <property name="visible">True</property>
+                <layout>
+                  <property name="column">0</property>
+                  <property name="row">2</property>
+                </layout>
               </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">2</property>
-              </packing>
             </child>
             <child>
               <object class="CcSpeakerTestButton" id="rear_center_speaker_button">
                 <property name="visible">True</property>
+                <layout>
+                  <property name="column">2</property>
+                  <property name="row">2</property>
+                </layout>
               </object>
-              <packing>
-                <property name="left_attach">2</property>
-                <property name="top_attach">2</property>
-              </packing>
             </child>
             <child>
               <object class="CcSpeakerTestButton" id="lfe_speaker_button">
                 <property name="visible">True</property>
+                <layout>
+                  <property name="column">3</property>
+                  <property name="row">2</property>
+                </layout>
               </object>
-              <packing>
-                <property name="left_attach">3</property>
-                <property name="top_attach">2</property>
-              </packing>
             </child>
             <child>
               <object class="CcSpeakerTestButton" id="rear_right_speaker_button">
                 <property name="visible">True</property>
+                <layout>
+                  <property name="column">4</property>
+                  <property name="row">2</property>
+                </layout>
               </object>
-              <packing>
-                <property name="left_attach">4</property>
-                <property name="top_attach">2</property>
-              </packing>
             </child>
             <child>
               <object class="GtkLabel">
@@ -128,12 +132,12 @@
                 <style>
                   <class name="dim-label"/>
                 </style>
+                <layout>
+                  <property name="column">0</property>
+                  <property name="row">3</property>
+                  <property name="column-span">5</property>
+                </layout>
               </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">3</property>
-                <property name="width">5</property>
-              </packing>
             </child>
           </object>
         </child>
diff --git a/panels/sound/cc-sound-panel.c b/panels/sound/cc-sound-panel.c
index 5e6e03d01..0de1ca9f2 100644
--- a/panels/sound/cc-sound-panel.c
+++ b/panels/sound/cc-sound-panel.c
@@ -30,7 +30,6 @@
 #include <pulse/pulseaudio.h>
 #include <gvc-mixer-control.h>
 
-#include "list-box-helper.h"
 #include "cc-alert-chooser.h"
 #include "cc-balance-slider.h"
 #include "cc-device-combo-box.h"
@@ -202,15 +201,19 @@ test_output_configuration_button_clicked_cb (CcSoundPanel *self)
   GvcMixerUIDevice *device;
   GvcMixerStream *stream = NULL;
   CcOutputTestDialog *dialog;
+  GtkWidget *toplevel;
+  CcShell *shell;
 
   device = cc_device_combo_box_get_device (self->output_device_combo_box);
   if (device != NULL)
     stream = gvc_mixer_control_get_stream_from_device (self->mixer_control, device);
 
+  shell = cc_panel_get_shell (CC_PANEL (self));
+  toplevel = cc_shell_get_toplevel (shell);
+
   dialog = cc_output_test_dialog_new (device, stream);
-  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET 
(self))));
-  gtk_dialog_run (GTK_DIALOG (dialog));
-  gtk_widget_destroy (GTK_WIDGET (dialog));
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel));
+  gtk_window_present (GTK_WINDOW (dialog));
 }
 
 static const char *
diff --git a/panels/sound/cc-sound-panel.ui b/panels/sound/cc-sound-panel.ui
index b5706e28b..3249fb8ce 100644
--- a/panels/sound/cc-sound-panel.ui
+++ b/panels/sound/cc-sound-panel.ui
@@ -2,27 +2,22 @@
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
   <template class="CcSoundPanel" parent="CcPanel">
-    <property name="visible">True</property>
     <child>
       <object class="GtkScrolledWindow">
-        <property name="visible">True</property>
         <property name="hscrollbar_policy">never</property>
         <child>
-          <object class="HdyClamp">
-            <property name="visible">True</property>
+          <object class="AdwClamp">
             <property name="margin_top">32</property>
             <property name="margin_bottom">32</property>
             <property name="margin_start">12</property>
             <property name="margin_end">12</property>
             <child>
               <object class="GtkBox">
-                <property name="visible">True</property>
                 <property name="orientation">vertical</property>
                 <property name="spacing">12</property>
                 <property name="hexpand">True</property>
                 <child>
                   <object class="GtkLabel">
-                    <property name="visible">True</property>
                     <property name="xalign">0</property>
                     <property name="label" translatable="yes">System Volume</property>
                     <attributes>
@@ -31,13 +26,10 @@
                   </object>
                 </child>
                 <child>
-                  <object class="CcVolumeSlider" id="output_volume_slider">
-                    <property name="visible">True</property>
-                  </object>
+                  <object class="CcVolumeSlider" id="output_volume_slider" />
                 </child>
                 <child>
                   <object class="GtkLabel">
-                    <property name="visible">True</property>
                     <property name="xalign">0</property>
                     <property name="margin-top">18</property>
                     <property name="label" translatable="yes">Volume Levels</property>
@@ -48,16 +40,11 @@
                 </child>
                 <child>
                   <object class="CcStreamListBox" id="stream_list_box">
-                    <property name="visible">True</property>
                     <property name="label-size-group">label_size_group</property>
-                    <style>
-                      <class name="content"/>
-                    </style>
                   </object>
                 </child>
                 <child>
                   <object class="GtkLabel">
-                    <property name="visible">True</property>
                     <property name="xalign">0</property>
                     <property name="margin-top">18</property>
                     <property name="label" translatable="yes">Output</property>
@@ -68,23 +55,22 @@
                 </child>
                 <child>
                   <object class="GtkListBox" id="output_list_box">
-                    <property name="visible">True</property>
                     <property name="selection_mode">none</property>
                     <style>
                       <class name="content"/>
                     </style>
                     <child>
                       <object class="GtkListBoxRow">
-                        <property name="visible">True</property>
                         <property name="activatable">False</property>
                         <child>
                           <object class="GtkBox">
-                            <property name="visible">True</property>
-                            <property name="margin">12</property>
+                            <property name="margin-top">12</property>
+                            <property name="margin-bottom">12</property>
+                            <property name="margin-start">12</property>
+                            <property name="margin-end">12</property>
                             <property name="spacing">12</property>
                             <child>
                               <object class="GtkLabel" id="output_device_label">
-                                <property name="visible">True</property>
                                 <property name="ellipsize">end</property>
                                 <property name="xalign">0</property>
                                 <property name="label" translatable="yes">Output Device</property>
@@ -92,24 +78,20 @@
                             </child>
                             <child>
                               <object class="GtkBox">
-                                <property name="visible">True</property>
                                 <property name="orientation">vertical</property>
                                 <property name="hexpand">True</property>
                                 <property name="spacing">9</property>
                                 <child>
                                   <object class="GtkBox">
-                                    <property name="visible">True</property>
                                     <property name="spacing">6</property>
                                     <child>
                                       <object class="CcDeviceComboBox" id="output_device_combo_box">
-                                        <property name="visible">True</property>
                                         <property name="hexpand">True</property>
                                         <signal name="changed" handler="output_device_changed_cb" 
object="CcSoundPanel" swapped="yes"/>
                                       </object>
                                     </child>
                                     <child>
                                       <object class="GtkButton">
-                                        <property name="visible">True</property>
                                         <property name="label" translatable="yes">Test</property>
                                         <signal name="clicked" 
handler="test_output_configuration_button_clicked_cb" object="CcSoundPanel" swapped="yes"/>
                                       </object>
@@ -117,9 +99,7 @@
                                   </object>
                                 </child>
                                 <child>
-                                  <object class="CcLevelBar" id="output_level_bar">
-                                    <property name="visible">True</property>
-                                  </object>
+                                  <object class="CcLevelBar" id="output_level_bar" />
                                 </child>
                               </object>
                             </child>
@@ -129,16 +109,16 @@
                     </child>
                     <child>
                       <object class="GtkListBoxRow" id="output_profile_row">
-                        <property name="visible">True</property>
                         <property name="activatable">False</property>
                         <child>
                           <object class="GtkBox">
-                            <property name="visible">True</property>
-                            <property name="margin">12</property>
+                            <property name="margin-top">12</property>
+                            <property name="margin-bottom">12</property>
+                            <property name="margin-start">12</property>
+                            <property name="margin-end">12</property>
                             <property name="spacing">12</property>
                             <child>
                               <object class="GtkLabel" id="output_configuration_label">
-                                <property name="visible">True</property>
                                 <property name="ellipsize">end</property>
                                 <property name="xalign">0</property>
                                 <property name="label" translatable="yes">Configuration</property>
@@ -146,11 +126,9 @@
                             </child>
                             <child>
                               <object class="GtkBox">
-                                <property name="visible">True</property>
                                 <property name="spacing">6</property>
                                 <child>
                                   <object class="CcProfileComboBox" id="output_profile_combo_box">
-                                    <property name="visible">True</property>
                                     <property name="hexpand">True</property>
                                   </object>
                                 </child>
@@ -162,16 +140,16 @@
                     </child>
                     <child>
                       <object class="GtkListBoxRow">
-                        <property name="visible">True</property>
                         <property name="activatable">False</property>
                         <child>
                           <object class="GtkBox">
-                            <property name="visible">True</property>
-                            <property name="margin">12</property>
+                            <property name="margin-top">12</property>
+                            <property name="margin-bottom">12</property>
+                            <property name="margin-start">12</property>
+                            <property name="margin-end">12</property>
                             <property name="spacing">12</property>
                             <child>
                               <object class="GtkLabel" id="output_balance_label">
-                                <property name="visible">True</property>
                                 <property name="ellipsize">end</property>
                                 <property name="xalign">0</property>
                                 <property name="label" translatable="yes">Balance</property>
@@ -179,7 +157,6 @@
                             </child>
                             <child>
                               <object class="CcBalanceSlider" id="balance_slider">
-                                <property name="visible">True</property>
                                 <property name="hexpand">True</property>
                               </object>
                             </child>
@@ -189,16 +166,16 @@
                     </child>
                     <child>
                       <object class="GtkListBoxRow" id="fade_row">
-                        <property name="visible">True</property>
                         <property name="activatable">False</property>
                         <child>
                           <object class="GtkBox">
-                            <property name="visible">True</property>
-                            <property name="margin">12</property>
+                            <property name="margin-top">12</property>
+                            <property name="margin-bottom">12</property>
+                            <property name="margin-start">12</property>
+                            <property name="margin-end">12</property>
                             <property name="spacing">12</property>
                             <child>
                               <object class="GtkLabel" id="output_fade_label">
-                                <property name="visible">True</property>
                                 <property name="ellipsize">end</property>
                                 <property name="xalign">0</property>
                                 <property name="label" translatable="yes">Fade</property>
@@ -206,7 +183,6 @@
                             </child>
                             <child>
                               <object class="CcFadeSlider" id="fade_slider">
-                                <property name="visible">True</property>
                                 <property name="hexpand">True</property>
                               </object>
                             </child>
@@ -216,16 +192,16 @@
                     </child>
                     <child>
                       <object class="GtkListBoxRow" id="subwoofer_row">
-                        <property name="visible">True</property>
                         <property name="activatable">False</property>
                         <child>
                           <object class="GtkBox">
-                            <property name="visible">True</property>
-                            <property name="margin">12</property>
+                            <property name="margin-top">12</property>
+                            <property name="margin-bottom">12</property>
+                            <property name="margin-start">12</property>
+                            <property name="margin-end">12</property>
                             <property name="spacing">12</property>
                             <child>
                               <object class="GtkLabel" id="output_subwoofer_label">
-                                <property name="visible">True</property>
                                 <property name="ellipsize">end</property>
                                 <property name="xalign">0</property>
                                 <property name="label" translatable="yes">Subwoofer</property>
@@ -233,7 +209,6 @@
                             </child>
                             <child>
                               <object class="CcSubwooferSlider" id="subwoofer_slider">
-                                <property name="visible">True</property>
                                 <property name="hexpand">True</property>
                               </object>
                             </child>
@@ -245,7 +220,6 @@
                 </child>
                 <child>
                   <object class="GtkLabel">
-                    <property name="visible">True</property>
                     <property name="xalign">0</property>
                     <property name="margin-top">18</property>
                     <property name="label" translatable="yes">Input</property>
@@ -256,23 +230,22 @@
                 </child>
                 <child>
                   <object class="GtkListBox" id="input_list_box">
-                    <property name="visible">True</property>
                     <property name="selection_mode">none</property>
                     <style>
                       <class name="content"/>
                     </style>
                     <child>
                       <object class="GtkListBoxRow">
-                        <property name="visible">True</property>
                         <property name="activatable">False</property>
                         <child>
                           <object class="GtkBox">
-                            <property name="visible">True</property>
-                            <property name="margin">12</property>
+                            <property name="margin-top">12</property>
+                            <property name="margin-bottom">12</property>
+                            <property name="margin-start">12</property>
+                            <property name="margin-end">12</property>
                             <property name="spacing">12</property>
                             <child>
                               <object class="GtkLabel" id="input_device_label">
-                                <property name="visible">True</property>
                                 <property name="ellipsize">end</property>
                                 <property name="xalign">0</property>
                                 <property name="label" translatable="yes">Input Device</property>
@@ -280,21 +253,17 @@
                             </child>
                             <child>
                               <object class="GtkBox">
-                                <property name="visible">True</property>
                                 <property name="orientation">vertical</property>
                                 <property name="hexpand">True</property>
                                 <property name="spacing">9</property>
                                 <child>
                                   <object class="CcDeviceComboBox" id="input_device_combo_box">
-                                    <property name="visible">True</property>
                                     <property name="hexpand">True</property>
                                     <signal name="changed" handler="input_device_changed_cb" 
object="CcSoundPanel" swapped="yes"/>
                                   </object>
                                 </child>
                                 <child>
-                                  <object class="CcLevelBar" id="input_level_bar">
-                                    <property name="visible">True</property>
-                                  </object>
+                                  <object class="CcLevelBar" id="input_level_bar" />
                                 </child>
                               </object>
                             </child>
@@ -304,16 +273,16 @@
                     </child>
                     <child>
                       <object class="GtkListBoxRow" id="input_profile_row">
-                        <property name="visible">True</property>
                         <property name="activatable">False</property>
                         <child>
                           <object class="GtkBox">
-                            <property name="visible">True</property>
-                            <property name="margin">12</property>
+                            <property name="margin-top">12</property>
+                            <property name="margin-bottom">12</property>
+                            <property name="margin-start">12</property>
+                            <property name="margin-end">12</property>
                             <property name="spacing">12</property>
                             <child>
                               <object class="GtkLabel" id="input_configuration_label">
-                                <property name="visible">True</property>
                                 <property name="ellipsize">end</property>
                                 <property name="xalign">0</property>
                                 <property name="label" translatable="yes">Configuration</property>
@@ -321,11 +290,9 @@
                             </child>
                             <child>
                               <object class="GtkBox">
-                                <property name="visible">True</property>
                                 <property name="spacing">6</property>
                                 <child>
                                   <object class="CcProfileComboBox" id="input_profile_combo_box">
-                                    <property name="visible">True</property>
                                     <property name="hexpand">True</property>
                                   </object>
                                 </child>
@@ -337,16 +304,16 @@
                     </child>
                     <child>
                       <object class="GtkListBoxRow">
-                        <property name="visible">True</property>
                         <property name="activatable">False</property>
                         <child>
                           <object class="GtkBox">
-                            <property name="visible">True</property>
-                            <property name="margin">12</property>
+                            <property name="margin-top">12</property>
+                            <property name="margin-bottom">12</property>
+                            <property name="margin-start">12</property>
+                            <property name="margin-end">12</property>
                             <property name="spacing">12</property>
                             <child>
                               <object class="GtkLabel" id="input_volume_label">
-                                <property name="visible">True</property>
                                 <property name="ellipsize">end</property>
                                 <property name="xalign">0</property>
                                 <property name="label" translatable="yes">Volume</property>
@@ -354,7 +321,6 @@
                             </child>
                             <child>
                               <object class="CcVolumeSlider" id="input_volume_slider">
-                                <property name="visible">True</property>
                                 <property name="hexpand">True</property>
                               </object>
                             </child>
@@ -366,7 +332,6 @@
                 </child>
                 <child>
                   <object class="GtkLabel">
-                    <property name="visible">True</property>
                     <property name="xalign">0</property>
                     <property name="margin-top">18</property>
                     <property name="label" translatable="yes">Alert Sound</property>
@@ -377,7 +342,6 @@
                 </child>
                 <child>
                   <object class="CcAlertChooser">
-                    <property name="visible">True</property>
                     <property name="hexpand">True</property>
                   </object>
                 </child>
diff --git a/panels/sound/cc-speaker-test-button.c b/panels/sound/cc-speaker-test-button.c
index 833b3990b..71824aaba 100644
--- a/panels/sound/cc-speaker-test-button.c
+++ b/panels/sound/cc-speaker-test-button.c
@@ -80,9 +80,7 @@ get_icon_name (CcSpeakerTestButton *self)
 static void
 update_icon (CcSpeakerTestButton *self)
 {
-  gtk_image_set_from_icon_name (self->image,
-                                get_icon_name (self),
-                                GTK_ICON_SIZE_DIALOG);
+  gtk_image_set_from_icon_name (self->image, get_icon_name (self));
 }
 
 static GStrv
diff --git a/panels/sound/cc-speaker-test-button.ui b/panels/sound/cc-speaker-test-button.ui
index 7e37034c8..2c8bdf892 100644
--- a/panels/sound/cc-speaker-test-button.ui
+++ b/panels/sound/cc-speaker-test-button.ui
@@ -8,10 +8,14 @@
         <property name="visible">True</property>
         <property name="orientation">vertical</property>
         <property name="spacing">6</property>
-        <property name="margin">12</property>
+        <property name="margin-top">12</property>
+        <property name="margin-bottom">12</property>
+        <property name="margin-start">12</property>
+        <property name="margin-end">12</property>
         <child>
           <object class="GtkImage" id="image">
             <property name="visible">True</property>
+            <property name="icon-size">large</property>
           </object>
         </child>
         <child>
diff --git a/panels/sound/cc-stream-list-box.c b/panels/sound/cc-stream-list-box.c
index ca914ef94..d98197610 100644
--- a/panels/sound/cc-stream-list-box.c
+++ b/panels/sound/cc-stream-list-box.c
@@ -23,11 +23,13 @@
 #include "cc-stream-list-box.h"
 #include "cc-stream-row.h"
 #include "cc-sound-enums.h"
+#include "cc-sound-resources.h"
 
 struct _CcStreamListBox
 {
-  GtkListBox       parent_instance;
+  GtkBox           parent_instance;
 
+  GtkListBox      *listbox;
   GtkSizeGroup    *label_size_group;
   GvcMixerControl *mixer_control;
   CcStreamType     stream_type;
@@ -35,7 +37,7 @@ struct _CcStreamListBox
   guint            stream_removed_handler_id;
 };
 
-G_DEFINE_TYPE (CcStreamListBox, cc_stream_list_box, GTK_TYPE_LIST_BOX)
+G_DEFINE_TYPE (CcStreamListBox, cc_stream_list_box, GTK_TYPE_BOX)
 
 enum
 {
@@ -100,28 +102,24 @@ stream_added_cb (CcStreamListBox *self,
     }
 
   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));
+  gtk_list_box_append (self->listbox, GTK_WIDGET (row));
 }
 
-static CcStreamRow *
+static GtkWidget *
 find_row (CcStreamListBox *self,
           guint            id)
 {
-  g_autoptr(GList) children = NULL;
-  GList *link;
+  GtkWidget *child;
 
-  children = gtk_container_get_children (GTK_CONTAINER (self));
-  for (link = children; link; link = link->next)
+  for (child = gtk_widget_get_first_child (GTK_WIDGET (self->listbox));
+       child;
+       child = gtk_widget_get_next_sibling (child))
     {
-      CcStreamRow *row = link->data;
-
-      if (!CC_IS_STREAM_ROW (row))
+      if (!CC_IS_STREAM_ROW (child))
         continue;
 
-      if (id == cc_stream_row_get_id (row))
-        return row;
+      if (id == cc_stream_row_get_id (CC_STREAM_ROW (child)))
+        return child;
     }
 
   return NULL;
@@ -131,11 +129,11 @@ static void
 stream_removed_cb (CcStreamListBox *self,
                    guint            id)
 {
-  CcStreamRow *row;
+  GtkWidget *row;
 
   row = find_row (self, id);
   if (row != NULL)
-    gtk_container_remove (GTK_CONTAINER (self), GTK_WIDGET (row));
+    gtk_list_box_remove (self->listbox, row);
 }
 
 static void
@@ -186,6 +184,7 @@ void
 cc_stream_list_box_class_init (CcStreamListBoxClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   object_class->set_property = cc_stream_list_box_set_property;
   object_class->get_property = cc_stream_list_box_get_property;
@@ -197,13 +196,20 @@ cc_stream_list_box_class_init (CcStreamListBoxClass *klass)
                                                         NULL,
                                                         GTK_TYPE_SIZE_GROUP,
                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/control-center/sound/cc-stream-list-box.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, CcStreamListBox, listbox);
 }
 
 void
 cc_stream_list_box_init (CcStreamListBox *self)
 {
-  gtk_list_box_set_selection_mode (GTK_LIST_BOX (self), GTK_SELECTION_NONE);
-  gtk_list_box_set_sort_func (GTK_LIST_BOX (self), sort_cb, self, NULL);
+  g_resources_register (cc_sound_get_resource ());
+
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  gtk_list_box_set_sort_func (self->listbox, sort_cb, self, NULL);
 }
 
 void
diff --git a/panels/sound/cc-stream-list-box.h b/panels/sound/cc-stream-list-box.h
index 8a46fd7c9..f2d30752c 100644
--- a/panels/sound/cc-stream-list-box.h
+++ b/panels/sound/cc-stream-list-box.h
@@ -27,7 +27,7 @@
 G_BEGIN_DECLS
 
 #define CC_TYPE_STREAM_LIST_BOX (cc_stream_list_box_get_type ())
-G_DECLARE_FINAL_TYPE (CcStreamListBox, cc_stream_list_box, CC, STREAM_LIST_BOX, GtkListBox)
+G_DECLARE_FINAL_TYPE (CcStreamListBox, cc_stream_list_box, CC, STREAM_LIST_BOX, GtkBox)
 
 void cc_stream_list_box_set_mixer_control (CcStreamListBox *combo_box,
                                            GvcMixerControl *mixer_control);
diff --git a/panels/sound/cc-stream-list-box.ui b/panels/sound/cc-stream-list-box.ui
new file mode 100644
index 000000000..95f88f7dc
--- /dev/null
+++ b/panels/sound/cc-stream-list-box.ui
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <template class="CcStreamListBox" parent="GtkBox">
+    <child>
+      <object class="GtkListBox" id="listbox">
+        <property name="hexpand">True</property>
+        <property name="selection-mode">none</property>
+        <style>
+          <class name="content" />
+        </style>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/panels/sound/cc-stream-row.c b/panels/sound/cc-stream-row.c
index f0277d1de..7fae94f11 100644
--- a/panels/sound/cc-stream-row.c
+++ b/panels/sound/cc-stream-row.c
@@ -80,7 +80,7 @@ cc_stream_row_new (GtkSizeGroup    *size_group,
                    GvcMixerControl *mixer_control)
 {
   CcStreamRow *self;
-  g_autoptr(GtkIconInfo) icon_info = NULL;
+  g_autoptr(GtkIconPaintable) icon_paintable = NULL;
   g_autoptr(GIcon) gicon = NULL;
   const gchar *stream_name;
   const gchar *icon_name;
@@ -101,19 +101,22 @@ cc_stream_row_new (GtkSizeGroup    *size_group,
   /* Explicitly lookup for the icon, since some streams may give us an
    * icon name (e.g. "audio") that doesn't really exist in the theme.
    */
-  icon_info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (),
-                                          icon_name,
-                                          24,
-                                          GTK_ICON_LOOKUP_GENERIC_FALLBACK);
-
-  if (icon_info)
+  icon_paintable = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_for_display (gdk_display_get_default ()),
+                                               icon_name,
+                                               NULL,
+                                               24,
+                                               gtk_widget_get_scale_factor (GTK_WIDGET (self)),
+                                               GTK_TEXT_DIR_RTL,
+                                               0);
+
+  if (icon_paintable)
     gicon = g_themed_icon_new_with_default_fallbacks (symbolic_icon_name);
   else if (g_str_has_prefix (stream_name, SPEECH_DISPATCHER_PREFIX))
     gicon = g_themed_icon_new_with_default_fallbacks ("preferences-desktop-accessibility-symbolic");
   else
     gicon = g_themed_icon_new_with_default_fallbacks ("application-x-executable-symbolic");
 
-  gtk_image_set_from_gicon (self->icon_image, gicon, GTK_ICON_SIZE_LARGE_TOOLBAR);
+  gtk_image_set_from_gicon (self->icon_image, gicon);
 
   gtk_label_set_label (self->name_label, gvc_mixer_stream_get_name (stream));
   cc_volume_slider_set_stream (self->volume_slider, stream, stream_type);
diff --git a/panels/sound/cc-stream-row.ui b/panels/sound/cc-stream-row.ui
index 782956a8b..756f6bbdc 100644
--- a/panels/sound/cc-stream-row.ui
+++ b/panels/sound/cc-stream-row.ui
@@ -2,26 +2,26 @@
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
   <template class="CcStreamRow" parent="GtkListBoxRow">
+    <property name="activatable">False</property>
     <child>
       <object class="GtkBox">
-        <property name="visible">True</property>
-        <property name="margin">12</property>
+        <property name="margin-top">12</property>
+        <property name="margin-bottom">12</property>
+        <property name="margin-start">12</property>
+        <property name="margin-end">12</property>
         <property name="spacing">12</property>
         <child>
           <object class="GtkBox" id="label_box">
-            <property name="visible">True</property>
             <property name="spacing">6</property>
               <child>
                 <object class="GtkImage" id="icon_image">
-                  <property name="visible">True</property>
                   <style>
                     <class name="lowres-icon"/>
-                 </style>
+                  </style>
                 </object>
               </child>
               <child>
                 <object class="GtkLabel" id="name_label">
-                  <property name="visible">True</property>
                   <property name="ellipsize">end</property>
                   <property name="xalign">0</property>
                 </object>
@@ -30,7 +30,6 @@
         </child>
         <child>
           <object class="CcVolumeSlider" id="volume_slider">
-            <property name="visible">True</property>
             <property name="hexpand">True</property>
           </object>
         </child>
diff --git a/panels/sound/cc-volume-slider.c b/panels/sound/cc-volume-slider.c
index 1451a1e39..1b3f13adc 100644
--- a/panels/sound/cc-volume-slider.c
+++ b/panels/sound/cc-volume-slider.c
@@ -60,7 +60,7 @@ update_volume_icon (CcVolumeSlider *self)
   else
     icon_name = "audio-volume-high-symbolic";
 
-  gtk_image_set_from_icon_name (self->stream_type_icon, icon_name, GTK_ICON_SIZE_BUTTON);
+  gtk_image_set_from_icon_name (self->stream_type_icon, icon_name);
 }
 
 static void
@@ -215,14 +215,12 @@ cc_volume_slider_set_stream (CcVolumeSlider *self,
     {
     case CC_STREAM_TYPE_INPUT:
       gtk_image_set_from_icon_name (self->stream_type_icon,
-                                    "microphone-sensitivity-muted-symbolic",
-                                    GTK_ICON_SIZE_BUTTON);
+                                    "microphone-sensitivity-muted-symbolic");
       break;
 
     case CC_STREAM_TYPE_OUTPUT:
       gtk_image_set_from_icon_name (self->stream_type_icon,
-                                    "audio-volume-muted-symbolic",
-                                    GTK_ICON_SIZE_BUTTON);
+                                    "audio-volume-muted-symbolic");
       break;
 
     default:
diff --git a/panels/sound/cc-volume-slider.ui b/panels/sound/cc-volume-slider.ui
index 4fb054027..2a07a1fa4 100644
--- a/panels/sound/cc-volume-slider.ui
+++ b/panels/sound/cc-volume-slider.ui
@@ -14,8 +14,10 @@
     <child>
       <object class="GtkToggleButton" id="mute_button">
         <property name="visible">True</property>
-        <property name="relief">none</property>
         <signal name="toggled" handler="mute_button_toggled_cb" object="CcVolumeSlider" swapped="yes"/>
+        <style>
+          <class name="flat" />
+        </style>
         <child>
           <object class="GtkImage" id="stream_type_icon">
             <property name="visible">True</property>
diff --git a/panels/sound/sound.gresource.xml b/panels/sound/sound.gresource.xml
index a7b662dd2..5f3964f98 100644
--- a/panels/sound/sound.gresource.xml
+++ b/panels/sound/sound.gresource.xml
@@ -10,6 +10,7 @@
     <file preprocess="xml-stripblanks">cc-sound-button.ui</file>
     <file preprocess="xml-stripblanks">cc-sound-panel.ui</file>
     <file preprocess="xml-stripblanks">cc-speaker-test-button.ui</file>
+    <file preprocess="xml-stripblanks">cc-stream-list-box.ui</file>
     <file preprocess="xml-stripblanks">cc-stream-row.ui</file>
     <file preprocess="xml-stripblanks">cc-subwoofer-slider.ui</file>
     <file preprocess="xml-stripblanks">cc-volume-slider.ui</file>
diff --git a/shell/cc-panel-loader.c b/shell/cc-panel-loader.c
index b9bead778..3d204b0a3 100644
--- a/shell/cc-panel-loader.c
+++ b/shell/cc-panel-loader.c
@@ -56,7 +56,7 @@ extern GType cc_notifications_panel_get_type (void);
 //extern GType cc_removable_media_panel_get_type (void);
 //extern GType cc_search_panel_get_type (void);
 //extern GType cc_sharing_panel_get_type (void);
-//extern GType cc_sound_panel_get_type (void);
+extern GType cc_sound_panel_get_type (void);
 #ifdef BUILD_THUNDERBOLT
 //extern GType cc_bolt_panel_get_type (void);
 #endif /* BUILD_THUNDERBOLT */
@@ -127,7 +127,7 @@ static CcPanelLoaderVtable default_panels[] =
   //PANEL_TYPE("removable-media",  cc_removable_media_panel_get_type,      NULL),
   //PANEL_TYPE("search",           cc_search_panel_get_type,               NULL),
   //PANEL_TYPE("sharing",          cc_sharing_panel_get_type,              NULL),
-  //PANEL_TYPE("sound",            cc_sound_panel_get_type,                NULL),
+  PANEL_TYPE("sound",            cc_sound_panel_get_type,                NULL),
 #ifdef BUILD_THUNDERBOLT
   //PANEL_TYPE("thunderbolt",      cc_bolt_panel_get_type,                 NULL),
 #endif


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