Skip to content

Commit 11e2849

Browse files
committed
HID: wacom: Support devices with two touchrings
JIRA: https://issues.redhat.com/browse/RHEL-102058 Upstream Status: since v6.12 commit 19591e1 Author: Jason Gerecke <jason.gerecke@wacom.com> Date: Tue Jul 30 08:51:59 2024 -0700 HID: wacom: Support devices with two touchrings If a device has more than one touchring, we want to be sure that userspace is able to distinguish them. Following previous standards, the first absolute ring will be reported as ABS_WHEEL and the second as ABS_THROTTLE. Relative rings will use REL_WHEEL_HI_RES / REL_WHEEL for the first and REL_HWHEEL_HI_RES / REL_HWHEEL for the second. Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com> Signed-off-by: Jiri Kosina <jkosina@suse.com> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
1 parent d8bf393 commit 11e2849

File tree

2 files changed

+49
-12
lines changed

2 files changed

+49
-12
lines changed

drivers/hid/wacom_wac.c

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,10 +2049,21 @@ static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
20492049
break;
20502050
case WACOM_HID_WD_TOUCHRING:
20512051
if (field->flags & HID_MAIN_ITEM_RELATIVE) {
2052-
wacom_map_usage(input, usage, field, EV_REL, REL_WHEEL_HI_RES, 0);
2053-
set_bit(REL_WHEEL, input->relbit);
2052+
wacom_wac->relring_count++;
2053+
if (wacom_wac->relring_count == 1) {
2054+
wacom_map_usage(input, usage, field, EV_REL, REL_WHEEL_HI_RES, 0);
2055+
set_bit(REL_WHEEL, input->relbit);
2056+
}
2057+
else if (wacom_wac->relring_count == 2) {
2058+
wacom_map_usage(input, usage, field, EV_REL, REL_HWHEEL_HI_RES, 0);
2059+
set_bit(REL_HWHEEL, input->relbit);
2060+
}
20542061
} else {
2055-
wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
2062+
wacom_wac->absring_count++;
2063+
if (wacom_wac->absring_count == 1)
2064+
wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
2065+
else if (wacom_wac->absring_count == 2)
2066+
wacom_map_usage(input, usage, field, EV_ABS, ABS_THROTTLE, 0);
20562067
}
20572068
features->device_type |= WACOM_DEVICETYPE_PAD;
20582069
break;
@@ -2175,14 +2186,37 @@ static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field
21752186
value = wacom_offset_rotation(input, usage, value, 1, 2);
21762187
}
21772188
else if (field->flags & HID_MAIN_ITEM_RELATIVE) {
2178-
/* We must invert the sign for vertical
2179-
* relative scrolling. Clockwise rotation
2180-
* produces positive values from HW, but
2181-
* userspace treats positive REL_WHEEL as a
2182-
* scroll *up*!
2183-
*/
2184-
int hires_value = -value * 120 / usage->resolution_multiplier;
2185-
int *ring_value = &wacom_wac->hid_data.ring_value;
2189+
int hires_value = value * 120 / usage->resolution_multiplier;
2190+
int *ring_value;
2191+
int lowres_code;
2192+
2193+
if (usage->code == REL_WHEEL_HI_RES) {
2194+
/* We must invert the sign for vertical
2195+
* relative scrolling. Clockwise
2196+
* rotation produces positive values
2197+
* from HW, but userspace treats
2198+
* positive REL_WHEEL as a scroll *up*!
2199+
*/
2200+
hires_value = -hires_value;
2201+
ring_value = &wacom_wac->hid_data.ring_value;
2202+
lowres_code = REL_WHEEL;
2203+
}
2204+
else if (usage->code == REL_HWHEEL_HI_RES) {
2205+
/* No need to invert the sign for
2206+
* horizontal relative scrolling.
2207+
* Clockwise rotation produces positive
2208+
* values from HW and userspace treats
2209+
* positive REL_HWHEEL as a scroll
2210+
* right.
2211+
*/
2212+
ring_value = &wacom_wac->hid_data.ring2_value;
2213+
lowres_code = REL_HWHEEL;
2214+
}
2215+
else {
2216+
hid_err(wacom->hdev, "unrecognized relative wheel with code %d\n",
2217+
usage->code);
2218+
break;
2219+
}
21862220

21872221
value = hires_value;
21882222
*ring_value += hires_value;
@@ -2193,7 +2227,7 @@ static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field
21932227
if (*ring_value >= 120 || *ring_value <= -120) {
21942228
int clicks = *ring_value / 120;
21952229

2196-
input_event(input, usage->type, REL_WHEEL, clicks);
2230+
input_event(input, usage->type, lowres_code, clicks);
21972231
*ring_value -= clicks * 120;
21982232
}
21992233
}

drivers/hid/wacom_wac.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ struct hid_data {
313313
int height;
314314
int id;
315315
int ring_value;
316+
int ring2_value;
316317
int cc_report;
317318
int cc_index;
318319
int cc_value_index;
@@ -356,6 +357,8 @@ struct wacom_wac {
356357
int num_contacts_left;
357358
u8 bt_features;
358359
u8 bt_high_speed;
360+
u8 absring_count;
361+
u8 relring_count;
359362
int mode_report;
360363
int mode_value;
361364
struct hid_data hid_data;

0 commit comments

Comments
 (0)