From c8ec33e72a5146b60485e72264d496aba3299752 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 3 Dec 2014 14:45:26 +1000 Subject: [PATCH] Add a config interface for click methods Two methods are provided: * button area - used on most clickpads, a click with a touch within a given area generates left/middle/right clicks * clickfinger - used on apple touchpads, a click with 1/2/3 fingers on the touchpad generates a left, right, middle click Both methods already exist in the touchpad code, this is just the configuration interface. Signed-off-by: Peter Hutterer --- src/libinput-private.h | 9 +++++ src/libinput.c | 50 ++++++++++++++++++++++++ src/libinput.h | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ src/libinput.sym | 4 ++ 4 files changed, 165 insertions(+) diff --git a/src/libinput-private.h b/src/libinput-private.h index 012c82d..b938ed0 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -146,6 +146,14 @@ struct libinput_device_config_scroll_method { uint32_t (*get_default_button)(struct libinput_device *device); }; +struct libinput_device_config_click_method { + uint32_t (*get_methods)(struct libinput_device *device); + enum libinput_config_status (*set_method)(struct libinput_device *device, + enum libinput_config_click_method method); + enum libinput_config_click_method (*get_method)(struct libinput_device *device); + enum libinput_config_click_method (*get_default_method)(struct libinput_device *device); +}; + struct libinput_device_config { struct libinput_device_config_tap *tap; struct libinput_device_config_calibration *calibration; @@ -154,6 +162,7 @@ struct libinput_device_config { struct libinput_device_config_natural_scroll *natural_scroll; struct libinput_device_config_left_handed *left_handed; struct libinput_device_config_scroll_method *scroll_method; + struct libinput_device_config_click_method *click_method; }; struct libinput_device { diff --git a/src/libinput.c b/src/libinput.c index 6f45405..951698a 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1636,6 +1636,56 @@ libinput_device_config_left_handed_get_default(struct libinput_device *device) } LIBINPUT_EXPORT uint32_t +libinput_device_config_click_get_methods(struct libinput_device *device) +{ + if (device->config.click_method) + return device->config.click_method->get_methods(device); + else + return 0; +} + +LIBINPUT_EXPORT enum libinput_config_status +libinput_device_config_click_set_method(struct libinput_device *device, + enum libinput_config_click_method method) +{ + if ((libinput_device_config_click_get_methods(device) & method) != method) + return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; + + /* Check method is a single valid method */ + switch (method) { + case LIBINPUT_CONFIG_CLICK_METHOD_NONE: + case LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS: + case LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER: + break; + default: + return LIBINPUT_CONFIG_STATUS_INVALID; + } + + if (device->config.click_method) + return device->config.click_method->set_method(device, method); + else /* method must be _NONE to get here */ + return LIBINPUT_CONFIG_STATUS_SUCCESS; +} + +LIBINPUT_EXPORT enum libinput_config_click_method +libinput_device_config_click_get_method(struct libinput_device *device) +{ + if (device->config.click_method) + return device->config.click_method->get_method(device); + else + return LIBINPUT_CONFIG_CLICK_METHOD_NONE; +} + +LIBINPUT_EXPORT enum libinput_config_click_method +libinput_device_config_click_get_default_method(struct libinput_device *device) +{ + if (device->config.click_method) + return device->config.click_method->get_default_method(device); + else + return LIBINPUT_CONFIG_CLICK_METHOD_NONE; +} + +LIBINPUT_EXPORT uint32_t libinput_device_config_scroll_get_methods(struct libinput_device *device) { if (device->config.scroll_method) diff --git a/src/libinput.h b/src/libinput.h index dbc4b2e..7b7a2db 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -2179,6 +2179,108 @@ libinput_device_config_left_handed_get_default(struct libinput_device *device); /** * @ingroup config * + * The click method defines when to generate software-emulated + * buttons, usually on a device that does not have a specific physical + * button available. + */ +enum libinput_config_click_method { + /** + * Do not send software-emulated button events. This has no effect + * on physical button generations. + */ + LIBINPUT_CONFIG_CLICK_METHOD_NONE = 0, + /** + * Use software-button areas (see @ref clickfinger) to generate + * button events. + */ + LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS = (1 << 0), + /** + * The number of fingers decides which button press to generate. + */ + LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER = (1 << 1), +}; + +/** + * @ingroup config + * + * Check which button click methods a device supports. The button click + * method defines when to generate software-emulated buttons, usually on a + * device that does not have a specific physical button available. + * + * @param device The device to configure + * + * @return A bitmask of possible methods. + * + * @see libinput_device_config_click_get_methods + * @see libinput_device_config_click_set_method + * @see libinput_device_config_click_get_method + */ +uint32_t +libinput_device_config_click_get_methods(struct libinput_device *device); + +/** + * @ingroup config + * + * Set the button click method for this device. The button click + * method defines when to generate software-emulated buttons, usually on a + * device that does not have a specific physical button available. + * + * @note The selected click method may not take effect immediately. The + * device may require changing to a neutral state first before activating + * the new method. + * + * @param device The device to configure + * @param method The button click method + * + * @return A config status code + * + * @see libinput_device_config_click_get_methods + * @see libinput_device_config_click_get_method + * @see libinput_device_config_click_get_default_method + */ +enum libinput_config_status +libinput_device_config_click_set_method(struct libinput_device *device, + enum libinput_config_click_method method); +/** + * @ingroup config + * + * Get the button click method for this device. The button click + * method defines when to generate software-emulated buttons, usually on a + * device that does not have a specific physical button available. + * + * @param device The device to configure + * + * @return The current button click method for this device + * + * @see libinput_device_config_click_get_methods + * @see libinput_device_config_click_set_method + * @see libinput_device_config_click_get_default_method + */ +enum libinput_config_click_method +libinput_device_config_click_get_method(struct libinput_device *device); + +/** + * @ingroup config + * + * Get the default button click method for this device. The button click + * method defines when to generate software-emulated buttons, usually on a + * device that does not have a specific physical button available. + * + * @param device The device to configure + * + * @return The default button click method for this device + * + * @see libinput_device_config_click_get_methods + * @see libinput_device_config_click_set_method + * @see libinput_device_config_click_get_method + */ +enum libinput_config_click_method +libinput_device_config_click_get_default_method(struct libinput_device *device); + + +/** + * @ingroup config + * * The scroll method of a device selects when to generate scroll axis events * instead of pointer motion events. */ diff --git a/src/libinput.sym b/src/libinput.sym index 018578d..9be6cf4 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -15,6 +15,10 @@ global: libinput_device_config_calibration_get_matrix; libinput_device_config_calibration_has_matrix; libinput_device_config_calibration_set_matrix; + libinput_device_config_click_get_default_method; + libinput_device_config_click_get_method; + libinput_device_config_click_get_methods; + libinput_device_config_click_set_method; libinput_device_config_scroll_get_button; libinput_device_config_scroll_get_default_button; libinput_device_config_scroll_get_default_method; -- 2.7.4