[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

wsmoused(8) motion speed configuration



The following diff is derived from PR #4031, and adds two new options to
wsmoused(8) to let the user compensate for the speed of the mouse cursor
on fast hardware (oh, and while there, it replaces the few uses of
atoi(3) with strtonum(3)).

If you have experienced wsmoused being too fast on your hardware, please
test, tinker with -x and -y gain factors, and let me know of your
working settings.

Technical comments about the diff are also welcomed, of course.

Miod

Index: wsmoused.8
===================================================================
RCS file: /cvs/src/usr.sbin/wsmoused/wsmoused.8,v
retrieving revision 1.12
diff -u -p -r1.12 wsmoused.8
--- wsmoused.8	2003/11/08 08:49:51	1.12
+++ wsmoused.8	2005/03/07 14:14:13
@@ -38,6 +38,8 @@
 .Op Fl M Ar N=M
 .Op Fl p Ar device
 .Op Fl t Ar type
+.Op Fl x Ar gain
+.Op Fl y Ar gain
 .Nm wsmoused
 .Fl i
 .Op Fl p Ar device
@@ -161,6 +163,14 @@ Kensington ThinkingMouse protocol.
 .It Ar mmhitab
 Hitachi tablet protocol.
 .El
+.It Fl x Ar gain
+Specify the gain factor for the X axis of the device.
+The default value is 1.
+If the mouse cursor moves too fast, you may want to increase this value.
+.It Fl y Ar gain
+Specify the gain factor for the Y axis of the device.
+The default value is 1.
+If the mouse cursor moves too fast, you may want to increase this value.
 .El
 .Pp
 .Nm
Index: wsmoused.c
===================================================================
RCS file: /cvs/src/usr.sbin/wsmoused/wsmoused.c,v
retrieving revision 1.18
diff -u -p -r1.18 wsmoused.c
--- wsmoused.c	2004/01/04 21:41:12	1.18
+++ wsmoused.c	2005/03/07 14:14:14
@@ -94,6 +94,8 @@ mouse_t mouse = {
 	wmode : 0,
 	mfd : -1,
 	clickthreshold : 500,	/* 0.5 sec */
+	xgain: 1,
+	ygain: 1
 };
 
 /* identify the type of a wsmouse supported mouse */
@@ -184,20 +186,20 @@ mouse_installmap(char *arg)
 		arg = skipspace(arg);
 		if ((arg <= s) || (*arg != '='))
 			return FALSE;
-		lbutton = atoi(s);
+		lbutton = strtonum(s, 1, MOUSE_MAXBUTTON, NULL);
+		if (errno != 0)
+			return FALSE;
 
 		arg = skipspace(++arg);
 		s = arg;
 		while (isdigit(*arg))
 			++arg;
 		if (arg <= s || (!isspace(*arg) && *arg != '\0'))
-			return FALSE;
-		pbutton = atoi(s);
-
-		if (lbutton <= 0 || lbutton > MOUSE_MAXBUTTON)
 			return FALSE;
-		if (pbutton <= 0 || pbutton > MOUSE_MAXBUTTON)
+		pbutton = strtonum(s, 1, MOUSE_MAXBUTTON, NULL);
+		if (errno != 0)
 			return FALSE;
+
 		p2l[pbutton - 1] = lbutton - 1;
 	}
 	return TRUE;
@@ -283,7 +285,10 @@ mouse_click(struct wscons_event *event)
 	ioctl(mouse.cfd, WSDISPLAYIO_WSMOUSED, event);
 }
 
