From b87251ca714bab509958b712a6d3486925666bfd Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 24 Mar 2015 16:33:29 +0100 Subject: [PATCH] Add a normalized_is_zero helper function Add a normalized_is_zero helper function, and use it where applicable. Signed-off-by: Hans de Goede Reviewed-by: Peter Hutterer --- 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 f852ff5a..aba58732 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 37ad13a6..2078bd7d 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 52b89d38..a972b9d0 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 31f2dbc1..722505c3 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 */