[PATCH libinput 4/6] evdev: move natural scrolling configuration into evdev

Peter Hutterer peter.hutterer at who-t.net
Tue Nov 18 23:26:45 PST 2014


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 at who-t.net>
---
 src/evdev-mt-touchpad.c | 57 +++----------------------------------------------
 src/evdev-mt-touchpad.h |  5 -----
 src/evdev.c             | 49 ++++++++++++++++++++++++++++++++++++++++++
 src/evdev.h             |  6 ++++++
 4 files changed, 58 insertions(+), 59 deletions(-)

diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index 512131b..cba231f 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);
 }
 
@@ -905,56 +900,10 @@ tp_init_accel(struct tp_dispatch *tp, double diagonal)
 }
 
 static int
-tp_scroll_config_natural_has(struct libinput_device *device)
+tp_init_scroll(struct tp_dispatch *tp, struct evdev_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 int
-tp_init_scroll(struct tp_dispatch *tp)
-{
-
-	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);
 
 	/* In mm for touchpads with valid resolution, see tp_init_accel() */
 	tp->device->scroll.threshold = 5.0;
@@ -1027,7 +976,7 @@ tp_init(struct tp_dispatch *tp,
 	tp->hysteresis.margin_y =
 		diagonal / DEFAULT_HYSTERESIS_MARGIN_DENOMINATOR;
 
-	if (tp_init_scroll(tp) != 0)
+	if (tp_init_scroll(tp, device) != 0)
 		return -1;
 
 	if (tp_init_accel(tp, diagonal) != 0)
diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h
index baa51a3..fb6a79d 100644
--- a/src/evdev-mt-touchpad.h
+++ b/src/evdev-mt-touchpad.h
@@ -201,11 +201,6 @@ struct tp_dispatch {
 		struct evdev_device *trackpoint;
 	} buttons;				/* physical buttons */
 
-	struct {
-		struct libinput_device_config_natural_scroll config_natural;
-		bool natural_scrolling_enabled;
-	} scroll;
-
 	enum touchpad_event queued;
 
 	struct {
diff --git a/src/evdev.c b/src/evdev.c
index 89c6802..d0ddc37 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 a1613b4..b8191cc 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,
-- 
2.1.0



More information about the wayland-devel mailing list