Peter Hutterer said the following on 10/12/2012 06:37 AM:
  [...]
+                       *builtin = (flag&  (direct_flag | pointer_flag) == 
direct_flag)
+                                   ? IS_BUILTIN_TRUE : IS_BUILTIN_FALSE;
please expand this to a normal condition - this is too nested to be
easily readable.

Updated patch attached. Got rid of the 2 additional vars as they did not really help with readability.

Cheers,
Olivier.
>From 6ad00f204455b7a94986b2f0c2ecd8bfb2c34ce8 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 the device is a screen tablet
check DIRECT flag is set but not POINTER.

Signed-off-by: Olivier Fourdan <ofour...@redhat.com>
---
 configure.ac        |    1 +
 libwacom/libwacom.c |   28 +++++++++++++++++++++++++---
 2 files changed, 26 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..a60527f 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)
 {
@@ -163,10 +176,19 @@ get_device_info (const char   *path,
 		if (g_file_get_contents (sysfs_path, &contents, NULL, NULL)) {
 			int flag;
 
-			/* 0x01: POINTER flag
-			 * 0x02: DIRECT flag */
 			flag = atoi(contents);
-			*builtin = (flag & 0x02) == 0x02 ? IS_BUILTIN_TRUE : IS_BUILTIN_FALSE;
+			flag &= (1 << INPUT_PROP_DIRECT) | (1 << INPUT_PROP_POINTER);
+			/*
+			 * To ensure we are dealing with a screen tablet, need
+			 * to check that it has DIRECT and non-POINTER (DIRECT
+			 * alone is not sufficient since it's set for drawing
+			 * tablets as well)
+			 */
+			if (flag == (1 << INPUT_PROP_DIRECT))
+				*builtin = IS_BUILTIN_TRUE;
+			else
+				*builtin = 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