[PATCH libinput 1/2] Use an enum to enable/disable tapping configuration

Hans de Goede hdegoede at redhat.com
Mon Jul 21 01:01:27 PDT 2014


Hi,

On 07/21/2014 08:40 AM, Peter Hutterer wrote:
> More expressive in the caller and less ambiguous about return values (is it 1?
> is it non-zero? can it be negative?)
> 
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

Looks good, series is:

Reviewed-by: Hans de Goede <hdegoede at redhat.com>

Regards,

Hans
> ---
>  src/evdev-mt-touchpad-tap.c | 14 ++++++-----
>  src/libinput-private.h      |  6 ++---
>  src/libinput.c              | 14 +++++++----
>  src/libinput.h              | 25 ++++++++++++++-----
>  test/touchpad.c             | 60 +++++++++++++++++++++++++++++++++------------
>  5 files changed, 83 insertions(+), 36 deletions(-)
> 
> diff --git a/src/evdev-mt-touchpad-tap.c b/src/evdev-mt-touchpad-tap.c
> index 0f1f837..6008507 100644
> --- a/src/evdev-mt-touchpad-tap.c
> +++ b/src/evdev-mt-touchpad-tap.c
> @@ -625,7 +625,8 @@ tp_tap_config_count(struct libinput_device *device)
>  }
>  
>  static enum libinput_config_status
> -tp_tap_config_set_enabled(struct libinput_device *device, int enabled)
> +tp_tap_config_set_enabled(struct libinput_device *device,
> +			  enum libinput_config_tap_state enabled)
>  {
>  	struct evdev_dispatch *dispatch;
>  	struct tp_dispatch *tp;
> @@ -633,12 +634,12 @@ tp_tap_config_set_enabled(struct libinput_device *device, int enabled)
>  	dispatch = ((struct evdev_device *) device)->dispatch;
>  	tp = container_of(dispatch, tp, base);
>  
> -	tp->tap.enabled = enabled;
> +	tp->tap.enabled = (enabled == LIBINPUT_CONFIG_TAP_ENABLED);
>  
>  	return LIBINPUT_CONFIG_STATUS_SUCCESS;
>  }
>  
> -static int
> +static enum libinput_config_tap_state
>  tp_tap_config_is_enabled(struct libinput_device *device)
>  {
>  	struct evdev_dispatch *dispatch;
> @@ -647,10 +648,11 @@ tp_tap_config_is_enabled(struct libinput_device *device)
>  	dispatch = ((struct evdev_device *) device)->dispatch;
>  	tp = container_of(dispatch, tp, base);
>  
> -	return tp->tap.enabled;
> +	return tp->tap.enabled ? LIBINPUT_CONFIG_TAP_ENABLED :
> +				 LIBINPUT_CONFIG_TAP_DISABLED;
>  }
>  
> -static int
> +static enum libinput_config_tap_state
>  tp_tap_config_get_default(struct libinput_device *device)
>  {
>  	/**
> @@ -662,7 +664,7 @@ tp_tap_config_get_default(struct libinput_device *device)
>  	 *   usually know where to enable it, or at least you can search for
>  	 *   it.
>  	 */
> -	return false;
> +	return LIBINPUT_CONFIG_TAP_DISABLED;
>  }
>  
>  int
> diff --git a/src/libinput-private.h b/src/libinput-private.h
> index 23c5140..94a3e07 100644
> --- a/src/libinput-private.h
> +++ b/src/libinput-private.h
> @@ -84,9 +84,9 @@ struct libinput_seat {
>  struct libinput_device_config_tap {
>  	int (*count)(struct libinput_device *device);
>  	enum libinput_config_status (*set_enabled)(struct libinput_device *device,
> -						   int enable);
> -	int (*get_enabled)(struct libinput_device *device);
> -	int (*get_default)(struct libinput_device *device);
> +						   enum libinput_config_tap_state enable);
> +	enum libinput_config_tap_state (*get_enabled)(struct libinput_device *device);
> +	enum libinput_config_tap_state (*get_default)(struct libinput_device *device);
>  };
>  
>  struct libinput_device_config {
> diff --git a/src/libinput.c b/src/libinput.c
> index ff4b01e..a278ce4 100644
> --- a/src/libinput.c
> +++ b/src/libinput.c
> @@ -1284,8 +1284,12 @@ libinput_device_config_tap_get_finger_count(struct libinput_device *device)
>  
>  LIBINPUT_EXPORT enum libinput_config_status
>  libinput_device_config_tap_set_enabled(struct libinput_device *device,
> -				       int enable)
> +				       enum libinput_config_tap_state enable)
>  {
> +	if (enable != LIBINPUT_CONFIG_TAP_ENABLED &&
> +	    enable != LIBINPUT_CONFIG_TAP_DISABLED)
> +		return LIBINPUT_CONFIG_STATUS_INVALID;
> +
>  	if (enable &&
>  	    libinput_device_config_tap_get_finger_count(device) == 0)
>  		return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
> @@ -1293,20 +1297,20 @@ libinput_device_config_tap_set_enabled(struct libinput_device *device,
>  	return device->config.tap->set_enabled(device, enable);
>  }
>  
> -LIBINPUT_EXPORT int
> +LIBINPUT_EXPORT enum libinput_config_tap_state
>  libinput_device_config_tap_get_enabled(struct libinput_device *device)
>  {
>  	if (libinput_device_config_tap_get_finger_count(device) == 0)
> -		return 0;
> +		return LIBINPUT_CONFIG_TAP_DISABLED;
>  
>  	return device->config.tap->get_enabled(device);
>  }
>  
> -LIBINPUT_EXPORT int
> +LIBINPUT_EXPORT enum libinput_config_tap_state
>  libinput_device_config_tap_get_default_enabled(struct libinput_device *device)
>  {
>  	if (libinput_device_config_tap_get_finger_count(device) == 0)
> -		return 0;
> +		return LIBINPUT_CONFIG_TAP_DISABLED;
>  
>  	return device->config.tap->get_default(device);
>  }
> diff --git a/src/libinput.h b/src/libinput.h
> index 7d33f2b..3cd8e7b 100644
> --- a/src/libinput.h
> +++ b/src/libinput.h
> @@ -1443,6 +1443,16 @@ libinput_config_status_to_str(enum libinput_config_status status);
>  
>  /**
>   * @ingroup config
> + */
> +enum libinput_config_tap_state {
> +	LIBINPUT_CONFIG_TAP_DISABLED, /**< Tapping is to be disabled, or is
> +					currently disabled */
> +	LIBINPUT_CONFIG_TAP_ENABLED, /**< Tapping is to be enabled, or is
> +				       currently enabled */
> +};
> +
> +/**
> + * @ingroup config
>   *
>   * Check if the device supports tap-to-click. See
>   * libinput_device_config_tap_set_enabled() for more information.
> @@ -1468,7 +1478,8 @@ libinput_device_config_tap_get_finger_count(struct libinput_device *device);
>   * libinput_device_config_tap_get_finger_count().
>   *
>   * @param device The device to configure
> - * @param enable Non-zero to enable, zero to disable
> + * @param enable @ref LIBINPUT_CONFIG_TAP_ENABLED to enable tapping or @ref
> + * LIBINPUT_CONFIG_TAP_DISABLED to disable tapping
>   *
>   * @return A config status code. Disabling tapping on a device that does not
>   * support tapping always succeeds.
> @@ -1479,7 +1490,7 @@ libinput_device_config_tap_get_finger_count(struct libinput_device *device);
>   */
>  enum libinput_config_status
>  libinput_device_config_tap_set_enabled(struct libinput_device *device,
> -				       int enable);
> +				       enum libinput_config_tap_state enable);
>  
>  /**
>   * @ingroup config
> @@ -1489,13 +1500,14 @@ libinput_device_config_tap_set_enabled(struct libinput_device *device,
>   *
>   * @param device The device to configure
>   *
> - * @return 1 if enabled, 0 otherwise.
> + * @return @ref LIBINPUT_CONFIG_TAP_ENABLED if tapping is currently enabled,
> + * or @ref LIBINPUT_CONFIG_TAP_DISABLED is currently disabled
>   *
>   * @see libinput_device_config_tap_get_finger_count
>   * @see libinput_device_config_tap_set_enabled
>   * @see libinput_device_config_tap_get_default_enabled
>   */
> -int
> +enum libinput_config_tap_state
>  libinput_device_config_tap_get_enabled(struct libinput_device *device);
>  
>  /**
> @@ -1504,13 +1516,14 @@ libinput_device_config_tap_get_enabled(struct libinput_device *device);
>   * Return the default setting for whether tapping is enabled on this device.
>   *
>   * @param device The device to configure
> - * @return 1 if tapping is enabled by default, or 0 otherwise
> + * @return @ref LIBINPUT_CONFIG_TAP_ENABLED if tapping is enabled by default,
> + * or @ref LIBINPUT_CONFIG_TAP_DISABLED is disabled by default
>   *
>   * @see libinput_device_config_tap_get_finger_count
>   * @see libinput_device_config_tap_set_enabled
>   * @see libinput_device_config_tap_get_enabled
>   */
> -int
> +enum libinput_config_tap_state
>  libinput_device_config_tap_get_default_enabled(struct libinput_device *device);
>  
>  #ifdef __cplusplus
> diff --git a/test/touchpad.c b/test/touchpad.c
> index 334a59c..86b2c91 100644
> --- a/test/touchpad.c
> +++ b/test/touchpad.c
> @@ -116,7 +116,8 @@ START_TEST(touchpad_1fg_tap)
>  	struct libinput *li = dev->libinput;
>  	struct libinput_event *event;
>  
> -	libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
> +	libinput_device_config_tap_set_enabled(dev->libinput_device,
> +					       LIBINPUT_CONFIG_TAP_ENABLED);
>  
>  	litest_drain_events(li);
>  
> @@ -143,7 +144,8 @@ START_TEST(touchpad_1fg_tap_n_drag)
>  	struct libinput *li = dev->libinput;
>  	struct libinput_event *event;
>  
> -	libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
> +	libinput_device_config_tap_set_enabled(dev->libinput_device,
> +					       LIBINPUT_CONFIG_TAP_ENABLED);
>  
>  	litest_drain_events(li);
>  
> @@ -195,7 +197,8 @@ START_TEST(touchpad_2fg_tap)
>  	struct litest_device *dev = litest_current_device();
>  	struct libinput *li = dev->libinput;
>  
> -	libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
> +	libinput_device_config_tap_set_enabled(dev->libinput_device,
> +					       LIBINPUT_CONFIG_TAP_ENABLED);
>  
>  	litest_drain_events(dev->libinput);
>  
> @@ -221,7 +224,8 @@ START_TEST(touchpad_2fg_tap_inverted)
>  	struct litest_device *dev = litest_current_device();
>  	struct libinput *li = dev->libinput;
>  
> -	libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
> +	libinput_device_config_tap_set_enabled(dev->libinput_device,
> +					       LIBINPUT_CONFIG_TAP_ENABLED);
>  
>  	litest_drain_events(dev->libinput);
>  
> @@ -247,7 +251,8 @@ START_TEST(touchpad_1fg_tap_click)
>  	struct litest_device *dev = litest_current_device();
>  	struct libinput *li = dev->libinput;
>  
> -	libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
> +	libinput_device_config_tap_set_enabled(dev->libinput_device,
> +					       LIBINPUT_CONFIG_TAP_ENABLED);
>  
>  	litest_drain_events(dev->libinput);
>  
> @@ -276,7 +281,8 @@ START_TEST(touchpad_2fg_tap_click)
>  	struct litest_device *dev = litest_current_device();
>  	struct libinput *li = dev->libinput;
>  
> -	libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
> +	libinput_device_config_tap_set_enabled(dev->libinput_device,
> +					       LIBINPUT_CONFIG_TAP_ENABLED);
>  
>  	litest_drain_events(dev->libinput);
>  
> @@ -307,7 +313,8 @@ START_TEST(touchpad_2fg_tap_click_apple)
>  	struct litest_device *dev = litest_current_device();
>  	struct libinput *li = dev->libinput;
>  
> -	libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
> +	libinput_device_config_tap_set_enabled(dev->libinput_device,
> +					       LIBINPUT_CONFIG_TAP_ENABLED);
>  
>  	litest_drain_events(dev->libinput);
>  
> @@ -415,7 +422,8 @@ START_TEST(touchpad_1fg_double_tap_click)
>  	struct litest_device *dev = litest_current_device();
>  	struct libinput *li = dev->libinput;
>  
> -	libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
> +	libinput_device_config_tap_set_enabled(dev->libinput_device,
> +					       LIBINPUT_CONFIG_TAP_ENABLED);
>  
>  	litest_drain_events(dev->libinput);
>  
> @@ -451,7 +459,8 @@ START_TEST(touchpad_1fg_tap_n_drag_click)
>  	struct libinput *li = dev->libinput;
>  	struct libinput_event *event;
>  
> -	libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
> +	libinput_device_config_tap_set_enabled(dev->libinput_device,
> +					       LIBINPUT_CONFIG_TAP_ENABLED);
>  
>  	litest_drain_events(dev->libinput);
>  
> @@ -503,7 +512,8 @@ START_TEST(touchpad_3fg_tap)
>  	struct libinput_event *event;
>  	int i;
>  
> -	libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
> +	libinput_device_config_tap_set_enabled(dev->libinput_device,
> +					       LIBINPUT_CONFIG_TAP_ENABLED);
>  
>  	for (i = 0; i < 3; i++) {
>  		litest_drain_events(li);
> @@ -798,7 +808,8 @@ START_TEST(clickpad_softbutton_left_tap_n_drag)
>  	struct litest_device *dev = litest_current_device();
>  	struct libinput *li = dev->libinput;
>  
> -	libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
> +	libinput_device_config_tap_set_enabled(dev->libinput_device,
> +					       LIBINPUT_CONFIG_TAP_ENABLED);
>  
>  	litest_drain_events(li);
>  
> @@ -840,7 +851,8 @@ START_TEST(clickpad_softbutton_right_tap_n_drag)
>  	struct litest_device *dev = litest_current_device();
>  	struct libinput *li = dev->libinput;
>  
> -	libinput_device_config_tap_set_enabled(dev->libinput_device, 1);
> +	libinput_device_config_tap_set_enabled(dev->libinput_device,
> +					       LIBINPUT_CONFIG_TAP_ENABLED);
>  
>  	litest_drain_events(li);
>  
> @@ -1323,7 +1335,8 @@ START_TEST(touchpad_tap_is_available)
>  	struct litest_device *dev = litest_current_device();
>  
>  	ck_assert_int_ge(libinput_device_config_tap_get_finger_count(dev->libinput_device), 1);
> -	ck_assert_int_eq(libinput_device_config_tap_get_enabled(dev->libinput_device), 0);
> +	ck_assert_int_eq(libinput_device_config_tap_get_enabled(dev->libinput_device),
> +			 LIBINPUT_CONFIG_TAP_DISABLED);
>  }
>  END_TEST
>  
> @@ -1332,8 +1345,10 @@ START_TEST(touchpad_tap_is_not_available)
>  	struct litest_device *dev = litest_current_device();
>  
>  	ck_assert_int_eq(libinput_device_config_tap_get_finger_count(dev->libinput_device), 0);
> -	ck_assert_int_eq(libinput_device_config_tap_get_enabled(dev->libinput_device), 0);
> -	ck_assert_int_eq(libinput_device_config_tap_set_enabled(dev->libinput_device, 1),
> +	ck_assert_int_eq(libinput_device_config_tap_get_enabled(dev->libinput_device),
> +			 LIBINPUT_CONFIG_TAP_DISABLED);
> +	ck_assert_int_eq(libinput_device_config_tap_set_enabled(dev->libinput_device,
> +								LIBINPUT_CONFIG_TAP_ENABLED),
>  			 LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
>  }
>  END_TEST
> @@ -1342,7 +1357,19 @@ START_TEST(touchpad_tap_default)
>  {
>  	struct litest_device *dev = litest_current_device();
>  
> -	ck_assert_int_eq(libinput_device_config_tap_get_default_enabled(dev->libinput_device), 0);
> +	ck_assert_int_eq(libinput_device_config_tap_get_default_enabled(dev->libinput_device),
> +			 LIBINPUT_CONFIG_TAP_DISABLED);
> +}
> +END_TEST
> +
> +START_TEST(touchpad_tap_invalid)
> +{
> +	struct litest_device *dev = litest_current_device();
> +
> +	ck_assert_int_eq(libinput_device_config_tap_set_enabled(dev->libinput_device, 2),
> +			 LIBINPUT_CONFIG_STATUS_INVALID);
> +	ck_assert_int_eq(libinput_device_config_tap_set_enabled(dev->libinput_device, -1),
> +			 LIBINPUT_CONFIG_STATUS_INVALID);
>  }
>  END_TEST
>  
> @@ -1544,6 +1571,7 @@ int main(int argc, char **argv) {
>  	litest_add("touchpad:tap", touchpad_1fg_tap_n_drag_click, LITEST_CLICKPAD, LITEST_ANY);
>  
>  	litest_add("touchpad:tap", touchpad_tap_default, LITEST_TOUCHPAD, LITEST_ANY);
> +	litest_add("touchpad:tap", touchpad_tap_invalid, LITEST_TOUCHPAD, LITEST_ANY);
>  	litest_add("touchpad:tap", touchpad_tap_is_available, LITEST_TOUCHPAD, LITEST_ANY);
>  	litest_add("touchpad:tap", touchpad_tap_is_not_available, LITEST_ANY, LITEST_TOUCHPAD);
>  
> 


More information about the wayland-devel mailing list