Skip to content

Commit efe9e18

Browse files
author
Robin Müller
committed
Cleaned up code
- removed scroll.last_point as this is the same as mt_slots.last_points[0] - added macro to determine the current_gesture depending on the scroll enabled flag and the corresponding axis of the both finger vectors
1 parent 75b500f commit efe9e18

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

src/gesture_detection.c

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
#include "gesture_detection.h"
3737

38-
// FIXME use 2 for SCROLL_FINGER_COUNT as soon as possible
3938
#define SCROLL_FINGER_COUNT 2
4039
#define SCROLL_SLOW_DOWN_FACTOR -0.006
4140

@@ -51,7 +50,6 @@ typedef struct mt_slots {
5150
} mt_slots_t;
5251

5352
typedef struct scroll {
54-
point_t last_point;
5553
struct input_event last_x_abs_event;
5654
struct input_event last_y_abs_event;
5755
double x_velocity;
@@ -100,7 +98,6 @@ static void init_gesture() {
10098
if (finger_count == SCROLL_FINGER_COUNT) {
10199
gesture_start.distance = calculate_distance(mt_slots.points[0], mt_slots.points[1]);
102100
scroll.width = 0;
103-
scroll.last_point = mt_slots.points[0];
104101
scroll.x_velocity = 0;
105102
scroll.y_velocity = 0;
106103
current_gesture = NO_GESTURE;
@@ -165,7 +162,6 @@ static void process_abs_event(struct input_event event) {
165162
scroll.x_velocity = -calcualte_velocity(scroll.last_x_abs_event, event);
166163
}
167164
scroll.last_x_abs_event = event;
168-
scroll.last_point.x = mt_slots.points[0].x;
169165
}
170166
mt_slots.last_points[mt_slots.active].x = mt_slots.points[mt_slots.active].x;
171167
// store the current x position for the current mt_slot
@@ -180,7 +176,6 @@ static void process_abs_event(struct input_event event) {
180176
scroll.y_velocity = calcualte_velocity(scroll.last_y_abs_event, event);
181177
}
182178
scroll.last_y_abs_event = event;
183-
scroll.last_point.y = mt_slots.points[0].y;
184179
}
185180
mt_slots.last_points[mt_slots.active].y = mt_slots.points[mt_slots.active].y;
186181
// 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) {
233228
return result;
234229
}
235230

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+
236243
static input_event_array_t *process_syn_event(struct input_event event,
237244
configuration_t config,
238245
point_t thresholds) {
@@ -259,16 +266,7 @@ static input_event_array_t *process_syn_event(struct input_event event,
259266
y_distance = gesture_start.point.y - mt_slots.points[0].y;
260267
if (fabs(x_distance) > fabs(y_distance)) {
261268
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);
272270
}
273271

274272
if (current_gesture == SWIPE) {
@@ -278,20 +276,11 @@ static input_event_array_t *process_syn_event(struct input_event event,
278276
direction = RIGHT;
279277
}
280278
} 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);
282280
}
283281
} else {
284282
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);
295284
}
296285

297286
if (current_gesture == SWIPE) {
@@ -301,7 +290,7 @@ static input_event_array_t *process_syn_event(struct input_event event,
301290
direction = DOWN;
302291
}
303292
} 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);
305294
}
306295
}
307296
}

0 commit comments

Comments
 (0)