From: Hans de Goede Date: Tue, 16 Sep 2014 14:22:35 +0000 (+0200) Subject: evdev: Move generic scroll code from evdev-mt-touchpad.c to evdev.c X-Git-Tag: 0.7.0~128 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0f112646ceb24501058708489febed8854444349;p=platform%2Fupstream%2Flibinput.git 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 Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index d9f6fd7e..d1e4acd4 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -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; diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h index b67b063e..8671f797 100644 --- a/src/evdev-mt-touchpad.h +++ b/src/evdev-mt-touchpad.h @@ -200,10 +200,6 @@ struct tp_dispatch { } top_area; } buttons; /* physical buttons */ - struct { - enum libinput_pointer_axis direction; - } scroll; - enum touchpad_event queued; struct { diff --git a/src/evdev.c b/src/evdev.c index f7fd2b4f..45020bad 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -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) { diff --git a/src/evdev.h b/src/evdev.h index f5345fa3..311dddc8 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -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);