mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-01-01 00:00:09 +01:00
Change absolute and touch events to use mm as default unit
Instead of device-specific coordinates that the caller can't interpret without knowing the range anyway, return mm as the default value. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
3a812385d1
commit
21cf84a580
4 changed files with 40 additions and 26 deletions
|
|
@ -164,4 +164,11 @@ evdev_device_remove(struct evdev_device *device);
|
|||
void
|
||||
evdev_device_destroy(struct evdev_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;
|
||||
}
|
||||
|
||||
#endif /* EVDEV_H */
|
||||
|
|
|
|||
|
|
@ -319,13 +319,19 @@ libinput_event_pointer_get_dy(struct libinput_event_pointer *event)
|
|||
LIBINPUT_EXPORT double
|
||||
libinput_event_pointer_get_absolute_x(struct libinput_event_pointer *event)
|
||||
{
|
||||
return event->x;
|
||||
struct evdev_device *device =
|
||||
(struct evdev_device *) event->base.device;
|
||||
|
||||
return evdev_convert_to_mm(device->abs.absinfo_x, event->x);
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT double
|
||||
libinput_event_pointer_get_absolute_y(struct libinput_event_pointer *event)
|
||||
{
|
||||
return event->y;
|
||||
struct evdev_device *device =
|
||||
(struct evdev_device *) event->base.device;
|
||||
|
||||
return evdev_convert_to_mm(device->abs.absinfo_y, event->y);
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT double
|
||||
|
|
@ -402,7 +408,10 @@ libinput_event_touch_get_seat_slot(struct libinput_event_touch *event)
|
|||
LIBINPUT_EXPORT double
|
||||
libinput_event_touch_get_x(struct libinput_event_touch *event)
|
||||
{
|
||||
return event->x;
|
||||
struct evdev_device *device =
|
||||
(struct evdev_device *) event->base.device;
|
||||
|
||||
return evdev_convert_to_mm(device->abs.absinfo_x, event->x);
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT double
|
||||
|
|
@ -428,7 +437,10 @@ libinput_event_touch_get_y_transformed(struct libinput_event_touch *event,
|
|||
LIBINPUT_EXPORT double
|
||||
libinput_event_touch_get_y(struct libinput_event_touch *event)
|
||||
{
|
||||
return event->y;
|
||||
struct evdev_device *device =
|
||||
(struct evdev_device *) event->base.device;
|
||||
|
||||
return evdev_convert_to_mm(device->abs.absinfo_y, event->y);
|
||||
}
|
||||
|
||||
struct libinput_source *
|
||||
|
|
|
|||
|
|
@ -452,11 +452,9 @@ libinput_event_pointer_get_dy(struct libinput_event_pointer *event);
|
|||
/**
|
||||
* @ingroup event_pointer
|
||||
*
|
||||
* Return the current absolute x coordinate of the pointer event.
|
||||
*
|
||||
* The coordinate is in a device specific coordinate space; to get the
|
||||
* corresponding output screen coordinate, use
|
||||
* libinput_event_pointer_get_x_transformed().
|
||||
* Return the current absolute x coordinate of the pointer event, in mm from
|
||||
* the top left corner of the device. To get the corresponding output screen
|
||||
* coordinate, use libinput_event_pointer_get_x_transformed().
|
||||
*
|
||||
* For pointer events that are not of type
|
||||
* LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, this function returns 0.
|
||||
|
|
@ -472,11 +470,9 @@ libinput_event_pointer_get_absolute_x(struct libinput_event_pointer *event);
|
|||
/**
|
||||
* @ingroup event_pointer
|
||||
*
|
||||
* Return the current absolute y coordinate of the pointer event.
|
||||
*
|
||||
* The coordinate is in a device specific coordinate space; to get the
|
||||
* corresponding output screen coordinate, use
|
||||
* libinput_event_pointer_get_y_transformed().
|
||||
* Return the current absolute y coordinate of the pointer event, in mm from
|
||||
* the top left corner of the device. To get the corresponding output screen
|
||||
* coordinate, use libinput_event_pointer_get_x_transformed().
|
||||
*
|
||||
* For pointer events that are not of type
|
||||
* LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, this function returns 0.
|
||||
|
|
@ -677,11 +673,9 @@ libinput_event_touch_get_seat_slot(struct libinput_event_touch *event);
|
|||
/**
|
||||
* @ingroup event_touch
|
||||
*
|
||||
* Return the current absolute x coordinate of the touch event.
|
||||
*
|
||||
* The coordinate is in a device specific coordinate space; to get the
|
||||
* corresponding output screen coordinate, use
|
||||
* libinput_event_touch_get_x_transformed().
|
||||
* Return the current absolute x coordinate of the touch event, in mm from
|
||||
* the top left corner of the device. To get the corresponding output screen
|
||||
* coordinate, use libinput_event_touch_get_x_transformed().
|
||||
*
|
||||
* @note this function should only be called for LIBINPUT_EVENT_TOUCH_DOWN and
|
||||
* LIBINPUT_EVENT_TOUCH_MOTION.
|
||||
|
|
@ -695,11 +689,9 @@ libinput_event_touch_get_x(struct libinput_event_touch *event);
|
|||
/**
|
||||
* @ingroup event_touch
|
||||
*
|
||||
* Return the current absolute y coordinate of the touch event.
|
||||
*
|
||||
* The coordinate is in a device specific coordinate space; to get the
|
||||
* corresponding output screen coordinate, use
|
||||
* libinput_event_touch_get_y_transformed().
|
||||
* Return the current absolute y coordinate of the touch event, in mm from
|
||||
* the top left corner of the device. To get the corresponding output screen
|
||||
* coordinate, use libinput_event_touch_get_y_transformed().
|
||||
*
|
||||
* For LIBINPUT_EVENT_TOUCH_UP 0 is returned.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -329,13 +329,16 @@ print_touch_event_with_coords(struct libinput_event *ev)
|
|||
struct libinput_event_touch *t = libinput_event_get_touch_event(ev);
|
||||
double x = libinput_event_touch_get_x_transformed(t, screen_width);
|
||||
double y = libinput_event_touch_get_y_transformed(t, screen_height);
|
||||
double xmm = libinput_event_touch_get_x(t);
|
||||
double ymm = libinput_event_touch_get_y(t);
|
||||
|
||||
print_event_time(libinput_event_touch_get_time(t));
|
||||
|
||||
printf("%d (%d) %5.2f/%5.2f\n",
|
||||
printf("%d (%d) %5.2f/%5.2f (%5.2f/%5.2fmm)\n",
|
||||
libinput_event_touch_get_slot(t),
|
||||
libinput_event_touch_get_seat_slot(t),
|
||||
x, y);
|
||||
x, y,
|
||||
xmm, ymm);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue