[PATCH libinput 1/5] Add a config interface for click methods

Peter Hutterer peter.hutterer at who-t.net
Tue Dec 9 20:15:11 PST 2014


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 <peter.hutterer at who-t.net>
---
I fully admit, I'm not happy with the naming but I can't come up with
something nicer.

 src/libinput-private.h |   9 +++++
 src/libinput.c         |  50 ++++++++++++++++++++++++
 src/libinput.h         | 102 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 161 insertions(+)

diff --git a/src/libinput-private.h b/src/libinput-private.h
index b36dc95..dce0e78 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 279cce0..d917cb4 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -1584,6 +1584,56 @@ libinput_device_config_buttons_get_default_left_handed(struct libinput_device *d
 }
 
 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 57d9ded..0f0b01f 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -2212,6 +2212,108 @@ libinput_device_config_buttons_get_default_left_handed(struct libinput_device *d
 /**
  * @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 tpbuttons) 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.
  */
-- 
2.1.0



More information about the wayland-devel mailing list