diff --git a/src/libinput-private.h b/src/libinput-private.h index f6ba51ca..83906f5b 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -85,6 +85,13 @@ struct libinput_device { int refcount; }; +struct libinput_tool { + struct list link; + uint32_t serial; + enum libinput_tool_type type; + int refcount; +}; + typedef void (*libinput_source_dispatch_t)(void *data); diff --git a/src/libinput.c b/src/libinput.c index 96dda717..5e6ba93c 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -515,6 +515,35 @@ libinput_event_tablet_get_time(struct libinput_event_tablet *event) return event->time; } +LIBINPUT_EXPORT enum libinput_tool_type +libinput_tool_get_type(struct libinput_tool *tool) +{ + return tool->type; +} + +LIBINPUT_EXPORT uint32_t +libinput_tool_get_serial(struct libinput_tool *tool) +{ + return tool->serial; +} + +LIBINPUT_EXPORT void +libinput_tool_ref(struct libinput_tool *tool) +{ + tool->refcount++; +} + +LIBINPUT_EXPORT void +libinput_tool_unref(struct libinput_tool *tool) +{ + assert(tool->refcount > 0); + + if (--tool->refcount == 0) { + list_remove(&tool->link); + free(tool); + } +} + struct libinput_source * libinput_add_fd(struct libinput *libinput, int fd, diff --git a/src/libinput.h b/src/libinput.h index 123d778f..0bd24c2e 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -182,6 +182,32 @@ enum libinput_tablet_axis { LIBINPUT_TABLET_AXIS_CNT = LIBINPUT_TABLET_AXIS_Y + 1 }; +/** + * @ingroup device + * + * An object representing a tool being used by the device. It must have the @ref + * LIBINPUT_DEVICE_CAP_TABLET capability. + */ +struct libinput_tool; + +/** + * @ingroup device + * + * Available tool types for a device. It must have the @ref + * LIBINPUT_DEVICE_CAP_TABLET capability. + */ +enum libinput_tool_type { + LIBINPUT_TOOL_NONE = -1, + 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 * @@ -874,6 +900,53 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, uint32_t libinput_event_tablet_get_time(struct libinput_event_tablet *event); +/** + * @ingroup event_tablet + * + * Return the type of tool type for a tool object + * + * @param tool The libinput tool + * @return The tool type for this tool object + */ +enum libinput_tool_type +libinput_tool_get_type(struct libinput_tool *tool); + +/** + * @ingroup event_tablet + * + * Increment the ref count of tool by one + * + * @param tool The tool to increment the ref count of + */ +void +libinput_tool_ref(struct libinput_tool *tool); + +/** + * @ingroup event_tablet + * + * Decrement the ref count of tool by one. When the ref count of tool reaches 0, + * the memory allocated for tool will be freed. + * + * @param tool The tool to decrement the ref count of + */ +void +libinput_tool_unref(struct libinput_tool *tool); + +/** + * @ingroup event_tablet + * + * Return the serial number of a tool + * + * @note Not all tablets report a serial number along with the type of tool + * being used. If the hardware does not provide a unique serial number, the + * serial number is always 0. + * + * @param tool The libinput tool + * @return The new tool serial triggering this event + */ +uint32_t +libinput_tool_get_serial(struct libinput_tool *tool); + /** * @defgroup base Initialization and manipulation of libinput contexts */