-/* workaround for cursor speed on serial mice */
+/*
+ * Compensate for cursor speed on serial mice
+ * Note that the normal gain processing will still be run afterwards.
+ */
 static void
 normalize_event(struct wscons_event *event)
 {
@@ -291,7 +296,7 @@ normalize_event(struct wscons_event *eve
 	int two_power = 1;
 
 /* 2: normal speed, 3: slower cursor, 1: faster cursor */
-#define NORMALIZE_DIVISOR 3
+#define NORMALIZE_DIVISOR 2
 
 	switch (event->type) {
 	case WSCONS_EVENT_MOUSE_DELTA_X:
@@ -314,6 +319,20 @@ normalize_event(struct wscons_event *eve
 	}
 }
 
+/* apply gain reduction to the event */
+static void
+adj_delta_xy(struct wscons_event *event)
+{
+	switch (event->type) {
+	case WSCONS_EVENT_MOUSE_DELTA_X:
+		event->value /= mouse.xgain;
+		break;
+	case WSCONS_EVENT_MOUSE_DELTA_Y:
+		event->value /= mouse.ygain;
+		break;
+	}
+}
+
 /* send a wscons_event to the kernel */
 static int
 treat_event(struct wscons_event *event)
@@ -321,6 +340,7 @@ treat_event(struct wscons_event *event)
 	struct wscons_event mapped_event;
 
 	if (IS_MOTION_EVENT(event->type)) {
+		adj_delta_xy(event);
 		ioctl(mouse.cfd, WSDISPLAYIO_WSMOUSED, event);
 		return 1;
 	} else if (IS_BUTTON_EVENT(event->type)) {
@@ -499,8 +519,9 @@ main(int argc, char **argv)
 {
 	int opt;
 	int i;
+	const char *errstr;
 
-#define GETOPT_STRING "2dfhip:t:C:I:M:"
+#define GETOPT_STRING "2dfhip:t:x:y:C:I:M:"
 	while ((opt = (getopt(argc, argv, GETOPT_STRING))) != -1) {
 		switch (opt) {
 		case '2':
@@ -540,13 +561,35 @@ main(int argc, char **argv)
 			warnx("no such mouse protocol `%s'", optarg);
 			usage();
 			break;
+		case 'x':
+#define	MAX_GAINTHRESHOLD	200
+			mouse.xgain = strtonum(optarg, 1,
+			    MAX_GAINTHRESHOLD, &errstr);
+			if (errstr != NULL) {
+				warnx("X axis gain value `%s' is %s, "
+				    "acceptable range is 1-%d",
+				    optarg, errstr, MAX_GAINTHRESHOLD);
+				usage();
+			}
+			break;
+		case 'y':
+			mouse.ygain = strtonum(optarg, 1,
+			    MAX_GAINTHRESHOLD, &errstr);
+			if (errstr != NULL) {
+				warnx("Y axis gain value `%s' is %s, "
+				    "acceptable range is 1-%d",
+				    optarg, errstr, MAX_GAINTHRESHOLD);
+				usage();
+			}
+			break;
 		case 'C':
 #define MAX_CLICKTHRESHOLD 2000 /* max delay for double click */
-			mouse.clickthreshold = atoi(optarg);
-			if (mouse.clickthreshold < 0 ||
-			    mouse.clickthreshold > MAX_CLICKTHRESHOLD) {
-				warnx("invalid threshold `%s': max value is %d",
-				    optarg, MAX_CLICKTHRESHOLD);
+			mouse.clickthreshold = strtonum(optarg, 0,
+			    MAX_CLICKTHRESHOLD, &errstr);
+			if (errstr != NULL) {
+				warnx("threshold value `%s' is %s, "
+				    "acceptable range is 0-%d",
+				    optarg, errstr, MAX_CLICKTHRESHOLD);
 				usage();
 			}
 			break;
Index: wsmoused.h
===================================================================
RCS file: /cvs/src/usr.sbin/wsmoused/wsmoused.h,v
retrieving revision 1.4
diff -u -p -r1.4 wsmoused.h
--- wsmoused.h	2002/02/15 02:18:39	1.4
+++ wsmoused.h	2005/03/07 14:14:14
@@ -97,19 +97,21 @@ extern char *pidfile;
 
 /* mouse structure : main structure */
 typedef struct mouse_s {
-    int flags;
-    char *portname;		/* /dev/XXX */
-    int proto;			/* MOUSE_PROTO_XXX */
-    int baudrate;
-    int old_baudrate;
-    unsigned char rate;			/* report rate */
-    unsigned char resolution;		/* MOUSE_RES_XXX or a positive number */
-    int zmap;			/* MOUSE_{X|Y}AXIS or a button number */
-    int wmode;			/* wheel mode button number */
-    int mfd;			/* mouse file descriptor */
-    int cfd;			/* console file descriptor */
-    long clickthreshold;	/* double click speed in msec */
-} mouse_t ;
+	int flags;
+	char *portname;			/* /dev/XXX */
+	int proto;			/* MOUSE_PROTO_XXX */
+	int baudrate;
+	int old_baudrate;
+	unsigned char rate;		/* report rate */
+	unsigned int resolution;	/* MOUSE_RES_XXX or a positive number */
+	int zmap;			/* MOUSE_{X|Y}AXIS or a button number */
+	int wmode;			/* wheel mode button number */
+	int mfd;			/* mouse file descriptor */
+	int cfd;			/* console file descriptor */
+	long clickthreshold;		/* double click speed in msec */
+	int xgain;
+	int ygain;
+} mouse_t;
 
 /* Mouse buttons */



Visit your host, monkey.org