diff options
| author | Peter Hutterer <peter.hutterer@who-t.net> | 2013-07-04 10:07:44 +1000 |
|---|---|---|
| committer | Peter Hutterer <peter.hutterer@who-t.net> | 2013-07-04 10:07:44 +1000 |
| commit | e6f85ee1f16f2b209d01b71fbc2c256b304956ba (patch) | |
| tree | 67e392125a4903f9f51678c928ce5a686e79214b /libevdev | |
| parent | bafd498b6734e4339378f323bfacbbd2d57b3e38 (diff) | |
| download | libevdev-e6f85ee1f16f2b209d01b71fbc2c256b304956ba.tar.gz | |
Add two helper functions to check event type/code
These aren't really that useful since they're just one or two lines in
code, but it saves callers from accidentally misplacing braces, etc.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'libevdev')
| -rw-r--r-- | libevdev/libevdev.c | 15 | ||||
| -rw-r--r-- | libevdev/libevdev.h | 42 |
2 files changed, 57 insertions, 0 deletions
diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c index 525f2de..3a6c6eb 100644 --- a/libevdev/libevdev.c +++ b/libevdev/libevdev.c @@ -928,6 +928,21 @@ libevdev_grab(struct libevdev *dev, int grab) return rc < 0 ? -errno : 0; } +int +libevdev_is_event_type(const struct input_event *ev, unsigned int type) +{ + return type < EV_MAX && ev->type == type; +} + +int +libevdev_is_event_code(const struct input_event *ev, unsigned int type, unsigned int code) +{ + return type < EV_MAX && + ev->type == type && + (type == EV_SYN || code <= libevdev_get_event_type_max(type)) && + ev->code == code; +} + const char* libevdev_get_event_type_name(unsigned int type) { diff --git a/libevdev/libevdev.h b/libevdev/libevdev.h index 7d5fdf7..dcb07c1 100644 --- a/libevdev/libevdev.h +++ b/libevdev/libevdev.h @@ -870,6 +870,48 @@ int libevdev_kernel_set_abs_value(struct libevdev *dev, unsigned int code, const /** * @ingroup misc * + * Helper function to check if an event is of a specific type. This is + * virtually the same as: + * + * ev->type == type + * + * with the exception that some sanity checks are performed to ensure type + * is valid. + * + * @param ev The input event to check + * @param type Input event type to compare the event against (EV_REL, EV_ABS, + * etc.) + * + * @return 1 if the event type matches the given type, 0 otherwise (or if + * type is invalid) + */ +int libevdev_is_event_type(const struct input_event *ev, unsigned int type); + +/** + * @ingroup misc + * + * Helper function to check if an event is of a specific type and code. This + * is virtually the same as: + * + * ev->type == type && ev->code == code + * + * with the exception that some sanity checks are performed to ensure type and + * code are valid. + * + * @param ev The input event to check + * @param type Input event type to compare the event against (EV_REL, EV_ABS, + * etc.) + * @param code Input event code to compare the event against (ABS_X, REL_X, + * etc.) + * + * @return 1 if the event type matches the given type and code, 0 otherwise + * (or if type/code are invalid) + */ +int libevdev_is_event_code(const struct input_event *ev, unsigned int type, unsigned int code); + +/** + * @ingroup misc + * * @param type The event type to return the name for. * * @return The name of the given event type (e.g. EV_ABS) or NULL for an |
