[PATCH V3 libinput] evdev: remove checks for fake_resolution

spitzak at gmail.com spitzak at gmail.com
Thu Jun 25 08:06:29 PDT 2015


From: Bill Spitzak <bill.spitzak at dreamworks.com>

(changes from previous version: rounds the guess and changes 0 to 1,
removed unused variables)

Instead a default resolution is set if the device does not claim one.
The selected value is a guess that the trackpad is 67 mm tall and
that the device units are square.

This estimate was arrived at by equating the results calculated when
fake_resolution is on or off and computing the ratio of units to
resolution and choosing the most popular value (yres = height / 66.666).

Also fixes an apparent bug in computing motion_dist.scale_coeff, I
believe the fake value was the reciprocal of the intended value.

Unfortunately this patch has not been tested as I lack the ability to do so.
It is unclear to me if the absinfo_x/y->maximum/minimum fields have been
filled in before evdev_fix_abs_resolution is called, this patch
assumes that.
---
 src/evdev-mt-touchpad-buttons.c | 59 +++++++++--------------------------------
 src/evdev-mt-touchpad.c         | 32 +++++-----------------
 src/evdev.c                     | 16 ++++++++---
 3 files changed, 31 insertions(+), 76 deletions(-)

diff --git a/src/evdev-mt-touchpad-buttons.c b/src/evdev-mt-touchpad-buttons.c
index 6abf9d5..09e5917 100644
--- a/src/evdev-mt-touchpad-buttons.c
+++ b/src/evdev-mt-touchpad-buttons.c
@@ -532,7 +532,7 @@ tp_init_softbuttons(struct tp_dispatch *tp,
 
 	/* button height: 10mm or 15% of the touchpad height,
 	   whichever is smaller */
-	if (!device->abs.fake_resolution && (height * 0.15/yres) > 10) {
+	if ((height * 0.15/yres) > 10) {
 		tp->buttons.bottom_area.top_edge =
 		absinfo_y->maximum - 10 * yres;
 	} else {
@@ -547,7 +547,7 @@ tp_init_top_softbuttons(struct tp_dispatch *tp,
 			struct evdev_device *device,
 			double topbutton_size_mult)
 {
-	int width, height;
+	int width;
 	const struct input_absinfo *absinfo_x, *absinfo_y;
 	int xoffset, yoffset;
 	int yres;
@@ -559,7 +559,6 @@ tp_init_top_softbuttons(struct tp_dispatch *tp,
 	yoffset = absinfo_y->minimum;
 	yres = absinfo_y->resolution;
 	width = abs(absinfo_x->maximum - absinfo_x->minimum);
-	height = abs(absinfo_y->maximum - absinfo_y->minimum);
 
 	if (tp->buttons.has_topbuttons) {
 		/* T440s has the top button line 5mm from the top, event
@@ -567,14 +566,8 @@ tp_init_top_softbuttons(struct tp_dispatch *tp,
 		   top - which maps to 15%.  We allow the caller to enlarge the
 		   area using a multiplier for the touchpad disabled case. */
 		double topsize_mm = 10 * topbutton_size_mult;
-		double topsize_pct = .15 * topbutton_size_mult;
 
-		if (!device->abs.fake_resolution) {
-			tp->buttons.top_area.bottom_edge =
-			yoffset + topsize_mm * yres;
-		} else {
-			tp->buttons.top_area.bottom_edge = height * topsize_pct + yoffset;
-		}
+		tp->buttons.top_area.bottom_edge = yoffset + topsize_mm * yres;
 		tp->buttons.top_area.rightbutton_left_edge = width * .58 + xoffset;
 		tp->buttons.top_area.leftbutton_right_edge = width * .42 + xoffset;
 	} else {
@@ -713,8 +706,6 @@ tp_init_buttons(struct tp_dispatch *tp,
 {
 	struct libinput *libinput = tp_libinput_context(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,
@@ -738,19 +729,9 @@ tp_init_buttons(struct tp_dispatch *tp,
 	absinfo_x = device->abs.absinfo_x;
 	absinfo_y = device->abs.absinfo_y;
 
-	/* pinned-finger motion threshold, see tp_unpin_finger.
-	   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);
-		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;
-	} else {
-		tp->buttons.motion_dist.x_scale_coeff = 1.0/absinfo_x->resolution;
-		tp->buttons.motion_dist.y_scale_coeff = 1.0/absinfo_y->resolution;
-	}
+	/* pinned-finger motion threshold, see tp_unpin_finger. */
+	tp->buttons.motion_dist.x_scale_coeff = 1.0/absinfo_x->resolution;
+	tp->buttons.motion_dist.y_scale_coeff = 1.0/absinfo_y->resolution;
 
 	tp->buttons.config_method.get_methods = tp_button_config_click_get_methods;
 	tp->buttons.config_method.set_method = tp_button_config_click_set_method;
@@ -832,29 +813,15 @@ tp_check_clickfinger_distance(struct tp_dispatch *tp,
 	x = abs(t1->point.x - t2->point.x);
 	y = abs(t1->point.y - t2->point.y);
 
-	/* no resolution, so let's assume they're close enough together */
-	if (tp->device->abs.fake_resolution) {
-		int w, h;
-
-		/* 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;
+	/* maximum spread is 40mm horiz, 20mm vert. Anything wider than that
+	 * is probably a gesture. The y spread is small so we ignore clicks
+	 * with thumbs at the bottom of the touchpad while the pointer
+	 * moving finger is still on the pad */
 
-		return (x < w * 0.3 && y < h * 0.3) ? 1 : 0;
-	} else {
-		/* maximum spread is 40mm horiz, 20mm vert. Anything wider than that
-		 * is probably a gesture. The y spread is small so we ignore clicks
-		 * with thumbs at the bottom of the touchpad while the pointer
-		 * moving finger is still on the pad */
+	x /= tp->device->abs.absinfo_x->resolution;
+	y /= tp->device->abs.absinfo_y->resolution;
 
-		x /= tp->device->abs.absinfo_x->resolution;
-		y /= tp->device->abs.absinfo_y->resolution;
-
-		return (x < 40 && y < 20) ? 1 : 0;
-	}
+	return (x < 40 && y < 20) ? 1 : 0;
 
 }
 
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index 4666870..c4e56ba 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -30,10 +30,6 @@
 
 #include "evdev-mt-touchpad.h"
 
-/* Number found by trial-and error, seems to be 1200, divided by the
- * TP_MAGIC_SLOWDOWN in filter.c */
-#define DEFAULT_ACCEL_NUMERATOR 3000.0
-#define DEFAULT_HYSTERESIS_MARGIN_DENOMINATOR 700.0
 #define DEFAULT_TRACKPOINT_ACTIVITY_TIMEOUT 500 /* ms */
 #define DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_1 200 /* ms */
 #define DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_2 500 /* ms */
@@ -1282,17 +1278,8 @@ tp_init_accel(struct tp_dispatch *tp, double diagonal)
 	 * and y resolution, so that a circle on the
 	 * touchpad does not turn into an elipse on the screen.
 	 */
-	if (!tp->device->abs.fake_resolution) {
-		tp->accel.x_scale_coeff = (DEFAULT_MOUSE_DPI/25.4) / res_x;
-		tp->accel.y_scale_coeff = (DEFAULT_MOUSE_DPI/25.4) / res_y;
-	} else {
-	/*
-	 * For touchpads where the driver does not provide resolution, fall
-	 * back to scaling motion events based on the diagonal size in units.
-	 */
-		tp->accel.x_scale_coeff = DEFAULT_ACCEL_NUMERATOR / diagonal;
-		tp->accel.y_scale_coeff = DEFAULT_ACCEL_NUMERATOR / diagonal;
-	}
+	tp->accel.x_scale_coeff = (DEFAULT_MOUSE_DPI/25.4) / res_x;
+	tp->accel.y_scale_coeff = (DEFAULT_MOUSE_DPI/25.4) / res_y;
 
 	switch (tp->device->model) {
 	case EVDEV_MODEL_LENOVO_X230:
@@ -1494,18 +1481,11 @@ tp_init(struct tp_dispatch *tp,
 						       EV_ABS,
 						       ABS_MT_DISTANCE);
 
-	if (device->abs.fake_resolution) {
-		tp->hysteresis_margin.x =
-			diagonal / DEFAULT_HYSTERESIS_MARGIN_DENOMINATOR;
-		tp->hysteresis_margin.y =
-			diagonal / DEFAULT_HYSTERESIS_MARGIN_DENOMINATOR;
-	} else {
-		int res_x = tp->device->abs.absinfo_x->resolution,
-		    res_y = tp->device->abs.absinfo_y->resolution;
+	int res_x = tp->device->abs.absinfo_x->resolution,
+	    res_y = tp->device->abs.absinfo_y->resolution;
 
-		tp->hysteresis_margin.x = res_x/2;
-		tp->hysteresis_margin.y = res_y/2;
-	}
+	tp->hysteresis_margin.x = res_x/2;
+	tp->hysteresis_margin.y = res_y/2;
 
 	if (tp_init_accel(tp, diagonal) != 0)
 		return -1;
diff --git a/src/evdev.c b/src/evdev.c
index cfcdc34..0bd19a4 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1748,16 +1748,20 @@ evdev_configure_mt_device(struct evdev_device *device)
 	int num_slots;
 	int active_slot;
 	int slot;
+	int guessed_resolution;
 
 	if (!libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) ||
 	    !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y))
 		 return 0;
 
+	guessed_resolution =
+	    (device->abs.absinfo_y->maximum - device->abs.absinfo_y->minimum + 1 + 33) / 67;
+	if (guessed_resolution < 1) guessed_resolution = 1;
 	if (evdev_fix_abs_resolution(device,
 				     ABS_MT_POSITION_X,
 				     ABS_MT_POSITION_Y,
-				     EVDEV_FAKE_RESOLUTION,
-				     EVDEV_FAKE_RESOLUTION))
+				     guessed_resolution,
+				     guessed_resolution))
 		device->abs.fake_resolution = 1;
 
 	device->abs.absinfo_x = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X);
@@ -1812,6 +1816,7 @@ evdev_configure_device(struct evdev_device *device)
 	struct libevdev *evdev = device->evdev;
 	const char *devnode = udev_device_get_devnode(device->udev_device);
 	enum evdev_device_udev_tags udev_tags;
+	int guessed_resolution;
 
 	udev_tags = evdev_device_get_udev_tags(device, device->udev_device);
 
@@ -1864,11 +1869,14 @@ evdev_configure_device(struct evdev_device *device)
 		evdev_fix_android_mt(device);
 
 	if (libevdev_has_event_code(evdev, EV_ABS, ABS_X)) {
+		guessed_resolution =
+		    (device->abs.absinfo_y->maximum - device->abs.absinfo_y->minimum + 1 + 33) / 67;
+		if (guessed_resolution < 1) guessed_resolution = 1;
 		if (evdev_fix_abs_resolution(device,
 					     ABS_X,
 					     ABS_Y,
-					     EVDEV_FAKE_RESOLUTION,
-					     EVDEV_FAKE_RESOLUTION))
+					     guessed_resolution,
+					     guessed_resolution))
 			device->abs.fake_resolution = 1;
 		device->abs.absinfo_x = libevdev_get_abs_info(evdev, ABS_X);
 		device->abs.absinfo_y = libevdev_get_abs_info(evdev, ABS_Y);
-- 
1.9.1



More information about the wayland-devel mailing list