diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2016-07-15 11:04:04 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2016-08-01 07:10:27 +1000 |
commit | b1c51ee9d9825a92daf1d81d8645de436f5ade95 (patch) | |
tree | b412d10bbc298f05cd3dbecdd272604f93bb3b64 | |
parent | 45a574a7859cb83e589c6f2d33d81a3f666ba60d (diff) |
evdev: add helper functions to convert between units and mm
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r-- | src/evdev.h | 55 | ||||
-rw-r--r-- | src/libinput-private.h | 6 |
2 files changed, 61 insertions, 0 deletions
diff --git a/src/evdev.h b/src/evdev.h index d70dd34..f73b88b 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -537,4 +537,59 @@ evdev_libinput_context(const struct evdev_device *device) return device->base.seat->libinput; } +/** + * Convert the pair of coordinates in device space to mm. This takes the + * axis min into account, i.e. a unit of min is equivalent to 0 mm. + */ +static inline struct phys_coords +evdev_device_units_to_mm(const struct evdev_device* device, + const struct device_coords *units) +{ + struct phys_coords mm = { 0, 0 }; + const struct input_absinfo *absx, *absy; + + if (device->abs.absinfo_x == NULL || + device->abs.absinfo_y == NULL) { + log_bug_libinput(evdev_libinput_context(device), + "%s: is not an abs device\n", + device->devname); + return mm; + } + + absx = device->abs.absinfo_x; + absy = device->abs.absinfo_y; + + mm.x = (units->x - absx->minimum)/absx->resolution; + mm.y = (units->y - absy->minimum)/absy->resolution; + + return mm; +} + +/** + * Convert the pair of coordinates in mm to device units. This takes the + * axis min into account, i.e. 0 mm is equivalent to the min. + */ +static inline struct device_coords +evdev_device_mm_to_units(const struct evdev_device *device, + const struct phys_coords *mm) +{ + struct device_coords units = { 0, 0 }; + const struct input_absinfo *absx, *absy; + + if (device->abs.absinfo_x == NULL || + device->abs.absinfo_y == NULL) { + log_bug_libinput(evdev_libinput_context(device), + "%s: is not an abs device\n", + device->devname); + return units; + } + + absx = device->abs.absinfo_x; + absy = device->abs.absinfo_y; + + units.x = mm->x * absx->resolution + absx->minimum; + units.y = mm->y * absy->resolution + absy->minimum; + + return units; +} #endif /* EVDEV_H */ diff --git a/src/libinput-private.h b/src/libinput-private.h index 472f6f3..62576b5 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -82,6 +82,12 @@ struct threshold { int lower; }; +/* A pair of coordinates in mm */ +struct phys_coords { + double x; + double y; +}; + struct tablet_axes { struct device_coords point; struct normalized_coords delta; |