From 06453ba7a533b919460d78de0edf1cd980bc638a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 19 Dec 2013 11:22:53 +1000 Subject: [PATCH] Add libinput_event_get_context() Add a function to retrieve the libinput context from any event. Signed-off-by: Peter Hutterer --- src/libinput.c | 13 +++++++++++-- src/libinput.h | 11 +++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index a9e458f2..d2e7596b 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -50,6 +50,7 @@ struct libinput_source { struct libinput_event { enum libinput_event_type type; + struct libinput *libinput; union libinput_event_target target; }; @@ -133,6 +134,12 @@ libinput_event_get_target(struct libinput_event *event) return event->target; } +LIBINPUT_EXPORT struct libinput* +libinput_event_get_context(struct libinput_event *event) +{ + return event->libinput; +} + LIBINPUT_EXPORT struct libinput_seat * libinput_event_added_seat_get_seat(struct libinput_event_added_seat *event) { @@ -596,10 +603,12 @@ libinput_dispatch(struct libinput *libinput) static void init_event_base(struct libinput_event *event, + struct libinput *libinput, enum libinput_event_type type, union libinput_event_target target) { event->type = type; + event->libinput = libinput; event->target = target; } @@ -608,7 +617,7 @@ post_base_event(struct libinput *libinput, enum libinput_event_type type, struct libinput_event *event) { - init_event_base(event, type, + init_event_base(event, libinput, type, (union libinput_event_target) { .libinput = libinput }); libinput_post_event(libinput, event); } @@ -618,7 +627,7 @@ post_device_event(struct libinput_device *device, enum libinput_event_type type, struct libinput_event *event) { - init_event_base(event, type, + init_event_base(event, device->seat->libinput, type, (union libinput_event_target) { .device = device }); libinput_post_event(device->seat->libinput, event); } diff --git a/src/libinput.h b/src/libinput.h index 894312df..5f4f51ed 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -240,6 +240,17 @@ libinput_event_get_type(struct libinput_event *event); union libinput_event_target libinput_event_get_target(struct libinput_event *event); +/** + * @ingroup event + * + * Get the libinput context from the event. + * + * @param event The libinput event + * @return The libinput context for this event. + */ +struct libinput* +libinput_event_get_context(struct libinput_event *event); + /** * @defgroup event_added_seat Added seat event */