From 3ab63fd03b447c3d1fccd8f22d2925bf6d10ad2f Mon Sep 17 00:00:00 2001 From: panoplie <59100-panoplie@users.noreply.gitlab.gnome.org> Date: Mon, 21 Feb 2022 16:23:24 +0100 Subject: [PATCH] gtkeventcontrollerscroll: Add scroll unit getter The scroll unit is accessible through gtk_event_controller_scroll_get_unit() after the "scroll" signal reception. --- gtk/gtkeventcontrollerscroll.c | 27 +++++++++++++++++++++++++++ gtk/gtkeventcontrollerscroll.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/gtk/gtkeventcontrollerscroll.c b/gtk/gtkeventcontrollerscroll.c index 67dafb73ed..e1422e1598 100644 --- a/gtk/gtkeventcontrollerscroll.c +++ b/gtk/gtkeventcontrollerscroll.c @@ -85,6 +85,8 @@ struct _GtkEventControllerScroll double cur_dx; double cur_dy; + GdkScrollUnit cur_unit; + guint hold_timeout_id; guint active : 1; }; @@ -365,6 +367,8 @@ gtk_event_controller_scroll_handle_event (GtkEventController *controller, g_clear_handle_id (&scroll->hold_timeout_id, g_source_remove); + scroll->cur_unit = gdk_scroll_event_get_unit (event); + /* FIXME: Handle device changes */ direction = gdk_scroll_event_get_direction (event); if (direction == GDK_SCROLL_SMOOTH) @@ -497,6 +501,9 @@ gtk_event_controller_scroll_class_init (GtkEventControllerScrollClass *klass) * Signals that the widget should scroll by the * amount specified by @dx and @dy. * + * For the representation unit of the deltas, see + * [method@Gtk.EventControllerScroll.get_unit]. + * * Returns: %TRUE if the scroll event was handled, * %FALSE otherwise. */ @@ -614,3 +621,23 @@ gtk_event_controller_scroll_get_flags (GtkEventControllerScroll *scroll) return scroll->flags; } + +/** + * gtk_event_controller_scroll_get_unit: + * @scroll: a `GtkEventControllerScroll`. + * + * Gets the scroll unit of the last + * [signal@Gtk.EventControllerScroll::scroll] signal received. + * + * Returns: the scroll unit. + * + * Since: 4.8 + */ +GdkScrollUnit +gtk_event_controller_scroll_get_unit (GtkEventControllerScroll *scroll) +{ + g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_SCROLL (scroll), + GDK_SCROLL_UNIT_WHEEL); + + return scroll->cur_unit; +} diff --git a/gtk/gtkeventcontrollerscroll.h b/gtk/gtkeventcontrollerscroll.h index 7d77097255..2be1753568 100644 --- a/gtk/gtkeventcontrollerscroll.h +++ b/gtk/gtkeventcontrollerscroll.h @@ -71,6 +71,9 @@ GDK_AVAILABLE_IN_ALL GtkEventControllerScrollFlags gtk_event_controller_scroll_get_flags (GtkEventControllerScroll *scroll); +GDK_AVAILABLE_IN_4_8 +GdkScrollUnit gtk_event_controller_scroll_get_unit (GtkEventControllerScroll *scroll); + G_END_DECLS #endif /* __GTK_EVENT_CONTROLLER_SCROLL_H__ */