Add a config interface for enabling/disabling event generation from a device
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 30 Jan 2014 06:18:55 +0000 (16:18 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 18 Sep 2014 01:31:14 +0000 (11:31 +1000)
Rather than adding a config interface to disable a device merely allow a
caller to toggle the "send events" mode on the device. If off, the device
won't send events (though further events may be received depending on the
current state of the device).
Default is enabled, i.e. the device sends events.

A special mode is added to the obvious enable/disable: disable the device when
an external mouse is connected. Once set, the device will be enabled when no
mouse is present and stop sending events otherwise. This isn't hooked up to
anything yet though.

Built into the config API is the default option of "enabled". Any device
supports this, for the obvious reason. Disabling or conditionally disabling is
left to the implementation.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
src/libinput-private.h
src/libinput.c
src/libinput.h

index cb90a15..cf03c03 100644 (file)
@@ -101,9 +101,18 @@ struct libinput_device_config_calibration {
                                                          float matrix[6]);
 };
 
+struct libinput_device_config_send_events {
+       uint32_t (*get_modes)(struct libinput_device *device);
+       enum libinput_config_status (*set_mode)(struct libinput_device *device,
+                                                  enum libinput_config_send_events_mode mode);
+       enum libinput_config_send_events_mode (*get_mode)(struct libinput_device *device);
+       enum libinput_config_send_events_mode (*get_default_mode)(struct libinput_device *device);
+};
+
 struct libinput_device_config {
        struct libinput_device_config_tap *tap;
        struct libinput_device_config_calibration *calibration;
+       struct libinput_device_config_send_events *sendevents;
 };
 
 struct libinput_device {
index 20aa1cb..14f0257 100644 (file)
@@ -1349,3 +1349,42 @@ libinput_device_config_calibration_get_default_matrix(struct libinput_device *de
 
        return device->config.calibration->get_default_matrix(device, matrix);
 }
+
+LIBINPUT_EXPORT uint32_t
+libinput_device_config_send_events_get_modes(struct libinput_device *device)
+{
+       uint32_t modes = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
+
+       if (device->config.sendevents)
+               modes |= device->config.sendevents->get_modes(device);
+
+       return modes;
+}
+
+LIBINPUT_EXPORT enum libinput_config_status
+libinput_device_config_send_events_set_mode(struct libinput_device *device,
+                                           enum libinput_config_send_events_mode mode)
+{
+       if ((libinput_device_config_send_events_get_modes(device) & mode) == 0)
+               return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
+
+       if (device->config.sendevents)
+               return device->config.sendevents->set_mode(device, mode);
+       else /* mode must be _ENABLED to get here */
+               return LIBINPUT_CONFIG_STATUS_SUCCESS;
+}
+
+LIBINPUT_EXPORT enum libinput_config_send_events_mode
+libinput_device_config_send_events_get_mode(struct libinput_device *device)
+{
+       if (device->config.sendevents)
+               return device->config.sendevents->get_mode(device);
+       else
+               return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
+}
+
+LIBINPUT_EXPORT enum libinput_config_send_events_mode
+libinput_device_config_send_events_get_default_mode(struct libinput_device *device)
+{
+       return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
+}
index a8a19c5..806e1ab 100644 (file)
@@ -1683,6 +1683,106 @@ int
 libinput_device_config_calibration_get_default_matrix(struct libinput_device *device,
                                                      float matrix[6]);
 
+/**
+ * The send-event mode of a device defines when a device may generate events
+ * and pass those events to the caller.
+ */
+enum libinput_config_send_events_mode {
+       /**
+        * Send events from this device normally.
+        */
+       LIBINPUT_CONFIG_SEND_EVENTS_ENABLED = (1 << 0),
+       /**
+        * Do not send events through this device. Depending on the device,
+        * this may close all file descriptors on the device or it may leave
+        * the file descriptors open and route events through a different
+        * device.
+        */
+       LIBINPUT_CONFIG_SEND_EVENTS_DISABLED = (1 << 1),
+       /**
+        * If an external pointer device is plugged in, do not send events
+        * from this device. This option may be available on built-in
+        * touchpads.
+        */
+       LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE = (1 << 2),
+};
+
+/**
+ * @ingroup config
+ *
+ * Return the possible send-event modes for this device. These modes define
+ * when a device may process and send events.
+ *
+ * @param device The device to configure
+ *
+ * @return A bitmask of possible modes.
+ *
+ * @see libinput_device_config_send_events_set_mode
+ * @see libinput_device_config_send_events_get_mode
+ * @see libinput_device_config_send_events_get_default_mode
+ */
+uint32_t
+libinput_device_config_send_events_get_modes(struct libinput_device *device);
+
+/**
+ * Set the send-event mode for this device. The mode defines when the device
+ * processes and sends events to the caller.
+ *
+ * The selected mode may not take effect immediately. Events already
+ * received and processed from this device are unaffected and will be passed
+ * to the caller on the next call to libinput_get_event().
+ *
+ * If the mode is one of @ref LIBINPUT_CONFIG_SEND_EVENTS_DISABLED or
+ * @ref LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE, the device
+ * may wait for or generate events until it is in a neutral state.
+ * For example, this may include waiting for or generating button release
+ * events.
+ *
+ * If the device is already suspended, this function does nothing and
+ * returns success. Changing the send-event mode on a device that has been
+ * removed is permitted.
+ *
+ * @param device The device to configure
+ * @param mode The send-event mode for this device.
+ *
+ * @return A config status code.
+ *
+ * @see libinput_device_config_send_events_get_modes
+ * @see libinput_device_config_send_events_get_mode
+ * @see libinput_device_config_send_events_get_default_mode
+ */
+enum libinput_config_status
+libinput_device_config_send_events_set_mode(struct libinput_device *device,
+                                           enum libinput_config_send_events_mode mode);
+
+/**
+ * Get the send-event mode for this device. The mode defines when the device
+ * processes and sends events to the caller.
+ *
+ * @param device The device to configure
+ * @return The current send-event mode for this device.
+ *
+ * @see libinput_device_config_send_events_get_modes
+ * @see libinput_device_config_send_events_set_mode
+ * @see libinput_device_config_send_events_get_default_mode
+ */
+enum libinput_config_send_events_mode
+libinput_device_config_send_events_get_mode(struct libinput_device *device);
+
+/**
+ * Get the default send-event mode for this device. The mode defines when
+ * the device processes and sends events to the caller.
+ *
+ * @param device The device to configure
+ * @return The current send-event mode for this device.
+ *
+ * @see libinput_device_config_send_events_get_modes
+ * @see libinput_device_config_send_events_set_mode
+ * @see libinput_device_config_send_events_get_default_mode
+ */
+enum libinput_config_send_events_mode
+libinput_device_config_send_events_get_default_mode(struct libinput_device *device);
+
 #ifdef __cplusplus
 }
 #endif