touchpad: change manual calculations of dimensions to helper functions

Wherever we use an absolute size in mm on the touchpad, switch to the new
helper functions. In a few cases we only need one coordinate so just leave the
other one as 0 in those cases.

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 2016-07-15 11:31:07 +10:00
parent b1c51ee9d9
commit c543b4a91a
3 changed files with 71 additions and 60 deletions

View file

@ -537,33 +537,26 @@ static void
tp_init_softbuttons(struct tp_dispatch *tp, tp_init_softbuttons(struct tp_dispatch *tp,
struct evdev_device *device) struct evdev_device *device)
{ {
int width, height; double width, height;
const struct input_absinfo *absinfo_x, *absinfo_y; struct device_coords edges;
struct device_coords offset;
int xres, yres;
int mb_le, mb_re; /* middle button left/right edge */ int mb_le, mb_re; /* middle button left/right edge */
struct phys_coords mm = { 0.0, 0.0 };
absinfo_x = device->abs.absinfo_x; evdev_device_get_size(device, &width, &height);
absinfo_y = device->abs.absinfo_y;
offset.x = absinfo_x->minimum,
offset.y = absinfo_y->minimum,
xres = absinfo_x->resolution;
yres = absinfo_y->resolution;
width = device->abs.dimensions.x;
height = device->abs.dimensions.y;
/* button height: 10mm or 15% or the touchpad height, /* button height: 10mm or 15% or the touchpad height,
whichever is smaller */ whichever is smaller */
if ((height * 0.15)/yres > 10) { if (height * 0.15 > 10)
tp->buttons.bottom_area.top_edge = mm.y = height - 10;
absinfo_y->maximum - 10 * yres; else
} else { mm.y = height * 0.85;
tp->buttons.bottom_area.top_edge = height * .85 + offset.y;
} mm.x = width * 0.5;
edges = evdev_device_mm_to_units(device, &mm);
tp->buttons.bottom_area.top_edge = edges.y;
tp->buttons.bottom_area.rightbutton_left_edge = edges.x;
tp->buttons.bottom_area.middlebutton_left_edge = INT_MAX; tp->buttons.bottom_area.middlebutton_left_edge = INT_MAX;
tp->buttons.bottom_area.rightbutton_left_edge = width/2 + offset.x;
/* if middlebutton emulation is enabled, don't init a software area */ /* if middlebutton emulation is enabled, don't init a software area */
if (device->middlebutton.want_enabled) if (device->middlebutton.want_enabled)
@ -580,14 +573,21 @@ tp_init_softbuttons(struct tp_dispatch *tp,
* All Dell touchpads appear to have a middle marker. * All Dell touchpads appear to have a middle marker.
*/ */
if (tp->device->model_flags & EVDEV_MODEL_DELL_TOUCHPAD) { if (tp->device->model_flags & EVDEV_MODEL_DELL_TOUCHPAD) {
const int MIDDLE_BUTTON_WIDTH = 10; /* mm */ mm.x = width/2 - 5; /* 10mm wide */
int half_width = MIDDLE_BUTTON_WIDTH/2 * xres; /* units */ edges = evdev_device_mm_to_units(device, &mm);
mb_le = edges.x;
mb_le = offset.x + width/2 - half_width; mm.x = width/2 + 5; /* 10mm wide */
mb_re = offset.x + width/2 + half_width; edges = evdev_device_mm_to_units(device, &mm);
mb_re = edges.x;
} else { } else {
mb_le = offset.x + width * 0.375; mm.x = width * 0.375;
mb_re = offset.x + width * 0.625; edges = evdev_device_mm_to_units(device, &mm);
mb_le = edges.x;
mm.x = width * 0.625;
edges = evdev_device_mm_to_units(device, &mm);
mb_re = edges.x;
} }
tp->buttons.bottom_area.middlebutton_left_edge = mb_le; tp->buttons.bottom_area.middlebutton_left_edge = mb_le;
@ -599,18 +599,7 @@ tp_init_top_softbuttons(struct tp_dispatch *tp,
struct evdev_device *device, struct evdev_device *device,
double topbutton_size_mult) double topbutton_size_mult)
{ {
int width; struct device_coords edges;
const struct input_absinfo *absinfo_x, *absinfo_y;
struct device_coords offset;
int yres;
absinfo_x = device->abs.absinfo_x;
absinfo_y = device->abs.absinfo_y;
offset.x = absinfo_x->minimum,
offset.y = absinfo_y->minimum;
yres = absinfo_y->resolution;
width = device->abs.dimensions.x;
if (tp->buttons.has_topbuttons) { if (tp->buttons.has_topbuttons) {
/* T440s has the top button line 5mm from the top, event /* T440s has the top button line 5mm from the top, event
@ -618,10 +607,20 @@ tp_init_top_softbuttons(struct tp_dispatch *tp,
top - which maps to 15%. We allow the caller to enlarge the top - which maps to 15%. We allow the caller to enlarge the
area using a multiplier for the touchpad disabled case. */ area using a multiplier for the touchpad disabled case. */
double topsize_mm = 10 * topbutton_size_mult; double topsize_mm = 10 * topbutton_size_mult;
struct phys_coords mm;
double width, height;
tp->buttons.top_area.bottom_edge = offset.y + topsize_mm * yres; evdev_device_get_size(device, &width, &height);
tp->buttons.top_area.rightbutton_left_edge = width * .58 + offset.x;
tp->buttons.top_area.leftbutton_right_edge = width * .42 + offset.x; mm.x = width * 0.58;
mm.y = topsize_mm;
edges = evdev_device_mm_to_units(device, &mm);
tp->buttons.top_area.bottom_edge = edges.y;
tp->buttons.top_area.rightbutton_left_edge = edges.x;
mm.x = width * 0.42;
edges = evdev_device_mm_to_units(device, &mm);
tp->buttons.top_area.leftbutton_right_edge = edges.x;
} else { } else {
tp->buttons.top_area.bottom_edge = INT_MIN; tp->buttons.top_area.bottom_edge = INT_MIN;
} }

View file

@ -285,28 +285,29 @@ void
tp_edge_scroll_init(struct tp_dispatch *tp, struct evdev_device *device) tp_edge_scroll_init(struct tp_dispatch *tp, struct evdev_device *device)
{ {
struct tp_touch *t; struct tp_touch *t;
int edge_width, edge_height;
double width, height; double width, height;
bool want_horiz_scroll = true; bool want_horiz_scroll = true;
struct device_coords edges;
struct phys_coords mm = { 0.0, 0.0 };
evdev_device_get_size(device, &width, &height);
/* Touchpads smaller than 50mm are not tall enough to have a /* Touchpads smaller than 50mm are not tall enough to have a
horizontal scroll area, it takes too much space away. But horizontal scroll area, it takes too much space away. But
clickpads have enough space here anyway because of the clickpads have enough space here anyway because of the
software button area (and all these tiny clickpads were built software button area (and all these tiny clickpads were built
when software buttons were a thing, e.g. Lenovo *20 series) when software buttons were a thing, e.g. Lenovo *20 series)
*/ */
if (!tp->buttons.is_clickpad) { if (!tp->buttons.is_clickpad)
evdev_device_get_size(device, &width, &height);
want_horiz_scroll = (height >= 50); want_horiz_scroll = (height >= 50);
}
/* 7mm edge size */ /* 7mm edge size */
edge_width = device->abs.absinfo_x->resolution * 7; mm.x = width - 7;
edge_height = device->abs.absinfo_y->resolution * 7; mm.y = height - 7;
edges = evdev_device_mm_to_units(device, &mm);
tp->scroll.right_edge = device->abs.absinfo_x->maximum - edge_width; tp->scroll.right_edge = edges.x;
if (want_horiz_scroll) if (want_horiz_scroll)
tp->scroll.bottom_edge = device->abs.absinfo_y->maximum - edge_height; tp->scroll.bottom_edge = edges.y;
else else
tp->scroll.bottom_edge = INT_MAX; tp->scroll.bottom_edge = INT_MAX;

View file

@ -1989,25 +1989,32 @@ static void
tp_init_palmdetect(struct tp_dispatch *tp, tp_init_palmdetect(struct tp_dispatch *tp,
struct evdev_device *device) struct evdev_device *device)
{ {
int width; double width, height;
struct phys_coords mm = { 0.0, 0.0 };
struct device_coords edges;
tp->palm.right_edge = INT_MAX; tp->palm.right_edge = INT_MAX;
tp->palm.left_edge = INT_MIN; tp->palm.left_edge = INT_MIN;
width = device->abs.dimensions.x;
/* Wacom doesn't have internal touchpads */ /* Wacom doesn't have internal touchpads */
if (device->model_flags & EVDEV_MODEL_WACOM_TOUCHPAD) if (device->model_flags & EVDEV_MODEL_WACOM_TOUCHPAD)
return; return;
evdev_device_get_size(device, &width, &height);
/* Enable palm detection on touchpads >= 70 mm. Anything smaller /* Enable palm detection on touchpads >= 70 mm. Anything smaller
probably won't need it, until we find out it does */ probably won't need it, until we find out it does */
if (width/device->abs.absinfo_x->resolution < 70) if (width < 70.0)
return; return;
/* palm edges are 5% of the width on each side */ /* palm edges are 5% of the width on each side */
tp->palm.right_edge = device->abs.absinfo_x->maximum - width * 0.05; mm.x = width * 0.05;
tp->palm.left_edge = device->abs.absinfo_x->minimum + width * 0.05; edges = evdev_device_mm_to_units(device, &mm);
tp->palm.left_edge = edges.x;
mm.x = width * 0.95;
edges = evdev_device_mm_to_units(device, &mm);
tp->palm.right_edge = edges.x;
tp->palm.monitor_trackpoint = true; tp->palm.monitor_trackpoint = true;
} }
@ -2031,8 +2038,9 @@ tp_init_thumb(struct tp_dispatch *tp)
struct evdev_device *device = tp->device; struct evdev_device *device = tp->device;
const struct input_absinfo *abs; const struct input_absinfo *abs;
double w = 0.0, h = 0.0; double w = 0.0, h = 0.0;
struct device_coords edges;
struct phys_coords mm = { 0.0, 0.0 };
int xres, yres; int xres, yres;
int ymax;
double threshold; double threshold;
if (!tp->buttons.is_clickpad) if (!tp->buttons.is_clickpad)
@ -2050,10 +2058,13 @@ tp_init_thumb(struct tp_dispatch *tp)
/* detect thumbs by pressure in the bottom 15mm, detect thumbs by /* detect thumbs by pressure in the bottom 15mm, detect thumbs by
* lingering in the bottom 8mm */ * lingering in the bottom 8mm */
ymax = tp->device->abs.absinfo_y->maximum; mm.y = h * 0.85;
yres = tp->device->abs.absinfo_y->resolution; edges = evdev_device_mm_to_units(device, &mm);
tp->thumb.upper_thumb_line = ymax - yres * 15; tp->thumb.upper_thumb_line = edges.y;
tp->thumb.lower_thumb_line = ymax - yres * 8;
mm.y = h * 0.92;
edges = evdev_device_mm_to_units(device, &mm);
tp->thumb.lower_thumb_line = edges.y;
abs = libevdev_get_abs_info(device->evdev, ABS_MT_PRESSURE); abs = libevdev_get_abs_info(device->evdev, ABS_MT_PRESSURE);
if (!abs) if (!abs)