From: Peter Hutterer Date: Wed, 17 Feb 2016 23:42:27 +0000 (+1000) Subject: tablet: use the tilt resolution if we have it X-Git-Tag: 1.2.0~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0e17dc58aa2469909d9e21d889ff119b6170e15a;p=platform%2Fupstream%2Flibinput.git tablet: use the tilt resolution if we have it A nonzero resolution on the tilt axes is units/rad so we can calculate the physical min/max based. Uneven min/max ranges are supported. Signed-off-by: Peter Hutterer Reviewed-by: Jason Gerecke --- diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 1e5c2cd5..22ea1ebc 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -231,16 +231,25 @@ adjust_tilt(const struct input_absinfo *absinfo) double value = (absinfo->value - absinfo->minimum) / range; const int WACOM_MAX_DEGREES = 64; - /* Map to the (-1, 1) range */ - 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. - */ + /* If resolution is nonzero, it's in units/radian. But require + * a min/max less/greater than zero so we can assume 0 is the + * center */ + if (absinfo->resolution != 0 && + absinfo->maximum > 0 && + absinfo->minimum < 0) { + value = 180.0/M_PI * absinfo->value/absinfo->resolution; + } else { + /* 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. + */ + /* Map to the (-1, 1) range */ + value = (value * 2) - 1; + value *= WACOM_MAX_DEGREES; + } - return value * WACOM_MAX_DEGREES; + return value; } static inline int32_t diff --git a/test/tablet.c b/test/tablet.c index c5dc892e..ad6ac458 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -3298,7 +3298,8 @@ START_TEST(tilt_x) ck_assert_double_ge(tx, -52); ty = libinput_event_tablet_tool_get_tilt_y(tev); - ck_assert_double_eq(ty, -64); + ck_assert_double_ge(ty, -65); + ck_assert_double_lt(ty, -63); libinput_event_destroy(event); @@ -3320,7 +3321,8 @@ START_TEST(tilt_x) ck_assert_double_le(tx, expected_tx + 2); ty = libinput_event_tablet_tool_get_tilt_y(tev); - ck_assert_double_eq(ty, -64); + ck_assert_double_ge(ty, -65); + ck_assert_double_lt(ty, -63); libinput_event_destroy(event); @@ -3365,7 +3367,8 @@ START_TEST(tilt_y) ck_assert_double_ge(ty, -52); tx = libinput_event_tablet_tool_get_tilt_x(tev); - ck_assert_double_eq(tx, -64); + ck_assert_double_ge(tx, -65); + ck_assert_double_lt(tx, -63); libinput_event_destroy(event); @@ -3387,7 +3390,8 @@ START_TEST(tilt_y) ck_assert_double_le(ty, expected_ty + 2); tx = libinput_event_tablet_tool_get_tilt_x(tev); - ck_assert_double_eq(tx, -64); + ck_assert_double_ge(tx, -65); + ck_assert_double_lt(tx, -63); libinput_event_destroy(event);