summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2022-11-15 13:53:43 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2022-11-28 08:25:41 +1000
commita7e4cbc212be85950f942830aebfb017f43b2504 (patch)
tree2066b01b338d97c8fe9a0b00c19852e3856309f5 /tools
parentbb6ff0ec002c10111eaffa70beb5d029bb503e77 (diff)
quirks: allow overriding of AttrEventCode and AttrInputProp
This switches the quirk from AttrEventCodeEnable/Disable to just AttrEventCode with a +/- prefix for each entry. This switches the quirk from AttrInputPropEnable/Disable to just AttrInputProp with a +/- prefix for each entry. Previously, both event codes and input props would only apply the last-matching section entry for a device. Furthermore, an earlier Disable entry would take precedence over a later Enable entry. For example, a set of sections with these lines *should* enable left, right and middle: [first] AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;BTN_MIDDLE [second] AttrEventCodeDisable=BTN_RIGHT [third] AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT; Alas: the first line was effectively ignored (quirks only returned the last-matching one, i.e. the one from "third"). And due to implementation details in evdev.c, the Disable attribute was processed after Enable, i.e. the device was enabled for left + right and then disabled for right. As a result, the device only had BTN_LEFT enabled. Fix this by changing the attribute to carry both enable/disable information and merging the commands together. Internally, all quirks matching a device are simply ref'd into an array in the struct quirks. The applied value is simply the last entry in the array corresponding to our quirk. For AttrEventCode and AttrInputProp instead do this: - switch them to a tuple with the code as first entry and a boolean enable/disable as second entry - if the struct quirk already has an entry for either, append the more recent one to the existing entry (instead of creating a new entry in the array). This way we have all entries that match and in-order of precedence - i.e. we can process them left-to-right to end up with the right state. Fixes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/821 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'tools')
-rw-r--r--tools/shared.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/tools/shared.c b/tools/shared.c
index 8dc3b607..d7791838 100644
--- a/tools/shared.c
+++ b/tools/shared.c
@@ -632,11 +632,13 @@ sprintf_event_codes(char *buf, size_t sz, struct quirks *quirks, enum quirk q)
off += printed;
for (size_t i = 0; off < sz && i < t->ntuples; i++) {
- const char *name = libevdev_event_code_get_name(
- t->tuples[i].first,
- t->tuples[i].second);
+ unsigned int type = t->tuples[i].first;
+ unsigned int code = t->tuples[i].second;
+ bool enable = t->tuples[i].third;
- printed = snprintf(buf + off, sz - off, "%s;", name);
+ const char *name = libevdev_event_code_get_name(type, code);
+
+ printed = snprintf(buf + off, sz - off, "%c%s;", enable ? '+' : '-', name);
assert(printed != -1);
off += printed;
}
@@ -645,21 +647,24 @@ sprintf_event_codes(char *buf, size_t sz, struct quirks *quirks, enum quirk q)
static void
sprintf_input_props(char *buf, size_t sz, struct quirks *quirks, enum quirk q)
{
- const uint32_t *properties;
- size_t nprops = 0;
+ const struct quirk_tuples *t;
size_t off = 0;
int printed;
const char *name;
- quirks_get_uint32_array(quirks, q, &properties, &nprops);
+ quirks_get_tuples(quirks, q, &t);
name = quirk_get_name(q);
printed = snprintf(buf, sz, "%s=", name);
assert(printed != -1);
off += printed;
- for (size_t i = 0; off < sz && i < nprops; i++) {
- const char *name = libevdev_property_get_name(properties[i]);
- printed = snprintf(buf + off, sz - off, "%s;", name);
+ for (size_t i = 0; off < sz && i < t->ntuples; i++) {
+ unsigned int prop = t->tuples[i].first;
+ bool enable = t->tuples[i].second;
+
+ const char *name = libevdev_property_get_name(prop);
+
+ printed = snprintf(buf + off, sz - off, "%c%s;", enable ? '+' : '-', name);
assert(printed != -1);
off += printed;
}
@@ -747,13 +752,11 @@ tools_list_device_quirks(struct quirks_context *ctx,
snprintf(buf, sizeof(buf), "%s=%d", name, b);
callback(userdata, buf);
break;
- case QUIRK_ATTR_EVENT_CODE_DISABLE:
- case QUIRK_ATTR_EVENT_CODE_ENABLE:
+ case QUIRK_ATTR_EVENT_CODE:
sprintf_event_codes(buf, sizeof(buf), quirks, q);
callback(userdata, buf);
break;
- case QUIRK_ATTR_INPUT_PROP_DISABLE:
- case QUIRK_ATTR_INPUT_PROP_ENABLE:
+ case QUIRK_ATTR_INPUT_PROP:
sprintf_input_props(buf, sizeof(buf), quirks, q);
callback(userdata, buf);
break;