[gtksourceview/gtksourceview-5-4] map: protect against spurious adjustment notifications



commit 5cebb4ac58b8440d45fa7b67068ef529ac17aaf2
Author: Christian Hergert <chergert redhat com>
Date:   Sat Jun 11 20:37:18 2022 -0700

    map: protect against spurious adjustment notifications
    
    Sometimes GtkTextView will cause us to get notifications when things didn't
    really change. This protects against that with a cached value so that we
    can more readiliy avoid extraneous size allocations.

 gtksourceview/gtksourcemap.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
---
diff --git a/gtksourceview/gtksourcemap.c b/gtksourceview/gtksourcemap.c
index d3c10ce9..708eb338 100644
--- a/gtksourceview/gtksourcemap.c
+++ b/gtksourceview/gtksourcemap.c
@@ -182,6 +182,12 @@ typedef struct
        /* The location of the slider in widget coordinate space. */
        GdkRectangle slider_area;
 
+       /* We compare against old values from the vadjustment as it can
+        * notify a bit more than is necessary.
+        */
+       double last_vadj_upper;
+       double last_vadj_value;
+
        /* Weak pointer view to child view bindings */
        GBinding *buffer_binding;
        GBinding *indent_width_binding;
@@ -479,7 +485,7 @@ gtk_source_map_rebuild_css (GtkSourceMap *map)
 static void
 update_child_vadjustment (GtkSourceMap *map)
 {
-       GtkSourceMapPrivate *priv;
+       GtkSourceMapPrivate *priv = gtk_source_map_get_instance_private (map);
        GtkAdjustment *vadj;
        GtkAdjustment *child_vadj;
        gdouble value;
@@ -489,8 +495,6 @@ update_child_vadjustment (GtkSourceMap *map)
        gdouble child_page_size;
        gdouble new_value = 0.0;
 
-       priv = gtk_source_map_get_instance_private (map);
-
        vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (priv->view));
        g_object_get (vadj,
                      "upper", &upper,
@@ -521,8 +525,15 @@ static void
 view_vadj_value_changed (GtkSourceMap  *map,
                          GtkAdjustment *vadj)
 {
-       update_child_vadjustment (map);
-       gtk_widget_queue_allocate (GTK_WIDGET (map));
+       GtkSourceMapPrivate *priv = gtk_source_map_get_instance_private (map);
+       double value = gtk_adjustment_get_value (vadj);
+
+       if (value != priv->last_vadj_value)
+       {
+               priv->last_vadj_value = value;
+               update_child_vadjustment (map);
+               gtk_widget_queue_allocate (GTK_WIDGET (map));
+       }
 }
 
 static void
@@ -530,7 +541,14 @@ view_vadj_notify_upper (GtkSourceMap  *map,
                         GParamSpec    *pspec,
                         GtkAdjustment *vadj)
 {
-       gtk_widget_queue_allocate (GTK_WIDGET (map));
+       GtkSourceMapPrivate *priv = gtk_source_map_get_instance_private (map);
+       double upper = gtk_adjustment_get_upper (vadj);
+
+       if (upper != priv->last_vadj_upper)
+       {
+               priv->last_vadj_upper = upper;
+               gtk_widget_queue_allocate (GTK_WIDGET (map));
+       }
 }
 
 static void


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