[PATCH libinput] udev: check wacom devices for a paired product id

Quentin Glidic sardemff7+wayland at sardemff7.net
Wed Jul 20 11:36:52 UTC 2016


On 20/07/2016 12:02, Peter Hutterer wrote:
> The newer Wacom Cintiqs have touch devices with a different PID than the pen
> device. Use the new libwacom_get_paired_device call where available to pair
> the two devices and give them the same device group.
>
> This isn't that important just yet, so no need to force users to update to a
> new libwacom version.
>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> Tested-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
> ---
>  configure.ac                 |  9 +++++++
>  udev/Makefile.am             |  5 ++++
>  udev/libinput-device-group.c | 62 ++++++++++++++++++++++++++++++++++++++++++--
>  3 files changed, 74 insertions(+), 2 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 9e238b4..1bf912e 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -208,7 +208,16 @@ AC_ARG_ENABLE(libwacom,
>  if test "x$use_libwacom" = "xyes"; then
>  	PKG_CHECK_MODULES(LIBWACOM, [libwacom >= 0.12], [HAVE_LIBWACOM="yes"])
>  	AC_DEFINE(HAVE_LIBWACOM, 1, [Build with libwacom])
> +	AC_CHECK_LIB([wacom],
> +		     [libwacom_get_paired_device],
> +		     [libwacom_have_get_paired_device=yes,
> +		      AC_DEFINE(HAVE_LIBWACOM_GET_PAIRED_DEVICE, [1],
> +				[libwacom_get_paired_device() is available])],
> +		     [libwacom_have_get_paired_device=no],
> +		     [$LIBWACOM_LIBS])

I may be nitpicking here, but this check sounds wrong. Say you are 
cross-compiling, will AC_CHECK_LIB find the right one? Making it search 
for -lwacom *and* passing $LIBWACOM_LIBS sounds wrong too.
I would use AC_LINK_IFELSE[1] directly.

Cheers,


[1] 
<https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf.html#Running-the-Linker>

>  fi
> +AM_CONDITIONAL(HAVE_LIBWACOM_GET_PAIRED_DEVICE,
> +	       [test "x$libwacom_get_paired_device" == "xyes"])
 >
>  AM_CONDITIONAL(HAVE_VALGRIND, [test "x$VALGRIND" != "x"])
>  AM_CONDITIONAL(BUILD_TESTS, [test "x$build_tests" = "xyes"])
> diff --git a/udev/Makefile.am b/udev/Makefile.am
> index cfb854e..78e3791 100644
> --- a/udev/Makefile.am
> +++ b/udev/Makefile.am
> @@ -10,6 +10,11 @@ libinput_device_group_SOURCES = libinput-device-group.c
>  libinput_device_group_CFLAGS = $(LIBUDEV_CFLAGS) $(GCC_CFLAGS)
>  libinput_device_group_LDADD = $(LIBUDEV_LIBS)
>
> +if HAVE_LIBWACOM_GET_PAIRED_DEVICE
> +libinput_device_group_CFLAGS += $(LIBWACOM_CFLAGS)
> +libinput_device_group_LDADD += $(LIBWACOM_LIBS)
> +endif
> +
>  libinput_model_quirks_SOURCES = libinput-model-quirks.c
>  libinput_model_quirks_CFLAGS = \
>  			       -I$(top_srcdir)/src \
> diff --git a/udev/libinput-device-group.c b/udev/libinput-device-group.c
> index ab9409b..217ed44 100644
> --- a/udev/libinput-device-group.c
> +++ b/udev/libinput-device-group.c
> @@ -21,11 +21,47 @@
>   * DEALINGS IN THE SOFTWARE.
>   */
>
> +#include "config.h"
> +
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
>  #include <libudev.h>
>
> +#if HAVE_LIBWACOM_GET_PAIRED_DEVICE
> +#include <libwacom/libwacom.h>
> +
> +static void
> +wacom_handle_paired(struct udev_device *device,
> +		    int *vendor_id,
> +		    int *product_id)
> +{
> +	WacomDeviceDatabase *db = NULL;
> +	WacomDevice *tablet = NULL;
> +	const WacomMatch *paired;
> +
> +	db = libwacom_database_new();
> +	if (!db)
> +		goto out;
> +
> +	tablet = libwacom_new_from_usbid(db, *vendor_id, *product_id, NULL);
> +	if (!tablet)
> +		goto out;
> +	paired = libwacom_get_paired_device(tablet);
> +	if (!paired)
> +		goto out;
> +
> +	*vendor_id = libwacom_match_get_vendor_id(paired);
> +	*product_id = libwacom_match_get_product_id(paired);
> +
> +out:
> +	if (tablet)
> +		libwacom_destroy(tablet);
> +	if (db)
> +		libwacom_database_destroy(db);
> +}
> +#endif
> +
>  int main(int argc, char **argv)
>  {
>  	int rc = 1;
> @@ -34,6 +70,7 @@ int main(int argc, char **argv)
>  	const char *syspath,
>  	           *phys = NULL;
>  	const char *product;
> +	int bustype, vendor_id, product_id, version;
>  	char group[1024];
>  	char *str;
>
> @@ -73,8 +110,29 @@ int main(int argc, char **argv)
>  	   on that*/
>  	product = udev_device_get_property_value(device, "PRODUCT");
>  	if (!product)
> -		product = "";
> -	snprintf(group, sizeof(group), "%s:%s", product, phys);
> +		product = "00/00/00/00";
> +
> +	if (sscanf(product,
> +		   "%x/%x/%x/%x",
> +		   &bustype,
> +		   &vendor_id,
> +		   &product_id,
> +		   &version) != 4) {
> +		snprintf(group, sizeof(group), "%s:%s", product, phys);
> +	} else {
> +#if HAVE_LIBWACOM_GET_PAIRED_DEVICE
> +	    if (vendor_id == VENDOR_ID_WACOM)
> +		    wacom_handle_paired(device, &vendor_id, &product_id);
> +#endif
> +	    snprintf(group,
> +		     sizeof(group),
> +		     "%x/%x/%x/%x:%s",
> +		     bustype,
> +		     vendor_id,
> +		     product_id,
> +		     version,
> +		     phys);
> +	}
>
>  	str = strstr(group, "/input");
>  	if (str)
>


-- 

Quentin “Sardem FF7” Glidic


More information about the wayland-devel mailing list