>From de46c3bb8351399c3e2ec02e11f93f0ce6403e5f Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <ofour...@redhat.com>
Date: Mon, 8 Oct 2012 16:00:41 +0200
Subject: [PATCH 1/2] lib: add "IntegratedIn" to device group

to describe integrated system devices and screen tablets.

A bit field allows to indentify the level of integration of
a device:

    WACOM_DEVICE_INTEGRATED_NONE    device is a standalone tablet
    WACOM_DEVICE_INTEGRATED_DISPLAY device is a screen tablet
    WACOM_DEVICE_INTEGRATED_SYSTEM  device is an ISD such as
                                    a tablet PC.
    WACOM_DEVICE_INTEGRATED_UNSET   The information is not set
                                    in the database

These definitions supercede the previous libwacom_is_builtin()
API which is now deprecated.
---
 libwacom/libwacom-database.c |   56 +++++++++++++++++++++++++-----------
 libwacom/libwacom.c          |   64 +++++++++++++++++++++++++++++------------
 libwacom/libwacom.h          |   23 ++++++++++++++-
 libwacom/libwacomint.h       |   10 +-----
 4 files changed, 107 insertions(+), 46 deletions(-)

diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c
index d39305d..5ef8201 100644
--- a/libwacom/libwacom-database.c
+++ b/libwacom/libwacom-database.c
@@ -256,6 +256,14 @@ struct {
 	{ "Touchstrip2",	WACOM_STATUS_LED_TOUCHSTRIP2 }
 };
 
