[PATCH libinput] evdev: add support for LIBINPUT_MODEL_* udev tags

Peter Hutterer peter.hutterer at who-t.net
Wed Apr 22 19:07:37 PDT 2015


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 at who-t.net>
---
A few more changes than expected, so sending this out again for another
set of eyes on it. This is the infrastructure to tag things with
LIBINPUT_MODEL_* udev properties, it's not in use by anything just yet.

 doc/device-configuration-via-udev.dox | 15 +++++++++++++++
 src/evdev.c                           | 22 ++++++++++++++++++++++
 src/evdev.h                           |  6 ++++++
 udev/90-libinput-model-quirks.hwdb    | 16 ++++++++++++++++
 udev/90-libinput-model-quirks.rules   | 25 +++++++++++++++++++++++++
 udev/Makefile.am                      |  8 +++++++-
 6 files changed, 91 insertions(+), 1 deletion(-)
 create mode 100644 udev/90-libinput-model-quirks.hwdb
 create mode 100644 udev/90-libinput-model-quirks.rules

diff --git a/doc/device-configuration-via-udev.dox b/doc/device-configuration-via-udev.dox
index c22aafa..e38b93f 100644
--- a/doc/device-configuration-via-udev.dox
+++ b/doc/device-configuration-via-udev.dox
@@ -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
 
+ at 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.
+
 */
diff --git a/src/evdev.c b/src/evdev.c
index 964b3ba..e3bba93 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -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);
 
diff --git a/src/evdev.h b/src/evdev.h
index 9f24453..edd4011 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -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
index 0000000..02bb8f9
--- /dev/null
+++ b/udev/90-libinput-model-quirks.hwdb
@@ -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
index 0000000..4b98874
--- /dev/null
+++ b/udev/90-libinput-model-quirks.rules
@@ -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"
diff --git a/udev/Makefile.am b/udev/Makefile.am
index 3691172..7d19809 100644
--- a/udev/Makefile.am
+++ b/udev/Makefile.am
@@ -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
-- 
2.3.5



More information about the wayland-devel mailing list