mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-25 02:20:05 +01:00
core: Add internal event notification mechanism
For features like e.g. disable-touchpad-while-typing, it is necessary for one device to be able to listen into another device's events. It is tempting to use the existing device_added / device_removed mechanism to give e.g. the keyboard a link to the touchpad, and make the keyboard code disable / re-enable the touchpad but this is wrong. This needs to be a setting of the touchpad, and the policy for things like which events to count as activity, and what sort of timeout to use to consider the device idle, belongs in the touchpad code not in the keyboard code. Add an event listeners mechanism so that the touchpad can listen for (e.g.) keyboard events, and respond to these itself. 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
d9631dbe21
commit
ad2acca72d
2 changed files with 47 additions and 0 deletions
|
|
@ -144,12 +144,19 @@ struct libinput_device_config {
|
|||
struct libinput_device {
|
||||
struct libinput_seat *seat;
|
||||
struct list link;
|
||||
struct list event_listeners;
|
||||
void *user_data;
|
||||
int terminated;
|
||||
int refcount;
|
||||
struct libinput_device_config config;
|
||||
};
|
||||
|
||||
struct libinput_event_listener {
|
||||
struct list link;
|
||||
void (*notify_func)(uint64_t time, struct libinput_event *ev, void *notify_func_data);
|
||||
void *notify_func_data;
|
||||
};
|
||||
|
||||
typedef void (*libinput_source_dispatch_t)(void *data);
|
||||
|
||||
|
||||
|
|
@ -205,6 +212,18 @@ void
|
|||
libinput_device_init(struct libinput_device *device,
|
||||
struct libinput_seat *seat);
|
||||
|
||||
void
|
||||
libinput_device_add_event_listener(struct libinput_device *device,
|
||||
struct libinput_event_listener *listener,
|
||||
void (*notify_func)(
|
||||
uint64_t time,
|
||||
struct libinput_event *event,
|
||||
void *notify_func_data),
|
||||
void *notify_func_data);
|
||||
|
||||
void
|
||||
libinput_device_remove_event_listener(struct libinput_event_listener *listener);
|
||||
|
||||
void
|
||||
notify_added_device(struct libinput_device *device);
|
||||
|
||||
|
|
|
|||
|
|
@ -674,6 +674,7 @@ libinput_device_init(struct libinput_device *device,
|
|||
{
|
||||
device->seat = seat;
|
||||
device->refcount = 1;
|
||||
list_init(&device->event_listeners);
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT struct libinput_device *
|
||||
|
|
@ -686,6 +687,7 @@ libinput_device_ref(struct libinput_device *device)
|
|||
static void
|
||||
libinput_device_destroy(struct libinput_device *device)
|
||||
{
|
||||
assert(list_empty(&device->event_listeners));
|
||||
evdev_device_destroy((struct evdev_device *) device);
|
||||
}
|
||||
|
||||
|
|
@ -732,6 +734,26 @@ libinput_dispatch(struct libinput *libinput)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
libinput_device_add_event_listener(struct libinput_device *device,
|
||||
struct libinput_event_listener *listener,
|
||||
void (*notify_func)(
|
||||
uint64_t time,
|
||||
struct libinput_event *event,
|
||||
void *notify_func_data),
|
||||
void *notify_func_data)
|
||||
{
|
||||
listener->notify_func = notify_func;
|
||||
listener->notify_func_data = notify_func_data;
|
||||
list_insert(&device->event_listeners, &listener->link);
|
||||
}
|
||||
|
||||
void
|
||||
libinput_device_remove_event_listener(struct libinput_event_listener *listener)
|
||||
{
|
||||
list_remove(&listener->link);
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
update_seat_key_count(struct libinput_seat *seat,
|
||||
int32_t key,
|
||||
|
|
@ -799,7 +821,13 @@ post_device_event(struct libinput_device *device,
|
|||
enum libinput_event_type type,
|
||||
struct libinput_event *event)
|
||||
{
|
||||
struct libinput_event_listener *listener, *tmp;
|
||||
|
||||
init_event_base(event, device, type);
|
||||
|
||||
list_for_each_safe(listener, tmp, &device->event_listeners, link)
|
||||
listener->notify_func(time, event, listener->notify_func_data);
|
||||
|
||||
libinput_post_event(device->seat->libinput, event);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue