[PATCH libinput v2] Add seat wide slot to touch events
Jonas Ådahl
jadahl at gmail.com
Sat Feb 22 06:38:27 PST 2014
Since a Wayland compositor have to represent all touch devices of a seat
as one virtual device, lets make that easier by also providing seat wide
slots with touch events.
Seat wide slots may be accessed using
libinput_event_touch_get_seat_slot().
Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
---
Changes since v1:
For now, drop touch events we cant assign a seat slot.
src/evdev.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
src/evdev.h | 3 +++
src/libinput-private.h | 2 ++
src/libinput.c | 9 +++++++++
src/libinput.h | 16 ++++++++++++++++
tools/event-debug.c | 3 ++-
6 files changed, 80 insertions(+), 1 deletion(-)
diff --git a/src/evdev.c b/src/evdev.c
index beec75e..ad5009d 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -109,7 +109,9 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time)
{
int32_t cx, cy;
int slot;
+ int seat_slot;
struct libinput_device *base = &device->base;
+ struct libinput_seat *seat = base->seat;
slot = device->mt.slot;
@@ -128,9 +130,18 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time)
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
break;
+ seat_slot = ffs(~seat->slot_map) - 1;
+ device->mt.slots[slot].seat_slot = seat_slot;
+
+ if (seat_slot == -1)
+ break;
+
+ seat->slot_map |= 1 << seat_slot;
+
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);
@@ -139,9 +150,15 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time)
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
break;
+ seat_slot = device->mt.slots[slot].seat_slot;
+
+ if (seat_slot == -1)
+ break;
+
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);
@@ -150,9 +167,17 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time)
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
break;
+ seat_slot = device->mt.slots[slot].seat_slot;
+
+ if (seat_slot == -1)
+ break;
+
+ seat->slot_map &= ~(1 << seat_slot);
+
touch_notify_touch(base,
time,
slot,
+ seat_slot,
0, 0,
LIBINPUT_TOUCH_TYPE_UP);
break;
@@ -160,10 +185,19 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time)
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
break;
+ seat_slot = ffs(~seat->slot_map) - 1;
+ device->abs.seat_slot = seat_slot;
+
+ if (seat_slot == -1)
+ break;
+
+ 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);
@@ -171,9 +205,15 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time)
case EVDEV_ABSOLUTE_MOTION:
transform_absolute(device, &cx, &cy);
if (device->seat_caps & EVDEV_DEVICE_TOUCH) {
+ seat_slot = device->abs.seat_slot;
+
+ if (seat_slot == -1)
+ break;
+
touch_notify_touch(base,
time,
-1,
+ seat_slot,
li_fixed_from_int(cx),
li_fixed_from_int(cy),
LIBINPUT_TOUCH_TYPE_DOWN);
@@ -188,9 +228,17 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time)
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
break;
+ seat_slot = device->abs.seat_slot;
+
+ if (seat_slot == -1)
+ break;
+
+ seat->slot_map &= ~(1 << seat_slot);
+
touch_notify_touch(base,
time,
-1,
+ seat_slot,
0, 0,
LIBINPUT_TOUCH_TYPE_UP);
break;
diff --git a/src/evdev.h b/src/evdev.h
index 3c9f93a..fefde7a 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -64,6 +64,8 @@ struct evdev_device {
int min_x, max_x, min_y, max_y;
int32_t x, y;
+ int32_t seat_slot;
+
int apply_calibration;
float calibration[6];
} abs;
@@ -71,6 +73,7 @@ struct evdev_device {
struct {
int slot;
struct {
+ int32_t seat_slot;
int32_t x, y;
} slots[MAX_SLOTS];
} mt;
diff --git a/src/libinput-private.h b/src/libinput-private.h
index 1fff7de..9cda209 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -57,6 +57,7 @@ struct libinput_seat {
struct list devices_list;
void *user_data;
int refcount;
+ uint32_t slot_map;
char *physical_name;
char *logical_name;
libinput_seat_destroy_func destroy;
@@ -155,6 +156,7 @@ 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);
diff --git a/src/libinput.c b/src/libinput.c
index d954603..beb199d 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -72,6 +72,7 @@ struct libinput_event_touch {
struct libinput_event base;
uint32_t time;
int32_t slot;
+ int32_t seat_slot;
li_fixed_t x;
li_fixed_t y;
enum libinput_touch_type touch_type;
@@ -357,6 +358,12 @@ libinput_event_touch_get_slot(struct libinput_event_touch *event)
return event->slot;
}
+LIBINPUT_EXPORT int32_t
+libinput_event_touch_get_seat_slot(struct libinput_event_touch *event)
+{
+ return event->seat_slot;
+}
+
LIBINPUT_EXPORT li_fixed_t
libinput_event_touch_get_x(struct libinput_event_touch *event)
{
@@ -836,6 +843,7 @@ 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)
@@ -849,6 +857,7 @@ touch_notify_touch(struct libinput_device *device,
*touch_event = (struct libinput_event_touch) {
.time = time,
.slot = slot,
+ .seat_slot = seat_slot,
.x = x,
.y = y,
.touch_type = touch_type,
diff --git a/src/libinput.h b/src/libinput.h
index 1d166b2..993472c 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -580,6 +580,22 @@ libinput_event_touch_get_slot(struct libinput_event_touch *event);
/**
* @ingroup event_touch
*
+ * Get the seat slot of the touch event. A seat slot is a non-negative seat
+ * wide unique identifier of an active touch point.
+ *
+ * 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.
+ *
+ * @return The seat slot of the touch event
+ */
+int32_t
+libinput_event_touch_get_seat_slot(struct libinput_event_touch *event);
+
+/**
+ * @ingroup event_touch
+ *
* Return the current absolute x coordinate of the touch event.
*
* The coordinate is in a device specific coordinate space; to get the
diff --git a/tools/event-debug.c b/tools/event-debug.c
index d60cb2e..4eb5dd3 100644
--- a/tools/event-debug.c
+++ b/tools/event-debug.c
@@ -336,9 +336,10 @@ print_touch_event(struct libinput_event *ev)
print_event_time(libinput_event_touch_get_time(t));
- printf("%6s %d %5.2f/%5.2f\n",
+ printf("%6s %d (%d) %5.2f/%5.2f\n",
type,
libinput_event_touch_get_slot(t),
+ libinput_event_touch_get_seat_slot(t),
li_fixed_to_double(x),
li_fixed_to_double(y));
}
--
1.8.3.2
More information about the wayland-devel
mailing list