Input: add ABS_TWIST and support it in HID and Wacom
Subsystems (4)
v2 cover Input: add ABS_TWIST and support it in HID and Wacom
Some styli can report rotation along their long ("barrel") axis, commonly referred to as "twist". While the HID specification defines this usage as HID_DG_TWIST (0x000d0041) in the Digitizers page, there is currently no corresponding evdev axis code to expose it to userspace.
Because evdev has no MSC_SCAN equivalent for axes, drivers and OEMs currently work around this by mapping stylus twist onto unrelated axes such as ABS_Z or ABS_RZ. As a result, userspace input stacks must maintain device-specific workarounds to know which axis carries twist.
This series introduces a dedicated ABS_TWIST (0x1d) axis for single-tool devices such as styli and wires it up in the HID subsystem:
1. Input: Define ABS_TWIST (0x1d) in input-event-codes.h, add its name to hid-debug.c, and document its semantics in event-codes.rst.
2. HID: Map HID_DG_TWIST (0x000d0041) to ABS_TWIST in hid-input, compute its resolution in units/radian, and add KUnit test coverage.
3. HID: wacom: Report un-offset pen twist on ABS_TWIST (zero at top/-Y) while keeping the shifted ABS_Z axis (zero at left/-X) for backwards compatibility with existing applications.
v1: https://lore.kernel.org/linux-input/[email protected]/
Changes in v2:
- Rebased onto v7.4-rc4 (8d7fe9885c62, including hid-for-linus-2026112301).
- Patch 1 (Dmitry):
- Moved ABS_TWIST directly below ABS_SND_PROFILE in event-codes.rst.
- Expanded event-codes.rst with precise value semantics: clockwise rotation when viewed down the barrel toward the surface, zero when the neutral reference faces the top (-Y, north) of the surface, support for both non-negative [0, 360) and signed [-180, 180) full-revolution ranges with wraparound, units/radian resolution, and the distinction from ABS_MT_ORIENTATION.
- Patch 2:
- No changes.
- Patch 3 (Jason):
- Added comments explaining the forced angular resolution_code in wacom_map_usage(), the order-dependent double-mapping in wacom_wac_pen_usage_mapping(), and explicit ABS_Z emission in wacom_wac_pen_event().
- Emit un-offset twist (zero at top/-Y, matching ABS_TWIST documentation and HID_DG_TWIST) on ABS_TWIST across all three pen rotation paths, while preserving the +1/4 revolution offset (zero at left/-X) on legacy ABS_Z.
Testing:
Hardware-tested with a Wacom Intuos Pro and Art Pen 2 (HID_GENERIC path): verified ABS_TWIST reports 0 when the barrel button points to the top (-Y) edge, increases clockwise when viewed from eraser toward tip, tracks ABS_Z with a constant +450 (+90 deg) offset, resets cleanly to 0 on proximity exit, and exposes min -900, max 899, resolution 287.
Siarhei Vishniakou (3):
Input: add ABS_TWIST event code
HID: input: map Digitizers Twist usage to ABS_TWIST
HID: wacom: report ABS_TWIST alongside ABS_Z for pen twist
Documentation/input/event-codes.rst | 23 +++++++ drivers/hid/hid-debug.c | 1 + drivers/hid/hid-input-test.c | 87 ++++++++++++++++++++++++ drivers/hid/hid-input.c | 5 ++ drivers/hid/wacom_wac.c | 94 ++++++++++++++++++++------ include/uapi/linux/input-event-codes.h | 1 + 6 files changed, 189 insertions(+), 22 deletions(-)
base-commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
Signature · 1 line
2.56.1.911.g883d8bcb20-goog
PATCH v2 1/3 Input: add ABS_TWIST event code
Some styli can report the rotation along their long ("barrel") axis. This is typically referred to as "twist".
Unlike ABS_MT_ORIENTATION (which describes the 2D alignment of the contact ellipse on the surface, analogous to stylus azimuth/tilt projected onto the surface), twist captures the roll of a tool around its own longitudinal axis independently of tilt or azimuth.
In the HID usage pages, twist is already supported as HID_DG_TWIST (0x000d0041). However, this usage is not reported to userspace via the evdev interface today, since there is no MSC_SCAN equivalent for axes.
Peripheral OEMs get around this today by mapping this axis to other axes like ABS_Z or ABS_RZ. This is not a valid way to report twist.
As a result, userspace programs that would like to support twist must account for the various ways specific OEMs map this, since there is no generic axis for this.
Unify this behaviour by introducing a new axis, ABS_TWIST (0x1d). This axis applies to single-pointer devices (such as styli), as opposed to per-slot multi-touch devices (which would use an ABS_MT_* axis).
Document ABS_TWIST in event-codes.rst with its value semantics:
clockwise-increasing when viewed down the tool's major axis toward the surface, 0 aligned toward the top (-Y, north) of the interaction surface matching HID_DG_TWIST, supporting either non-negative [0, maximum] or signed [minimum, maximum] full-revolution ranges, and resolution in units/radian.
---
Changes since v1:
- Moved ABS_TWIST directly below ABS_SND_PROFILE in event-codes.rst (Dmitry).
- Expanded event-codes.rst documentation with precise value semantics:
clockwise-increasing direction viewed down the barrel toward the surface, 0 aligned toward the top (-Y, north) of the surface, non-negative [0, 360) and signed [-180, 180) ranges, wraparound behavior, and distinction from ABS_MT_ORIENTATION (Dmitry).
Documentation/input/event-codes.rst | 23 +++++++++++++++++++++++ drivers/hid/hid-debug.c | 1 + include/uapi/linux/input-event-codes.h | 1 + 3 files changed, 25 insertions(+)
Documentation/input/event-codes.rst +23 -0
@@ -247,6 +247,29 @@ A few EV_ABS codes have special meanings: An event is emitted only when the selected profile changes, indicating the newly selected profile value. +* ABS_TWIST: + + - Used to describe the rotation of a tool (such as a stylus) around its own + major (barrel) axis. Unlike ABS_MT_ORIENTATION (which describes the 2D + orientation of a contact ellipse on the surface), ABS_TWIST reports the + tool's roll around its longitudinal axis independently of tilt or azimuth. + - Values increase for clockwise rotation and decrease for counter-clockwise + rotation when viewed looking down the tool's major axis toward the + interaction surface (e.g., from the eraser end of a stylus toward the tip). + - A value of 0 corresponds to the tool's neutral reference orientation (e.g., + its primary barrel button or flat edge) facing toward the top (-Y, north) + of the interaction surface. + - The range reported in struct input_absinfo may be either non-negative or + signed. A non-negative range ([0, maximum]) covers [0, 360) degrees. + A signed range ([minimum, maximum]) is centered at 0 and covers + [-180, 180) degrees. + - Unless the hardware only supports a restricted angular range, the + [minimum, maximum] range spans one full revolution and wraps between + maximum and minimum. + - If the resolution is non-zero, the twist data is in units/radian. If the + resolution is zero, userspace may assume the full [minimum, maximum] range + represents one full revolution. + * ABS_MT_<name>: - Used to describe multitouch input events. Please see
drivers/hid/hid-debug.c +1 -0
@@ -3518,6 +3518,7 @@ static const char *absolutes[ABS_CNT] = { [ABS_HAT3Y] = "Hat 3Y", [ABS_PRESSURE] = "Pressure", [ABS_DISTANCE] = "Distance", [ABS_TILT_X] = "XTilt", [ABS_TILT_Y] = "YTilt", [ABS_TOOL_WIDTH] = "ToolWidth", + [ABS_TWIST] = "Twist", [ABS_VOLUME] = "Volume", [ABS_PROFILE] = "Profile", [ABS_SND_PROFILE] = "SoundProfile", [ABS_MISC] = "Misc",
include/uapi/linux/input-event-codes.h +1 -0
@@ -892,6 +892,7 @@#define ABS_TILT_X 0x1a#define ABS_TILT_Y 0x1b#define ABS_TOOL_WIDTH 0x1c +#define ABS_TWIST 0x1d#define ABS_VOLUME 0x20#define ABS_PROFILE 0x21
Signature · 1 line
2.56.1.911.g883d8bcb20-goog
Dmitry Torokhov
maintainerRe: [PATCH v2 1/3] Input: add ABS_TWIST event code
Quoted 31 lines · Siarhei Vishniakou
Some styli can report the rotation along their long ("barrel") axis. This is typically referred to as "twist".
Unlike
ABS_MT_ORIENTATION(which describes the 2D alignment of the contact ellipse on the surface, analogous to stylus azimuth/tilt projected onto the surface), twist captures the roll of a tool around its own longitudinal axis independently of tilt or azimuth.In the HID usage pages, twist is already supported as
HID_DG_TWIST(0x000d0041). However, this usage is not reported to userspace via the evdev interface today, since there is noMSC_SCANequivalent for axes.Peripheral OEMs get around this today by mapping this axis to other axes like
ABS_ZorABS_RZ. This is not a valid way to report twist.As a result, userspace programs that would like to support twist must account for the various ways specific OEMs map this, since there is no generic axis for this.
Unify this behaviour by introducing a new axis,
ABS_TWIST(0x1d). This axis applies to single-pointer devices (such as styli), as opposed to per-slot multi-touch devices (which would use an ABS_MT_* axis).Document
ABS_TWISTinevent-codes.rstwith its value semantics:
clockwise-increasing when viewed down the tool's major axis toward the surface, 0 aligned toward the top (-Y, north) of the interaction surface matchingHID_DG_TWIST, supporting either non-negative [0, maximum] or signed [minimum, maximum] full-revolution ranges, and resolution in units/radian.Signed-off-by Siarhei Vishniakou <[email protected]>
Quoted 9 lines
---
Changes since v1:
- MovedABS_TWISTdirectly belowABS_SND_PROFILEinevent-codes.rst(Dmitry).
- Expandedevent-codes.rstdocumentation with precise value semantics:
clockwise-increasing direction viewed down the barrel toward the surface, 0 aligned toward the top (-Y, north) of the surface, non-negative [0, 360) and signed [-180, 180) ranges, wraparound behavior, and distinction fromABS_MT_ORIENTATION(Dmitry).
I'd like Peter (CCed) to take a look at this too...
Quoted 64 lines
Documentation/input/event-codes.rst | 23 +++++++++++++++++++++++ drivers/hid/hid-debug.c | 1 + include/uapi/linux/input-event-codes.h | 1 + 3 files changed, 25 insertions(+)Documentation/input/event-codes.rst +23
-0@@ -247,6 +247,29 @@ A few EV_ABS codes have special meanings: An event is emitted only when the selected profile changes, indicating the newly selected profile value. +* ABS_TWIST: + + - Used to describe the rotation of a tool (such as a stylus) around its own + major (barrel) axis. Unlike ABS_MT_ORIENTATION (which describes the 2D + orientation of a contact ellipse on the surface), ABS_TWIST reports the + tool's roll around its longitudinal axis independently of tilt or azimuth. + - Values increase for clockwise rotation and decrease for counter-clockwise + rotation when viewed looking down the tool's major axis toward the + interaction surface (e.g., from the eraser end of a stylus toward the tip). + - A value of 0 corresponds to the tool's neutral reference orientation (e.g., + its primary barrel button or flat edge) facing toward the top (-Y, north) + of the interaction surface. + - The range reported in struct input_absinfo may be either non-negative or + signed. A non-negative range ([0, maximum]) covers [0, 360) degrees. + A signed range ([minimum, maximum]) is centered at 0 and covers + [-180, 180) degrees. + - Unless the hardware only supports a restricted angular range, the + [minimum, maximum] range spans one full revolution and wraps between + maximum and minimum. + - If the resolution is non-zero, the twist data is in units/radian. If the + resolution is zero, userspace may assume the full [minimum, maximum] range + represents one full revolution. + * ABS_MT_<name>: - Used to describe multitouch input events. Please seedrivers/hid/hid-debug.c +1
-0@@ -3518,6 +3518,7 @@ static const char *absolutes[ABS_CNT] = { [ABS_HAT3Y] = "Hat 3Y", [ABS_PRESSURE] = "Pressure", [ABS_DISTANCE] = "Distance", [ABS_TILT_X] = "XTilt", [ABS_TILT_Y] = "YTilt", [ABS_TOOL_WIDTH] = "ToolWidth", + [ABS_TWIST] = "Twist", [ABS_VOLUME] = "Volume", [ABS_PROFILE] = "Profile", [ABS_SND_PROFILE] = "SoundProfile", [ABS_MISC] = "Misc",include/uapi/linux/input-event-codes.h +1
-0@@ -892,6 +892,7 @@#define ABS_TILT_X 0x1a#define ABS_TILT_Y 0x1b#define ABS_TOOL_WIDTH 0x1c +#define ABS_TWIST 0x1d#define ABS_VOLUME 0x20#define ABS_PROFILE 0x21
Signature · 1 line
Dmitry
PATCH v2 2/3 HID: input: map Digitizers Twist usage to ABS_TWIST
In reply to Siarhei VishniakouThe axis ABS_TWIST is used to report the "twist" (or barrel) rotation of a stylus.
Map the HID Digitizers Twist usage (0x000d0041) to ABS_TWIST in hid-input, and calculate its axis resolution in units/radian.
---
Changes since v1:
- No changes (rebased cleanly onto v7.4-rc4).
drivers/hid/hid-input-test.c | 87 ++++++++++++++++++++++++++++++++++++ drivers/hid/hid-input.c | 5 +++ 2 files changed, 92 insertions(+)
drivers/hid/hid-input-test.c +87 -0
@@ -67,9 +67,96 @@ static void hid_test_input_get_battery_property(struct kunit *test)KUNIT_EXPECT_EQ (test, val.intval,POWER_SUPPLY_STATUS_DISCHARGING ); } +static void hid_test_input_calc_abs_res_twist (struct kunit *test) +{ +struct hid_field field = { + .logical_minimum =0 , + .logical_maximum =3599 , + .physical_minimum =0 , + .physical_maximum =3599 , + .unit =0x14 ,/* Degrees */ + .unit_exponent =-1 , + }; + +/* 0..3599 over 0..359.9 degrees -> ~573 units/radian */ +KUNIT_EXPECT_EQ (test,hidinput_calc_abs_res (&field,ABS_TWIST ),573 ); + +/* 0..359 over 0..359 degrees -> ~57 units/radian */ + field.logical_maximum =359 ; + field.physical_maximum =359 ; + field.unit_exponent =0 ; +KUNIT_EXPECT_EQ (test,hidinput_calc_abs_res (&field,ABS_TWIST ),57 ); + +/* 0..628 over 0..6.28 radians -> 100 units/radian */ + field.logical_maximum =628 ; + field.physical_maximum =628 ; + field.unit =0x12 ;/* Radians */ + field.unit_exponent =-2 ; +KUNIT_EXPECT_EQ (test,hidinput_calc_abs_res (&field,ABS_TWIST ),100 ); + +/* Linear unit (centimeters) is invalid for ABS_TWIST */ + field.unit =0x11 ; +KUNIT_EXPECT_EQ (test,hidinput_calc_abs_res (&field,ABS_TWIST ),0 ); +} + +static void hid_test_input_configure_twist_usage (struct kunit *test) +{ +struct hid_device *dev; +struct hid_driver *drv; +struct hid_input *hidinput; +struct input_dev *input; +struct hid_field *field; +struct hid_usage *usage; + + dev =kunit_kzalloc (test,sizeof (*dev),GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, dev); + + drv =kunit_kzalloc (test,sizeof (*drv),GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, drv); + dev->driver = drv; + + input =kunit_kzalloc (test,sizeof (*input),GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, input); + input->absinfo =kunit_kcalloc (test,ABS_CNT ,sizeof (*input->absinfo),GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, input->absinfo); +input_set_drvdata (input, dev); + + hidinput =kunit_kzalloc (test,sizeof (*hidinput),GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, hidinput); + hidinput->input = input; + + field =kunit_kzalloc (test,sizeof (*field),GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, field); + field->report_count =1 ; + field->logical_minimum =0 ; + field->logical_maximum =3599 ; + field->physical_minimum =0 ; + field->physical_maximum =3599 ; + field->unit =0x14 ;/* Degrees */ + field->unit_exponent =-1 ; + field->usages_priorities =kunit_kzalloc (test,sizeof (int ),GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, field->usages_priorities); + + usage =kunit_kzalloc (test,sizeof (*usage),GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, usage); + usage->hid =HID_DG_TWIST ; + +hidinput_configure_usage (hidinput, field, usage,0 ); + +KUNIT_EXPECT_EQ (test, usage->type,EV_ABS ); +KUNIT_EXPECT_EQ (test, usage->code,ABS_TWIST ); +KUNIT_EXPECT_TRUE (test,test_bit (EV_ABS , input->evbit)); +KUNIT_EXPECT_TRUE (test,test_bit (ABS_TWIST , input->absbit)); +KUNIT_EXPECT_EQ (test,input_abs_get_min (input,ABS_TWIST ),0 ); +KUNIT_EXPECT_EQ (test,input_abs_get_max (input,ABS_TWIST ),3599 ); +KUNIT_EXPECT_EQ (test,input_abs_get_res (input,ABS_TWIST ),573 ); +} +static struct kunit_case hid_input_tests[] = {KUNIT_CASE (hid_test_input_update_battery_charge_status),KUNIT_CASE (hid_test_input_get_battery_property), +KUNIT_CASE (hid_test_input_calc_abs_res_twist), +KUNIT_CASE (hid_test_input_configure_twist_usage), { } };
drivers/hid/hid-input.c +5 -0
@@ -291,6 +291,7 @@ __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code)case ABS_WHEEL :case ABS_TILT_X :case ABS_TILT_Y : +case ABS_TWIST :if (field->unit ==0x14 ) {/* If degrees */ /* Convert to radians */ prev = logical_extents;
@@ -1064,6 +1065,10 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fielmap_abs_clear (ABS_TILT_Y );break ; +case 0x41 :/* Twist */ +map_abs_clear (ABS_TWIST ); +break ; +case 0x33 :/* Touch */ case 0x42 :/* TipSwitch */ case 0x43 :/* TipSwitch2 */
Signature · 1 line
2.56.1.911.g883d8bcb20-goog
PATCH v2 3/3 HID: wacom: report ABS_TWIST alongside ABS_Z for pen twist
In reply to Siarhei VishniakouHistorically, Wacom tablets reported stylus barrel rotation (twist) via ABS_Z because a dedicated evdev axis did not exist, with the zero point offset by +1/4 revolution so that 0 aligns with the tablet's left (-X) edge for compatibility with legacy userspace.
Now that ABS_TWIST is defined, report pen twist on ABS_TWIST using the standard HID coordinate system (zero at the top/-Y edge, increasing clockwise), while keeping the shifted ABS_Z axis for backwards compatibility with existing applications.
---
Changes since v1:
- Added comments explaining the forced angular resolution_code in wacom_map_usage(), the order-dependent double-mapping in wacom_wac_pen_usage_mapping(), and explicit ABS_Z emission in wacom_wac_pen_event() (Jason).
- Emit un-offset twist (zero at top/-Y, matching ABS_TWIST documentation and HID_DG_TWIST) on ABS_TWIST across all three pen rotation paths (wacom_intuos_general, wacom_intuos_pro2_bt_pen, wacom_wac_pen_event), while preserving the +1/4 revolution offset (zero at left/-X) on ABS_Z for backwards compatibility.
drivers/hid/wacom_wac.c | 94 +++++++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 22 deletions(-)
drivers/hid/wacom_wac.c +72 -22
@@ -769,8 +769,10 @@ static void wacom_exit_report(struct wacom_wac *wacom)input_report_key (input,BTN_STYLUS2 ,0 );input_report_key (input,BTN_TOUCH ,0 );input_report_abs (input,ABS_WHEEL ,0 ); -if (features->type >=INTUOS3S ) +if (features->type >=INTUOS3S ) {input_report_abs (input,ABS_Z ,0 ); +input_report_abs (input,ABS_TWIST ,0 ); + } }input_report_key (input, wacom->tool[idx],0 );input_report_abs (input,ABS_MISC ,0 );/* reset tool id */
@@ -943,11 +945,22 @@ static int wacom_intuos_general(struct wacom_wac *wacom)case 0x05 :/* Rotation packet */ if (features->type >=INTUOS3S ) { +int twist, rot; +/* I3 marker pen rotation */ t = (data[6 ] <<3 ) | ((data[7 ] >>5 ) &7 ); - t = (data[7 ] &0x20 ) ? ((t >900 ) ? ((t-1 ) /2 -1350 ) : - ((t-1 ) /2 +450 )) : (450 - t /2 ) ; -input_report_abs (input,ABS_Z , t); + twist = (data[7 ] &0x20 ) ? (int )((t -1 ) /2 ) : + -(int )(t /2 ); +input_report_abs (input,ABS_TWIST , twist); + +/* +* Shift zero point from top (-Y) to left (-X) for +* legacy ABS_Z compatibility. +*/ + rot = twist +450 ; +if (rot >899 ) + rot -=1800 ; +input_report_abs (input,ABS_Z , rot); }else {/* 4D mouse 2nd packet */ t = (data[6 ] <<3 ) | ((data[7 ] >>5 ) &7 );
@@ -1365,10 +1378,12 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)if (wacom->features.type ==INTUOSP2_BT || wacom->features.type ==INTUOSP2S_BT ) { -/* Fix rotation alignment: userspace expects zero at left */ -int16_t rotation = - (int16_t )get_unaligned_le16 (&frame[9 ]); - rotation +=1800 /4 ; +s16 twist = (s16 )get_unaligned_le16 (&frame[9 ]); +/* +* Legacy ABS_Z expects zero at left (-X), while +* hardware and ABS_TWIST use zero at top (-Y). +*/ +int rotation = twist +1800 /4 ;if (rotation >899 ) rotation -=1800 ;
@@ -1377,6 +1392,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom) (signed char)frame[7]);input_report_abs (pen_input,ABS_TILT_Y , (signed char )frame[8 ]); +input_report_abs (pen_input,ABS_TWIST , twist);input_report_abs (pen_input,ABS_Z , rotation);input_report_abs (pen_input,ABS_WHEEL ,get_unaligned_le16 (&frame[11 ]));
@@ -1914,9 +1930,14 @@ static void wacom_map_usage(struct input_dev *input, struct hid_usage *usage,int resolution_code = code;int resolution; -if (equivalent_usage ==HID_DG_TWIST ) { - resolution_code =ABS_RZ ; - } +/* +* HID_DG_TWIST is double-mapped to both ABS_Z (for backwards +* compatibility) and ABS_TWIST. Force a radial axis code here so +* hidinput_calc_abs_res() computes angular resolution (units/radian) +* even when configuring ABS_Z, which it otherwise treats as linear. +*/ +if (equivalent_usage ==HID_DG_TWIST ) + resolution_code =ABS_TWIST ; resolution =hidinput_calc_abs_res (field, resolution_code);
@@ -2385,7 +2406,16 @@ static void wacom_wac_pen_usage_mapping(struct hid_device *hdev,wacom_map_usage (input, usage, field,EV_ABS ,ABS_TILT_Y ,0 );break ;case HID_DG_TWIST : +/* +* Map HID_DG_TWIST twice for backwards compatibility with +* legacy userspace that expects pen twist on ABS_Z. The order +* matters: the latter call overwrites usage->type and +* usage->code to point to ABS_TWIST, which prevents +* wacom_wac_pen_event() from automatically emitting ABS_Z; +* ABS_Z is emitted explicitly there instead. +*/ wacom_map_usage (input, usage, field,EV_ABS ,ABS_Z ,0 ); +wacom_map_usage (input, usage, field,EV_ABS ,ABS_TWIST ,0 );break ;case HID_DG_ERASER :input_set_capability (input,EV_KEY ,BTN_TOOL_RUBBER );
@@ -2492,15 +2522,9 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field }return ;case HID_DG_TWIST : -/* don't modify the value if the pen doesn't support the feature */ -if (!wacom_is_art_pen (wacom_wac->id[0 ]))return ; - -/* -* Userspace expects pen twist to have its zero point when -* the buttons/finger is on the tablet's left. HID values -* are zero when buttons are toward the top. -*/ - value =wacom_offset_rotation (input, usage, value,1 ,4 ); +/* don't report twist if the pen doesn't support the feature */ +if (!wacom_is_art_pen (wacom_wac->id[0 ])) +return ;break ;case WACOM_HID_WD_SENSE : wacom_wac->hid_data.sense_state = value;
@@ -2588,10 +2612,29 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *fieldreturn ;/* send pen events only when the pen is in range */ -if (wacom_wac->hid_data.inrange_state) +if (wacom_wac->hid_data.inrange_state) {input_event (input, usage->type, usage->code, value); -else if (wacom_wac->shared->stylus_in_proximity && !wacom_wac->hid_data.sense_state) +if (equivalent_usage ==HID_DG_TWIST ) { +/* +* wacom_wac_pen_usage_mapping() double-maps +* HID_DG_TWIST to both ABS_Z and ABS_TWIST, but +* usage->type and usage->code can only hold one +* mapping (ABS_TWIST). The input_event() above emits +* ABS_TWIST using the un-offset HID value (zero when +* buttons are toward the top, -Y). Also report on +* ABS_Z for backwards compatibility, shifted so its +* zero point is on the tablet's left (-X) as legacy +* userspace expects. +*/ + value =wacom_offset_rotation (input, usage, value,1 ,4 ); +input_report_abs (input,ABS_Z , value); + } + }else if (wacom_wac->shared->stylus_in_proximity && + !wacom_wac->hid_data.sense_state) {input_event (input, usage->type, usage->code,0 ); +if (equivalent_usage ==HID_DG_TWIST ) +input_report_abs (input,ABS_Z ,0 ); + } } static void wacom_wac_pen_pre_report(struct hid_device *hdev,
@@ -3807,6 +3850,7 @@ void wacom_setup_device_quirks(struct wacom *wacom)__clear_bit (BTN_TOOL_PENCIL , wacom_wac->pen_input->keybit);__clear_bit (BTN_TOOL_AIRBRUSH , wacom_wac->pen_input->keybit);__clear_bit (ABS_Z , wacom_wac->pen_input->absbit); +__clear_bit (ABS_TWIST , wacom_wac->pen_input->absbit);__clear_bit (ABS_DISTANCE , wacom_wac->pen_input->absbit);__clear_bit (ABS_TILT_X , wacom_wac->pen_input->absbit);__clear_bit (ABS_TILT_Y , wacom_wac->pen_input->absbit);
@@ -3889,6 +3933,8 @@ int wacom_setup_pen_input_capabilities(struct input_dev *input_dev,case CINTIQ_COMPANION_2 :input_set_abs_params (input_dev,ABS_Z ,-900 ,899 ,0 ,0 );input_abs_set_res (input_dev,ABS_Z ,287 ); +input_set_abs_params (input_dev,ABS_TWIST ,-900 ,899 ,0 ,0 ); +input_abs_set_res (input_dev,ABS_TWIST ,287 );wacom_setup_cintiq (wacom_wac);break ;
@@ -3901,6 +3947,8 @@ int wacom_setup_pen_input_capabilities(struct input_dev *input_dev,case INTUOS4S :input_set_abs_params (input_dev,ABS_Z ,-900 ,899 ,0 ,0 );input_abs_set_res (input_dev,ABS_Z ,287 ); +input_set_abs_params (input_dev,ABS_TWIST ,-900 ,899 ,0 ,0 ); +input_abs_set_res (input_dev,ABS_TWIST ,287 ); fallthrough;case INTUOS :
@@ -3921,6 +3969,8 @@ int wacom_setup_pen_input_capabilities(struct input_dev *input_dev,input_set_abs_params (input_dev,ABS_Z ,-900 ,899 ,0 ,0 );input_abs_set_res (input_dev,ABS_Z ,287 ); +input_set_abs_params (input_dev,ABS_TWIST ,-900 ,899 ,0 ,0 ); +input_abs_set_res (input_dev,ABS_TWIST ,287 );wacom_setup_intuos (wacom_wac);break ;
Signature · 1 line
2.56.1.911.g883d8bcb20-goog