[PATCH xf86-input-libinput] Use the libinput touch count to init the right number of touches

Peter Hutterer peter.hutterer at who-t.net
Wed May 2 04:03:12 UTC 2018


Initial version by Johannes Pointner <h4nn35.work at gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 configure.ac       | 12 +++++++++++-
 src/xf86libinput.c | 10 +++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5892c5e..9c7174c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,11 +47,11 @@ XORG_DEFAULT_OPTIONS
 PKG_CHECK_MODULES(XORG, [xorg-server >= 1.10] xproto [inputproto >= 2.2])
 PKG_CHECK_MODULES(LIBINPUT, [libinput >= 1.4.901])
 
-AC_MSG_CHECKING([if libinput_device_config_accel_set_curve_point is available])
 OLD_LIBS=$LIBS
 OLD_CFLAGS=$CFLAGS
 LIBS="$LIBS $LIBINPUT_LIBS"
 CFLAGS="$CFLAGS $LIBINPUT_CFLAGS"
+AC_MSG_CHECKING([if libinput_device_config_accel_set_curve_point is available])
 AC_LINK_IFELSE(
                [AC_LANG_PROGRAM([[#include <libinput.h>]],
                                 [[libinput_device_config_accel_set_curve_point(NULL, 0, 0)]])],
@@ -61,6 +61,16 @@ AC_LINK_IFELSE(
                 [libinput_have_custom_accel_curve=yes]],
                [AC_MSG_RESULT([no])
                 [libinput_have_custom_accel_curve=no]])
+AC_MSG_CHECKING([if libinput_device_touch_get_touch_count is available])
+AC_LINK_IFELSE(
+               [AC_LANG_PROGRAM([[#include <libinput.h>]],
+                                [[libinput_device_touch_get_touch_count(NULL)]])],
+               [AC_MSG_RESULT([yes])
+                AC_DEFINE(HAVE_LIBINPUT_TOUCH_COUNT, [1],
+                          [libinput_device_touch_get_touch_count() is available])
+                [libinput_have_touch_count=yes]],
+               [AC_MSG_RESULT([no])
+                [libinput_have_touch_count=no]])
 LIBS=$OLD_LIBS
 CFLAGS=$OLD_CFLAGS
 
diff --git a/src/xf86libinput.c b/src/xf86libinput.c
index 4a1b9e6..180907e 100644
--- a/src/xf86libinput.c
+++ b/src/xf86libinput.c
@@ -1095,11 +1095,13 @@ xf86libinput_init_touch(InputInfoPtr pInfo)
 {
 	DeviceIntPtr dev = pInfo->dev;
 	struct xf86libinput *driver_data = pInfo->private;
+	struct libinput_device *device = driver_data->shared_device->device;
 	int min, max, res;
 	unsigned char btnmap[MAX_BUTTONS + 1];
 	Atom btnlabels[MAX_BUTTONS];
 	Atom axislabels[TOUCHPAD_NUM_AXES];
 	int nbuttons = 7;
+	int ntouches = TOUCH_MAX_SLOTS;
 
 	init_button_map(btnmap, ARRAY_SIZE(btnmap));
 	init_button_labels(btnlabels, ARRAY_SIZE(btnlabels));
@@ -1123,7 +1125,13 @@ xf86libinput_init_touch(InputInfoPtr pInfo)
 	xf86InitValuatorAxisStruct(dev, 1,
 			           XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_POSITION_Y),
 				   min, max, res * 1000, 0, res * 1000, Absolute);
-	InitTouchClassDeviceStruct(dev, TOUCH_MAX_SLOTS, XIDirectTouch, 2);
+
+#if HAVE_LIBINPUT_TOUCH_COUNT
+	ntouches = libinput_device_touch_get_touch_count(device);
+	if (ntouches == 0) /* unknown -  mtdev */
+		ntouches = TOUCH_MAX_SLOTS;
+#endif
+	InitTouchClassDeviceStruct(dev, ntouches, XIDirectTouch, 2);
 
 }
 
-- 
2.14.3



More information about the xorg-devel mailing list