[gtk: 3/9] gdk/events: Set discrete scroll deltas in its constructor
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk: 3/9] gdk/events: Set discrete scroll deltas in its constructor
- Date: Wed, 10 Aug 2022 16:51:56 +0000 (UTC)
commit 6ebb38e12e1d096c02e6eee3148552904ff87d81
Author: José Expósito <jose exposito89 gmail com>
Date: Mon Sep 20 19:59:45 2021 +0200
gdk/events: Set discrete scroll deltas in its constructor
Instead of calculating the discrete scroll deltas in
GtkEventControllerScroll, move that code to the event constructor and
access the precalculated values using gdk_scroll_event_get_deltas.
Refactor, no functional changes.
gdk/gdkevents.c | 23 +++++++++++++++++++++++
gtk/gtkeventcontrollerscroll.c | 20 +-------------------
2 files changed, 24 insertions(+), 19 deletions(-)
---
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
index 0e78d337d2..4b61715575 100644
--- a/gdk/gdkevents.c
+++ b/gdk/gdkevents.c
@@ -2368,10 +2368,33 @@ gdk_scroll_event_new_discrete (GdkSurface *surface,
GdkScrollDirection direction)
{
GdkScrollEvent *self = gdk_event_alloc (GDK_SCROLL, surface, device, time);
+ double delta_x = 0, delta_y = 0;
+
+ switch (direction)
+ {
+ case GDK_SCROLL_UP:
+ delta_y = -1;
+ break;
+ case GDK_SCROLL_DOWN:
+ delta_y = 1;
+ break;
+ case GDK_SCROLL_LEFT:
+ delta_x = -1;
+ break;
+ case GDK_SCROLL_RIGHT:
+ delta_x = 1;
+ break;
+ case GDK_SCROLL_SMOOTH:
+ default:
+ g_assert_not_reached ();
+ break;
+ }
self->tool = tool != NULL ? g_object_ref (tool) : NULL;
self->state = state;
self->direction = direction;
+ self->delta_x = delta_x;
+ self->delta_y = delta_y;
self->unit = GDK_SCROLL_UNIT_WHEEL;
return (GdkEvent *) self;
diff --git a/gtk/gtkeventcontrollerscroll.c b/gtk/gtkeventcontrollerscroll.c
index d78cc01770..e51cb7b241 100644
--- a/gtk/gtkeventcontrollerscroll.c
+++ b/gtk/gtkeventcontrollerscroll.c
@@ -416,25 +416,7 @@ gtk_event_controller_scroll_handle_event (GtkEventController *controller,
}
else
{
- switch (direction)
- {
- case GDK_SCROLL_UP:
- dy -= 1;
- break;
- case GDK_SCROLL_DOWN:
- dy += 1;
- break;
- case GDK_SCROLL_LEFT:
- dx -= 1;
- break;
- case GDK_SCROLL_RIGHT:
- dx += 1;
- break;
- case GDK_SCROLL_SMOOTH:
- default:
- g_assert_not_reached ();
- break;
- }
+ gdk_scroll_event_get_deltas (event, &dx, &dy);
if ((scroll->flags & GTK_EVENT_CONTROLLER_SCROLL_VERTICAL) == 0)
dy = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]