tablet: factor out setting axis bits on a tool

No functional changes.

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-18 12:03:34 +10:00
parent 8f56a7ea93
commit 5cac5248fc

View file

@ -351,6 +351,48 @@ tablet_process_misc(struct tablet_dispatch *tablet,
}
}
static inline void
copy_axis_cap(const struct tablet_dispatch *tablet,
struct libinput_tool *tool,
enum libinput_tablet_axis axis)
{
if (bit_is_set(tablet->axis_caps, axis))
set_bit(tool->axis_caps, axis);
}
static void
tool_set_bits(const struct tablet_dispatch *tablet,
struct libinput_tool *tool)
{
enum libinput_tool_type type = tool->type;
/* Determine the axis capabilities of the tool. Here's a break
* down of the heuristics used here:
* - The Wacom art pen supports all of the extra axes, along
* with rotation
* - The Wacom airbrush supports a wheel with a ~90 deg
* range.
* - All of normal pens and the airbrush support all of the
* extra axes if the tablet can report them
* - All of the mouse-like devices don't report any of
* the extra axes except for rotation (calculated from tilt x/y).
*/
switch (type) {
case LIBINPUT_TOOL_PEN:
case LIBINPUT_TOOL_ERASER:
case LIBINPUT_TOOL_PENCIL:
case LIBINPUT_TOOL_BRUSH:
case LIBINPUT_TOOL_AIRBRUSH:
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_PRESSURE);
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_DISTANCE);
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_TILT_X);
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_TILT_Y);
break;
default:
break;
}
}
static struct libinput_tool *
tablet_get_tool(struct tablet_dispatch *tablet,
enum libinput_tool_type type,
@ -397,43 +439,7 @@ tablet_get_tool(struct tablet_dispatch *tablet,
.refcount = 1,
};
/* Determine the axis capabilities of the tool. Here's a break
* down of the heuristics used here:
* - The Wacom art pen supports all of the extra axes, along
* with rotation
* - All of normal pens and the airbrush support all of the
* extra axes if the tablet can report them
* - All of the mouse like devices don't really report any of
* the extra axes except for rotation.
* (as of writing this comment, rotation isn't supported, so you
* won't see the mouse or art pen here)
*/
switch (type) {
case LIBINPUT_TOOL_PEN:
case LIBINPUT_TOOL_ERASER:
case LIBINPUT_TOOL_PENCIL:
case LIBINPUT_TOOL_BRUSH:
case LIBINPUT_TOOL_AIRBRUSH:
if (bit_is_set(tablet->axis_caps,
LIBINPUT_TABLET_AXIS_PRESSURE))
set_bit(tool->axis_caps,
LIBINPUT_TABLET_AXIS_PRESSURE);
if (bit_is_set(tablet->axis_caps,
LIBINPUT_TABLET_AXIS_DISTANCE))
set_bit(tool->axis_caps,
LIBINPUT_TABLET_AXIS_DISTANCE);
if (bit_is_set(tablet->axis_caps,
LIBINPUT_TABLET_AXIS_TILT_X))
set_bit(tool->axis_caps,
LIBINPUT_TABLET_AXIS_TILT_X);
if (bit_is_set(tablet->axis_caps,
LIBINPUT_TABLET_AXIS_TILT_Y))
set_bit(tool->axis_caps,
LIBINPUT_TABLET_AXIS_TILT_Y);
break;
default:
break;
}
tool_set_bits(tablet, tool);
list_insert(tool_list, &tool->link);
}