evdev: Move generic scroll code from evdev-mt-touchpad.c to evdev.c

So that it can be used for middle button trackpoint scrolling too.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Hans de Goede 2014-09-16 16:22:35 +02:00 committed by Peter Hutterer
parent 19648e29ab
commit 0f112646ce
4 changed files with 67 additions and 58 deletions

View file

@ -492,47 +492,7 @@ tp_post_twofinger_scroll(struct tp_dispatch *tp, uint64_t time)
dy /= nchanged;
tp_filter_motion(tp, &dx, &dy, time);
/* Require at least five px scrolling to start */
if (dy <= -5.0 || dy >= 5.0)
tp->scroll.direction |= (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
if (dx <= -5.0 || dx >= 5.0)
tp->scroll.direction |= (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
if (dy != 0.0 &&
(tp->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))) {
pointer_notify_axis(&tp->device->base,
time,
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
dy);
}
if (dx != 0.0 &&
(tp->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))) {
pointer_notify_axis(&tp->device->base,
time,
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
dx);
}
}
static void
tp_stop_scroll_events(struct tp_dispatch *tp, uint64_t time)
{
/* terminate scrolling with a zero scroll event */
if (tp->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
pointer_notify_axis(&tp->device->base,
time,
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
0);
if (tp->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
pointer_notify_axis(&tp->device->base,
time,
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
0);
tp->scroll.direction = 0;
evdev_post_scroll(tp->device, time, dx, dy);
}
static int
@ -548,7 +508,7 @@ tp_post_scroll_events(struct tp_dispatch *tp, uint64_t time)
}
if (nfingers_down != 2) {
tp_stop_scroll_events(tp, time);
evdev_stop_scroll(tp->device, time);
return 0;
}
@ -567,7 +527,7 @@ tp_post_events(struct tp_dispatch *tp, uint64_t time)
consumed |= tp_post_button_events(tp, time);
if (consumed) {
tp_stop_scroll_events(tp, time);
evdev_stop_scroll(tp->device, time);
return;
}
@ -846,14 +806,6 @@ tp_init_accel(struct tp_dispatch *tp, double diagonal)
return 0;
}
static int
tp_init_scroll(struct tp_dispatch *tp)
{
tp->scroll.direction = 0;
return 0;
}
static int
tp_init_palmdetect(struct tp_dispatch *tp,
struct evdev_device *device)
@ -909,9 +861,6 @@ tp_init(struct tp_dispatch *tp,
tp->hysteresis.margin_y =
diagonal / DEFAULT_HYSTERESIS_MARGIN_DENOMINATOR;
if (tp_init_scroll(tp) != 0)
return -1;
if (tp_init_accel(tp, diagonal) != 0)
return -1;

View file

@ -200,10 +200,6 @@ struct tp_dispatch {
} top_area;
} buttons; /* physical buttons */
struct {
enum libinput_pointer_axis direction;
} scroll;
enum touchpad_event queued;
struct {

View file

@ -1081,6 +1081,8 @@ evdev_device_create(struct libinput_seat *seat,
device->fd = fd;
device->pending_event = EVDEV_NONE;
device->devname = libevdev_get_name(device->evdev);
device->scroll.threshold = 5.0; /* Default may be overridden */
device->scroll.direction = 0;
matrix_init_identity(&device->abs.calibration);
matrix_init_identity(&device->abs.usermatrix);
@ -1265,6 +1267,53 @@ evdev_device_get_size(struct evdev_device *device,
return 0;
}
void
evdev_post_scroll(struct evdev_device *device,
uint64_t time,
double dx,
double dy)
{
if (dy <= -device->scroll.threshold || dy >= device->scroll.threshold)
device->scroll.direction |= (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
if (dx <= -device->scroll.threshold || dx >= device->scroll.threshold)
device->scroll.direction |= (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
if (dy != 0.0 &&
(device->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))) {
pointer_notify_axis(&device->base,
time,
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
dy);
}
if (dx != 0.0 &&
(device->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))) {
pointer_notify_axis(&device->base,
time,
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
dx);
}
}
void
evdev_stop_scroll(struct evdev_device *device, uint64_t time)
{
/* terminate scrolling with a zero scroll event */
if (device->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
pointer_notify_axis(&device->base,
time,
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
0);
if (device->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
pointer_notify_axis(&device->base,
time,
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
0);
device->scroll.direction = 0;
}
static void
release_pressed_keys(struct evdev_device *device)
{

View file

@ -95,6 +95,11 @@ struct evdev_device {
int dx, dy;
} rel;
struct {
double threshold;
uint32_t direction;
} scroll;
enum evdev_event_type pending_event;
enum evdev_device_seat_capability seat_caps;
enum evdev_device_tags tags;
@ -229,6 +234,16 @@ evdev_pointer_notify_button(struct evdev_device *device,
int button,
enum libinput_button_state state);
void
evdev_post_scroll(struct evdev_device *device,
uint64_t time,
double dx,
double dy);
void
evdev_stop_scroll(struct evdev_device *device, uint64_t time);
void
evdev_device_remove(struct evdev_device *device);