[PATCH libinput 7/9] Add functions to convert back to the base event

Peter Hutterer peter.hutterer at who-t.net
Thu Mar 27 21:38:50 PDT 2014


A few functions only work on the base event but once we've converted to the
target event we can't go back. Casting works for now but that would expose
internal ABI.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
I got annoyed that I had to pass two arguments around or lose some
type-safety just to e.g. get the event type from multiple places.

 src/libinput.c | 24 ++++++++++++++++++++++++
 src/libinput.h | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/src/libinput.c b/src/libinput.c
index 182c401..1e31be3 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -1090,3 +1090,27 @@ libinput_device_has_capability(struct libinput_device *device,
 	return evdev_device_has_capability((struct evdev_device *) device,
 					   capability);
 }
+
+LIBINPUT_EXPORT struct libinput_event *
+libinput_event_device_notify_get_base_event(struct libinput_event_device_notify *event)
+{
+	return &event->base;
+}
+
+LIBINPUT_EXPORT struct libinput_event *
+libinput_event_keyboard_get_base_event(struct libinput_event_keyboard *event)
+{
+	return &event->base;
+}
+
+LIBINPUT_EXPORT struct libinput_event *
+libinput_event_pointer_get_base_event(struct libinput_event_pointer *event)
+{
+	return &event->base;
+}
+
+LIBINPUT_EXPORT struct libinput_event *
+libinput_event_touch_get_base_event(struct libinput_event_touch *event)
+{
+	return &event->base;
+}
diff --git a/src/libinput.h b/src/libinput.h
index dab24b7..6e43181 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -271,6 +271,8 @@ libinput_event_get_device(struct libinput_event *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.
  *
+ * The inverse of this function is libinput_event_pointer_get_base_event().
+ *
  * @return A pointer event, or NULL for other events
  */
 struct libinput_event_pointer *
@@ -282,6 +284,8 @@ libinput_event_get_pointer_event(struct libinput_event *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.
  *
+ * The inverse of this function is libinput_event_keyboard_get_base_event().
+ *
  * @return A keyboard event, or NULL for other events
  */
 struct libinput_event_keyboard *
@@ -293,6 +297,8 @@ libinput_event_get_keyboard_event(struct libinput_event *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.
  *
+ * The inverse of this function is libinput_event_touch_get_base_event().
+ *
  * @return A touch event, or NULL for other events
  */
 struct libinput_event_touch *
@@ -304,12 +310,23 @@ libinput_event_get_touch_event(struct libinput_event *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.
  *
+ * The inverse of this function is
+ * libinput_event_device_notify_get_base_event().
+ *
  * @return A device event, or NULL for other events
  */
 struct libinput_event_device_notify *
 libinput_event_get_device_notify_event(struct libinput_event *event);
 
 /**
+ * @ingroup event
+ *
+ * @return The generic libinput_event of this event
+ */
+struct libinput_event *
+libinput_event_device_notify_get_base_event(struct libinput_event_device_notify *event);
+
+/**
  * @defgroup event_keyboard Keyboard events
  *
  * Key events are generated when a key changes its logical state, usually by
@@ -340,6 +357,15 @@ libinput_event_keyboard_get_key(struct libinput_event_keyboard *event);
 enum libinput_keyboard_key_state
 libinput_event_keyboard_get_key_state(struct libinput_event_keyboard *event);
 
+
+/**
+ * @ingroup event_keyboard
+ *
+ * @return The generic libinput_event of this event
+ */
+struct libinput_event *
+libinput_event_keyboard_get_base_event(struct libinput_event_keyboard *event);
+
 /**
  * @defgroup event_pointer Pointer events
  *
@@ -538,6 +564,15 @@ li_fixed_t
 libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event);
 
 /**
+ * @ingroup event_pointer
+ *
+ * @return The generic libinput_event of this event
+ */
+struct libinput_event *
+libinput_event_pointer_get_base_event(struct libinput_event_pointer *event);
+
+
+/**
  * @defgroup event_touch Touch events
  *
  * Events from absolute touch devices.
@@ -658,6 +693,14 @@ libinput_event_touch_get_y_transformed(struct libinput_event_touch *event,
 				       uint32_t height);
 
 /**
+ * @ingroup event_touch
+ *
+ * @return The generic libinput_event of this event
+ */
+struct libinput_event *
+libinput_event_touch_get_base_event(struct libinput_event_touch *event);
+
+/**
  * @defgroup base Initialization and manipulation of libinput contexts
  */
 
-- 
1.8.5.3



More information about the wayland-devel mailing list