[PATCH libinput 2/5] evdev: add internal tagging system

Peter Hutterer peter.hutterer at who-t.net
Wed Sep 3 23:31:56 PDT 2014


For conditional touchpad disabling we need two pieces of knowledge: is the
device an internal touchpad and is another device an external mouse-like
device. For that use-case it's enough to tag any device that's on USB and
Bluetooth with pointer capabilities as external mouse. A more complex can be
done when needed.

The tag function is part of the dispatch interface (to save on udev code) and
called before the caller is notified about the new device, i.e. the device is
fully configured by the time it needs to be tagged, and other devices can rely
on the tags being assigned by the time they get notified about the new device.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-mt-touchpad.c |  1 +
 src/evdev.c             | 43 +++++++++++++++++++++++++++++++++++++++++++
 src/evdev.h             | 10 ++++++++++
 3 files changed, 54 insertions(+)

diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index 118e1a8..076b32a 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -681,6 +681,7 @@ static struct evdev_dispatch_interface tp_interface = {
 	tp_destroy,
 	NULL, /* device_added */
 	NULL, /* device_removed */
+	NULL, /* tag_device */
 };
 
 static void
diff --git a/src/evdev.c b/src/evdev.c
index df7548e..0a8f2ba 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -24,6 +24,7 @@
 #include "config.h"
 
 #include <errno.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 #include "linux/input.h"
@@ -546,6 +547,19 @@ evdev_need_touch_frame(struct evdev_device *device)
 }
 
 static void
+evdev_tag_external_mouse(struct evdev_device *device,
+			 struct udev_device *udev_device)
+{
+	int bustype;
+
+	bustype = libevdev_get_id_bustype(device->evdev);
+	if (bustype == BUS_USB || bustype == BUS_BLUETOOTH) {
+		if (device->seat_caps & EVDEV_DEVICE_POINTER)
+			device->tags |= EVDEV_TAG_EXTERNAL_MOUSE;
+	}
+}
+
+static void
 fallback_process(struct evdev_dispatch *dispatch,
 		 struct evdev_device *device,
 		 struct input_event *event,
@@ -578,6 +592,13 @@ fallback_destroy(struct evdev_dispatch *dispatch)
 	free(dispatch);
 }
 
+static void
+fallback_tag_device(struct evdev_device *device,
+		    struct udev_device *udev_device)
+{
+	evdev_tag_external_mouse(device, udev_device);
+}
+
 static int
 evdev_calibration_has_matrix(struct libinput_device *libinput_device)
 {
@@ -624,6 +645,7 @@ struct evdev_dispatch_interface fallback_interface = {
 	fallback_destroy,
 	NULL, /* device_added */
 	NULL, /* device_removed */
+	fallback_tag_device,
 };
 
 static uint32_t
@@ -792,6 +814,25 @@ configure_pointer_acceleration(struct evdev_device *device)
 	return 0;
 }
 
+static void
+evdev_tag_device(struct evdev_device *device)
+{
+	struct udev *udev;
+	struct udev_device *udev_device = NULL;
+
+	udev = udev_new();
+	if (!udev)
+		return;
+
+	udev_device = udev_device_new_from_syspath(udev, device->syspath);
+	if (udev_device) {
+		if (device->dispatch->interface->tag_device)
+			device->dispatch->interface->tag_device(device, udev_device);
+		udev_device_unref(udev_device);
+	}
+	udev_unref(udev);
+}
+
 static int
 evdev_configure_device(struct evdev_device *device)
 {
@@ -1055,6 +1096,8 @@ evdev_device_create(struct libinput_seat *seat,
 		goto err;
 
 	list_insert(seat->devices_list.prev, &device->base.link);
+
+	evdev_tag_device(device);
 	evdev_notify_added_device(device);
 
 	return device;
diff --git a/src/evdev.h b/src/evdev.h
index 74053c5..f5345fa 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -48,6 +48,11 @@ enum evdev_device_seat_capability {
 	EVDEV_DEVICE_TOUCH = (1 << 2)
 };
 
+enum evdev_device_tags {
+	EVDEV_TAG_EXTERNAL_MOUSE = (1 << 0),
+	EVDEV_TAG_INTERNAL_TOUCHPAD = (1 << 1),
+};
+
 struct mt_slot {
 	int32_t seat_slot;
 	int32_t x, y;
@@ -92,6 +97,7 @@ struct evdev_device {
 
 	enum evdev_event_type pending_event;
 	enum evdev_device_seat_capability seat_caps;
+	enum evdev_device_tags tags;
 
 	int is_mt;
 
@@ -128,6 +134,10 @@ struct evdev_dispatch_interface {
 	/* A device was removed */
 	void (*device_removed)(struct evdev_device *device,
 			       struct evdev_device *removed_device);
+
+	/* Tag device with one of EVDEV_TAG */
+	void (*tag_device)(struct evdev_device *device,
+			   struct udev_device *udev_device);
 };
 
 struct evdev_dispatch {
-- 
1.9.3



More information about the wayland-devel mailing list