[PATCH libinput 3/8] evdev: Add an internal device suspend / resume notification system

Hans de Goede hdegoede at redhat.com
Tue Sep 16 07:22:37 PDT 2014


We have the ability for a device to form a link to another device through the
device_added / device_removed callbacks. A device having such a link to
another device may also want to know when that other device is disabled /
enabled (suspended / resumed). So add a notification mechanism for this too.

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 src/evdev-mt-touchpad.c |  2 ++
 src/evdev.c             | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/evdev.h             | 15 ++++++++++++++
 3 files changed, 69 insertions(+)

diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index b0318da..72e1c23 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -696,6 +696,8 @@ static struct evdev_dispatch_interface tp_interface = {
 	tp_destroy,
 	tp_device_added,
 	tp_device_removed,
+	NULL, /* device_suspended */
+	NULL, /* device_resumed */
 	tp_tag_device,
 };
 
diff --git a/src/evdev.c b/src/evdev.c
index 85e4d71..cb43c27 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -692,6 +692,8 @@ struct evdev_dispatch_interface fallback_interface = {
 	fallback_destroy,
 	NULL, /* device_added */
 	NULL, /* device_removed */
+	NULL, /* device_suspended */
+	NULL, /* device_resumed */
 	fallback_tag_device,
 };
 
@@ -1078,11 +1080,17 @@ evdev_notify_added_device(struct evdev_device *device)
 		if (dev == &device->base)
 			continue;
 
+		/* Notify existing device d about addition of device device */
 		if (d->dispatch->interface->device_added)
 			d->dispatch->interface->device_added(d, device);
 
+		/* Notify new device device about existing device d */
 		if (device->dispatch->interface->device_added)
 			device->dispatch->interface->device_added(device, d);
+
+		/* Notify new device device if existing device d is suspended */
+		if (d->suspended && device->dispatch->interface->device_suspended)
+			device->dispatch->interface->device_suspended(device, d);
 	}
 
 	notify_added_device(&device->base);
@@ -1413,9 +1421,51 @@ release_pressed_keys(struct evdev_device *device)
 	}
 }
 
+void
+evdev_notify_suspended_device(struct evdev_device *device)
+{
+	struct libinput_device *it;
+
+	if (device->suspended)
+		return;
+
+	list_for_each(it, &device->base.seat->devices_list, link) {
+		struct evdev_device *d = (struct evdev_device*)it;
+		if (it == &device->base)
+			continue;
+
+		if (d->dispatch->interface->device_suspended)
+			d->dispatch->interface->device_suspended(d, device);
+	}
+
+	device->suspended = 1;
+}
+
+void
+evdev_notify_resumed_device(struct evdev_device *device)
+{
+	struct libinput_device *it;
+
+	if (!device->suspended)
+		return;
+
+	list_for_each(it, &device->base.seat->devices_list, link) {
+		struct evdev_device *d = (struct evdev_device*)it;
+		if (it == &device->base)
+			continue;
+
+		if (d->dispatch->interface->device_resumed)
+			d->dispatch->interface->device_resumed(d, device);
+	}
+
+	device->suspended = 0;
+}
+
 int
 evdev_device_suspend(struct evdev_device *device)
 {
+	evdev_notify_suspended_device(device);
+
 	if (device->source) {
 		libinput_remove_source(device->base.seat->libinput,
 				       device->source);
@@ -1506,6 +1556,8 @@ evdev_device_resume(struct evdev_device *device)
 
 	memset(device->hw_key_mask, 0, sizeof(device->hw_key_mask));
 
+	evdev_notify_resumed_device(device);
+
 	return 0;
 }
 
diff --git a/src/evdev.h b/src/evdev.h
index e1506d2..4047a6d 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -110,6 +110,7 @@ struct evdev_device {
 	enum evdev_device_tags tags;
 
 	int is_mt;
+	int suspended;
 
 	struct {
 		struct motion_filter *filter;
@@ -145,6 +146,14 @@ struct evdev_dispatch_interface {
 	void (*device_removed)(struct evdev_device *device,
 			       struct evdev_device *removed_device);
 
+	/* A device was suspended */
+	void (*device_suspended)(struct evdev_device *device,
+				 struct evdev_device *suspended_device);
+
+	/* A device was resumed */
+	void (*device_resumed)(struct evdev_device *device,
+			       struct evdev_device *resumed_device);
+
 	/* Tag device with one of EVDEV_TAG */
 	void (*tag_device)(struct evdev_device *device,
 			   struct udev_device *udev_device);
@@ -228,6 +237,12 @@ int
 evdev_device_resume(struct evdev_device *device);
 
 void
+evdev_notify_suspended_device(struct evdev_device *device);
+
+void
+evdev_notify_resumed_device(struct evdev_device *device);
+
+void
 evdev_keyboard_notify_key(struct evdev_device *device,
 			  uint32_t time,
 			  int key,
-- 
2.1.0



More information about the wayland-devel mailing list