[PATCH libinput 1/5] evdev: add a internal device notification mechanism

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


When a device is added or removed, notify all internal devices about the
device change. This allows all devices to configure themselves depending on
other devices in the system. Prime use-case here is an internal touchpad that
wants to know if an external mouse is connected.

On device added, notification goes both ways: existing devices are notified
about the new device, and the new device is notified about existing devices.
On device removed, notification only goes one way.

In both cases, the internal notification is complete before the event is sent
to the caller.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-mt-touchpad.c |  4 +++-
 src/evdev.c             | 37 +++++++++++++++++++++++++++++++++++--
 src/evdev.h             |  8 ++++++++
 3 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index 51eced6..118e1a8 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -678,7 +678,9 @@ tp_resume(struct tp_dispatch *tp, struct evdev_device *device)
 
 static struct evdev_dispatch_interface tp_interface = {
 	tp_process,
-	tp_destroy
+	tp_destroy,
+	NULL, /* device_added */
+	NULL, /* device_removed */
 };
 
 static void
diff --git a/src/evdev.c b/src/evdev.c
index 88b7c9e..df7548e 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -621,7 +621,9 @@ evdev_calibration_get_default_matrix(struct libinput_device *libinput_device,
 
 struct evdev_dispatch_interface fallback_interface = {
 	fallback_process,
-	fallback_destroy
+	fallback_destroy,
+	NULL, /* device_added */
+	NULL, /* device_removed */
 };
 
 static uint32_t
@@ -959,6 +961,26 @@ evdev_configure_device(struct evdev_device *device)
 	return 0;
 }
 
+static void
+evdev_notify_added_device(struct evdev_device *device)
+{
+	struct libinput_device *dev;
+
+	list_for_each(dev, &device->base.seat->devices_list, link) {
+		struct evdev_device *d = (struct evdev_device*)dev;
+		if (dev == &device->base)
+			continue;
+
+		if (d->dispatch->interface->device_added)
+			d->dispatch->interface->device_added(d, device);
+
+		if (device->dispatch->interface->device_added)
+			device->dispatch->interface->device_added(device, d);
+	}
+
+	notify_added_device(&device->base);
+}
+
 struct evdev_device *
 evdev_device_create(struct libinput_seat *seat,
 		    const char *devnode,
@@ -1033,7 +1055,7 @@ evdev_device_create(struct libinput_seat *seat,
 		goto err;
 
 	list_insert(seat->devices_list.prev, &device->base.link);
-	notify_added_device(&device->base);
+	evdev_notify_added_device(device);
 
 	return device;
 
@@ -1323,6 +1345,17 @@ evdev_device_resume(struct evdev_device *device)
 void
 evdev_device_remove(struct evdev_device *device)
 {
+	struct libinput_device *dev;
+
+	list_for_each(dev, &device->base.seat->devices_list, link) {
+		struct evdev_device *d = (struct evdev_device*)dev;;
+		if (dev == &device->base)
+			continue;
+
+		if (d->dispatch->interface->device_removed)
+			d->dispatch->interface->device_removed(d, device);
+	}
+
 	evdev_device_suspend(device);
 
 	/* A device may be removed while suspended. Free the syspath to
diff --git a/src/evdev.h b/src/evdev.h
index bdd4a4e..74053c5 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -120,6 +120,14 @@ struct evdev_dispatch_interface {
 
 	/* Destroy an event dispatch handler and free all its resources. */
 	void (*destroy)(struct evdev_dispatch *dispatch);
+
+	/* A new device was added */
+	void (*device_added)(struct evdev_device *device,
+			     struct evdev_device *added_device);
+
+	/* A device was removed */
+	void (*device_removed)(struct evdev_device *device,
+			       struct evdev_device *removed_device);
 };
 
 struct evdev_dispatch {
-- 
1.9.3



More information about the wayland-devel mailing list