[PATCH libinput 11/12] Add another data type for discrete coordinates

Peter Hutterer peter.hutterer at who-t.net
Thu Mar 12 01:36:42 PDT 2015


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-mt-touchpad-edge-scroll.c |  8 +++++---
 src/evdev.c                         | 27 ++++++++++++++++-----------
 src/libinput-private.h              |  8 ++++++--
 src/libinput.c                      | 12 +++++-------
 4 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/src/evdev-mt-touchpad-edge-scroll.c b/src/evdev-mt-touchpad-edge-scroll.c
index d33f4fd..6e24819 100644
--- a/src/evdev-mt-touchpad-edge-scroll.c
+++ b/src/evdev-mt-touchpad-edge-scroll.c
@@ -315,6 +315,7 @@ tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time)
 	double initial_dx, initial_dy, *initial_delta;
 	struct normalized_coords normalized;
 	const struct normalized_coords zero = { 0.0, 0.0 };
+	const struct discrete_coords zero_discrete = { 0.0, 0.0 };
 
 	if (tp->scroll.method != LIBINPUT_CONFIG_SCROLL_EDGE)
 		return 0;
@@ -331,7 +332,7 @@ tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time)
 						AS_MASK(t->scroll.direction),
 						LIBINPUT_POINTER_AXIS_SOURCE_FINGER,
 						&zero,
-						0, 0);
+						&zero_discrete);
 					t->scroll.direction = -1;
 				}
 				continue;
@@ -383,7 +384,7 @@ tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time)
 				    AS_MASK(axis),
 				    LIBINPUT_POINTER_AXIS_SOURCE_FINGER,
 				    &normalized,
-				    0, 0);
+				    &zero_discrete);
 		t->scroll.direction = axis;
 
 		tp_edge_scroll_handle_event(tp, t, SCROLL_EVENT_POSTED);
@@ -398,6 +399,7 @@ tp_edge_scroll_stop_events(struct tp_dispatch *tp, uint64_t time)
 	struct libinput_device *device = &tp->device->base;
 	struct tp_touch *t;
 	const struct normalized_coords zero = { 0.0, 0.0 };
+	const struct discrete_coords zero_discrete = { 0.0, 0.0 };
 
 	tp_for_each_touch(tp, t) {
 		if (t->scroll.direction != -1) {
@@ -405,7 +407,7 @@ tp_edge_scroll_stop_events(struct tp_dispatch *tp, uint64_t time)
 					    AS_MASK(t->scroll.direction),
 					    LIBINPUT_POINTER_AXIS_SOURCE_FINGER,
 					    &zero,
-					    0.0, 0.0);
+					    &zero_discrete);
 			t->scroll.direction = -1;
 		}
 	}
diff --git a/src/evdev.c b/src/evdev.c
index cab7e85..c661af9 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -586,15 +586,16 @@ evdev_notify_axis(struct evdev_device *device,
 		  uint32_t axes,
 		  enum libinput_pointer_axis_source source,
 		  const struct normalized_coords *delta_in,
-		  double x_discrete, double y_discrete)
+		  const struct discrete_coords *discrete_in)
 {
 	struct normalized_coords delta = *delta_in;
+	struct discrete_coords discrete = *discrete_in;
 
 	if (device->scroll.natural_scrolling_enabled) {
 		delta.x *= -1;
 		delta.y *= -1;
-		x_discrete *= -1;
-		y_discrete *= -1;
+		discrete.x *= -1;
+		discrete.y *= -1;
 	}
 
 	pointer_notify_axis(&device->base,
@@ -602,7 +603,7 @@ evdev_notify_axis(struct evdev_device *device,
 			    axes,
 			    source,
 			    &delta,
-			    x_discrete, y_discrete);
+			    &discrete);
 }
 
 static inline void
