tablet: add libinput_tool_get_tool_id()

The tool ID on wacom tablets is what really defines the tool, so one can
differ between say an Intuos Grip Pen, Art Pen or Classic Pen. They're all
BTN_TOOL_PEN in the kernel driver.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Reviewed-by: Stephen Chandler Paul <thatslyude@gmail.com>
This commit is contained in:
Peter Hutterer 2015-02-19 14:56:34 +10:00
parent 9ba09f5b55
commit 9088138c80
6 changed files with 38 additions and 0 deletions

View file

@ -62,6 +62,11 @@ tablet_process_absolute(struct tablet_dispatch *tablet,
set_bit(tablet->changed_axes, axis);
tablet_set_status(tablet, TABLET_AXES_UPDATED);
break;
/* tool_id is the identifier for the tool we can use in libwacom
* to identify it (if we have one anyway) */
case ABS_MISC:
tablet->current_tool_id = e->value;
break;
default:
log_info(device->base.seat->libinput,
"Unhandled ABS event code %#x\n", e->code);
@ -324,6 +329,7 @@ tablet_process_misc(struct tablet_dispatch *tablet,
static struct libinput_tool *
tablet_get_tool(struct tablet_dispatch *tablet,
enum libinput_tool_type type,
uint32_t tool_id,
uint32_t serial)
{
struct libinput_tool *tool = NULL, *t;
@ -362,6 +368,7 @@ tablet_get_tool(struct tablet_dispatch *tablet,
*tool = (struct libinput_tool) {
.type = type,
.serial = serial,
.tool_id = tool_id,
.refcount = 1,
};
@ -499,6 +506,7 @@ tablet_flush(struct tablet_dispatch *tablet,
struct libinput_tool *tool =
tablet_get_tool(tablet,
tablet->current_tool_type,
tablet->current_tool_id,
tablet->current_tool_serial);
if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {

View file

@ -59,6 +59,7 @@ struct tablet_dispatch {
struct button_state prev_button_state;
enum libinput_tool_type current_tool_type;
uint32_t current_tool_id;
uint32_t current_tool_serial;
};

View file

@ -188,6 +188,7 @@ struct libinput_device {
struct libinput_tool {
struct list link;
uint32_t serial;
uint32_t tool_id;
enum libinput_tool_type type;
unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)];
int refcount;

View file

@ -662,6 +662,12 @@ libinput_tool_get_type(struct libinput_tool *tool)
return tool->type;
}
LIBINPUT_EXPORT uint32_t
libinput_tool_get_tool_id(struct libinput_tool *tool)
{
return tool->tool_id;
}
LIBINPUT_EXPORT uint32_t
libinput_tool_get_serial(struct libinput_tool *tool)
{

View file

@ -160,6 +160,7 @@ struct libinput_tool;
* usage of the tool as advertised by the manufacturer. Multiple different
* physical tools may share the same tool type, e.g. a Wacom Classic Pen,
* Wacom Pro Pen and a Wacom Grip Pen are all of type LIBINPUT_TOOL_PEN.
* Use libinput_tool_get_tool_id() to get a specific model where applicable.
*
* Note that on some device, the eraser tool is on the tail end of a pen
* device. On other devices, e.g. MS Surface 3, the eraser is the pen tip
@ -1192,10 +1193,30 @@ libinput_event_tablet_get_time(struct libinput_event_tablet *event);
*
* @param tool The libinput tool
* @return The tool type for this tool object
*
* @see libinput_tool_get_tool_id
*/
enum libinput_tool_type
libinput_tool_get_type(struct libinput_tool *tool);
/**
* @ingroup event_tablet
*
* Return the tool ID for a tool object. If nonzero, this number identifies
* the specific type of the tool with more precision than the type returned in
* libinput_tool_get_type(). Not all tablets support a tool ID.
*
* Tablets known to support tool IDs include the Wacom Intuos 3, 4, 5, Wacom
* Cintiq and Wacom Intuos Pro series.
*
* @param tool The libinput tool
* @return The tool ID for this tool object or 0 if none is provided
*
* @see libinput_tool_get_type
*/
uint32_t
libinput_tool_get_tool_id(struct libinput_tool *tool);
/**
* @ingroup event_tablet
*

View file

@ -153,6 +153,7 @@ LIBINPUT_0.12.0 {
libinput_event_tablet_get_x_transformed;
libinput_event_tablet_get_y_transformed;
libinput_tool_get_serial;
libinput_tool_get_tool_id;
libinput_tool_get_type;
libinput_tool_get_user_data;
libinput_tool_has_axis;