Discussion:
[Linuxwacom-devel] [PATCH libwacom] Return the device database sorted by vendor/product ID
Peter Hutterer
2016-04-22 04:12:42 UTC
Permalink
Little effect for most users of the database, but the generated udev rules
become more predictable and a lot easier to patch this way.

Signed-off-by: Peter Hutterer <***@who-t.net>
---
I admit, it's a bit heavy-handed to sort the database even though we need it
mainly for the rules file. But it's less lines of code doing it this way :)

libwacom/libwacom-database.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c
index 997b53f..ccdf5a5 100644
--- a/libwacom/libwacom-database.c
+++ b/libwacom/libwacom-database.c
@@ -696,6 +696,19 @@ libwacom_database_destroy(WacomDeviceDatabase *db)
g_free (db);
}

+static gint
+device_compare(gconstpointer pa, gconstpointer pb)
+{
+ const WacomDevice *a = pa,
+ *b = pb;
+ int cmp;
+
+ cmp = libwacom_get_vendor_id(a) - libwacom_get_vendor_id(b);
+ if (cmp == 0)
+ cmp = libwacom_get_product_id(a) - libwacom_get_product_id(b);
+ return cmp;
+}
+
WacomDevice**
libwacom_list_devices_from_database(const WacomDeviceDatabase *db, WacomError *error)
{
@@ -714,6 +727,8 @@ libwacom_list_devices_from_database(const WacomDeviceDatabase *db, WacomError *e
return NULL;
}

+ devices = g_list_sort (devices, device_compare);
+
for (p = list, cur = devices; cur; cur = g_list_next (cur))
*p++ = (WacomDevice *) cur->data;
g_list_free (devices);
--
2.7.3
Loading...