mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-02-03 14:40:26 +01:00
evdev: Add an internal device suspend / resume notification system
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@redhat.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
7e932ed33f
commit
3bf9b02d81
3 changed files with 69 additions and 0 deletions
|
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
|
|||
52
src/evdev.c
52
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
15
src/evdev.h
15
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);
|
||||
|
|
@ -227,6 +236,12 @@ evdev_device_suspend(struct evdev_device *device);
|
|||
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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue