Move evdev_convert_to_mm to a more generic helper
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 13 Jun 2024 04:10:06 +0000 (14:10 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 5 Nov 2024 02:05:05 +0000 (12:05 +1000)
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1013>

src/evdev.c
src/evdev.h
src/libinput.c
src/util-input-event.h

index 3a336a1effb42aae43c177206ec0c8b0fbdd933f..4b37064f34600356e5a10b87d281ab99e5c65046 100644 (file)
@@ -2727,8 +2727,8 @@ evdev_device_get_size(const struct evdev_device *device,
            !x->resolution || !y->resolution)
                return -1;
 
-       *width = evdev_convert_to_mm(x, x->maximum);
-       *height = evdev_convert_to_mm(y, y->maximum);
+       *width = absinfo_convert_to_mm(x, x->maximum);
+       *height = absinfo_convert_to_mm(y, y->maximum);
 
        return 0;
 }
index 4971e4e9520879f87764903556cb235a78f355a9..9f34253c7e4e2b8053d0fc09ce1f78cf625cd23c 100644 (file)
@@ -37,6 +37,7 @@
 #include "timer.h"
 #include "filter.h"
 #include "quirks.h"
+#include "util-input-event.h"
 
 /* The fake resolution value for abs devices without resolution */
 #define EVDEV_FAKE_RESOLUTION 1
@@ -649,20 +650,13 @@ evdev_middlebutton_is_available(struct libinput_device *device);
 enum libinput_config_middle_emulation_state
 evdev_middlebutton_get_default(struct libinput_device *device);
 
-static inline double
-evdev_convert_to_mm(const struct input_absinfo *absinfo, double v)
-{
-       double value = v - absinfo->minimum;
-       return value/absinfo->resolution;
-}
-
 static inline struct phys_coords
 evdev_convert_xy_to_mm(const struct evdev_device *device, int x, int y)
 {
        struct phys_coords mm;
 
-       mm.x = evdev_convert_to_mm(device->abs.absinfo_x, x);
-       mm.y = evdev_convert_to_mm(device->abs.absinfo_y, y);
+       mm.x = absinfo_convert_to_mm(device->abs.absinfo_x, x);
+       mm.y = absinfo_convert_to_mm(device->abs.absinfo_y, y);
 
        return mm;
 }
index 76e7235ed8fe877c5d3c8126993c053878938e91..9f68634599c09604808eed470d93b71174a53ae2 100644 (file)
@@ -626,7 +626,7 @@ libinput_event_pointer_get_absolute_x(struct libinput_event_pointer *event)
                           0,
                           LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE);
 
-       return evdev_convert_to_mm(device->abs.absinfo_x, event->absolute.x);
+       return absinfo_convert_to_mm(device->abs.absinfo_x, event->absolute.x);
 }
 
 LIBINPUT_EXPORT double
@@ -639,7 +639,7 @@ libinput_event_pointer_get_absolute_y(struct libinput_event_pointer *event)
                           0,
                           LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE);
 
-       return evdev_convert_to_mm(device->abs.absinfo_y, event->absolute.y);
+       return absinfo_convert_to_mm(device->abs.absinfo_y, event->absolute.y);
 }
 
 LIBINPUT_EXPORT double
@@ -918,7 +918,7 @@ libinput_event_touch_get_x(struct libinput_event_touch *event)
                           LIBINPUT_EVENT_TOUCH_DOWN,
                           LIBINPUT_EVENT_TOUCH_MOTION);
 
-       return evdev_convert_to_mm(device->abs.absinfo_x, event->point.x);
+       return absinfo_convert_to_mm(device->abs.absinfo_x, event->point.x);
 }
 
 LIBINPUT_EXPORT double
@@ -962,7 +962,7 @@ libinput_event_touch_get_y(struct libinput_event_touch *event)
                           LIBINPUT_EVENT_TOUCH_DOWN,
                           LIBINPUT_EVENT_TOUCH_MOTION);
 
-       return evdev_convert_to_mm(device->abs.absinfo_y, event->point.y);
+       return absinfo_convert_to_mm(device->abs.absinfo_y, event->point.y);
 }
 
 LIBINPUT_EXPORT uint32_t
@@ -1313,8 +1313,8 @@ libinput_event_tablet_tool_get_x(struct libinput_event_tablet_tool *event)
                           LIBINPUT_EVENT_TABLET_TOOL_BUTTON,
                           LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
 
-       return evdev_convert_to_mm(device->abs.absinfo_x,
-                                  event->axes.point.x);
+       return absinfo_convert_to_mm(device->abs.absinfo_x,
+                                    event->axes.point.x);
 }
 
 LIBINPUT_EXPORT double
@@ -1330,8 +1330,8 @@ libinput_event_tablet_tool_get_y(struct libinput_event_tablet_tool *event)
                           LIBINPUT_EVENT_TABLET_TOOL_BUTTON,
                           LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
 
-       return evdev_convert_to_mm(device->abs.absinfo_y,
-                                  event->axes.point.y);
+       return absinfo_convert_to_mm(device->abs.absinfo_y,
+                                    event->axes.point.y);
 }
 
 LIBINPUT_EXPORT double
index b7910215bef7272370711b80471994e795e96038..6f3dc87d667150e1f23f6c912d7ed310cd8c4c7c 100644 (file)
@@ -90,3 +90,10 @@ absinfo_scale_axis(const struct input_absinfo *absinfo, double val, double to_ra
 {
        return (val - absinfo->minimum) * to_range / absinfo_range(absinfo);
 }
+
+static inline double
+absinfo_convert_to_mm(const struct input_absinfo *absinfo, double v)
+{
+       double value = v - absinfo->minimum;
+       return value/absinfo->resolution;
+}