[PATCH v2 libinput 1/5] tablet: move the libwacom check for left-handed-ness into a helper function

Peter Hutterer peter.hutterer at who-t.net
Mon Apr 11 04:15:28 UTC 2016


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
Changes since v1:
- new in this version

 src/evdev-tablet.c | 38 +-------------------------------------
 src/evdev.c        | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/evdev.h        |  3 +++
 3 files changed, 56 insertions(+), 37 deletions(-)

diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
index 9a1ac52..3c3ebcf 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -1571,45 +1571,9 @@ tablet_init_accel(struct tablet_dispatch *tablet, struct evdev_device *device)
 static void
 tablet_init_left_handed(struct evdev_device *device)
 {
-#if HAVE_LIBWACOM
-	struct libinput *libinput = device->base.seat->libinput;
-	WacomDeviceDatabase *db;
-	WacomDevice *d = NULL;
-	WacomError *error;
-	const char *devnode;
-
-	db = libwacom_database_new();
-	if (!db) {
-		log_info(libinput,
-			 "Failed to initialize libwacom context.\n");
-		return;
-	}
-	error = libwacom_error_new();
-	devnode = udev_device_get_devnode(device->udev_device);
-
-	d = libwacom_new_from_path(db,
-				   devnode,
-				   WFALLBACK_NONE,
-				   error);
-
-	if (d) {
-		if (libwacom_is_reversible(d))
+	if (evdev_tablet_has_left_handed(device))
 		    evdev_init_left_handed(device,
 					   tablet_change_to_left_handed);
-	} else if (libwacom_error_get_code(error) == WERROR_UNKNOWN_MODEL) {
-		log_info(libinput, "Tablet unknown to libwacom\n");
-	} else {
-		log_error(libinput,
-			  "libwacom error: %s\n",
-			  libwacom_error_get_message(error));
-	}
-
-	if (error)
-		libwacom_error_free(&error);
-	if (d)
-		libwacom_destroy(d);
-	libwacom_database_destroy(db);
-#endif
 }
 
 static int
diff --git a/src/evdev.c b/src/evdev.c
index 6bb8986..a5511c5 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -43,6 +43,10 @@
 #include "filter.h"
 #include "libinput-private.h"
 
+#if HAVE_LIBWACOM
+#include <libwacom/libwacom.h>
+#endif
+
 #define DEFAULT_WHEEL_CLICK_ANGLE 15
 #define DEFAULT_MIDDLE_BUTTON_SCROLL_TIMEOUT ms2us(200)
 
@@ -2858,3 +2862,51 @@ evdev_device_destroy(struct evdev_device *device)
 	free(device->mt.slots);
 	free(device);
 }
+
+bool
+evdev_tablet_has_left_handed(struct evdev_device *device)
+{
+#if HAVE_LIBWACOM
+	struct libinput *libinput = device->base.seat->libinput;
+	WacomDeviceDatabase *db;
+	WacomDevice *d = NULL;
+	WacomError *error;
+	const char *devnode;
+	bool has_left_handed = false;
+
+	db = libwacom_database_new();
+	if (!db) {
+		log_info(libinput,
+			 "Failed to initialize libwacom context.\n");
+		goto out;
+	}
+
+	error = libwacom_error_new();
+	devnode = udev_device_get_devnode(device->udev_device);
+
+	d = libwacom_new_from_path(db,
+				   devnode,
+				   WFALLBACK_NONE,
+				   error);
+
+	if (d) {
+		if (libwacom_is_reversible(d))
+			has_left_handed = true;
+	} else if (libwacom_error_get_code(error) == WERROR_UNKNOWN_MODEL) {
+		log_info(libinput, "Tablet unknown to libwacom\n");
+	} else {
+		log_error(libinput,
+			  "libwacom error: %s\n",
+			  libwacom_error_get_message(error));
+	}
+
+	if (error)
+		libwacom_error_free(&error);
+	if (d)
+		libwacom_destroy(d);
+	libwacom_database_destroy(db);
+
+out:
+	return has_left_handed;
+#endif
+}
diff --git a/src/evdev.h b/src/evdev.h
index 4a5d807..f5e7bed 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -454,6 +454,9 @@ int
 evdev_init_left_handed(struct evdev_device *device,
 		       void (*change_to_left_handed)(struct evdev_device *));
 
+bool
+evdev_tablet_has_left_handed(struct evdev_device *device);
+
 static inline uint32_t
 evdev_to_left_handed(struct evdev_device *device,
 		     uint32_t button)
-- 
2.5.5



More information about the wayland-devel mailing list