[PATCH libinput 09/24] Add LIBINPUT_EVENT_POINTER_TOOL_UPDATE event type

Peter Hutterer peter.hutterer at who-t.net
Sun Apr 27 22:07:14 PDT 2014


On Mon, Apr 21, 2014 at 07:11:18PM +0200, Carlos Garnacho wrote:
> This event would be emitted whenever a device with
> LIBINPUT_DEVICE_CAP_STYLUS capabilities changes its tool type.
> 
> When the tablet reaches proximity, the tool/serial will be
> updated to match the current physical stylus'. Likewise, when
> the stylus moves out of proximity, the tool will be reset to
> LIBINPUT_TOOL_NONE, so this event comes in pairs and can be used
> to track stylus proximity.
> 
> Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
> ---
>  src/libinput-private.h |  6 ++++++
>  src/libinput.c         | 41 ++++++++++++++++++++++++++++++++++++++
>  src/libinput.h         | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 101 insertions(+)
> 
> diff --git a/src/libinput-private.h b/src/libinput-private.h
> index 4eac89d..7cdce64 100644
> --- a/src/libinput-private.h
> +++ b/src/libinput-private.h
> @@ -159,6 +159,12 @@ pointer_notify_axis_frame(struct libinput_device *device,
>  			  uint32_t time);
>  
>  void
> +pointer_notify_tool_update(struct libinput_device *device,
> +			   uint32_t time,
> +			   enum libinput_tool tool,
> +			   uint32_t serial);
> +
> +void
>  touch_notify_touch_down(struct libinput_device *device,
>  			uint32_t time,
>  			int32_t slot,
> diff --git a/src/libinput.c b/src/libinput.c
> index 4ecd068..76a0b12 100644
> --- a/src/libinput.c
> +++ b/src/libinput.c
> @@ -66,6 +66,8 @@ struct libinput_event_pointer {
>  	enum libinput_pointer_button_state state;
>  	enum libinput_pointer_axis axis;
>  	li_fixed_t value;
> +	enum libinput_tool tool;
> +	uint32_t tool_serial;
>  };
>  
>  struct libinput_event_touch {
> @@ -176,6 +178,7 @@ libinput_event_get_pointer_event(struct libinput_event *event)
>  	case LIBINPUT_EVENT_POINTER_BUTTON:
>  	case LIBINPUT_EVENT_POINTER_AXIS:
>  	case LIBINPUT_EVENT_POINTER_AXIS_FRAME:
> +	case LIBINPUT_EVENT_POINTER_TOOL_UPDATE:
>  		return (struct libinput_event_pointer *) event;
>  	case LIBINPUT_EVENT_TOUCH_DOWN:
>  	case LIBINPUT_EVENT_TOUCH_UP:
> @@ -204,6 +207,7 @@ libinput_event_get_keyboard_event(struct libinput_event *event)
>  	case LIBINPUT_EVENT_POINTER_BUTTON:
>  	case LIBINPUT_EVENT_POINTER_AXIS:
>  	case LIBINPUT_EVENT_POINTER_AXIS_FRAME:
> +	case LIBINPUT_EVENT_POINTER_TOOL_UPDATE:
>  	case LIBINPUT_EVENT_TOUCH_DOWN:
>  	case LIBINPUT_EVENT_TOUCH_UP:
>  	case LIBINPUT_EVENT_TOUCH_MOTION:
> @@ -229,6 +233,7 @@ libinput_event_get_touch_event(struct libinput_event *event)
>  	case LIBINPUT_EVENT_POINTER_BUTTON:
>  	case LIBINPUT_EVENT_POINTER_AXIS:
>  	case LIBINPUT_EVENT_POINTER_AXIS_FRAME:
> +	case LIBINPUT_EVENT_POINTER_TOOL_UPDATE:
>  		break;
>  	case LIBINPUT_EVENT_TOUCH_DOWN:
>  	case LIBINPUT_EVENT_TOUCH_UP:
> @@ -256,6 +261,7 @@ libinput_event_get_device_notify_event(struct libinput_event *event)
>  	case LIBINPUT_EVENT_POINTER_BUTTON:
>  	case LIBINPUT_EVENT_POINTER_AXIS:
>  	case LIBINPUT_EVENT_POINTER_AXIS_FRAME:
> +	case LIBINPUT_EVENT_POINTER_TOOL_UPDATE:
>  	case LIBINPUT_EVENT_TOUCH_DOWN:
>  	case LIBINPUT_EVENT_TOUCH_UP:
>  	case LIBINPUT_EVENT_TOUCH_MOTION:
> @@ -355,6 +361,18 @@ libinput_event_pointer_get_axis(struct libinput_event_pointer *event)
>  	return event->axis;
>  }
>  
> +LIBINPUT_EXPORT enum libinput_tool
> +libinput_event_pointer_get_tool(struct libinput_event_pointer *event)
> +{
> +	return event->tool;
> +}
> +
> +LIBINPUT_EXPORT uint32_t
> +libinput_event_pointer_get_tool_serial(struct libinput_event_pointer *event)
> +{
> +	return event->tool_serial;
> +}


I think the tool needs to be an object, with the serial as a property on
the object, similar to the seat object. So that'd leave us with
    struct libinput_tool libinput_event_pointer_get_tool();
and
    int32_t libinput_tool_get_serial();

Note that we've used -1 for "no tool" in the wacom drivers, so the serial
should be a int32_t.

Cheers,
   Peter
 
> +
>  LIBINPUT_EXPORT li_fixed_t
>  libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event)
>  {
> @@ -867,6 +885,29 @@ pointer_notify_axis_frame(struct libinput_device *device,
>  }
>  
>  void
> +pointer_notify_tool_update(struct libinput_device *device,
> +			   uint32_t time,
> +			   enum libinput_tool tool,
> +			   uint32_t serial)
> +{
> +	struct libinput_event_pointer *tool_update_event;
> +
> +	tool_update_event = zalloc(sizeof *tool_update_event);
> +	if (!tool_update_event)
> +		return;
> +
> +	*tool_update_event = (struct libinput_event_pointer) {
> +		.time = time,
> +		.tool = tool,
> +		.tool_serial = serial,
> +	};
> +
> +	post_device_event(device,
> +			  LIBINPUT_EVENT_POINTER_TOOL_UPDATE,
> +			  &tool_update_event->base);
> +}
> +
> +void
>  touch_notify_touch_down(struct libinput_device *device,
>  			uint32_t time,
>  			int32_t slot,
> diff --git a/src/libinput.h b/src/libinput.h
> index f6a881c..8d40a1a 100644
> --- a/src/libinput.h
> +++ b/src/libinput.h
> @@ -117,6 +117,24 @@ enum libinput_pointer_axis {
>  };
>  
>  /**
> + * @ingroup device
> + *
> + * Available tool types for a device. It must have the @ref
> + * LIBINPUT_DEVICE_CAP_STYLUS capability.
> + */
> +enum libinput_tool {
> +	LIBINPUT_TOOL_NONE = 0,
> +	LIBINPUT_TOOL_PEN = 0x140, /* Matches BTN_TOOL_PEN */
> +	LIBINPUT_TOOL_ERASER,
> +	LIBINPUT_TOOL_BRUSH,
> +	LIBINPUT_TOOL_PENCIL,
> +	LIBINPUT_TOOL_AIRBRUSH,
> +	LIBINPUT_TOOL_FINGER,
> +	LIBINPUT_TOOL_MOUSE,
> +	LIBINPUT_TOOL_LENS
> +};
> +
> +/**
>   * @ingroup base
>   *
>   * Event type for events returned by libinput_get_event().
> @@ -157,6 +175,12 @@ enum libinput_event_type {
>  	 */
>  	LIBINPUT_EVENT_POINTER_AXIS_FRAME,
>  
> +	/**
> +	 * Signals that a device with the @ref LIBINPUT_DEVICE_CAP_STYLUS
> +	 * capability has changed its tool.
> +	 */
> +	LIBINPUT_EVENT_POINTER_TOOL_UPDATE,
> +
>  	LIBINPUT_EVENT_TOUCH_DOWN = 500,
>  	LIBINPUT_EVENT_TOUCH_UP,
>  	LIBINPUT_EVENT_TOUCH_MOTION,
> @@ -557,6 +581,36 @@ libinput_event_pointer_get_axis(struct libinput_event_pointer *event);
>  /**
>   * @ingroup event_pointer
>   *
> + * Return the tool mode set by this event.
> + * For pointer events that are not of type @ref LIBINPUT_EVENT_POINTER_TOOL_UPDATE,
> + * this function returns @ref LIBINPUT_TOOL_NONE.
> + *
> + * @note It is an application bug to call this function for events other than
> + * @ref LIBINPUT_EVENT_POINTER_TOOL_UPDATE.
> + *
> + * @return The new tool triggering this event
> + */
> +enum libinput_tool
> +libinput_event_pointer_get_tool(struct libinput_event_pointer *event);
> +
> +/**
> + * @ingroup event_pointer
> + *
> + * Return the tool serial set by this event.
> + * For pointer events that are not of type @ref LIBINPUT_EVENT_POINTER_TOOL_UPDATE,
> + * this function returns @ref LIBINPUT_TOOL_NONE.
> + *
> + * @note It is an application bug to call this function for events other than
> + * @ref LIBINPUT_EVENT_POINTER_TOOL_UPDATE.
> + *
> + * @return The new tool serial triggering this event
> + */
> +uint32_t
> +libinput_event_pointer_get_tool_serial(struct libinput_event_pointer *event);
> +
> +/**
> + * @ingroup event_pointer
> + *
>   * Return the axis value of the given axis. The interpretation of the value
>   * is dependent on the axis. For the two scrolling axes
>   * LIBINPUT_POINTER_AXIS_VERTICAL_SCROLL and
> -- 
> 1.9.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