evdev: add support for LIBINPUT_MODEL_* udev tags
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 20 Apr 2015 18:29:44 +0000 (14:29 -0400)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 23 Apr 2015 22:38:58 +0000 (08:38 +1000)
Some devices need specific configuration or different defaults.
Push that into udev rules and a hwdb file, that's where detection is the
easiest. The LIBINPUT_MODEL_ prefix is used to determine some type of device
model. Note that this property is a private API and subject to change at
any time without notice.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Tested-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
doc/device-configuration-via-udev.dox
src/evdev.c
src/evdev.h
udev/90-libinput-model-quirks.hwdb [new file with mode: 0644]
udev/90-libinput-model-quirks.rules [new file with mode: 0644]
udev/Makefile.am

index c22aafab9aea8aee30eea85b0479bbd310ea48dd..e38b93f6e7ba292807444f1cbb8c6cab721063d5 100644 (file)
@@ -63,6 +63,9 @@ libinput_pointer_get_axis_source() for details.
 <dt>POINTINGSTICK_CONST_ACCEL</dt>
 <dd>A constant (linear) acceleration factor to apply to pointingstick deltas
 to normalize them.
+<dt>LIBINPUT_MODEL_*</dt>
+<dd><b>This prefix is reserved as private API, do not use.</b>. See @ref
+model_specific_configuration for details.
 </dd>
 </dl>
 
@@ -98,4 +101,16 @@ ACTION=="add|change", KERNEL=="event[0-9]*", ENV{ID_VENDOR_ID}=="012a", \
 ENV{ID_MODEL_ID}=="034b", ENV{ID_INPUT_TOUCHPAD}="", ENV{ID_INPUT_TABLET}="1"
 @endcode
 
+@section model_specific_configuration Model-specific configuration
+
+libinput reserves the property prefix <b>LIBINPUT_MODEL_</b> for
+model-specific configuration. <b>This prefix is reserved as private API, do
+not use.</b>
+
+The effect of this property may be to enable or disable certain
+features on a specific device or set of devices, to change configuration
+defaults or any other reason. The effects of setting this property, the
+format of the property and the value of the property are subject to change
+at any time.
+
 */
index 964b3ba1647995866aaefbc685ca07df761252bd..e3bba93e7ea105a247451bc3c1baf8ea9476ed0a 100644 (file)
@@ -1422,6 +1422,27 @@ evdev_read_dpi_prop(struct evdev_device *device)
        return dpi;
 }
 
+static inline enum evdev_device_model
+evdev_read_model(struct evdev_device *device)
+{
+       const struct model_map {
+               const char *property;
+               enum evdev_device_model model;
+       } model_map[] = {
+               { NULL, EVDEV_MODEL_DEFAULT },
+       };
+       const struct model_map *m = model_map;
+
+       while (m->property) {
+               if (!!udev_device_get_property_value(device->udev_device,
+                                                    m->property))
+                       break;
+               m++;
+       }
+
+       return m->model;
+}
+
 /* Return 1 if the given resolutions have been set, or 0 otherwise */
 inline int
 evdev_fix_abs_resolution(struct evdev_device *device,
@@ -1950,6 +1971,7 @@ evdev_device_create(struct libinput_seat *seat,
        device->scroll.wheel_click_angle =
                evdev_read_wheel_click_prop(device);
        device->dpi = evdev_read_dpi_prop(device);
+       device->model = evdev_read_model(device);
        /* at most 5 SYN_DROPPED log-messages per 30s */
        ratelimit_init(&device->syn_drop_limit, 30ULL * 1000, 5);
 
index 9f2445348678a6d755fc0e591a4d6d7130edd3e1..edd40119d52c8ce4ab0b185f023ccba68f0bab87 100644 (file)
@@ -93,6 +93,10 @@ enum evdev_middlebutton_event {
        MIDDLEBUTTON_EVENT_ALL_UP,
 };
 
+enum evdev_device_model {
+       EVDEV_MODEL_DEFAULT,
+};
+
 struct mt_slot {
        int32_t seat_slot;
        struct device_coords point;
@@ -202,6 +206,8 @@ struct evdev_device {
 
        int dpi; /* HW resolution */
        struct ratelimit syn_drop_limit; /* ratelimit for SYN_DROPPED logging */
+
+       enum evdev_device_model model;
 };
 
 #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
diff --git a/udev/90-libinput-model-quirks.hwdb b/udev/90-libinput-model-quirks.hwdb
new file mode 100644 (file)
index 0000000..02bb8f9
--- /dev/null
@@ -0,0 +1,16 @@
+# Do not edit this file, it will be overwritten on update
+#
+# This file contains hwdb matches for libinput model-specific quirks.
+# The contents of this file are a contract between libinput, udev rules and
+# the hwdb.
+# IT IS NOT A STABLE API AND SUBJECT TO CHANGE AT ANY TIME
+
+# The lookup keys are composed in:
+#      90-libinput-model-quirks.rules
+#
+# Match string formats:
+#      libinput:<modalias>
+#      libinput:name:<name>:dmi:<dmi string>
+
+#
+# Sort by brand, model
diff --git a/udev/90-libinput-model-quirks.rules b/udev/90-libinput-model-quirks.rules
new file mode 100644 (file)
index 0000000..4b98874
--- /dev/null
@@ -0,0 +1,25 @@
+# Do not edit this file, it will be overwritten on update
+#
+# This file contains lookup rules for libinput model-specific quirks.
+# The contents of this file are a contract between libinput, udev rules and
+# the hwdb.
+# IT IS NOT A STABLE API AND SUBJECT TO CHANGE AT ANY TIME
+#
+# The hwdb database is in:
+#      90-libinput-model-quirks.hwdb
+
+ACTION!="add|change", GOTO="libinput_model_quirks_end"
+KERNEL!="event*", GOTO="libinput_model_quirks_end"
+
+# hwdb matches:
+# 
+# libinput:<modalias>
+IMPORT{builtin}="hwdb --subsystem=input --lookup-prefix=libinput:", \
+  GOTO="libinput_model_quirks_end"
+
+# libinput:name:<name>:dmi:<dmi string>
+KERNELS=="input*", \
+  IMPORT{builtin}="hwdb 'libinput:name:$attr{name}:$attr{[dmi/id]modalias}'", \
+  GOTO="libinput_model_quirks_end"
+
+LABEL="libinput_model_quirks_end"
index 3691172c30c6c1d3903705b99db76b458058f531..7d19809db68cd5cd8b9e906165137297291f2146 100644 (file)
@@ -6,4 +6,10 @@ libinput_device_group_CFLAGS = $(LIBUDEV_CFLAGS) $(GCC_CFLAGS)
 libinput_device_group_LDADD = $(LIBUDEV_LIBS)
 
 udev_rulesdir=$(UDEV_DIR)/rules.d
-dist_udev_rules_DATA = 80-libinput-device-groups.rules
+dist_udev_rules_DATA = \
+       80-libinput-device-groups.rules \
+       90-libinput-model-quirks.rules
+
+udev_hwdbdir=$(UDEV_DIR)/hwdb.d
+dist_udev_hwdb_DATA = \
+       90-libinput-model-quirks.hwdb