>From da71825141c1a516f9f8b3253c57f4805afddbe8 Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <ofour...@redhat.com>
Date: Thu, 25 Oct 2012 14:43:28 +0200
Subject: [PATCH 2/4] lib: add SVG layouts to device properties

Signed-off-by: Olivier Fourdan <ofour...@redhat.com>
---
 libwacom/libwacom-database.c |   18 ++++++++++++----
 libwacom/libwacom.c          |   44 ++++++++++++++++++++++++++++++++++++++++++
 libwacom/libwacom.h          |    7 ++++++
 libwacom/libwacomint.h       |    2 +
 4 files changed, 66 insertions(+), 5 deletions(-)

diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c
index d39305d..bbea114 100644
--- a/libwacom/libwacom-database.c
+++ b/libwacom/libwacom-database.c
@@ -319,12 +319,14 @@ libwacom_parse_buttons(WacomDevice *device,
 }
 
 static WacomDevice*
-libwacom_parse_tablet_keyfile(const char *path)
+libwacom_parse_tablet_keyfile(const char *datadir, const char *filename)
 {
 	WacomDevice *device = NULL;
 	GKeyFile *keyfile;
 	GError *error = NULL;
 	gboolean rc;
+	char *path;
+	char *layout;
 	char *class;
 	char *match;
 	char **styli_list;
@@ -332,6 +334,7 @@ libwacom_parse_tablet_keyfile(const char *path)
 
 	keyfile = g_key_file_new();
 
+	path = g_build_filename (datadir, filename, NULL);
 	rc = g_key_file_load_from_file(keyfile, path, G_KEY_FILE_NONE, &error);
 
 	if (!rc) {
@@ -358,7 +361,12 @@ libwacom_parse_tablet_keyfile(const char *path)
 	device->name = g_key_file_get_string(keyfile, DEVICE_GROUP, "Name", NULL);
 	device->width = g_key_file_get_integer(keyfile, DEVICE_GROUP, "Width", NULL);
 	device->height = g_key_file_get_integer(keyfile, DEVICE_GROUP, "Height", NULL);
-
+	layout = g_key_file_get_string(keyfile, DEVICE_GROUP, "Layout", NULL);
+	if (layout) {
+		/* For the layout, we store the full path to the SVG layout */
+		device->layout = g_build_filename (datadir, "layouts", layout, NULL);
+		g_free (layout);
+	}
 	class = g_key_file_get_string(keyfile, DEVICE_GROUP, "Class", NULL);
 	device->cls = libwacom_class_string_to_enum(class);
 	g_free(class);
@@ -445,6 +453,8 @@ libwacom_parse_tablet_keyfile(const char *path)
 	}
 
 out:
+	if (path)
+		g_free(path);
 	if (keyfile)
 		g_key_file_free(keyfile);
 	if (error)
@@ -515,9 +525,7 @@ libwacom_database_new_for_path (const char *datadir)
 	    WacomDevice *d;
 	    const WacomMatch **matches, **match;
 
-	    path = g_build_filename (datadir, files[n]->d_name, NULL);
-	    d = libwacom_parse_tablet_keyfile(path);
-	    g_free(path);
+	    d = libwacom_parse_tablet_keyfile(datadir, files[n]->d_name);
 
 	    if (!d)
 		    continue;
diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c
index 4f8c5f9..25efa1b 100644
--- a/libwacom/libwacom.c
+++ b/libwacom/libwacom.c
@@ -290,6 +290,7 @@ libwacom_copy(const WacomDevice *device)
 	d->name = g_strdup (device->name);
 	d->width = device->width;
 	d->height = device->height;
+	d->layout = g_strdup(device->layout);
 	d->nmatches = device->nmatches;
 	d->matches = g_malloc((d->nmatches + 1) * sizeof(WacomMatch*));
 	for (i = 0; i < d->nmatches; i++)
@@ -333,6 +334,26 @@ compare_matches(WacomDevice *a, WacomDevice *b)
 	return 0;
 }
 
+/* Compare layouts based on file name, stripping the full path */
+static gboolean
+libwacom_same_layouts (WacomDevice *a, WacomDevice *b)
+{
+	gchar *file1, *file2;
+
+	/* Conveniently handle the null case */
+	if (a->layout == b->layout)
+		return TRUE;
+
+	file1 = NULL;
+	file2 = NULL;
+	if (a->layout != NULL)
+		file1 = g_path_get_basename (a->layout);
+	if (b->layout != NULL)
+		file2 = g_path_get_basename (b->layout);
+
+	return (g_strcmp0 (file1, file2) == 0);
+}
+
 int
 libwacom_compare(WacomDevice *a, WacomDevice *b, WacomCompareFlags flags)
 {
@@ -347,6 +368,9 @@ libwacom_compare(WacomDevice *a, WacomDevice *b, WacomCompareFlags flags)
 	if (a->width != b->width || a->height != b->height)
 		return 1;
 
+	if (!libwacom_same_layouts (a, b))
+		return 1;
+
 	if (a->cls != b->cls)
 		return 1;
 
@@ -537,6 +561,19 @@ static void print_styli_for_device (int fd, WacomDevice *device)
 	dprintf(fd, "\n");
 }
 
+static void print_layout_for_device (int fd, WacomDevice *device)
+{
+	const char *layout_filename;
+	gchar      *base_name;
+
+	layout_filename = libwacom_get_layout_filename(device);
+	if (layout_filename) {
+		base_name = g_path_get_basename (layout_filename);
+		dprintf(fd, "Layout=%s\n", base_name);
+		g_free (base_name);
+	}
+}
+
 static void print_supported_leds (int fd, WacomDevice *device)
 {
 	char *leds_name[] = {
@@ -638,6 +675,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_layout_for_device(fd, device);
 	print_styli_for_device(fd, device);
 	dprintf(fd, "\n");
 
@@ -666,6 +704,7 @@ libwacom_destroy(WacomDevice *device)
 		return;
 
 	g_free (device->name);
+	g_free (device->layout);
 
 	for (i = 0; i < device->nmatches; i++) {
 		g_free (device->matches[i]->match);
@@ -724,6 +763,11 @@ const char* libwacom_get_name(WacomDevice *device)
 	return device->name;
 }
 
+const char* libwacom_get_layout_filename(WacomDevice *device)
+{
+	return device->layout;
+}
+
 int libwacom_get_product_id(WacomDevice *device)
 {
 	g_return_val_if_fail(device->match >= 0, -1);
diff --git a/libwacom/libwacom.h b/libwacom/libwacom.h
index 8830db8..30968f2 100644
--- a/libwacom/libwacom.h
+++ b/libwacom/libwacom.h
@@ -330,6 +330,13 @@ const char* libwacom_get_name(WacomDevice *device);
 
 /**
  * @param device The tablet to query
+ * @return The full filename including path to the SVG layout of the device
+ * if available, or NULL otherwise
+ */
+const char* libwacom_get_layout_filename(WacomDevice *device);
+
+/**
+ * @param device The tablet to query
  * @return The numeric vendor ID for this device
  */
 int libwacom_get_vendor_id(WacomDevice *device);
diff --git a/libwacom/libwacomint.h b/libwacom/libwacomint.h
index 55436e9..20c40f8 100644
--- a/libwacom/libwacomint.h
+++ b/libwacom/libwacomint.h
@@ -93,6 +93,8 @@ struct _WacomDevice {
 	int num_leds;
 	WacomStatusLEDs *status_leds;
 
+	char *layout;
+
 	gint refcnt; /* for the db hashtable */
 };
 
-- 
1.7.1

------------------------------------------------------------------------------
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to