+struct {
+	const char             *key;
+	WacomIntegrationFlags   value;
+} integration_flags[] = {
+	{ "Display",		WACOM_DEVICE_INTEGRATED_DISPLAY },
+	{ "System",		WACOM_DEVICE_INTEGRATED_SYSTEM }
+};
+
 static void
 libwacom_parse_buttons_key(WacomDevice      *device,
 			   GKeyFile         *keyfile,
@@ -327,8 +335,7 @@ libwacom_parse_tablet_keyfile(const char *path)
 	gboolean rc;
 	char *class;
 	char *match;
-	char **styli_list;
-	char **leds_list;
+	char **string_list;
 
 	keyfile = g_key_file_new();
 
@@ -359,25 +366,42 @@ libwacom_parse_tablet_keyfile(const char *path)
 	device->width = g_key_file_get_integer(keyfile, DEVICE_GROUP, "Width", NULL);
 	device->height = g_key_file_get_integer(keyfile, DEVICE_GROUP, "Height", NULL);
 
+	device->integration_flags = WACOM_DEVICE_INTEGRATED_UNSET;
+	string_list = g_key_file_get_string_list(keyfile, DEVICE_GROUP, "IntegratedIn", NULL, NULL);
+	if (string_list) {
+		guint i, n;
+
+		device->integration_flags = WACOM_DEVICE_INTEGRATED_NONE;
+		for (i = 0; string_list[i]; i++) {
+			for (n = 0; n < G_N_ELEMENTS (integration_flags); n++) {
+				if (!strcmp(string_list[i], integration_flags[n].key)) {
+					device->integration_flags |= integration_flags[n].value;
+					break;
+				}
+			}
+		}
+		g_strfreev (string_list);
+	}
+
 	class = g_key_file_get_string(keyfile, DEVICE_GROUP, "Class", NULL);
 	device->cls = libwacom_class_string_to_enum(class);
 	g_free(class);
 
-	styli_list = g_key_file_get_string_list(keyfile, DEVICE_GROUP, "Styli", NULL, NULL);
-	if (styli_list) {
+	string_list = g_key_file_get_string_list(keyfile, DEVICE_GROUP, "Styli", NULL, NULL);
+	if (string_list) {
 		GArray *array;
 		guint i;
 
 		array = g_array_new (FALSE, FALSE, sizeof(int));
 		device->num_styli = 0;
-		for (i = 0; styli_list[i]; i++) {
-			glong long_value = strtol (styli_list[i], NULL, 0);
+		for (i = 0; string_list[i]; i++) {
+			glong long_value = strtol (string_list[i], NULL, 0);
 			int int_value = long_value;
 
 			g_array_append_val (array, int_value);
 			device->num_styli++;
 		}
-		g_strfreev (styli_list);
+		g_strfreev (string_list);
 		device->supported_styli = (int *) g_array_free (array, FALSE);
 	} else {
 		device->supported_styli = g_new (int, 2);
@@ -399,15 +423,12 @@ libwacom_parse_tablet_keyfile(const char *path)
 	if (g_key_file_get_boolean(keyfile, FEATURES_GROUP, "Ring2", NULL))
 		device->features |= FEATURE_RING2;
 
-	if (g_key_file_get_boolean(keyfile, FEATURES_GROUP, "BuiltIn", NULL))
-		device->features |= FEATURE_BUILTIN;
-
 	if (g_key_file_get_boolean(keyfile, FEATURES_GROUP, "Reversible", NULL))
 		device->features |= FEATURE_REVERSIBLE;
 
-	if (device->features & FEATURE_BUILTIN &&
+	if (device->integration_flags & WACOM_DEVICE_INTEGRATED_DISPLAY &&
 	    device->features & FEATURE_REVERSIBLE)
-		g_warning ("Tablet '%s' is both reversible and builtin. This is impossible", libwacom_get_match(device));
+		g_warning ("Tablet '%s' is both reversible and integrated in screen. This is impossible", libwacom_get_match(device));
 
 	if (!(device->features & FEATURE_RING) &&
 	    (device->features & FEATURE_RING2))
@@ -425,22 +446,23 @@ libwacom_parse_tablet_keyfile(const char *path)
 		libwacom_parse_buttons(device, keyfile);
 	}
 
-	leds_list = g_key_file_get_string_list(keyfile, FEATURES_GROUP, "StatusLEDs", NULL, NULL);
-	if (leds_list) {
+	string_list = g_key_file_get_string_list(keyfile, FEATURES_GROUP, "StatusLEDs", NULL, NULL);
+	if (string_list) {
 		GArray *array;
 		guint i, n;
+
 		array = g_array_new (FALSE, FALSE, sizeof(WacomStatusLEDs));
 		device->num_leds = 0;
-		for (i = 0; leds_list[i]; i++) {
+		for (i = 0; string_list[i]; i++) {
 			for (n = 0; n < G_N_ELEMENTS (supported_leds); n++) {
-				if (!strcmp(leds_list[i], supported_leds[n].key)) {
+				if (!strcmp(string_list[i], supported_leds[n].key)) {
 					g_array_append_val (array, supported_leds[n].value);
 					device->num_leds++;
 					break;
 				}
 			}
 		}
-		g_strfreev (leds_list);
+		g_strfreev (string_list);
 		device->status_leds = (WacomStatusLEDs *) g_array_free (array, FALSE);
 	}
 
diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c
index 4f8c5f9..5f8dec1 100644
--- a/libwacom/libwacom.c
+++ b/libwacom/libwacom.c
@@ -111,13 +111,13 @@ get_bus (GUdevDevice *device)
 }
 
 static gboolean
-get_device_info (const char   *path,
-		 int          *vendor_id,
-		 int          *product_id,
-		 char        **name,
-		 WacomBusType *bus,
-		 IsBuiltin    *builtin,
-		 WacomError   *error)
+get_device_info (const char            *path,
+		 int                   *vendor_id,
+		 int                   *product_id,
+		 char                 **name,
+		 WacomBusType          *bus,
+		 WacomIntegrationFlags *integration_flags,
+		 WacomError            *error)
 {
 	GUdevClient *client;
 	GUdevDevice *device;
@@ -129,7 +129,7 @@ get_device_info (const char   *path,
 	g_type_init();
 
 	retval = FALSE;
-	*builtin = IS_BUILTIN_UNSET;
+	*integration_flags = WACOM_DEVICE_INTEGRATED_UNSET;
 	*name = NULL;
 	bus_str = NULL;
 	client = g_udev_client_new (subsystems);
@@ -154,7 +154,7 @@ get_device_info (const char   *path,
 
 	bus_str = get_bus (device);
 
-	/* Is the device builtin? */
+	/* Is the device integrated in display? */
 	devname = g_udev_device_get_name (device);
 	if (devname != NULL) {
 		char *sysfs_path, *contents;
@@ -166,7 +166,7 @@ get_device_info (const char   *path,
 			/* 0x01: POINTER flag
 			 * 0x02: DIRECT flag */
 			flag = atoi(contents);
-			*builtin = (flag & 0x02) == 0x02 ? IS_BUILTIN_TRUE : IS_BUILTIN_FALSE;
+			*integration_flags = (flag & 0x02) == 0x02 ? WACOM_DEVICE_INTEGRATED_DISPLAY : WACOM_DEVICE_INTEGRATED_NONE;
 			g_free (contents);
 		}
 		g_free (sysfs_path);
@@ -290,6 +290,7 @@ libwacom_copy(const WacomDevice *device)
 	d->name = g_strdup (device->name);
 	d->width = device->width;
 	d->height = device->height;
+	d->integration_flags = device->integration_flags;
 	d->nmatches = device->nmatches;
 	d->matches = g_malloc((d->nmatches + 1) * sizeof(WacomMatch*));
 	for (i = 0; i < d->nmatches; i++)
@@ -347,6 +348,9 @@ libwacom_compare(WacomDevice *a, WacomDevice *b, WacomCompareFlags flags)
 	if (a->width != b->width || a->height != b->height)
 		return 1;
 
+	if (a->integration_flags != b->integration_flags)
+		return 1;
+
 	if (a->cls != b->cls)
 		return 1;
 
@@ -416,7 +420,7 @@ libwacom_new_from_path(WacomDeviceDatabase *db, const char *path, WacomFallbackF
 	WacomBusType bus;
 	const WacomDevice *device;
 	WacomDevice *ret;
-	IsBuiltin builtin;
+	WacomIntegrationFlags integration_flags;
 	char *name;
 
 	if (!db) {
@@ -429,7 +433,7 @@ libwacom_new_from_path(WacomDeviceDatabase *db, const char *path, WacomFallbackF
 		return NULL;
 	}
 
-	if (!get_device_info (path, &vendor_id, &product_id, &name, &bus, &builtin, error))
+	if (!get_device_info (path, &vendor_id, &product_id, &name, &bus, &integration_flags, error))
 		return NULL;
 
 	device = libwacom_new (db, vendor_id, product_id, bus, error);
@@ -457,10 +461,10 @@ libwacom_new_from_path(WacomDeviceDatabase *db, const char *path, WacomFallbackF
 	libwacom_update_match(ret, bus, vendor_id, product_id);
 
 	if (device) {
-		if (builtin == IS_BUILTIN_TRUE)
-			ret->features |= FEATURE_BUILTIN;
-		else if (builtin == IS_BUILTIN_FALSE)
-			ret->features &= ~FEATURE_BUILTIN;
+		if (integration_flags == WACOM_DEVICE_INTEGRATED_DISPLAY)
+			ret->integration_flags |= WACOM_DEVICE_INTEGRATED_DISPLAY;
+		else if (integration_flags == WACOM_DEVICE_INTEGRATED_NONE)
+			ret->integration_flags &= ~WACOM_DEVICE_INTEGRATED_DISPLAY;
 
 		return ret;
 	}
@@ -593,6 +597,24 @@ static void print_buttons_for_device (int fd, WacomDevice *device)
 	dprintf(fd, "\n");
 }
 
+static void print_integrated_flags_for_device (int fd, WacomDevice *device)
+{
+	/*
+	 * If WACOM_DEVICE_INTEGRATED_UNSET is set, the info is not provided by
+	 * the tablet database but deduced otherwise (e.g. from sysfs device
+	 * properties on Linux)
+	 */
+	if (device->integration_flags & WACOM_DEVICE_INTEGRATED_UNSET)
+		return;
+	dprintf(fd, "IntegratedIn=");
+	if (device->integration_flags & WACOM_DEVICE_INTEGRATED_DISPLAY)
+		dprintf(fd, "Display;");
+	if (device->integration_flags & WACOM_DEVICE_INTEGRATED_SYSTEM)
+		dprintf(fd, "System;");
+	dprintf(fd, "\n");
+}
+
+
 void
 libwacom_print_device_description(int fd, WacomDevice *device)
 {
@@ -638,6 +660,7 @@ libwacom_print_device_description(int fd, WacomDevice *device)
 	dprintf(fd, "Class=%s\n",		class_name);
 	dprintf(fd, "Width=%d\n",		libwacom_get_width(device));
 	dprintf(fd, "Height=%d\n",		libwacom_get_height(device));
+	print_integrated_flags_for_device(fd, device);
 	print_styli_for_device(fd, device);
 	dprintf(fd, "\n");
 
@@ -646,7 +669,6 @@ libwacom_print_device_description(int fd, WacomDevice *device)
 	dprintf(fd, "Stylus=%s\n",	 libwacom_has_stylus(device)	? "true" : "false");
 	dprintf(fd, "Ring=%s\n",	 libwacom_has_ring(device)	? "true" : "false");
 	dprintf(fd, "Ring2=%s\n",	 libwacom_has_ring2(device)	? "true" : "false");
-	dprintf(fd, "BuiltIn=%s\n",	 libwacom_is_builtin(device)	? "true" : "false");
 	dprintf(fd, "Touch=%s\n",	 libwacom_has_touch(device)	? "true" : "false");
 	print_supported_leds(fd, device);
 
@@ -809,7 +831,6 @@ int libwacom_get_strips_num_modes(WacomDevice *device)
 	return device->strips_num_modes;
 }
 
-
 const WacomStatusLEDs *libwacom_get_status_leds(WacomDevice *device, int *num_leds)
 {
 	*num_leds = device->num_leds;
@@ -858,7 +879,7 @@ int libwacom_get_button_led_group (WacomDevice *device,
 
 int libwacom_is_builtin(WacomDevice *device)
 {
-	return !!(device->features & FEATURE_BUILTIN);
+	return !!(device->integration_flags & WACOM_DEVICE_INTEGRATED_DISPLAY);
 }
 
 int libwacom_is_reversible(WacomDevice *device)
@@ -866,6 +887,11 @@ int libwacom_is_reversible(WacomDevice *device)
 	return !!(device->features & FEATURE_REVERSIBLE);
 }
 
+WacomIntegrationFlags libwacom_get_integration_flags (WacomDevice *device)
+{
+	return device->integration_flags;
+}
+
 WacomBusType libwacom_get_bustype(WacomDevice *device)
 {
 	g_return_val_if_fail(device->match >= 0, -1);
diff --git a/libwacom/libwacom.h b/libwacom/libwacom.h
index 8830db8..cc21072 100644
--- a/libwacom/libwacom.h
+++ b/libwacom/libwacom.h
@@ -115,6 +115,16 @@ typedef enum {
 } WacomBusType;
 
 /**
+ * Tablet integration.
+ */
+typedef enum {
+	WACOM_DEVICE_INTEGRATED_NONE    = 0,
+	WACOM_DEVICE_INTEGRATED_DISPLAY = (1 << 0),
+	WACOM_DEVICE_INTEGRATED_SYSTEM  = (1 << 1),
+	WACOM_DEVICE_INTEGRATED_UNSET   = (1 << 31) /* Should be last */
+} WacomIntegrationFlags;
+
+/**
  * Classes of devices.
  */
 typedef enum {
@@ -454,12 +464,15 @@ const WacomStatusLEDs *libwacom_get_status_leds(WacomDevice *device, int *num_le
 int libwacom_get_button_led_group (WacomDevice *device,
 				   char         button);
 
+#ifndef LIBWACOM_DISABLE_DEPRECATED
 /**
  * @param device The tablet to query
- * @return non-zero if the device is built-in or zero if the device is an
- * external tablet
+ * @return non-zero if the device is built into the screen (ie a screen tablet)
+ * or zero if the device is an external tablet
+ * Deprecated: 0.7: Use libwacom_get_integration_flags() instead.
  */
 int libwacom_is_builtin(WacomDevice *device);
+#endif
 
 /**
  * @param device The tablet to query
@@ -470,6 +483,12 @@ int libwacom_is_reversible(WacomDevice *device);
 
 /**
  * @param device The tablet to query
+ * @return the integration flags for the device
+ */
+WacomIntegrationFlags libwacom_get_integration_flags (WacomDevice *device);
+
+/**
+ * @param device The tablet to query
  * @return The bustype of this device.
  */
 WacomBusType libwacom_get_bustype(WacomDevice *device);
diff --git a/libwacom/libwacomint.h b/libwacom/libwacomint.h
index 55436e9..95812c2 100644
--- a/libwacom/libwacomint.h
+++ b/libwacom/libwacomint.h
@@ -40,19 +40,12 @@
 
 #define GENERIC_DEVICE_MATCH "generic"
 
-typedef enum {
-	IS_BUILTIN_UNSET	= -1,
-	IS_BUILTIN_FALSE	= 0,
-	IS_BUILTIN_TRUE		= 1
-} IsBuiltin;
-
 enum WacomFeature {
 	FEATURE_STYLUS		= (1 << 0),
 	FEATURE_TOUCH		= (1 << 1),
 	FEATURE_RING		= (1 << 2),
 	FEATURE_RING2		= (1 << 3),
-	FEATURE_BUILTIN		= (1 << 4),
-	FEATURE_REVERSIBLE	= (1 << 5)
+	FEATURE_REVERSIBLE	= (1 << 4)
 };
 
 /* WARNING: When adding new members to this struct
@@ -79,6 +72,7 @@ struct _WacomDevice {
 	WacomClass cls;
 	int num_strips;
 	uint32_t features;
+	uint32_t integration_flags;
 
 	int strips_num_modes;
 	int ring_num_modes;
-- 
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