[PATCH libinput] evdev: store the device dimensions
Hans de Goede
hdegoede at redhat.com
Thu Jun 25 00:43:50 PDT 2015
Hi,
On 25-06-15 09:07, Peter Hutterer wrote:
> We use width/height often enough that storing it once is better than
> calculating it on each event.
>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
Looks good to me:
Reviewed-by: Hans de Goede <hdegoede at redhat.com>
Regards,
Hans
> ---
> src/evdev-mt-touchpad-buttons.c | 18 ++++++++----------
> src/evdev-mt-touchpad-edge-scroll.c | 4 ++--
> src/evdev-mt-touchpad.c | 12 ++++--------
> src/evdev.c | 8 ++++++++
> src/evdev.h | 2 ++
> 5 files changed, 24 insertions(+), 20 deletions(-)
>
> diff --git a/src/evdev-mt-touchpad-buttons.c b/src/evdev-mt-touchpad-buttons.c
> index 8d4e278..d004ff5 100644
> --- a/src/evdev-mt-touchpad-buttons.c
> +++ b/src/evdev-mt-touchpad-buttons.c
> @@ -527,8 +527,8 @@ tp_init_softbuttons(struct tp_dispatch *tp,
> xoffset = absinfo_x->minimum,
> yoffset = absinfo_y->minimum;
> yres = absinfo_y->resolution;
> - width = abs(absinfo_x->maximum - absinfo_x->minimum);
> - height = abs(absinfo_y->maximum - absinfo_y->minimum);
> + width = device->abs.dimensions.x;
> + height = device->abs.dimensions.y;
>
> /* button height: 10mm or 15% of the touchpad height,
> whichever is smaller */
> @@ -558,8 +558,8 @@ tp_init_top_softbuttons(struct tp_dispatch *tp,
> xoffset = absinfo_x->minimum,
> yoffset = absinfo_y->minimum;
> yres = absinfo_y->resolution;
> - width = abs(absinfo_x->maximum - absinfo_x->minimum);
> - height = abs(absinfo_y->maximum - absinfo_y->minimum);
> + width = device->abs.dimensions.x;
> + height = device->abs.dimensions.y;
>
> if (tp->buttons.has_topbuttons) {
> /* T440s has the top button line 5mm from the top, event
> @@ -742,8 +742,8 @@ tp_init_buttons(struct tp_dispatch *tp,
> The MAGIC for resolution-less touchpads ends up as 2% of the diagonal */
> if (device->abs.fake_resolution) {
> const int BUTTON_MOTION_MAGIC = 0.007;
> - width = abs(absinfo_x->maximum - absinfo_x->minimum);
> - height = abs(absinfo_y->maximum - absinfo_y->minimum);
> + width = device->abs.dimensions.x;
> + height = device->abs.dimensions.y;
> diagonal = sqrt(width*width + height*height);
> tp->buttons.motion_dist.x_scale_coeff = diagonal * BUTTON_MOTION_MAGIC;
> tp->buttons.motion_dist.y_scale_coeff = diagonal * BUTTON_MOTION_MAGIC;
> @@ -838,10 +838,8 @@ tp_check_clickfinger_distance(struct tp_dispatch *tp,
>
> /* Use a maximum of 30% of the touchpad width or height if
> * we dont' have resolution. */
> - w = tp->device->abs.absinfo_x->maximum -
> - tp->device->abs.absinfo_x->minimum;
> - h = tp->device->abs.absinfo_y->maximum -
> - tp->device->abs.absinfo_y->minimum;
> + w = tp->device->abs.dimensions.x;
> + h = tp->device->abs.dimensions.y;
>
> return (x < w * 0.3 && y < h * 0.3) ? 1 : 0;
> } else {
> diff --git a/src/evdev-mt-touchpad-edge-scroll.c b/src/evdev-mt-touchpad-edge-scroll.c
> index 6bfef90..9a9d3b8 100644
> --- a/src/evdev-mt-touchpad-edge-scroll.c
> +++ b/src/evdev-mt-touchpad-edge-scroll.c
> @@ -275,8 +275,8 @@ tp_edge_scroll_init(struct tp_dispatch *tp, struct evdev_device *device)
> int width, height;
> int edge_width, edge_height;
>
> - width = device->abs.absinfo_x->maximum - device->abs.absinfo_x->minimum;
> - height = device->abs.absinfo_y->maximum - device->abs.absinfo_y->minimum;
> + width = device->abs.dimensions.x;
> + height = device->abs.dimensions.y;
>
> switch (tp->model) {
> case MODEL_ALPS:
> diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
> index 9e60f46..ae42a9b 100644
> --- a/src/evdev-mt-touchpad.c
> +++ b/src/evdev-mt-touchpad.c
> @@ -1402,10 +1402,8 @@ tp_init_palmdetect(struct tp_dispatch *tp,
> tp->palm.left_edge = INT_MIN;
> tp->palm.vert_center = INT_MIN;
>
> - width = abs(device->abs.absinfo_x->maximum -
> - device->abs.absinfo_x->minimum);
> - height = abs(device->abs.absinfo_y->maximum -
> - device->abs.absinfo_y->minimum);
> + width = device->abs.dimensions.x;
> + height = device->abs.dimensions.y;
>
> /* Wacom doesn't have internal touchpads,
> * Apple touchpads are always big enough to warrant palm detection */
> @@ -1484,10 +1482,8 @@ tp_init(struct tp_dispatch *tp,
> if (tp_init_slots(tp, device) != 0)
> return -1;
>
> - width = abs(device->abs.absinfo_x->maximum -
> - device->abs.absinfo_x->minimum);
> - height = abs(device->abs.absinfo_y->maximum -
> - device->abs.absinfo_y->minimum);
> + width = device->abs.dimensions.x;
> + height = device->abs.dimensions.y;
> diagonal = sqrt(width*width + height*height);
>
> tp->reports_distance = libevdev_has_event_code(device->evdev,
> diff --git a/src/evdev.c b/src/evdev.c
> index e439a79..f24a5ec 100644
> --- a/src/evdev.c
> +++ b/src/evdev.c
> @@ -1766,6 +1766,10 @@ evdev_configure_mt_device(struct evdev_device *device)
>
> device->abs.absinfo_x = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X);
> device->abs.absinfo_y = libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y);
> + device->abs.dimensions.x = abs(device->abs.absinfo_x->maximum -
> + device->abs.absinfo_x->minimum);
> + device->abs.dimensions.y = abs(device->abs.absinfo_y->maximum -
> + device->abs.absinfo_y->minimum);
> device->is_mt = 1;
>
> /* We only handle the slotted Protocol B in libinput.
> @@ -1891,6 +1895,10 @@ evdev_configure_device(struct evdev_device *device)
> device->abs.absinfo_y = libevdev_get_abs_info(evdev, ABS_Y);
> device->abs.point.x = device->abs.absinfo_x->value;
> device->abs.point.y = device->abs.absinfo_y->value;
> + device->abs.dimensions.x = abs(device->abs.absinfo_x->maximum -
> + device->abs.absinfo_x->minimum);
> + device->abs.dimensions.y = abs(device->abs.absinfo_y->maximum -
> + device->abs.absinfo_y->minimum);
>
> if (evdev_is_fake_mt_device(device)) {
> udev_tags &= ~EVDEV_UDEV_TAG_TOUCHSCREEN;
> diff --git a/src/evdev.h b/src/evdev.h
> index 566b0a4..0485894 100644
> --- a/src/evdev.h
> +++ b/src/evdev.h
> @@ -137,6 +137,8 @@ struct evdev_device {
> struct matrix calibration;
> struct matrix default_calibration; /* from LIBINPUT_CALIBRATION_MATRIX */
> struct matrix usermatrix; /* as supplied by the caller */
> +
> + struct device_coords dimensions;
> } abs;
>
> struct {
>
More information about the wayland-devel
mailing list