As discussed on the mailing list, replace the cryptic hex values with bit shifts from linux/input.h (if available, adds a check to configure.ac for that as well).
>From 6083b1e619d35d98ba5339baeef50ffb1590a957 Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <ofour...@redhat.com>
Date: Thu, 11 Oct 2012 10:32:10 +0200
Subject: [PATCH] lib: use kernel flags if available

to identify screen tablets if not set in the database.

To properly ensure that you're getting a touchscreen,
check DIRECT flag is set but not POINTER.

Signed-off-by: Olivier Fourdan <ofour...@redhat.com>
---
 configure.ac        |    1 +
 libwacom/libwacom.c |   20 +++++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index 432f0e7..64571ef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,6 +32,7 @@ AC_CHECK_PROG(HAVE_DOXYGEN, [doxygen], [yes], [no])
 AM_CONDITIONAL(HAVE_DOXYGEN, test "x$HAVE_DOXYGEN" = xyes)
 
 PKG_CHECK_MODULES(GLIB, glib-2.0 gudev-1.0)
+AC_CHECK_HEADERS(linux/input.h)
 
 AC_CONFIG_FILES([Makefile
                  data/Makefile
diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c
index fe850a2..e380d83 100644
--- a/libwacom/libwacom.c
+++ b/libwacom/libwacom.c
@@ -34,6 +34,19 @@
 #include <string.h>
 #include <gudev/gudev.h>
 
+#ifdef HAVE_LINUX_INPUT_H
+#include <linux/input.h>
+#endif
+
+/* Defined in linux/input.h but older versions may be missing these definitions */
+#ifndef INPUT_PROP_POINTER
+#define INPUT_PROP_POINTER		0x00	/* needs a pointer */
+#endif
+
+#ifndef INPUT_PROP_DIRECT
+#define INPUT_PROP_DIRECT		0x01	/* direct input devices */
+#endif
+
 static const WacomDevice *
 libwacom_get_device(WacomDeviceDatabase *db, const char *match)
 {
@@ -162,11 +175,12 @@ get_device_info (const char   *path,
 		sysfs_path = g_build_filename ("/sys/class/input", devname, "device/properties", NULL);
 		if (g_file_get_contents (sysfs_path, &contents, NULL, NULL)) {
 			int flag;
+			int direct_flag = (1 << INPUT_PROP_DIRECT);
+			int pointer_flag = (1 << INPUT_PROP_POINTER);
 
-			/* 0x01: POINTER flag
-			 * 0x02: DIRECT flag */
 			flag = atoi(contents);
-			*builtin = (flag & 0x02) == 0x02 ? IS_BUILTIN_TRUE : IS_BUILTIN_FALSE;
+			*builtin = (flag & (direct_flag | pointer_flag) == direct_flag)
+			            ? IS_BUILTIN_TRUE : IS_BUILTIN_FALSE;
 			g_free (contents);
 		}
 		g_free (sysfs_path);
-- 
1.7.1

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to