[sound-juicer/gnome-3-18] Limit range of EggPlayPreview scale



commit 25266c1aae3351e427d92a6ddb64fecf800c922e
Author: Phillip Wood <phillip wood dunelm org uk>
Date:   Tue Feb 9 11:03:54 2016 +0000

    Limit range of EggPlayPreview scale
    
    When moving the scale with the mouse if one moves past the end of the
    scale the value seen by the ‘change-value’ handler keeps changing
    which means that time label could show times greater than the track
    length. Fix this by checking that the value is within the permitted
    range.
    
    Note that handling ‘change-value’ is preferable to handling
    ‘value-changed’ here as ‘change-value’ is only emitted in response to
    scroll events so it avoids a feedback loop which would exist between a
    ‘value-changed’ handler and timeout_cb() which calls
    gtk_range_set_value().

 src/egg-play-preview.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/src/egg-play-preview.c b/src/egg-play-preview.c
index 264f54c..546a0a4 100644
--- a/src/egg-play-preview.c
+++ b/src/egg-play-preview.c
@@ -600,14 +600,32 @@ _ui_set_sensitive (EggPlayPreview *play_preview, gboolean sensitive)
        gtk_widget_set_sensitive (priv->time_scale, sensitive && priv->is_seekable);
 }
 
+/*
+ * Note that handling ‘change-value’ is preferable to handling
+ * ‘value-changed’ as ‘change-value’ is only emitted in response to
+ * scroll events so it avoids a feedback loop which would exist
+ * between a ‘value-changed’ handler and timeout_cb() which calls
+ * gtk_range_set_value().
+ */
 static gboolean
 _change_value_cb (GtkRange *range, GtkScrollType scroll, gdouble value, EggPlayPreview *play_preview)
 {
        EggPlayPreviewPrivate *priv;
+       GtkAdjustment *adjustment;
+       double lower, upper;
 
        priv = GET_PRIVATE (play_preview);
+       adjustment = gtk_range_get_adjustment (range);
+       lower = gtk_adjustment_get_lower (adjustment);
+       upper = gtk_adjustment_get_upper (adjustment);
+       /* Clamp value to be within the adjustment range. */
+       if (value < lower)
+               value = lower;
 
-       if (priv->is_seekable) {
+       if (value > upper)
+               value = upper;
+
+       if (priv->is_seekable && value != gtk_adjustment_get_value (adjustment)) {
                priv->position = (int) (value / 100.0 * priv->duration);
                _seek (priv->playbin, priv->position);
                _ui_update_duration (play_preview);


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