[PATCH libinput 10/17] Add a config interface for enabling/disabling event generation from a device
Hans de Goede
hdegoede at redhat.com
Sun Sep 14 03:17:05 PDT 2014
Hi,
First of all patches 1 - 9 look good and are:
Reviewed-by: Hans de Goede <hdegoede at redhat.com>
On 09/03/2014 04:03 AM, Peter Hutterer wrote:
> 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 at who-t.net>
> ---
> src/evdev.c | 25 +++++++++++++
> src/evdev.h | 3 ++
> src/libinput-private.h | 9 +++++
> src/libinput.c | 39 +++++++++++++++++++
> src/libinput.h | 100 +++++++++++++++++++++++++++++++++++++++++++++++++
> 5 files changed, 176 insertions(+)
>
> diff --git a/src/evdev.c b/src/evdev.c
> index 9e91ee5..9d98b58 100644
> --- a/src/evdev.c
> +++ b/src/evdev.c
> @@ -1189,6 +1189,31 @@ evdev_device_suspend(struct evdev_device *device)
> return 0;
> }
>
> +int
> +evdev_device_resume(struct evdev_device *device)
> +{
> + struct libinput *libinput = device->base.seat->libinput;
> + int fd;
> +
> + if (device->fd != -1)
> + return 0;
> +
> + fd = open_restricted(libinput, device->devnode, O_RDWR | O_NONBLOCK);
> +
> + if (fd < 0)
> + return -errno;
> +
> + device->fd = fd;
> + device->source =
> + libinput_add_fd(libinput, fd, evdev_device_dispatch, device);
> + if (!device->source)
> + return -ENOMEM;
> +
> + memset(device->hw_key_mask, 0, sizeof(device->hw_key_mask));
> +
> + return 0;
> +}
> +
Suspend also closes the mtdev handle, should we not re-open that here too ?
Also it would be good to split this large commit in 2, 1 just adding the
resume function, and 1 with the rest.
> void
> evdev_device_remove(struct evdev_device *device)
> {
> diff --git a/src/evdev.h b/src/evdev.h
> index ef02491..8a6dfec 100644
> --- a/src/evdev.h
> +++ b/src/evdev.h
> @@ -189,6 +189,9 @@ evdev_device_transform_y(struct evdev_device *device,
> int
> evdev_device_suspend(struct evdev_device *device);
>
> +int
> +evdev_device_resume(struct evdev_device *device);
> +
> void
> evdev_keyboard_notify_key(struct evdev_device *device,
> uint32_t time,
> diff --git a/src/libinput-private.h b/src/libinput-private.h
> index cb90a15..cf03c03 100644
> --- a/src/libinput-private.h
> +++ b/src/libinput-private.h
> @@ -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 {
> diff --git a/src/libinput.c b/src/libinput.c
> index 20aa1cb..14f0257 100644
> --- a/src/libinput.c
> +++ b/src/libinput.c
> @@ -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;
> +}
> diff --git a/src/libinput.h b/src/libinput.h
> index 5af0dde..334b16d 100644
> --- a/src/libinput.h
> +++ b/src/libinput.h
> @@ -1634,6 +1634,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
>
Otherwise looks good to me.
Regards,
Hans
More information about the wayland-devel
mailing list