[nautilus/wip/antoniof/pathbar-nice-refinements: 1/2] pathbar: Fix automatically scrolling




commit c4cb037fcbaa7bc005f1b1de2d4bd2f6cc846f45
Author: António Fernandes <antoniof gnome org>
Date:   Thu Jun 30 18:51:20 2022 +0100

    pathbar: Fix automatically scrolling
    
    We want to automatically set the scrolling position to the end, in order
    to reveal the current folder when:
    
        1. the path changes.
        2. the window is resized.
    
    However, this is not working as expected in the first case, maybe
    because we need to wait until the next main context iteration.
    
    Fix it by adding a scrolling animation.

 src/nautilus-pathbar.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
---
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index f43ccaf5f..c092cabb2 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -205,9 +205,25 @@ action_pathbar_properties (GSimpleAction *action,
 }
 
 static void
-on_adjustment_changed (GtkAdjustment *adjustment)
+on_adjustment_changed (GtkAdjustment   *adjustment,
+                       NautilusPathBar *self)
 {
-    /* Automatically scroll to the end, to keep the current folder visible */
+    /* Automatically scroll to the end, to reveal the current folder. */
+    g_autoptr (AdwAnimation) anim = NULL;
+    anim = adw_timed_animation_new (GTK_WIDGET (self),
+                                    gtk_adjustment_get_value (adjustment),
+                                    gtk_adjustment_get_upper (adjustment),
+                                    800,
+                                    adw_property_animation_target_new (G_OBJECT (adjustment), "value"));
+    adw_timed_animation_set_easing (ADW_TIMED_ANIMATION (anim), ADW_EASE_OUT_CUBIC);
+    adw_animation_play (anim);
+}
+
+static void
+on_page_size_changed (GtkAdjustment *adjustment)
+{
+    /* When window is resized, immediately set new value, otherwise we would get
+     * an underflow gradient for an moment. */
     gtk_adjustment_set_value (adjustment, gtk_adjustment_get_upper (adjustment));
 }
 
@@ -237,7 +253,8 @@ nautilus_path_bar_init (NautilusPathBar *self)
     gtk_box_append (GTK_BOX (self), self->scrolled);
 
     adjustment = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (self->scrolled));
-    g_signal_connect (adjustment, "changed", (GCallback) on_adjustment_changed, NULL);
+    g_signal_connect (adjustment, "changed", G_CALLBACK (on_adjustment_changed), self);
+    g_signal_connect (adjustment, "notify::page-size", G_CALLBACK (on_page_size_changed), self);
 
     self->buttons_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
     gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (self->scrolled), self->buttons_box);


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