[PATCH libinput 1/3] core: Add internal event notification mechanism

Peter Hutterer peter.hutterer at who-t.net
Sun Sep 21 22:03:17 PDT 2014


On Thu, Sep 18, 2014 at 01:11:03PM +0200, Hans de Goede wrote:
> For features like e.g. disable-touchpad-while-typing, it is necessary for one
> device to be able to listen into another device's events.
> 
> It is tempting to use the existing device_added / device_removed mechanism
> to give e.g. the keyboard a link to the touchpad, and make the keyboard code
> disable / re-enable the touchpad but this wrong. This needs to be a setting
> of the touchpad, and the policy for things like which events to count as
> activity, and what sort of timeout to use to consider the device idle, belongs
> in the touchpad code not in the keyboard code.
> 
> Add an event listeners mechanism so that the touchpad can listen for (e.g.)
> keyboard events, and respond to these itself.
> 
> Signed-off-by: Hans de Goede <hdegoede at redhat.com>
> ---
>  src/libinput-private.h | 18 ++++++++++++++++++
>  src/libinput.c         | 27 +++++++++++++++++++++++++++
>  2 files changed, 45 insertions(+)
> 
> diff --git a/src/libinput-private.h b/src/libinput-private.h
> index cf03c03..94d6580 100644
> --- a/src/libinput-private.h
> +++ b/src/libinput-private.h
> @@ -118,12 +118,19 @@ struct libinput_device_config {
>  struct libinput_device {
>  	struct libinput_seat *seat;
>  	struct list link;
> +	struct list event_listeners;
>  	void *user_data;
>  	int terminated;
>  	int refcount;
>  	struct libinput_device_config config;
>  };
>  
> +struct libinput_event_listener {
> +	struct list link;
> +	void (*notify_func)(struct libinput_event *ev, void *notify_func_data);
> +	void *notify_func_data;
> +};
> +
>  typedef void (*libinput_source_dispatch_t)(void *data);
>  
>  
> @@ -180,6 +187,17 @@ libinput_device_init(struct libinput_device *device,
>  		     struct libinput_seat *seat);
>  
>  void
> +libinput_device_add_eventlistener(struct libinput_device *device,

event_listener vs eventlistener here, please use the former. otherwise:
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

Cheers,
   Peter


> +				  struct libinput_event_listener *listener,
> +				  void (*notify_func)(
> +					struct libinput_event *event,
> +					void *notify_func_data),
> +				  void *notify_func_data);
> +
> +void
> +libinput_device_remove_eventlistener(struct libinput_event_listener *listener);
> +
> +void
>  notify_added_device(struct libinput_device *device);
>  
>  void
> diff --git a/src/libinput.c b/src/libinput.c
> index 14f0257..79ae90a 100644
> --- a/src/libinput.c
> +++ b/src/libinput.c
> @@ -674,6 +674,7 @@ libinput_device_init(struct libinput_device *device,
>  {
>  	device->seat = seat;
>  	device->refcount = 1;
> +	list_init(&device->event_listeners);
>  }
>  
>  LIBINPUT_EXPORT struct libinput_device *
> @@ -686,6 +687,7 @@ libinput_device_ref(struct libinput_device *device)
>  static void
>  libinput_device_destroy(struct libinput_device *device)
>  {
> +	assert(list_empty(&device->event_listeners));
>  	evdev_device_destroy((struct evdev_device *) device);
>  }
>  
> @@ -732,6 +734,25 @@ libinput_dispatch(struct libinput *libinput)
>  	return 0;
>  }
>  
> +void
> +libinput_device_add_eventlistener(struct libinput_device *device,
> +				  struct libinput_event_listener *listener,
> +				  void (*notify_func)(
> +					struct libinput_event *event,
> +					void *notify_func_data),
> +				  void *notify_func_data)
> +{
> +	listener->notify_func = notify_func;
> +	listener->notify_func_data = notify_func_data;
> +	list_insert(&device->event_listeners, &listener->link);
> +}
> +
> +void
> +libinput_device_remove_eventlistener(struct libinput_event_listener *listener)
> +{
> +	list_remove(&listener->link);
> +}
> +
>  static uint32_t
>  update_seat_key_count(struct libinput_seat *seat,
>  		      int32_t key,
> @@ -798,7 +819,13 @@ post_device_event(struct libinput_device *device,
>  		  enum libinput_event_type type,
>  		  struct libinput_event *event)
>  {
> +	struct libinput_event_listener *listener, *tmp;
> +
>  	init_event_base(event, device, type);
> +
> +	list_for_each_safe(listener, tmp, &device->event_listeners, link)
> +		listener->notify_func(event, listener->notify_func_data);
> +
>  	libinput_post_event(device->seat->libinput, event);
>  }
>  
> -- 
> 2.1.0
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> 


More information about the wayland-devel mailing list