summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac19
-rw-r--r--udev/Makefile.am9
-rw-r--r--udev/libinput-device-group.c64
3 files changed, 89 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index 9e238b46..b6f75552 100644
--- a/configure.ac
+++ b/configure.ac
@@ -208,7 +208,26 @@ 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])
+
+ OLD_LIBS=$LIBS
+ OLD_CFLAGS=$CFLAGS
+ LIBS="$LIBS $LIBWACOM_LIBS"
+ CFLAGS="$CFLAGS $LIBWACOM_CFLAGS"
+ AC_MSG_CHECKING([if libwacom_get_paired_device is available])
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([[#include <libwacom/libwacom.h>]],
+ [[libwacom_get_paired_device(NULL)]])],
+ [AC_MSG_RESULT([yes])
+ AC_DEFINE(HAVE_LIBWACOM_GET_PAIRED_DEVICE, [1],
+ [libwacom_get_paired_device() is available])
+ [libwacom_have_get_paired_device=yes]],
+ [AC_MSG_RESULT([no])
+ [libwacom_have_get_paired_device=no]])
+ LIBS=$OLD_LIBS
+ CFLAGS=$OLD_CFLAGS
fi
+AM_CONDITIONAL(HAVE_LIBWACOM_GET_PAIRED_DEVICE,
+ [test "x$libwacom_have_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 cfb854e1..f06dc564 100644
--- a/udev/Makefile.am
+++ b/udev/Makefile.am
@@ -7,9 +7,16 @@ litest_rules = 80-libinput-device-groups-litest.rules \
noinst_SCRIPTS = $(litest_rules)
libinput_device_group_SOURCES = libinput-device-group.c
-libinput_device_group_CFLAGS = $(LIBUDEV_CFLAGS) $(GCC_CFLAGS)
+libinput_device_group_CFLAGS = -I$(top_srcdir)/src \
+ $(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 ab9409bf..fa70e115 100644
--- a/udev/libinput-device-group.c
+++ b/udev/libinput-device-group.c
@@ -21,11 +21,49 @@
* DEALINGS IN THE SOFTWARE.
*/
+#include "config.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libudev.h>
+#include "libinput-util.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 +72,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 +112,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)