diff options
-rw-r--r-- | src/evdev-tablet.c | 35 | ||||
-rw-r--r-- | src/evdev-tablet.h | 27 | ||||
-rw-r--r-- | src/libinput.h | 14 |
3 files changed, 74 insertions, 2 deletions
diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 872556a..aa9d2cb 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -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: diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 4498425..679050b 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -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(); } diff --git a/src/libinput.h b/src/libinput.h index b4272b2..ca00bdc 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -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. |