[PATCH libinput 1/3] Add configurable button map to tappings
Hans de Goede
hdegoede at redhat.com
Fri Aug 12 12:40:32 UTC 2016
Hi,
On 22-07-16 04:46, Peter Hutterer wrote:
> The previously hardcoded button map for tapping is 1/2/3 to LRM. But the
> middle button is a common feature on the desktop (used for paste, most
> prominently) and three-finger tapping is almost impossible to do reliably on
> some touchpads (e.g. the T440 has a recognition rate of ~1 in 5).
>
> Left and right buttons have a prominent physical position (either softbuttons
> or physical buttons) so make the tap order configurable. Those that require
> middle buttons reliably can use the [software] buttons for left/right and
> 2-finger tap for a middle button.
>
> https://bugs.freedesktop.org/show_bug.cgi?id=96962
>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
Series looks good to me:
Reviewed-by: Hans de Goede <hdegoede at redhat.com>
Regards,
Hans
> ---
> src/evdev-mt-touchpad-tap.c | 22 ++++++++++++
> src/libinput-private.h | 5 +++
> src/libinput.c | 36 ++++++++++++++++++++
> src/libinput.h | 82 +++++++++++++++++++++++++++++++++++++++++++++
> src/libinput.sym | 6 ++++
> tools/shared.c | 21 ++++++++++++
> tools/shared.h | 1 +
> 7 files changed, 173 insertions(+)
>
> diff --git a/src/evdev-mt-touchpad-tap.c b/src/evdev-mt-touchpad-tap.c
> index c2b331c..3ca4f95 100644
> --- a/src/evdev-mt-touchpad-tap.c
> +++ b/src/evdev-mt-touchpad-tap.c
> @@ -935,6 +935,25 @@ tp_tap_config_get_default(struct libinput_device *device)
> }
>
> static enum libinput_config_status
> +tp_tap_config_set_map(struct libinput_device *device,
> + enum libinput_config_tap_button_map map)
> +{
> + return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
> +}
> +
> +static enum libinput_config_tap_button_map
> +tp_tap_config_get_map(struct libinput_device *device)
> +{
> + return LIBINPUT_CONFIG_TAP_MAP_LRM;
> +}
> +
> +static enum libinput_config_tap_button_map
> +tp_tap_config_get_default_map(struct libinput_device *device)
> +{
> + return LIBINPUT_CONFIG_TAP_MAP_LRM;
> +}
> +
> +static enum libinput_config_status
> tp_tap_config_set_drag_enabled(struct libinput_device *device,
> enum libinput_config_drag_state enabled)
> {
> @@ -1017,6 +1036,9 @@ tp_init_tap(struct tp_dispatch *tp)
> tp->tap.config.set_enabled = tp_tap_config_set_enabled;
> tp->tap.config.get_enabled = tp_tap_config_is_enabled;
> tp->tap.config.get_default = tp_tap_config_get_default;
> + tp->tap.config.set_map = tp_tap_config_set_map;
> + tp->tap.config.get_map = tp_tap_config_get_map;
> + tp->tap.config.get_default_map = tp_tap_config_get_default_map;
> tp->tap.config.set_drag_enabled = tp_tap_config_set_drag_enabled;
> tp->tap.config.get_drag_enabled = tp_tap_config_get_drag_enabled;
> tp->tap.config.get_default_drag_enabled = tp_tap_config_get_default_drag_enabled;
> diff --git a/src/libinput-private.h b/src/libinput-private.h
> index 472f6f3..1f27af6 100644
> --- a/src/libinput-private.h
> +++ b/src/libinput-private.h
> @@ -158,6 +158,11 @@ struct libinput_device_config_tap {
> enum libinput_config_tap_state (*get_enabled)(struct libinput_device *device);
> enum libinput_config_tap_state (*get_default)(struct libinput_device *device);
>
> + enum libinput_config_status (*set_map)(struct libinput_device *device,
> + enum libinput_config_tap_button_map map);
> + enum libinput_config_tap_button_map (*get_map)(struct libinput_device *device);
> + enum libinput_config_tap_button_map (*get_default_map)(struct libinput_device *device);
> +
> enum libinput_config_status (*set_drag_enabled)(struct libinput_device *device,
> enum libinput_config_drag_state);
> enum libinput_config_drag_state (*get_drag_enabled)(struct libinput_device *device);
> diff --git a/src/libinput.c b/src/libinput.c
> index a8240bd..6958042 100644
> --- a/src/libinput.c
> +++ b/src/libinput.c
> @@ -3352,6 +3352,42 @@ libinput_device_config_tap_get_default_enabled(struct libinput_device *device)
> }
>
> LIBINPUT_EXPORT enum libinput_config_status
> +libinput_device_config_tap_set_button_map(struct libinput_device *device,
> + enum libinput_config_tap_button_map map)
> +{
> + switch (map) {
> + case LIBINPUT_CONFIG_TAP_MAP_LRM:
> + case LIBINPUT_CONFIG_TAP_MAP_LMR:
> + break;
> + default:
> + return LIBINPUT_CONFIG_STATUS_INVALID;
> + }
> +
> + if (libinput_device_config_tap_get_finger_count(device) == 0)
> + return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
> +
> + return device->config.tap->set_map(device, map);
> +}
> +
> +LIBINPUT_EXPORT enum libinput_config_tap_button_map
> +libinput_device_config_tap_get_button_map(struct libinput_device *device)
> +{
> + if (libinput_device_config_tap_get_finger_count(device) == 0)
> + return LIBINPUT_CONFIG_TAP_MAP_LRM;
> +
> + return device->config.tap->get_map(device);
> +}
> +
> +LIBINPUT_EXPORT enum libinput_config_tap_button_map
> +libinput_device_config_tap_get_default_button_map(struct libinput_device *device)
> +{
> + if (libinput_device_config_tap_get_finger_count(device) == 0)
> + return LIBINPUT_CONFIG_TAP_MAP_LRM;
> +
> + return device->config.tap->get_default_map(device);
> +}
> +
> +LIBINPUT_EXPORT enum libinput_config_status
> libinput_device_config_tap_set_drag_enabled(struct libinput_device *device,
> enum libinput_config_drag_state enable)
> {
> diff --git a/src/libinput.h b/src/libinput.h
> index 83e58b6..2bf1d33 100644
> --- a/src/libinput.h
> +++ b/src/libinput.h
> @@ -3773,6 +3773,88 @@ libinput_device_config_tap_get_default_enabled(struct libinput_device *device);
>
> /**
> * @ingroup config
> + */
> +enum libinput_config_tap_button_map {
> + /** 1/2/3 finger tap maps to left/right/middle */
> + LIBINPUT_CONFIG_TAP_MAP_LRM,
> + /** 1/2/3 finger tap maps to left/middle/right*/
> + LIBINPUT_CONFIG_TAP_MAP_LMR,
> +};
> +
> +/**
> + * @ingroup config
> + *
> + * Set the finger number to button number mapping for tap-to-click. The
> + * default mapping on most devices is to have a 1, 2 and 3 finger tap to map
> + * to the left, right and middle button, respectively.
> + * A device may permit changing the button mapping but disallow specific
> + * maps. In this case @ref LIBINPUT_CONFIG_STATUS_UNSUPPORTED is returned,
> + * the caller is expected to handle this case correctly.
> + *
> + * Changing the button mapping may not take effect immediately,
> + * the device may wait until it is in a neutral state before applying any
> + * changes.
> + *
> + * The mapping may be changed when tap-to-click is disabled. The new mapping
> + * takes effect when tap-to-click is enabled in the future.
> + *
> + * @note It is an application bug to call this function for devices where
> + * libinput_device_config_tap_get_finger_count() returns 0.
> + *
> + * @param device The device to configure
> + * @param map The new finger-to-button number mapping
> + * @return A config status code. Changing the order on a device that does not
> + * support tapping always fails with @ref LIBINPUT_CONFIG_STATUS_UNSUPPORTED.
> + *
> + * @see libinput_device_config_tap_get_button_map
> + * @see libinput_device_config_tap_get_default_button_map
> + */
> +enum libinput_config_status
> +libinput_device_config_tap_set_button_map(struct libinput_device *device,
> + enum libinput_config_tap_button_map map);
> +
> +/**
> + * @ingroup config
> + *
> + * Get the finger number to button number mapping for tap-to-click.
> + *
> + * The return value for a device that does not support tapping is always
> + * @ref LIBINPUT_CONFIG_TAP_MAP_LRM.
> + *
> + * @note It is an application bug to call this function for devices where
> + * libinput_device_config_tap_get_finger_count() returns 0.
> + *
> + * @param device The device to configure
> + * @return The current finger-to-button number mapping
> + *
> + * @see libinput_device_config_tap_set_button_map
> + * @see libinput_device_config_tap_get_default_button_map
> + */
> +enum libinput_config_tap_button_map
> +libinput_device_config_tap_get_button_map(struct libinput_device *device);
> +
> +/**
> + * @ingroup config
> + *
> + * Get the default finger number to button number mapping for tap-to-click.
> + *
> + * The return value for a device that does not support tapping is always
> + * @ref LIBINPUT_CONFIG_TAP_MAP_LRM.
> + *
> + * @note It is an application bug to call this function for devices where
> + * libinput_device_config_tap_get_finger_count() returns 0.
> + *
> + * @param device The device to configure
> + * @return The current finger-to-button number mapping
> + *
> + * @see libinput_device_config_tap_set_button_map
> + * @see libinput_device_config_tap_get_default_button_map
> + */
> +enum libinput_config_tap_button_map
> +libinput_device_config_tap_get_default_button_map(struct libinput_device *device);
> +
> +/**
> + * @ingroup config
> *
> * A config status to distinguish or set dragging on a device. Currently
> * implemented for tap-and-drag only, see
> diff --git a/src/libinput.sym b/src/libinput.sym
> index cb3f2b8..97bb57f 100644
> --- a/src/libinput.sym
> +++ b/src/libinput.sym
> @@ -274,3 +274,9 @@ LIBINPUT_1.4 {
> libinput_tablet_pad_mode_group_set_user_data;
> libinput_tablet_pad_mode_group_unref;
> } LIBINPUT_1.3;
> +
> +LIBINPUT_1.5 {
> + libinput_device_config_tap_get_button_map;
> + libinput_device_config_tap_get_default_button_map;
> + libinput_device_config_tap_set_button_map;
> +} LIBINPUT_1.4;
> diff --git a/tools/shared.c b/tools/shared.c
> index 29af9ef..95655ba 100644
> --- a/tools/shared.c
> +++ b/tools/shared.c
> @@ -45,6 +45,7 @@ enum options {
> OPT_VERBOSE,
> OPT_TAP_ENABLE,
> OPT_TAP_DISABLE,
> + OPT_TAP_MAP,
> OPT_DRAG_ENABLE,
> OPT_DRAG_DISABLE,
> OPT_DRAG_LOCK_ENABLE,
> @@ -101,6 +102,7 @@ tools_usage()
> "--set-scroll-button=BTN_MIDDLE ... set the button to the given button code\n"
> "--set-profile=[adaptive|flat].... set pointer acceleration profile\n"
> "--set-speed=<value>.... set pointer acceleration speed\n"
> + "--set-tap-map=[lrm|lmr] ... set button mapping for tapping\n"
> "\n"
> "These options apply to all applicable devices, if a feature\n"
> "is not explicitly specified it is left at each device's default.\n"
> @@ -121,6 +123,7 @@ tools_init_context(struct tools_context *context)
>
> memset(options, 0, sizeof(*options));
> options->tapping = -1;
> + options->tap_map = -1;
> options->drag = -1;
> options->drag_lock = -1;
> options->natural_scroll = -1;
> @@ -168,6 +171,7 @@ tools_parse_args(int argc, char **argv, struct tools_context *context)
> { "set-scroll-method", 1, 0, OPT_SCROLL_METHOD },
> { "set-scroll-button", 1, 0, OPT_SCROLL_BUTTON },
> { "set-profile", 1, 0, OPT_PROFILE },
> + { "set-tap-map", 1, 0, OPT_TAP_MAP },
> { "speed", 1, 0, OPT_SPEED },
> { 0, 0, 0, 0}
> };
> @@ -206,6 +210,20 @@ tools_parse_args(int argc, char **argv, struct tools_context *context)
> case OPT_TAP_DISABLE:
> options->tapping = 0;
> break;
> + case OPT_TAP_MAP:
> + if (!optarg) {
> + tools_usage();
> + return 1;
> + }
> + if (streq(optarg, "lrm")) {
> + options->tap_map = LIBINPUT_CONFIG_TAP_MAP_LRM;
> + } else if (streq(optarg, "lmr")) {
> + options->tap_map = LIBINPUT_CONFIG_TAP_MAP_LMR;
> + } else {
> + tools_usage();
> + return 1;
> + }
> + break;
> case OPT_DRAG_ENABLE:
> options->drag = 1;
> break;
> @@ -451,6 +469,9 @@ tools_device_apply_config(struct libinput_device *device,
> {
> if (options->tapping != -1)
> libinput_device_config_tap_set_enabled(device, options->tapping);
> + if (options->tap_map != -1)
> + libinput_device_config_tap_set_button_map(device,
> + options->tap_map);
> if (options->drag != -1)
> libinput_device_config_tap_set_drag_enabled(device,
> options->drag);
> diff --git a/tools/shared.h b/tools/shared.h
> index 14ed9cc..c0bb103 100644
> --- a/tools/shared.h
> +++ b/tools/shared.h
> @@ -46,6 +46,7 @@ struct tools_options {
> int middlebutton;
> enum libinput_config_click_method click_method;
> enum libinput_config_scroll_method scroll_method;
> + enum libinput_config_tap_button_map tap_map;
> int scroll_button;
> double speed;
> int dwt;
>
More information about the wayland-devel
mailing list