[PATCH libinput 2/2] Split up the touch event into the different touch types
Jonas Ådahl
jadahl at gmail.com
Wed Feb 19 13:04:11 PST 2014
Instead of having one touch events representing different types of touch
events by providing a touch type, have one separate event type per touch
type. This means the LIBINPUT_EVENT_TYPE_TOUCH is replaced with
LIBINPUT_EVENT_TYPE_TOUCH_DOWN, LIBINPUT_EVENT_TYPE_TOUCH_MOTION,
LIBINPUT_EVENT_TYPE_TOUCH_UP and LIBINPUT_EVENT_TYPE_TOUCH_CANCEL.
Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
---
src/evdev.c | 63 +++++++++++-----------------------
src/libinput-private.h | 27 +++++++++++----
src/libinput.c | 93 +++++++++++++++++++++++++++++++++++++++-----------
src/libinput.h | 54 ++++++++++++-----------------
tools/event-debug.c | 45 +++++++++++++-----------
5 files changed, 159 insertions(+), 123 deletions(-)
diff --git a/src/evdev.c b/src/evdev.c
index 2b7070a..d54bcd1 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -110,6 +110,7 @@ static void
evdev_flush_pending_event(struct evdev_device *device, uint32_t time)
{
int32_t cx, cy;
+ li_fixed_t x, y;
int slot;
uint32_t seat_slot;
struct libinput_device *base = &device->base;
@@ -135,28 +136,20 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time)
seat_slot = ffs(~seat->slot_map) - 1;
device->mt.slots[slot].seat_slot = seat_slot;
seat->slot_map |= 1 << seat_slot;
+ x = li_fixed_from_int(device->mt.slots[slot].x);
+ y = li_fixed_from_int(device->mt.slots[slot].y);
- touch_notify_touch(base,
- time,
- slot,
- seat_slot,
- li_fixed_from_int(device->mt.slots[slot].x),
- li_fixed_from_int(device->mt.slots[slot].y),
- LIBINPUT_TOUCH_TYPE_DOWN);
+ touch_notify_touch_down(base, time, slot, seat_slot, x, y);
break;
case EVDEV_ABSOLUTE_MT_MOTION:
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
break;
seat_slot = device->mt.slots[slot].seat_slot;
+ x = li_fixed_from_int(device->mt.slots[slot].x);
+ y = li_fixed_from_int(device->mt.slots[slot].y);
- touch_notify_touch(base,
- time,
- slot,
- seat_slot,
- li_fixed_from_int(device->mt.slots[slot].x),
- li_fixed_from_int(device->mt.slots[slot].y),
- LIBINPUT_TOUCH_TYPE_MOTION);
+ touch_notify_touch_motion(base, time, slot, seat_slot, x, y);
break;
case EVDEV_ABSOLUTE_MT_UP:
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
@@ -165,12 +158,7 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time)
seat_slot = device->mt.slots[slot].seat_slot;
seat->slot_map &= ~(1 << seat_slot);
- touch_notify_touch(base,
- time,
- slot,
- seat_slot,
- 0, 0,
- LIBINPUT_TOUCH_TYPE_UP);
+ touch_notify_touch_up(base, time, slot, seat_slot);
break;
case EVDEV_ABSOLUTE_TOUCH_DOWN:
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
@@ -181,29 +169,21 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time)
seat->slot_map |= 1 << seat_slot;
transform_absolute(device, &cx, &cy);
- touch_notify_touch(base,
- time,
- -1,
- seat_slot,
- li_fixed_from_int(cx),
- li_fixed_from_int(cy),
- LIBINPUT_TOUCH_TYPE_DOWN);
+ x = li_fixed_from_int(cx);
+ y = li_fixed_from_int(cy);
+
+ touch_notify_touch_down(base, time, -1, seat_slot, x, y);
break;
case EVDEV_ABSOLUTE_MOTION:
transform_absolute(device, &cx, &cy);
+ x = li_fixed_from_int(cx);
+ y = li_fixed_from_int(cy);
+
if (device->seat_caps & EVDEV_DEVICE_TOUCH) {
- touch_notify_touch(base,
- time,
- -1,
- device->abs.seat_slot,
- li_fixed_from_int(cx),
- li_fixed_from_int(cy),
- LIBINPUT_TOUCH_TYPE_DOWN);
+ seat_slot = device->abs.seat_slot;
+ touch_notify_touch_motion(base, time, -1, seat_slot, x, y);
} else if (device->seat_caps & EVDEV_DEVICE_POINTER) {
- pointer_notify_motion_absolute(base,
- time,
- li_fixed_from_int(cx),
- li_fixed_from_int(cy));
+ pointer_notify_motion_absolute(base, time, x, y);
}
break;
case EVDEV_ABSOLUTE_TOUCH_UP:
@@ -213,12 +193,7 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time)
seat_slot = device->abs.seat_slot;
seat->slot_map &= ~(1 << seat_slot);
- touch_notify_touch(base,
- time,
- -1,
- seat_slot,
- 0, 0,
- LIBINPUT_TOUCH_TYPE_UP);
+ touch_notify_touch_up(base, time, -1, seat_slot);
break;
default:
assert(0 && "Unknown pending event type");
diff --git a/src/libinput-private.h b/src/libinput-private.h
index e9931b8..d6d82bc 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -146,13 +146,26 @@ pointer_notify_axis(struct libinput_device *device,
li_fixed_t value);
void
-touch_notify_touch(struct libinput_device *device,
- uint32_t time,
- int32_t slot,
- int32_t seat_slot,
- li_fixed_t x,
- li_fixed_t y,
- enum libinput_touch_type touch_type);
+touch_notify_touch_down(struct libinput_device *device,
+ uint32_t time,
+ int32_t slot,
+ int32_t seat_slot,
+ li_fixed_t x,
+ li_fixed_t y);
+
+void
+touch_notify_touch_motion(struct libinput_device *device,
+ uint32_t time,
+ int32_t slot,
+ int32_t seat_slot,
+ li_fixed_t x,
+ li_fixed_t y);
+
+void
+touch_notify_touch_up(struct libinput_device *device,
+ uint32_t time,
+ int32_t slot,
+ int32_t seat_slot);
void
touch_notify_frame(struct libinput_device *device,
diff --git a/src/libinput.c b/src/libinput.c
index e0b7f71..75f1ad1 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -75,7 +75,6 @@ struct libinput_event_touch {
int32_t seat_slot;
li_fixed_t x;
li_fixed_t y;
- enum libinput_touch_type touch_type;
};
static void
@@ -115,7 +114,10 @@ libinput_event_get_pointer_event(struct libinput_event *event)
case LIBINPUT_EVENT_POINTER_BUTTON:
case LIBINPUT_EVENT_POINTER_AXIS:
return (struct libinput_event_pointer *) event;
- case LIBINPUT_EVENT_TOUCH_TOUCH:
+ case LIBINPUT_EVENT_TOUCH_DOWN:
+ case LIBINPUT_EVENT_TOUCH_UP:
+ case LIBINPUT_EVENT_TOUCH_MOTION:
+ case LIBINPUT_EVENT_TOUCH_CANCEL:
case LIBINPUT_EVENT_TOUCH_FRAME:
break;
}
@@ -138,7 +140,10 @@ libinput_event_get_keyboard_event(struct libinput_event *event)
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
case LIBINPUT_EVENT_POINTER_BUTTON:
case LIBINPUT_EVENT_POINTER_AXIS:
- case LIBINPUT_EVENT_TOUCH_TOUCH:
+ case LIBINPUT_EVENT_TOUCH_DOWN:
+ case LIBINPUT_EVENT_TOUCH_UP:
+ case LIBINPUT_EVENT_TOUCH_MOTION:
+ case LIBINPUT_EVENT_TOUCH_CANCEL:
case LIBINPUT_EVENT_TOUCH_FRAME:
break;
}
@@ -160,7 +165,10 @@ libinput_event_get_touch_event(struct libinput_event *event)
case LIBINPUT_EVENT_POINTER_BUTTON:
case LIBINPUT_EVENT_POINTER_AXIS:
break;
- case LIBINPUT_EVENT_TOUCH_TOUCH:
+ case LIBINPUT_EVENT_TOUCH_DOWN:
+ case LIBINPUT_EVENT_TOUCH_UP:
+ case LIBINPUT_EVENT_TOUCH_MOTION:
+ case LIBINPUT_EVENT_TOUCH_CANCEL:
case LIBINPUT_EVENT_TOUCH_FRAME:
return (struct libinput_event_touch *) event;
}
@@ -182,7 +190,10 @@ libinput_event_get_device_notify_event(struct libinput_event *event)
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
case LIBINPUT_EVENT_POINTER_BUTTON:
case LIBINPUT_EVENT_POINTER_AXIS:
- case LIBINPUT_EVENT_TOUCH_TOUCH:
+ case LIBINPUT_EVENT_TOUCH_DOWN:
+ case LIBINPUT_EVENT_TOUCH_UP:
+ case LIBINPUT_EVENT_TOUCH_MOTION:
+ case LIBINPUT_EVENT_TOUCH_CANCEL:
case LIBINPUT_EVENT_TOUCH_FRAME:
break;
}
@@ -334,12 +345,6 @@ libinput_event_touch_get_y(struct libinput_event_touch *event)
return event->y;
}
-LIBINPUT_EXPORT enum libinput_touch_type
-libinput_event_touch_get_touch_type(struct libinput_event_touch *event)
-{
- return event->touch_type;
-}
-
struct libinput_source *
libinput_add_fd(struct libinput *libinput,
int fd,
@@ -778,13 +783,39 @@ pointer_notify_axis(struct libinput_device *device,
}
void
-touch_notify_touch(struct libinput_device *device,
- uint32_t time,
- int32_t slot,
- int32_t seat_slot,
- li_fixed_t x,
- li_fixed_t y,
- enum libinput_touch_type touch_type)
+touch_notify_touch_down(struct libinput_device *device,
+ uint32_t time,
+ int32_t slot,
+ int32_t seat_slot,
+ li_fixed_t x,
+ li_fixed_t y)
+{
+ struct libinput_event_touch *touch_event;
+
+ touch_event = zalloc(sizeof *touch_event);
+ if (!touch_event)
+ return;
+
+ *touch_event = (struct libinput_event_touch) {
+ .time = time,
+ .slot = slot,
+ .seat_slot = seat_slot,
+ .x = x,
+ .y = y,
+ };
+
+ post_device_event(device,
+ LIBINPUT_EVENT_TOUCH_DOWN,
+ &touch_event->base);
+}
+
+void
+touch_notify_touch_motion(struct libinput_device *device,
+ uint32_t time,
+ int32_t slot,
+ int32_t seat_slot,
+ li_fixed_t x,
+ li_fixed_t y)
{
struct libinput_event_touch *touch_event;
@@ -798,11 +829,33 @@ touch_notify_touch(struct libinput_device *device,
.seat_slot = seat_slot,
.x = x,
.y = y,
- .touch_type = touch_type,
};
post_device_event(device,
- LIBINPUT_EVENT_TOUCH_TOUCH,
+ LIBINPUT_EVENT_TOUCH_MOTION,
+ &touch_event->base);
+}
+
+void
+touch_notify_touch_up(struct libinput_device *device,
+ uint32_t time,
+ int32_t slot,
+ int32_t seat_slot)
+{
+ struct libinput_event_touch *touch_event;
+
+ touch_event = zalloc(sizeof *touch_event);
+ if (!touch_event)
+ return;
+
+ *touch_event = (struct libinput_event_touch) {
+ .time = time,
+ .slot = slot,
+ .seat_slot = seat_slot,
+ };
+
+ post_device_event(device,
+ LIBINPUT_EVENT_TOUCH_UP,
&touch_event->base);
}
diff --git a/src/libinput.h b/src/libinput.h
index a27c164..780b10e 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -99,21 +99,6 @@ enum libinput_pointer_axis {
};
/**
- * @ingroup device
- *
- * Logical touch state of a touch point. A touch point usually follows the
- * sequence down, motion, up, with the number of motion events being zero or
- * greater. If a touch point was used for gesture interpretation internally
- * and will not generate any further events, the touchpoint is cancelled.
- */
-enum libinput_touch_type {
- LIBINPUT_TOUCH_TYPE_DOWN = 0,
- LIBINPUT_TOUCH_TYPE_UP = 1,
- LIBINPUT_TOUCH_TYPE_MOTION = 2,
- LIBINPUT_TOUCH_TYPE_CANCEL = 4
-};
-
-/**
* @ingroup base
*
* Event type for events returned by libinput_get_event().
@@ -149,7 +134,10 @@ enum libinput_event_type {
LIBINPUT_EVENT_POINTER_BUTTON,
LIBINPUT_EVENT_POINTER_AXIS,
- LIBINPUT_EVENT_TOUCH_TOUCH = 500,
+ LIBINPUT_EVENT_TOUCH_DOWN = 500,
+ LIBINPUT_EVENT_TOUCH_UP,
+ LIBINPUT_EVENT_TOUCH_MOTION,
+ LIBINPUT_EVENT_TOUCH_CANCEL,
/**
* Signals the end of a set of touchpoints at one device sample
* time. This event has no coordinate information attached.
@@ -172,7 +160,9 @@ struct libinput_event_pointer;
*
* Touch event representing a touch down, move or up, as well as a touch
* cancel and touch frame events. Valid event types for this event are @ref
- * LIBINPUT_EVENT_TOUCH_TOUCH and @ref LIBINPUT_EVENT_TOUCH_FRAME.
+ * LIBINPUT_EVENT_TOUCH_DOWN, LIBINPUT_EVENT_TOUCH_MOTION,
+ * LIBINPUT_EVENT_TOUCH_UP, LIBINPUT_EVENT_TOUCH_CANCEL and @ref
+ * LIBINPUT_EVENT_TOUCH_FRAME.
*/
struct libinput_event_touch;
@@ -561,7 +551,8 @@ libinput_event_touch_get_time(struct libinput_event_touch *event);
* If the touch event has no assigned slot, for example if it is from a
* single touch device, this function returns -1.
*
- * @note this function should not be called for LIBINPUT_EVENT_TOUCH_FRAME.
+ * @note this function should not be called for LIBINPUT_EVENT_TOUCH_CANCEL or
+ * LIBINPUT_EVENT_TOUCH_FRAME.
*
* @return The slot of this touch event
*/
@@ -577,7 +568,8 @@ libinput_event_touch_get_slot(struct libinput_event_touch *event);
* Events from single touch devices will be represented as one individual
* touch point per device.
*
- * @note this function should not be called for LIBINPUT_EVENT_TOUCH_FRAME.
+ * @note this function should not be called for LIBINPUT_EVENT_TOUCH_CANCEL or
+ * LIBINPUT_EVENT_TOUCH_FRAME.
*
* @return The seat slot of the touch event
*/
@@ -593,7 +585,8 @@ libinput_event_touch_get_seat_slot(struct libinput_event_touch *event);
* corresponding output screen coordinate, use
* libinput_event_touch_get_x_transformed().
*
- * @note this function should not be called for LIBINPUT_EVENT_TOUCH_FRAME.
+ * @note this function should only be called for LIBINPUT_EVENT_TOUCH_DOWN and
+ * LIBINPUT_EVENT_TOUCH_MOTION.
*
* @param event The libinput touch event
* @return the current absolute x coordinate
@@ -610,7 +603,10 @@ libinput_event_touch_get_x(struct libinput_event_touch *event);
* corresponding output screen coordinate, use
* libinput_event_touch_get_y_transformed().
*
- * @note this function should not be called for LIBINPUT_EVENT_TOUCH_FRAME.
+ * For LIBINPUT_EVENT_TOUCH_UP 0 is returned.
+ *
+ * @note this function should only be called for LIBINPUT_EVENT_TOUCH_DOWN and
+ * LIBINPUT_EVENT_TOUCH_MOTION.
*
* @param event The libinput touch event
* @return the current absolute y coordinate
@@ -624,7 +620,8 @@ libinput_event_touch_get_y(struct libinput_event_touch *event);
* Return the current absolute x coordinate of the touch event, transformed to
* screen coordinates.
*
- * @note this function should not be called for LIBINPUT_EVENT_TOUCH_FRAME.
+ * @note this function should only be called for LIBINPUT_EVENT_TOUCH_DOWN and
+ * LIBINPUT_EVENT_TOUCH_MOTION.
*
* @param event The libinput touch event
* @param width The current output screen width
@@ -640,7 +637,8 @@ libinput_event_touch_get_x_transformed(struct libinput_event_touch *event,
* Return the current absolute y coordinate of the touch event, transformed to
* screen coordinates.
*
- * @note this function should not be called for LIBINPUT_EVENT_TOUCH_FRAME.
+ * @note this function should only be called for LIBINPUT_EVENT_TOUCH_DOWN and
+ * LIBINPUT_EVENT_TOUCH_MOTION.
*
* @param event The libinput touch event
* @param height The current output screen height
@@ -651,16 +649,6 @@ libinput_event_touch_get_y_transformed(struct libinput_event_touch *event,
uint32_t height);
/**
- * @ingroup event_touch
- *
- * @note this function should not be called for LIBINPUT_EVENT_TOUCH_FRAME.
- *
- * @return the type of touch that occured on the device
- */
-enum libinput_touch_type
-libinput_event_touch_get_touch_type(struct libinput_event_touch *event);
-
-/**
* @defgroup base Initialization and manipulation of libinput contexts
*/
diff --git a/tools/event-debug.c b/tools/event-debug.c
index 4eb5dd3..876f6f0 100644
--- a/tools/event-debug.c
+++ b/tools/event-debug.c
@@ -199,8 +199,17 @@ print_event_header(struct libinput_event *ev)
case LIBINPUT_EVENT_POINTER_AXIS:
type = "POINTER_AXIS";
break;
- case LIBINPUT_EVENT_TOUCH_TOUCH:
- type = "TOUCH_TOUCH";
+ case LIBINPUT_EVENT_TOUCH_DOWN:
+ type = "TOUCH_DOWN";
+ break;
+ case LIBINPUT_EVENT_TOUCH_MOTION:
+ type = "TOUCH_MOTION";
+ break;
+ case LIBINPUT_EVENT_TOUCH_UP:
+ type = "TOUCH_UP";
+ break;
+ case LIBINPUT_EVENT_TOUCH_CANCEL:
+ type = "TOUCH_CANCEL";
break;
case LIBINPUT_EVENT_TOUCH_FRAME:
type = "TOUCH_FRAME";
@@ -309,7 +318,7 @@ print_axis_event(struct libinput_event *ev)
}
static void
-print_touch_frame_event(struct libinput_event *ev)
+print_touch_event_without_coords(struct libinput_event *ev)
{
struct libinput_event_touch *t = libinput_event_get_touch_event(ev);
@@ -318,26 +327,15 @@ print_touch_frame_event(struct libinput_event *ev)
}
static void
-print_touch_event(struct libinput_event *ev)
+print_touch_event_with_coords(struct libinput_event *ev)
{
struct libinput_event_touch *t = libinput_event_get_touch_event(ev);
li_fixed_t x = libinput_event_touch_get_x_transformed(t, screen_width),
y = libinput_event_touch_get_y_transformed(t, screen_height);
- const char *type;
-
- switch (libinput_event_touch_get_touch_type(t)) {
- case LIBINPUT_TOUCH_TYPE_DOWN: type = "down"; break;
- case LIBINPUT_TOUCH_TYPE_UP: type = "up"; break;
- case LIBINPUT_TOUCH_TYPE_MOTION: type = "motion"; break;
- case LIBINPUT_TOUCH_TYPE_CANCEL: type = "cancel"; break;
- default:
- abort();
- }
print_event_time(libinput_event_touch_get_time(t));
- printf("%6s %d (%d) %5.2f/%5.2f\n",
- type,
+ printf("%d (%d) %5.2f/%5.2f\n",
libinput_event_touch_get_slot(t),
libinput_event_touch_get_seat_slot(t),
li_fixed_to_double(x),
@@ -376,11 +374,20 @@ handle_and_print_events(struct libinput *li)
case LIBINPUT_EVENT_POINTER_AXIS:
print_axis_event(ev);
break;
- case LIBINPUT_EVENT_TOUCH_TOUCH:
- print_touch_event(ev);
+ case LIBINPUT_EVENT_TOUCH_DOWN:
+ print_touch_event_with_coords(ev);
+ break;
+ case LIBINPUT_EVENT_TOUCH_MOTION:
+ print_touch_event_with_coords(ev);
+ break;
+ case LIBINPUT_EVENT_TOUCH_UP:
+ print_touch_event_without_coords(ev);
+ break;
+ case LIBINPUT_EVENT_TOUCH_CANCEL:
+ print_touch_event_without_coords(ev);
break;
case LIBINPUT_EVENT_TOUCH_FRAME:
- print_touch_frame_event(ev);
+ print_touch_event_without_coords(ev);
break;
}
--
1.8.3.2
More information about the wayland-devel
mailing list