From: Peter Hutterer Date: Thu, 19 Dec 2013 23:22:32 +0000 (+1000) Subject: Provide accessors to retrieve the right event type X-Git-Tag: 0.1.0~62 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e99d36278789a9f8e7bcc1ce47fa11ed77011b2c;p=platform%2Fupstream%2Flibinput.git Provide accessors to retrieve the right event type Slightly enhances the type-safety. A caller may now do something along the lines of struct libinput_event_pointer *ptrev; ptrev = libinput_event_get_pointer_event(event); if (!ptrev) oops, that wasn't a pointer event Signed-off-by: Peter Hutterer --- diff --git a/src/libinput.c b/src/libinput.c index ec862394..45f922ec 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -107,6 +107,92 @@ libinput_event_get_device(struct libinput_event *event) return event->device; } +LIBINPUT_EXPORT struct libinput_event_pointer* +libinput_event_get_pointer_event(struct libinput_event *event) +{ + switch (event->type) { + case LIBINPUT_EVENT_NONE: + abort(); /* not used as actual event type */ + case LIBINPUT_EVENT_DEVICE_ADDED: + case LIBINPUT_EVENT_DEVICE_REMOVED: + case LIBINPUT_EVENT_KEYBOARD_KEY: + break; + case LIBINPUT_EVENT_POINTER_MOTION: + case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: + case LIBINPUT_EVENT_POINTER_BUTTON: + case LIBINPUT_EVENT_POINTER_AXIS: + return (struct libinput_event_pointer*)event; + case LIBINPUT_EVENT_TOUCH_TOUCH: + break; + } + + return NULL; +} + +LIBINPUT_EXPORT struct libinput_event_keyboard* +libinput_event_get_keyboard_event(struct libinput_event *event) +{ + switch (event->type) { + case LIBINPUT_EVENT_NONE: + abort(); /* not used as actual event type */ + case LIBINPUT_EVENT_DEVICE_ADDED: + case LIBINPUT_EVENT_DEVICE_REMOVED: + break; + case LIBINPUT_EVENT_KEYBOARD_KEY: + return (struct libinput_event_keyboard*)event; + case LIBINPUT_EVENT_POINTER_MOTION: + case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: + case LIBINPUT_EVENT_POINTER_BUTTON: + case LIBINPUT_EVENT_POINTER_AXIS: + case LIBINPUT_EVENT_TOUCH_TOUCH: + break; + } + + return NULL; +} + +LIBINPUT_EXPORT struct libinput_event_touch* +libinput_event_get_touch_event(struct libinput_event *event) +{ + switch (event->type) { + case LIBINPUT_EVENT_NONE: + abort(); /* not used as actual event type */ + case LIBINPUT_EVENT_DEVICE_ADDED: + case LIBINPUT_EVENT_DEVICE_REMOVED: + case LIBINPUT_EVENT_KEYBOARD_KEY: + case LIBINPUT_EVENT_POINTER_MOTION: + case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: + case LIBINPUT_EVENT_POINTER_BUTTON: + case LIBINPUT_EVENT_POINTER_AXIS: + break; + case LIBINPUT_EVENT_TOUCH_TOUCH: + return (struct libinput_event_touch*)event; + } + + return NULL; +} + +LIBINPUT_EXPORT struct libinput_event_device_notify* +libinput_event_get_device_notify_event(struct libinput_event *event) +{ + switch (event->type) { + case LIBINPUT_EVENT_NONE: + abort(); /* not used as actual event type */ + case LIBINPUT_EVENT_DEVICE_ADDED: + case LIBINPUT_EVENT_DEVICE_REMOVED: + return (struct libinput_event_device_notify*)event; + case LIBINPUT_EVENT_KEYBOARD_KEY: + case LIBINPUT_EVENT_POINTER_MOTION: + case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: + case LIBINPUT_EVENT_POINTER_BUTTON: + case LIBINPUT_EVENT_POINTER_AXIS: + case LIBINPUT_EVENT_TOUCH_TOUCH: + break; + } + + return NULL; +} + LIBINPUT_EXPORT uint32_t libinput_event_keyboard_get_time( struct libinput_event_keyboard *event) diff --git a/src/libinput.h b/src/libinput.h index ec8336d7..1df6cdd3 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -237,6 +237,50 @@ libinput_event_get_context(struct libinput_event *event); struct libinput_device* libinput_event_get_device(struct libinput_event *event); +/** + * @ingroup event + * + * Return the pointer event that is this input event. If the event type does + * not match the pointer event types, this function returns NULL. + * + * @return A pointer event, or NULL for other events + */ +struct libinput_event_pointer* +libinput_event_get_pointer_event(struct libinput_event *event); + +/** + * @ingroup event + * + * Return the keyboard event that is this input event. If the event type does + * not match the keyboard event types, this function returns NULL. + * + * @return A keyboard event, or NULL for other events + */ +struct libinput_event_keyboard* +libinput_event_get_keyboard_event(struct libinput_event *event); + +/** + * @ingroup event + * + * Return the touch event that is this input event. If the event type does + * not match the touch event types, this function returns NULL. + * + * @return A touch event, or NULL for other events + */ +struct libinput_event_touch* +libinput_event_get_touch_event(struct libinput_event *event); + +/** + * @ingroup event + * + * Return the device event that is this input event. If the event type does + * not match the device event types, this function returns NULL. + * + * @return A device event, or NULL for other events + */ +struct libinput_event_device_notify* +libinput_event_get_device_notify_event(struct libinput_event *event); + /** * @defgroup event_keyboard Keyboard events *