From: Peter Hutterer Date: Thu, 13 Jun 2024 04:10:06 +0000 (+1000) Subject: Move evdev_convert_to_mm to a more generic helper X-Git-Tag: 1.27.0~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cfbdca5953bc1d37df1945aa735cd751aea6976c;p=platform%2Fupstream%2Flibinput.git Move evdev_convert_to_mm to a more generic helper Part-of: --- diff --git a/src/evdev.c b/src/evdev.c index 3a336a1e..4b37064f 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -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; } diff --git a/src/evdev.h b/src/evdev.h index 4971e4e9..9f34253c 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -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; } diff --git a/src/libinput.c b/src/libinput.c index 76e7235e..9f686345 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -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 diff --git a/src/util-input-event.h b/src/util-input-event.h index b7910215..6f3dc87d 100644 --- a/src/util-input-event.h +++ b/src/util-input-event.h @@ -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; +}