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

Peter Hutterer peter.hutterer at who-t.net
Wed Feb 10 06:17:33 UTC 2016


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 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 309233a..5ed02a9 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -1562,45 +1562,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 a50b0a3..2ec049f 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)
 
@@ -2861,3 +2865,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 79afc20..f36b0d7 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -467,6 +467,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.0



More information about the wayland-devel mailing list