test: adjust the relative pointer motion test for low-dpi devices
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 12 Jun 2019 04:24:57 +0000 (14:24 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 13 Jun 2019 22:52:25 +0000 (08:52 +1000)
This escaped us before because the MOUSE_DPI setting on the low-dpi device was
ignored thanks to a broken udev rule (see a future commit for that).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test/test-pointer.c

index 8578d68..2d71d50 100644 (file)
 #include "litest.h"
 
 static void
-test_relative_event(struct litest_device *dev, int dx, int dy)
+test_relative_event(struct litest_device *dev, double dx, double dy)
 {
        struct libinput *li = dev->libinput;
        struct libinput_event_pointer *ptrev;
        struct libinput_event *event;
+       struct udev_device *ud;
        double ev_dx, ev_dy;
        double expected_dir;
        double expected_length;
        double actual_dir;
        double actual_length;
+       const char *prop;
+       int dpi = 1000;
 
        litest_event(dev, EV_REL, REL_X, dx);
        litest_event(dev, EV_REL, REL_Y, dy);
@@ -55,6 +58,22 @@ test_relative_event(struct litest_device *dev, int dx, int dy)
        event = libinput_get_event(li);
        ptrev = litest_is_motion_event(event);
 
+       /* low-dpi devices scale up, not down, especially for slow motion.
+        * so a 1 unit movement in a 200dpi mouse still sends a 1 pixel
+        * movement. Work aorund this here by checking for the MOUSE_DPI
+        * property.
+        */
+       ud = libinput_device_get_udev_device(dev->libinput_device);
+       litest_assert_ptr_notnull(ud);
+       prop = udev_device_get_property_value(ud, "MOUSE_DPI");
+       if (prop) {
+               dpi = parse_mouse_dpi_property(prop);
+
+               dx *= 1000.0/dpi;
+               dy *= 1000.0/dpi;
+       }
+       udev_device_unref(ud);
+
        expected_length = sqrt(4 * dx*dx + 4 * dy*dy);
        expected_dir = atan2(dx, dy);