touchpad: default to a 69x50mm sized touchpad
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 30 Jun 2015 04:26:11 +0000 (14:26 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 14 Jul 2015 00:12:12 +0000 (10:12 +1000)
The previous approach of using the axis ranges and approximating parameters
based on the x/y axis range clutters up the code and is generally unreliable.
If we look at Synaptics touchpads, the resolution ranges from 42 to 130 while
the axes stay the same axis range. Other touchpads likely have a similar
variation across the various models.

Let's make this simpler in code: unless we know otherwise, simply assume a
default-sized touchpad.
Anything that deviates from that can be fixed with the new hwdb entries to
provide a more correct setting.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
src/evdev-mt-touchpad.c

index 3f5daba..11fc03b 100644 (file)
@@ -1559,6 +1559,43 @@ error:
 }
 
 static int
+tp_init_default_resolution(struct tp_dispatch *tp,
+                          struct evdev_device *device)
+{
+       const int touchpad_width_mm = 69, /* 1 under palm detection */
+                 touchpad_height_mm = 50;
+       int xres, yres;
+
+       if (!device->abs.fake_resolution)
+               return 0 ;
+
+       /* we only get here if
+        * - the touchpad provides no resolution
+        * - the udev hwdb didn't override the resoluion
+        * - no ATTR_SIZE_HINT is set
+        *
+        * The majority of touchpads that triggers all these conditions
+        * are old ones, so let's assume a small touchpad size and assume
+        * that.
+        */
+       log_info(tp_libinput_context(tp),
+                "%s: no resolution or size hints, assuming a size of %dx%dmm\n",
+                device->devname,
+                touchpad_width_mm,
+                touchpad_height_mm);
+
+       xres = device->abs.dimensions.x/touchpad_width_mm;
+       yres = device->abs.dimensions.y/touchpad_height_mm;
+       libevdev_set_abs_resolution(device->evdev, ABS_X, xres);
+       libevdev_set_abs_resolution(device->evdev, ABS_Y, yres);
+       libevdev_set_abs_resolution(device->evdev, ABS_MT_POSITION_X, xres);
+       libevdev_set_abs_resolution(device->evdev, ABS_MT_POSITION_Y, yres);
+       device->abs.fake_resolution = 0;
+
+       return 0;
+}
+
+static int
 tp_init(struct tp_dispatch *tp,
        struct evdev_device *device)
 {
@@ -1571,6 +1608,9 @@ tp_init(struct tp_dispatch *tp,
        if (tp_sanity_check(tp, device) != 0)
                return -1;
 
+       if (tp_init_default_resolution(tp, device) != 0)
+               return -1;
+
        if (tp_init_slots(tp, device) != 0)
                return -1;