mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-04-24 03:20:44 +02:00
tablet: use a struct rather than a double array for axis values
Makes the code less generic, but more expressive. No visible functional changes. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Acked-by: Jason Gerecke <jason.gerecke@wacom.com>
This commit is contained in:
parent
b1d6c5aa54
commit
d524313d2b
4 changed files with 161 additions and 174 deletions
|
|
@ -251,8 +251,8 @@ convert_tilt_to_rotation(struct tablet_dispatch *tablet)
|
|||
values. The device has a 175 degree CCW hardware offset but since we use
|
||||
atan2 the effective offset is just 5 degrees.
|
||||
*/
|
||||
x = tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_X];
|
||||
y = tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_Y];
|
||||
x = tablet->axes.tilt.x;
|
||||
y = tablet->axes.tilt.y;
|
||||
clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X);
|
||||
clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y);
|
||||
|
||||
|
|
@ -262,7 +262,7 @@ convert_tilt_to_rotation(struct tablet_dispatch *tablet)
|
|||
|
||||
angle = fmod(360 + angle - offset, 360);
|
||||
|
||||
tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z] = angle;
|
||||
tablet->axes.rotation = angle;
|
||||
set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
|
||||
}
|
||||
|
||||
|
|
@ -290,29 +290,26 @@ tablet_handle_xy(struct tablet_dispatch *tablet, struct evdev_device *device)
|
|||
{
|
||||
struct device_coords point;
|
||||
const struct input_absinfo *absinfo;
|
||||
int a;
|
||||
|
||||
a = LIBINPUT_TABLET_TOOL_AXIS_X;
|
||||
if (bit_is_set(tablet->changed_axes, a)) {
|
||||
if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X)) {
|
||||
absinfo = libevdev_get_abs_info(device->evdev, ABS_X);
|
||||
|
||||
if (device->left_handed.enabled)
|
||||
tablet->axes[a] = invert_axis(absinfo);
|
||||
tablet->axes.point.x = invert_axis(absinfo);
|
||||
else
|
||||
tablet->axes[a] = absinfo->value;
|
||||
tablet->axes.point.x = absinfo->value;
|
||||
}
|
||||
point.x = tablet->axes[a];
|
||||
point.x = tablet->axes.point.x;
|
||||
|
||||
a = LIBINPUT_TABLET_TOOL_AXIS_Y;
|
||||
if (bit_is_set(tablet->changed_axes, a)) {
|
||||
if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y)) {
|
||||
absinfo = libevdev_get_abs_info(device->evdev, ABS_Y);
|
||||
|
||||
if (device->left_handed.enabled)
|
||||
tablet->axes[a] = invert_axis(absinfo);
|
||||
tablet->axes.point.y = invert_axis(absinfo);
|
||||
else
|
||||
tablet->axes[a] = absinfo->value;
|
||||
tablet->axes.point.y = absinfo->value;
|
||||
}
|
||||
point.y = tablet->axes[a];
|
||||
point.y = tablet->axes.point.y;
|
||||
|
||||
evdev_transform_absolute(device, &point);
|
||||
|
||||
|
|
@ -325,15 +322,14 @@ tablet_handle_pressure(struct tablet_dispatch *tablet,
|
|||
struct libinput_tablet_tool *tool)
|
||||
{
|
||||
const struct input_absinfo *absinfo;
|
||||
int a;
|
||||
|
||||
a = LIBINPUT_TABLET_TOOL_AXIS_PRESSURE;
|
||||
if (bit_is_set(tablet->changed_axes, a)) {
|
||||
if (bit_is_set(tablet->changed_axes,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) {
|
||||
absinfo = libevdev_get_abs_info(device->evdev, ABS_PRESSURE);
|
||||
tablet->axes[a] = normalize_pressure(absinfo, tool);
|
||||
tablet->axes.pressure = normalize_pressure(absinfo, tool);
|
||||
}
|
||||
|
||||
return tablet->axes[a];
|
||||
return tablet->axes.pressure;
|
||||
}
|
||||
|
||||
static inline double
|
||||
|
|
@ -341,15 +337,14 @@ tablet_handle_distance(struct tablet_dispatch *tablet,
|
|||
struct evdev_device *device)
|
||||
{
|
||||
const struct input_absinfo *absinfo;
|
||||
int a;
|
||||
|
||||
a = LIBINPUT_TABLET_TOOL_AXIS_DISTANCE;
|
||||
if (bit_is_set(tablet->changed_axes, a)) {
|
||||
if (bit_is_set(tablet->changed_axes,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) {
|
||||
absinfo = libevdev_get_abs_info(device->evdev, ABS_DISTANCE);
|
||||
tablet->axes[a] = normalize_dist_slider(absinfo);
|
||||
tablet->axes.distance = normalize_dist_slider(absinfo);
|
||||
}
|
||||
|
||||
return tablet->axes[a];
|
||||
return tablet->axes.distance;
|
||||
}
|
||||
|
||||
static inline double
|
||||
|
|
@ -357,15 +352,14 @@ tablet_handle_slider(struct tablet_dispatch *tablet,
|
|||
struct evdev_device *device)
|
||||
{
|
||||
const struct input_absinfo *absinfo;
|
||||
int a;
|
||||
|
||||
a = LIBINPUT_TABLET_TOOL_AXIS_SLIDER;
|
||||
if (bit_is_set(tablet->changed_axes, a)) {
|
||||
if (bit_is_set(tablet->changed_axes,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) {
|
||||
absinfo = libevdev_get_abs_info(device->evdev, ABS_WHEEL);
|
||||
tablet->axes[a] = normalize_dist_slider(absinfo);
|
||||
tablet->axes.slider = normalize_dist_slider(absinfo);
|
||||
}
|
||||
|
||||
return tablet->axes[a];
|
||||
return tablet->axes.slider;
|
||||
}
|
||||
|
||||
static inline struct normalized_range_coords
|
||||
|
|
@ -374,25 +368,24 @@ tablet_handle_tilt(struct tablet_dispatch *tablet,
|
|||
{
|
||||
struct normalized_range_coords tilt;
|
||||
const struct input_absinfo *absinfo;
|
||||
int a;
|
||||
|
||||
a = LIBINPUT_TABLET_TOOL_AXIS_TILT_X;
|
||||
if (bit_is_set(tablet->changed_axes, a)) {
|
||||
if (bit_is_set(tablet->changed_axes,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_TILT_X)) {
|
||||
absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_X);
|
||||
tablet->axes[a] = normalize_tilt(absinfo);
|
||||
tablet->axes.tilt.x = normalize_tilt(absinfo);
|
||||
if (device->left_handed.enabled)
|
||||
tablet->axes[a] *= -1;
|
||||
tablet->axes.tilt.x *= -1;
|
||||
}
|
||||
tilt.x = tablet->axes[a];
|
||||
tilt.x = tablet->axes.tilt.x;
|
||||
|
||||
a = LIBINPUT_TABLET_TOOL_AXIS_TILT_Y;
|
||||
if (bit_is_set(tablet->changed_axes, a)) {
|
||||
if (bit_is_set(tablet->changed_axes,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) {
|
||||
absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_Y);
|
||||
tablet->axes[a] = normalize_tilt(absinfo);
|
||||
tablet->axes.tilt.y = normalize_tilt(absinfo);
|
||||
if (device->left_handed.enabled)
|
||||
tablet->axes[a] *= -1;
|
||||
tablet->axes.tilt.y *= -1;
|
||||
}
|
||||
tilt.y = tablet->axes[a];
|
||||
tilt.y = tablet->axes.tilt.y;
|
||||
|
||||
return tilt;
|
||||
}
|
||||
|
|
@ -402,26 +395,22 @@ tablet_handle_artpen_rotation(struct tablet_dispatch *tablet,
|
|||
struct evdev_device *device)
|
||||
{
|
||||
const struct input_absinfo *absinfo;
|
||||
int a;
|
||||
|
||||
a = LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z;
|
||||
if (bit_is_set(tablet->changed_axes, a)) {
|
||||
if (bit_is_set(tablet->changed_axes,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) {
|
||||
absinfo = libevdev_get_abs_info(device->evdev,
|
||||
ABS_Z);
|
||||
/* artpen has 0 with buttons pointing east */
|
||||
tablet->axes[a] = convert_to_degrees(absinfo, 90);
|
||||
tablet->axes.rotation = convert_to_degrees(absinfo, 90);
|
||||
}
|
||||
|
||||
return tablet->axes[a];
|
||||
return tablet->axes.rotation;
|
||||
}
|
||||
|
||||
static inline double
|
||||
tablet_handle_mouse_rotation(struct tablet_dispatch *tablet,
|
||||
struct evdev_device *device)
|
||||
{
|
||||
int a;
|
||||
|
||||
a = LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z;
|
||||
if (bit_is_set(tablet->changed_axes,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_TILT_X) ||
|
||||
bit_is_set(tablet->changed_axes,
|
||||
|
|
@ -429,7 +418,7 @@ tablet_handle_mouse_rotation(struct tablet_dispatch *tablet,
|
|||
convert_tilt_to_rotation(tablet);
|
||||
}
|
||||
|
||||
return tablet->axes[a];
|
||||
return tablet->axes.rotation;
|
||||
}
|
||||
|
||||
static inline double
|
||||
|
|
@ -442,68 +431,50 @@ tablet_handle_wheel(struct tablet_dispatch *tablet,
|
|||
a = LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL;
|
||||
if (bit_is_set(tablet->changed_axes, a)) {
|
||||
*wheel_discrete = tablet->deltas[a];
|
||||
tablet->axes[a] = normalize_wheel(tablet,
|
||||
tablet->deltas[a]);
|
||||
tablet->axes.wheel = normalize_wheel(tablet,
|
||||
tablet->deltas[a]);
|
||||
} else {
|
||||
tablet->axes[a] = 0;
|
||||
tablet->axes.wheel = 0;
|
||||
*wheel_discrete = 0;
|
||||
}
|
||||
|
||||
return tablet->axes[a];
|
||||
return tablet->axes.wheel;
|
||||
}
|
||||
|
||||
static bool
|
||||
tablet_check_notify_axes(struct tablet_dispatch *tablet,
|
||||
struct evdev_device *device,
|
||||
struct libinput_tablet_tool *tool,
|
||||
double *axes_out,
|
||||
size_t axes_sz,
|
||||
int *wheel_discrete_out)
|
||||
struct tablet_axes *axes_out)
|
||||
{
|
||||
double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0};
|
||||
int wheel_discrete = 0;
|
||||
struct device_coords point;
|
||||
struct normalized_range_coords tilt;
|
||||
struct tablet_axes axes = {0};
|
||||
const char tmp[sizeof(tablet->changed_axes)] = {0};
|
||||
|
||||
if (memcmp(tmp, tablet->changed_axes, sizeof(tmp)) == 0)
|
||||
return false;
|
||||
|
||||
assert(axes_sz == sizeof(axes));
|
||||
point = tablet_handle_xy(tablet, device);
|
||||
axes[LIBINPUT_TABLET_TOOL_AXIS_X] = point.x;
|
||||
axes[LIBINPUT_TABLET_TOOL_AXIS_Y] = point.y;
|
||||
axes.point = tablet_handle_xy(tablet, device);
|
||||
axes.pressure = tablet_handle_pressure(tablet, device, tool);
|
||||
axes.distance = tablet_handle_distance(tablet, device);
|
||||
axes.slider = tablet_handle_slider(tablet, device);
|
||||
|
||||
axes[LIBINPUT_TABLET_TOOL_AXIS_PRESSURE] =
|
||||
tablet_handle_pressure(tablet, device, tool);
|
||||
axes[LIBINPUT_TABLET_TOOL_AXIS_DISTANCE] =
|
||||
tablet_handle_distance(tablet, device);
|
||||
axes[LIBINPUT_TABLET_TOOL_AXIS_SLIDER] =
|
||||
tablet_handle_slider(tablet, device);
|
||||
|
||||
tilt = tablet_handle_tilt(tablet, device);
|
||||
axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_X] = tilt.x;
|
||||
axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_Y] = tilt.y;
|
||||
axes.tilt = tablet_handle_tilt(tablet, device);
|
||||
|
||||
/* We must check ROTATION_Z after TILT_X/Y so that the tilt axes are
|
||||
* already normalized and set if we have the mouse/lens tool */
|
||||
if (tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE ||
|
||||
tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_LENS) {
|
||||
axes[LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z] =
|
||||
tablet_handle_mouse_rotation(tablet, device);
|
||||
axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_X] = 0;
|
||||
axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_Y] = 0;
|
||||
axes.rotation = tablet_handle_mouse_rotation(tablet, device);
|
||||
axes.tilt.x = 0;
|
||||
axes.tilt.y = 0;
|
||||
|
||||
} else {
|
||||
axes[LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z] =
|
||||
tablet_handle_artpen_rotation(tablet, device);
|
||||
axes.rotation = tablet_handle_artpen_rotation(tablet, device);
|
||||
}
|
||||
|
||||
axes[LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL] =
|
||||
tablet_handle_wheel(tablet, device, &wheel_discrete);
|
||||
axes.wheel = tablet_handle_wheel(tablet, device, &axes.wheel_discrete);
|
||||
|
||||
memcpy(axes_out, axes, sizeof(axes));
|
||||
*wheel_discrete_out = wheel_discrete;
|
||||
*axes_out = axes;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -923,7 +894,7 @@ tablet_notify_button_mask(struct tablet_dispatch *tablet,
|
|||
time,
|
||||
tool,
|
||||
tip_state,
|
||||
tablet->axes,
|
||||
&tablet->axes,
|
||||
i,
|
||||
state);
|
||||
}
|
||||
|
|
@ -983,21 +954,20 @@ sanitize_pressure_distance(struct tablet_dispatch *tablet,
|
|||
if (tool_in_contact) {
|
||||
clear_bit(tablet->changed_axes,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
|
||||
tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_DISTANCE] =
|
||||
0;
|
||||
tablet->axes.distance = 0;
|
||||
} else {
|
||||
clear_bit(tablet->changed_axes,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
|
||||
tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_PRESSURE] = 0;
|
||||
tablet->axes.pressure = 0;
|
||||
}
|
||||
} else if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE) &&
|
||||
!tool_in_contact) {
|
||||
/* Make sure that the last axis value sent to the caller is a 0 */
|
||||
if (tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_PRESSURE] == 0)
|
||||
if (tablet->axes.pressure == 0)
|
||||
clear_bit(tablet->changed_axes,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
|
||||
else
|
||||
tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_PRESSURE] = 0;
|
||||
tablet->axes.pressure = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1195,8 +1165,7 @@ tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet,
|
|||
struct libinput_tablet_tool *tool,
|
||||
uint64_t time)
|
||||
{
|
||||
double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0};
|
||||
int wheel_discrete = 0;
|
||||
struct tablet_axes axes = {0};
|
||||
|
||||
/* We need to make sure that we check that the tool is not out of
|
||||
* proximity before we send any axis updates. This is because many
|
||||
|
|
@ -1210,9 +1179,7 @@ tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet,
|
|||
* information (it'll be mostly 0), so we just get the
|
||||
* current state and skip over updating the axes.
|
||||
*/
|
||||
static_assert(sizeof(axes) == sizeof(tablet->axes),
|
||||
"Mismatching array sizes");
|
||||
memcpy(axes, tablet->axes, sizeof(axes));
|
||||
axes = tablet->axes;
|
||||
|
||||
/* Dont' send an axis event, but we may have a tip event
|
||||
* update */
|
||||
|
|
@ -1220,9 +1187,7 @@ tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet,
|
|||
} else if (!tablet_check_notify_axes(tablet,
|
||||
device,
|
||||
tool,
|
||||
axes,
|
||||
sizeof(axes),
|
||||
&wheel_discrete)) {
|
||||
&axes)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
|
@ -1232,7 +1197,7 @@ tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet,
|
|||
tool,
|
||||
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN,
|
||||
tablet->changed_axes,
|
||||
axes);
|
||||
&axes);
|
||||
tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
|
||||
tablet_unset_status(tablet, TABLET_AXES_UPDATED);
|
||||
}
|
||||
|
|
@ -1243,7 +1208,7 @@ tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet,
|
|||
tool,
|
||||
LIBINPUT_TABLET_TOOL_TIP_DOWN,
|
||||
tablet->changed_axes,
|
||||
tablet->axes);
|
||||
&tablet->axes);
|
||||
tablet_unset_status(tablet, TABLET_AXES_UPDATED);
|
||||
tablet_unset_status(tablet, TABLET_TOOL_ENTERING_CONTACT);
|
||||
tablet_set_status(tablet, TABLET_TOOL_IN_CONTACT);
|
||||
|
|
@ -1253,7 +1218,7 @@ tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet,
|
|||
tool,
|
||||
LIBINPUT_TABLET_TOOL_TIP_UP,
|
||||
tablet->changed_axes,
|
||||
tablet->axes);
|
||||
&tablet->axes);
|
||||
tablet_unset_status(tablet, TABLET_AXES_UPDATED);
|
||||
tablet_unset_status(tablet, TABLET_TOOL_LEAVING_CONTACT);
|
||||
tablet_unset_status(tablet, TABLET_TOOL_IN_CONTACT);
|
||||
|
|
@ -1271,8 +1236,7 @@ tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet,
|
|||
tool,
|
||||
tip_state,
|
||||
tablet->changed_axes,
|
||||
axes,
|
||||
wheel_discrete);
|
||||
&axes);
|
||||
tablet_unset_status(tablet, TABLET_AXES_UPDATED);
|
||||
}
|
||||
|
||||
|
|
@ -1348,7 +1312,7 @@ tablet_flush(struct tablet_dispatch *tablet,
|
|||
tool,
|
||||
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT,
|
||||
tablet->changed_axes,
|
||||
tablet->axes);
|
||||
&tablet->axes);
|
||||
|
||||
tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
|
||||
tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ struct tablet_dispatch {
|
|||
struct evdev_device *device;
|
||||
unsigned int status;
|
||||
unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)];
|
||||
double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1];
|
||||
struct tablet_axes axes;
|
||||
double deltas[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1];
|
||||
unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)];
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,17 @@ struct threshold {
|
|||
int lower;
|
||||
};
|
||||
|
||||
struct tablet_axes {
|
||||
struct device_coords point;
|
||||
double distance;
|
||||
double pressure;
|
||||
struct normalized_range_coords tilt;
|
||||
double rotation;
|
||||
double slider;
|
||||
double wheel;
|
||||
int wheel_discrete;
|
||||
};
|
||||
|
||||
struct libinput_interface_backend {
|
||||
int (*resume)(struct libinput *libinput);
|
||||
void (*suspend)(struct libinput *libinput);
|
||||
|
|
@ -493,8 +504,7 @@ tablet_notify_axis(struct libinput_device *device,
|
|||
struct libinput_tablet_tool *tool,
|
||||
enum libinput_tablet_tool_tip_state tip_state,
|
||||
unsigned char *changed_axes,
|
||||
double *axes,
|
||||
int wheel_discrete);
|
||||
const struct tablet_axes *axes);
|
||||
|
||||
void
|
||||
tablet_notify_proximity(struct libinput_device *device,
|
||||
|
|
@ -502,7 +512,7 @@ tablet_notify_proximity(struct libinput_device *device,
|
|||
struct libinput_tablet_tool *tool,
|
||||
enum libinput_tablet_tool_proximity_state state,
|
||||
unsigned char *changed_axes,
|
||||
double *axes);
|
||||
const struct tablet_axes *axes);
|
||||
|
||||
void
|
||||
tablet_notify_tip(struct libinput_device *device,
|
||||
|
|
@ -510,14 +520,14 @@ tablet_notify_tip(struct libinput_device *device,
|
|||
struct libinput_tablet_tool *tool,
|
||||
enum libinput_tablet_tool_tip_state tip_state,
|
||||
unsigned char *changed_axes,
|
||||
double *axes);
|
||||
const struct tablet_axes *axes);
|
||||
|
||||
void
|
||||
tablet_notify_button(struct libinput_device *device,
|
||||
uint64_t time,
|
||||
struct libinput_tablet_tool *tool,
|
||||
enum libinput_tablet_tool_tip_state tip_state,
|
||||
double *axes,
|
||||
const struct tablet_axes *axes,
|
||||
int32_t button,
|
||||
enum libinput_button_state state);
|
||||
|
||||
|
|
|
|||
141
src/libinput.c
141
src/libinput.c
|
|
@ -131,9 +131,7 @@ struct libinput_event_tablet_tool {
|
|||
enum libinput_button_state state;
|
||||
uint32_t seat_button_count;
|
||||
uint64_t time;
|
||||
double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1];
|
||||
double wheel_delta;
|
||||
int wheel_discrete;
|
||||
struct tablet_axes axes;
|
||||
unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)];
|
||||
struct libinput_tablet_tool *tool;
|
||||
enum libinput_tablet_tool_proximity_state proximity_state;
|
||||
|
|
@ -1056,9 +1054,8 @@ libinput_event_tablet_tool_wheel_has_changed(
|
|||
LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
|
||||
}
|
||||
|
||||
static double
|
||||
libinput_event_tablet_tool_get_axis_value(struct libinput_event_tablet_tool *event,
|
||||
enum libinput_tablet_tool_axis axis)
|
||||
LIBINPUT_EXPORT double
|
||||
libinput_event_tablet_tool_get_x(struct libinput_event_tablet_tool *event)
|
||||
{
|
||||
struct evdev_device *device =
|
||||
(struct evdev_device *) event->base.device;
|
||||
|
|
@ -1071,80 +1068,103 @@ libinput_event_tablet_tool_get_axis_value(struct libinput_event_tablet_tool *eve
|
|||
LIBINPUT_EVENT_TABLET_TOOL_BUTTON,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
|
||||
|
||||
switch(axis) {
|
||||
case LIBINPUT_TABLET_TOOL_AXIS_X:
|
||||
return evdev_convert_to_mm(device->abs.absinfo_x,
|
||||
event->axes[axis]);
|
||||
case LIBINPUT_TABLET_TOOL_AXIS_Y:
|
||||
return evdev_convert_to_mm(device->abs.absinfo_y,
|
||||
event->axes[axis]);
|
||||
case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE:
|
||||
case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE:
|
||||
case LIBINPUT_TABLET_TOOL_AXIS_TILT_X:
|
||||
case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y:
|
||||
case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z:
|
||||
case LIBINPUT_TABLET_TOOL_AXIS_SLIDER:
|
||||
case LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL:
|
||||
return event->axes[axis];
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT double
|
||||
libinput_event_tablet_tool_get_x(struct libinput_event_tablet_tool *event)
|
||||
{
|
||||
return libinput_event_tablet_tool_get_axis_value(event,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_X);
|
||||
return evdev_convert_to_mm(device->abs.absinfo_x,
|
||||
event->axes.point.x);
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT double
|
||||
libinput_event_tablet_tool_get_y(struct libinput_event_tablet_tool *event)
|
||||
{
|
||||
return libinput_event_tablet_tool_get_axis_value(event,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_Y);
|
||||
struct evdev_device *device =
|
||||
(struct evdev_device *) event->base.device;
|
||||
|
||||
require_event_type(libinput_event_get_context(&event->base),
|
||||
event->base.type,
|
||||
0,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_AXIS,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_TIP,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
|
||||
|
||||
return evdev_convert_to_mm(device->abs.absinfo_y,
|
||||
event->axes.point.y);
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT double
|
||||
libinput_event_tablet_tool_get_pressure(struct libinput_event_tablet_tool *event)
|
||||
{
|
||||
return libinput_event_tablet_tool_get_axis_value(event,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
|
||||
require_event_type(libinput_event_get_context(&event->base),
|
||||
event->base.type,
|
||||
0,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_AXIS,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_TIP,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
|
||||
|
||||
return event->axes.pressure;
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT double
|
||||
libinput_event_tablet_tool_get_distance(struct libinput_event_tablet_tool *event)
|
||||
{
|
||||
return libinput_event_tablet_tool_get_axis_value(event,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
|
||||
require_event_type(libinput_event_get_context(&event->base),
|
||||
event->base.type,
|
||||
0,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_AXIS,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_TIP,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
|
||||
|
||||
return event->axes.distance;
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT double
|
||||
libinput_event_tablet_tool_get_tilt_x(struct libinput_event_tablet_tool *event)
|
||||
{
|
||||
return libinput_event_tablet_tool_get_axis_value(event,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_TILT_X);
|
||||
require_event_type(libinput_event_get_context(&event->base),
|
||||
event->base.type,
|
||||
0,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_AXIS,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_TIP,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
|
||||
|
||||
return event->axes.tilt.x;
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT double
|
||||
libinput_event_tablet_tool_get_tilt_y(struct libinput_event_tablet_tool *event)
|
||||
{
|
||||
return libinput_event_tablet_tool_get_axis_value(event,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_TILT_Y);
|
||||
require_event_type(libinput_event_get_context(&event->base),
|
||||
event->base.type,
|
||||
0,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_AXIS,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_TIP,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
|
||||
|
||||
return event->axes.tilt.y;
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT double
|
||||
libinput_event_tablet_tool_get_rotation(struct libinput_event_tablet_tool *event)
|
||||
{
|
||||
return libinput_event_tablet_tool_get_axis_value(event,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
|
||||
require_event_type(libinput_event_get_context(&event->base),
|
||||
event->base.type,
|
||||
0,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_AXIS,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_TIP,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
|
||||
|
||||
return event->axes.rotation;
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT double
|
||||
libinput_event_tablet_tool_get_slider_position(struct libinput_event_tablet_tool *event)
|
||||
{
|
||||
return libinput_event_tablet_tool_get_axis_value(event,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_SLIDER);
|
||||
require_event_type(libinput_event_get_context(&event->base),
|
||||
event->base.type,
|
||||
0,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_AXIS,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_TIP,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
|
||||
|
||||
return event->axes.slider;
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT double
|
||||
|
|
@ -1157,8 +1177,7 @@ libinput_event_tablet_tool_get_wheel_delta(struct libinput_event_tablet_tool *ev
|
|||
LIBINPUT_EVENT_TABLET_TOOL_TIP,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
|
||||
|
||||
return libinput_event_tablet_tool_get_axis_value(event,
|
||||
LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
|
||||
return event->axes.wheel;
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT int
|
||||
|
|
@ -1172,7 +1191,7 @@ libinput_event_tablet_tool_get_wheel_delta_discrete(
|
|||
LIBINPUT_EVENT_TABLET_TOOL_TIP,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
|
||||
|
||||
return event->wheel_discrete;
|
||||
return event->axes.wheel_discrete;
|
||||
}
|
||||
|
||||
LIBINPUT_EXPORT double
|
||||
|
|
@ -1191,7 +1210,7 @@ libinput_event_tablet_tool_get_x_transformed(struct libinput_event_tablet_tool *
|
|||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
|
||||
|
||||
return evdev_device_transform_x(device,
|
||||
event->axes[LIBINPUT_TABLET_TOOL_AXIS_X],
|
||||
event->axes.point.x,
|
||||
width);
|
||||
}
|
||||
|
||||
|
|
@ -1211,7 +1230,7 @@ libinput_event_tablet_tool_get_y_transformed(struct libinput_event_tablet_tool *
|
|||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
|
||||
|
||||
return evdev_device_transform_y(device,
|
||||
event->axes[LIBINPUT_TABLET_TOOL_AXIS_Y],
|
||||
event->axes.point.y,
|
||||
height);
|
||||
}
|
||||
|
||||
|
|
@ -2170,8 +2189,7 @@ tablet_notify_axis(struct libinput_device *device,
|
|||
struct libinput_tablet_tool *tool,
|
||||
enum libinput_tablet_tool_tip_state tip_state,
|
||||
unsigned char *changed_axes,
|
||||
double *axes,
|
||||
int wheel_discrete)
|
||||
const struct tablet_axes *axes)
|
||||
{
|
||||
struct libinput_event_tablet_tool *axis_event;
|
||||
|
||||
|
|
@ -2184,13 +2202,12 @@ tablet_notify_axis(struct libinput_device *device,
|
|||
.tool = tool,
|
||||
.proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN,
|
||||
.tip_state = tip_state,
|
||||
.wheel_discrete = wheel_discrete,
|
||||
.axes = *axes,
|
||||
};
|
||||
|
||||
memcpy(axis_event->changed_axes,
|
||||
changed_axes,
|
||||
sizeof(axis_event->changed_axes));
|
||||
memcpy(axis_event->axes, axes, sizeof(axis_event->axes));
|
||||
|
||||
post_device_event(device,
|
||||
time,
|
||||
|
|
@ -2204,7 +2221,7 @@ tablet_notify_proximity(struct libinput_device *device,
|
|||
struct libinput_tablet_tool *tool,
|
||||
enum libinput_tablet_tool_proximity_state proximity_state,
|
||||
unsigned char *changed_axes,
|
||||
double *axes)
|
||||
const struct tablet_axes *axes)
|
||||
{
|
||||
struct libinput_event_tablet_tool *proximity_event;
|
||||
|
||||
|
|
@ -2217,10 +2234,8 @@ tablet_notify_proximity(struct libinput_device *device,
|
|||
.tool = tool,
|
||||
.tip_state = LIBINPUT_TABLET_TOOL_TIP_UP,
|
||||
.proximity_state = proximity_state,
|
||||
.axes = *axes,
|
||||
};
|
||||
memcpy(proximity_event->axes,
|
||||
axes,
|
||||
sizeof(proximity_event->axes));
|
||||
memcpy(proximity_event->changed_axes,
|
||||
changed_axes,
|
||||
sizeof(proximity_event->changed_axes));
|
||||
|
|
@ -2239,7 +2254,7 @@ tablet_notify_tip(struct libinput_device *device,
|
|||
struct libinput_tablet_tool *tool,
|
||||
enum libinput_tablet_tool_tip_state tip_state,
|
||||
unsigned char *changed_axes,
|
||||
double *axes)
|
||||
const struct tablet_axes *axes)
|
||||
{
|
||||
struct libinput_event_tablet_tool *tip_event;
|
||||
|
||||
|
|
@ -2252,10 +2267,8 @@ tablet_notify_tip(struct libinput_device *device,
|
|||
.tool = tool,
|
||||
.tip_state = tip_state,
|
||||
.proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN,
|
||||
.axes = *axes,
|
||||
};
|
||||
memcpy(tip_event->axes,
|
||||
axes,
|
||||
sizeof(tip_event->axes));
|
||||
memcpy(tip_event->changed_axes,
|
||||
changed_axes,
|
||||
sizeof(tip_event->changed_axes));
|
||||
|
|
@ -2271,7 +2284,7 @@ tablet_notify_button(struct libinput_device *device,
|
|||
uint64_t time,
|
||||
struct libinput_tablet_tool *tool,
|
||||
enum libinput_tablet_tool_tip_state tip_state,
|
||||
double *axes,
|
||||
const struct tablet_axes *axes,
|
||||
int32_t button,
|
||||
enum libinput_button_state state)
|
||||
{
|
||||
|
|
@ -2294,8 +2307,8 @@ tablet_notify_button(struct libinput_device *device,
|
|||
.seat_button_count = seat_button_count,
|
||||
.proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN,
|
||||
.tip_state = tip_state,
|
||||
.axes = *axes,
|
||||
};
|
||||
memcpy(button_event->axes, axes, sizeof(button_event->axes));
|
||||
|
||||
post_device_event(device,
|
||||
time,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue