[PATCH libinput 1/2] Add a normalized_is_zero helper function

Hans de Goede hdegoede at redhat.com
Tue Mar 24 08:51:34 PDT 2015


Add a normalized_is_zero helper function, and use it where applicable.

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 src/evdev-mt-touchpad-gestures.c | 5 ++---
 src/evdev-mt-touchpad.c          | 2 +-
 src/evdev.c                      | 6 ++----
 src/libinput-private.h           | 6 ++++++
 4 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c
index f852ff5..aba5873 100644
--- a/src/evdev-mt-touchpad-gestures.c
+++ b/src/evdev-mt-touchpad-gestures.c
@@ -99,8 +99,7 @@ tp_gesture_post_pointer_motion(struct tp_dispatch *tp, uint64_t time)
 
 	tp_filter_motion(tp, &delta.x, &delta.y, &unaccel.x, &unaccel.y, time);
 
-	if (delta.x != 0.0 || delta.y != 0.0 ||
-	    unaccel.x != 0.0 || unaccel.y != 0.0) {
+	if (!normalized_is_zero(delta) || !normalized_is_zero(unaccel)) {
 		pointer_notify_motion(&tp->device->base, time,
 				      &delta, &unaccel);
 	}
@@ -114,7 +113,7 @@ tp_gesture_post_twofinger_scroll(struct tp_dispatch *tp, uint64_t time)
 	delta = tp_get_average_touches_delta(tp);
 	tp_filter_motion(tp, &delta.x, &delta.y, NULL, NULL, time);
 
-	if (delta.x == 0.0 && delta.y == 0.0)
+	if (normalized_is_zero(delta))
 		return;
 
 	tp_gesture_start(tp, time);
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index 37ad13a..2078bd7 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -70,7 +70,7 @@ tp_filter_motion(struct tp_dispatch *tp,
 	unaccelerated.x = *dx;
 	unaccelerated.y = *dy;
 
-	if (unaccelerated.x != 0.0 || unaccelerated.y != 0.0)
+	if (!normalized_is_zero(unaccelerated))
 		accelerated = filter_dispatch(tp->device->pointer.filter,
 					      &unaccelerated,
 					      tp,
diff --git a/src/evdev.c b/src/evdev.c
index 52b89d3..a972b9d 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -268,10 +268,8 @@ evdev_flush_pending_event(struct evdev_device *device, uint64_t time)
 		/* Apply pointer acceleration. */
 		accel = filter_dispatch(device->pointer.filter, &unaccel, device, time);
 
-		if (accel.x == 0.0 && accel.y == 0.0 &&
-		    unaccel.x == 0.0 && unaccel.y == 0.0) {
+		if (normalized_is_zero(accel) && normalized_is_zero(unaccel))
 			break;
-		}
 
 		pointer_notify_motion(base, time, &accel, &unaccel);
 		break;
@@ -2098,7 +2096,7 @@ 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 (!normalized_is_zero(event)) {
 		const struct discrete_coords zero_discrete = { 0.0, 0.0 };
 		evdev_notify_axis(device,
 				  time,
diff --git a/src/libinput-private.h b/src/libinput-private.h
index 4b3c174..6f4c1c0 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -380,4 +380,10 @@ normalized_length(struct normalized_coords norm)
 	return hypot(norm.x, norm.y);
 }
 
+static inline int
+normalized_is_zero(struct normalized_coords norm)
+{
+	return norm.x == 0.0 && norm.y == 0.0;
+}
+
 #endif /* LIBINPUT_PRIVATE_H */
-- 
2.3.1



More information about the wayland-devel mailing list