diff mbox series

[3/5] HID: wacom: Support touchrings with relative motion

Message ID 20240730155159.3156-3-jason.gerecke@wacom.com (mailing list archive)
State New
Delegated to: Jiri Kosina
Headers show
Series [1/5] HID: wacom: Defer calculation of resolution until resolution_code is known | expand

Commit Message

Gerecke, Jason July 30, 2024, 3:51 p.m. UTC
From: Jason Gerecke <jason.gerecke@wacom.com>

If a touchring is configured to send relative events (e.g. +1 or -1 every
time some bit of rotational distance is covered), we should similarly
send relative events up to userspace. Previous non-HID tablets used
REL_WHEEL to send this kind of information, so we opt to use this same
axis since userspace (xf86-input-wacom and libinput) already expects
this kind of behavior from the Wacom kernel driver.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
---
 drivers/hid/wacom_wac.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index 7e81c93d18229..96b158a94ef9c 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -1911,6 +1911,7 @@  static void wacom_map_usage(struct input_dev *input, struct hid_usage *usage,
 		}
 		input_abs_set_res(input, code, resolution);
 		break;
+	case EV_REL:
 	case EV_KEY:
 	case EV_MSC:
 	case EV_SW:
@@ -2047,7 +2048,10 @@  static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
 		features->device_type |= WACOM_DEVICETYPE_PAD;
 		break;
 	case WACOM_HID_WD_TOUCHRING:
-		wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
+		if (field->flags & HID_MAIN_ITEM_RELATIVE)
+			wacom_map_usage(input, usage, field, EV_REL, REL_WHEEL, 0);
+		else
+			wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
 		features->device_type |= WACOM_DEVICETYPE_PAD;
 		break;
 	case WACOM_HID_WD_TOUCHRINGSTATUS:
@@ -2112,7 +2116,10 @@  static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field
 		return;
 
 	if (wacom_equivalent_usage(field->physical) == HID_DG_TABLETFUNCTIONKEY) {
-		if (usage->hid != WACOM_HID_WD_TOUCHRING)
+		bool is_abs_touchring = usage->hid == WACOM_HID_WD_TOUCHRING &&
+					!(field->flags & HID_MAIN_ITEM_RELATIVE);
+
+		if (!is_abs_touchring)
 			wacom_wac->hid_data.inrange_state |= value;
 	}
 
@@ -2165,6 +2172,15 @@  static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field
 				 hdev->product == 0x3AA)
 				value = wacom_offset_rotation(input, usage, value, 1, 2);
 		}
+		else if (field->flags & HID_MAIN_ITEM_RELATIVE) {
+			/* We must invert the sign for vertical
+			 * relative scrolling. Clockwise rotation
+			 * produces positive values from HW, but
+			 * userspace treats positive REL_WHEEL as a
+			 * scroll *up*!
+			 */
+			value = -value;
+		}
 		else {
 			value = wacom_offset_rotation(input, usage, value, 1, 4);
 		}