1From 4ef417938760f98e530c152ee50071da2af31b06 Mon Sep 17 00:00:00 2001 2From: Kristian Rietveld <kris@lanedo.com> 3Date: Sun, 2 Sep 2012 14:16:45 +0200 4Subject: [PATCH 18/68] Introduce phase field in GdkEventScroll 5 6Using the phase field it is possible to distinguish between 7events generated while the user is performing a gesture and 8momentum events that are generated after the gesture has been 9finished. 10--- 11 gdk/gdkevents.c | 1 + 12 gdk/gdkevents.h | 9 +++++++++ 13 gdk/gdkwindow.c | 1 + 14 gdk/quartz/gdkevents-quartz.c | 36 +++++++++++++++++++++++++++++++++--- 15 4 files changed, 44 insertions(+), 3 deletions(-) 16 17diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c 18index 0f8bba2..d3d67db 100644 19--- a/gdk/gdkevents.c 20+++ b/gdk/gdkevents.c 21@@ -394,6 +394,7 @@ gdk_event_new (GdkEventType type) 22 new_event->scroll.y_root = 0.; 23 new_event->scroll.delta_x = 0.; 24 new_event->scroll.delta_y = 0.; 25+ new_event->scroll.phase = GDK_EVENT_SCROLL_PHASE_NONE; 26 break; 27 case GDK_ENTER_NOTIFY: 28 case GDK_LEAVE_NOTIFY: 29diff --git a/gdk/gdkevents.h b/gdk/gdkevents.h 30index f6b4e04..765b520 100644 31--- a/gdk/gdkevents.h 32+++ b/gdk/gdkevents.h 33@@ -263,6 +263,14 @@ typedef enum 34 GDK_OWNER_CHANGE_CLOSE 35 } GdkOwnerChange; 36 37+typedef enum 38+{ 39+ GDK_EVENT_SCROLL_PHASE_NONE, 40+ GDK_EVENT_SCROLL_PHASE_START, 41+ GDK_EVENT_SCROLL_PHASE_ACTIVE, 42+ GDK_EVENT_SCROLL_PHASE_END 43+} GdkEventScrollPhase; 44+ 45 struct _GdkEventAny 46 { 47 GdkEventType type; 48@@ -340,6 +348,7 @@ struct _GdkEventScroll 49 gboolean has_deltas; 50 gdouble delta_x; 51 gdouble delta_y; 52+ GdkEventScrollPhase phase; 53 }; 54 55 struct _GdkEventKey 56diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c 57index d48751e..1843873 100644 58--- a/gdk/gdkwindow.c 59+++ b/gdk/gdkwindow.c 60@@ -10803,6 +10803,7 @@ proxy_button_event (GdkEvent *source_event, 61 event->scroll.has_deltas = source_event->scroll.has_deltas; 62 event->scroll.delta_x = source_event->scroll.delta_x; 63 event->scroll.delta_y = source_event->scroll.delta_y; 64+ event->scroll.phase = source_event->scroll.phase; 65 return TRUE; 66 67 default: 68diff --git a/gdk/quartz/gdkevents-quartz.c b/gdk/quartz/gdkevents-quartz.c 69index e7d97dc..bb4da70 100644 70--- a/gdk/quartz/gdkevents-quartz.c 71+++ b/gdk/quartz/gdkevents-quartz.c 72@@ -62,6 +62,7 @@ static GdkWindow *find_toplevel_under_pointer (GdkDisplay *display, 73 - (BOOL) hasPreciseScrollingDeltas; 74 - (CGFloat) scrollingDeltaX; 75 - (CGFloat) scrollingDeltaY; 76+- (int) phase; 77 @end 78 79 80@@ -990,6 +991,7 @@ fill_scroll_event (GdkWindow *window, 81 gboolean has_deltas, 82 gdouble delta_x, 83 gdouble delta_y, 84+ GdkEventScrollPhase phase, 85 GdkScrollDirection direction) 86 { 87 GdkWindowObject *private; 88@@ -1012,6 +1014,7 @@ fill_scroll_event (GdkWindow *window, 89 event->scroll.has_deltas = has_deltas; 90 event->scroll.delta_x = delta_x; 91 event->scroll.delta_y = delta_y; 92+ event->scroll.phase = phase; 93 } 94 95 static void 96@@ -1300,6 +1303,28 @@ test_resize (NSEvent *event, GdkWindow *toplevel, gint x, gint y) 97 return FALSE; 98 } 99 100+static GdkEventScrollPhase 101+gdk_event_scroll_phase_from_ns_event_phase (NSUInteger phase) 102+{ 103+ switch (phase) 104+ { 105+ case 0: 106+ return GDK_EVENT_SCROLL_PHASE_NONE; 107+ 108+ case 1 << 0: 109+ return GDK_EVENT_SCROLL_PHASE_START; 110+ 111+ case 1 << 1: 112+ case 1 << 2: 113+ return GDK_EVENT_SCROLL_PHASE_ACTIVE; 114+ 115+ case 1 << 3: 116+ return GDK_EVENT_SCROLL_PHASE_END; 117+ } 118+ 119+ return GDK_EVENT_SCROLL_PHASE_NONE; 120+} 121+ 122 static gboolean 123 gdk_event_translate (GdkEvent *event, 124 NSEvent *nsevent) 125@@ -1491,6 +1516,7 @@ gdk_event_translate (GdkEvent *event, 126 if (gdk_quartz_osx_version() >= GDK_OSX_LION && 127 [(id <PreciseDeltas>) nsevent hasPreciseScrollingDeltas]) 128 { 129+ GdkEventScrollPhase phase; 130 dx = [(id <PreciseDeltas>) nsevent scrollingDeltaX]; 131 dy = [(id <PreciseDeltas>) nsevent scrollingDeltaY]; 132 133@@ -1509,8 +1535,10 @@ gdk_event_translate (GdkEvent *event, 134 direction = GDK_SCROLL_LEFT; 135 } 136 137+ phase = gdk_event_scroll_phase_from_ns_event_phase ([(id <PreciseDeltas>) nsevent phase]); 138+ 139 fill_scroll_event (window, event, nsevent, x, y, x_root, y_root, 140- TRUE, -dx, -dy, direction); 141+ TRUE, -dx, -dy, phase, direction); 142 } 143 else 144 { 145@@ -1525,7 +1553,8 @@ gdk_event_translate (GdkEvent *event, 146 direction = GDK_SCROLL_UP; 147 148 fill_scroll_event (window, event, nsevent, x, y, x_root, y_root, 149- FALSE, 0.0, fabs (dy), direction); 150+ FALSE, 0.0, fabs (dy), GDK_EVENT_SCROLL_PHASE_NONE, 151+ direction); 152 } 153 else if (dx != 0.0) 154 { 155@@ -1535,7 +1564,8 @@ gdk_event_translate (GdkEvent *event, 156 direction = GDK_SCROLL_LEFT; 157 158 fill_scroll_event (window, event, nsevent, x, y, x_root, y_root, 159- FALSE, fabs (dx), 0.0, direction); 160+ FALSE, fabs (dx), 0.0, GDK_EVENT_SCROLL_PHASE_NONE, 161+ direction); 162 } 163 } 164 } 165-- 1661.7.10.2 (Apple Git-33) 167