[PATCH libinput 10/10] Add config api for middle button emulation

Peter Hutterer peter.hutterer at who-t.net
Mon Jun 2 22:35:03 PDT 2014


---
 src/libinput-private.h |  8 ++++++++
 src/libinput.c         | 33 ++++++++++++++++++++++++++++++
 src/libinput.h         | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+)

diff --git a/src/libinput-private.h b/src/libinput-private.h
index 22220de..28f071a 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -120,6 +120,13 @@ struct libinput_device_config_pointer_mode {
 	void (*reset)(struct libinput_device *device);
 };
 
+struct libinput_device_config_middlebutton_emulation {
+	int (*available)(struct libinput_device *device);
+	int (*enable)(struct libinput_device *device, int enable);
+	int (*is_enabled)(struct libinput_device *device);
+	void (*reset)(struct libinput_device *device);
+};
+
 struct libinput_device_config {
 	struct libinput_device_config_tap *tap;
 	struct libinput_device_config_scroll *scroll;
@@ -127,6 +134,7 @@ struct libinput_device_config {
 	struct libinput_device_config_accel *accel;
 	struct libinput_device_config_disable_while_typing *dwt;
 	struct libinput_device_config_pointer_mode *mode;
+	struct libinput_device_config_middlebutton_emulation *mbemu;
 };
 
 struct libinput_device {
diff --git a/src/libinput.c b/src/libinput.c
index 5324407..bd06960 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -1406,3 +1406,36 @@ libinput_device_config_pointer_mode_reset(struct libinput_device *device)
 	if (device->config.mode)
 		device->config.mode->reset(device);
 }
+
+LIBINPUT_EXPORT int
+libinput_device_config_middlebutton_emulation_is_available(struct libinput_device *device)
+{
+	return device->config.mbemu ?
+		device->config.mbemu->available(device) : 0;
+}
+
+LIBINPUT_EXPORT enum libinput_config_status
+libinput_device_config_middlebutton_emulation_enable(struct libinput_device *device,
+						     int enable)
+{
+	if (!libinput_device_config_middlebutton_emulation_is_available(device))
+		return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
+
+	return device->config.mbemu->enable(device, enable);
+}
+
+LIBINPUT_EXPORT int
+libinput_device_config_middlebutton_emulation_is_enabled(struct libinput_device *device)
+{
+	if (!libinput_device_config_middlebutton_emulation_is_available(device))
+		return 0;
+
+	return device->config.mbemu->is_enabled(device);
+}
+
+LIBINPUT_EXPORT void
+libinput_device_config_middlebutton_emulation_reset(struct libinput_device *device)
+{
+	if (device->config.mbemu)
+		device->config.mbemu->reset(device);
+}
diff --git a/src/libinput.h b/src/libinput.h
index 1a51b82..b78283f 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -1789,6 +1789,60 @@ libinput_device_config_pointer_mode_get_mode(struct libinput_device *device);
 void
 libinput_device_config_pointer_mode_reset(struct libinput_device *device);
 
+/**
+ * @ingroup config
+ *
+ * Devices without a physical middle button may provide middle-button
+ * emulation by pressing the left and the right button simultaneously.
+ *
+ * @param device The device to configure
+ *
+ * @return 1 if available, 0 if not available
+ */
+int
+libinput_device_config_middlebutton_emulation_is_available(struct libinput_device *device);
+
+/**
+ * @ingroup config
+ *
+ * Enable or disable middle button emulation on this device. Note that
+ * enabling middle button emulation causes a delay in the delivery of button
+ * events.
+ *
+ * @param device The device to configure
+ * @param enable 1 to enable, 0 to disable
+ *
+ * @return A config status code
+ */
+enum libinput_config_status
+libinput_device_config_middlebutton_emulation_enable(struct libinput_device *device,
+						     int enable);
+
+/**
+ * @ingroup config
+ *
+ * Check if middle button emulation is enabled on this device. If the device
+ * does not support middle button emulation, this function returns 0.
+ *
+ * @param device The device to configure
+ *
+ * @return 0 if disabled, 1 if enabled
+ */
+int
+libinput_device_config_middlebutton_emulation_is_enabled(struct libinput_device *device);
+
+/**
+ * @ingroup config
+ *
+ * Reset to the default emulation status. If the device does not support
+ * middle button emulation, this function does nothing.
+ *
+ * @param device The device to configure
+ *
+ */
+void
+libinput_device_config_middlebutton_emulation_reset(struct libinput_device *device);
+
 
 #ifdef __cplusplus
 }
-- 
1.9.0



More information about the wayland-devel mailing list