diff options
author | António Fernandes <antoniof@gnome.org> | 2021-12-20 16:53:36 +0000 |
---|---|---|
committer | António Fernandes <antoniof@gnome.org> | 2022-01-05 12:55:14 +0000 |
commit | 2124425cc938bac18ad704554a0f511fdaf07cc9 (patch) | |
tree | 06bc0c9628258147311e75f57f345cc4e9b21e5c | |
parent | 9049f14925801a84599d905293196e33de76185a (diff) | |
download | nautilus-2124425cc938bac18ad704554a0f511fdaf07cc9.tar.gz |
--- WIP --- Scroll-event for ZOOM
-rw-r--r-- | src/nautilus-files-view.c | 83 |
1 files 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); |