Skip to content

Commit 75b500f

Browse files
author
Robin Müller
committed
Zooming is independent from the swipe direction so handle it without determine the direction
1 parent 69bb71b commit 75b500f

File tree

1 file changed

+57
-58
lines changed

1 file changed

+57
-58
lines changed

src/gesture_detection.c

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -239,71 +239,70 @@ static input_event_array_t *process_syn_event(struct input_event event,
239239
input_event_array_t *result = NULL;
240240
if (finger_count > 0 && event.code == SYN_REPORT) {
241241
direction_t direction = NONE;
242-
243-
int32_t x_distance, y_distance;
244-
x_distance = gesture_start.point.x - mt_slots.points[0].x;
245-
y_distance = gesture_start.point.y - mt_slots.points[0].y;
246-
if (fabs(x_distance) > fabs(y_distance)) {
247-
if (current_gesture == NO_GESTURE) {
248-
point_t v1 = create_direction_vector(mt_slots.last_points[0], mt_slots.points[0]);
249-
point_t v2 = create_direction_vector(mt_slots.last_points[1], mt_slots.points[1]);
250-
// if horizontal scrolling is enable, the finger_count matches SCROLL_FINGER_COUNT and
251-
// the x direction of the direction vectors for both fingers is equal the current_gesture
252-
// will be SCROLL
253-
if (config.scroll.horz && finger_count == SCROLL_FINGER_COUNT && v1.x != 0 && v1.x == v2.x) {
254-
current_gesture = SCROLL;
255-
// if zooming is enable, the finger_count matches SCROLL_FINGER_COUNT and the direction
256-
// vectors for both fingers are opposed to each other the current_gesture will be ZOOM
257-
} else if (config.zoom.enabled && finger_count == SCROLL_FINGER_COUNT && (v1.x != v2.x || v1.y != v2.y)) {
258-
current_gesture = ZOOM;
259-
// if no scrolling and zooming is enabled or the finger_count does not match
260-
// SCROLL_FINGER_COUNT the current_gesture will be SWIPE
261-
} else if ((!config.scroll.horz && !config.zoom.enabled) || finger_count != SCROLL_FINGER_COUNT) {
262-
current_gesture = SWIPE;
263-
}
242+
point_t v1;
243+
point_t v2;
244+
if (current_gesture == NO_GESTURE) {
245+
v1 = create_direction_vector(mt_slots.last_points[0], mt_slots.points[0]);
246+
v2 = create_direction_vector(mt_slots.last_points[1], mt_slots.points[1]);
247+
// if zooming is enable, the finger_count matches SCROLL_FINGER_COUNT and the direction
248+
// vectors for both fingers are opposed to each other the current_gesture will be ZOOM
249+
if (config.zoom.enabled && finger_count == SCROLL_FINGER_COUNT && (v1.x != v2.x || v1.y != v2.y)) {
250+
current_gesture = ZOOM;
264251
}
252+
}
265253

266-
if (current_gesture == SWIPE) {
267-
if (x_distance > thresholds.x) {
268-
direction = LEFT;
269-
} else if (x_distance < -thresholds.x) {
270-
direction = RIGHT;
254+
if (current_gesture == ZOOM) {
255+
printf("zoom\n");
256+
} else {
257+
int32_t x_distance, y_distance;
258+
x_distance = gesture_start.point.x - mt_slots.points[0].x;
259+
y_distance = gesture_start.point.y - mt_slots.points[0].y;
260+
if (fabs(x_distance) > fabs(y_distance)) {
261+
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+
}
271272
}
272-
} else if (current_gesture == SCROLL) {
273+
274+
if (current_gesture == SWIPE) {
275+
if (x_distance > thresholds.x) {
276+
direction = LEFT;
277+
} else if (x_distance < -thresholds.x) {
278+
direction = RIGHT;
279+
}
280+
} else if (current_gesture == SCROLL) {
273281
result = do_scroll(scroll.last_point.x - mt_slots.points[0].x, config.scroll.horz_delta, REL_HWHEEL);
274-
} else if (current_gesture == ZOOM) {
275-
printf("zoom\n");
276-
}
277-
} else {
278-
if (current_gesture == NO_GESTURE) {
279-
point_t v1 = create_direction_vector(mt_slots.last_points[0], mt_slots.points[0]);
280-
point_t v2 = create_direction_vector(mt_slots.last_points[1], mt_slots.points[1]);
281-
// if vertical scrolling is enable, the finger_count matches SCROLL_FINGER_COUNT and
282-
// the y direction of the direction vectors for both fingers is equal the current_gesture
283-
// will be SCROLL
284-
if (config.scroll.vert && finger_count == SCROLL_FINGER_COUNT && v1.y != 0 && v1.y == v2.y) {
285-
current_gesture = SCROLL;
286-
// if zooming is enable, the finger_count matches SCROLL_FINGER_COUNT and the direction
287-
// vectors for both fingers are opposed to each other the current_gesture will be ZOOM
288-
} else if (config.zoom.enabled && finger_count == SCROLL_FINGER_COUNT && (v1.x != v2.x || v1.y != v2.y)) {
289-
current_gesture = ZOOM;
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;
294282
}
295-
}
283+
} else {
284+
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+
}
295+
}
296296

297-
if (current_gesture == SWIPE) {
298-
if (y_distance > thresholds.y) {
299-
direction = UP;
300-
} else if (y_distance < -thresholds.y) {
301-
direction = DOWN;
297+
if (current_gesture == SWIPE) {
298+
if (y_distance > thresholds.y) {
299+
direction = UP;
300+
} else if (y_distance < -thresholds.y) {
301+
direction = DOWN;
302+
}
303+
} else if (current_gesture == SCROLL) {
304+
result = do_scroll(mt_slots.points[0].y - scroll.last_point.y, config.scroll.vert_delta, REL_WHEEL);
302305
}
303-
} else if (current_gesture == SCROLL) {
304-
result = do_scroll(mt_slots.points[0].y - scroll.last_point.y, config.scroll.vert_delta, REL_WHEEL);
305-
} else if (current_gesture == ZOOM) {
306-
printf("zoom\n");
307306
}
308307
}
309308
if (direction != NONE) {

0 commit comments

Comments
 (0)