Add an interface to enable/disable tapping
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 7 Jan 2014 01:42:32 +0000 (11:42 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 3 Jul 2014 03:48:44 +0000 (13:48 +1000)
Provide an interface to enable/disable tapping, with a default mapping of
1/2/3 fingers mapping to L/R/M button events, respectively.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Jonas Ã…dahl <jadahl@gmail.com>
src/libinput-private.h
src/libinput.c
src/libinput.h

index 00901b4d1a7f79bbce0a939d2c7aab69f1be8b14..23c514050de0ab9afb9d311ff6b9ed53aa8d70c1 100644 (file)
@@ -81,12 +81,25 @@ struct libinput_seat {
        uint32_t button_count[KEY_CNT];
 };
 
+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);
+};
+
+struct libinput_device_config {
+       struct libinput_device_config_tap *tap;
+};
+
 struct libinput_device {
        struct libinput_seat *seat;
        struct list link;
        void *user_data;
        int terminated;
        int refcount;
+       struct libinput_device_config config;
 };
 
 typedef void (*libinput_source_dispatch_t)(void *data);
index 6ea9e485f9b22a127005c9eb7154cb5876a8a262..ff4b01e13551d0abb82288947e5eef8a27aa2d2f 100644 (file)
@@ -1275,3 +1275,38 @@ libinput_config_status_to_str(enum libinput_config_status status)
 
        return str;
 }
+
+LIBINPUT_EXPORT int
+libinput_device_config_tap_get_finger_count(struct libinput_device *device)
+{
+       return device->config.tap ? device->config.tap->count(device) : 0;
+}
+
+LIBINPUT_EXPORT enum libinput_config_status
+libinput_device_config_tap_set_enabled(struct libinput_device *device,
+                                      int enable)
+{
+       if (enable &&
+           libinput_device_config_tap_get_finger_count(device) == 0)
+               return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
+
+       return device->config.tap->set_enabled(device, enable);
+}
+
+LIBINPUT_EXPORT int
+libinput_device_config_tap_get_enabled(struct libinput_device *device)
+{
+       if (libinput_device_config_tap_get_finger_count(device) == 0)
+               return 0;
+
+       return device->config.tap->get_enabled(device);
+}
+
+LIBINPUT_EXPORT int
+libinput_device_config_tap_get_default_enabled(struct libinput_device *device)
+{
+       if (libinput_device_config_tap_get_finger_count(device) == 0)
+               return 0;
+
+       return device->config.tap->get_default(device);
+}
index ead30646d379dacbffdcbc4efbdadadcb7486be3..0d4b79cbeba508aeaafcb99dccec97f6a7e66ce4 100644 (file)
@@ -1436,8 +1436,79 @@ enum libinput_config_status {
 const char *
 libinput_config_status_to_str(enum libinput_config_status status);
 
+/**
+ * @ingroup config
+ *
+ * Check if the device supports tap-to-click. See
+ * libinput_device_config_tap_set_enabled() for more information.
+ *
+ * @param device The device to configure
+ * @return The number of fingers that can generate a tap event, or 0 if the
+ * device does not support tapping.
+ *
+ * @see libinput_device_config_tap_set_enabled
+ * @see libinput_device_config_tap_get_enabled
+ * @see libinput_device_config_tap_set_enabled_get_default
+ */
+int
+libinput_device_config_tap_get_finger_count(struct libinput_device *device);
+
+/**
+ * @ingroup config
+ *
+ * Enable or disable tap-to-click on this device, with a default mapping of
+ * 1, 2, 3 finger tap mapping to left, right, middle click, respectively.
+ * Tapping is limited by the number of simultaneous touches
+ * supported by the device, see
+ * libinput_device_config_tap_get_finger_count().
+ *
+ * @param device The device to configure
+ * @param enable Non-zero to enable, zero to disable
+ *
+ * @return A config status code. Disabling tapping on a device that does not
+ * support tapping always succeeds.
+ *
+ * @see libinput_device_config_tap_get_finger_count
+ * @see libinput_device_config_tap_get_enabled
+ * @see libinput_device_config_tap_get_default_enabled
+ */
+enum libinput_config_status
+libinput_device_config_tap_set_enabled(struct libinput_device *device,
+                                      int enable);
+
+/**
+ * @ingroup config
+ *
+ * Check if tap-to-click is enabled on this device. If the device does not
+ * support tapping, this function always returns 0.
+ *
+ * @param device The device to configure
+ *
+ * @return 1 if enabled, 0 otherwise.
+ *
+ * @see libinput_device_config_tap_get_finger_count
+ * @see libinput_device_config_tap_set_enabled
+ * @see libinput_device_config_tap_get_default_enabled
+ */
+int
+libinput_device_config_tap_get_enabled(struct libinput_device *device);
+
+/**
+ * @ingroup config
+ *
+ * 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
+ *
+ * @see libinput_device_config_tap_get_finger_count
+ * @see libinput_device_config_tap_set_enabled
+ * @see libinput_device_config_tap_get_enabled
+ */
+int
+libinput_device_config_tap_get_default_enabled(struct libinput_device *device);
+
 #ifdef __cplusplus
 }
 #endif
-
 #endif /* LIBINPUT_H */