Skip to content

Commit

Permalink
HID: wacom: Set eraser status when either 'Eraser' or 'Invert' usage …
Browse files Browse the repository at this point in the history
…is set

Microsoft defines two slightly different behaviors for pens that are
being used to erase. The first one, for pens that can be used while
inverted specifies that both 'Invert' and 'Eraser' usages should be
set while the pen is in contact and erasing. For pens that use an
eraser button though, they specify that only the 'Eraser' usage should
be set (while hovering, only the 'Invert' usage is to be set).

We used our internal 'invert_state' flag to determine if a pen has an
intent to erase (whether hovering or not). That flag was previously
only depending on the 'Invert' usage, which was sufficient for the
first type of pen (EMR) but not the second type (AES). This commit
makes the flag depend on either usage being set, and also renames it
to make its function more clear.

This change should not normally have an impact on userspace due to
both the existing driver and firmware design. The driver already only
determines tool type based on the first event in an interaction (e.g.
it will see the 'Invert' bit set when the eraser comes into prox and
then report BTN_TOOL_RUBBER for the rest of the interaction, even if
'Invert' is cleared). AES firmware is also careful to send reports
that work through a set of defined state transitions, even in the
corner-case where the eraser button is pressed when the pen is already
in contact with the display (Prox|Tip -> Prox -> 0 -> Invert -> Eraser).
Regardless, it seems reasonable to ensure the driver's state variables
match programmer expectation.

Link: https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/windows-pen-states
Signed-off-by: Jason Gerecke <[email protected]>
Signed-off-by: Jiri Kosina <[email protected]>
[[email protected]: Imported into input-wacom (a025b0dbd83f)]
Signed-off-by: Jason Gerecke <[email protected]>
  • Loading branch information
jigpu committed Oct 23, 2024
1 parent 605d359 commit 4f0ee05
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions 4.18/wacom_wac.c
Original file line number Diff line number Diff line change
Expand Up @@ -2447,9 +2447,11 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field
wacom_wac->hid_data.sense_state = value;
return;
case HID_DG_INVERT:
wacom_wac->hid_data.invert_state = value;
wacom_wac->hid_data.eraser |= value;
return;
case HID_DG_ERASER:
wacom_wac->hid_data.eraser |= value;
fallthrough;
case HID_DG_TIPSWITCH:
wacom_wac->hid_data.tipswitch |= value;
return;
Expand Down Expand Up @@ -2590,7 +2592,7 @@ static void wacom_wac_pen_report(struct hid_device *hdev,

if (entering_range) { /* first in range */
/* Going into range select tool */
if (wacom_wac->hid_data.invert_state)
if (wacom_wac->hid_data.eraser)
wacom_wac->tool[0] = BTN_TOOL_RUBBER;
else if (wacom_wac->features.quirks & WACOM_QUIRK_AESPEN)
wacom_wac->tool[0] = BTN_TOOL_PEN;
Expand Down Expand Up @@ -2644,6 +2646,7 @@ static void wacom_wac_pen_report(struct hid_device *hdev,
}

wacom_wac->hid_data.tipswitch = false;
wacom_wac->hid_data.eraser = false;

input_sync(input);
}
Expand Down
2 changes: 1 addition & 1 deletion 4.18/wacom_wac.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ struct hid_data {
__s16 inputmode_index; /* InputMode HID feature index in the report */
bool sense_state;
bool inrange_state;
bool invert_state;
bool eraser;
bool tipswitch;
bool barrelswitch;
bool barrelswitch2;
Expand Down

0 comments on commit 4f0ee05

Please sign in to comment.