[Xfce4-commits] <xfce4-mixer:gber/improvements> Indicate in the plugin tooltip whether the track is muted

Guido Berhoerster noreply at xfce.org
Fri Sep 21 17:18:13 CEST 2012


Updating branch refs/heads/gber/improvements
         to 521f16c2f9904c11af1d1a0ee09db504ac727771 (commit)
       from c307eeda920f331185b204da2f8ba0633c316e90 (commit)

commit 521f16c2f9904c11af1d1a0ee09db504ac727771
Author: Guido Berhoerster <guido+xfce at berhoerster.name>
Date:   Fri Sep 21 12:00:36 2012 +0200

    Indicate in the plugin tooltip whether the track is muted
    
    Let XfceVolumeButton keep state istelf by adding a "is-muted" property and
    remove the "mute-toggled" signal.

 NEWS                              |    1 +
 panel-plugin/xfce-mixer-plugin.c  |   16 +++++--
 panel-plugin/xfce-volume-button.c |   84 ++++++++++++++++++++----------------
 panel-plugin/xfce-volume-button.h |    3 +-
 4 files changed, 61 insertions(+), 43 deletions(-)

diff --git a/NEWS b/NEWS
index c056db7..c4ccfac 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@
   and ignore mouse wheel and mute toggle events (bug #6625, bug #7630).
 - Avoid the deprecated GtkTooltips API and let XfceVolumeButton handle
   tooltips.
+- Indicate in the plugin tooltip whether the track is muted.
 
 
 4.8.0
diff --git a/panel-plugin/xfce-mixer-plugin.c b/panel-plugin/xfce-mixer-plugin.c
index da09a72..82f7db3 100644
--- a/panel-plugin/xfce-mixer-plugin.c
+++ b/panel-plugin/xfce-mixer-plugin.c
@@ -68,8 +68,9 @@ static gboolean xfce_mixer_plugin_size_changed                (XfcePanelPlugin
 static void     xfce_mixer_plugin_clicked                     (XfceMixerPlugin  *mixer_plugin);
 static void     xfce_mixer_plugin_volume_changed              (XfceMixerPlugin  *mixer_plugin,
                                                                gdouble           volume);
-static void     xfce_mixer_plugin_mute_toggled                (XfceMixerPlugin  *mixer_plugin,
-                                                               gboolean          mute);
+static void     xfce_mixer_plugin_is_muted_property_changed   (XfceMixerPlugin  *mixer_plugin,
+                                                               GParamSpec       *pspec,
+                                                               GObject          *object);
 static void     xfce_mixer_plugin_update_track                (XfceMixerPlugin  *mixer_plugin);
 #ifdef HAVE_GST_MIXER_NOTIFICATION
 static void     xfce_mixer_plugin_bus_message                 (GstBus           *bus,
@@ -205,7 +206,7 @@ xfce_mixer_plugin_init (XfceMixerPlugin *mixer_plugin)
   /* Create volume button for the plugin */
   mixer_plugin->button = xfce_volume_button_new ();
   g_signal_connect_swapped (G_OBJECT (mixer_plugin->button), "volume-changed", G_CALLBACK (xfce_mixer_plugin_volume_changed), mixer_plugin);
-  g_signal_connect_swapped (G_OBJECT (mixer_plugin->button), "mute-toggled", G_CALLBACK (xfce_mixer_plugin_mute_toggled), mixer_plugin);
+  g_signal_connect_swapped (G_OBJECT (mixer_plugin->button), "notify::is-muted", G_CALLBACK (xfce_mixer_plugin_is_muted_property_changed), mixer_plugin);
   g_signal_connect_swapped (G_OBJECT (mixer_plugin->button), "clicked", G_CALLBACK (xfce_mixer_plugin_clicked), mixer_plugin);
   gtk_container_add (GTK_CONTAINER (mixer_plugin->hvbox), mixer_plugin->button);
   gtk_widget_show (mixer_plugin->button);
@@ -553,9 +554,12 @@ xfce_mixer_plugin_volume_changed (XfceMixerPlugin  *mixer_plugin,
 
 
 static void
-xfce_mixer_plugin_mute_toggled (XfceMixerPlugin *mixer_plugin,
-                                gboolean         mute)
+xfce_mixer_plugin_is_muted_property_changed (XfceMixerPlugin *mixer_plugin,
+                                             GParamSpec      *pspec,
+                                             GObject         *object)
 {
+  gboolean mute;
+
   g_return_if_fail (mixer_plugin != NULL);
   g_return_if_fail (GST_IS_MIXER (mixer_plugin->card));
   g_return_if_fail (GST_IS_MIXER_TRACK (mixer_plugin->track));
@@ -564,6 +568,8 @@ xfce_mixer_plugin_mute_toggled (XfceMixerPlugin *mixer_plugin,
   mixer_plugin->ignore_bus_messages = TRUE;
 #endif
 
+  g_object_get (object, "is-muted", &mute, NULL);
+
   if (G_LIKELY (xfce_mixer_track_type_new (mixer_plugin->track) == XFCE_MIXER_TRACK_TYPE_PLAYBACK))
     {
       /* Apply mute change to the sound card */
diff --git a/panel-plugin/xfce-volume-button.c b/panel-plugin/xfce-volume-button.c
index ca2236b..e80c792 100644
--- a/panel-plugin/xfce-volume-button.c
+++ b/panel-plugin/xfce-volume-button.c
@@ -48,6 +48,7 @@ enum
   PROP_0,
   PROP_TRACK_LABEL,
   PROP_IS_CONFIGURED,
+  PROP_IS_MUTED,
   N_PROPERTIES,
 };
 
@@ -57,7 +58,6 @@ enum
 enum
 {
   VOLUME_CHANGED,
-  MUTE_TOGGLED,
   LAST_SIGNAL,
 };
 
@@ -106,8 +106,6 @@ static void       xfce_volume_button_volume_changed (XfceVolumeButton      *butt
                                                      gdouble                volume);
 static void       xfce_volume_button_update_icons   (XfceVolumeButton      *button,
                                                      GtkIconTheme          *icon_theme);
-static void       xfce_volume_button_mute_toggled   (XfceVolumeButton      *button,
-                                                     gboolean               mute);
 
 
 
@@ -118,8 +116,6 @@ struct _XfceVolumeButtonClass
   /* Signals */
   void (*volume_changed) (XfceVolumeButton *button,
                           gdouble           volume);
-  void (*mute_toggled)   (XfceVolumeButton *button,
-                          gboolean          mute);
 };
 
 struct _XfceVolumeButton
@@ -198,7 +194,6 @@ xfce_volume_button_class_init (XfceVolumeButtonClass *klass)
   gobject_class->get_property = xfce_volume_button_get_property;
 
   klass->volume_changed = xfce_volume_button_volume_changed;
-  klass->mute_toggled = xfce_volume_button_mute_toggled;
 
   g_object_class_install_property (gobject_class,
                                    PROP_TRACK_LABEL,
@@ -216,6 +211,14 @@ xfce_volume_button_class_init (XfceVolumeButtonClass *klass)
                                                          FALSE,
                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
 
+  g_object_class_install_property (gobject_class,
+                                   PROP_IS_MUTED,
+                                   g_param_spec_boolean ("is-muted",
+                                                         "is-muted",
+                                                         "is-muted",
+                                                         FALSE,
+                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
+
   button_signals[VOLUME_CHANGED] = g_signal_new ("volume-changed",
                                                  G_TYPE_FROM_CLASS (klass),
                                                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
@@ -226,17 +229,6 @@ xfce_volume_button_class_init (XfceVolumeButtonClass *klass)
                                                  G_TYPE_NONE, 
                                                  1, 
                                                  G_TYPE_DOUBLE);
-
-  button_signals[MUTE_TOGGLED] = g_signal_new ("mute-toggled",
-                                               G_TYPE_FROM_CLASS (klass),
-                                               G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                                               G_STRUCT_OFFSET (XfceVolumeButtonClass, mute_toggled),
-                                               NULL, 
-                                               NULL,
-                                               g_cclosure_marshal_VOID__BOOLEAN,
-                                               G_TYPE_NONE, 
-                                               1, 
-                                               G_TYPE_BOOLEAN);
 }
 
 
@@ -321,6 +313,7 @@ static void xfce_volume_button_set_property (GObject      *object,
 {
   XfceVolumeButton *button = XFCE_VOLUME_BUTTON (object);
   gboolean          is_configured;
+  gboolean          is_muted;
 
   switch (prop_id)
     {
@@ -330,6 +323,14 @@ static void xfce_volume_button_set_property (GObject      *object,
         if (button->is_configured)
           xfce_volume_button_update (button);
         break;
+      case PROP_IS_MUTED:
+        is_muted = g_value_get_boolean (value);
+        if (button->is_configured && button->is_muted != is_muted)
+          {
+            button->is_muted = is_muted;
+            xfce_volume_button_update (button);
+          }
+        break;
       case PROP_IS_CONFIGURED:
         is_configured = g_value_get_boolean (value);
         if (button->is_configured != is_configured)
@@ -358,6 +359,9 @@ static void xfce_volume_button_get_property (GObject      *object,
       case PROP_TRACK_LABEL:
         g_value_set_string (value, button->track_label);
         break;
+      case PROP_IS_MUTED:
+        g_value_set_boolean (value, button->is_muted);
+        break;
       case PROP_IS_CONFIGURED:
         g_value_set_boolean (value, button->is_configured);
         break;
@@ -457,9 +461,6 @@ xfce_volume_button_button_pressed (GtkWidget        *widget,
 
           /* Toggle the button's mute state */
           xfce_volume_button_set_muted (button, mute);
-
-          /* Notify listeners of the mute change */
-          g_signal_emit_by_name (button, "mute-toggled", mute);
         }
 
       /* Middle mouse button was handled, do not propagate the event any further */
@@ -538,7 +539,7 @@ xfce_volume_button_update (XfceVolumeButton *button)
 
   if (G_UNLIKELY (!button->is_configured || button->is_muted || value < VOLUME_EPSILON))
     {
-      /* By definition, use the first icon if the button is muted or the volume is 0 */
+      /* By definition, use the first icon if the button is muted or the volume is 0% */
       pixbuf = button->pixbufs[0];
     }
   else
@@ -561,8 +562,11 @@ xfce_volume_button_update (XfceVolumeButton *button)
     gtk_widget_set_tooltip_text (GTK_WIDGET (button), _("No valid device and/or element."));
   else
     {
-      /* Set tooltip (e.g. 'Master: 50%') */
-      tip_text = g_strdup_printf (_("%s: %i%%"), button->track_label, (gint) value);
+      /* Set tooltip (e.g. 'Master: 50% (muted)') */
+      if (button->is_muted)
+        tip_text = g_strdup_printf (_("%s: muted"), button->track_label);
+      else
+        tip_text = g_strdup_printf (_("%s: %i%%"), button->track_label, (gint) (value * 100));
       gtk_widget_set_tooltip_text (GTK_WIDGET (button), tip_text);
       g_free (tip_text);
     }
@@ -581,15 +585,30 @@ xfce_volume_button_volume_changed (XfceVolumeButton *button,
 
 void
 xfce_volume_button_set_muted (XfceVolumeButton *button,
-                              gboolean          muted)
+                              gboolean          is_muted)
 {
+  GValue value = G_VALUE_INIT;
+
   g_return_if_fail (IS_XFCE_VOLUME_BUTTON (button));
 
-  /* Change mute value */
-  button->is_muted = muted;
+  g_value_init (&value, G_TYPE_BOOLEAN);
+  g_value_set_boolean (&value, is_muted);
+  g_object_set_property (G_OBJECT (button), "is-muted", &value);
+}
 
-  /* Update the state of the button */
-  xfce_volume_button_update (button);
+
+
+gboolean
+xfce_volume_button_get_muted (XfceVolumeButton *button)
+{
+  GValue value = G_VALUE_INIT;
+
+  g_return_val_if_fail (IS_XFCE_VOLUME_BUTTON (button), FALSE);
+
+  g_value_init (&value, G_TYPE_BOOLEAN);
+  g_object_get_property (G_OBJECT (button), "is-muted", &value);
+
+  return g_value_get_boolean (&value);
 }
 
 
@@ -652,15 +671,6 @@ xfce_volume_button_set_icon_size (XfceVolumeButton *button,
 
 
 
-static void
-xfce_volume_button_mute_toggled (XfceVolumeButton *button,
-                                 gboolean          mute)
-{
-  /* Do nothing */
-}
-
-
-
 void
 xfce_volume_button_set_track_label (XfceVolumeButton *button,
                                     const gchar      *track_label)
diff --git a/panel-plugin/xfce-volume-button.h b/panel-plugin/xfce-volume-button.h
index eb10f6e..4217ecc 100644
--- a/panel-plugin/xfce-volume-button.h
+++ b/panel-plugin/xfce-volume-button.h
@@ -41,9 +41,10 @@ GType     xfce_volume_button_get_type           (void) G_GNUC_CONST;
 GtkWidget *xfce_volume_button_new               (void);
 
 void       xfce_volume_button_set_muted         (XfceVolumeButton *button,
-                                                 gboolean          muted);
+                                                 gboolean          is_muted);
 void       xfce_volume_button_set_volume        (XfceVolumeButton *button,
                                                  gdouble           volume);
+gboolean   xfce_volume_button_get_muted         (XfceVolumeButton *button);
 void       xfce_volume_button_update            (XfceVolumeButton *button);
 void       xfce_volume_button_set_icon_size     (XfceVolumeButton *button,
                                                  gint              size);


More information about the Xfce4-commits mailing list