[PATCH libinput 5/5] Add seat wide slot to touch events

Jonas Ådahl jadahl at gmail.com
Wed Feb 12 12:36:42 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>
---
 src/evdev.c            | 24 ++++++++++++++++++++++++
 src/evdev.h            |  3 +++
 src/libinput-private.h |  2 ++
 src/libinput.c         |  9 +++++++++
 src/libinput.h         | 13 +++++++++++++
 5 files changed, 51 insertions(+)

diff --git a/src/evdev.c b/src/evdev.c
index 3fe28e4..7393df7 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;
+	uint32_t seat_slot;
 	struct libinput_device *base = &device->base;
+	struct libinput_seat *seat = base->seat;
 
 	slot = device->mt.slot;
 
@@ -128,9 +130,14 @@ 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;
+		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 +146,12 @@ 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;
+
 		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 +160,13 @@ 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;
+		seat->slot_map &= ~(1 << seat_slot);
+
 		touch_notify_touch(base,
 				   time,
 				   slot,
+				   seat_slot,
 				   0, 0,
 				   LIBINPUT_TOUCH_TYPE_UP);
 		break;
@@ -160,10 +174,15 @@ 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;
+		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);
@@ -174,6 +193,7 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time)
 			touch_notify_touch(base,
 					   time,
 					   -1,
+					   device->abs.seat_slot,
 					   li_fixed_from_int(cx),
 					   li_fixed_from_int(cy),
 					   LIBINPUT_TOUCH_TYPE_DOWN);
@@ -188,9 +208,13 @@ 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;
+		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..6e7f081 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;
 
+		uint32_t seat_slot;
+
 		int apply_calibration;
 		float calibration[6];
 	} abs;
@@ -71,6 +73,7 @@ struct evdev_device {
 	struct {
 		int slot;
 		struct {
+			uint32_t seat_slot;
 			int32_t x, y;
 		} slots[MAX_SLOTS];
 	} mt;
diff --git a/src/libinput-private.h b/src/libinput-private.h
index 0d7de90..e9931b8 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;
@@ -148,6 +149,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 465913b..e0b7f71 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;
@@ -295,6 +296,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)
 {
@@ -774,6 +781,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)
@@ -787,6 +795,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 30b6011..2d6c5ad 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -571,6 +571,19 @@ 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 seat wide unique
+ * identifier of an active touch point.
+ *
+ * @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
-- 
1.8.3.2



More information about the wayland-devel mailing list