From ad031733f25e064ecfe8a449d1a5035da1a421de Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 4 Jul 2016 12:59:01 +1000 Subject: [PATCH] evdev: move axis dimension handling into a single helper function Signed-off-by: Peter Hutterer --- src/evdev.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/evdev.c b/src/evdev.c index 59dbde3e..409799d9 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -2116,14 +2116,30 @@ evdev_reject_device(struct evdev_device *device) return false; } -static bool -evdev_configure_mt_device(struct evdev_device *device) +static void +evdev_extract_abs_axes(struct evdev_device *device) { struct libevdev *evdev = device->evdev; - if (!libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) || + if (!libevdev_has_event_code(evdev, EV_ABS, ABS_X) || + !libevdev_has_event_code(evdev, EV_ABS, ABS_Y)) + return; + + if (evdev_fix_abs_resolution(device, ABS_X, ABS_Y)) + 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); + 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) || + !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) || !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y)) - return true; + return; if (evdev_fix_abs_resolution(device, ABS_MT_POSITION_X, @@ -2137,8 +2153,6 @@ evdev_configure_mt_device(struct evdev_device *device) device->abs.dimensions.y = abs(device->abs.absinfo_y->maximum - device->abs.absinfo_y->minimum); device->is_mt = 1; - - return true; } static struct evdev_dispatch * @@ -2201,22 +2215,10 @@ evdev_configure_device(struct evdev_device *device) evdev_fix_android_mt(device); if (libevdev_has_event_code(evdev, EV_ABS, ABS_X)) { - if (evdev_fix_abs_resolution(device, ABS_X, ABS_Y)) - 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); - 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); + evdev_extract_abs_axes(device); - if (evdev_is_fake_mt_device(device)) { + if (evdev_is_fake_mt_device(device)) udev_tags &= ~EVDEV_UDEV_TAG_TOUCHSCREEN; - } else if (!evdev_configure_mt_device(device)) { - return NULL; - } } /* libwacom assigns touchpad (or touchscreen) _and_ tablet to the