Re: [PATCH v2 1/3] Input: add ABS_TWIST event code

From
Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date
2026-11-26 05:53:35
Also in
linux-input, lkml
Reply to
Siarhei Vishniakou, 2026-11-26
On Wed, Nov 25, 2026 at 06:43:35PM -0800, Siarhei Vishniakou wrote:
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.

Signed-off-by: Siarhei Vishniakou <redacted>
---
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).
I'd like Peter (CCed) to take a look at this too...
quoted hunk ↗ jump to hunk
 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(+)
diff --git a/Documentation/input/event-codes.rst b/Documentation/input/event-codes.rst
index 77a6c9b3956d..4f03dcacbd55 100644
--- a/Documentation/input/event-codes.rst
+++ b/Documentation/input/event-codes.rst
@@ -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
diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c
index f44e6e708404..2e9ff8a3b2cf 100644
--- a/drivers/hid/hid-debug.c
+++ b/drivers/hid/hid-debug.c
@@ -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",
diff --git a/include/uapi/linux/input-event-codes.h b/include/uapi/linux/input-event-codes.h
index 4217950e5d16..d4ed115fdeca 100644
--- a/include/uapi/linux/input-event-codes.h
+++ b/include/uapi/linux/input-event-codes.h
@@ -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
-- 
Dmitry
Thread (5 messages) 5 messages, 2 authors, last reply 3d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help