diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2016-07-21 11:46:05 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2016-08-15 09:05:57 +1000 |
commit | 59fac8e90269af863231752dc5897f11146f6e05 (patch) | |
tree | 09bfe5e560cd615e3d53b6b64febbac4a4696440 | |
parent | a1863b6db801fb50d11e7c1ddff93c9a09ab661f (diff) |
Add configurable button map to tappings
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@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r-- | src/evdev-mt-touchpad-tap.c | 22 | ||||
-rw-r--r-- | src/libinput-private.h | 5 | ||||
-rw-r--r-- | src/libinput.c | 36 | ||||
-rw-r--r-- | src/libinput.h | 82 | ||||
-rw-r--r-- | src/libinput.sym | 6 | ||||
-rw-r--r-- | tools/shared.c | 21 | ||||
-rw-r--r-- | tools/shared.h | 1 |
7 files changed, 173 insertions, 0 deletions
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 62576b5..479da75 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -164,6 +164,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 397c6f6..18a96bd 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; |