[Xfce4-commits] <xfce4-mixer:master> Refactor the handling of minimum volumes

Guido Berhoerster noreply at xfce.org
Thu Dec 27 11:26:03 CET 2012


Updating branch refs/heads/master
         to 10d82e6eb52dd4f27db48386bf208c2157bc9e3d (commit)
       from d87694483f47d69bd52320b125e5db85f9481cd4 (commit)

commit 10d82e6eb52dd4f27db48386bf208c2157bc9e3d
Author: Guido Berhoerster <guido+xfce at berhoerster.name>
Date:   Wed Dec 26 18:57:53 2012 +0100

    Refactor the handling of minimum volumes
    
    Move the logic that automatically mutes a track when the volume reaches
    the minimun and unmutes a track when the volume is raised from the
    minimum from the volume button widget into the plugin code.

 panel-plugin/xfce-mixer-plugin.c  |   22 ++++++++++++++++++----
 panel-plugin/xfce-volume-button.c |   24 ++++--------------------
 2 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/panel-plugin/xfce-mixer-plugin.c b/panel-plugin/xfce-mixer-plugin.c
index 7600cb2..5562e80 100644
--- a/panel-plugin/xfce-mixer-plugin.c
+++ b/panel-plugin/xfce-mixer-plugin.c
@@ -864,18 +864,32 @@ static void
 xfce_mixer_plugin_button_volume_changed (XfceMixerPlugin  *mixer_plugin,
                                          gdouble           button_volume)
 {
-  gint   volume;
+  gint   old_volume;
+  gint   new_volume;
 
   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));
 
+  old_volume = xfce_mixer_plugin_get_volume (mixer_plugin);
   /* Convert relative to absolute volume */
-  volume = (gint) round (mixer_plugin->track->min_volume + (button_volume * (mixer_plugin->track->max_volume - mixer_plugin->track->min_volume)));
+  new_volume = (gint) round (mixer_plugin->track->min_volume + (button_volume * (mixer_plugin->track->max_volume - mixer_plugin->track->min_volume)));
 
-  xfce_mixer_debug ("button emitted 'volume-changed', new volume is %d (%d%%)", volume, (gint) round (button_volume * 100));
+  xfce_mixer_debug ("button emitted 'volume-changed', new volume is %d (%d%%)", new_volume, (gint) round (button_volume * 100));
 
-  xfce_mixer_plugin_set_volume (mixer_plugin, volume);
+  xfce_mixer_plugin_set_volume (mixer_plugin, new_volume);
+
+  /* Mute when volume reaches the minimum, unmute if volume is raised from the minimum */
+  if (old_volume > mixer_plugin->track->min_volume && new_volume == mixer_plugin->track->min_volume)
+    {
+      xfce_mixer_plugin_set_muted (mixer_plugin, TRUE);
+      xfce_mixer_plugin_update_muted (mixer_plugin, TRUE);
+    }
+  else if (old_volume == mixer_plugin->track->min_volume && new_volume > mixer_plugin->track->min_volume)
+    {
+      xfce_mixer_plugin_set_muted (mixer_plugin, FALSE);
+      xfce_mixer_plugin_update_muted (mixer_plugin, FALSE);
+    }
 }
 
 
diff --git a/panel-plugin/xfce-volume-button.c b/panel-plugin/xfce-volume-button.c
index 223701b..6877614 100644
--- a/panel-plugin/xfce-volume-button.c
+++ b/panel-plugin/xfce-volume-button.c
@@ -459,16 +459,8 @@ xfce_volume_button_scale_changed_value (XfceVolumeButton *button,
 
   if (fabs (new_value - old_value) > VOLUME_EPSILON)
     {
-      /* Mute when volume reaches 0%, unmute if volume is raised from 0% */
-      if (new_value < VOLUME_EPSILON && !button->is_muted && !button->no_mute)
-        xfce_volume_button_set_muted (button, TRUE);
-      else if (old_value < VOLUME_EPSILON && button->is_muted && !button->no_mute)
-        xfce_volume_button_set_muted (button, FALSE);
-      else
-        {
-          /* Update the state of the button */
-          xfce_volume_button_update (button);
-        }
+      /* Update the state of the button */
+      xfce_volume_button_update (button);
 
       /* Notify listeners of the new volume */
       g_signal_emit_by_name (button, "volume-changed", new_value);
@@ -789,16 +781,8 @@ xfce_volume_button_scroll_event (GtkWidget      *widget,
   new_value = gtk_adjustment_get_value (GTK_ADJUSTMENT (button->adjustment));
   if (fabs (new_value - old_value) > VOLUME_EPSILON)
     {
-      /* Mute when volume reaches 0%, unmute if volume is raised from 0% */
-      if (new_value < VOLUME_EPSILON && !button->is_muted && !button->no_mute)
-        xfce_volume_button_set_muted (button, TRUE);
-      else if (old_value < VOLUME_EPSILON && button->is_muted && !button->no_mute)
-        xfce_volume_button_set_muted (button, FALSE);
-      else
-        {
-          /* Update the state of the button */
-          xfce_volume_button_update (button);
-        }
+      /* Update the state of the button */
+      xfce_volume_button_update (button);
 
       /* Notify listeners of the new volume */
       g_signal_emit_by_name (button, "volume-changed", new_value);


More information about the Xfce4-commits mailing list