Module Name:    src
Committed By:   nia
Date:           Sat Mar 14 13:08:18 UTC 2020

Modified Files:
        src/share/man/man4: pms.4
        src/sys/dev/pckbport: synaptics.c

Log Message:
synaptics: Make up_down_emulation useful for single-button clickpads

On devices such as the Thinkpad X250, the clickpad can be pressed
to generate mouse button events 1 and 2. There are also additional
physical buttons which the pms(4) driver recognizes as "up/down" buttons
(mouse buttons 3 and 4). Allow these to be remapped to buttons 1 and 2
and used like normal touchpad buttons with the following sysctl:

# sysctl -w hw.synaptics.up_down_emulation=3

While here, adjust the existing "middle button emulation"
(hw.synaptics.up_down_emulation=1) so it works with single-button
clickpads.

XXX: 3 may be a more useful default than the current default,
depending on hardware availability of touchpads with "up/down buttons".

Update the documentation accordingly.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/share/man/man4/pms.4
cvs rdiff -u -r1.54 -r1.55 src/sys/dev/pckbport/synaptics.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man4/pms.4
diff -u src/share/man/man4/pms.4:1.34 src/share/man/man4/pms.4:1.35
--- src/share/man/man4/pms.4:1.34	Mon Feb 10 16:13:48 2020
+++ src/share/man/man4/pms.4	Sat Mar 14 13:08:18 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: pms.4,v 1.34 2020/02/10 16:13:48 ryoon Exp $
+.\" $NetBSD: pms.4,v 1.35 2020/03/14 13:08:18 nia Exp $
 .\"
 .\" Copyright (c) 1993 Christopher G. Demetriou
 .\" All rights reserved.
@@ -105,10 +105,17 @@ variables control behavior of Synaptics 
 If the touchpad reports the existence of Up/Down buttons, this value
 determines if they should be reported as button 4 and 5 events or if
 they should be used to emulate some other event.
-When set to 0, report Up/Down events as buttons 4 and 5.
-When set to 1, the Up and Down buttons are both mapped to the middle button.
-When set to 2 (default), the Up and Down buttons are used for Z-axis
+.Bl -bullet
+.It
+If set to 0, Up/Down events generate button 4 and 5 clicks.
+.It
+If set to 1, Up/Down events generate middle button clicks.
+.It
+If set to 2 (default), the Up and Down buttons are used for Z-axis
 emulation, which more closely resembles how mouse wheels operate.
+.It
+If set to 3, Up/Down events generate left/right clicks.
+.El
 .It Dv hw.synaptics.up_down_motion_delta
 When the Up/Down buttons are used for Z-axis emulation, this value specifies
 the emulated delta-Z value per click.
@@ -139,9 +146,14 @@ reported pressure drops below this value
 More recent touchpads can report the presence of more than one finger
 on the pad.
 This value determines how such events are used.
+.Bl -bullet
+.It
 If set to 0 (default), two-finger events are ignored.
+.It
 If set to 1, two-finger events generate a right button click.
+.It
 If set to 2, two-finger events generate a middle button click.
+.El
 .It Dv hw.synaptics.scale_x
 .It Dv hw.synaptics.scale_y
 .It Dv hw.synaptics.scale_z

Index: src/sys/dev/pckbport/synaptics.c
diff -u src/sys/dev/pckbport/synaptics.c:1.54 src/sys/dev/pckbport/synaptics.c:1.55
--- src/sys/dev/pckbport/synaptics.c:1.54	Tue Feb 25 21:41:38 2020
+++ src/sys/dev/pckbport/synaptics.c	Sat Mar 14 13:08:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: synaptics.c,v 1.54 2020/02/25 21:41:38 ryoon Exp $	*/
+/*	$NetBSD: synaptics.c,v 1.55 2020/03/14 13:08:18 nia Exp $	*/
 
 /*
  * Copyright (c) 2005, Steve C. Woodford
@@ -48,7 +48,7 @@
 #include "opt_pms.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: synaptics.c,v 1.54 2020/02/25 21:41:38 ryoon Exp $");
+__KERNEL_RCSID(0, "$NetBSD: synaptics.c,v 1.55 2020/03/14 13:08:18 nia Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -852,8 +852,11 @@ pms_sysctl_synaptics_verify(SYSCTLFN_ARG
 		return error;
 
 	/* Sanity check the params. */
-	if (node.sysctl_num == synaptics_up_down_emul_nodenum ||
-	    node.sysctl_num == synaptics_two_fingers_emul_nodenum) {
+	if (node.sysctl_num == synaptics_up_down_emul_nodenum) {
+		if (t < 0 || t > 3)
+			return (EINVAL);
+	} else
+	if (node.sysctl_num == synaptics_two_fingers_emul_nodenum) {
 		if (t < 0 || t > 2)
 			return (EINVAL);
 	} else
@@ -1092,13 +1095,29 @@ pms_synaptics_parse(struct pms_softc *ps
 			/* Old style Middle Button. */
 			sp.sp_middle = (psc->packet[0] & PMS_LBUTMASK) ^
 		    	    (psc->packet[3] & PMS_LBUTMASK);
-		} else if (synaptics_up_down_emul == 1) {
+		} else if (synaptics_up_down_emul != 1) {
+			sp.sp_middle = 0;
+		}
+
+		switch (synaptics_up_down_emul) {
+		case 1:
 			/* Do middle button emulation using up/down buttons */
 			sp.sp_middle = sp.sp_up | sp.sp_down;
 			sp.sp_up = sp.sp_down = 0;
-		} else
-			sp.sp_middle = 0;
-
+			break;
+		case 3:
+			/* Do left/right button emulation using up/down buttons */
+			sp.sp_left = sp.sp_up;
+			sp.sp_right = sp.sp_down;
+			sp.sp_up = sp.sp_down = 0;
+			break;
+		default:
+			/*
+			 * Don't do any remapping...
+			 * Z-axis emulation is handled in pms_synaptics_process_packet
+			 */
+			break;
+		}
 	}
 
 	pms_synaptics_process_packet(psc, &sp);

Reply via email to