From ec91b2de100b966d6111497f0455d9e336944ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Date: Tue, 22 Jun 2021 18:27:14 +0200 Subject: [PATCH] gtkeventcontrollerscroll: Refactor scroll end Move the logic to end scrolling to its own function to be able to reuse it. Refactor, no functional changes. Part-of: --- gtk/gtkeventcontrollerscroll.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/gtk/gtkeventcontrollerscroll.c b/gtk/gtkeventcontrollerscroll.c index cfe284cd71..e0acee7a2e 100644 --- a/gtk/gtkeventcontrollerscroll.c +++ b/gtk/gtkeventcontrollerscroll.c @@ -250,6 +250,28 @@ gtk_event_controller_scroll_begin (GtkEventController *controller) return TRUE; } +static gboolean +gtk_event_controller_scroll_end (GtkEventController *controller) +{ + GtkEventControllerScroll *scroll = GTK_EVENT_CONTROLLER_SCROLL (controller); + + if (!scroll->active) + return FALSE; + + g_signal_emit (controller, signals[SCROLL_END], 0); + scroll->active = FALSE; + + if (scroll->flags & GTK_EVENT_CONTROLLER_SCROLL_KINETIC) + { + double vel_x, vel_y; + + scroll_history_finish (scroll, &vel_x, &vel_y); + g_signal_emit (controller, signals[DECELERATE], 0, vel_x, vel_y); + } + + return TRUE; +} + static gboolean gtk_event_controller_scroll_handle_event (GtkEventController *controller, GdkEvent *event, @@ -343,17 +365,8 @@ gtk_event_controller_scroll_handle_event (GtkEventController *controller, if (scroll->active && gdk_scroll_event_is_stop (event)) { - g_signal_emit (controller, signals[SCROLL_END], 0); - scroll->active = FALSE; + gtk_event_controller_scroll_end (controller); handled = FALSE; - - if (scroll->flags & GTK_EVENT_CONTROLLER_SCROLL_KINETIC) - { - double vel_x, vel_y; - - scroll_history_finish (scroll, &vel_x, &vel_y); - g_signal_emit (controller, signals[DECELERATE], 0, vel_x, vel_y); - } } return handled;