[PATCH libinput 11/17] evdev: hook up a generic enable/disable interface for devices

Hans de Goede hdegoede at redhat.com
Sun Sep 14 03:18:37 PDT 2014


Hi,

On 09/03/2014 04:03 AM, Peter Hutterer wrote:
> The evdev fallback dispatch supports enabling and disabling devices. That's
> fairly easy to support since we don't (yet) have extra event generation within
> the fallback backend. Thus, we can simply close the fd and re-open it again
> later.
> 
> Touchpads are currently excluded here, they generate extra events on tapping,
> scrolling, and software buttons and need a more complex implementation.
> 
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

Looks good:

Reviewed-by: Hans de Goede <hdegoede at redhat.com>

Regards,

Hans

> ---
>  src/evdev.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  src/evdev.h |  5 +++++
>  2 files changed, 63 insertions(+), 1 deletion(-)
> 
> diff --git a/src/evdev.c b/src/evdev.c
> index 9d98b58..c9e9b2d 100644
> --- a/src/evdev.c
> +++ b/src/evdev.c
> @@ -624,14 +624,63 @@ struct evdev_dispatch_interface fallback_interface = {
>  	fallback_destroy
>  };
>  
> +static uint32_t
> +evdev_sendevents_get_modes(struct libinput_device *device)
> +{
> +	return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED |
> +	       LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;
> +}
> +
> +static enum libinput_config_status
> +evdev_sendevents_set_mode(struct libinput_device *device,
> +			  enum libinput_config_send_events_mode mode)
> +{
> +	struct evdev_device *evdev = (struct evdev_device*)device;
> +	struct evdev_dispatch *dispatch = evdev->dispatch;
> +
> +	if (mode == dispatch->sendevents.current_mode)
> +		return LIBINPUT_CONFIG_STATUS_SUCCESS;
> +
> +	switch(mode) {
> +	case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED:
> +		evdev_device_resume(evdev);
> +		break;
> +	case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED:
> +		evdev_device_suspend(evdev);
> +		break;
> +	default:
> +		return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
> +	}
> +
> +	dispatch->sendevents.current_mode = mode;
> +
> +	return LIBINPUT_CONFIG_STATUS_SUCCESS;
> +}
> +
> +static enum libinput_config_send_events_mode
> +evdev_sendevents_get_mode(struct libinput_device *device)
> +{
> +	struct evdev_device *evdev = (struct evdev_device*)device;
> +	struct evdev_dispatch *dispatch = evdev->dispatch;
> +
> +	return dispatch->sendevents.current_mode;
> +}
> +
> +static enum libinput_config_send_events_mode
> +evdev_sendevents_get_default_mode(struct libinput_device *device)
> +{
> +	return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
> +}
> +
>  static struct evdev_dispatch *
>  fallback_dispatch_create(struct libinput_device *device)
>  {
> -	struct evdev_dispatch *dispatch = malloc(sizeof *dispatch);
> +	struct evdev_dispatch *dispatch = zalloc(sizeof *dispatch);
>  	if (dispatch == NULL)
>  		return NULL;
>  
>  	dispatch->interface = &fallback_interface;
> +
>  	device->config.calibration = &dispatch->calibration;
>  
>  	dispatch->calibration.has_matrix = evdev_calibration_has_matrix;
> @@ -639,6 +688,14 @@ fallback_dispatch_create(struct libinput_device *device)
>  	dispatch->calibration.get_matrix = evdev_calibration_get_matrix;
>  	dispatch->calibration.get_default_matrix = evdev_calibration_get_default_matrix;
>  
> +	device->config.sendevents = &dispatch->sendevents.config;
> +
> +	dispatch->sendevents.current_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
> +	dispatch->sendevents.config.get_modes = evdev_sendevents_get_modes;
> +	dispatch->sendevents.config.set_mode = evdev_sendevents_set_mode;
> +	dispatch->sendevents.config.get_mode = evdev_sendevents_get_mode;
> +	dispatch->sendevents.config.get_default_mode = evdev_sendevents_get_default_mode;
> +
>  	return dispatch;
>  }
>  
> diff --git a/src/evdev.h b/src/evdev.h
> index 8a6dfec..2af6828 100644
> --- a/src/evdev.h
> +++ b/src/evdev.h
> @@ -124,6 +124,11 @@ struct evdev_dispatch_interface {
>  struct evdev_dispatch {
>  	struct evdev_dispatch_interface *interface;
>  	struct libinput_device_config_calibration calibration;
> +
> +	struct {
> +		struct libinput_device_config_send_events config;
> +		enum libinput_config_send_events_mode current_mode;
> +	} sendevents;
>  };
>  
>  struct evdev_device *
> 


More information about the wayland-devel mailing list