evdev: store the device dimensions

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@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
Peter Hutterer 2015-06-25 14:10:38 +10:00
parent 387b8057b1
commit 0d2c25e123
5 changed files with 24 additions and 20 deletions

View file

@ -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 double 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 {

View file

@ -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:

View file

@ -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,

View file

@ -1762,6 +1762,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.
@ -1874,6 +1878,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;

View file

@ -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 {