Skip to content

Commit 7953794

Browse files
PinglinuxJiri Kosina
authored andcommitted
HID: input: map HID_GD_Z to ABS_DISTANCE for stylus/pen
HID_GD_Z is mapped to ABS_Z for stylus and pen in hid-input.c. But HID_GD_Z should be used to report ABS_DISTANCE for stylus and pen as described at: Documentation/input/event-codes.rst#n226 * ABS_DISTANCE: - Used to describe the distance of a tool from an interaction surface. This event should only be emitted while the tool is hovering, meaning in close proximity of the device and while the value of the BTN_TOUCH code is 0. If the input device may be used freely in three dimensions, consider ABS_Z instead. - BTN_TOOL_<name> should be set to 1 when the tool comes into detectable proximity and set to 0 when the tool leaves detectable proximity. BTN_TOOL_<name> signals the type of tool that is currently detected by the hardware and is otherwise independent of ABS_DISTANCE and/or BTN_TOUCH. This patch makes the correct mapping. The ABS_DISTANCE is currently not mapped by any HID usage in hid-generic driver. Signed-off-by: Ping Cheng <ping.cheng@wacom.com> Cc: stable@kernel.org Signed-off-by: Jiri Kosina <jkosina@suse.com>
1 parent 0678f56 commit 7953794

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

drivers/hid/hid-input.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,14 +878,30 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
878878

879879
switch (usage->hid) {
880880
/* These usage IDs map directly to the usage codes. */
881-
case HID_GD_X: case HID_GD_Y: case HID_GD_Z:
881+
case HID_GD_X: case HID_GD_Y:
882882
case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ:
883883
if (field->flags & HID_MAIN_ITEM_RELATIVE)
884884
map_rel(usage->hid & 0xf);
885885
else
886886
map_abs_clear(usage->hid & 0xf);
887887
break;
888888

889+
case HID_GD_Z:
890+
/* HID_GD_Z is mapped to ABS_DISTANCE for stylus/pen */
891+
if (field->flags & HID_MAIN_ITEM_RELATIVE) {
892+
map_rel(usage->hid & 0xf);
893+
} else {
894+
if (field->application == HID_DG_PEN ||
895+
field->physical == HID_DG_PEN ||
896+
field->logical == HID_DG_STYLUS ||
897+
field->physical == HID_DG_STYLUS ||
898+
field->application == HID_DG_DIGITIZER)
899+
map_abs_clear(ABS_DISTANCE);
900+
else
901+
map_abs_clear(usage->hid & 0xf);
902+
}
903+
break;
904+
889905
case HID_GD_WHEEL:
890906
if (field->flags & HID_MAIN_ITEM_RELATIVE) {
891907
set_bit(REL_WHEEL, input->relbit);

0 commit comments

Comments
 (0)