diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2021-03-29 13:16:13 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2021-04-23 10:22:39 +1000 |
commit | 412a2af64a8ace1332b3e54984a1756c8fdc8dce (patch) | |
tree | 3402704e83414eb62d4ffea5549219709f2c9f3e /libwacom | |
parent | eed08c0c0d344749f8cae2b1d0a6bc66dbcd5e64 (diff) | |
download | libwacom-412a2af64a8ace1332b3e54984a1756c8fdc8dce.tar.gz |
Overhaul match generation logic
Make this less nested and easier to understand. For each match string:
- create a new match object
- add that match object to the device
- first time only: set the match to be the default match
libwacom_add_match() is a bit peculiar at the moment: if called with a new
match it merely appends to the list but leaves device->match unmodified (at
zero by default). If called with an existing match string, it'll point
device->match to the match in the list.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'libwacom')
-rw-r--r-- | libwacom/libwacom-database.c | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c index b48c4e9..d783088 100644 --- a/libwacom/libwacom-database.c +++ b/libwacom/libwacom-database.c @@ -180,8 +180,8 @@ match_from_string(const char *str, WacomBusType *bus, int *vendor_id, int *produ return TRUE; } -static gboolean -libwacom_add_match_from_string(WacomDevice *device, const char *matchstr) +static WacomMatch * +libwacom_match_from_string(WacomDevice *device, const char *matchstr) { char *name = NULL; int vendor_id, product_id; @@ -189,7 +189,7 @@ libwacom_add_match_from_string(WacomDevice *device, const char *matchstr) WacomMatch *match; if (matchstr == NULL) - return FALSE; + return NULL; if (g_str_equal(matchstr, GENERIC_DEVICE_MATCH)) { name = NULL; @@ -198,15 +198,13 @@ libwacom_add_match_from_string(WacomDevice *device, const char *matchstr) product_id = 0; } else if (!match_from_string(matchstr, &bus, &vendor_id, &product_id, &name)) { DBG("failed to match '%s' for product/vendor IDs. Skipping.\n", matchstr); - return FALSE; + return NULL; } match = libwacom_match_new(name, bus, vendor_id, product_id); - libwacom_add_match(device, match); - libwacom_match_unref(match); - free(name); - return TRUE; + + return match; } static gboolean @@ -679,26 +677,24 @@ libwacom_parse_tablet_keyfile(WacomDeviceDatabase *db, } else { guint i; guint nmatches = 0; - guint first_valid_match = 0; for (i = 0; string_list[i]; i++) { - if (libwacom_add_match_from_string(device, string_list[i])) { - nmatches++; - if (nmatches == 1) - first_valid_match = i; - } else { + WacomMatch *m = libwacom_match_from_string(device, + string_list[i]); + if (!m) { DBG("'%s' is an invalid DeviceMatch in '%s'\n", string_list[i], path); + continue; } - } - if (nmatches == 0) { - g_strfreev (string_list); - goto out; - } - if (nmatches > 1) { + libwacom_add_match(device, m); + nmatches++; /* set default to first entry */ - libwacom_add_match_from_string(device, string_list[first_valid_match]); + if (nmatches == 1) + libwacom_add_match(device, m); + libwacom_match_unref(m); } g_strfreev (string_list); + if (nmatches == 0) + goto out; } paired = g_key_file_get_string(keyfile, DEVICE_GROUP, "PairedID", NULL); |