35
35
36
36
#include "gesture_detection.h"
37
37
38
- // FIXME use 2 for SCROLL_FINGER_COUNT as soon as possible
39
38
#define SCROLL_FINGER_COUNT 2
40
39
#define SCROLL_SLOW_DOWN_FACTOR -0.006
41
40
@@ -51,7 +50,6 @@ typedef struct mt_slots {
51
50
} mt_slots_t ;
52
51
53
52
typedef struct scroll {
54
- point_t last_point ;
55
53
struct input_event last_x_abs_event ;
56
54
struct input_event last_y_abs_event ;
57
55
double x_velocity ;
@@ -100,7 +98,6 @@ static void init_gesture() {
100
98
if (finger_count == SCROLL_FINGER_COUNT ) {
101
99
gesture_start .distance = calculate_distance (mt_slots .points [0 ], mt_slots .points [1 ]);
102
100
scroll .width = 0 ;
103
- scroll .last_point = mt_slots .points [0 ];
104
101
scroll .x_velocity = 0 ;
105
102
scroll .y_velocity = 0 ;
106
103
current_gesture = NO_GESTURE ;
@@ -165,7 +162,6 @@ static void process_abs_event(struct input_event event) {
165
162
scroll .x_velocity = - calcualte_velocity (scroll .last_x_abs_event , event );
166
163
}
167
164
scroll .last_x_abs_event = event ;
168
- scroll .last_point .x = mt_slots .points [0 ].x ;
169
165
}
170
166
mt_slots .last_points [mt_slots .active ].x = mt_slots .points [mt_slots .active ].x ;
171
167
// store the current x position for the current mt_slot
@@ -180,7 +176,6 @@ static void process_abs_event(struct input_event event) {
180
176
scroll .y_velocity = calcualte_velocity (scroll .last_y_abs_event , event );
181
177
}
182
178
scroll .last_y_abs_event = event ;
183
- scroll .last_point .y = mt_slots .points [0 ].y ;
184
179
}
185
180
mt_slots .last_points [mt_slots .active ].y = mt_slots .points [mt_slots .active ].y ;
186
181
// store the current y position for the current mt_slot
@@ -233,6 +228,18 @@ static point_t create_direction_vector(point_t p1, point_t p2) {
233
228
return result ;
234
229
}
235
230
231
+ #define determine_gesture (scroll_enabled , v1 , v2 ) \
232
+ /* if scrolling is enable, the finger_count matches SCROLL_FINGER_COUNT and\
233
+ the direction of the direction vectors for both fingers is equal the current_gesture\
234
+ will be SCROLL*/ \
235
+ if (scroll_enabled && finger_count == SCROLL_FINGER_COUNT && v1 != 0 && v1 == v2) { \
236
+ current_gesture = SCROLL; \
237
+ /* if no scrolling and zooming is enabled or the finger_count does not match\
238
+ SCROLL_FINGER_COUNT the current_gesture will be SWIPE*/ \
239
+ } else if (!scroll_enabled || finger_count != SCROLL_FINGER_COUNT ) { \
240
+ current_gesture = SWIPE ; \
241
+ }
242
+
236
243
static input_event_array_t * process_syn_event (struct input_event event ,
237
244
configuration_t config ,
238
245
point_t thresholds ) {
@@ -259,16 +266,7 @@ static input_event_array_t *process_syn_event(struct input_event event,
259
266
y_distance = gesture_start .point .y - mt_slots .points [0 ].y ;
260
267
if (fabs (x_distance ) > fabs (y_distance )) {
261
268
if (current_gesture == NO_GESTURE ) {
262
- // if horizontal scrolling is enable, the finger_count matches SCROLL_FINGER_COUNT and
263
- // the x direction of the direction vectors for both fingers is equal the current_gesture
264
- // will be SCROLL
265
- if (config .scroll .horz && finger_count == SCROLL_FINGER_COUNT && v1 .x != 0 && v1 .x == v2 .x ) {
266
- current_gesture = SCROLL ;
267
- // if no scrolling and zooming is enabled or the finger_count does not match
268
- // SCROLL_FINGER_COUNT the current_gesture will be SWIPE
269
- } else if ((!config .scroll .horz && !config .zoom .enabled ) || finger_count != SCROLL_FINGER_COUNT ) {
270
- current_gesture = SWIPE ;
271
- }
269
+ determine_gesture (config .scroll .horz , v1 .x , v2 .x );
272
270
}
273
271
274
272
if (current_gesture == SWIPE ) {
@@ -278,20 +276,11 @@ static input_event_array_t *process_syn_event(struct input_event event,
278
276
direction = RIGHT ;
279
277
}
280
278
} else if (current_gesture == SCROLL ) {
281
- result = do_scroll (scroll . last_point .x - mt_slots .points [0 ].x , config .scroll .horz_delta , REL_HWHEEL );
279
+ result = do_scroll (mt_slots . last_points [ 0 ] .x - mt_slots .points [0 ].x , config .scroll .horz_delta , REL_HWHEEL );
282
280
}
283
281
} else {
284
282
if (current_gesture == NO_GESTURE ) {
285
- // if vertical scrolling is enable, the finger_count matches SCROLL_FINGER_COUNT and
286
- // the y direction of the direction vectors for both fingers is equal the current_gesture
287
- // will be SCROLL
288
- if (config .scroll .vert && finger_count == SCROLL_FINGER_COUNT && v1 .y != 0 && v1 .y == v2 .y ) {
289
- current_gesture = SCROLL ;
290
- // if no scrolling and zooming is enabled or the finger_count does not match
291
- // SCROLL_FINGER_COUNT the current_gesture will be SWIPE
292
- } else if ((!config .scroll .vert && !config .zoom .enabled ) || finger_count != SCROLL_FINGER_COUNT ) {
293
- current_gesture = SWIPE ;
294
- }
283
+ determine_gesture (config .scroll .vert , v1 .y , v2 .y );
295
284
}
296
285
297
286
if (current_gesture == SWIPE ) {
@@ -301,7 +290,7 @@ static input_event_array_t *process_syn_event(struct input_event event,
301
290
direction = DOWN ;
302
291
}
303
292
} else if (current_gesture == SCROLL ) {
304
- result = do_scroll (mt_slots .points [0 ].y - scroll . last_point .y , config .scroll .vert_delta , REL_WHEEL );
293
+ result = do_scroll (mt_slots .points [0 ].y - mt_slots . last_points [ 0 ] .y , config .scroll .vert_delta , REL_WHEEL );
305
294
}
306
295
}
307
296
}
0 commit comments