mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-01-12 04:30:23 +01:00
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 <hdegoede@redhat.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
18887f90ee
commit
ff02bd1b5b
3 changed files with 93 additions and 102 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue