[PATCH libinput] tablet: invert tilt axes when left-handed is enabled

Peter Hutterer peter.hutterer at who-t.net
Sun Dec 20 17:46:02 PST 2015


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-tablet.c |  4 ++++
 test/tablet.c      | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
index bf61411..50891e3 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -365,6 +365,8 @@ tablet_handle_tilt(struct tablet_dispatch *tablet,
 	if (bit_is_set(tablet->changed_axes, a)) {
 		absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_X);
 		tablet->axes[a] = normalize_tilt(absinfo);
+		if (device->left_handed.enabled)
+			tablet->axes[a] *= -1;
 	}
 	tilt.x = tablet->axes[a];
 
@@ -372,6 +374,8 @@ tablet_handle_tilt(struct tablet_dispatch *tablet,
 	if (bit_is_set(tablet->changed_axes, a)) {
 		absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_Y);
 		tablet->axes[a] = normalize_tilt(absinfo);
+		if (device->left_handed.enabled)
+			tablet->axes[a] *= -1;
 	}
 	tilt.y = tablet->axes[a];
 
diff --git a/test/tablet.c b/test/tablet.c
index a55b60a..87af814 100644
--- a/test/tablet.c
+++ b/test/tablet.c
@@ -1018,6 +1018,43 @@ START_TEST(no_left_handed)
 }
 END_TEST
 
+START_TEST(left_handed_tilt)
+{
+#if HAVE_LIBWACOM
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event *event;
+	struct libinput_event_tablet_tool *tev;
+	enum libinput_config_status status;
+	struct axis_replacement axes[] = {
+		{ ABS_DISTANCE, 10 },
+		{ ABS_TILT_X, 90 },
+		{ ABS_TILT_Y, 10 },
+		{ -1, -1 }
+	};
+	double tx, ty;
+
+	status = libinput_device_config_left_handed_set(dev->libinput_device, 1);
+	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
+
+	litest_drain_events(li);
+
+	litest_tablet_proximity_in(dev, 10, 10, axes);
+	libinput_dispatch(li);
+	event = libinput_get_event(li);
+	tev = litest_is_tablet_event(event,
+				     LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
+	tx = libinput_event_tablet_tool_get_tilt_x(tev);
+	ty = libinput_event_tablet_tool_get_tilt_y(tev);
+
+	ck_assert_double_lt(tx, 0);
+	ck_assert_double_gt(ty, 0);
+
+	libinput_event_destroy(event);
+#endif
+}
+END_TEST
+
 START_TEST(motion_event_state)
 {
 	struct litest_device *dev = litest_current_device();
@@ -2852,6 +2889,7 @@ litest_setup_tests(void)
 	litest_add("tablet:tilt", tilt_x, LITEST_TABLET|LITEST_TILT, LITEST_ANY);
 	litest_add("tablet:tilt", tilt_y, LITEST_TABLET|LITEST_TILT, LITEST_ANY);
 	litest_add_for_device("tablet:left_handed", left_handed, LITEST_WACOM_INTUOS);
+	litest_add_for_device("tablet:left_handed", left_handed_tilt, LITEST_WACOM_INTUOS);
 	litest_add_for_device("tablet:left_handed", no_left_handed, LITEST_WACOM_CINTIQ);
 	litest_add("tablet:normalization", normalization, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:pad", pad_buttons_ignored, LITEST_TABLET, LITEST_ANY);
-- 
2.5.0



More information about the wayland-devel mailing list