[PATCH libinput 1/4] evdev: keep the absinfo struct around instead of min/max
Hans de Goede
hdegoede at redhat.com
Thu Jun 19 01:05:46 PDT 2014
Hi,
Series looks good to me, and is:
Reviewed-by: Hans de Goede <hdegoede at redhat.com>
Regards,
Hans
On 06/19/2014 05:45 AM, Peter Hutterer wrote:
> We'll need that later for conversion to mm.
>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
> src/evdev-mt-touchpad-buttons.c | 20 +++++++++++++-------
> src/evdev-mt-touchpad.c | 6 ++++--
> src/evdev.c | 25 +++++++++++++------------
> src/evdev.h | 2 +-
> 4 files changed, 31 insertions(+), 22 deletions(-)
>
> diff --git a/src/evdev-mt-touchpad-buttons.c b/src/evdev-mt-touchpad-buttons.c
> index ce48ed0..45d5d70 100644
> --- a/src/evdev-mt-touchpad-buttons.c
> +++ b/src/evdev-mt-touchpad-buttons.c
> @@ -565,6 +565,7 @@ tp_init_buttons(struct tp_dispatch *tp,
> struct tp_touch *t;
> int width, height;
> double diagonal;
> + const struct input_absinfo *absinfo_x, *absinfo_y;
>
> tp->buttons.is_clickpad = libevdev_has_property(device->evdev,
> INPUT_PROP_BUTTONPAD);
> @@ -580,8 +581,11 @@ tp_init_buttons(struct tp_dispatch *tp,
> log_bug_kernel("non clickpad without right button?\n");
> }
>
> - width = abs(device->abs.max_x - device->abs.min_x);
> - height = abs(device->abs.max_y - device->abs.min_y);
> + absinfo_x = device->abs.absinfo_x;
> + absinfo_y = device->abs.absinfo_y;
> +
> + width = abs(absinfo_x->maximum - absinfo_x->minimum);
> + height = abs(absinfo_y->maximum - absinfo_y->minimum);
> diagonal = sqrt(width*width + height*height);
>
> tp->buttons.motion_dist = diagonal * DEFAULT_BUTTON_MOTION_THRESHOLD;
> @@ -590,13 +594,15 @@ tp_init_buttons(struct tp_dispatch *tp,
> tp->buttons.use_clickfinger = true;
>
> if (tp->buttons.is_clickpad && !tp->buttons.use_clickfinger) {
> - tp->buttons.bottom_area.top_edge = height * .8 + device->abs.min_y;
> - tp->buttons.bottom_area.rightbutton_left_edge = width/2 + device->abs.min_x;
> + int xoffset = absinfo_x->minimum,
> + yoffset = absinfo_y->minimum;
> + tp->buttons.bottom_area.top_edge = height * .8 + yoffset;
> + tp->buttons.bottom_area.rightbutton_left_edge = width/2 + xoffset;
>
> if (tp->buttons.has_topbuttons) {
> - tp->buttons.top_area.bottom_edge = height * .08 + device->abs.min_y;
> - tp->buttons.top_area.rightbutton_left_edge = width * .58 + device->abs.min_x;
> - tp->buttons.top_area.leftbutton_right_edge = width * .42 + device->abs.min_x;
> + tp->buttons.top_area.bottom_edge = height * .08 + yoffset;
> + tp->buttons.top_area.rightbutton_left_edge = width * .58 + xoffset;
> + tp->buttons.top_area.leftbutton_right_edge = width * .42 + xoffset;
> } else {
> tp->buttons.top_area.bottom_edge = INT_MIN;
> }
> diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
> index 92e0651..787afa4 100644
> --- a/src/evdev-mt-touchpad.c
> +++ b/src/evdev-mt-touchpad.c
> @@ -750,8 +750,10 @@ tp_init(struct tp_dispatch *tp,
> if (tp_init_slots(tp, device) != 0)
> return -1;
>
> - width = abs(device->abs.max_x - device->abs.min_x);
> - height = abs(device->abs.max_y - device->abs.min_y);
> + width = abs(device->abs.absinfo_x->maximum -
> + device->abs.absinfo_x->minimum);
> + height = abs(device->abs.absinfo_y->maximum -
> + device->abs.absinfo_y->minimum);
> diagonal = sqrt(width*width + height*height);
>
> tp->hysteresis.margin_x =
> diff --git a/src/evdev.c b/src/evdev.c
> index 51ad5e3..907d18e 100644
> --- a/src/evdev.c
> +++ b/src/evdev.c
> @@ -89,13 +89,19 @@ transform_absolute(struct evdev_device *device, int32_t *x, int32_t *y)
> }
> }
>
> +static inline double
> +scale_axis(const struct input_absinfo *absinfo, double val, double to_range)
> +{
> + return (val - absinfo->minimum) * to_range /
> + (absinfo->maximum - absinfo->minimum + 1);
> +}
> +
> double
> evdev_device_transform_x(struct evdev_device *device,
> double x,
> uint32_t width)
> {
> - return (x - device->abs.min_x) * width /
> - (device->abs.max_x - device->abs.min_x + 1);
> + return scale_axis(device->abs.absinfo_x, x, width);
> }
>
> double
> @@ -103,8 +109,7 @@ evdev_device_transform_y(struct evdev_device *device,
> double y,
> uint32_t height)
> {
> - return (y - device->abs.min_y) * height /
> - (device->abs.max_y - device->abs.min_y + 1);
> + return scale_axis(device->abs.absinfo_y, y, height);
> }
>
> static void
> @@ -606,13 +611,11 @@ evdev_configure_device(struct evdev_device *device)
> if (libevdev_has_event_type(evdev, EV_ABS)) {
>
> if ((absinfo = libevdev_get_abs_info(evdev, ABS_X))) {
> - device->abs.min_x = absinfo->minimum;
> - device->abs.max_x = absinfo->maximum;
> + device->abs.absinfo_x = absinfo;
> has_abs = 1;
> }
> if ((absinfo = libevdev_get_abs_info(evdev, ABS_Y))) {
> - device->abs.min_y = absinfo->minimum;
> - device->abs.max_y = absinfo->maximum;
> + device->abs.absinfo_y = absinfo;
> has_abs = 1;
> }
> /* We only handle the slotted Protocol B in weston.
> @@ -621,11 +624,9 @@ evdev_configure_device(struct evdev_device *device)
> if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) &&
> libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y)) {
> absinfo = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X);
> - device->abs.min_x = absinfo->minimum;
> - device->abs.max_x = absinfo->maximum;
> + device->abs.absinfo_x = absinfo;
> absinfo = libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y);
> - device->abs.min_y = absinfo->minimum;
> - device->abs.max_y = absinfo->maximum;
> + device->abs.absinfo_y = absinfo;
> device->is_mt = 1;
> has_touch = 1;
> has_mt = 1;
> diff --git a/src/evdev.h b/src/evdev.h
> index d057010..03b6742 100644
> --- a/src/evdev.h
> +++ b/src/evdev.h
> @@ -66,7 +66,7 @@ struct evdev_device {
> const char *devname;
> int fd;
> struct {
> - int min_x, max_x, min_y, max_y;
> + const struct input_absinfo *absinfo_x, *absinfo_y;
> int32_t x, y;
>
> int32_t seat_slot;
>
More information about the wayland-devel
mailing list