[PATCH libinput 3/3] Deprecate libinput_device_has_capability

Jonas Ã…dahl jadahl at gmail.com
Mon Jan 26 22:52:04 PST 2015


On Tue, Jan 27, 2015 at 03:45:58PM +1000, Peter Hutterer wrote:
> With the introduction of capability events, this is theoretically racy.
> 
> In the current implementation that's fine as we add the capabilities before we
> return the device, but in the future a capability event may be in the event
> queue to add/remove a capability, so this call is unreliable.
> 
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
>  src/libinput.h |  9 +++++++--
>  test/touch.c   | 16 ++++++++++++----
>  2 files changed, 19 insertions(+), 6 deletions(-)
> 
> diff --git a/src/libinput.h b/src/libinput.h
> index 50bedc8..1029483 100644
> --- a/src/libinput.h
> +++ b/src/libinput.h
> @@ -1593,13 +1593,18 @@ libinput_device_led_update(struct libinput_device *device,
>  /**
>   * @ingroup device
>   *
> - * Check if the given device has the specified capability
> + * Check if the given device has the specified capability.
> + *
> + * @note This function should not be used. It suffers from potential race
> + * conditions as it will give the capabilities of the device right now which
> + * may be different to the capabilities as seen in the event stream.
>   *
>   * @return 1 if the given device has the capability or 0 if not
>   */
>  int
>  libinput_device_has_capability(struct libinput_device *device,
> -			       enum libinput_device_capability capability);
> +			       enum libinput_device_capability capability)
> +	LIBINPUT_ATTRIBUTE_DEPRECATED;
>  
>  /**
>   * @ingroup device
> diff --git a/test/touch.c b/test/touch.c
> index 29890a4..aad7455 100644
> --- a/test/touch.c
> +++ b/test/touch.c
> @@ -427,19 +427,27 @@ START_TEST(fake_mt_exists)
>  	struct litest_device *dev = litest_current_device();
>  	struct libinput *li = dev->libinput;
>  	struct libinput_event *event;
> +	struct libinput_event_device_capability *cev;
>  	struct libinput_device *device;
>  
>  	litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED, -1);
>  	event = libinput_get_event(li);
>  	device = libinput_event_get_device(event);
> +	libinput_device_ref(device);
> +	libinput_event_destroy(event);
>  
> -	ck_assert(!libinput_device_has_capability(device,
> -						  LIBINPUT_DEVICE_CAP_TOUCH));
> +	litest_wait_for_event_of_type(li,
> +				      LIBINPUT_EVENT_DEVICE_CAPABILITY_ADDED,
> +				      -1);
> +	event = libinput_get_event(li);
> +	cev = libinput_event_get_device_capability_event(event);
>  
>  	/* This test may need fixing if we add other fake-mt devices that
>  	 * have different capabilities */
> -	ck_assert(libinput_device_has_capability(device,
> -						 LIBINPUT_DEVICE_CAP_POINTER));
> +	ck_assert_int_eq(libinput_event_device_capability_get_capability(cev),
> +			 LIBINPUT_DEVICE_CAP_POINTER);

You dont test for no-touch capability any longer after this change. You
need to retrieve every capability event there is and check that none is
a touch capability event.


Jonas

> +	libinput_event_destroy(event);
> +	libinput_device_unref(device);
>  }
>  END_TEST
>  
> -- 
> 2.1.0
> 
> _______________________________________________
> 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