diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 2cf8b567..1636e7a2 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "evdev-mt-touchpad.h" @@ -753,9 +754,21 @@ tp_init_palmdetect(struct tp_dispatch *tp, { int width; + /* We don't know how big the touchpad is */ + if (device->abs.absinfo_x->resolution == 1) + return 0; + width = abs(device->abs.absinfo_x->maximum - device->abs.absinfo_x->minimum); + /* Enable palm detection on touchpads >= 80 mm. Anything smaller + probably won't need it, until we find out it does */ + if (width/device->abs.absinfo_x->resolution < 80) { + tp->palm.right_edge = INT_MAX; + tp->palm.left_edge = INT_MIN; + return 0; + } + /* palm edges are 5% of the width on each side */ tp->palm.right_edge = device->abs.absinfo_x->maximum - width * 0.05; tp->palm.left_edge = device->abs.absinfo_x->minimum + width * 0.05; diff --git a/test/touchpad.c b/test/touchpad.c index 1d95399c..c1bdbd53 100644 --- a/test/touchpad.c +++ b/test/touchpad.c @@ -1241,11 +1241,24 @@ START_TEST(touchpad_tap_default) } END_TEST +static int +touchpad_has_palm_detect_size(struct litest_device *dev) +{ + double width, height; + + libinput_device_get_size(dev->libinput_device, &width, &height); + + return width >= 80; +} + START_TEST(touchpad_palm_detect_at_edge) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; + if (!touchpad_has_palm_detect_size(dev)) + return; + litest_drain_events(li); litest_touch_down(dev, 0, 99, 50); @@ -1265,6 +1278,9 @@ START_TEST(touchpad_palm_detect_at_bottom_corners) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; + if (!touchpad_has_palm_detect_size(dev)) + return; + /* Run for non-clickpads only: make sure the bottom corners trigger palm detection too */ litest_drain_events(li); @@ -1286,6 +1302,9 @@ START_TEST(touchpad_palm_detect_at_top_corners) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; + if (!touchpad_has_palm_detect_size(dev)) + return; + /* Run for non-clickpads only: make sure the bottom corners trigger palm detection too */ litest_drain_events(li); @@ -1307,6 +1326,9 @@ START_TEST(touchpad_palm_detect_palm_stays_palm) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; + if (!touchpad_has_palm_detect_size(dev)) + return; + litest_drain_events(li); litest_touch_down(dev, 0, 99, 20); @@ -1323,6 +1345,9 @@ START_TEST(touchpad_palm_detect_palm_becomes_pointer) struct libinput_event *ev; enum libinput_event_type type; + if (!touchpad_has_palm_detect_size(dev)) + return; + litest_drain_events(li); litest_touch_down(dev, 0, 99, 50); @@ -1352,6 +1377,9 @@ START_TEST(touchpad_palm_detect_no_palm_moving_into_edges) struct libinput_event *ev; enum libinput_event_type type; + if (!touchpad_has_palm_detect_size(dev)) + return; + /* moving non-palm into the edge does not label it as palm */ litest_drain_events(li);