diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2014-11-18 11:01:10 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2014-11-20 08:18:10 +1000 |
commit | 044b11ec3595d88b2dd762bea95dcb8fbd53a86e (patch) | |
tree | c0ad7ed52967ab4ed981c4e6b4f9763001860cdd | |
parent | 8630a8e0c28de32dde34d01a97b703ed3840a285 (diff) | |
download | libinput-044b11ec3595d88b2dd762bea95dcb8fbd53a86e.tar.gz |
evdev: move natural scrolling configuration into evdev
We're about to add natural scroll support to other devices as well, let's
share the code.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r-- | src/evdev-mt-touchpad.c | 57 | ||||
-rw-r--r-- | src/evdev-mt-touchpad.h | 2 | ||||
-rw-r--r-- | src/evdev.c | 49 | ||||
-rw-r--r-- | src/evdev.h | 6 |
4 files changed, 58 insertions, 56 deletions
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 8266c983..9265a8a9 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -494,11 +494,6 @@ tp_post_twofinger_scroll(struct tp_dispatch *tp, uint64_t time) tp_filter_motion(tp, &dx, &dy, time); - if (tp->scroll.natural_scrolling_enabled) { - dx = -dx; - dy = -dy; - } - evdev_post_scroll(tp->device, time, dx, dy); } @@ -907,47 +902,6 @@ tp_init_accel(struct tp_dispatch *tp, double diagonal) return 0; } -static int -tp_scroll_config_natural_has(struct libinput_device *device) -{ - return 1; -} - -static enum libinput_config_status -tp_scroll_config_natural_set(struct libinput_device *device, - int enabled) -{ - struct evdev_dispatch *dispatch; - struct tp_dispatch *tp = NULL; - - dispatch = ((struct evdev_device *) device)->dispatch; - tp = container_of(dispatch, tp, base); - - tp->scroll.natural_scrolling_enabled = enabled ? true : false; - - return LIBINPUT_CONFIG_STATUS_SUCCESS; -} - -static int -tp_scroll_config_natural_get(struct libinput_device *device) -{ - struct evdev_dispatch *dispatch; - struct tp_dispatch *tp = NULL; - - dispatch = ((struct evdev_device *) device)->dispatch; - tp = container_of(dispatch, tp, base); - - return tp->scroll.natural_scrolling_enabled ? 1 : 0; -} - -static int -tp_scroll_config_natural_get_default(struct libinput_device *device) -{ - /* could enable this on Apple touchpads. could do that, could - * very well do that... */ - return 0; -} - static uint32_t tp_scroll_config_scroll_mode_get_modes(struct libinput_device *device) { @@ -993,15 +947,10 @@ tp_scroll_config_scroll_mode_get_default_mode(struct libinput_device *device) } static int -tp_init_scroll(struct tp_dispatch *tp) +tp_init_scroll(struct tp_dispatch *tp, struct evdev_device *device) { - tp->scroll.config_natural.has = tp_scroll_config_natural_has; - tp->scroll.config_natural.set_enabled = tp_scroll_config_natural_set; - tp->scroll.config_natural.get_enabled = tp_scroll_config_natural_get; - tp->scroll.config_natural.get_default_enabled = tp_scroll_config_natural_get_default; - tp->scroll.natural_scrolling_enabled = false; - tp->device->base.config.natural_scroll = &tp->scroll.config_natural; + evdev_init_natural_scroll(device); tp->scroll.config_mode.get_modes = tp_scroll_config_scroll_mode_get_modes; tp->scroll.config_mode.set_mode = tp_scroll_config_scroll_mode_set_mode; @@ -1096,7 +1045,7 @@ tp_init(struct tp_dispatch *tp, if (tp_init_sendevents(tp, device) != 0) return -1; - if (tp_init_scroll(tp) != 0) + if (tp_init_scroll(tp, device) != 0) return -1; device->seat_caps |= EVDEV_DEVICE_POINTER; diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h index 4d7b8a90..4ca810f5 100644 --- a/src/evdev-mt-touchpad.h +++ b/src/evdev-mt-touchpad.h @@ -202,9 +202,7 @@ struct tp_dispatch { } buttons; /* physical buttons */ struct { - struct libinput_device_config_natural_scroll config_natural; struct libinput_device_config_scroll_mode config_mode; - bool natural_scrolling_enabled; enum libinput_config_scroll_mode mode; } scroll; diff --git a/src/evdev.c b/src/evdev.c index 89c68028..d0ddc374 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -968,6 +968,50 @@ evdev_init_sendevents(struct evdev_device *device, dispatch->sendevents.config.get_default_mode = evdev_sendevents_get_default_mode; } +static int +evdev_scroll_config_natural_has(struct libinput_device *device) +{ + return 1; +} + +static enum libinput_config_status +evdev_scroll_config_natural_set(struct libinput_device *device, + int enabled) +{ + struct evdev_device *dev = (struct evdev_device *)device; + + dev->scroll.natural_scrolling_enabled = enabled ? true : false; + + return LIBINPUT_CONFIG_STATUS_SUCCESS; +} + +static int +evdev_scroll_config_natural_get(struct libinput_device *device) +{ + struct evdev_device *dev = (struct evdev_device *)device; + + return dev->scroll.natural_scrolling_enabled ? 1 : 0; +} + +static int +evdev_scroll_config_natural_get_default(struct libinput_device *device) +{ + /* could enable this on Apple touchpads. could do that, could + * very well do that... */ + return 0; +} + +void +evdev_init_natural_scroll(struct evdev_device *device) +{ + device->scroll.config_natural.has = evdev_scroll_config_natural_has; + device->scroll.config_natural.set_enabled = evdev_scroll_config_natural_set; + device->scroll.config_natural.get_enabled = evdev_scroll_config_natural_get; + device->scroll.config_natural.get_default_enabled = evdev_scroll_config_natural_get_default; + device->scroll.natural_scrolling_enabled = false; + device->base.config.natural_scroll = &device->scroll.config_natural; +} + static struct evdev_dispatch * fallback_dispatch_create(struct libinput_device *device) { @@ -1668,6 +1712,11 @@ evdev_post_scroll(struct evdev_device *device, { double trigger_horiz, trigger_vert; + if (device->scroll.natural_scrolling_enabled) { + dx = -dx; + dy = -dy; + } + if (!evdev_is_scrolling(device, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) device->scroll.buildup_vertical += dy; diff --git a/src/evdev.h b/src/evdev.h index a1613b49..b8191cce 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -115,6 +115,9 @@ struct evdev_device { uint32_t direction; double buildup_vertical; double buildup_horizontal; + + struct libinput_device_config_natural_scroll config_natural; + bool natural_scrolling_enabled; } scroll; enum evdev_event_type pending_event; @@ -285,6 +288,9 @@ evdev_pointer_notify_button(struct evdev_device *device, enum libinput_button_state state); void +evdev_init_natural_scroll(struct evdev_device *device); + +void evdev_post_scroll(struct evdev_device *device, uint64_t time, double dx, |