@@ -610,6 +611,7 @@ evdev_process_relative(struct evdev_device *device,
 		       struct input_event *e, uint64_t time)
 {
 	struct normalized_coords wheel_degrees = { 0.0, 0.0 };
+	struct discrete_coords discrete = { 0.0, 0.0 };
 
 	switch (e->code) {
 	case REL_X:
@@ -628,26 +630,26 @@ evdev_process_relative(struct evdev_device *device,
 		evdev_flush_pending_event(device, time);
 		wheel_degrees.y = -1 * e->value *
 					device->scroll.wheel_click_angle;
+		discrete.y = -1 * e->value;
 		evdev_notify_axis(
 			device,
 			time,
 			AS_MASK(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL),
 			LIBINPUT_POINTER_AXIS_SOURCE_WHEEL,
 			&wheel_degrees,
-			0.0,
-			-1 * e->value);
+			&discrete);
 		break;
 	case REL_HWHEEL:
 		evdev_flush_pending_event(device, time);
 		wheel_degrees.x = e->value * device->scroll.wheel_click_angle;
+		discrete.x = e->value;
 		evdev_notify_axis(
 			device,
 			time,
 			AS_MASK(LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL),
 			LIBINPUT_POINTER_AXIS_SOURCE_WHEEL,
 			&wheel_degrees,
-			e->value,
-			0.0);
+			&discrete);
 		break;
 	}
 }
@@ -1977,13 +1979,15 @@ evdev_post_scroll(struct evdev_device *device,
 			       LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
 		event.x = 0.0;
 
-	if (event.x != 0.0 || event.y != 0.0)
+	if (event.x != 0.0 || event.y != 0.0) {
+		const struct discrete_coords zero_discrete = { 0.0, 0.0 };
 		evdev_notify_axis(device,
 				  time,
 				  device->scroll.direction,
 				  source,
 				  &event,
-				  0.0, 0.0);
+				  &zero_discrete);
+	}
 }
 
 void
@@ -1992,6 +1996,7 @@ evdev_stop_scroll(struct evdev_device *device,
 		  enum libinput_pointer_axis_source source)
 {
 	const struct normalized_coords zero = { 0.0, 0.0 };
+	const struct discrete_coords zero_discrete = { 0.0, 0.0 };
 
 	/* terminate scrolling with a zero scroll event */
 	if (device->scroll.direction != 0)
@@ -2000,7 +2005,7 @@ evdev_stop_scroll(struct evdev_device *device,
 				    device->scroll.direction,
 				    source,
 				    &zero,
-				    0.0, 0.0);
+				    &zero_discrete);
 
 	device->scroll.buildup.x = 0;
 	device->scroll.buildup.y = 0;
diff --git a/src/libinput-private.h b/src/libinput-private.h
index 91bfc37..e39ac5e 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -42,6 +42,11 @@ struct normalized_coords {
 	double x, y;
 };
 
+/* A discrete step pair (mouse wheels) */
+struct discrete_coords {
+	int x, y;
+};
+
 struct libinput_interface_backend {
 	int (*resume)(struct libinput *libinput);
 	void (*suspend)(struct libinput *libinput);
@@ -310,8 +315,7 @@ pointer_notify_axis(struct libinput_device *device,
 		    uint32_t axes,
 		    enum libinput_pointer_axis_source source,
 		    const struct normalized_coords *delta,
-		    double x_discrete,
-		    double y_discrete);
+		    const struct discrete_coords *discrete);
 
 void
 touch_notify_touch_down(struct libinput_device *device,
diff --git a/src/libinput.c b/src/libinput.c
index 1a68069..8db6997 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -59,8 +59,7 @@ struct libinput_event_pointer {
 	uint32_t time;
 	struct normalized_coords delta;
 	struct device_coords absolute;
-	double x_discrete;
-	double y_discrete;
+	struct discrete_coords discrete;
 	double dx_unaccel;
 	double dy_unaccel;
 	uint32_t button;
@@ -428,10 +427,10 @@ libinput_event_pointer_get_axis_value_discrete(struct libinput_event_pointer *ev
 	} else {
 		switch (axis) {
 		case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL:
-			value = event->x_discrete;
+			value = event->discrete.x;
 			break;
 		case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL:
-			value = event->y_discrete;
+			value = event->discrete.y;
 			break;
 		}
 	}
@@ -1037,7 +1036,7 @@ pointer_notify_axis(struct libinput_device *device,
 		    uint32_t axes,
 		    enum libinput_pointer_axis_source source,
 		    const struct normalized_coords *delta,
-		    double x_discrete, double y_discrete)
+		    const struct discrete_coords *discrete)
 {
 	struct libinput_event_pointer *axis_event;
 
@@ -1050,8 +1049,7 @@ pointer_notify_axis(struct libinput_device *device,
 		.delta = *delta,
 		.source = source,
 		.axes = axes,
-		.x_discrete = x_discrete,
-		.y_discrete = y_discrete,
+		.discrete = *discrete,
 	};
 
 	post_device_event(device, time,
-- 
2.1.0



More information about the wayland-devel mailing list