diff mbox series

HID: wacom: Only report rotation for art pen

Message ID 20220512035909.17523-1-ping.cheng@wacom.com
State New
Headers show
Series HID: wacom: Only report rotation for art pen | expand

Commit Message

Ping Cheng May 12, 2022, 3:59 a.m. UTC
The generic routine, wacom_wac_pen_event, turns rotation value 90
degree anti-clockwise before posting the events. This non-zero
event trggers a non-zero ABS_Z event for non art pen tools. However,
HID_DG_TWIST is only supported by art pen.

Signed-off-by: Ping Cheng <ping.cheng@wacom.com>
Reviewed-by: Jason Gerecke <jason.gerecke@wacom.com>
---
 drivers/hid/wacom_wac.c | 158 ++++++++++++++++++++++++++----------------------
 1 file changed, 85 insertions(+), 73 deletions(-)
diff mbox series

Patch

diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index 5c7ee45..be9af54 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -642,90 +642,99 @@  static int wacom_intuos_id_mangle(int tool_id)
 	return (tool_id & ~0xFFF) << 4 | (tool_id & 0xFFF);
 }
 
-static int wacom_intuos_get_tool_type(int tool_id)
+static bool wacom_is_art_pen(int tool_id)
 {
-	int tool_type;
+	bool is_art_pen = false;
 
 	switch (tool_id) {
-	case 0x812: /* Inking pen */
-	case 0x801: /* Intuos3 Inking pen */
-	case 0x12802: /* Intuos4/5 Inking Pen */
-	case 0x012:
-		tool_type = BTN_TOOL_PENCIL;
+	case 0x885:	/* Intuos3 Marker Pen */
+	case 0x804:	/* Intuos4/5 13HD/24HD Marker Pen */
+	case 0x10804:	/* Intuos4/5 13HD/24HD Art Pen */
+		is_art_pen = true;
 		break;
+	}
+	return is_art_pen;
+}
 
