tablet: Report and normalize distance, pressure, and tilt axes

Report the values for the distance, pressure, and tilt axes. Pressure is
normalized to a range of 0 to 1, and tilt is normalized to a range of -1 to 1.

Based off the patch originally written by Carlos Garnacho

Signed-off-by: Stephen Chandler Paul <thatslyude@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
Stephen Chandler Paul 2014-06-06 20:31:38 -04:00
parent b2629dc8a1
commit 8f572b6fd1
3 changed files with 74 additions and 2 deletions

View file

@ -47,6 +47,10 @@ tablet_process_absolute(struct tablet_dispatch *tablet,
switch (e->code) {
case ABS_X:
case ABS_Y:
case ABS_PRESSURE:
case ABS_TILT_X:
case ABS_TILT_Y:
case ABS_DISTANCE:
axis = evcode_to_axis(e->code);
if (axis == LIBINPUT_TABLET_AXIS_NONE) {
log_bug_libinput("Invalid ABS event code %#x\n",
@ -78,6 +82,23 @@ tablet_update_tool(struct tablet_dispatch *tablet,
tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
}
static inline double
normalize_pressure(const struct input_absinfo * absinfo) {
double range = absinfo->maximum - absinfo->minimum + 1;
double value = (absinfo->value + absinfo->minimum) / range;
return value;
}
static inline double
normalize_tilt(const struct input_absinfo * absinfo) {
double range = absinfo->maximum - absinfo->minimum + 1;
double value = (absinfo->value + absinfo->minimum) / range;
/* Map to the (-1, 1) range */
return (value * 2) - 1;
}
static void
tablet_check_notify_axes(struct tablet_dispatch *tablet,
struct evdev_device *device,
@ -99,8 +120,16 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet,
switch (a) {
case LIBINPUT_TABLET_AXIS_X:
case LIBINPUT_TABLET_AXIS_Y:
case LIBINPUT_TABLET_AXIS_DISTANCE:
tablet->axes[a] = absinfo->value;
break;
case LIBINPUT_TABLET_AXIS_PRESSURE:
tablet->axes[a] = normalize_pressure(absinfo);
break;
case LIBINPUT_TABLET_AXIS_TILT_VERTICAL:
case LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL:
tablet->axes[a] = normalize_tilt(absinfo);
break;
default:
log_bug_libinput("Invalid axis update: %d\n", a);
break;
@ -165,6 +194,12 @@ tablet_process_key(struct tablet_dispatch *tablet,
tablet_update_tool(tablet, e->code, e->value);
break;
case BTN_TOUCH:
if (e->value)
tablet_set_status(tablet, TABLET_STYLUS_IN_CONTACT);
else
tablet_unset_status(tablet, TABLET_STYLUS_IN_CONTACT);
/* Fall through */
case BTN_STYLUS:
case BTN_STYLUS2:
default:

View file

@ -33,7 +33,8 @@ enum tablet_status {
TABLET_TOOL_UPDATED = 1 << 1,
TABLET_TOOL_LEAVING_PROXIMITY = 1 << 2,
TABLET_BUTTONS_PRESSED = 1 << 3,
TABLET_BUTTONS_RELEASED = 1 << 4
TABLET_BUTTONS_RELEASED = 1 << 4,
TABLET_STYLUS_IN_CONTACT = 1 << 5
};
struct button_state {
@ -67,6 +68,18 @@ evcode_to_axis(const uint32_t evcode)
case ABS_Y:
axis = LIBINPUT_TABLET_AXIS_Y;
break;
case ABS_DISTANCE:
axis = LIBINPUT_TABLET_AXIS_DISTANCE;
break;
case ABS_PRESSURE:
axis = LIBINPUT_TABLET_AXIS_PRESSURE;
break;
case ABS_TILT_X:
axis = LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL;
break;
case ABS_TILT_Y:
axis = LIBINPUT_TABLET_AXIS_TILT_VERTICAL;
break;
default:
axis = LIBINPUT_TABLET_AXIS_NONE;
break;
@ -87,6 +100,18 @@ axis_to_evcode(const enum libinput_tablet_axis axis)
case LIBINPUT_TABLET_AXIS_Y:
evcode = ABS_Y;
break;
case LIBINPUT_TABLET_AXIS_DISTANCE:
evcode = ABS_DISTANCE;
break;
case LIBINPUT_TABLET_AXIS_PRESSURE:
evcode = ABS_PRESSURE;
break;
case LIBINPUT_TABLET_AXIS_TILT_VERTICAL:
evcode = ABS_TILT_X;
break;
case LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL:
evcode = ABS_TILT_Y;
break;
default:
abort();
}

View file

@ -179,7 +179,11 @@ enum libinput_tablet_axis {
LIBINPUT_TABLET_AXIS_NONE = -1,
LIBINPUT_TABLET_AXIS_X = 0,
LIBINPUT_TABLET_AXIS_Y = 1,
LIBINPUT_TABLET_AXIS_CNT = LIBINPUT_TABLET_AXIS_Y + 1
LIBINPUT_TABLET_AXIS_DISTANCE = 2,
LIBINPUT_TABLET_AXIS_PRESSURE = 3,
LIBINPUT_TABLET_AXIS_TILT_VERTICAL = 4,
LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL = 5,
LIBINPUT_TABLET_AXIS_CNT = LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL + 1
};
/**
@ -870,6 +874,14 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event,
* however libinput provides libinput_event_tablet_get_x_transformed() and
* libinput_event_tablet_get_y_transformed() for transforming each respective
* axis value.
* - @ref LIBINPUT_TABLET_AXIS_DISTANCE - Approximately how many millimeters
* away from the tablet's sensor the tool is
* - @ref LIBINPUT_TABLET_AXIS_PRESSURE - The current pressure being applied on
* the tool in use, normalized from 0 to 1
* - @ref LIBINPUT_TABLET_AXIS_TILT_VERTICAL and @ref
* LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL - normalized value between -1 and 1
* that indicates the tilt vertical or horizontal tilt of the tool
* respectively
*
* For tablet events that are not of type @ref LIBINPUT_EVENT_TABLET_AXIS, this
* function returns 0.