mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jason Gerecke <killertofu@gmail.com>
To: Siarhei Vishniakou <svv@google.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Jiri Kosina <jikos@kernel.org>,
	 Benjamin Tissoires <bentiss@kernel.org>,
	Ping Cheng <ping.cheng@wacom.com>,
	 Jason Gerecke <jason.gerecke@wacom.com>,
	Jonathan Corbet <corbet@lwn.net>,
	 Henrik Rydberg <rydberg@bitmath.org>,
	linux-input@vger.kernel.org,  linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] HID: wacom: report ABS_TWIST alongside ABS_Z for pen twist
Date: Fri, 13 Nov 2026 15:29:35 -0800	[thread overview]
Message-ID: <CANRwn3S63O+WRTGhpcNR__ybSuYUb2uEJavUY3b9Uaa_vEhWXQ@mail.gmail.com> (raw)
In-Reply-To: <20261110020632.4003499-4-svv@google.com>

On Mon, Nov 9, 2026 at 6:21 PM Siarhei Vishniakou <svv@google.com> wrote:
>
> Historically, Wacom tablets reported stylus barrel rotation (twist)
> via ABS_Z because a dedicated evdev axis did not exist. Now that we
> have this axis, report pen twist on ABS_TWIST in addition to ABS_Z.
>
> Keep reporting ABS_Z to maintain backward compatibility for existing
> applications that support Wacom devices.
>
> Signed-off-by: Siarhei Vishniakou <svv@google.com>
> ---
>  drivers/hid/wacom_wac.c | 35 +++++++++++++++++++++++++++++------
>  1 file changed, 29 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
> index 614f2adab563..7676bc26a027 100644
> --- a/drivers/hid/wacom_wac.c
> +++ b/drivers/hid/wacom_wac.c
> @@ -802,8 +802,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 */
> @@ -981,6 +983,7 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
>                         t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
>                                 ((t-1) / 2 + 450)) : (450 - t / 2) ;
>                         input_report_abs(input, ABS_Z, t);
> +                       input_report_abs(input, ABS_TWIST, t);
>                 } else {
>                         /* 4D mouse 2nd packet */
>                         t = (data[6] << 3) | ((data[7] >> 5) & 7);
> @@ -1411,6 +1414,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
>                                 input_report_abs(pen_input, ABS_TILT_Y,
>                                                  (signed char)frame[8]);
>                                 input_report_abs(pen_input, ABS_Z, rotation);
> +                               input_report_abs(pen_input, ABS_TWIST, rotation);
>                                 input_report_abs(pen_input, ABS_WHEEL,
>                                                  get_unaligned_le16(&frame[11]));
>                         }
> @@ -1935,7 +1939,7 @@ static void wacom_map_usage(struct input_dev *input, struct hid_usage *usage,
>         int resolution;
>
>         if (equivalent_usage == HID_DG_TWIST) {
> -               resolution_code = ABS_RZ;
> +               resolution_code = ABS_TWIST;
>         }

Requesting a comment here just to make sure that anyone that is only
casually reading doesn't think this code is dead. Setting *some* kind
of radial axis here (be it ABS_RZ or ABS_TWIST) is critical to
ensuring HID properly calculates the resolution for ABS_Z, and that
might not be obvious when you see HID_DG_TWIST forcing the
resolution_code to ABS_TWIST.

>
>         resolution = hidinput_calc_abs_res(field, resolution_code);
> @@ -2332,6 +2336,7 @@ static void wacom_wac_pen_usage_mapping(struct hid_device *hdev,
>                 break;
>         case HID_DG_TWIST:

Also requesting a comment for this case that explains that the usage
here is mapped twice for backwards-compatibility, and that the order
matters since the latter call will override `usage->type` and
`usage->code`, preventing wacom_wac_pen_event from automatically
emitting an ABS_Z event.

>                 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);
> @@ -2522,10 +2527,21 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field
>                 return;
>
>         /* send pen events only when the pen is in range */
> -       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)
> -               input_event(input, usage->type, usage->code, 0);
> +       if (!wacom_wac->hid_data.inrange_state) {
> +               if (!wacom_wac->shared->stylus_in_proximity ||
> +                   wacom_wac->hid_data.sense_state)
> +                       return;
> +               value = 0;
> +       }
> +
> +       input_event(input, usage->type, usage->code, value);
> +       /*
> +        * ABS_Z was used to report twist data, because ABS_TWIST was not yet
> +        * defined at the time. For compatibility purposes, also report twist
> +        * via ABS_Z.
> +        */

I think this comment could be a little more clear, perhaps referencing
the double-mapping in wacom_wac_pen_usage_mapping (and how we need to
send data out of both ABS_TWIST and ABS_Z but that `usage->type` and
`usage->code` can only be set to one of those two)

Jason (she/they)
---
Now instead of four in the eights place /
you’ve got three, ‘Cause you added one  /
(That is to say, eight) to the two,     /
But you can’t take seven from three,    /
So you look at the sixty-fours....

> +       if (equivalent_usage == HID_DG_TWIST)
> +               input_report_abs(input, ABS_Z, value);
>  }
>
>  static void wacom_wac_pen_pre_report(struct hid_device *hdev,
> @@ -3741,6 +3757,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);
> @@ -3823,6 +3840,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;
>
> @@ -3835,6 +3854,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:
> @@ -3855,6 +3876,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;
> --
> 2.56.0.455.g6c5a503b38-goog
>
>

  reply	other threads:[~2026-11-13 23:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10  2:06 [PATCH 0/3] Input: add ABS_TWIST and support it in HID and Wacom Siarhei Vishniakou
2026-11-10  2:06 ` [PATCH 1/3] Input: add ABS_TWIST event code Siarhei Vishniakou
2026-11-10  2:06 ` [PATCH 2/3] HID: input: map Digitizers Twist usage to ABS_TWIST Siarhei Vishniakou
2026-11-10  2:06 ` [PATCH 3/3] HID: wacom: report ABS_TWIST alongside ABS_Z for pen twist Siarhei Vishniakou
2026-11-13 23:29   ` Jason Gerecke [this message]
2026-11-10  2:25 ` [PATCH 0/3] Input: add ABS_TWIST and support it in HID and Wacom Dmitry Torokhov
2026-11-10 18:57   ` Siarhei Vishniakou
2026-11-22 22:13     ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANRwn3S63O+WRTGhpcNR__ybSuYUb2uEJavUY3b9Uaa_vEhWXQ@mail.gmail.com \
    --to=killertofu@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jason.gerecke@wacom.com \
    --cc=jikos@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ping.cheng@wacom.com \
    --cc=rydberg@bitmath.org \
    --cc=svv@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®