-	case 0x822: /* Pen */
-	case 0x842:
-	case 0x852:
-	case 0x823: /* Intuos3 Grip Pen */
-	case 0x813: /* Intuos3 Classic Pen */
-	case 0x885: /* Intuos3 Marker Pen */
-	case 0x802: /* Intuos4/5 13HD/24HD General Pen */
-	case 0x804: /* Intuos4/5 13HD/24HD Marker Pen */
-	case 0x8e2: /* IntuosHT2 pen */
-	case 0x022:
-	case 0x10804: /* Intuos4/5 13HD/24HD Art Pen */
-	case 0x10842: /* MobileStudio Pro Pro Pen slim */
-	case 0x14802: /* Intuos4/5 13HD/24HD Classic Pen */
-	case 0x16802: /* Cintiq 13HD Pro Pen */
-	case 0x18802: /* DTH2242 Pen */
-	case 0x10802: /* Intuos4/5 13HD/24HD General Pen */
-		tool_type = BTN_TOOL_PEN;
-		break;
+static int wacom_intuos_get_tool_type(int tool_id)
+{
+	int tool_type = BTN_TOOL_PEN;
+
+	if (!wacom_is_art_pen(tool_id)) {
+		switch (tool_id) {
+		case 0x812: /* Inking pen */
+		case 0x801: /* Intuos3 Inking pen */
+		case 0x12802: /* Intuos4/5 Inking Pen */
+		case 0x012:
+			tool_type = BTN_TOOL_PENCIL;
+			break;
 
-	case 0x832: /* Stroke pen */
-	case 0x032:
-		tool_type = BTN_TOOL_BRUSH;
-		break;
+		case 0x822: /* Pen */
+		case 0x842:
+		case 0x852:
+		case 0x823: /* Intuos3 Grip Pen */
+		case 0x813: /* Intuos3 Classic Pen */
+		case 0x802: /* Intuos4/5 13HD/24HD General Pen */
+		case 0x8e2: /* IntuosHT2 pen */
+		case 0x022:
+		case 0x10842: /* MobileStudio Pro Pro Pen slim */
+		case 0x14802: /* Intuos4/5 13HD/24HD Classic Pen */
+		case 0x16802: /* Cintiq 13HD Pro Pen */
+		case 0x18802: /* DTH2242 Pen */
+		case 0x10802: /* Intuos4/5 13HD/24HD General Pen */
+			tool_type = BTN_TOOL_PEN;
+			break;
 
-	case 0x007: /* Mouse 4D and 2D */
-	case 0x09c:
-	case 0x094:
-	case 0x017: /* Intuos3 2D Mouse */
-	case 0x806: /* Intuos4 Mouse */
-		tool_type = BTN_TOOL_MOUSE;
-		break;
+		case 0x832: /* Stroke pen */
+		case 0x032:
+			tool_type = BTN_TOOL_BRUSH;
+			break;
 
-	case 0x096: /* Lens cursor */
-	case 0x097: /* Intuos3 Lens cursor */
-	case 0x006: /* Intuos4 Lens cursor */
-		tool_type = BTN_TOOL_LENS;
-		break;
+		case 0x007: /* Mouse 4D and 2D */
+		case 0x09c:
+		case 0x094:
+		case 0x017: /* Intuos3 2D Mouse */
+		case 0x806: /* Intuos4 Mouse */
+			tool_type = BTN_TOOL_MOUSE;
+			break;
 
-	case 0x82a: /* Eraser */
-	case 0x84a:
-	case 0x85a:
-	case 0x91a:
-	case 0xd1a:
-	case 0x0fa:
-	case 0x82b: /* Intuos3 Grip Pen Eraser */
-	case 0x81b: /* Intuos3 Classic Pen Eraser */
-	case 0x91b: /* Intuos3 Airbrush Eraser */
-	case 0x80c: /* Intuos4/5 13HD/24HD Marker Pen Eraser */
-	case 0x80a: /* Intuos4/5 13HD/24HD General Pen Eraser */
-	case 0x90a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
-	case 0x1480a: /* Intuos4/5 13HD/24HD Classic Pen Eraser */
-	case 0x1090a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
-	case 0x1080c: /* Intuos4/5 13HD/24HD Art Pen Eraser */
-	case 0x1084a: /* MobileStudio Pro Pro Pen slim Eraser */
-	case 0x1680a: /* Cintiq 13HD Pro Pen Eraser */
-	case 0x1880a: /* DTH2242 Eraser */
-	case 0x1080a: /* Intuos4/5 13HD/24HD General Pen Eraser */
-		tool_type = BTN_TOOL_RUBBER;
-		break;
+		case 0x096: /* Lens cursor */
+		case 0x097: /* Intuos3 Lens cursor */
+		case 0x006: /* Intuos4 Lens cursor */
+			tool_type = BTN_TOOL_LENS;
+			break;
 
-	case 0xd12:
-	case 0x912:
-	case 0x112:
-	case 0x913: /* Intuos3 Airbrush */
-	case 0x902: /* Intuos4/5 13HD/24HD Airbrush */
-	case 0x10902: /* Intuos4/5 13HD/24HD Airbrush */
-		tool_type = BTN_TOOL_AIRBRUSH;
-		break;
+		case 0x82a: /* Eraser */
+		case 0x84a:
+		case 0x85a:
+		case 0x91a:
+		case 0xd1a:
+		case 0x0fa:
+		case 0x82b: /* Intuos3 Grip Pen Eraser */
+		case 0x81b: /* Intuos3 Classic Pen Eraser */
+		case 0x91b: /* Intuos3 Airbrush Eraser */
+		case 0x80c: /* Intuos4/5 13HD/24HD Marker Pen Eraser */
+		case 0x80a: /* Intuos4/5 13HD/24HD General Pen Eraser */
+		case 0x90a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
+		case 0x1480a: /* Intuos4/5 13HD/24HD Classic Pen Eraser */
+		case 0x1090a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
+		case 0x1080c: /* Intuos4/5 13HD/24HD Art Pen Eraser */
+		case 0x1084a: /* MobileStudio Pro Pro Pen slim Eraser */
+		case 0x1680a: /* Cintiq 13HD Pro Pen Eraser */
+		case 0x1880a: /* DTH2242 Eraser */
+		case 0x1080a: /* Intuos4/5 13HD/24HD General Pen Eraser */
+			tool_type = BTN_TOOL_RUBBER;
+			break;
 
-	default: /* Unknown tool */
-		tool_type = BTN_TOOL_PEN;
-		break;
+		case 0xd12:
+		case 0x912:
+		case 0x112:
+		case 0x913: /* Intuos3 Airbrush */
+		case 0x902: /* Intuos4/5 13HD/24HD Airbrush */
+		case 0x10902: /* Intuos4/5 13HD/24HD Airbrush */
+			tool_type = BTN_TOOL_AIRBRUSH;
+			break;
+		}
 	}
 	return tool_type;
 }
@@ -2332,6 +2341,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