summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2016-02-02 16:15:40 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2016-02-09 12:19:12 +1000
commitc9abcb2e1ccd1b056fedeca17687f7e49b72b8b7 (patch)
treeb577857bd53eb6543a291701f3075f470bb697ac /src
parent0e87dc9af2be104fd6cfa50e5f013068e42666d4 (diff)
tablet: change tilt axes to use degrees
The Wacom tilt range is 64 degrees so we map everything into that until we know otherwise. This commit also switches the tilt axes around to align the angles with the x/y orientation, i.e. tilting the top of the stylus towards the positive x axis now generates a positive x tilt. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Jason Gerecke <jason.gerecke@wacom.com>
Diffstat (limited to 'src')
-rw-r--r--src/evdev-tablet.c21
-rw-r--r--src/libinput-private.h7
-rw-r--r--src/libinput.h16
3 files changed, 33 insertions, 11 deletions
diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
index e684055b..9fd98403 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -225,13 +225,22 @@ normalize_pressure(const struct input_absinfo *absinfo,
}
static inline double
-normalize_tilt(const struct input_absinfo *absinfo)
+adjust_tilt(const struct input_absinfo *absinfo)
{
double range = absinfo->maximum - absinfo->minimum;
double value = (absinfo->value - absinfo->minimum) / range;
+ const int WACOM_MAX_DEGREES = 64;
/* Map to the (-1, 1) range */
- return (value * 2) - 1;
+ value = (value * 2) - 1;
+
+ /* Wacom supports physical [-64, 64] degrees, so map to that by
+ * default. If other tablets have a different physical range or
+ * nonzero physical offsets, they need extra treatment
+ * here.
+ */
+
+ return value * WACOM_MAX_DEGREES;
}
static inline int32_t
@@ -398,17 +407,17 @@ tablet_handle_slider(struct tablet_dispatch *tablet,
return tablet->axes.slider;
}
-static inline struct normalized_range_coords
+static inline struct tilt_degrees
tablet_handle_tilt(struct tablet_dispatch *tablet,
struct evdev_device *device)
{
- struct normalized_range_coords tilt;
+ struct tilt_degrees tilt;
const struct input_absinfo *absinfo;
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.tilt.x = normalize_tilt(absinfo);
+ tablet->axes.tilt.x = adjust_tilt(absinfo);
if (device->left_handed.enabled)
tablet->axes.tilt.x *= -1;
}
@@ -417,7 +426,7 @@ tablet_handle_tilt(struct tablet_dispatch *tablet,
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.tilt.y = normalize_tilt(absinfo);
+ tablet->axes.tilt.y = adjust_tilt(absinfo);
if (device->left_handed.enabled)
tablet->axes.tilt.y *= -1;
}
diff --git a/src/libinput-private.h b/src/libinput-private.h
index bc7000d7..8d2492aa 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -63,6 +63,11 @@ struct normalized_range_coords {
double x, y;
};
+/* A pair of angles in degrees */
+struct tilt_degrees {
+ double x, y;
+};
+
/* A threshold with an upper and lower limit */
struct threshold {
int upper;
@@ -74,7 +79,7 @@ struct tablet_axes {
struct normalized_coords delta;
double distance;
double pressure;
- struct normalized_range_coords tilt;
+ struct tilt_degrees tilt;
double rotation;
double slider;
double wheel;
diff --git a/src/libinput.h b/src/libinput.h
index d808c162..b14c2811 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -1648,12 +1648,16 @@ libinput_event_tablet_tool_get_distance(struct libinput_event_tablet_tool *event
* @ingroup event_tablet
*
* Returns the current tilt along the X axis of the tablet's current logical
- * orientation, normalized to the range [-1, 1].
+ * orientation, in degrees off the tablet's z axis. That is, if the tool is
+ * perfectly orthogonal to the tablet, the tilt angle is 0. When the top
+ * tilts towards the logical top/left of the tablet, the x/y tilt angles are
+ * negative, if the top tilts towards the logical bottom/right of the
+ * tablet, the x/y tilt angles are positive.
*
* If this axis does not exist on the current tool, this function returns 0.
*
* @param event The libinput tablet tool event
- * @return The current value of the the axis
+ * @return The current value of the the axis in degrees
*/
double
libinput_event_tablet_tool_get_tilt_x(struct libinput_event_tablet_tool *event);
@@ -1662,12 +1666,16 @@ libinput_event_tablet_tool_get_tilt_x(struct libinput_event_tablet_tool *event);
* @ingroup event_tablet
*
* Returns the current tilt along the Y axis of the tablet's current logical
- * orientation, normalized to the range [-1, 1].
+ * orientation, in degrees off the tablet's z axis. That is, if the tool is
+ * perfectly orthogonal to the tablet, the tilt angle is 0. When the top
+ * tilts towards the logical top/left of the tablet, the x/y tilt angles are
+ * negative, if the top tilts towards the logical bottom/right of the
+ * tablet, the x/y tilt angles are positive.
*
* If this axis does not exist on the current tool, this function returns 0.
*
* @param event The libinput tablet tool event
- * @return The current value of the the axis
+ * @return The current value of the the axis in degrees
*/
double
libinput_event_tablet_tool_get_tilt_y(struct libinput_event_tablet_tool *event);