mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-08 06:38:02 +02:00
evdev: add a helper macro for the absinfo range
The range is (max - min + 1) because the kernel range is inclusive min and max. Let's fix that once and for all with a helper function. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
a5b6f4009b
commit
4effe6b1b9
8 changed files with 38 additions and 35 deletions
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
#include "quirks.h"
|
#include "quirks.h"
|
||||||
#include "evdev-mt-touchpad.h"
|
#include "evdev-mt-touchpad.h"
|
||||||
|
#include "util-input-event.h"
|
||||||
|
|
||||||
#define DEFAULT_TRACKPOINT_ACTIVITY_TIMEOUT ms2us(300)
|
#define DEFAULT_TRACKPOINT_ACTIVITY_TIMEOUT ms2us(300)
|
||||||
#define DEFAULT_TRACKPOINT_EVENT_TIMEOUT ms2us(40)
|
#define DEFAULT_TRACKPOINT_EVENT_TIMEOUT ms2us(40)
|
||||||
|
|
@ -3629,7 +3630,7 @@ tp_init_pressure(struct tp_dispatch *tp,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned int range = abs->maximum - abs->minimum;
|
double range = absinfo_range(abs);
|
||||||
|
|
||||||
/* Approximately the synaptics defaults */
|
/* Approximately the synaptics defaults */
|
||||||
hi = abs->minimum + 0.12 * range;
|
hi = abs->minimum + 0.12 * range;
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "evdev-tablet-pad.h"
|
#include "evdev-tablet-pad.h"
|
||||||
|
#include "util-input-event.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
@ -151,7 +152,7 @@ normalize_ring(const struct input_absinfo *absinfo)
|
||||||
current logical rotation, increasing clockwise to 1. Wacom has
|
current logical rotation, increasing clockwise to 1. Wacom has
|
||||||
0 on the left-most wheel position.
|
0 on the left-most wheel position.
|
||||||
*/
|
*/
|
||||||
double range = absinfo->maximum - absinfo->minimum + 1;
|
double range = absinfo_range(absinfo);
|
||||||
double value = (absinfo->value - absinfo->minimum) / range - 0.25;
|
double value = (absinfo->value - absinfo->minimum) / range - 0.25;
|
||||||
|
|
||||||
if (value < 0.0)
|
if (value < 0.0)
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "evdev-tablet.h"
|
#include "evdev-tablet.h"
|
||||||
|
#include "util-input-event.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
@ -334,8 +335,7 @@ tablet_update_tool(struct tablet_dispatch *tablet,
|
||||||
static inline double
|
static inline double
|
||||||
normalize_slider(const struct input_absinfo *absinfo)
|
normalize_slider(const struct input_absinfo *absinfo)
|
||||||
{
|
{
|
||||||
double range = absinfo->maximum - absinfo->minimum;
|
double value = (absinfo->value - absinfo->minimum) / absinfo_range(absinfo);
|
||||||
double value = (absinfo->value - absinfo->minimum) / range;
|
|
||||||
|
|
||||||
return value * 2 - 1;
|
return value * 2 - 1;
|
||||||
}
|
}
|
||||||
|
|
@ -343,8 +343,7 @@ normalize_slider(const struct input_absinfo *absinfo)
|
||||||
static inline double
|
static inline double
|
||||||
normalize_distance(const struct input_absinfo *absinfo)
|
normalize_distance(const struct input_absinfo *absinfo)
|
||||||
{
|
{
|
||||||
double range = absinfo->maximum - absinfo->minimum;
|
double value = (absinfo->value - absinfo->minimum) / absinfo_range(absinfo);
|
||||||
double value = (absinfo->value - absinfo->minimum) / range;
|
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
@ -374,8 +373,7 @@ normalize_pressure(const struct input_absinfo *absinfo,
|
||||||
static inline double
|
static inline double
|
||||||
adjust_tilt(const struct input_absinfo *absinfo)
|
adjust_tilt(const struct input_absinfo *absinfo)
|
||||||
{
|
{
|
||||||
double range = absinfo->maximum - absinfo->minimum + 1;
|
double value = (absinfo->value - absinfo->minimum) / absinfo_range(absinfo);
|
||||||
double value = (absinfo->value - absinfo->minimum) / range;
|
|
||||||
const int WACOM_MAX_DEGREES = 64;
|
const int WACOM_MAX_DEGREES = 64;
|
||||||
|
|
||||||
/* If resolution is nonzero, it's in units/radian. But require
|
/* If resolution is nonzero, it's in units/radian. But require
|
||||||
|
|
@ -433,8 +431,7 @@ static double
|
||||||
convert_to_degrees(const struct input_absinfo *absinfo, double offset)
|
convert_to_degrees(const struct input_absinfo *absinfo, double offset)
|
||||||
{
|
{
|
||||||
/* range is [0, 360[, i.e. range + 1 */
|
/* range is [0, 360[, i.e. range + 1 */
|
||||||
double range = absinfo->maximum - absinfo->minimum + 1;
|
double value = (absinfo->value - absinfo->minimum) / absinfo_range(absinfo);
|
||||||
double value = (absinfo->value - absinfo->minimum) / range;
|
|
||||||
|
|
||||||
return fmod(value * 360.0 + offset, 360.0);
|
return fmod(value * 360.0 + offset, 360.0);
|
||||||
}
|
}
|
||||||
|
|
@ -1077,7 +1074,7 @@ tool_set_bits(const struct tablet_dispatch *tablet,
|
||||||
static inline int
|
static inline int
|
||||||
axis_range_percentage(const struct input_absinfo *a, double percent)
|
axis_range_percentage(const struct input_absinfo *a, double percent)
|
||||||
{
|
{
|
||||||
return (a->maximum - a->minimum) * percent/100.0 + a->minimum;
|
return absinfo_range(a) * percent/100.0 + a->minimum;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
|
|
||||||
23
src/evdev.c
23
src/evdev.c
|
|
@ -378,8 +378,7 @@ evdev_transform_relative(struct evdev_device *device,
|
||||||
static inline double
|
static inline double
|
||||||
scale_axis(const struct input_absinfo *absinfo, double val, double to_range)
|
scale_axis(const struct input_absinfo *absinfo, double val, double to_range)
|
||||||
{
|
{
|
||||||
return (val - absinfo->minimum) * to_range /
|
return (val - absinfo->minimum) * to_range / absinfo_range(absinfo);
|
||||||
(absinfo->maximum - absinfo->minimum + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double
|
||||||
|
|
@ -1673,8 +1672,8 @@ evdev_fix_abs_resolution(struct evdev_device *device,
|
||||||
*/
|
*/
|
||||||
if (!evdev_read_attr_res_prop(device, &xres, &yres) &&
|
if (!evdev_read_attr_res_prop(device, &xres, &yres) &&
|
||||||
evdev_read_attr_size_prop(device, &widthmm, &heightmm)) {
|
evdev_read_attr_size_prop(device, &widthmm, &heightmm)) {
|
||||||
xres = (absx->maximum - absx->minimum)/widthmm;
|
xres = absinfo_range(absx)/widthmm;
|
||||||
yres = (absy->maximum - absy->minimum)/heightmm;
|
yres = absinfo_range(absy)/heightmm;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* libevdev_set_abs_resolution() changes the absinfo we already
|
/* libevdev_set_abs_resolution() changes the absinfo we already
|
||||||
|
|
@ -1843,10 +1842,8 @@ evdev_extract_abs_axes(struct evdev_device *device,
|
||||||
|
|
||||||
device->abs.absinfo_x = libevdev_get_abs_info(evdev, ABS_X);
|
device->abs.absinfo_x = libevdev_get_abs_info(evdev, ABS_X);
|
||||||
device->abs.absinfo_y = libevdev_get_abs_info(evdev, ABS_Y);
|
device->abs.absinfo_y = libevdev_get_abs_info(evdev, ABS_Y);
|
||||||
device->abs.dimensions.x = abs(device->abs.absinfo_x->maximum -
|
device->abs.dimensions.x = abs((int)absinfo_range(device->abs.absinfo_x));
|
||||||
device->abs.absinfo_x->minimum);
|
device->abs.dimensions.y = abs((int)absinfo_range(device->abs.absinfo_y));
|
||||||
device->abs.dimensions.y = abs(device->abs.absinfo_y->maximum -
|
|
||||||
device->abs.absinfo_y->minimum);
|
|
||||||
|
|
||||||
if (evdev_is_fake_mt_device(device) ||
|
if (evdev_is_fake_mt_device(device) ||
|
||||||
!libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) ||
|
!libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) ||
|
||||||
|
|
@ -1865,10 +1862,8 @@ evdev_extract_abs_axes(struct evdev_device *device,
|
||||||
|
|
||||||
device->abs.absinfo_x = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X);
|
device->abs.absinfo_x = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X);
|
||||||
device->abs.absinfo_y = libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y);
|
device->abs.absinfo_y = libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y);
|
||||||
device->abs.dimensions.x = abs(device->abs.absinfo_x->maximum -
|
device->abs.dimensions.x = abs((int)absinfo_range(device->abs.absinfo_x));
|
||||||
device->abs.absinfo_x->minimum);
|
device->abs.dimensions.y = abs((int)absinfo_range(device->abs.absinfo_y));
|
||||||
device->abs.dimensions.y = abs(device->abs.absinfo_y->maximum -
|
|
||||||
device->abs.absinfo_y->minimum);
|
|
||||||
device->is_mt = 1;
|
device->is_mt = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2562,8 +2557,8 @@ evdev_device_calibrate(struct evdev_device *device,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sx = device->abs.absinfo_x->maximum - device->abs.absinfo_x->minimum + 1;
|
sx = absinfo_range(device->abs.absinfo_x);
|
||||||
sy = device->abs.absinfo_y->maximum - device->abs.absinfo_y->minimum + 1;
|
sy = absinfo_range(device->abs.absinfo_y);
|
||||||
|
|
||||||
/* The transformation matrix is in the form:
|
/* The transformation matrix is in the form:
|
||||||
* [ a b c ]
|
* [ a b c ]
|
||||||
|
|
|
||||||
|
|
@ -66,3 +66,9 @@ input_event_set_time(struct input_event *e,
|
||||||
e->input_event_sec = tval.tv_sec;
|
e->input_event_sec = tval.tv_sec;
|
||||||
e->input_event_usec = tval.tv_usec;
|
e->input_event_usec = tval.tv_usec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline double
|
||||||
|
absinfo_range(const struct input_absinfo *abs)
|
||||||
|
{
|
||||||
|
return (double)(abs->maximum - abs->minimum + 1);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
#include "libinput-util.h"
|
#include "libinput-util.h"
|
||||||
#include "evdev-tablet.h"
|
#include "evdev-tablet.h"
|
||||||
#include "litest.h"
|
#include "litest.h"
|
||||||
|
#include "util-input-event.h"
|
||||||
|
|
||||||
static inline unsigned int
|
static inline unsigned int
|
||||||
pick_stylus_or_btn0(struct litest_device *dev)
|
pick_stylus_or_btn0(struct litest_device *dev)
|
||||||
|
|
@ -1998,11 +1999,11 @@ rotate_event(struct litest_device *dev, int angle_degrees)
|
||||||
|
|
||||||
abs = libevdev_get_abs_info(dev->evdev, ABS_TILT_X);
|
abs = libevdev_get_abs_info(dev->evdev, ABS_TILT_X);
|
||||||
ck_assert_notnull(abs);
|
ck_assert_notnull(abs);
|
||||||
tilt_center_x = (abs->maximum - abs->minimum + 1) / 2;
|
tilt_center_x = absinfo_range(abs) / 2;
|
||||||
|
|
||||||
abs = libevdev_get_abs_info(dev->evdev, ABS_TILT_Y);
|
abs = libevdev_get_abs_info(dev->evdev, ABS_TILT_Y);
|
||||||
ck_assert_notnull(abs);
|
ck_assert_notnull(abs);
|
||||||
tilt_center_y = (abs->maximum - abs->minimum + 1) / 2;
|
tilt_center_y = absinfo_range(abs) / 2;
|
||||||
|
|
||||||
x = cos(a) * 20 + tilt_center_x;
|
x = cos(a) * 20 + tilt_center_x;
|
||||||
y = sin(a) * 20 + tilt_center_y;
|
y = sin(a) * 20 + tilt_center_y;
|
||||||
|
|
@ -2098,7 +2099,7 @@ START_TEST(left_handed_artpen_rotation)
|
||||||
|
|
||||||
abs = libevdev_get_abs_info(dev->evdev, ABS_Z);
|
abs = libevdev_get_abs_info(dev->evdev, ABS_Z);
|
||||||
ck_assert_notnull(abs);
|
ck_assert_notnull(abs);
|
||||||
scale = (abs->maximum - abs->minimum + 1)/360.0;
|
scale = absinfo_range(abs)/360.0;
|
||||||
|
|
||||||
litest_event(dev, EV_KEY, BTN_TOOL_BRUSH, 1);
|
litest_event(dev, EV_KEY, BTN_TOOL_BRUSH, 1);
|
||||||
litest_event(dev, EV_ABS, ABS_MISC, 0x804); /* Art Pen */
|
litest_event(dev, EV_ABS, ABS_MISC, 0x804); /* Art Pen */
|
||||||
|
|
@ -3343,9 +3344,9 @@ START_TEST(mouse_wheel)
|
||||||
for (i = 2; i < 5; i++) {
|
for (i = 2; i < 5; i++) {
|
||||||
/* send x/y events to make sure we reset the wheel */
|
/* send x/y events to make sure we reset the wheel */
|
||||||
abs = libevdev_get_abs_info(dev->evdev, ABS_X);
|
abs = libevdev_get_abs_info(dev->evdev, ABS_X);
|
||||||
litest_event(dev, EV_ABS, ABS_X, (abs->maximum - abs->minimum)/i);
|
litest_event(dev, EV_ABS, ABS_X, absinfo_range(abs)/i);
|
||||||
abs = libevdev_get_abs_info(dev->evdev, ABS_Y);
|
abs = libevdev_get_abs_info(dev->evdev, ABS_Y);
|
||||||
litest_event(dev, EV_ABS, ABS_Y, (abs->maximum - abs->minimum)/i);
|
litest_event(dev, EV_ABS, ABS_Y, absinfo_range(abs)/i);
|
||||||
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
||||||
libinput_dispatch(li);
|
libinput_dispatch(li);
|
||||||
|
|
||||||
|
|
@ -3436,7 +3437,7 @@ START_TEST(airbrush_slider)
|
||||||
|
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
|
||||||
scale = abs->maximum - abs->minimum;
|
scale = absinfo_range(abs);
|
||||||
for (v = abs->minimum; v < abs->maximum; v += 8) {
|
for (v = abs->minimum; v < abs->maximum; v += 8) {
|
||||||
litest_event(dev, EV_ABS, ABS_WHEEL, v);
|
litest_event(dev, EV_ABS, ABS_WHEEL, v);
|
||||||
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
||||||
|
|
@ -3510,7 +3511,7 @@ START_TEST(artpen_rotation)
|
||||||
|
|
||||||
abs = libevdev_get_abs_info(dev->evdev, ABS_Z);
|
abs = libevdev_get_abs_info(dev->evdev, ABS_Z);
|
||||||
ck_assert_notnull(abs);
|
ck_assert_notnull(abs);
|
||||||
scale = (abs->maximum - abs->minimum + 1)/360.0;
|
scale = absinfo_range(abs)/360.0;
|
||||||
|
|
||||||
litest_event(dev, EV_KEY, BTN_TOOL_BRUSH, 1);
|
litest_event(dev, EV_KEY, BTN_TOOL_BRUSH, 1);
|
||||||
litest_event(dev, EV_ABS, ABS_MISC, 0x804); /* Art Pen */
|
litest_event(dev, EV_ABS, ABS_MISC, 0x804); /* Art Pen */
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
#include "libinput-util.h"
|
#include "libinput-util.h"
|
||||||
#include "evdev-tablet.h"
|
#include "evdev-tablet.h"
|
||||||
#include "litest.h"
|
#include "litest.h"
|
||||||
|
#include "util-input-event.h"
|
||||||
|
|
||||||
START_TEST(totem_type)
|
START_TEST(totem_type)
|
||||||
{
|
{
|
||||||
|
|
@ -143,9 +144,9 @@ START_TEST(totem_proximity_in_on_init)
|
||||||
const struct input_absinfo *abs;
|
const struct input_absinfo *abs;
|
||||||
|
|
||||||
abs = libevdev_get_abs_info(dev->evdev, ABS_MT_POSITION_X);
|
abs = libevdev_get_abs_info(dev->evdev, ABS_MT_POSITION_X);
|
||||||
w = (abs->maximum - abs->minimum + 1)/abs->resolution;
|
w = absinfo_range(abs)/abs->resolution;
|
||||||
abs = libevdev_get_abs_info(dev->evdev, ABS_MT_POSITION_Y);
|
abs = libevdev_get_abs_info(dev->evdev, ABS_MT_POSITION_Y);
|
||||||
h = (abs->maximum - abs->minimum + 1)/abs->resolution;
|
h = absinfo_range(abs)/abs->resolution;
|
||||||
|
|
||||||
litest_tablet_proximity_in(dev, 50, 50, NULL);
|
litest_tablet_proximity_in(dev, 50, 50, NULL);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
#include "shared.h"
|
#include "shared.h"
|
||||||
#include "util-macros.h"
|
#include "util-macros.h"
|
||||||
|
#include "util-input-event.h"
|
||||||
|
|
||||||
static volatile sig_atomic_t stop = 0;
|
static volatile sig_atomic_t stop = 0;
|
||||||
static struct tools_options options;
|
static struct tools_options options;
|
||||||
|
|
@ -149,7 +150,7 @@ normalize(struct libevdev *evdev, int code, int value)
|
||||||
if (!abs)
|
if (!abs)
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
|
||||||
return 1.0 * (value - abs->minimum)/(abs->maximum - abs->minimum + 1);
|
return 1.0 * (value - abs->minimum)/absinfo_range(abs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue