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 <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2013-12-20 09:22:32 +10:00
parent aac781511f
commit e99d362787
2 changed files with 130 additions and 0 deletions

View file

@ -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)

View file

@ -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
*