From ff02bd1b5b821d67efbf082fdca9f7109c10a025 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 17 Feb 2015 11:40:17 +0100 Subject: [PATCH] touchpad: Move gesture handling code to evdev-mt-touchpad-gestures.c Just moving some code around, no functional changes. Signed-off-by: Hans de Goede Reviewed-by: Peter Hutterer --- src/evdev-mt-touchpad-gestures.c | 94 +++++++++++++++++++++++++++++++- src/evdev-mt-touchpad.c | 92 ------------------------------- src/evdev-mt-touchpad.h | 9 --- 3 files changed, 93 insertions(+), 102 deletions(-) diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c index 4317d282..3a013f5a 100644 --- a/src/evdev-mt-touchpad-gestures.c +++ b/src/evdev-mt-touchpad-gestures.c @@ -31,7 +31,53 @@ #define DEFAULT_GESTURE_SWITCH_TIMEOUT 100 /* ms */ -void +static void +tp_get_average_touches_delta(struct tp_dispatch *tp, double *dx, double *dy) +{ + struct tp_touch *t; + int nchanged = 0; + double tmpx, tmpy; + + *dx = 0.0; + *dy = 0.0; + + tp_for_each_touch(tp, t) { + if (tp_touch_active(tp, t) && t->dirty) { + nchanged++; + tp_get_delta(t, &tmpx, &tmpy); + + *dx += tmpx; + *dy += tmpy; + } + } + + if (nchanged == 0) + return; + + *dx /= nchanged; + *dy /= nchanged; +} + +static void +tp_get_combined_touches_delta(struct tp_dispatch *tp, double *dx, double *dy) +{ + struct tp_touch *t; + double tdx, tdy; + unsigned int i; + + for (i = 0; i < tp->real_touches; i++) { + t = &tp->touches[i]; + + if (!tp_touch_active(tp, t) || !t->dirty) + continue; + + tp_get_delta(t, &tdx, &tdy); + *dx += tdx; + *dy += tdy; + } +} + +static void tp_gesture_start(struct tp_dispatch *tp, uint64_t time) { if (tp->gesture.started) @@ -45,6 +91,44 @@ tp_gesture_start(struct tp_dispatch *tp, uint64_t time) tp->gesture.started = true; } +static void +tp_gesture_post_pointer_motion(struct tp_dispatch *tp, uint64_t time) +{ + double dx = 0.0, dy = 0.0; + double dx_unaccel, dy_unaccel; + + /* When a clickpad is clicked, combine motion of all active touches */ + if (tp->buttons.is_clickpad && tp->buttons.state) + tp_get_combined_touches_delta(tp, &dx, &dy); + else + tp_get_average_touches_delta(tp, &dx, &dy); + + tp_filter_motion(tp, &dx, &dy, &dx_unaccel, &dy_unaccel, time); + + if (dx != 0.0 || dy != 0.0 || dx_unaccel != 0.0 || dy_unaccel != 0.0) { + pointer_notify_motion(&tp->device->base, time, + dx, dy, dx_unaccel, dy_unaccel); + } +} + +static void +tp_gesture_post_twofinger_scroll(struct tp_dispatch *tp, uint64_t time) +{ + double dx = 0, dy =0; + + tp_get_average_touches_delta(tp, &dx, &dy); + tp_filter_motion(tp, &dx, &dy, NULL, NULL, time); + + if (dx == 0.0 && dy == 0.0) + return; + + tp_gesture_start(tp, time); + evdev_post_scroll(tp->device, + time, + LIBINPUT_POINTER_AXIS_SOURCE_FINGER, + dx, dy); +} + void tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time) { @@ -72,6 +156,14 @@ tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time) } } +void +tp_gesture_stop_twofinger_scroll(struct tp_dispatch *tp, uint64_t time) +{ + evdev_stop_scroll(tp->device, + time, + LIBINPUT_POINTER_AXIS_SOURCE_FINGER); +} + void tp_gesture_stop(struct tp_dispatch *tp, uint64_t time) { diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 32ed7bf5..b90d84c5 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -493,59 +493,6 @@ tp_palm_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) t->palm.y = t->y; } -static void -tp_get_average_touches_delta(struct tp_dispatch *tp, double *dx, double *dy) -{ - struct tp_touch *t; - int nchanged = 0; - double tmpx, tmpy; - - *dx = 0.0; - *dy = 0.0; - - tp_for_each_touch(tp, t) { - if (tp_touch_active(tp, t) && t->dirty) { - nchanged++; - tp_get_delta(t, &tmpx, &tmpy); - - *dx += tmpx; - *dy += tmpy; - } - } - - if (nchanged == 0) - return; - - *dx /= nchanged; - *dy /= nchanged; -} - -void -tp_gesture_post_twofinger_scroll(struct tp_dispatch *tp, uint64_t time) -{ - double dx = 0, dy =0; - - tp_get_average_touches_delta(tp, &dx, &dy); - tp_filter_motion(tp, &dx, &dy, NULL, NULL, time); - - if (dx == 0.0 && dy == 0.0) - return; - - tp_gesture_start(tp, time); - evdev_post_scroll(tp->device, - time, - LIBINPUT_POINTER_AXIS_SOURCE_FINGER, - dx, dy); -} - -void -tp_gesture_stop_twofinger_scroll(struct tp_dispatch *tp, uint64_t time) -{ - evdev_stop_scroll(tp->device, - time, - LIBINPUT_POINTER_AXIS_SOURCE_FINGER); -} - static void tp_unhover_touches(struct tp_dispatch *tp, uint64_t time) { @@ -679,45 +626,6 @@ tp_post_process_state(struct tp_dispatch *tp, uint64_t time) tp->queued = TOUCHPAD_EVENT_NONE; } -static void -tp_get_combined_touches_delta(struct tp_dispatch *tp, double *dx, double *dy) -{ - struct tp_touch *t; - double tdx, tdy; - unsigned int i; - - for (i = 0; i < tp->real_touches; i++) { - t = tp_get_touch(tp, i); - - if (!tp_touch_active(tp, t) || !t->dirty) - continue; - - tp_get_delta(t, &tdx, &tdy); - *dx += tdx; - *dy += tdy; - } -} - -void -tp_gesture_post_pointer_motion(struct tp_dispatch *tp, uint64_t time) -{ - double dx = 0.0, dy = 0.0; - double dx_unaccel, dy_unaccel; - - /* When a clickpad is clicked, combine motion of all active touches */ - if (tp->buttons.is_clickpad && tp->buttons.state) - tp_get_combined_touches_delta(tp, &dx, &dy); - else - tp_get_average_touches_delta(tp, &dx, &dy); - - tp_filter_motion(tp, &dx, &dy, &dx_unaccel, &dy_unaccel, time); - - if (dx != 0.0 || dy != 0.0 || dx_unaccel != 0.0 || dy_unaccel != 0.0) { - pointer_notify_motion(&tp->device->base, time, - dx, dy, dx_unaccel, dy_unaccel); - } -} - static void tp_post_events(struct tp_dispatch *tp, uint64_t time) { diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h index 3e4ac0fd..f04cc112 100644 --- a/src/evdev-mt-touchpad.h +++ b/src/evdev-mt-touchpad.h @@ -373,9 +373,6 @@ tp_init_gesture(struct tp_dispatch *tp); void tp_remove_gesture(struct tp_dispatch *tp); -void -tp_gesture_start(struct tp_dispatch *tp, uint64_t time); - void tp_gesture_stop(struct tp_dispatch *tp, uint64_t time); @@ -385,13 +382,7 @@ tp_gesture_handle_state(struct tp_dispatch *tp, uint64_t time); void tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time); -void -tp_gesture_post_twofinger_scroll(struct tp_dispatch *tp, uint64_t time); - void tp_gesture_stop_twofinger_scroll(struct tp_dispatch *tp, uint64_t time); -void -tp_gesture_post_pointer_motion(struct tp_dispatch *tp, uint64_t time); - #endif