The touchpad/track point on my laptop are ridiculously fast and very
hard to use. Same goes for ordinary mouses. Here's my attempt at
solving this.
When user sets sensitivity, instead of passing movement right through,
scale it, accumulate it, and flush when the accumulator is full.
diff -Nuar usr.sbin/wsmoused_orig/Makefile usr.sbin/wsmoused/Makefile
--- usr.sbin/wsmoused_orig/Makefile Thu Aug 27 22:49:52 2009
+++ usr.sbin/wsmoused/Makefile Thu Aug 27 23:49:51 2009
@@ -5,6 +5,7 @@
PROG= wsmoused
SRCS= wsmoused.c mouse_protocols.c
+LDFLAGS= -lm
.else
diff -Nuar usr.sbin/wsmoused_orig/wsmoused.8 usr.sbin/wsmoused/wsmoused.8
--- usr.sbin/wsmoused_orig/wsmoused.8 Thu Aug 27 22:49:52 2009
+++ usr.sbin/wsmoused/wsmoused.8 Fri Aug 28 00:23:51 2009
@@ -32,6 +32,7 @@
.Nd wsmouse daemon
.Sh SYNOPSIS
.Nm wsmoused
+.Op Fl s Ar sens
.Op Fl 2dfi
.Op Fl C Ar thresh
.Op Fl D Ar device
@@ -63,6 +64,10 @@
.Pp
The options are as follows:
.Bl -tag -width "-p device"
+.It Fl s Ar sens
+Set mouse sensitivity.
+.Ar sens
+is a floating point number between 0 and 10.
.It Fl 2
Indicate that the mouse has two buttons.
In that case, the right button pastes.
@@ -185,9 +190,10 @@
To start wsmoused on the
.Nm wsdisplay1
display terminals, using a two-button serial mouse connected to
-.Pa /dev/cua0 :
+.Pa /dev/cua0
+with movement speed set to 50% of normal:
.Pp
-.Dl # wsmoused -2 -D /dev/ttyDcfg -p /dev/cua0
+.Dl # wsmoused -s 0.5 -2 -D /dev/ttyDcfg -p /dev/cua0
.Pp
To start wsmoused on the
.Nm wsdisplay0
diff -Nuar usr.sbin/wsmoused_orig/wsmoused.c usr.sbin/wsmoused/wsmoused.c
--- usr.sbin/wsmoused_orig/wsmoused.c Thu Aug 27 22:49:52 2009
+++ usr.sbin/wsmoused/wsmoused.c Fri Aug 28 00:25:45 2009
@@ -68,6 +68,7 @@
#include <string.h>
#include <stdlib.h>
#include <syslog.h>
+#include <math.h>
#include "mouse_protocols.h"
#include "wsmoused.h"
@@ -83,6 +84,7 @@
int nodaemon = FALSE;
int identify = FALSE;
char *pidfile = NULL;
+double sensitivity = 0.0;
mouse_t mouse = {
.flags = 0,
@@ -339,19 +341,55 @@
treat_event(struct wscons_event *event)
{
struct wscons_event mapped_event;
+ double ipart;
+ static double xaccum = 0, yaccum = 0;
- if (IS_MOTION_EVENT(event->type)) {
+ switch (event->type) {
+ case WSCONS_EVENT_MOUSE_DELTA_X:
+ if (sensitivity != 0.0) {
+ xaccum += event->value * sensitivity;
+ if (fabs(xaccum) > 1) {
+ if (xaccum > 0)
+ ipart = floor(xaccum);
+ else
+ ipart = ceil(xaccum);
+ event->value = (int) ipart;
+ xaccum -= ipart;
+ ioctl(mouse.cfd, WSDISPLAYIO_WSMOUSED, event);
+ }
+ } else
+ ioctl(mouse.cfd, WSDISPLAYIO_WSMOUSED, event);
+ break;
+ case WSCONS_EVENT_MOUSE_DELTA_Y:
+ if (sensitivity != 0.0) {
+ yaccum += event->value * sensitivity;
+ if (fabs(yaccum) > 1) {
+ if (yaccum > 0)
+ ipart = floor(yaccum);
+ else
+ ipart = ceil(yaccum);
+ event->value = (int) ipart;
+ yaccum -= ipart;
+ ioctl(mouse.cfd, WSDISPLAYIO_WSMOUSED, event);
+ }
+ } else
+ ioctl(mouse.cfd, WSDISPLAYIO_WSMOUSED, event);
+ break;
+ case WSCONS_EVENT_MOUSE_DELTA_Z:
+ case WSCONS_EVENT_MOUSE_DELTA_W:
ioctl(mouse.cfd, WSDISPLAYIO_WSMOUSED, event);
- return 1;
- } else if (IS_BUTTON_EVENT(event->type) &&
- (uint)event->value < MOUSE_MAXBUTTON) {
- mouse_map(event, &mapped_event);
- mouse_click(&mapped_event);
- return 1;
- }
- if (event->type == WSCONS_EVENT_WSMOUSED_CLOSE)
+ break;
+ case WSCONS_EVENT_MOUSE_UP:
+ case WSCONS_EVENT_MOUSE_DOWN:
+ if (event->value < MOUSE_MAXBUTTON) {
+ mouse_map(event, &mapped_event);
+ mouse_click(&mapped_event);
+ }
+ break;
+ case WSCONS_EVENT_WSMOUSED_CLOSE:
/* we have to close mouse fd */
return 0;
+ }
return 1;
}
@@ -518,7 +556,7 @@
static void
usage(void)
{
- fprintf(stderr, "usage: %s [-2dfi] [-C thresh] [-D device] [-I file]"
+ fprintf(stderr, "usage: %s [-s sens] [-2dfi] [-C thresh] [-D device]
[-I file]"
" [-M N=M]\n\t[-p device] [-t type]\n", __progname);
exit(1);
}
@@ -531,7 +569,7 @@
int opt;
int i;
-#define GETOPT_STRING "2dfhip:t:C:D:I:M:"
+#define GETOPT_STRING "2dfhip:t:C:D:I:M:s:"
while ((opt = (getopt(argc, argv, GETOPT_STRING))) != -1) {
switch (opt) {
case '2':
@@ -592,6 +630,14 @@
case 'M':
if (!mouse_installmap(optarg)) {
warnx("invalid mapping `%s'", optarg);
+ usage();
+ }
+ break;
+ case 's':
+ sensitivity = atof(optarg);
+ if (sensitivity <= 0.0 || sensitivity > 10.0) {
+ warnx("sensitivity must be a floating point "
+ "number between 0 and 10");
usage();
}
break;