[nautilus/wip/antoniof/switch-to-gtk4: 14/36] --- WIP --- Scroll-event for ZOOM




commit 2dc098b4473e8afe1aeda2b3d343f6f3cf276c27
Author: António Fernandes <antoniof gnome org>
Date:   Mon Dec 20 16:53:36 2021 +0000

    --- WIP --- Scroll-event for ZOOM

 src/nautilus-files-view.c | 83 +++++++++++++++--------------------------------
 1 file changed, 26 insertions(+), 57 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index c32af3dd5..78474a747 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -9122,73 +9122,37 @@ nautilus_files_view_set_property (GObject      *object,
 
 /* handle Ctrl+Scroll, which will cause a zoom-in/out */
 static gboolean
-on_event (GtkWidget *widget,
-          GdkEvent  *event,
-          gpointer   user_data)
+on_scroll (GtkEventControllerScroll *scroll,
+           gdouble                   dx,
+           gdouble                   dy,
+           gpointer                  user_data)
 {
     NautilusFilesView *directory_view;
-    static gdouble total_delta_y = 0;
     GdkModifierType state;
+    GdkEvent *event;
     GdkScrollDirection direction;
-    gdouble delta_x, delta_y;
 
-    directory_view = NAUTILUS_FILES_VIEW (widget);
-
-    if (gdk_event_get_event_type (event) != GDK_SCROLL)
-    {
-        return GDK_EVENT_PROPAGATE;
-    }
-
-    if (!gdk_event_get_state (event, &state))
-    {
-        return GDK_EVENT_PROPAGATE;
-    }
+    directory_view = NAUTILUS_FILES_VIEW (user_data);
 
+    state = gtk_event_controller_get_current_event_state (GTK_EVENT_CONTROLLER (scroll));
     if (!(state & GDK_CONTROL_MASK))
     {
         return GDK_EVENT_PROPAGATE;
     }
 
-    if (gdk_event_get_scroll_direction (event, &direction))
+    event = gtk_event_controller_get_current_event (GTK_EVENT_CONTROLLER (scroll));
+    direction = gdk_scroll_event_get_direction (event);
+    if (direction == GDK_SCROLL_UP)
     {
-        if (direction == GDK_SCROLL_UP)
-        {
-            /* Zoom In */
-            nautilus_files_view_bump_zoom_level (directory_view, 1);
-            return GDK_EVENT_STOP;
-        }
-        else if (direction == GDK_SCROLL_DOWN)
-        {
-            /* Zoom Out */
-            nautilus_files_view_bump_zoom_level (directory_view, -1);
-            return GDK_EVENT_STOP;
-        }
+        /* Zoom In */
+        nautilus_files_view_bump_zoom_level (directory_view, 1);
+        return GDK_EVENT_STOP;
     }
-
-    if (gdk_event_get_scroll_deltas (event, &delta_x, &delta_y))
+    else if (direction == GDK_SCROLL_DOWN)
     {
-        /* try to emulate a normal scrolling event by summing deltas */
-        total_delta_y += delta_y;
-
-        if (total_delta_y >= 1)
-        {
-            total_delta_y = 0;
-            /* emulate scroll down */
-            nautilus_files_view_bump_zoom_level (directory_view, -1);
-            return GDK_EVENT_STOP;
-        }
-        else if (total_delta_y <= -1)
-        {
-            total_delta_y = 0;
-            /* emulate scroll up */
-            nautilus_files_view_bump_zoom_level (directory_view, 1);
-            return GDK_EVENT_STOP;
-        }
-        else
-        {
-            /* eat event */
-            return GDK_EVENT_STOP;
-        }
+        /* Zoom Out */
+        nautilus_files_view_bump_zoom_level (directory_view, -1);
+        return GDK_EVENT_STOP;
     }
 
     return GDK_EVENT_PROPAGATE;
@@ -9512,6 +9476,7 @@ nautilus_files_view_init (NautilusFilesView *view)
 #endif
     NautilusDirectory *scripts_directory;
     NautilusDirectory *templates_directory;
+    GtkEventController *controller;
     gchar *templates_uri;
 #if 0 && NAUTILUS_CLIPBOARD_NEEDS_GTK4_REIMPLEMENTATION
     GtkClipboard *clipboard;
@@ -9612,10 +9577,14 @@ nautilus_files_view_init (NautilusFilesView *view)
                                     GTK_POLICY_AUTOMATIC);
     gtk_widget_show (priv->scrolled_window);
 
-    g_signal_connect_swapped (priv->scrolled_window,
-                              "event",
-                              G_CALLBACK (on_event),
-                              view);
+    controller = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL |
+                                                  GTK_EVENT_CONTROLLER_SCROLL_DISCRETE);
+    gtk_widget_add_controller (priv->scrolled_window, controller);
+    gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
+    g_signal_connect (controller,
+                      "scroll",
+                      G_CALLBACK (on_scroll),
+                      view);
 
     gtk_overlay_set_child (GTK_OVERLAY (priv->overlay), priv->scrolled_window);
 


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