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

Peter Hutterer peter.hutterer at who-t.net
Wed Feb 19 20:53:18 PST 2014


On Wed, Feb 19, 2014 at 10:04:10PM +0100, Jonas Ådahl wrote:
> 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         | 16 ++++++++++++++++
>  tools/event-debug.c    |  3 ++-
>  6 files changed, 56 insertions(+), 1 deletion(-)
> 
> diff --git a/src/evdev.c b/src/evdev.c
> index d2cdbaf..2b7070a 100644
> --- a/src/evdev.c
> +++ b/src/evdev.c
> @@ -111,7 +111,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;
>  
> @@ -130,9 +132,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;

funny, had a bit of a deja-vu here :)
see http://lists.freedesktop.org/archives/wayland-devel/2014-February/013238.html
for my comments, both still apply.

Cheers,
   Peter


> +		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);
> @@ -141,9 +148,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);
> @@ -152,9 +162,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;
> @@ -162,10 +176,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);
> @@ -176,6 +195,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);
> @@ -190,9 +210,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..a27c164 100644
> --- a/src/libinput.h
> +++ b/src/libinput.h
> @@ -571,6 +571,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
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> 


More information about the wayland-devel mailing list