Add a normalized_is_zero helper function
authorHans de Goede <hdegoede@redhat.com>
Tue, 24 Mar 2015 15:33:29 +0000 (16:33 +0100)
committerHans de Goede <hdegoede@redhat.com>
Wed, 25 Mar 2015 14:16:41 +0000 (15:16 +0100)
Add a normalized_is_zero helper function, and use it where applicable.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
src/evdev-mt-touchpad-gestures.c
src/evdev-mt-touchpad.c
src/evdev.c
src/libinput-private.h

index f852ff5..aba5873 100644 (file)
@@ -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);
index 37ad13a..2078bd7 100644 (file)
@@ -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,
index 52b89d3..a972b9d 100644 (file)
@@ -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,
index 31f2dbc..722505c 100644 (file)
@@ -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 */